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

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.

  • thanks, the post you linked it was helpful, it works adding the value from custom attribute for every product – Raluca Albu Oct 25 '17 at 11:19
  • What if I want 2 custom attributes, brand and some other. What should I change in the plugin files? – Raluca Albu Oct 25 '17 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 Oct 25 '17 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.. – Raluca Albu Oct 26 '17 at 8:51
1

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, privacy policy and cookie policy

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