Discussions

Increase stock level if order has been canceled/deleted

Can I return the value of the product stock level to initial value when order has been canceled or deleted?

Posted: Dec 21, 2011

Comments

rfay Randy Fay on December 21, 2011

Assuming you're using commerce_stock, you'll want to create a rule that does that.

After an order has been saved,
if the order status is cancelled and the original order status was complete,
loop through the line items
decrement stock on the related products by the quantity in the line item.

z-buffer on December 22, 2011

Yes, I'm using commerce_stock and I've tried to create this rule before, but it didn't work.

Then I created this rule another way and it works fine, here the checklist:

1. Add event "After updating an existing commerce order"
2. Add condition:

if("[commerce-order:status]" == "canceled" && "[commerce-order-unchanged:status]" != "[commerce-order:status]") {
return TRUE;
}
else {
return FALSE;
}

3. Add action "Increase stock when canceling the order process" the same way as rule "Decrease stock when completing the order process" do it.
4. Profit! :)

But if I need doing this thing when order has been deleted? If I understand correctly, when order is deleted I can't get data from it. What can I do in this case?

z-buffer on December 23, 2011

Thanks, rfay )
Now I'm going to build a set of rules for stock level updating in other use cases, for example, when store manager change products number in some order and so on.
But I think, why there is no predefined set of rules for this more complex stock management? I saw several discussions on drupal.org related to such problems, so I think this feature can be useful...

vipingoyal on April 24, 2012

Can you tell me how you add this condition for checking if order is cancelled.
How you implement this condition, because at condition there is not any option for check order status.
It'll be very helpful for me, Thanks.