0

How to get the wistlist_item_id for particular customerId and productId in magento2?

Thanks.

2

You need to inject \Magento\Wishlist\Model\Wishlist Model class into your construct. Add this below code in your controller :

<?php
namespace VendorName\ModuleName\Controller\Index;
class Wishlist extends \Magento\Framework\App\Action\Action {

    /**
     * @var \Magento\Wishlist\Model\Wishlist
     */
    protected $wishlist;

    /**
     * [__construct description]
     * @param \Magento\Framework\App\Action\Context $context  [description]
     * @param \Magento\Wishlist\Model\Wishlist      $wishlist [description]
     */
    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Wishlist\Model\Wishlist $wishlist
    ) {
        $this->wishlist = $wishlist;
        parent::__construct($context);
    }
    /**
     * Default customer account page
     *
     * @return void
     */
    public function execute() {
        $customerId = '1';
        $wishListData = $this->wishlist->loadByCustomerId($customerId, true)->getItemCollection();
        foreach ($wishListData as $key => $value) {
            echo "Wishlist Item ID : ".$value['wishlist_item_id']."<br/>";
            echo "Wishlist Product ID : ".$value['product_id']."<br/>";
        }
    }
}
?>

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.