magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.5k stars 9.3k forks source link

Still shows Add to cart even if salable quantity is 0 #33819

Closed chequille closed 2 months ago

chequille commented 3 years ago

Preconditions (*)

  1. Magento 2.4.3

Steps to reproduce (*)

  1. Set "Display out of stock products" to Yes
  2. Place order with a product so salable qty is going to 0

Expected result (*)

  1. After placing order, add to cart should not be displayed anymore for product qith salable quantity 0

Actual result (*)

  1. Add to cart button is still shown

Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

nkajic commented 3 years ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 3 years ago

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

magento-deployment-service[bot] commented 3 years ago

Hi @nkajic, here is your Magento Instance: https://5101128433fb0b25d09163620dddf00d-2-4-develop.instances.magento-community.engineering Admin access: https://5101128433fb0b25d09163620dddf00d-2-4-develop.instances.magento-community.engineering/admin_d7c7 Login: cd346733 Password: b02b731c9ea6

tgreeve commented 2 years ago

@engcom-Echo @engcom-November @chequille

I found a reliable way to reproduce this issue in a fresh installed magento version 2.4.3-p1.

There should be a magento process listening to queue "inventory.reservations.updateSalabilityStatus" to mark the product out-of-stock in storefront (storefront-out-of-stock). When the process is running, the product will be marked as out-of-stock automatically when salable quantity reached zero.

You can find the process by top or ps command, the command is

/usr/local/bin/php /var/www/html/bin/magento queue:consumers:start inventory.reservations.updateSalabilityStatus --single-thread --max-messages=10000

Killing the process or the process isn't running, the product will not be marked as out-of-stock.

Hope this help.

tgreeve commented 2 years ago

After code review, storefront product Out of Stock status depends on 2 database columns when using Default Stock.

  1. cataloginventory_stock_item => is_in_stock
  2. cataloginventory_stock_status => stock_status

Number 2 defines the storefront behavior, so whenever this value is set to 0, the storefront will show the product as out of stock. Number 1 is the DB representation of the product "Stock Status" everyone see on the CMS product configuration page.

So consider the following situation:

When the last item of the product is sold, MQ consumer process the message in queue "inventory.reservations.updateSalabilityStatus" and set Number 2 to 0, thus storefront of the product will show Out of Stock.

(This should be expected scenario in the development team so far.)

But, when Stock indexer is triggered and Number 1 should be 1, Stock indexer will sync the 1 value in Number 1 to Number 2, thus the storefront Out of Stock status will be removed and the product page will show Add to cart icon.

The source code where Stock indexer determines the stock status can be found here.

The Stock indexer can be triggered by Schedule or by a Save action. When the indexer is set to be triggered on Save, there are numerous possibilities that it will roll back the Out of Stock status done by the queue consumer, including a CMS user modifying the product, an extension observer modifying custom attributes......

So basically, the Default Stock indexer ruined the MSI Out of Stock mechanism in a real production Magento setup.

gjportegies commented 2 years ago

@chequille we're experiencing exactly the same issue on a Magento 2.4.3 instance which is originally migrated from a Magento 1.9.4.3 instance.

nkajic commented 2 years ago

Hi @tgreeve thank you for your time describing problem.

I have same problem and see at least 5+ duplicate tickets closed without solution. How did you manage to solve this? Do you have some patch you can share with rest of us?

Thanks, N

chequille commented 2 years ago

Hi @nkajic see my comment above from https://github.com/magento/magento2/issues/33819#issuecomment-930529339 This helps on my site to get it almost working except of the fact, that I have to make catalog and product page not cachable.

nkajic commented 2 years ago

Hi @chequille

I have managed to get it working on 2.3.4-p1 by properly configuring consumers. #35105

But on earlier version there was definetly some other problem involved. Upgrading to 2.4.3-p1 and configuring consumers solved my problem.

I hope it hepls.

Thanks, N

chequille commented 2 years ago

Hi @nkajic, first, thanks for this info. Ok, I will try this on my local Ubuntu VM.

But if this is the only solution, somebody who does not have ssh acces to the server will never get it working, right? So far , I am in lucky, as my production site is on a VServer and I have ssh access.

As well I have a question regaring the consumers. You mentioned "properly configuring consumers", but what does it mean properly configured? Which consumers I have to run? Do I have to configure something else somewhere?

Do you have a description of everything you did? If yes, can you share it here?

Would be great. Best regards, Chequille

dphilipps commented 2 years ago

Hi @tgreeve I agree with your assessment about the indexer ruining the stock status. I raised this very issue in September 2021 https://github.com/magento/magento2/issues/34127 and it was eventually closed as a duplicate issue when it isn't - frustrating! With properly configured consumers products are correctly listed as out of stock when the saleable quantity hits 0 (there was an issue previously preventing this working properly). The separate issues as you mentioned is is the stock status is then reverted when a re-index is run (I would reproduce this by running a CLI reindex).

shomiadarshlt commented 1 year ago

@magento I am working on this.

shomiadarshlt commented 1 year ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 1 year ago

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

magento-deployment-service[bot] commented 1 year ago

Hi @shomiadarshlt, here is your Magento Instance: https://02f01d2fce71fbd22108a321e03258c9.instances-prod.magento-community.engineering Admin access: https://02f01d2fce71fbd22108a321e03258c9.instances-prod.magento-community.engineering/admin_dc9a Login: 9571699f Password: 7340d1512772

shomiadarshlt commented 1 year ago

Hi @chequille ,

I tried replicating the issue in magento 2.4 develop instance but could not replicate . The steps followed were :

Are there any steps that have been missed in replicating the issue ? Request you to help in this regard .

Thanks Shomi

JonathanHelvey commented 1 year ago

This is still happening on our store with Magento2.4.4-p5 with simple products. See the images below. I have not reproduced on a Vanilla Magento2 instance, only on my store. Steps to reproduce.

  1. Display out-of-stock items to - YES.
  2. Manage Stock to YES.
  3. No backordes.
  4. Add All inventory of product to Cart.
  5. Checkout with Free Shipping enabled.
  6. Reindex

The Product now shows in admin Quantity of 1 Salable Quantity 0. With the Product/order being in processing and waiting to be shipped. However on the frontend the product is still showing the 'ADD TO CART' button and showing in stock in both frontend and admin.

Screenshot 2023-08-29 at 6 24 00 PM Screenshot 2023-08-29 at 6 24 08 PM
JonathanHelvey commented 1 year ago

I do want to say we added this patch ACSD-47803 - Fixes the issue where out-of-stock configurable product swatches are displayed as available. After adding this patch it seems to have fixed our issue with add to cart button. So not sure if our store is experiencing the same issues as everyone else on this thread, but this patch did fix our issue even with simple products add to cart button when quantity is 0.

engcom-Bravo commented 2 months ago

Hi @chequille,

Thanks for your reporting and collaboration.

We have verified the issue in Latest 2.4-develop instance and the issue is no more reproducible.Kindly refer the screenshots.

Screenshot 2024-07-25 at 14 27 41 Screenshot 2024-07-25 at 14 28 01

There is no Add to Cart button for the products having salable quantity 0.

Hence we are closing this issue.

Thanks.