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

Created on 14 May 2018  路  11Comments  路  Source: magento/magento2

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!

Catalog CatalogInventory Cannot Reproduce Clear Description Confirmed Format is valid Ready for Work Reproduced on 2.2.x

All 11 comments

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.

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

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

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

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!

@vteofilo Thank you! Your fix solved my issues.

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

@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.

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.

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

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!

Was this page helpful?
0 / 5 - 0 ratings