#StackBounty: #magento2 #layout #template #overrides #upgrade Can't override template from own module

Bounty: 50

It seems to be impossible to override the template vendormagentomodule-checkoutviewfrontendtemplatescartitemrendereractionsedit.phtml from your own module e.g. by using layout updates.

(The template shows the edit button near quote items in the cart)

Preconditions:

Magento 2.3.5-p2

Steps to reproduce:

  1. Create own module (In my case: Company_Configurator)
  2. Create Template file: appcodeCompanyConfiguratorviewfrontendtemplatescartitemrendereractionsedit.phtml and change content.
  3. Create layout update file appcodeCompanyConfiguratorviewfrontendlayoutcheckout_cart_item_renderers.xml with following content:
<?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="checkout.cart.item.renderers.simple.actions.edit">
            <arguments>
                <argument name="template" xsi:type="string">Company_Configurator::cart/item/renderer/actions/edit.phtml</argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

Attempt 2:

I even tried to extend the block class, override it with dependency injection and then set the template:

app/code/Company/Configurator/etc/frontend/di.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="MagentoCheckoutBlockCartItemRendererActionsEdit"
                type="CompanyConfiguratorBlockCartItemRendererActionsEdit" />
</config>

appcodeCompanyConfiguratorBlockCartItemRendererActionsEdit.php

namespace CompanyConfiguratorBlockCartItemRendererActions;

class Edit extends MagentoCheckoutBlockCartItemRendererActionsEdit
{
    protected $_template = 'Company_Configurator::cart/item/renderer/actions/edit.phtml';

    function __construct(MagentoFrameworkViewElementTemplateContext $context, array $data = [])
    {
        parent::__construct($context, $data);
    }

    ...

}

Expected result:

Template should get changed to own template.

Actual result:

Old template is still loading.

Please Help


Get this bounty!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.