Question

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.

Was it helpful?

Solution

for category pages its works check this Blog link.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top