0

How to display products out of stock are the most recent on the search and category pages.

I debug to the file vendor/magento/module-review/Observer/CatalogBlockProductCollectionBeforeToHtmlObserver.php

in it i found the method public function execute(\Magento\Framework\Event\Observer $observer)

and added $productCollection->getSelect()->order('is_salable' . \Magento\Framework\Api\SortOrder::SORT_DESC);

result

    public function execute (\ Magento \ Framework \ Event \ Observer $ observer)
    {
        $ productCollection = $ observer-> getEvent () -> getCollection ();
        if ($ productCollection instanceof \ Magento \ Framework \ Data \ Collection) {
            $ productCollection-> getSelect () -> order ('is_salable'. \ Magento \ Framework \ Api \ SortOrder :: SORT_DESC);
            $ productCollection-> load ();
            $ this -> _ reviewFactory-> create () -> appendSummary ($ productCollection);
        }

        return $ this;
    }

The products were filtered out as i needed, but i can’t leave it as it is, tell me how i can implement it using modules or something similar, or if you have better ideas, i will consider them with pleasure, thanks

Your Answer

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

Browse other questions tagged or ask your own question.