1

I am using aloquick theme in Magento2. Some out of stock products are showing in Featured Products tab of Home Page. I would like to remove those out of stock product from Home Page. My admin panel settings is like below

enter image description here

0

By making the setting stores>configuration>catalog>inventory> Display Out of Stock Products to 'No' out of products will not visible at frontend. But it seems that in your featured block you have get the collection of product using incorrect code. Use below code which returns only In Stock products collection-

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$productCollectionFactory = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');

$productCollection = $productCollectionFactory->create() ->addAttributeToSelect('*') ->addAttributeToSort('created_at', 'DESC') ->joinField('stock_item', 'cataloginventory_stock_item', 'qty', 'product_id=entity_id', 'is_in_stock=1') ->setPageSize(8)->load();

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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