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

Magento 2.2.2 version stock status(Quantity) attribute(quantity_and_stock_status) is not updating in catalog product admin grid #15201

Closed
vijaymagento1 opened this issue May 14, 2018 · 12 comments
Labels
Component: Catalog Component: CatalogInventory 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

@vijaymagento1
Copy link

vijaymagento1 commented May 14, 2018

Hi Magento2 Support tean,
I have added product attribute(quantity_and_stock_status) column in catalog product admin grid for the filtering the "In Stock" and "Out of Stock" products list.

Preconditions

Magento 2.2.2

Steps to reproduce

  1. Go to Magento 2 admin => Stores => Attributes => Product => Search attribute code "quantity_and_stock_status".
  2. Change "Advanced Attribute Properties" settings Scope => "Store view/Global", "Add to Column Options" to "Yes" and set "Use in Filter Options" to "Yes".
    Screenshot:- https://i.imgur.com/bgqrgbK.png
  3. Now product attribute Quantity(quantity_and_stock_status) will be visible in to the catalog product settings Columns section and checked it to yes.
    Screenshot:- https://i.imgur.com/Rxbi1GC.png
  4. Make Product "Out of Stock" and Save it Flush/Refresh the Cache.
  5. Reindexng by the CLI php bin/magento indexer:reindexer

Expected result

"Stock status" has correct value.

Actual result

Product not updating stock status in catalog product admin grid it always shows "In Stock" status.
Screenshot:- https://i.imgur.com/wT5Kl2i.png

Please solve this issues as soon as possible. This issues is also persist in magento Latest version(2.2.4).

Thanks!

@magento-engcom-team magento-engcom-team added the Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed label May 14, 2018
@karangar
Copy link

Same problem in magneto 2.2.4
Please Check below screen shot.
screenshot-192 168 10 217-2018 06 18-15-50-12
screenshot-192 168 10 217-2018 06 18-15-48-30

Please help me how to resolve this problem.

@engcom-backlog-nickolas engcom-backlog-nickolas added Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Component: Catalog Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed 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: CatalogInventory labels Jul 12, 2018
@engcom-backlog-nickolas

Hello @vijaymagento1, thank you for your report.
We've acknowledged the issue and added to our backlog.

@engcom-backlog-nickolas engcom-backlog-nickolas removed their assignment Jul 12, 2018
@knelus
Copy link

knelus commented Jul 17, 2018

Exact same issue here. Hopefully Magento (Adobe) will fix this soon.

@magento-engcom-team magento-engcom-team added Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed and removed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed labels Jul 19, 2018
@xpedicion
Copy link

Also, the stock status column should not be labeled "Quantity".

@vteofilo
Copy link

vteofilo commented Sep 1, 2018

This worked for me:

As I have a specific function to update inventory that extends \Magento\CatalogInventory\Model\StockRegistry, I called inside it, but if you use Magento itself you should create a plugin to be called after you have run the function Magento\CatalogInventory\Model\StockRegistry::updateStockItemBySku(). At each inventory update, this function updates the is_in_stock status of the parent product by adding the items of the child products:

`

public function syncProductStock(int $productId)
{
    $product = $this->productFactory->create();
    $product->load($productId);

    $productParent= $this->productFactory->create();
    $productParent->load(
        $this->objectManager->get(\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable::class)
            ->getParentIdsByChild($productId)
    );

    $childrenIds = array_values(
        $this->objectManager->get(\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable::class)
            ->getChildrenIds($productParent->getId())[0]
    );
    $sumQuantity = 0;
    foreach ($childrenIds as $childrenId) {
        $sumQuantity += $this->objectManager->get(\Magento\CatalogInventory\Model\StockRegistry::class)
            ->getStockItem($childrenId)->getQty();
    }

    $isInStock = $sumQuantity > 0 ? 1 : 0;
    $product->addAttributeUpdate('quantity_and_stock_status', $this->getStockItem($productId)->getIsInStock(), $product->getStoreId());
    $productParent->addAttributeUpdate('quantity_and_stock_status', $isInStock, $product->getStoreId());

    $parentStockItem = $this->getStockItem($productParent->getId());
    $parentStockItem->setIsInStock($isInStock);
    $this->stockItemRepository->save($parentStockItem);
}`

The fix loads the product by productId, loads its parent, and takes the ids of all its children to the sum of each one's stock. Through the stock sum of the children products, 1 or 0 is assigned to the quantity_and_stock_status attribute of the child products and the parent product. Finally, it points to the IsInStock of the StockItemRepository according to the same sum and saves the parent stock.

Hope this helps! Thank you!

@danieljoeblack
Copy link

danieljoeblack commented Oct 3, 2018

@vteofilo Thank you! Your fix solved my issues.

@Puru2016
Copy link

@vteofilo please explain bit more how to use your fix to solve this issue?

@vteofilo
Copy link

@vteofilo please explain bit more how to use your fix to solve this issue?

@Puru2016 , yes of course! The fix loads the product by productId, loads its parent, and takes the ids of all its children to the sum of each one's stock. Through the stock sum of the children products, 1 or 0 is assigned to the quantity_and_stock_status attribute of the child products and the parent product. Finally, it points to the IsInStock of the StockItemRepository according to the same sum and saves the parent stock.

@magento-engcom-team
Copy link
Contributor

Hi @vijaymagento1.

Thank you for your report and collaboration!

The related internal Jira ticket MC-19978 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 Oct 2, 2019
@stylidev
Copy link

Hi Magento2 Support team,

Do we have a patch for this available, we are on 2.3.1 and the issue still persists as you can see in the screenshots:

Screen Shot 2019-10-31 at 12 23 57 PM

Screen Shot 2019-10-31 at 12 24 21 PM

@silversil
Copy link

silversil commented Jan 14, 2020

Same issue on 2.2.7 is possible that Magento team is not taking care of an issue such stupid and important at the same time?

I need to filter all items that have qty>1 in "out of stock" status, no solution! Absolutely absurd!

@vitormcsi
Copy link

@vteofilo you can help me to apply this code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Catalog Component: CatalogInventory 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