Skip to content

override LowQuantityCollection via preference (so low stock report includes products with 0 stock)

I have set up a notify stock level in order to have a list of what to restock. Products in each sources with a stock level below the notify level show up fine. But if that stock goes to 0, they no longer show in the report. This makes the report useless.

IT IS HARD CODED IN InventoryLowQuantityNotificationModelResourceModelLowQuantityCollection.php

private function addSourceItemInStockFilter(): void
    {
        $condition = '(' . SourceItemInterface::QUANTITY . ' > 0 AND main_table.status = ' .
            SourceItemInterface::STATUS_IN_STOCK . ')';
        $this->getSelect()->where($condition);
    }

I gather I now need to override that to be

private function addSourceItemInStockFilter(): void
    {
        $condition = '( main_table.status = ' .
            SourceItemInterface::STATUS_IN_STOCK . ')';
        $this->getSelect()->where($condition);
    }

So simple, yes? alas no

I tried a plugin, but this is a private function (duh)

I have tried preference, but it doesn’t seem to be happening either

custom module’s adminhtml di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
  <preference for="MagentoInventoryLowQuantityNotificationModelResourceModelLowQuantityCollection" type="MyCoMyModuleModelResourceModelLowAndNoQuantityCollection"/>
</config>

and then in custom module folder ModelResourceModelLowAndNoQuantityCollection.php

   namespace MyCoMyModuleModelResourceModel;
   use MagentoInventoryApiApiDataSourceItemInterface;
   use MagentoInventoryLowQuantityNotificationModelResourceModelLowQuantityCollection;
   class LowAndNoQuantityCollection   extends LowQuantityCollection
   {
       /**
       * Filter out of stock source items.
        * @return void
        */
       private function addSourceItemInStockFilter(): void
       {
           $condition = '( main_table.status = ' . SourceItemInterface::STATUS_IN_STOCK . ')';
           $this->getSelect()->where($condition);
       }
   }

It’s not dying but it’s also not doing that particular change 🙁

PS: I have verified that changing the core source does what I want (just to be sure!)

What am I missing?