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

Reindex cataloginventory_stock does not update cataloginventory_stock_status in 2.4.5 #37450

Closed
5 tasks
melnickforever opened this issue May 2, 2023 · 21 comments
Closed
5 tasks
Assignees
Labels
Issue: needs update Additional information is require, waiting for response Reported on 2.3.5-p1 Indicates original Magento version for the Issue report.

Comments

@melnickforever
Copy link

Preconditions and environment

  • Magento version 2.3.5-p1
  • in Magento 2.3.6 reindex cataloginventory_stock update field stock_status in the table cataloginventory_stock_status in 2.4.5-p1 - no

Steps to reproduce

Update directly stock_status in cataloginventory_stock_status .(imports can do this)
Run cataloginventory_stock reindex

Expected result

field stock_status in table cataloginventory_stock_status - updated

Actual result

field stock_status in table cataloginventory_stock_status - outdated

Additional information

No response

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
@m2-assistant
Copy link

m2-assistant bot commented May 2, 2023

Hi @melnickforever. Thank you for your report.
To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:


Join Magento Community Engineering Slack and ask your questions in #github channel.
⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
🕙 You can find the schedule on the Magento Community Calendar page.
📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

@m2-assistant
Copy link

m2-assistant bot commented May 3, 2023

Hi @engcom-Bravo. 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).
  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.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. Add label Issue: Confirmed once verification is complete.
  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-Bravo engcom-Bravo added the Reported on 2.3.5-p1 Indicates original Magento version for the Issue report. label May 3, 2023
@engcom-Dash
Copy link
Contributor

@magento give me 2.4-develop instance

@magento-deployment-service
Copy link

Hi @engcom-Dash. Thank you for your request. I'm working on Magento instance for you.

@magento-deployment-service
Copy link

@engcom-Bravo
Copy link
Contributor

@magento give me 2.4-develop instance

@magento-deployment-service
Copy link

Hi @engcom-Bravo. Thank you for your request. I'm working on Magento instance for you.

@magento-deployment-service
Copy link

@engcom-Bravo
Copy link
Contributor

Hi @melnickforever,

Thank you for reporting and collaboration.

Verified the issue on Magento 2.4-develop instance and the issue is not reproducible.Kindly refer the screenshots.

Steps to reproduce

  • Update directly stock_status in cataloginventory_stock_status .(imports can do this)
  • Run cataloginventory_stock reindex

We have imported a CSV file to update the stock of the product and the stock of the product is updated in both admin and table cataloginventory_stock_status field.

Screenshot 2023-05-04 at 12 41 38 PM

Screenshot 2023-05-04 at 12 41 47 PM

We have Imported Below CSV file :

Update.csv

When we update status of the product with the import in that case also both are updated.

Screenshot 2023-05-04 at 12 51 15 PM

Screenshot 2023-05-04 at 12 50 05 PM

Update.csv

Kindly recheck the behavior on Magento 2.4-develop instance and elaborate steps to reproduce if the issue is still reproducible.

Thanks.

@engcom-Bravo engcom-Bravo added the Issue: needs update Additional information is require, waiting for response label May 4, 2023
@engcom-Bravo
Copy link
Contributor

Hi @melnickforever,

We have noticed that this issue has not been updated for a period of 14 Days.
Hence we assume that this issue is fixed now, so we are closing it. Please raise a fresh ticket or reopen this ticket if you need more assistance on this.

Thanks.

@pmathbliss
Copy link

pmathbliss commented Jun 6, 2023

There is an issue with the cataloginventory_stock indexer.

The same value in the cataloginventory_stock_status is put into the table if the product is in stock and the record already exists in the table.

SELECT
  `e`.`entity_id`,
  `cis`.`website_id`,
  `cis`.`stock_id`,
  IF(cisi.qty > 0, cisi.qty, 0) AS `qty`,
  IF(
    cisi.use_config_manage_stock = 0
    AND cisi.manage_stock = 0,
    1,
    IF(
      cisi.is_in_stock = 0,
      0,
      IF(
        css.stock_status IS NOT NULL,
        css.stock_status,
        MAX(cisi.is_in_stock)
      )
    )
  ) AS `status`
FROM
  `catalog_product_entity` AS `e`
  CROSS JOIN `cataloginventory_stock` AS `cis`
  INNER JOIN `cataloginventory_stock_item` AS `cisi`
    ON cisi.stock_id = cis.stock_id
    AND cisi.product_id = e.entity_id
  INNER JOIN `catalog_product_entity_int` AS `mcpei`
    ON e.entity_id = mcpei.entity_id
    AND mcpei.attribute_id = 96
    AND mcpei.value = 1
  LEFT JOIN `cataloginventory_stock_status` AS `css`
    ON css.product_id = e.entity_id
WHERE (cis.website_id = 0)
  AND (e.type_id = 'simple')
  AND (
    e.entity_id IN (
      2508,
      2509,
      2510))

This if statement

IF(
        css.stock_status IS NOT NULL,
        css.stock_status,
        MAX(cisi.is_in_stock)
      )
  puts the same value back in the table rather than the current in stock value.

attribute_id 96 is product status.

@ValerieS
Copy link

ValerieS commented Jun 8, 2023

@magento-admin please reopen

@pmathbliss
Copy link

Anyone looking for a fix.

vendor/magento/module-inventory-catalog/Model/ResourceModel/StockStatusExpressionForDefaultStock.php

Line 49,
$connection->getCheckSql('css.stock_status IS NOT NULL', 'css.stock_status', $stockItemInStockField)
change to
$connection->getCheckSql('css.stock_status IS NOT NULL', 'cisi.is_in_stock', $stockItemInStockField)

@VictorSoaresRedstage
Copy link

Anyone looking for a fix.

vendor/magento/module-inventory-catalog/Model/ResourceModel/StockStatusExpressionForDefaultStock.php

Line 49, $connection->getCheckSql('css.stock_status IS NOT NULL', 'css.stock_status', $stockItemInStockField) change to $connection->getCheckSql('css.stock_status IS NOT NULL', 'cisi.is_in_stock', $stockItemInStockField)

Thanks @pmathbliss, I had the same issue and this worked for me.

@stefanskotte
Copy link

@pmathbliss Awesome - works here too !

@tayner
Copy link

tayner commented Aug 30, 2023

Thank you! Good job

@joeldavuk
Copy link

joeldavuk commented Nov 16, 2023

stock-37450-issue.patch
Confirmed this fixed this issue in 2.4.5-p1

@LudwigDev9
Copy link

Does anyone know why this is still an issue in 2.4.x?

I see the changes was never merged from magento/inventory#3388

I have been dealing with the issue as well and wanted to find out from @pmathbliss, if we update the code as per above does this automatically correct all products per index? or will that still be an manual process?

@splacento-incomm
Copy link

Anyone looking for a fix.

vendor/magento/module-inventory-catalog/Model/ResourceModel/StockStatusExpressionForDefaultStock.php

Line 49, $connection->getCheckSql('css.stock_status IS NOT NULL', 'css.stock_status', $stockItemInStockField) change to $connection->getCheckSql('css.stock_status IS NOT NULL', 'cisi.is_in_stock', $stockItemInStockField)

Having same issue on 2.4.6.
This actually works, thank you!

@joachimVT
Copy link

Having the same issue on 2.4.6-p4

@stefanskotte
Copy link

Confirmed working on 2.4.6-p7 as well, thank you @splacento-incomm this just made my day so much better. One less bug to worry about ..... until the next 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: needs update Additional information is require, waiting for response Reported on 2.3.5-p1 Indicates original Magento version for the Issue report.
Projects
None yet
Development

No branches or pull requests