0

I am trying to rewrite the protected function _prepareCollection method inside \Magento\Wishlist\Block\Customer\Wishlist however the wishlist page in my account now returns blank and it never makes it into the rewritten method.

Here is my di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <preference for="Magento\Wishlist\Block\Customer\Wishlist" type="Namespace\Module\Block\Customer\Favorites" />
</config>

And here is my php file located at Namespace/Module/Block/Customer/Favorites

<?php

namespace Namespace\Module\Block\Customer;

class Favorites extends \Magento\Wishlist\Block\Customer\Wishlist
{
    protected function _prepareCollection($collection)
    {
      parent::_prepareCollection($collection);
      die('working');
    }
}

Am i missing something here ? I know that I can't use a plugin because they don't work with protected methods. Is that now the same with class rewrites as well ? Help!

2 Answers 2

4

Worked like a charm. Was trying to add a function for delete all wishlist by extending \Magento\Wishlist\Block\Customer\Wishlist but wasn't giving the desired output, but after adding the constructor it worked.

2

Try adding the following to your block class:

protected function _construct()
{
    $this->setModuleName('Magento_Wishlist');
    parent::_construct();
}
1
  • I had the very same problem and this method was only solution which worked. Thank you very much.
    – vladPavlov
    Feb 20, 2017 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.