2

I have Magento 2.2.4 version, And I want to overwrite Magento_Checkout/template/minicart/item/default.html file in my custom module. For this, I created require-jsconfig.js file at below path

/app/code/Namespace/Module/view/frontend/requirejs-config.js

var config = {
    map: {
        '*': {
          'Magento_Checkout/template/minicart/item/default.html': 'Namespace_Module/template/minicart/item/default.html'
        }
  }
};

removed "var" folder from root and remove "pub/static/frontend" folder and run below command:

php bin/magento setup:static-content:deploy

But mini cart is showing blank. Can anyone help me to understand my mistake?

2 Answers 2

1

Magento provides requirejs-config.js files for overriding the js & html file to enhance the functionality of the existing js & html files by simply manipulating them into your custom module.

To do that just follow the following guidelines.

  • Create & register your custom module & create requirejs-config.js file at below location

Magento_root/app/code/Vendor/Module/view/frontend/requirejs-config.js

And below code in your requirejs-config.js

var config = {
    map: {
        '*': {
          'Magento_Checkout/template/minicart/item/default.html': 
              'Vendor_Module/template/minicart/item/default.html'
        }
  }
};

If you required to do very minor changes then instead of creating a module you can directly do that by simply overriding it with the help of your theme. For that just follow the below guidelines.

  • Just copy the file from the below location

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

  • Place it into your custom theme at the below location & make your changes there into that file

Magento_root/app/design/Vendor/theme/Magento_Checkout/web/template/minicart/item/default.html

So we can override any html file in this way.

Note: After making the changes to deploy it properly please run the below commands

php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento c:f                     
8
  • 1
    I tried to overwrite through requirejs-config.js not working Mar 6, 2019 at 10:15
  • Did you checked that is it calling your page or the default old page there in your cart section? try to make different changes into both of them & see which change is coming there. try to deploy your static content & before that delete the generated folder & the var/cache folder contents. Mar 6, 2019 at 10:20
  • After doing that I checked, it is calling the default file only. Not the updated one. But I can able to see my updated code under pub/static section. And I run below all command rm -rf pub/static/frontend/ , rm -rf var/, rm -rf generated/, php bin/magento setup:upgrade, php bin/magento setup:di:compile, php bin/magento setup:static-content:deploy, php bin/magento indexer:reindex, php bin/magento cache:clean, php bin/magento cache:flush Mar 6, 2019 at 11:05
  • Are you working on your local system or on the server? If you are working on the server then there is a possibility that some cache is set there try to remove that cache & also try with different browsers or browsers into incognito/safe mode because it can be possible that your browser cache is loading the old data! Mar 6, 2019 at 11:25
  • I am working on a server and open site in incognito/safe mode only Mar 6, 2019 at 11:27
0

You can also check xml file here

vendor/magento/module-checkout/view/frontend/layout/checkout_cart_sidebar_item_renderers.xml

in line 27

<item name="template" xsi:type="string">Magento_Checkout/minicart/item/default</item>

You have to create same file in your module vendor/module/view/frontend/layout/checkout_cart_sidebar_item_renderers.xml and add this content to it

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="minicart">
            <arguments>
                <argument name="jsLayout" xsi:type="array">
                    <item name="components" xsi:type="array">
                        <item name="minicart_content" xsi:type="array">
                            <item name="children" xsi:type="array">
                                <item name="item.renderer" xsi:type="array">
                                    <item name="config" xsi:type="array">
                                        <item name="template" xsi:type="string">vendor_module/minicart/item/default</item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </item>
                </argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

Your Answer

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

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