0

I want to get disabled product id's in my system but it gives me an empty array.

Here is screenshot of my products.When i grab disabled product by using this code

$updatedproids = [];
    $productCollection = $this->_productCollectionFactory->create();
    $productCollection->setFlag('has_stock_status_filter', false);
    $productCollection;

    foreach ($productCollection as $product) {
        $updatedproids[] = $product->getId();
    }
print_r($updatedproids);

I think there should be an issue with Magento Saleable Quantity but i'm not sure why i didn't get this.

10
  • If you are using MSI I don't think this has_stock_status_filter flag works. You should join with MSI tables. – Jonathan Ribas Aug 23 '20 at 7:25
  • How to do that will you please suggest me anything how to get data from these tables should i write SQL query or any other things actually i'm new to this @JonathanRibas – Prits Aug 23 '20 at 7:35
  • Are you using MSI for your stock management? – Jonathan Ribas Aug 23 '20 at 7:37
  • Actually my Magento version is Magento ver. 2.3.5-p1 so it is by default enable in Magento 2 @JonathanRibas – Prits Aug 23 '20 at 7:38
  • Take a look at Magento\InventorySalesApi module. – Jonathan Ribas Aug 23 '20 at 7:45
0

Please try this below:

    $updatedproids = [];
    $productCollection = $this->_productCollectionFactory->create()->addAttributeToSelect('*');
    $productCollection->addAttributeToFilter('status', array('in'=>array(2)))

    foreach ($productCollection as $product) {
        $updatedproids[] = $product->getId();
    }

    print_r($updatedproids);
1
  • It gives an empty array @Ritesh – Prits Aug 24 '20 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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