How to get wishlist image by product Magento 2?

Get Wishlist thumbnail image by the product SKU to display the Wishlist item image on the page Magento 2.

You need to required product SKU to fetch product object, based on the object, pass image id as wishlist_thumbnail to fetch thumb of the product.

Using ImageFactory class to fetch wishlist image programmatically, Continue reading “How to get wishlist image by product Magento 2?”

How to remove wishlist tabs from the admin Customer edit Page Magento 2?

You can remove wishlist tabs from the customer edit page in Magento 2 admin panel.

Your eCommerce site doesn’t support the wishlist functionality, you need to remove tabs from the customer section of the admin also.

Wishlist section displays the list of wishlist items grid for the specific customer.

Create a customer_index_edit.xml file in your module with adminhtml scope, Continue reading “How to remove wishlist tabs from the admin Customer edit Page Magento 2?”

Get wishlist collection of a customer by customer id Magento 2.

You can get wishlist collection of a customer by customer id. You can show detail of Customer Wishlist item in a store. Get Wishlist collection by calling Magento\Wishlist\Model\Wishlist Model file.

I have created a Block file for define Wishlist collection and load collection in template file by iterating over a collection loop.

<?php
namespace Rbj\Wishlist\Block;

class Demo extends \Magento\Framework\View\Element\Template
{
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Wishlist\Model\Wishlist $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;
    }
}

Call function in a template file, If Customer has wishlist item available, display item info otherwise no item found message will be displayed.

<?php
$customerId = 2; //CUSTOMER_ID
$wishlistCollection = $block->getWishlistByCustomerId($customerId);
if(count($wishlistCollection)) {
    foreach ($wishlistCollection as $_item) {
        echo $_item->getProduct()->getName();echo "<br>";
        echo $_item->getProduct()->getId();echo "<br>";
    }
} else {
    echo __("No Item found in your wishlist");
}

The result will be your Item list from a Wishlist.