1

I want to show a recently added wishlist to be displayed at the starting In wishlist Page in magento2? Any help would be appreciated.

1

You can create di.xml file in your custom module here

app/code/Vendor/Module/etc/di.xml

Content for this file is..

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Wishlist\Block\Customer\Wishlist" type="Vendor\Module\Block\Customer\Wishlist" />
</config>

Now we need to create one Block file here in custom module

app/code/Vendor/Module/Block/Customer/Wishlist.php

Content for this file is..

<?php
namespace Vendor\Module\Block\Customer;

class Wishlist extends \Magento\Wishlist\Block\Customer\Wishlist
{
    protected function _prepareCollection($collection)
    {
        $collection->setInStockFilter(true)->setOrder('added_at', 'DESC');
        return $this;
    }
}

Hope this will help you!

  • I have already tried this, it is not working for me. – Amy Nov 15 '19 at 6:55
  • Can you please confirm any other block is not conflicting here which override this same block ? Magento\Wishlist\Block\Customer\Wishlist – Kishan Savaliya Nov 15 '19 at 6:56
  • Or you can use echo die in _prepareCollection() function and check. – Kishan Savaliya Nov 15 '19 at 6:56
  • 1
    okay will check. – Amy Nov 15 '19 at 7:01
  • 1
    Okay thank you. – Amy Nov 15 '19 at 8:00

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.