0

I am using Magento 2.2.7. On custom product grid _prepareCollection() I tried to get all product collection by

$collection = $this->_productFactory->create()->getCollection();

but it gets only enabled & in_stock products. If I get count($collection->getData()) it shows all product count. but If I tried with $collection->count() it get only enabled and in_stock product count. How I get all products in grid through $this->setCollection($collection);

  • I think it is better to use \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory – fmsthird Apr 13 '19 at 23:38
  • same it hides out_of_stock and disabled product. But why can you help in this regard? – Iftakharul Alam Apr 14 '19 at 8:48
  • I guess the stock status is your problem (disabled products are by default removed from stock). Check the SQL output of your collection and maybe this workaround would help you -> github.com/magento/magento2/issues/13411 But as far as I know this limitation is added to product collection only in frontend and respects the configuration wheter to display out of stock products or not. I assume your code should run in admin area so the inventory plugin which affects the collection (Magento\CatalogInventory\Model\AddStockStatusToCollection::beforeLoad()) shouldn't be implied! – HelgeB Apr 14 '19 at 9:02

Your Answer

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

Browse other questions tagged or ask your own question.