Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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?
Comment | File | Size | Author |
---|---|---|---|
#3 | commerce_price_table-cart_refresh-2349617-3.patch | 1.42 KB | B31 |
Comments
Comment #1
akosipax CreditAttribution: akosipax commentedI 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.
Comment #2
akosipax CreditAttribution: akosipax commentedI 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.
Comment #3
B31 CreditAttribution: B31 commented@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.
Comment #4
rszrama CreditAttribution: rszrama commentedThe event should definitely remain the price calculation event, fwiw.