- I'm not sure if this is an m2 2.2 bug or just due the way I'm trying to filter the collection, but I can't seem to include disabled products in my product list collection.
- I've tried a few different options from what I've seen in a few forum posts.
- The below code snippet is purely to retrieve disabled products (as a first step, though the aim is to have enabled and disabled products).
This code results in zero products listed despite having disabled products which meet the criteria. Trying here in case there's something glaringly obvious I'm missing or a known bug with m2 2.2 requiring a workaround.
$collection = $this->productCollectionFactory->create(); //$collection->setVisibility($this->catalogProductVisibility->getVisibleInCatalogIds()); $collection = $this->_addProductAttributesAndPrices($collection) ->addStoreFilter() ->addAttributeToFilter('status', \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED) ->setCurPage($this->getRequest()->getParam($this->getData('page_var_name'), 1)); $conditions = $this->getConditions(); $conditions->collectValidatedAttributes($collection); $this->sqlBuilder->attachConditionToCollection($collection, $conditions); return $collection;
My widget is extended from:
class ProductsList extends \Magento\CatalogWidget\Block\Product\ProductsList