Prestashop: [1.7.7] $cart_presenter->present($cart, true) - wrong totals

Created on 12 Aug 2020  路  11Comments  路  Source: PrestaShop/PrestaShop

Steps to Reproduce

  1. Make product A with price 100 CZK.
  2. Make product B with price 20 CZK.
  3. Make a cart rule that gives product B as a gift to all orders.
  4. Add product A to cart. You will get product B automatically.
  5. Add product B to cart normally.
  6. Output content of this somewhere on the website.
$presenter = new CartPresenter();
$presented_cart = $presenter->present($this->context->cart, $shouldSeparateGifts = true);

or change 'cart' => $this->cart_presenter->present($this->context->cart), to 'cart' => $this->cart_presenter->present($this->context->cart, true), in classes/controller/FrontController and go to cart.

  1. Totals should be:
    Subtotal: 140 CZK
    Discounts: 20 CZK
    Total: 120 CZK

  2. Totals are:
    Subtotal: 180 CZK
    Discounts: 40 CZK
    Total: 140 CZK

Cause

1. Wrong subtotal - /src/Core/Cart/CartRow - Subtotal is calculated by $rowData['cart_quantity']instead of $rowData['quantity']. Cart_quantity holds total quantity of this product in cart (2), quantity holds the current row amount (1).
2. Wrong discount total - /src/Core/Cart/CartRuleCalculator - Error near if ((int) $cartRule->gift_product) {. The gift gets discounted twice. Why? Because it checks, if the row equals the product in the cart rule. But this condition will be met twice, in both passes, once for the actual gift and once for the normally added product.

I tried to fix it by this PR https://github.com/PrestaShop/PrestaShop/pull/17825, but it broke some tests and I don't have the skills to resolve the issue, nor know if my solution is correct.

Additional information

  • PrestaShop version: 1.7.7 beta release
  • PHP version: 7.2
1.7.6.7 1.7.7.0 Bug Cart rules FO Minor To Do

Most helpful comment

Why closing it so fast ?

When a bug is reported, the QA team attempts to reproduce it. Here it could not be reproduced.

This does not mean the conversation ends there

  • a closed issue can still be discussed
  • if new items are added and the bug can be reproduced we can re-open the issue

"The issue is closed" does not mean "this topic is closed" 馃槃 . Conversation and exploration can continue.

It's simply the only way to keep a backlog manageable. "Open issues" are "things we can act on". Things a developer can pick up and start working on. We cannot act on something we cant reproduce.

There is a lot of issues that are opened but actually do not refer to a bug inside prestashop software. It can come from server configuration, 3rd party theme, 3rd party module, overrides, custom code ... so if we cannot reproduce an issue on a standard environment, unless proved otherwise, we consider it does not come from prestashop software (and we then cannot act on it).

But once again: it does not mean topic is closed. It's just an issue status, that we use to search, filter, classify issues while manageing the backlog.

All 11 comments

Thanks for opening this issue! We will help you to keep its state consistent

Hello,

Capture d鈥檈虂cran 2020-08-13 a虁 10 53 49

It seems that your issue is fixed. I close this issue feel free to open a new one if you reproduce this again.

Thank you!

@sarahdib You did not reproduce it.

Ping @matks @eternoendless

Why closing it so fast ?

@jf-viguier it's part of the normal procedure we use to avoid having too many non reproductible issues open.

That said, looks like there was a mistake when trying to reproduce, we're investigating.

Don't forget $shouldSeparateGifts to true

Why closing it so fast ?

When a bug is reported, the QA team attempts to reproduce it. Here it could not be reproduced.

This does not mean the conversation ends there

  • a closed issue can still be discussed
  • if new items are added and the bug can be reproduced we can re-open the issue

"The issue is closed" does not mean "this topic is closed" 馃槃 . Conversation and exploration can continue.

It's simply the only way to keep a backlog manageable. "Open issues" are "things we can act on". Things a developer can pick up and start working on. We cannot act on something we cant reproduce.

There is a lot of issues that are opened but actually do not refer to a bug inside prestashop software. It can come from server configuration, 3rd party theme, 3rd party module, overrides, custom code ... so if we cannot reproduce an issue on a standard environment, unless proved otherwise, we consider it does not come from prestashop software (and we then cannot act on it).

But once again: it does not mean topic is closed. It's just an issue status, that we use to search, filter, classify issues while manageing the backlog.

@Hlavtox sorry I check with a member of the core team :)

I managed to reproduce this issue on 1.7.7, using the same values as @Hlavtox :

Capture d鈥檈虂cran 2020-08-13 a虁 11 38 09

@sarahdib the same issue exists on 1.7.6, it's not a 1.7.7 regression.

Was this page helpful?
0 / 5 - 0 ratings