0

I have used drupal commerce module. I have rules to increase stock when the order process is cancelled and decrease the stock after completed the order process.
When i cancelled the order status, the stock will be increased. It is fine.
When i trying to change the order status any of pending, processing, completed from cancelled, it didn't happened anything in my stocks.
But again when i changed status to cancelled, the stock will be increased.
So i want to write rule for "decrease stock when reverting from cancel the order process"
How to create rule for this edge cases?

  • Have you tried using Commerce Stock Reserve (link) together with Commerce Simple Stock? You might be able to get what you need with just the default rules. – Channel Islander Mar 13 '15 at 14:04
0

It can be done using hook_default_rules_configuration(). Below is my code:

<?php
/**
 * implement hook_default_rules_configuration().
*/
function phponwebsites_default_rules_configuration(){
$rules = array();
$rules_export = '{ "phponwebsites_rules_decrement_stock_revert_cancel" : {
            "LABEL" : "Stock: decrease when revert canceling the order process (cloned)",
            "PLUGIN" : "reaction rule",
            "OWNER" : "rules",
            "TAGS" : [ "stock_control" ],
            "REQUIRES" : [ "rules", "commerce_ss", "entity" ],
            "ON" : { "commerce_order_update" : [] },
            "IF" : [
              { "data_is" : { "data" : [ "commerce-order:status" ],
                  "op" : "IN",
                  "value" : { "value" : {
                      "pending" : "pending",
                      "processing" : "processing",
                      "completed" : "completed"
                    }
                  }
                }
              },
              { "data_is" : {
                  "data" : [ "commerce-order-unchanged:status" ], "value" : "canceled"
                }
              }
            ],
            "DO" : [
              { "LOOP" : {
                  "USING" : { "list" : [ "commerce-order:commerce-line-items" ] },
                  "ITEM" : { "list_item" : "Current list item" },
                  "DO" : [
                    { "commerce_ss_decrease_by_line_item" : { "commerce_line_item" : [ "list-item" ] } }
                  ]
                }
              }
            ]
          }
        }';
   $rules['phponwebsites_rules_decrement_stock_revert_cancel'] = rules_import($rules_export);
 return $rules;
}
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.