0

I want every collection with 0 stock to get moved to the bottom (last position)

I've tried using a plugin. My di.xml

<type name="Magento\Catalog\Model\Layer">
        <plugin name="Vendor_Module_Plugin"
                type="Vendor\Module\Plugin\CollectionPlugin"
                sortOrder="10"
                disabled="false"/>
</type>

My file name CollectionPlugin.php

class CollectionPlugin
{
   public function aroundgetProductCollection(
        Layer $subject,
        callable $proceed
    ) {
        $collection = $proceed();
        $collection->setOrder('is_salable DESC');
        return $collection;
    }
}

For some reason, It removes every product from the collection.

0

for category pages its works check this Blog link.

1
  • Thank you very much, I was on this page and it didn't work before. Is there a way to keep the order and just append the 0 stock products to the end? – Walter Woshid Apr 29 '20 at 13:41

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.