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

Can't add grouped product, with out of stock sub product, to cart #12970

Closed
kvydiuk opened this issue Jan 3, 2018 · 28 comments
Closed

Can't add grouped product, with out of stock sub product, to cart #12970

kvydiuk opened this issue Jan 3, 2018 · 28 comments
Labels
Component: GroupedProduct Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release

Comments

@kvydiuk
Copy link

kvydiuk commented Jan 3, 2018

When "Stores -> Configuration -> Catalog -> Inventory -> Options -> Display Out of Stock Products" config enabled.
Can't add grouped product, which haves out of stock sub product, to cart.

Preconditions

  1. Magento 2.1.8 CE/EE
  2. nginx/1.10.3
  3. Ver 15.1 Distrib 10.0.31-MariaDB
  4. PHP 7.0.22-0ubuntu0.16.04.1

Steps to reproduce

  1. Create grouped product with one out of stock sub product
  2. Set default sub products quantities biggest then "0"
    http://pix.toile-libre.org/upload/original/1514981790.png
  3. Set "Stores -> Configuration -> Catalog -> Inventory -> Options -> Display Out of Stock Products" to "Yes"
  4. Go to grouped product PDP
  5. Add product to cart

Expected result

  1. Sub products which are "In stock" is added to cart

Actual result

  1. No one product added to cart:
    http://pix.toile-libre.org/upload/original/1514981851.png
@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Jan 3, 2018
@kvydiuk kvydiuk changed the title Can't add grouped product, which haves out of stock sub product, to cart Can't add grouped product, with out of stock sub product, to cart Jan 3, 2018
@magento-engcom-team magento-engcom-team added the Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed label Jan 4, 2018
@magento-engcom-team
Copy link
Contributor

@breg-13, thank you for your report.
We've created internal ticket(s) MAGETWO-86389 to track progress on the issue.

@magento-engcom-team magento-engcom-team added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Jan 5, 2018
@p-bystritsky p-bystritsky self-assigned this Jan 5, 2018
@ashvinimarwal
Copy link

Facing the same issue.
Let me know what is the quick fix for this issue.

@adamlavery
Copy link

This issue can be resolved by setting the grouped product Manage Stock = No.

@magento-engcom-team, should grouped products be fixed to manage_stock=no? The grouped product is just a display container. There should never be any stock of the container to manage.

@CompactCodeEU
Copy link

I am having the same issue. When there is 1 assoc product with no stock then it just returns 'please specify quantities of product(s)"

@magento-engcom-team
Copy link
Contributor

Hi @breg-13. Thank you for your report.
The issue has been fixed in magento-engcom/magento2ce#1169 by @p-bystritsky in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming 2.2.8 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Nov 6, 2018
p-bystritsky added a commit to p-bystritsky/magento2 that referenced this issue Nov 7, 2018
@magento-engcom-team magento-engcom-team added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Nov 16, 2018
@magento-engcom-team
Copy link
Contributor

Hi @kirillvidyuk. Thank you for your report.
The issue has been fixed in magento-engcom/magento2ce#2315 by @p-bystritsky in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.1 release.

@bart42functions
Copy link

Hi,

It is still not working in version 2.3.1.
Line 347 of app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php
if ($isStrictProcessMode && !$subProduct->getQty()) { return __('Please specify the quantity of product(s).')->render(); }
will still throw an error. Removing it seems to work tho

@stephan-cream
Copy link
Contributor

stephan-cream commented Jun 18, 2019

This issue has not been resolved yet.

Preconditions
Magento 2.1.* , 2.2., 2.3. CE/EE
DB: Any
PHP: Any

Steps to reproduce:

  1. Create a grouped product
  2. Create two simple products
  3. Add two simple sub-products to the grouped product
  4. Set default quantity to 0 for each simple product association.
  5. Give sub-product 1 a stock quantity of 0 and the status 'Out of stock'.
  6. Give sub-product 2 a stock quantity of 10 and the status 'In stock'.
  7. Configure "Stores -> Configuration -> Catalog -> Inventory -> Options -> Display Out of Stock Products" to 'Yes'.
  8. (Optionally) Reindex inventory and flat tables.
  9. Go to the grouped product's detail page.
  10. Attempt to add sub-product 2 (which has stock).

Expected result:

  • Grouped product with sub-product 2 is added to the cart.
  • No errors occur.

Actual result:

  • Error is thrown "Please specify the quantity of product(s)." through the message manager
  • Grouped product with sub-product 2 is not added to the cart.

What i don't understand is why if ($isStrictProcessMode && !$subProduct->getQty()) is there.
If you don't have a default quantity, which is used to determine how many of the sub-product should be added or if it is set to 0, it should just ignore the sub-product in the first place.
The code beyond this if statement is NEVER reached as the Magento\Quote\Model\Quote function addProduct function always uses \Magento\Catalog\Model\Product\Type\AbstractType::PROCESS_MODE_FULL which results in $isStrictProcessMode === true.
Seeing as we set the default quantity to 0, it results in !$subProduct->getQty() === true.

There are two possible solutions:

  1. Remove the if statement altogether, however this would break backwards compatibility as $isStrictProcessMode would no longer be used and would need to be removed from the function parameters and the calls made to the function.
  2. Instead of !$subProduct->getQty() use (!is_numeric($subProduct->getQty()) || $subProduct->getQty() < 0), since 0 is still a valid default quantity.
    So you would get if ($isStrictProcessMode && (!is_numeric($subProduct->getQty()) || $subProduct->getQty() < 0)) {.

@stephan-cream stephan-cream reopened this Jun 18, 2019
@ghost ghost removed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Jun 18, 2019
@engcom-Charlie engcom-Charlie self-assigned this Jun 18, 2019
@m2-assistant
Copy link

m2-assistant bot commented Jun 18, 2019

Hi @engcom-Charlie. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • 6. Add label Issue: Confirmed once verification is complete.

  • 7. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-Charlie engcom-Charlie added Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Component: GroupedProduct Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed and removed Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line labels Jun 18, 2019
@ghost ghost unassigned engcom-Charlie Jun 18, 2019
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @engcom-Charlie
Thank you for verifying the issue. Based on the provided information internal tickets MC-17572, MC-17573 were created

Issue Available: @engcom-Charlie, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@magento-engcom-team magento-engcom-team added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Jun 18, 2019
@stephan-cream
Copy link
Contributor

I forgot to mention this by the way, but the error is thrown because of the 'Out of stock' product.
Since it is out of stock, the input field for this out of stock product is not submitted (or even shown).
As such the following if statement returns true (!isset($productsInfo[$subProduct->getId()]).
This does not occur when there are only 'In stock' products and the default quantity is set to 0 on the sub-product associations.

@magento-engcom-team
Copy link
Contributor

Hi @kirillvidyuk.

Thank you for your report and collaboration!

The related internal Jira ticket MC-17573 was closed as non-reproducible in 2.3-develop.
It means that Magento team either unable to reproduce this issue using provided Steps to Reproduce from the Description section on clean Magento instance or the issue has been already fixed in the scope of other tasks.

But if you still run into this problem please update or provide additional information/steps/preconditions in the Description section and reopen this issue.

@magento-engcom-team magento-engcom-team added Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch and removed Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Jun 28, 2019
@romeof1980
Copy link

romeof1980 commented Jun 8, 2022

We can confirm this issue has not been resolved yet.

Preconditions
Magento 2.4.3-p1 CE
PHP: 7.4.27

Steps to reproduce:
Create a grouped product
Create a few simple products
Add two or more simple sub-products to the grouped product
(In the grouped) Set "default quantity to 0 for each simple product association.
Give sub-product 1 a stock quantity of 0 and the status 'Out of stock'.
Give sub-product 2 a stock quantity of 10 and the status 'In stock'.
Configure "Stores -> Configuration -> Catalog -> Inventory -> Stock Options -> Display Out of Stock Products" to 'Yes'.
(Optionally) Reindex inventory and flat tables.
Go to the grouped product's detail page.
Attempt to add sub-product 2 (which has stock).

Expected result:
Grouped product with sub-product 2 is added to the cart.
No errors occur.

Actual result:
Error is thrown "Please specify the quantity of product(s)." through the message manager
Grouped product with sub-product 2 is not added to the cart.

Citing #12970 (comment) thanks @stephan-cream
same for me after debugging:
What i don't understand is why if ($isStrictProcessMode && !$subProduct->getQty()) is there.
If you don't have a default quantity, which is used to determine how many of the sub-product should be added or if it is set to 0, it should just ignore the sub-product in the first place.
The code beyond this if statement is NEVER reached as the Magento\Quote\Model\Quote function addProduct function always uses \Magento\Catalog\Model\Product\Type\AbstractType::PROCESS_MODE_FULL which results in $isStrictProcessMode === true.
Seeing as we set the default quantity to 0, it results in !$subProduct->getQty() === true.
There are two possible solutions:
Remove the if statement altogether, however this would break backwards compatibility as $isStrictProcessMode would no longer be used and would need to be removed from the function parameters and the calls made to the function.
Instead of !$subProduct->getQty() use (!is_numeric($subProduct->getQty()) || $subProduct->getQty() < 0), since 0 is still a valid default quantity.
So you would get if ($isStrictProcessMode && (!is_numeric($subProduct->getQty()) || $subProduct->getQty() < 0)) {.


For now I'm going with if ($isStrictProcessMode && (!is_numeric($subProduct->getQty()) || $subProduct->getQty() < 0) && $subProduct->isSalable()) { and can confirm the fix works

@romeof1980
Copy link

@magento give me 2.4-develop instance

@magento-deployment-service
Copy link

Hi @romeof1980. Thank you for your request. I'm working on Magento instance for you.

@magento-deployment-service
Copy link

Hi @romeof1980, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.

@romeof1980
Copy link

@magento give me 2.4-develop instance

@magento-deployment-service
Copy link

Hi @romeof1980. Thank you for your request. I'm working on Magento instance for you.

@magento-deployment-service
Copy link

Hi @romeof1980, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.

@romeof1980
Copy link

@magento give me 2.4.3 instance

@magento-deployment-service
Copy link

Hi @romeof1980. Thank you for your request. I'm working on Magento instance for you.

@magento-deployment-service
Copy link

@romeof1980
Copy link

romeof1980 commented Jun 9, 2022

how weird I can't reproduce this. I really can't understand how the clean 2.4.3 can add due to the following:
!$subProduct->getQty() how can the 2.4.3 instance bypass this if I add only 1 of the grouped-associated and the other has got qty=zero in the selector but is salable?
need more debug

@romeof1980
Copy link

@magento give me 2.4.3-p1 instance

@magento-deployment-service
Copy link

Hi @romeof1980. Thank you for your request. I'm working on Magento instance for you.

@magento-deployment-service
Copy link

Hi @romeof1980, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.

@romeof1980
Copy link

romeof1980 commented Jun 9, 2022

ok not able to reproduce on vanilla 2.4.3. Not a bug.
Just for reference: reproduced on custom installations where an AFTER plugin returns true/false listening on Magento\Catalog\Model\Product->isSalable
this is why it enters the return error warning message in the following snippet:

 if (!isset($productsInfo[$subProduct->getId()])) {
                if ($isStrictProcessMode && !$subProduct->getQty() && $subProduct->isSalable()) {
                    return __('Please specify the quantity of product(s).')->render();
                }

this is how it works:
$productsInfo[$subProduct->getId()]
this excludes from the check all the grouped (associated) products that are in the addtocart POST request i.e. in $productsInfo (even the products with qty==0 are present in the array. They will be considered correctly with qty-to-be-added==0)

&& $subProduct->isSalable()
this will NEVER be checked against products that have the quantity field in the list (no matter if at zero): only against products that are not available in the list (in vanilla they appear in the frontend grouped list as "out of stock" products).

another possibility is that if you have an implementation with js table pagination: only the product in the first page (and only if first page is current page when you add to cart) are considered in the add to cart POST request. If you have a product in stock in the other pages it throw the same error

@sdouma
Copy link

sdouma commented Aug 23, 2022

@romeof1980 thanks for going that deep. It is appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: GroupedProduct Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release
Projects
None yet
Development

No branches or pull requests

10 participants