I am using the following Rule to separate Qty's into separate line items in the cart. I needed to do this because of our integration with Salesforce.
{ "rules_split_quantity" : {
"LABEL" : "Split Quantity",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "rules_array_create", "commerce_cart" ],
"ON" : { "commerce_cart_product_add" : [] },
"IF" : [
{ "data_is" : { "data" : [ "quantity" ], "op" : "\u003E", "value" : "1" } }
],
"DO" : [
{ "array_create" : {
"USING" : { "size" : [ "quantity" ] },
"PROVIDE" : { "array_added" : { "amount_array" : "Amount Array" } }
}
},
{ "LOOP" : {
"USING" : { "list" : [ "amount-array" ] },
"ITEM" : { "list_item" : "Current list item" },
"DO" : [
{ "commerce_cart_product_add_by_sku" : {
"USING" : {
"user" : [ "site:current-user" ],
"sku" : [ "commerce-product:sku" ],
"quantity" : "1",
"combine" : "0"
},
"PROVIDE" : { "product_add_line_item" : { "product_add_line_item" : "Added product line item" } }
}
}
]
}
},
{ "list_remove" : {
"list" : [ "commerce-order:commerce-line-items" ],
"item" : [ "commerce-line-item" ]
}
}
]
}
}
The problem I am having now though is that if a user uses the Product Attribute feature on a product to change the price before adding to cart, it only maintains the new price if they add 1 item to the cart at a time.
If the user select a quantity of 5 at the adjusted price and hits add to cart, 5 items are added to the cart but the price remains unchanged.
I have tried adjusting this Rule a little to first grab the Price of the product before looping through, but it doesn't seem to see the adjust price, only the original price.
Comments
Comment #2
TravisJohnston CreditAttribution: TravisJohnston commentedI managed to solve this myself by instead using a custom module to split the quantities, adding a field to the line item called New Price, populating that field during the quantity split, then using a Rule to calculate sell price of product and using the value of the New Price field. More seen here http://drupal.stackexchange.com/questions/182445/split-line-items-by-qty-and-retain-altered-price