Here, we are discussing how to get wishlist items of the customer by customer id.
You can display Customer Wishlist item details in the store.
Use MagentoWishlistModelWishlist Model file to get Wishlist.
Create Block to load Wishlist collection.
<?php namespace MagemonkeyWishlistBlock; class Magemonkeydemo extends MagentoFrameworkViewElementTemplate { public function __construct( MagentoFrameworkViewElementTemplateContext $context, MagentoWishlistModelWishlist $wishlist, array $data = [] ) { $this->wishlist = $wishlist; parent::__construct($context,$data); } /** * @param int $customerId */ public function getWishlistByCustomerId($customerId) { $wishlist = $this->wishlist->loadByCustomerId($customerId)->getItemCollection(); return $wishlist; } } ?>
Now, add below code and call the function in a template file, It will display wishlist item if found, otherwise “Nothing found in your wishlist!” will be displayed.
<?php $customerId = 7; /* CUSTOMER'S ID */ $wishlistCollection = $block->getWishlistByCustomerId($customerId); if(count($wishlistCollection)) { foreach ($wishlistCollection as $_item) { /* You can get ID, Name, Desc. ... */ echo $_item->getProduct()->getId(); } } else { /* Display message if no item found in wishlist */ echo __("Nothing found in your wishlist!"); } ?>