Tags/topics: 
1
Answers
Vote up!
1
Vote down!

How may I set a minimum quantity for a specific sku? (solved)

Goal:

In this case the website needs to set a minimum quantity of an product because it will be embossed with the company logo. The company may wish to purchase one or more of the product than minimum.

Attempted:

Using the commerce pricing rules have created many rules to attempt to set a minimum quantity for a particular sku for one item and find it attached the rule to other items.

The rule that comes closest to doing this is;

Events;Calculating the sell price of a product, After updating an existing commerce line item
Conditions;Order contains a particular product Parameter: Order: [commerce-line-item:order], Product SKU: WTR-BLU-OS, Operator: <=, Quantity: 299
Actions; Set a data value Parameter: Data: [commerce-line-item:quantity], Value: 300

I have set this up on multiple Commerce Kickstart fresh installs. Have created a video showing what it does and does not do. http://youtu.be/iA-mWrdprJc

Have stepped through the steps for hours and am unable to locate or trace the point at which the event takes place to point it out.

Here are the three rules used;

Rule #1:

{ "rules_minimum_amount_rule_usb_blu_08" : {
"LABEL" : "minimum amount rule USB-BLU-08",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "commerce_order", "rules", "commerce_product_reference", "entity" ],
"ON" : {
"commerce_product_calculate_sell_price" : [],
"commerce_line_item_update" : []
},
"IF" : [
{ "commerce_order_contains_product" : {
"commerce_order" : [ "commerce-line-item:order" ],
"product_id" : "USB-BLU-08",
"operator" : "\u003C=",
"value" : "47"
}
}
],
"DO" : [
{ "data_set" : { "data" : [ "commerce-line-item:quantity" ], "value" : "48" } },
{ "data_set" : {
"data" : [ "commerce-line-item:commerce-total" ],
"value" : { "value" : { "amount" : 50000, "currency_code" : "USD" } }
}
}
]
}
}

Rule #2

{ "rules_minimum_amount_rule_hat2_blk_os" : {
"LABEL" : "minimum amount rule HAT2-BLK-OS",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "commerce_order", "rules", "commerce_product_reference", "entity" ],
"ON" : {
"commerce_product_calculate_sell_price" : [],
"commerce_line_item_update" : []
},
"IF" : [
{ "commerce_order_contains_product" : {
"commerce_order" : [ "commerce-line-item:order" ],
"product_id" : "HAT2-BLK-OS",
"operator" : "\u003C=",
"value" : "47"
}
}
],
"DO" : [
{ "data_set" : { "data" : [ "commerce-line-item:quantity" ], "value" : "48" } },
{ "data_set" : {
"data" : [ "commerce-line-item:commerce-total" ],
"value" : { "value" : { "amount" : 50000, "currency_code" : "USD" } }
}
}
]
}
}

Rule #3

{ "rules_minimum_amount_rule_via_store_pricing_rules_300" : {
"LABEL" : "minimum amount rule via store pricing rules 300",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "commerce_order", "rules", "commerce_product_reference", "entity" ],
"ON" : {
"commerce_product_calculate_sell_price" : [],
"commerce_line_item_update" : []
},
"IF" : [
{ "commerce_order_contains_product" : {
"commerce_order" : [ "commerce-line-item:order" ],
"product_id" : "MG2-YLW-OS",
"operator" : "\u003C=",
"value" : "299"
}
}
],
"DO" : [
{ "data_set" : { "data" : [ "commerce-line-item:quantity" ], "value" : "300" } },
{ "data_set" : {
"data" : [ "commerce-line-item:commerce-total" ],
"value" : { "value" : { "amount" : 62700, "currency_code" : "USD" } }
}
}
]
}
}

Is there another way to get this done? Another rule configuration?

Answer:

//Condition component 1 for product with sku : MG2-YLW-OS

{ "rules_condition_for_getting_cart_item_for_sku_mg2_ylw_os" : {
"LABEL" : "Condition for getting cart item for SKU MG2-YLW-OS",
"PLUGIN" : "and",
"OWNER" : "rules",
"REQUIRES" : [ "inline_conditions", "rules" ],
"USES VARIABLES" : { "line_item" : { "label" : "Line Item", "type" : "commerce_line_item" } },
"AND" : [
{ "commerce_product_contains_products" : { "commerce_line_item" : [ "line-item" ], "sku" : "MG2-YLW-OS" } },
{ "data_is" : { "data" : [ "line-item:quantity" ], "op" : "\u003C", "value" : "300" } }
]
}
}

//Reaction Rule 1 for product with sku : MG2-YLW-OS

{ "rules_set_minimum_number_of_items_in_the_cart" : {
"LABEL" : "Set minimum number of items in the cart",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "commerce_cart", "entity", "commerce_product_reference" ],
"ON" : {
"commerce_cart_product_add" : [],
"commerce_line_item_update" : [],
"commerce_order_update" : [],
"commerce_product_calculate_sell_price" : []
},
"IF" : [
{ "component_rules_condition_for_getting_cart_item_for_sku_mg2_ylw_os" : { "line_item" : [ "commerce-line-item" ] } }
],
"DO" : [
{ "data_set" : { "data" : [ "commerce-line-item:quantity" ], "value" : "300" } }
]
}
}

Asked by: garpy
on December 7, 2014

1 Answer

Vote up!
1
Vote down!

//Condition component 1 for product with sku : MG2-YLW-OS

{ "rules_condition_for_getting_cart_item_for_sku_mg2_ylw_os" : {
"LABEL" : "Condition for getting cart item for SKU MG2-YLW-OS",
"PLUGIN" : "and",
"OWNER" : "rules",
"REQUIRES" : [ "inline_conditions", "rules" ],
"USES VARIABLES" : { "line_item" : { "label" : "Line Item", "type" : "commerce_line_item" } },
"AND" : [
{ "commerce_product_contains_products" : { "commerce_line_item" : [ "line-item" ], "sku" : "MG2-YLW-OS" } },
{ "data_is" : { "data" : [ "line-item:quantity" ], "op" : "\u003C", "value" : "300" } }
]
}
}

//Reaction Rule 1 for product with sku : MG2-YLW-OS

{ "rules_set_minimum_number_of_items_in_the_cart" : {
"LABEL" : "Set minimum number of items in the cart",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "commerce_cart", "entity", "commerce_product_reference" ],
"ON" : {
"commerce_cart_product_add" : [],
"commerce_line_item_update" : [],
"commerce_order_update" : [],
"commerce_product_calculate_sell_price" : []
},
"IF" : [
{ "component_rules_condition_for_getting_cart_item_for_sku_mg2_ylw_os" : { "line_item" : [ "commerce-line-item" ] } }
],
"DO" : [
{ "data_set" : { "data" : [ "commerce-line-item:quantity" ], "value" : "300" } }
]
}
}

Answer by: garpy
Posted: Dec 13, 2014