I have tried to set quantity_and_stock_status attribute to make filterable on the product list page. I have set it from the admin panel(Stores -> Attributes -> Product) but I can not see a stock filter on the front end. What could be the issue? Please provide a solution. Thank you

2 Answers 2



is the attribute code name is


When changing the settings I have found a bug,it didn't save and showed the loading image,

It was a magento 2 bug same as https://github.com/magento/magento2/issues/8202 ,

for a quick solution you can do is inspect the options and remove the disabled attribute and then save.

It worked for me.

  • I have upgraded magento to latest version 2.2.4 and issue fixed.
    – Ankit8
    Commented Jun 2, 2018 at 5:41
  • yes, latest versions fixed the lot of bugs
    – Lasantha
    Commented Jun 2, 2018 at 12:10

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();

    $productParent= $this->productFactory->create();

    $childrenIds = array_values(
    $sumQuantity = 0;
    foreach ($childrenIds as $childrenId) {
        $productChildren = $this->productFactory->create();
        $sumQuantity += $this->objectManager->get(\Magento\CatalogInventory\Model\StockRegistry::class)

    $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());

Hope this helps! Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.