1
Answers
Vote up!
0
Vote down!

Adding Up Quantity

I have a very specific use case for this question, that may or may not be able to be answered here, so bear with me, but I have to figure this out in a few days for a client, so I'm a bit stressed, so bear with me.

I have a client that wanted to add break points in cases order through Drupal Commerce. That was easy enough to accomplish with Commerce Price Table (https://drupal.org/project/commerce_price_table). All the productions have the same price breaks (10-25, 26-75, 75+). All of this is accomplished, and was easier enough to configure. But here is the kicker; They want all the items added to tally up the quantity added to equal all the price breaks. So, say for instance they bought 5 cases of one item, and 5 cases of another, both items would get the 10 case price break.

I somewhat have it working, using rules. I modified the the price table rule that is created when activating the module. The event is set to "Calculating the sell price of a product", my condition is set to the particular product type I have this set on, and here is where is gets messy.

Actions:
I created a loop, created a list of "order:commerce-line-items", gave it a variable of total. Added an action calculating a value using "total:quantity" + "total:quantity" and giving it the variable name mm_total, I did so thinking it would that the loop would just continuously grab the quantity and add to it each pass it made on the item. I then used "replace price for price table", set it to "commerce-line-item", using a quantity value of mm-total. So in theory it checks against the total quantity and sets the price in the appropriate quantity bracket.

Well, it works, it does pull the correct prices based on the total quantity, but here is the weird thing I can't figure out. If the quantity value is lower than an item above it (i.e. item-1 is a quantity of 70, item-2 is a quantity of 60) then it no longer gives any value to quantity at all to get the price breaks. It's as if, at that point, each item has a quantity of 1, even though they don't. If the quantities are switched, it works again. As long at the quantities down the list increase, it works, if they decrease, it breaks. Not sure how to fix this, but I know it has to do with out my actions are setup, I just can't seem to find a different alternative.

If anyone has any advice it would be greatly appreciated. Thank you in advance.

Asked by: Yelldon
on January 30, 2014

1 Answer

Vote up!
0
Vote down!

I actually kind of figured it out the calculating sell price, I did the following:

I added a variable

Created a loop of line item order

-Added a calculate value, added the variable + the loop items:quantity
-Set a data value of the variable = to the calculated result

Outside of the loop, I added the replace the price in price table on the line item, quantity of the variable.

Works like a charm, but now my only issue is that I can't grab only certain items, as it does it for everything in the cart, which won't work. I've added a taxonomy term to sort by, and created a rule set, which would work if it could some how give me access to the variable in the original rule from the . Not sure how to tackle this.

If anyone runs across this and has any suggestions, please let me know. Thank you.

Answer by: Yelldon
Posted: Jan 31, 2014