I'm trying to override minicart.phtml file from Magento2\vendor\magento\module-checkout\view\frontend\templates\cart\minicart.phtml
to my custom module
Magento2\vendor\XXXX\YYYY\view\frontend\templates\cart\minicart.phtml
I copied everything from default.xml from Magento2\vendor\magento\module-checkout\view\frontend\layout\default.xml
to my custom module layout Magento2\vendor\XXXX\YYYY\view\frontend\layout\default.xml
with my custom template file path. Below is the layout file with Updated template path,
<?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">
<update handle="checkout_cart_sidebar_item_renderers"/>
<update handle="checkout_cart_sidebar_item_price_renderers"/>
<update handle="checkout_cart_sidebar_total_renderers"/>
<body>
<referenceBlock name="head.components">
<block class="Magento\Framework\View\Element\Js\Components" name="checkout_page_head_components" template="Magento_Checkout::js/components.phtml"/>
</referenceBlock>
<referenceContainer name="header-wrapper">
<block class="Magento\Checkout\Block\Cart\Sidebar" name="minicart" as="minicart" after="logo" template="XXXXXX_YYYYYY::cart/minicart.phtml">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="types" xsi:type="array"/>
<item name="components" xsi:type="array">
<item name="minicart_content" xsi:type="array">
<item name="component" xsi:type="string">Magento_Checkout/js/view/minicart</item>
<item name="config" xsi:type="array">
<item name="template" xsi:type="string">Magento_Checkout/minicart/content</item>
</item>
<item name="children" xsi:type="array">
<item name="subtotal.container" xsi:type="array">
<item name="component" xsi:type="string">uiComponent</item>
<item name="config" xsi:type="array">
<item name="displayArea" xsi:type="string">subtotalContainer</item>
</item>
<item name="children" xsi:type="array">
<item name="subtotal" xsi:type="array">
<item name="component" xsi:type="string">uiComponent</item>
<item name="config" xsi:type="array">
<item name="template" xsi:type="string">Magento_Checkout/minicart/subtotal</item>
</item>
</item>
</item>
</item>
<item name="extra_info" xsi:type="array">
<item name="component" xsi:type="string">uiComponent</item>
<item name="config" xsi:type="array">
<item name="displayArea" xsi:type="string">extraInfo</item>
</item>
</item>
<item name="promotion" xsi:type="array">
<item name="component" xsi:type="string">uiComponent</item>
<item name="config" xsi:type="array">
<item name="displayArea" xsi:type="string">promotion</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
<container name="minicart.addons" label="Mini-cart promotion block"/>
</block>
</referenceContainer>
</body>
</page>
Here you can see my updated template path,
<block class="Magento\Checkout\Block\Cart\Sidebar" name="minicart" as="minicart" after="logo" template="XXXXXX_YYYYYY::cart/minicart.phtml">
Then I cleared cache, upgrade, static content deploy .. Then I'm getting below error in store front.
Uncaught TypeError: Unable to process binding "if: function(){return getCartParam('summary_count') }"
Message: Unable to process binding "foreach: function(){return { data:getCartItems(),as:'item'} }"
Message: Unable to process binding "foreach: function(){return $parent.getRegion($parent.getItemRenderer(item.product_type)) }"
Message: Cannot read property 'simple' of undefined
at UiClass.getItemRenderer (minicart.js:139)
at foreach (eval at createBindingsStringEvaluator (knockout.js:2624), <anonymous>:3:93)
I put some logs in minicart.phtml and its loading . It's seems like minicart js is not loading properly…Any idea .?
Update:1
I put some logs in minicart.js
and it's loading. So I think it might have problem with content.html
. I'm using Magento 2.2.5 with default Luma theme
Best Answer
You can also try below method to override minicart.phtml
Go to :
and copy minicart.phtml file
After keep that file here
Clear cache and check...