I have a term reference field in product called "Weight" with values "Light", "Medium" & "heavy". I am using flat rate shipping service and trying to check the value of "Weight" field in Calculation rules.I know that I need to expose it by using "entity has field" but I end up having


I was able to get to the weight field by using any of them and then did a Data Comparison


this condition worked ok first time but not after that. can anyone please help me on this or if you think of another solution please let me know. Thanks

Config screenshot


What you can do is loop through the line items and each line item is passed through a rule component where you can check the line item's weight. If you want to get the shipping fee for line item, you would need to set a rule set component. If you just want the component to provide the weight of the line item, a rule component will do.

I am not sure what you are trying to achieve with the rule or how your flat rate shipping works. Are you looking for the heaviest weight present in the order and apply to the order the shipping fee of that weight? Or does the fee accumulate according to how many line items and their weight? Regardless of how your shipping rate works, it's still the same concept: Loop through the line items. Pass the line item to a rule component that checks the weight of the line item.

The rule will look like this (assuming your shipping condition is: if product is light - add 0.25$ to shipping fee, 0.5$ for medium, and 1$ for heavy.)


  /* ACTIONS*/
  // Add a variable: total_shipping_fee; set to 0.
  // Loop through line items
     // For each line item, trigger get_shipping_fee component passing line item and providing the prod_shipping_fee for the product
     //  Calculate value: total_shipping_fee + prod_shipping_fee
  // Set shipping fee to total_shipping_fee

For the rule set component: (get_shipping_fee), create three rules that checks the weight of the product; each rule returning or providing the shipping fee. For instance:

Parameter: line_item
Provided: shipping_fee

// If product is light

// Set shipping_fee to 0.25$

The provided variable or variable returned by the rule component depends on how your flat rate shipping works. Also, you might need to pass another variable to the rule component.

Also, if you're new to drupal and rules, you can read the documentation to make it easier for you.

Hopefully, this will give you ideas to the actual solution of your problem.

| improve this answer | |
  • Hi Pax. sorry I am pretty new to drupal. how would i loop through line items in the conditions? loop is only available in actions. thanks – Waqas Sep 17 '13 at 10:09
  • You can't. That's why you have to make a rule component passing the line item and that rule component will do the checking or have conditions. I'll add a "pseudo-rule" in my answer. If you let me know what shipping condition and action that you're trying to achieve, I can make a more accurate "pseudo-rule". – Pax Sep 17 '13 at 14:37

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.