I am trying to get product collection with all enabled/disabled products. It works fine until I upgrade Magento to 2.2. Now It's not fetching disabled products in collection. Here is my code -
class Index extends \Magento\Framework\App\Action\Action
{
protected $_productCollectionFactory;
public function __construct(
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
\Magento\Framework\ObjectManagerInterface $objectmanager,
) {
$this->_objectManager = $objectmanager;
parent::__construct($context);
$this->_productCollectionFactory = $productCollectionFactory;
}
public function execute()
{
$collection = $this->_productCollectionFactory->create()
->addAttributeToSelect('*')
->addAttributeToFilter('diamond_vendor', array('in'=>$vendor))
//->addAttributeToFilter('status', array('in'=>array(1,2)))
->addAttributeToFilter('entity_id', array('nin'=>$notin_ids))
->setPageSize($noOfProducts)
->load();
}
}
In this I also tried with -
$collection->getSelect()->where('stock_status_index.stock_status IN(1,0)');
But its not making any effect.
Plz help me in this.
thx.