function uc_stock_order in Ubercart 6.2
Implementation of hook_order().
File
- uc_stock/
uc_stock.module, line 208
Code
function uc_stock_order($op, &$order, $edit) {
switch ($op) {
case 'edit-products':
// Invoked when adding, editing or removing products in the order editor.
if (!isset($edit['update_stock']) || !$edit['update_stock']) {
return;
}
if (isset($edit['products']) && is_array($edit['products'])) {
foreach ($edit['products'] as $product) {
if ($product['model'] != $product['original_model']) {
$temp_product = new stdClass();
$temp_product->model = $product['original_model'];
$temp_product->qty = -$product['original_qty'];
uc_stock_adjust_product_stock($temp_product, 0, $order);
uc_stock_adjust_product_stock($product, 0, $order);
}
elseif ($product['qty'] != $product['original_qty']) {
$temp_product = new stdClass();
$temp_product->model = $product['model'];
$temp_product->qty = $product['qty'] - $product['original_qty'];
uc_stock_adjust_product_stock($temp_product, 0, $order);
}
}
}
switch ($edit['action']) {
case 'add':
$product = node_load(intval($edit['nid']));
$product->qty = intval($edit['qty']);
$product->price = $product->sell_price;
$product->data = module_invoke_all('add_to_cart_data', $edit);
foreach (module_implements('cart_item') as $module) {
$function = $module . '_cart_item';
$function('load', $product);
}
uc_stock_adjust_product_stock($product, 0, $order);
break;
case 'remove':
$order_product_id = intval($edit['opid']);
$product = db_fetch_object(db_query("SELECT model, qty FROM {uc_order_products} WHERE order_product_id = %d", $order_product_id));
$product->qty = -$product->qty;
uc_stock_adjust_product_stock($product, 0, $order);
break;
}
break;
}
}