1

How to get list of products for which backorder is enabled?

1 Answer 1

1

Inject this below class in your construct :

protected $collectionFactory;

public function __construct(
    .....
    \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory
    .....
) {
    .....
    $this->collectionFactory = $collectionFactory;
    .....
}

Now you can use this below code for fetch collection based on backorders.

$productCollection = $this->collectionFactory->create();
$productCollection->addAttributeToSelect('*')->joinField(
    'backorders',
    'cataloginventory_stock_item',
    'backorders',
    'product_id = entity_id',
)->joinTable(
    'cataloginventory_stock_item',
    'product_id = entity_id',
    ['']
)
->addAttributeToFilter(
    'status',
    \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
)->load();

For backorder enabled only, add more filter :

->addAttributeToFilter(
        'backorders',
        1
)
1
  • 1
    Thanks @Rohan. It worked. Commented Oct 19, 2021 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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