I am trying to define two shipping services - standard and express shipping - and combine these with calculation rules that depend on the quantity of the products. For example, I'd like to have 1 USD added for each product when using standard shipping, and 2 USD added for each product when using express shipping. However, it seems that regardless of the shipping service chosen, the calculation rules are fired and the shipping rates are using 1USD+2USD x product.

I've done the following:

  • Created two shipping services, one Standard, the other Express, both with a base rate of 0 USD
  • I've added two calculation rules (as shown here: http://www.commerceguys.com/resources/articles/249): one that adds 1USD per product, the other that adds 2USD per product
  • Now, I need to say "use calculation rule 1 only if standard shipping has been selected" and "use calculation rule 2 for express shipping". I don't really know how though. I've tried "shipping line item exists" and select it to be either of type standard of express, but still both rules are fired.

Any idea of how to do this?

Comments

pvhee’s picture

Status: Active » Closed (works as designed)

The trick here is twofold:

  • in the Calculation Rule, you need to add the condition "Entity has field: commerce_shipping_service" to bring the shipping service into scope, and then use "Data comparison: commerce_shipping_service equals standard or express or ... shipping service". This allows you to create different calculation rules for different shipping services.
  • When you have selected a shipping service, you add a line item to the order. However, if you go back from the review pane, you will see that the price of your shipping service has augmented! This is because you count the number of products + the shipping line item. To solve this, you need to discard any line items that are not products. That is a tricky thing however since you cannot directly add conditions within the loop. You need to add a new component that checks whether the line item has a field Commerce Product, and then calculate a value. You then need to pass this value as a provided argument via "set data value", and catch a within the loop and use it to add an extra amount to a commerce line item. Uff, this is not easy, but it is all logical after all.
guguss’s picture

Hi pvhee ^^

I am still wondering why the condition Shipping line item exists can't be used instead of the
Entity has field: commerce_shipping_service following by the Data comparison: commerce_shipping_service.

To add fee for a specific shipping service, I guess the shipping line item already exists so then the fee can be applied. I don't understand why the 2 conditions must be checked ?

Thanks,

Augustin

bessone’s picture

+1

mhalvaei’s picture

Issue summary: View changes

@pvhee , Thank you! Much appreciated.

mark_fullmer’s picture

+1 works!