Hello,

I need help to make a specific rule !

In my shop, there are static shipping costs by quantity parts. In example : If I buy between 1 and 12 units, shipping cost is 12€, if I buy between 12 and 24 units, shipping cost is 18€ ... For that, no problems !

But if I buy more than 72 units, shipping costs are no more statics, I have to apply a cost by unit. In example : If I buy 80 units, shipping cost is 80*0.3468€ (0.3468€ by unit). I can't make this rule because I can't access to "total product quantity" value in the action "Set the unit price to a specific amount"...

Any ideas about how to make this rule, how to access this value ?

Thanks a lot,

Best regards.

Comments

MarcElbichon’s picture

Can't you use site:current-cart-order:commerce-order-quantity data selector ?
Can you post your rule with static costs ? I'd like to see how you deal with line items.

Mantalo Conseil’s picture

Hello,

Thanks for your answer.
I can't find this data selector in the action "Set the unit price to a specific amount"...
This is the rule :

{ "rules_prix_par_zone_5_24" : {
    "LABEL" : "Prix par zone 5-24",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "commerce_order", "commerce_line_item", "commerce_shipping" ],
    "ON" : { "commerce_shipping_calculate_rate" : [] },
    "IF" : [
      { "data_is" : { "data" : [ "commerce-line-item:type" ], "value" : "shipping" } },
      { "data_is" : {
          "data" : [ "commerce-line-item:commerce-shipping-service" ],
          "value" : "livraison_domicile_2"
        }
      },
      { "entity_has_field" : {
          "entity" : [ "commerce-line-item:order" ],
          "field" : "commerce_customer_shipping"
        }
      },
      { "OR" : [
          { "commerce_order_compare_address" : {
              "commerce_order" : [ "commerce-line-item:order" ],
              "address_field" : "commerce_customer_shipping|commerce_customer_address",
              "address_component" : "postal_code",
              "operator" : "begins with",
              "value" : "75"
            }
          },
          { "commerce_order_compare_address" : {
              "commerce_order" : [ "commerce-line-item:order" ],
              "address_field" : "commerce_customer_shipping|commerce_customer_address",
              "address_component" : "postal_code",
              "operator" : "begins with",
              "value" : "77"
            }
          },
          { "commerce_order_compare_address" : {
              "commerce_order" : [ "commerce-line-item:order" ],
              "address_field" : "commerce_customer_shipping|commerce_customer_address",
              "address_component" : "postal_code",
              "operator" : "begins with",
              "value" : "78"
            }
          },
          { "commerce_order_compare_address" : {
              "commerce_order" : [ "commerce-line-item:order" ],
              "address_field" : "commerce_customer_shipping|commerce_customer_address",
              "address_component" : "postal_code",
              "operator" : "begins with",
              "value" : "91"
            }
          },
          { "commerce_order_compare_address" : {
              "commerce_order" : [ "commerce-line-item:order" ],
              "address_field" : "commerce_customer_shipping|commerce_customer_address",
              "address_component" : "postal_code",
              "operator" : "begins with",
              "value" : "92"
            }
          },
          { "commerce_order_compare_address" : {
              "commerce_order" : [ "commerce-line-item:order" ],
              "address_field" : "commerce_customer_shipping|commerce_customer_address",
              "address_component" : "postal_code",
              "operator" : "begins with",
              "value" : "93"
            }
          },
          { "commerce_order_compare_address" : {
              "commerce_order" : [ "commerce-line-item:order" ],
              "address_field" : "commerce_customer_shipping|commerce_customer_address",
              "address_component" : "postal_code",
              "operator" : "begins with",
              "value" : "94"
            }
          },
          { "commerce_order_compare_address" : {
              "commerce_order" : [ "commerce-line-item:order" ],
              "address_field" : "commerce_customer_shipping|commerce_customer_address",
              "address_component" : "postal_code",
              "operator" : "begins with",
              "value" : "95"
            }
          }
        ]
      },
      { "commerce_order_compare_total_product_quantity" : {
          "commerce_order" : [ "commerce-line-item:order" ],
          "operator" : "\u003E",
          "value" : "12"
        }
      },
      { "commerce_order_compare_total_product_quantity" : {
          "commerce_order" : [ "commerce-line-item:order" ],
          "operator" : "\u003C=",
          "value" : "24"
        }
      }
    ],
    "DO" : [
      { "commerce_line_item_unit_price_amount" : {
          "commerce_line_item" : [ "commerce-line-item" ],
          "amount" : "2226",
          "component_name" : "flat_rate_livraison_domicile_2",
          "round_mode" : "0"
        }
      }
    ]
  }
}

Maybe it's impossible to make it by rules, I'm thinking about use an Hook or something else in PHP ...

Thanks for your help !

MarcElbichon’s picture

Status: Active » Closed (cannot reproduce)

I think you can't. Maybe can you ask for a feature to commerce_shipping module.
Sorry, but I cannot be helpful for you. Closing this issue