Vote up!
Vote down!

Commerce Line Item Rules not sticking even after Entity Save

Hello All,

I've spend hours trying to get to to the bottom of this.
It seems that in Rules, using any of the Commerce Line Item action don't stick, even after invoking the Entity Save on the [commerce-line-item:order] as directed here http://www.drupalcommerce.org/node/1053

I have the latest versions of Drupal (7.14) Commerce (1.3) and Rules (2.1)

To reproduce:
Add Product (I put price $500) SKU: AAA
Add Product Display referencing SKU: AAA

Import the following Rule.

{ "rules_change_line_item_price" : {
    "LABEL" : "Change line Item price",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "commerce_line_item", "rules", "commerce_cart" ],
    "ON" : [ "commerce_cart_product_add" ],
    "DO" : [
      { "commerce_line_item_unit_price_subtract" : {
          "commerce_line_item" : [ "commerce_line_item" ],
          "amount" : "40000",
          "component_name" : "base_price",
          "round_mode" : "1"
      { "entity_save" : { "data" : [ "commerce-line-item:order" ], "immediate" : 1 } }

Add product to cart.
The Rule should subtract $400 dollars..
But the cart shows original price. No deduction

Rules Log shows that it ran successfully.

0 ms Reacting on event After adding a product to the cart.
0.475 ms Evaluating conditions of rule Change line Item price. [edit]
0.486 ms AND evaluated to TRUE.
" Rule Change line Item price fires. [edit]
0 ms Rule Change line Item price fires.
0.17 ms Evaluating the action commerce_line_item_unit_price_subtract. [edit] <----------------------------------!!!!
3.307 ms Evaluating the action entity_save. [edit]
3.382 ms Saved commerce_line_item:order of type commerce_order. <---------------------------------------!!!!
18.664 ms Rule Change line Item price has fired.

Any help to get this to work would be appreciated.

I've test all the Commerce Line Item Action

What is interesting is that the value gets changed. If i set a rule to output the [commerce-line-item:commerce-price:amount] as system message it will have calculated correctly. It just doesn't stick. The cart does not show the modified line item or reflect that the action took place in any way.

Note: if I use the Data Set Value action to change [commerce-line-item:quantity] and modify the quantity it will successfully work.

Asked by: yfreeman
on June 27, 2012

1 Answer