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;


$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? Dec 30, 2016 at 9:49
  • 1
    Just I have removed generation folder in var. I have to remove var folder fully??
    – Murali Raj
    Dec 30, 2016 at 9:50
  • Try bin/magento setup:di:compile
    – lpFranz
    Mar 13, 2018 at 18:06

2 Answers 2


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();
    return $collection;

  • Where I have to put this code in order to get the customer wishlist collection. I want to download the customer wishlist collection as a CSV file. Can you guide me on that?
    – MagentoDev
    Dec 23, 2019 at 7:38
  • As of now, I'm able to download the sample data as a CSV file. I have referred this URL: magento.stackexchange.com/questions/287976/…
    – MagentoDev
    Dec 23, 2019 at 7:42

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 and acknowledge you have read our privacy policy.

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