Prestashop: Unable to remove customized product from cart - minimum quantity error

Created on 5 Nov 2019  路  15Comments  路  Source: PrestaShop/PrestaShop

Describe the bug
During testing, I got the store to a situation, where I couldn't delete product from cart. It happened only on my phone and I can't (for now) reproduce it on desktop.

  • When I attempted to delete product from cart or reduce amount to 0, it threw 'You must add %quantity% minimum quantity'.
  • Adding and reducing count above 1 worked OK.
  • Behavior was the same if it was only this product in cart, or I added some another.

Steps to reproduce the issue:

  • Customize a product with a file.
  • Add it to cart.
  • Refresh the page, customize the product again, do not add it to cart.
  • Go to cart, try to remove product. Will not work.
  • After my fix, will work as it should and the logic will count only customized products that ARE in cart.

Possible fix
If we added two more conditions to the query, it should fix it.
in_cart = 1 AND quantity > 0
Another question is, why and how are these entries which are not in_cart and have zero quantity even created?

How it looked (ignore the variables I output to the error)

image0

The code causing the error

code

Database status for given id_cart and id_product

table

Database status for given query

select

Additional information
PrestaShop version: 1.7.6.0
PHP version: 7.2

1.7.5.2 1.7.6.0 1.7.6.1 1.7.6.2 Bug Customized FO Fixed Minor PR available Shopping carts FO

All 15 comments

Hi @Hlavtox,

Thanks for your report.
We have recently fixed two issues in PS1.7.7.0 similar to this problem.

  1. Customized product can't be deleted from the cart reported in this ticket: https://github.com/PrestaShop/PrestaShop/issues/15986 & fixed by this PR: https://github.com/PrestaShop/PrestaShop/pull/15987
  2. Removal of customization makes impossible to remove a product from the cart reported in this ticket: https://github.com/PrestaShop/PrestaShop/issues/15624 fixed by this PR: https://github.com/PrestaShop/PrestaShop/pull/15625

Thanks to check & feedback.

@khouloudbelguith
Hi, none of these PRs seem to be related.

I don't know how the 'corrupted' entries happen, but adding these two restrictions to the query in controllers/front/CartController.php fix the issue. Have a look on it.

CHANGE FROM:
`` /** * This process delete a product from the cart. */ protected function processDeleteProductInCart() { $customization_product = Db::getInstance()->executeS( 'SELECT * FROM' . _DB_PREFIX_ . 'customization' . ' WHEREid_cart= ' . (int) $this->context->cart->id . ' ANDid_product= ' . (int) $this->id_product . ' ANDid_customization` != ' . (int) $this->customization_id
);


CHANGE TO:


   ```
 /**
     * This process delete a product from the cart.
     */
    protected function processDeleteProductInCart()
    {
        $customization_product = Db::getInstance()->executeS(
            'SELECT * FROM `' . _DB_PREFIX_ . 'customization`'
            . ' WHERE `id_cart` = ' . (int) $this->context->cart->id
            . ' AND `id_product` = ' . (int) $this->id_product
            . ' AND `id_customization` != ' . (int) $this->customization_id
            . ' AND `in_cart` = 1'
            . ' AND `quantity` > 0'
        );

@Hlavtox,
Would you be willing to make a pull request on GitHub with your code suggestion?
https://github.com/PrestaShop/PrestaShop/tree/develop
In the meantime, I will try to reproduce the issue:

  1. What is the exact type of customization? Text or file?
  2. Is it required? yes or no?
  3. what is the exact version of the ps_shoppingcart module v2.0.2? or 2.0.3?
  4. Have only one customization or more
  5. The Minimum quantity for this product?

Thank you!

Hi @khouloudbelguith

Customization:

  • File type
  • Optional
  • ps_shopping cart version 2.0.3
  • Only one customization
  • Minimum quantity for all products is 1 (default).

@khouloudbelguith PR with a fix #16574

@Hlavtox, I did not manage to reproduce the issue with PS1.7.6.1 & PS1.7.6.2build1 & ps_shoppingcart v2.0.3
https://drive.google.com/file/d/1CXBDQC057LEs9F7G_Ki--Zg-5vZCID-R/view
Ping @sarahdib, could you please try to reproduce the issue.

Thanks!

@khouloudbelguith @sarahdib

Ladies, try it with a product that has combination, maybe it has something to do with it.

I just played with around with adding and removing customization, removing product from cart, changing quantity and I got it to this situation, where the entries existed (refer to the screenshots of my database.

@khouloudbelguith Managed to reproduce the issue. See the video:

https://drive.google.com/file/d/19SuT5YMueCVa-mG3AI2Bj1_kjB1qyZt8/view?usp=sharing

  • Customize a product with a file.
  • Add it to cart.
  • Refresh the page, customize the product again, do not add it to cart.
  • Go to cart, try to remove product. Will not work.
  • After my fix, will work as it should and the logic will count only customized products that ARE in cart.

Hello @Hlavtox @khouloudbelguith

@Hlavtox Thank you for this precious information.
@khouloudbelguith I manage to reproduce the issue in 1.7.5.2, 1.7.6.2 and develop.

Hi @sarahdib, thank you!

@Hlavtox, thanks for these clarifications.
I鈥檒l add this to the debug roadmap.
Thanks!

@khouloudbelguith @sarahdib You are welcome.

I made a PR ladies, link above. Check it out, get it accepted and we have this solved. Have a nice day! :)

Fixed in #16574

I am running into this problem with a recent site and see that there is a fix with version 1.7.7. Is this version of Presta available?

@birdiesroom You can apply the fix to your current Prestashop, just add these two lines and fixed! :)

9C4DD891-7653-46B2-8402-0553BE1E6044

Was this page helpful?
0 / 5 - 0 ratings