2

I'm trying to set unit price amount to some value when order state is changed to canceled. The order always contains only one line item. I want to set total amount of order to $charge's value.

The exported rule. $charge holds correct value. But unit price and total price is not changed.

{ "rules_order_cancel" : {
    "LABEL" : "Order cancel",
    "PLUGIN" : "reaction rule",
    "WEIGHT" : "10",
    "REQUIRES" : [ "rules", "php", "commerce_line_item", "commerce_product_reference" ],
    "ON" : [ "commerce_product_calculate_sell_price" ],
    "IF" : [
      { "data_is" : { "data" : [ "commerce-line-item:order:status" ], "value" : "canceled" } }
    ],
    "DO" : [
      { "php_eval" : { "code" : "if($commerce_line_item-\u003Etype == \u0027insurance_search_line_item\u0027) {\r\n  $def_num = count($commerce_line_item-\u003Efield_defendant[\u0027und\u0027]);\r\n  $amount = $def_num * 75 * 100;\r\n}\r\n\r\n$_SESSION[\u0027msi_charge\u0027] = $amount;" } },
      { "commerce_line_item_unit_price_amount" : {
          "commerce_line_item" : [ "commerce-line-item" ],
          "amount" : {
            "select" : "site:current-user:uid",
            "php" : { "code" : "$charge = $_SESSION[\u0027msi_charge\u0027];\r\nunset($_SESSION[\u0027msi_charge\u0027]);\r\ndsm($charge);\r\nreturn $charge;" }
          },
          "component_name" : "base_price",
          "round_mode" : "1"
        }
      }
    ]
  }
}

Your Answer

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

Browse other questions tagged or ask your own question.