Im trying to get all products in a collection: out of stock and products in stock. So what I did is:
/** @var $collection \Magentp\Catalog\Model\ResourceModel\Product\Collection */
$collection = $this->productCollectionFactory->create();
$collection->addAttributeToSelect('*');
$collection->addAttributeToFilter('visibility', \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH);
$collection->addAttributeToFilter('status', \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
$collection->sePageSize(3);
$collection->setCurPage(1);
Now, when I use a foreach()
loop with $collection->getItems()
as the array expression, it just shows the products that have stock, but when I use the $collection->getAllIds()
instead, it includes the products out of stock.
Can anyone explain why?