0

Following code isn't working to retreive disabled products even after adding respective filter:

    /**
     * @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
     */
    protected $_productCollectionFactory;

.....

 $childIds = array(1,2,3); //array of enabled and disabled product ids.
 $collection = $this->_productCollectionFactory->create()
            ->addAttributeToSelect('*')
            ->addAttributeToFilter('status', \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED)
            ->addAttributeToFilter('entity_id', array('in'=> $childIds))
            ->load();

Actual: $collection has all enabled products.

Expecting: $collection should have all disabled products from $productIds array. Need help to find disabled products in $childIds array. TIA

2
0

You may use getItems() instead of load(). And it's better to use the Service Contracts Layer instead of Collections.

1
  • I am sorry but it is not solving the problem. I would like to include disabled products in my collection. The solution given by you still giving me only enabled products. – Mayur Vijay Kathale Jul 8 '19 at 8:10
-1

You can try below one,

$searchCriteria = $this->_searchCriteriaBuilder->addFilter('status', \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED, 'eq')->create();
$searchResults = $this->_productRepository->getList($searchCriteria);
$disabledProducts = $searchResults->getItems();

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