Accessing product line items in shipping calculation (solved)
Hi there!
I have a scenario where I have to set up a rule that pick one of two base shipping flat rates depending on the type of product in the cart - if type A is present, base rate 1 is used, but if A's and B's are present, base rate 2 is used.
I then need to add an additional fee per item based on it being A or B to the total (I think I can manage most of this using Randy's now famous tutorial)
But all my problems seem to stem from the fact I can't reach the orders product line items in conditions - only specific line item slots (:0, :1 etc)
I've been battling this for days now, and have looked for similar issues/tutorials without luck. If anyone can give some guidence I would appreciate it :)
Best.
-------------------
Solution:
1) I created a component rule to work out the total for items of a particular type (two rules, as I have two types).
2) I call these rules in a loop on the shipping calculation.
cheaper items have smaller base rate, and only items 2+ are charged an additional rate:
1) I used 'product has taxonomy' (through extra module) to condition the shipping rule to only act when there are NO items of type 2.
2) I added a base shipping rate for items of type 1
3) I 'calculated a value' of total qty of cheaper items - 1
4) multiplied the result by the additional rate (100)
if only type 2 items or a mixture of types exist, the more expensive base rate and additional rates are used:
1) I used 'product has taxonomy' (through extra module) to condition the shipping rule to only act when there INCLUDE items of type 2.
2) I added a base shipping rate for items of type 2
3) I 'calculated a value' of total qty of more expensive items - 1
4) multiplied the result by the additional rate (200)
5) I 'calculated a value' of total qty of cheaper items
6) multiplied the result by the additional rate (100)
so - if any expensive items exist in the order, the more expensive base rate is used, ALL cheap items are treated as 'additional' (and add a rate) but the first of expensive items isn't charged extra (if there is only 1 expensive item, only the base rate is used)
I really hope this helps someone! shame about all the spammers on this site :(
Thanks for the module commerce guys!
Comments
(solved - see original post)