I see that my installation of Magento 2.1.0 has a problem! Refuses to hide out of stock products from search and category pages! I cleared the cache, I reindexed, but no luck!

Can you give me any advice?

My products are with stock 0, but in front, they appear in stock, and when you order them it gives you this error:

We don't have as many "Item's name" as you requested.


Later edit :

I also know this information :

Set in admin > Stores > configuration > Catalog > Inventory > Stock Options > Display Out of Stock Products to NO

This is actually a feature of Magento. Setting Display out-of-stock products to No only hides them from the category list pages and the search results page. The product page is actually still available. Starting with CE 1.9.1 there is even a message under the config setting Display out of stock products saying Products will still be shown by direct product URLs. And this is actually a good thing. This way search engines don't register a lot of 404 pages when your products get out of stock. I don't see the harm in leaving it like that. The customer cannot order them anyway. If you want a product not to be available at all in your store you have to mark it as disabled or set its visibility to Not visible individually or remove its association to the websites from the websites tab on the admin product edit page. Source: Out of stock products still appear in the frontend

  • I am also facing the same issue. Even after changing the backend configuration, I am still facing this. If you found the solution, please let me know. Commented Nov 8, 2017 at 15:32
  • Are you guys still experiencing this issue? Are you using custom theme? I think it probably could be the root of problem. Commented Jan 11, 2018 at 22:01

6 Answers 6


Go to admin > Stores > configuration > Catalog > Inventory > Stock Options

Set Display Out of Stock Products to NO

enter image description here

  • 3
    Already done that! Still no change!
    – edgetwism
    Commented Jul 18, 2016 at 9:58
  • hello, did anyone found the solution, there is no module and the new theme is built over the luma with some CSS only but still getting this issue, this configuration is not working Commented Jun 27, 2020 at 21:05

I was facing the exact same problem (Magento v2.1.9) due to "Backorders", which was set "Allow Qty Below 0 and Notify Customer"

Go to admin > Stores > configuration > Catalog > Inventory > Stock Options Set Display "Out of Stock Products" to NO

Go to admin > Stores > configuration > Catalog > Inventory > Product Stock Options Set Backorders to "No Backorders"

Note: Changing can take some time due to processing whole catalog.

enter image description here


I have the same issue on 2.2.3.On my side, it happened after the upgrade command.I tried commands and run queries but no luck.I sort it out using changing following option from Yes to No. Stores => Configuration => Catalog=> Catalog =>Disable Add to cart button for Guests From Yes to No.Hope this will help someone.Thanks enter image description here

  • By default there is no such option.
    – Priyank
    Commented Jun 20, 2018 at 13:02
namespace vendor\module\Block\Product;

class ListProduct extends \Magento\Catalog\Block\Product\ListProduct{

    protected function _getProductCollection(){
        $collection = parent::_getProductCollection();
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $productIds = $objectManager->create('\vendor\module\Helper\Data')->getIdsToLastStock($collection->getAllIds());
        $orderString = array('CASE e.entity_id');
        foreach($productIds as $i => $productId) {
            $orderString[] = 'WHEN '.$productId.' THEN '.$i;
        $orderString[] = 'END';
        $orderString = implode(' ', $orderString);
        $collection->addAttributeToFilter('entity_id', array('in' => $productIds));
        $collection->getSelect()->order(new \Zend_Db_Expr($orderString));
        return $collection;


Found the solution!

Put a filter in catalog : Quantity: 0.0000 - 0.0000!

Then select all, action> update atributes> advanced inventory > Stock Availability ( click change) > Select out of stock > save then reindex and the products are gone :)

  • And for configurable products ? Commented Jun 16, 2017 at 9:09

namespace vendor\module\Helper;

class Data extends \Magento\Framework\App\Helper\AbstractHelper {

protected $_stockItemRepository;
protected $_scopeConfig;
protected $_storeScope;

public function __construct(\Magento\CatalogInventory\Model\Stock\StockItemRepository $_stockItemRepository, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)
    $this->_stockItemRepository = $_stockItemRepository;
    $this->_scopeConfig = $scopeConfig;
    $this->_storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;

public function getIdsToLastStock($ids){
    if($this->_scopeConfig->getValue('module/vendor_module/active',$this->_storeScope)==1) {
        $products = array();
        $productIds = array();
        foreach ($ids as $id) {
            try {
                $stockItem = $this->_stockItemRepository->get($id);
                $products[] = array('id' => $id, 'stock' => $this->checkIfAvailableInStock($stockItem));
            } catch (\Exception $ex) {
                $products[] = array('id' => $id, 'stock' => 0);

        if (count($products) > 0) {
            foreach ($products as $id => $value) {
                $names[$id] = $value['stock'];
            $keys = array_keys($products);
                $names, SORT_ASC, SORT_NUMERIC, $products, $keys
            $result = array_combine($keys, $products);
            foreach ($result as $product) {
                $productIds[] = intval($product['id']);
            return $productIds;
        } else {
            return $ids;
    return $ids;

private function checkIfAvailableInStock($item){
            return 0;
    return 1;


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.