diff --git a/README.txt b/README.txt index 4bcd004..638d513 100644 --- a/README.txt +++ b/README.txt @@ -61,6 +61,17 @@ admin/commerce/config/stock/validation and admin/commerce/config/stock/control +Increase stock level when canceling an order +============================================ +If you want stock to be automatically returned when an order is canceled you can +enable the "Stock: Increase when canceling the order process" rule on the "stock +control" configuration page. +This will handle orders with a state change +from: Pending, Processing or Completed +to: Canceled +you can easily update this to include other states that are relevant to your +site. + Decimal Stock ============= The editing of stock levels support decimal quantities, to enable this feature diff --git a/modules/commerce_ss/commerce_ss.rules_defaults.inc b/modules/commerce_ss/commerce_ss.rules_defaults.inc index 6649a9c..f982da1 100644 --- a/modules/commerce_ss/commerce_ss.rules_defaults.inc +++ b/modules/commerce_ss/commerce_ss.rules_defaults.inc @@ -31,5 +31,40 @@ function commerce_ss_default_rules_configuration() { $rules['rules_decrement_stock_completing_order'] = rules_import($rules_export); + $rules_export ='{ "rules_increment_stock_canceling_order" : { + "LABEL" : "Stock: Increase when canceling the order process", + "PLUGIN" : "reaction rule", + "ACTIVE" : false, + "TAGS" : [ "stock_control" ], + "REQUIRES" : [ "rules", "commerce_ss", "entity" ], + "ON" : [ "commerce_order_update" ], + "IF" : [ + { "data_is" : { "data" : [ "commerce-order:status" ], "value" : "canceled" } }, + { "data_is" : { + "data" : [ "commerce-order-unchanged:status" ], + "op" : "IN", + "value" : { "value" : { + "pending" : "pending", + "processing" : "processing", + "completed" : "completed" + } + } + } + } + ], + "DO" : [ + { "LOOP" : { + "USING" : { "list" : [ "commerce-order:commerce-line-items" ] }, + "ITEM" : { "list_item" : "Current list item" }, + "DO" : [ + { "commerce_ss_increase_by_line_item" : { "commerce_line_item" : [ "list-item" ] } } + ] + } + } + ] + } + }'; + $rules['rules_increment_stock_canceling_order'] = rules_import($rules_export); + return $rules; }