magento2: Can't override knockoutjs template
Preconditions (*)
- 2.4.2 EE
Steps to reproduce (*)
I try to override the knockoutjs template vendor\amasty\module-single-step-checkout\view\frontend\web\template\checkout\summary\item\details.html from my own Theme.
The module amasty\module-single-step-checkout is registered as Amasty_Checkout
Attempt 1:
I copied the file into my theme at THEME\Amasty_Checkout\web\template\checkout\summary\item\details.html and made my changes, then I flushed the cache and the browser cache, but it still loads the old template.
I also executed grunt clean to clear static files. But it does not help either.
Attempt 2:
-
THEME\Company_Base\web\template\details.html (Copied from
THEME\Amasty_Checkout\web\template\checkout\summary\item\details.html) -
THEME\Amasty_Checkout\layout\checkout_index_index.xml:
<?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" layout="checkout" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.root">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="checkout" xsi:type="array">
<item name="children" xsi:type="array">
<item name="sidebar" xsi:type="array">
<item name="children" xsi:type="array">
<item name="summary" xsi:type="array">
<item name="children" xsi:type="array">
<item name="cart_items" xsi:type="array">
<item name="children" xsi:type="array">
<item name="details" xsi:type="array">
<item name="config" xsi:type="array">
<!-- Assigning a new template -->
<!--<item name="elementTmpl" xsi:type="string">Company_Base/details</item>-->
<item name="template" xsi:type="string">Company_Base/details</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>
Additional Information:
The template is set in the file vendor\amasty\module-single-step-checkout\view\frontend\web\js\view\checkout\summary\item\details.js:
/*jshint browser:true jquery:true*/
/*global alert*/
define(
[
'jquery',
'Magento_Checkout/js/view/summary/item/details',
'Magento_Checkout/js/model/quote',
'Magento_Ui/js/modal/confirm',
'Amasty_Checkout/js/action/remove-item',
'Amasty_Checkout/js/action/update-item',
'mage/translate',
'ko',
'Amasty_Checkout/js/options/configurable',
'priceOptions',
'mage/validation'
],
function ($, Component, quote, confirm, removeItemAction, updateItemAction, $t, ko, configurable, priceOptions) {
"use strict";
return Component.extend({
defaults: {
template: 'Amasty_Checkout/checkout/summary/item/details'
},
...
Expected result (*)
- Template should get overridden
Actual result (*)
- Template is not getting overridden
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 20 (10 by maintainers)
I have the same problem right now, tried to override
vendor/magento/module-tax/view/frontend/web/template/checkout/summary/shipping.htmlvia theme and it does not work.In case this helps anyone, I just found out that Amasty’s own template file in
view/frontend/web/template/checkout/summary/item/details.htmlis only loaded when “Allow to Edit Products in the Order Summary” is set to YES. If it is set to no then Magento’s own file is loaded.Im running Magento 2.3.3 and Amasty Checkout 3.0.13
cc @Eddcapone If you need any further discuss please ping me or DMs to me on slack (https://magentocommeng.slack.com) or skype (see my profile).
@mrtuvn ok thanks, but are you sure that this is not a bug? You can override templates by placing them in your own theme. I also managed to do this with .phtml and .html but in this case it just does not work. Maybe because the template is hardcoded into the .js view model file? You can’t even override it from a layout file. This looks like a bug to me. It should get programmed properly, so that you can override it from a layout file at least.