1

I can't find the phtml template for the minicart in the header, I think actually that the information like name, price, quantity etc are rendered with knockout js.

I want to add brand attribute value and sku under the name of each product.

How can I do that? Where are the files that I should override

Thanks!

2 Answers 2

3

Yes you have to override the following template

/vendor/magento/module-checkout/view/frontend/web/template/minicart/item/default.html 

and create a plugin for the function getItemData() of the class

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

so you can provide the additional data to the template. Check this post for more details about how you can extend the mini cart.

4
  • thanks, the post you linked it was helpful, it works adding the value from custom attribute for every product Commented Oct 25, 2017 at 11:19
  • What if I want 2 custom attributes, brand and some other. What should I change in the plugin files? Commented Oct 25, 2017 at 14:21
  • Add your other custom attribute at catalog_attributes.xml and also in the aroundGetItemData() function. Finally display it in the template default.html like is done for manufacturer.
    – Nikolas
    Commented Oct 25, 2017 at 14:36
  • I don't know exactly how should i return both values in aroundGetItemData(). Because i have the var $data and I don't understand exactly what is stored here.. Commented Oct 26, 2017 at 8:51
2

Override vendor/magento/module-checkout/view/frontend/web/template/minicart/item/default.html

in app/design/frontend/your_vendor/your_theme/Magento_Checkout/web/template/minicart/item/default.html

find below code

<strong class="product-item-name">
    <!-- ko if: product_has_url -->
    <a data-bind="attr: {href: product_url}, text: product_name"></a>
    <!-- /ko -->
    <!-- ko ifnot: product_has_url -->
        <!-- ko text: product_name --><!-- /ko -->
    <!-- /ko -->
</strong>

and replace above code with this

<strong class="product-item-name">
    <!-- ko if: product_has_url -->
    <a data-bind="attr: {href: product_url}, text: product_name"></a>
    <a data-bind="attr: {href: product_url}, text: product_sku"></a>
    <!-- /ko -->
    <!-- ko ifnot: product_has_url -->
        <!-- ko text: product_name --><!-- /ko -->
        <!-- ko text: product_sku --><!-- /ko -->
    <!-- /ko -->
</strong>

Now run php bin/magento setup:static-content:deploy command

For adding more product attributes in minicart, please refer protected function doGetItemData() in vendor/magento/module-checkout/CustomerData/DefaultItem.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.