I want to filter wishlist product collection with a unique id.
I have tried to override a method _createWishlistItemCollection
located at the path /vendor/magento/module-wishlist/Block/AbstractBlock.php
using preference method.
This is my di.xml
file
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Wishlist\Controller\Index\Send" type="Vendor\Module\Controller\Index\Send"/>
<preference for="Magento\Wishlist\Block\Share\Email\Items" type="Vendor\Module\Block\Share\Email\Items"/>
</config>
This is my block file
namespace Vendor\Module\Block\Share\Email;
class Items extends \Magento\Wishlist\Block\Share\Email\Items
{
protected function _createWishlistItemCollection() {
$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/testmulti.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('Your text message');
$collection = $this->_getWishlist()->getItemCollection();
if($this->getMid()){
$id = $this->getMid();
if($this->getMid() == 'default')
$id = 0;
$collection ->addFieldToFilter('multiwishlist_id', $id);
}
return $collection;
}
}
It is not entering into the overrided file. Plese help me with a solution.
setup:static-content:deploy
command, and before deploying delete the contents invar/generation
files