2

I want to add a new filter in shared wishlist items. I have used the preference method to override the block method. The problem is that the addFieldToFilter is not working. How can I achieve it?

Here is my di.xml

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

Company\Module\Block\Share\Email\Items.php

namespace Company\Module\Block\Share\Email;


class Items extends \Magento\Wishlist\Block\Share\Email\Items
{

    protected $_template = 'email/items.phtml';

    public function getWishlistItems()
    {
        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/jancy.log');
        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);
        $logger->info('entry');

        if ($this->_collection === null) {
            $this->_collection = $this->_createWishlistItemCollection();               
            $this->_prepareCollection($this->_collection);
         }            
         $this->_collection->addFieldToFilter('custom_id', '4');
        return $this->_collection;
    }


}

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.