Good afternoon everyone,
I've been trying to determine the cause of my site's order products to decrease twice. I narrowed it down to an issue specific to orders manipulated through the administration edits. I thought perhaps my conditional actions were wrong, but they are not. I set them up to add admin comments to orders when they fired to ensure the stock decrement conditional action is only fired once. I ran through creating an order on the admin side, with those comments, and this is the result:
01/20/2012 10:44:02 AM 1 Order created by the administration. 01/20/2012 10:44:38 AM - The stock level for 7734 has been decreased to 5. 01/20/2012 10:45:39 AM 1 Order not yet saved. Order decremented its own stock on product addition... 01/20/2012 10:45:53 AM - The stock level for 7734 has been increased to 6. 01/20/2012 10:46:21 AM 1 Order not yet saved. Order incremented its own stock on product quantity alteration. 01/20/2012 10:46:47 AM - Decremented stock at order complete trigger. 01/20/2012 10:46:47 AM - The stock level for 7734 has been decreased to 4. 01/20/2012 10:46:51 AM - Updated order status to payment received.
As you can see, the moment I add the product to order, the stock is adjusted. The stock is then removed again when the trigger fires. I'm not sure what we should consider the problem.
- Should stock be removed when added to an order?
-- If that's true, shouldn't we decrement stock when a user adds something to their cart on the public side?
--- If the stock handling moves to add to cart / add to order, should we remove the decrement stock trigger all together?
- Should stock only be removed when an order is moved to payment received, or other order complete statuses, as defined by the user's chosen conditional actions?
To me, the most simple answer would be to unify the system, trusting in the user's choice of conditional actions to remove the stock when they feel is the right time. To that end, I suggest the following code be removed to avoid the admin orders from double inventory reduction:
From: uc_order/uc_order.admin.inc : function uc_order_edit_form_submit
if (module_exists('uc_stock')) {
$qtys = array();
foreach ($order->products as $product) {
$qtys[$product->order_product_id] = $product->qty;
}
}
From: uc_order/uc_order.admin.inc : function uc_order_edit_products
// Decrement stock?
if (module_exists('uc_stock')) {
uc_stock_adjust_product_stock($product, 0, $order);
}
Other keywords I've seen used that relate to this problem:
- Duplicate stock decrement
- Stock removed twice
- Order completes twice (Clearly, this is not true, but might lead people to this solution)
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | uc_order.patch | 1.91 KB | michaelk |
Comments
Comment #1
michaelk commentedI also ran into this issue, and I went ahead and removed the uc_stock code that lance.gliser mentioned. Here is the patch that fixed the issue for me.
Comment #3
longwaveThis needs a bit more thought, because what if the store owner edits the order after it is considered completed? They may still want the stock levels to be updated in this case. This issue could perhaps be considered a duplicate of #1034044: Add checkboxes to enable/disable stock level changes when editing orders
Comment #4
lance.gliser commentedI think that might be a solid association longwave. The only real need is to provide some sort of control admins can use and understand.
Comment #5
vrajak@gmail.com commentedAnyone ever find a solution to this? My customer orders are just fine, its the one made via admin that are decrementing stock twice.
Thanks!
Comment #6
rjlang commentedA workaround for Ubercart 2 is described here:
http://www.ubercart.org/forum/bug_reports/30591/stock_doubledecremented_...
Comment #7
longwaveThis should be fixed in 6.x-2.x with the addition of the admin checkbox in #1034044: Add checkboxes to enable/disable stock level changes when editing orders