Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minimum qty input on products listing and product detail pages #609

Merged
merged 1 commit into from
Apr 18, 2024

Conversation

boherm
Copy link
Member

@boherm boherm commented Mar 14, 2024

Questions Answers
Description? With this PR, when you add a product with a minimal quantity to your cart, the product quantity should be updated in the quantity input of the product. This is for all products listing pages, product quick view and also product detail page.
Type? bug fix
BC breaks? no
Deprecations? no
Fixed ticket? Fixes #608 (related to #600)
Sponsor company PrestaShop SA
How to test? 0. Don't forget to rebuild the theme before!
1. Set a minimal quantity for ordering a product in BO.
2. Then go to the FO and search your product in categories pages, and see the value displayed in the quantity input.
3. After added to the cart, you must have "1" in the quantity input instead of the minimal quantity required to put the product on your cart.

@boherm boherm added this to the Beta milestone Mar 14, 2024
M0rgan01
M0rgan01 previously approved these changes Mar 18, 2024
Copy link

@florine2623 florine2623 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @boherm ,

Tested with all types of products.

Works well for standard and virtual products ! ✅

On a product with combination, it doesn't work as expected.
In the FO, the quantity minimum is always 1. There's an alert to tell the customer that there's a minimum quantity. ❌

Screen.Recording.2024-03-19.at.10.23.08.mov

Doesn't work on Pack product. ❌
In the FO, the quantity is always the minimum quantity. After adding the product to my cart, the quantity is not updated.

Screen.Recording.2024-03-19.at.10.26.14.mov

When I deleted the products in the cart and go back to category page, the minimum quantity is not updated directly. I have to add the product through my quickview page or
refresh again the page. ❌

Screen.Recording.2024-03-19.at.10.32.07.mov

Could you check ? ^^
Thanks!

"value"=>"{if $product.cart_quantity && $product.cart_quantity >= $product.minimal_quantity}1{else}{$product.minimal_quantity}{/if}",
"min"=>"{if $product.cart_quantity && $product.cart_quantity >= $product.minimal_quantity}1{else}{$product.minimal_quantity}{/if}"
"id" => "quantity_wanted_{$product.id_product}",
"value" => "1",
Copy link
Contributor

@SharakPL SharakPL Mar 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why you fixed the value to 1 instead of using $product.minimal_quantity. The same in other file.
Previous value was correct:

{if $product.cart_quantity && $product.cart_quantity >= $product.minimal_quantity}1{else}{$product.minimal_quantity}{/if}

The same conditions should be used to update min attribute:

  1. Let's say minimal_quantity is 10. If none of this product is in the cart yet then min should also be 10
  2. I add 10 to the cart, minimum requirements are met so the min should change to 1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this, it's an issue with the data in cache before template generation.
The cart_quantity, that must be unique by users, is in cache too and for everybody! With your solution, if we do a cache:clear at any time, it's working well.
So yeah, it's a core issue, but force to 1 and add some javascript can do the trick as long as we fix this cache issue in the core.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In all cases, this isn't a fault to cache the product list 🤷‍♂️
But the cart_quantity don't be cached in a global state.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it's seems not enough.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the cache problem, but then shouldn't the default value be {$product.minimal_quantity} It doesn't seem logic to have a value always to 1 when the min attribute under can be higher no?

It would mean the default cached page would use the min quantity for everyone and then your JS update handles updating/reducing it when relevant no?

@boherm boherm force-pushed the fix-min-qty-input branch 2 times, most recently from 5fcb7e9 to 2ebe2a7 Compare March 28, 2024 08:47
@SharakPL
Copy link
Contributor

IMO it would be better to use a different approach. Keep min exactly as it is set in product configuration and if the current product combination is already in the cart then the value should be updated to its amount in the cart and instead of theAdd to cart button there would be Update cart. It would make all calculations obsolete. Just get the product config and its amount in the cart.

@boherm
Copy link
Member Author

boherm commented Apr 3, 2024

Thanks for your comment @SharakPL, your approach with Update cart instead of Add to cart button seems cool, but I think that is a "feature" that need to be discuss together with @PrestaShop/product-council. I don't know if they had this possibility in mind.

Copy link

@florine2623 florine2623 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @boherm ,

Tested on branch develop on PS.

Tested on Product details page, Category related page, Homepage, Quickview and Search page.
Tested for standard product ✅ , combination ❌ , virtual ❌, pack ❌, product with custom 🤷 .

The minimal quantity is always the same on the Product Details page for Combination, pack and virtual ❌
On other pages, it works as expected ✅

  • Pack
Screen.Recording.2024-04-03.at.15.56.33.mov
  • Combination
Screen.Recording.2024-04-03.at.15.59.29.mov
  • Virtual
Screen.Recording.2024-04-03.at.16.07.59.mov
  • For customized product, it doesn't work either, but I think that's a wanted behavior as the Customization might not be checked. So we can't know if if have 3 of the same product.
    The issue is that I can't have 2 custom product with custom XX, and 1 other custom product with custom YY.
    I guess that for @PrestaShop/product-council to decide ^^
Screen.Recording.2024-04-03.at.16.10.55.mov

Thanks !
Waiting for your feedback !

@boherm
Copy link
Member Author

boherm commented Apr 10, 2024

Thanks @florine2623 for your message!
After some tests, I have totally the same behaviour on my side.
But, they are not related to HB theme, and we have the same problems on classic theme.

In fact, this is a problem with the core here and after a small talk with @jolelievre, this could be fix in another PR and directly on the core side.

What do you think? 🤔

@florine2623
Copy link

Hello @boherm and @jolelievre ,

Ok for me to get it fixed on the core directly ^^
I'll let you decide on what to do with this PR ! I'll take off the Waiting for QA label.

Thanks!

"value"=>"{if $product.cart_quantity && $product.cart_quantity >= $product.minimal_quantity}1{else}{$product.minimal_quantity}{/if}",
"min"=>"{if $product.cart_quantity && $product.cart_quantity >= $product.minimal_quantity}1{else}{$product.minimal_quantity}{/if}"
"id" => "quantity_wanted_{$product.id_product}",
"value" => "1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the cache problem, but then shouldn't the default value be {$product.minimal_quantity} It doesn't seem logic to have a value always to 1 when the min attribute under can be higher no?

It would mean the default cached page would use the min quantity for everyone and then your JS update handles updating/reducing it when relevant no?

"value"=>"{if $product.quantity_wanted}{$product.quantity_wanted}{else}1{/if}",
"min"=>"{if $product.quantity_wanted}{$product.minimal_quantity}{else}1{/if}"
"id" => "quantity_wanted",
"value" => "1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"value" => "1",
"value" => "{$product.minimal_quantity}",

Same question why not use the min quantity for both min and value attributes?

@nicosomb nicosomb merged commit 3186a65 into PrestaShop:develop Apr 18, 2024
6 checks passed
@boherm boherm deleted the fix-min-qty-input branch June 13, 2024 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

The Min quantity config is always preselected regardless of the quantity in the cart
8 participants