Display ‘Not Visible Individually’ Product Into Mini Cart In Magento 2

Display “Not Visible Individually” Product Into Mini Cart In Magento 2 – Here I am going to explain you how to display “not visible individually” products into mini cart in your custom module.To display “Not Visible Individually” products into mini cart you need to follow following steps-


Set preference for “Magento\Checkout\CustomerData\Cart” in di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
     <preference for="Magento\Checkout\CustomerData\Cart" type="Webkul\TestModule\CustomerData\Cart" />


Make a Cart.php file on location Webkul\TestModule\CustomerData then copy all the codes of Magento\Checkout\CustomerData\Cart.php to your custom module file Webkul\TestModule\CustomerData\Cart.php

Edit in method getRecentItems()

    protected function getRecentItems()
        $items = [];
        if (!$this->getSummaryCount()) {
            return $items;

        foreach (array_reverse($this->getAllQuoteItems()) as $item) {
            /* @var $item \Magento\Quote\Model\Quote\Item */
            if (!$item->getProduct()->isVisibleInSiteVisibility()) {
                $product =  $item->getOptionByCode('product_type') !== null
                    ? $item->getOptionByCode('product_type')->getProduct()
                    : $item->getProduct();

                $products = $this->catalogUrl->getRewriteByProductStore([$product->getId() => $item->getStoreId()]);
                if (!isset($products[$product->getId()])) {
                    if ($product->getId() === 4){ // set your condition 
                        $items[] = $this->itemPoolInterface->getItemData($item); // "not visible individually" product having id 4 added into items array
                $urlDataObject = new \Magento\Framework\DataObject($products[$product->getId()]);
            $items[] = $this->itemPoolInterface->getItemData($item);
        return $items;

In this way you can display “not visible individually” products into mini cart.

. . .

Comments (2)

Add Your Comment

  • Timo Gundacker
    This doesn’t seem to be working any more. While compiling I get: Class AbcpremiumMinicartInvisibleCustomerDataItemPoolInterface does not exist. Is there a fix for that?
    • Webkul Support
      Hello Timo Gundacker,
      The actual location of class ItemPoolInterface is MagentoCheckoutCustomerDataItemPoolInterface
      So, you will have to write “MagentoCheckoutCustomerDataItemPoolInterface” instead of “ItemPoolInterface” then it will work. With Regards, Rani (Webkul Team)
  • css.php