I have found a problem where if you have a price break at 5-9 products and 9 to unlimited products and then you go and add 5 products then add another 5 products.

The price in the basked is giving the total cost at the price break of 5... instead of the second price break of 9 - unlimited.

Once you refresh the page OR go to basket you get the correct pricing.. but not until you do this.

Is there a work around?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

akosipax’s picture

I am getting the same issue and it can happen when adding to the cart via the add-to-cart button or in the /cart page.

Steps to reproduce in the cart page:
1) Modify quantity of a line item so that it will reach a price break.
Result: The line item's unit price do not get updated. The cart form has to be submitted again to reflect the price change.

It seems to take the previous quantity's price.

If I have the following price table for Product A:

1 : 15.00
2 - 5 - 12.50
6++ - 10.00

And I do the following:

1) Add 1 Product A
Quantity: 1
Result: $ 15
2) Add another 1 Product A
Quantity: 2
Result: $ 30 (should be $25)
3) Add 4 more Product A
Quantity: 6
Result: [12.50 * 6] (where it should be 10 * 6)

It works the same way in the /cart page when I change the quantity of a product there.

akosipax’s picture

Status: Active » Needs review

I figured out what's going on in my scenario. It seems like the rule is being triggered "prematurely"; that is, the rule is triggered when the new quantity is not yet submitted and saved to the line item. Since the new quantity is not yet submitted, the action takes the old quantity when calculating the price.

I added the event "After updating an existing commerce line item" to trigger the rule so that it takes the new quantity. Also, the line item must be manually saved. We can do this without adding any code by adding a "Save Entity" action that passes the line item. Though I think we should not have to manually call "Save Entity" and just save the line item within the rule callback (commerce_price_table.rules.inc:52)

$line_item_wrapper->save()

Tagging as "Needs Review" to see what the maintainer say about saving the line item within the rule callback.

B31’s picture

@akosipax I tried your solution and It seems to work.

This is the patch. If the module is already installed you need to modify the rule.

rszrama’s picture

Category: Support request » Task
Status: Needs review » Needs work

The event should definitely remain the price calculation event, fwiw.