diff -urp ./uc_stock.ca.inc ../../ubercartS/uc_stock/uc_stock.ca.inc --- ./uc_stock.ca.inc 2009-09-23 21:50:45.000000000 +0200 +++ ../../ubercartS/uc_stock/uc_stock.ca.inc 2010-03-03 16:04:05.000000000 +0100 @@ -30,6 +30,36 @@ function uc_stock_ca_predicate() { ), ), ); + $predicates['uc_stock_action_increment_stock'] = array( + '#title' => t('Increment stock on cancelling order'), + '#trigger' => 'uc_order_status_update', + '#conditions' => array( + '#operator' => 'AND', + '#conditions' => array( + array( + '#name' => 'uc_order_status_condition', + '#title' => t('If the order status is Cancelled.'), + '#argument_map' => array( + 'order' => 'updated_order', + ), + '#settings' => array( + 'order_status' => 'canceled', + ), + ), + ), + ), + '#class' => 'uc_stock', + '#status' => 1, + '#actions' => array( + array( + '#name' => 'uc_stock_action_increment_stock', + '#title' => t('Increment stock of products in order'), + '#argument_map' => array( + 'order' => 'order', + ), + ), + ), + ); return $predicates; } @@ -46,6 +76,14 @@ function uc_stock_ca_action() { ), '#category' => t('Stock'), ); + $actions['uc_stock_action_increment_stock'] = array( + '#title' => t('Increment stock of products on the order with tracking activated.'), + '#callback' => 'uc_stock_action_increment_stock', + '#arguments' => array( + 'order' => array('#entity' => 'uc_order', '#title' => t('Order')), + ), + '#category' => t('Stock'), + ); return $actions; } @@ -62,3 +100,12 @@ function uc_stock_action_decrement_stock array_walk($order->products, 'uc_stock_decrement_product_stock', $order); } } + +/** + * Increase the stock of ordered products. + */ +function uc_stock_action_increment_stock($order, $settings) { + if (is_array($order->products)) { + array_walk($order->products, 'uc_stock_increment_product_stock', $order); + } +} diff -urp ./uc_stock.module ../../ubercartS/uc_stock/uc_stock.module --- ./uc_stock.module 2009-09-23 21:50:45.000000000 +0200 +++ ../../ubercartS/uc_stock/uc_stock.module 2010-03-03 16:03:40.000000000 +0100 @@ -303,3 +303,25 @@ function uc_stock_decrement_product_stoc uc_order_comment_save($order->order_id, 0, t('The stock level for %model_name has been decreased to !qty.', array('%model_name' => $product->model, '!qty' => $stock->stock))); } +/** + * Increment a product's stock. + * + * @param $product + * The product whose stock is decrementing. + */ +function uc_stock_increment_product_stock($product, $key, $order) { + // Product has an active stock? + if (!uc_stock_is_active($product->model)) { + return; + } + + // Decrement the product's stock. + uc_stock_adjust($product->model, $product->qty); + + // Load the new stock record + $stock = db_fetch_object(db_query("SELECT * FROM {uc_product_stock} WHERE sku = '%s'", $product->model)); + + // Save a comment about the stock level. + uc_order_comment_save($order->order_id, 0, t('The stock level for %model_name has been increased to !qty.', array('%model_name' => $product->model, '!qty' => $stock->stock))); +} + Seulement dans .: uc_stock.patch