{ "rules_decrement_stock_completing_order" : { "LABEL" : "Stock: Decrease when completing the order process", "PLUGIN" : "reaction rule", "OWNER" : "rules", "TAGS" : [ "stock_control" ], "REQUIRES" : [ "commerce_ss", "commerce_checkout" ], "ON" : { "commerce_checkout_complete" : [] }, "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_stock_validate_add_to_cart" : { "LABEL" : "Stock: validate add to cart", "PLUGIN" : "reaction rule", "OWNER" : "rules", "REQUIRES" : [ "rules", "commerce_stock" ], "ON" : { "commerce_stock_add_to_cart_check_product" : [] }, "IF" : [ { "NOT component_rules_commerce_stock_product_has_stock" : { "commerce_product" : [ "commerce_product" ], "required_stock" : [ "stock-requested-total" ] } } ], "DO" : [ { "data_calc" : { "USING" : { "input_1" : [ "commerce-product:commerce-stock" ], "op" : "-", "input_2" : [ "stock-already-ordered" ] }, "PROVIDE" : { "result" : { "approved_quantity" : "approved quantity" } } } }, { "commerce_stock_add_to_cart_set_state" : { "stock_action" : "1", "message" : "The maximum quantity for [commerce-product:title] that can be ordered is [commerce-product:commerce-stock-int].\r\n", "approved_quantity" : [ "approved-quantity" ] } } ] } } { "rules_stock_validate_checkout" : { "LABEL" : "Stock: validate checkout", "PLUGIN" : "reaction rule", "OWNER" : "rules", "REQUIRES" : [ "rules", "commerce_stock" ], "ON" : { "commerce_stock_check_product_checkout" : [] }, "IF" : [ { "NOT component_rules_commerce_stock_product_has_stock" : { "commerce_product" : [ "commerce_product" ], "required_stock" : [ "stock-already-ordered" ] } } ], "DO" : [ { "commerce_stock_checkout_state" : { "stock_action" : "1", "message" : "The maximum quantity for [commerce-product:title] that can be ordered is [commerce-product:commerce-stock-int].", "approved_quantity" : [ "commerce-product:commerce-stock" ] } } ] } } { "rules_commerce_stock_product_has_stock" : { "LABEL" : "Product has stock", "PLUGIN" : "rule condition set", "OWNER" : "rules", "REQUIRES" : [ "rules_conditional", "rules" ], "USES VARIABLES" : { "commerce_product" : { "label" : "Commerce product", "type" : "commerce_product" }, "required_stock" : { "label" : "Required stock", "type" : "decimal" } }, "DO" : [ { "component_rules_commerce_stock_get_product_stock" : { "USING" : { "commerce_product" : [ "commerce_product" ] }, "PROVIDE" : { "stock" : { "available_stock" : "Available stock" } } } } ], "RESULT" : [ { "NOT data_is" : { "data" : [ "required-stock" ], "op" : "\u003E", "value" : [ "available-stock" ] } } ] } } { "rules_commerce_stock_get_product_stock" : { "LABEL" : "Get product stock (This should become an event reaction rule, see #1288958)", "PLUGIN" : "rule set", "OWNER" : "rules", "REQUIRES" : [ "rules" ], "USES VARIABLES" : { "commerce_product" : { "label" : "Commerce product", "type" : "commerce_product" }, "stock" : { "label" : "Stock", "type" : "decimal", "parameter" : false } }, "RULES" : [ { "RULE" : { "PROVIDE" : { "variable_added" : { "stock_found" : "Stock found" } }, "DO" : [ { "variable_add" : { "USING" : { "type" : "boolean", "value" : 0 }, "PROVIDE" : { "variable_added" : { "stock_found" : "Stock found" } } } } ], "LABEL" : "Default stock-found" } }, { "RULE" : { "PROVIDE" : { "minimal_stock" : { "minimal_stock" : "Minimal stock" } }, "IF" : [ { "entity_has_field" : { "entity" : [ "commerce-product" ], "field" : "field_product_package_included" } } ], "DO" : [ { "component_rules_product_package_get_minimal_stock" : { "USING" : { "commerce_products" : [ "commerce-product:field-product-package-included" ] }, "PROVIDE" : { "minimal_stock" : { "minimal_stock" : "Minimal stock" } } } }, { "data_set" : { "data" : [ "stock" ], "value" : [ "minimal-stock" ] } }, { "data_set" : { "data" : [ "stock-found" ], "value" : 1 } } ], "LABEL" : "Product package" } }, { "RULE" : { "DO" : [ { "data_set" : { "data" : [ "stock" ], "value" : [ "commerce-product:commerce-stock" ] } } ], "LABEL" : "Else use product stock" } } ], "PROVIDES VARIABLES" : [ "stock" ] } } { "rules_product_package_get_minimal_stock" : { "LABEL" : "Product package get minimal stock", "PLUGIN" : "rule", "OWNER" : "rules", "REQUIRES" : [ "rules", "rules_conditional" ], "USES VARIABLES" : { "commerce_products" : { "label" : "Commerce products", "type" : "list\u003Ccommerce_product\u003E" }, "minimal_stock" : { "label" : "Minimal stock", "type" : "decimal", "parameter" : false } }, "DO" : [ { "data_set" : { "data" : [ "minimal-stock" ], "value" : "999999999" } }, { "LOOP" : { "USING" : { "list" : [ "commerce-products" ] }, "ITEM" : { "list_item" : "Aktuelle Listenelement" }, "DO" : [ { "CONDITIONAL" : [ { "IF" : { "data_is" : { "data" : [ "minimal-stock" ], "op" : "\u003C", "value" : [ "list-item:commerce-stock" ] } }, "DO" : [ { "data_set" : { "data" : [ "minimal-stock" ], "value" : [ "list-item:commerce-stock" ] } } ] } ] } ] } } ], "PROVIDES VARIABLES" : [ "minimal_stock" ] } }