Prestashop: Cart > getSpecificPrice called with shop group id rather than customer group id

Created on 7 May 2019  Â·  6Comments  Â·  Source: PrestaShop/PrestaShop

Describe the bug
I upgraded from 1.6.0.11 to 1.6.1.24
In the cart, reduction is shown in amount instead of percentage.

Debugging, I suspect the bug is due to the line 585 in classes/Cart.php :
SpecificPrice::getSpecificPrice( ... (6 parameters), $this->id_shop_group, ...)
But looking at the definition of this method :
public static function getSpecificPrice(... (6 parameters), $id_group, ...)

In other words : the method is asking for a (customer) group id, and a shop_group id is given instead.

(Consequence :

  • no specific price is found
  • so reduction_type is set to 0
  • so, in the template, the test '== amount' is valuated as true
  • so, the reduction is shown in amount
    )

To Reproduce
I didn't try to reduce the case to a reproductible one, but following steps should be sufficient :

  • start from a default mono-shop installation of Prestashop 1.6.1.24, with only one shop group whose id is 1
  • create a customer group TEST (whose id is > 1)
  • create a customer FOO, and put him in this group
  • for a product BAR, create a specific price (-10%) for this group
  • log in as FOO, add BAR in your cart
  • go to cart
  • expected : the reduction is shown in percentage (as in Prestashop 1.6.0.x)
  • observed : the reduction is shown in amount

This line has been introduced by the following commit :
https://github.com/PrestaShop/PrestaShop/commit/20b7c28f188560f2ccc243d77aae3b6ce339bd05 − Optimize Cart::getProducts performances & factorize some queries by @jocel1

All suggestions to correct this bug are welcome.

Test in Prestashop 1.7 are also welcome.

PrestaShop version: 1.6.1.24
PHP version: 5.6

1.6.1.24 1.7.5.2 1.7.6.0 Bug CO Minor To Do

All 6 comments

Hi @Yopai,

I did not manage to reproduce the issue with PS1.7.5.2.
image
As you may already know, normal maintenance support for PrestaShop 1.6 ended in October 2018, which is now in extended maintenance mode until June 30, 2019.

During this period, and in order to ensure the stability of current 1.6 shops, only critical bugs and security fixes will be fixed.
Thanks for your understanding!

hi @khouloudbelguith , I've just took a look at the code, and @Yopai is right, the wrong variable is used in the code :)

I mean, even in 1.7 code ;)

If I've all understood correctly, it's more than just a variable : a customer can have multiple groups. So either getSpecificPrice must be extended to allow an array of groups ids, or you have to loop over it for each customer group. Moreover, you have to ensure the specific price that is retrieved is the same that the one applied by the method computing the price (in case there are multiple specific prices for different groups)

It may be worth creating a reproducible case in 1.7 and reopen the bug (or open a new one), then, isn't it ?

@jocel1, thanks for your feedback.
Yes, I found the issue.
$id_group is used https://github.com/PrestaShop/PrestaShop/blob/aec97ddb1551fd7d6d56f75549a992d6937caf50/classes/SpecificPrice.php#L488
but in the cart class, id_shop_group is used instead of id_group
https://github.com/PrestaShop/PrestaShop/blob/1.7.5.2/classes/Cart.php#L754

I’ll add this to the debug roadmap so that it’s fixed.
@Yopai, If you have already fixed it on your end or if you think you can do it, please do send us a pull request!
Thanks!

Thanks for your interest

If I had fixed it cleanly, I would have been pleased to send a pull request.
Unfortunately, as :

  • I was only upgrading an old 1.6,
  • The bug was just a misrepresentation of the reduction,
  • This shop only has specific prices in percentages,
  • I've got not as many time I would like to do thinks cleanly,
    I was just told to do it the hacky way : remove the test in the .tpl file :)
Was this page helpful?
0 / 5 - 0 ratings