0

I am trying to get Wishlist product collection in Custom module controller for the new functionality. I searched in google and I got this:

Inject this class in your constructor:

protected $wishlistProvider;

public function __construct(
    ...
    \Magento\Wishlist\Controller\WishlistProviderInterface $wishlistProvider
) {
    $this->wishlistProvider = $wishlistProvider;
    ...
}

and

$currentUserWishlist = $this->wishlistProvider->getWishlist();
if ($currentUserWishlist) {
    $wishlistItems = $currentUserWishlist->getItemCollection();
}

I have tried using this code. But its not working. I am getting this error:

Uncaught TypeError: Argument 3 passed to namespace\modulename\Controller\Index\Index::__construct() must be an instance of Magento\Wishlist\Controller\WishlistProviderInterface, none given, called in /var/www/project_name/var/generation/namespace/modulename/Controller/Index/Index/Interceptor.php on line 14

Please suggest me a way to do this. Thanks in advance!!

  • Have you remove var folder? – Rakesh Jesadiya Dec 30 '16 at 9:49
  • 1
    Just I have removed generation folder in var. I have to remove var folder fully?? – Murali Raj Dec 30 '16 at 9:50
  • Try bin/magento setup:di:compile – lpFranz Mar 13 '18 at 18:06
0

In other way you can get wishlist items collection.

Use factory Magento\Wishlist\Model\ResourceModel\Item\CollectionFactory for getting wishlist product collection and filter that by addCustomerIdFilter($customerId)

protected $_currentUserWishlistCollectionFactory ;
protected $_Customersession;
public function __construct(
       \Magento\Wishlist\Model\ResourceModel\Item\CollectionFactory $currentUserWishlistCollectionFactory,
    \Magento\Customer\Model\Session $Customersession,
    ) {
    ....
    $this->_Customersession = $Customersession;
        $this->_currentUserWishlistCollectionFactory = $currentUserWishlistCollectionFactory;
....

    }

public function getcurrentUserWishlistItems(){

    $collection = $this->_currentUserWishlistCollectionFactory->create();
    $collection->addCustomerIdFilter($this->_Customersession->getCustomerId());
    return $collection;

}
0

Try to compile your codes:

bin/magento setup:di:compile

Appears to me, that your error will be solved with this.

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.