Question

my client want to show short description under mini cart title:

You can see image screenshot:

enter image description here

I used grep command found it coming from :/vendor/magento/module-checkout/CustomerData/DefaultItem.php

and using html template file from: /Magento_Checkout/web/template/minicart/item/default.html

so i have passed short description from DefaultItem.php to Ajax response show short description and Same changes on html template file default.html also but not reflecting on front.

i have cleared caches, deployed content and tried on private browser but still not working.

Was it helpful?

Solution

You need to override this file

/vendor/magento/module-checkout/CustomerData/DefaultItem.php

and add call sort description value here like below

/**
     * {@inheritdoc}
     */
    protected function doGetItemData()
    {
        $imageHelper = $this->imageHelper->init($this->getProductForThumbnail(), 'mini_cart_product_thumbnail');
        $productName = $this->escaper->escapeHtml($this->item->getProduct()->getName());

        return [
            'options' => $this->getOptionList(),
            'qty' => $this->item->getQty() * 1,
            'item_id' => $this->item->getId(),
            'configure_url' => $this->getConfigureUrl(),
            'is_visible_in_site_visibility' => $this->item->getProduct()->isVisibleInSiteVisibility(),
            'product_id' => $this->item->getProduct()->getId(),
            'product_name' => $productName,
            'product_sku' => $this->item->getProduct()->getSku(),
            'sort_description'=>'sort_description',
            'product_url' => $this->getProductUrl(),
            'product_has_url' => $this->hasProductUrl(),
            'product_price' => $this->checkoutHelper->formatPrice($this->item->getCalculationPrice()),
            'product_price_value' => $this->item->getCalculationPrice(),
            'product_image' => [
                'src' => $imageHelper->getUrl(),
                'alt' => $imageHelper->getLabel(),
                'width' => $imageHelper->getWidth(),
                'height' => $imageHelper->getHeight(),
            ],
            'canApplyMsrp' => $this->msrpHelper->isShowBeforeOrderConfirm($this->item->getProduct())
                && $this->msrpHelper->isMinimalPriceLessMsrp($this->item->getProduct()),
        ];
    }

And override this file in your theme

/Magento_Checkout/web/template/minicart/item/default.html

and add below code in file

<div class="sort-description" data-bind="html:sort_description"></div>

You will sure get description in minicart

OTHER TIPS

How can I get the value of short description instead a text line "sort-description"?

Thanks.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top