1

I am using Commerce 7.x-1.13 module on my website. I would like to calculate the shipping based on the order total. However, every time I refresh my checkout page, the shipping fee will be increased because the "order total" includes product price, tax, and shipping fee. Does anyone have any idea that I can calculate shipping only based on the product price?

Below is my shipping rule(if order subtotal<9, shipping=5% of subtotal; else shipping=9):

{ "rules_shipping_ground" : {
"LABEL" : "Ground",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [
  "rules",
  "rules_conditional",
  "commerce_line_item",
  "commerce_shipping"
],
"ON" : { "commerce_shipping_calculate_rate" : [] },
"IF" : [
  { "entity_has_field" : {
      "entity" : [ "commerce-line-item" ],
      "field" : "commerce_shipping_service"
    }
  },
  { "data_is" : {
      "data" : [ "commerce-line-item:commerce-shipping-service" ],
      "value" : "standard"
    }
  }
],
"DO" : [
  { "data_calc" : {
      "USING" : {
        "input_1" : [ "commerce-line-item:order:commerce-order-total:amount" ],
        "op" : "*",
        "input_2" : ".5"
      },
      "PROVIDE" : { "result" : { "5oftotal" : "5% of total" } }
    }
  },
  { "CONDITIONAL" : [
      {
        "IF" : { "data_is" : { "data" : [ "5oftotal" ], "op" : "\u003E", "value" : "900" } },
        "DO" : [
          { "commerce_line_item_unit_price_amount" : {
              "commerce_line_item" : [ "commerce_line_item" ],
              "amount" : [ "5oftotal" ],
              "component_name" : "flat_rate_standard",
              "round_mode" : "1"
            }
          }
        ]
      },
      { "ELSE" : [
          { "commerce_line_item_unit_price_amount" : {
              "commerce_line_item" : [ "commerce_line_item" ],
              "amount" : "900",
              "component_name" : "flat_rate_standard",
              "round_mode" : "1"
            }
          }
        ]
      }
    ]
  }
]

} }

  • Did you find a solution to this? – hockey2112 Aug 27 '18 at 16:26
  • @hockey2112 I added an "Add a variable" in action. And use "PHP evaluation " to calculate the total of all line items again. I don't think it's a good way to solve this problem. But I will try to refresh my memory and write a brief instruction if you need. – jmu Aug 28 '18 at 3:51
  • Thanks! I ended up using the Commerce Order Sub-total module: drupal.org/sandbox/joshmiller/2718047 – hockey2112 Aug 29 '18 at 15:27

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.