0

I try to add Stock and Out Of Stock filter in the Layered Navigation. I set the configuration of the attribute "quantity_and_stock_status":

enter image description here

In the storefront I look the filter, but if the configuration -> Display Product out of Stock is enabled it counts all items without stock status condition.

I have seen the following in the code. Magento does not filter if the option Display Product out of Stock is enabled.

  if (!$this->inventoryConfig->isShowOutOfStock($currentScopeId)) {
        $select->where('stock_index.stock_status = ?', Stock::STOCK_IN_STOCK);
    }

I have tried to replace this class but the methods are private and it gives error.

Is there any alternative?

1
  • Have you able to show the Stock filter on layer navigation? Aug 26, 2022 at 11:48

1 Answer 1

0

It's not enough to change that single line of code $this->scopeConfig->isSetFlag('cataloginventory/options/show_out_of_stock'); is called throughout the code in different ways and manners. The best approach would be to find every single call for this config and change it with plugins or preference if the methods are private, which they mostly are as it seems. Or you could do the worst hack in magento history and take the laziest approach, where you create a plugin for Magento\Framework\App\Config and check if the path is 'cataloginventory/options/show_out_of_stock' && your_custom_case and return true of false based on your needs.

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.