Skip to main content
added 11 characters in body
Source Link
Amit Bera
  • 77.7k
  • 20
  • 124
  • 239

In other way you can get wishlist items collection.

Use factory Magento\Wishlist\Model\ResourceModel\Ite\CollectionFactoryMagento\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\Ite\CollectionFactory\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;

}

In other way you can wishlist collection.

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

protected $_currentUserWishlistCollectionFactory ;
protected $_Customersession;
public function __construct(
       \Magento\Wishlist\Model\ResourceModel\Ite\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;

}

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;

}
Source Link
Amit Bera
  • 77.7k
  • 20
  • 124
  • 239

In other way you can wishlist collection.

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

protected $_currentUserWishlistCollectionFactory ;
protected $_Customersession;
public function __construct(
       \Magento\Wishlist\Model\ResourceModel\Ite\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;

}