2

I have override two core checkout xml files for overriding default.phtml file in magento 2 as per the ref url - Overriding template not working in Magento 2

But when I add configurable product to my cart, then its global attributes like color and size are not visible on cart page.

app/code/XYZ/Checkout/view/frontend/layout/checkout_cart_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock class="Magento\Checkout\Block\Cart" name="checkout.cart.form">
            <block class="Magento\Framework\View\Element\RendererList" name="checkout.cart.item.renderers.override" as="renderer.list.custom"/>
            <arguments>
                <argument name="renderer_list_name" xsi:type="string">checkout.cart.item.renderers.override</argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

app/code/XYZ/Checkout/view/frontend/layout/checkout_cart_item_renderers.xml

<?xml version="1.0"?>
<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.override">

            <block class="Magento\Checkout\Block\Cart\Item\Renderer" as="default" template="XYZ_Checkout::cart/item/default.phtml" />              

            <block class="Magento\Checkout\Block\Cart\Item\Renderer" as="simple" template="XYZ_Checkout::cart/item/default.phtml" />   

        </referenceBlock>
    </body>
</page>

3 Answers 3

0

I have no idea if it's correct, but I had the same issue and this worked for me:

<referenceBlock name="checkout.cart.item.renderers.override">
  <block class="Magento\ConfigurableProduct\Block\Cart\Item\Renderer\Configurable" as="configurable" template="XYZ_Checkout::cart/item/default.phtml">
    <block class="Magento\Checkout\Block\Cart\Item\Renderer\Actions" name="checkout.cart.item.renderers.configurable.actions" as="actions">
      <block class="Magento\Checkout\Block\Cart\Item\Renderer\Actions\Edit" name="checkout.cart.item.renderers.configurable.actions.edit" template="Magento_Checkout::cart/item/renderer/actions/edit.phtml"/>
      <block class="Magento\Checkout\Block\Cart\Item\Renderer\Actions\Remove" name="checkout.cart.item.renderers.configurable.actions.remove" template="Magento_Checkout::cart/item/renderer/actions/remove.phtml"/>
    </block>
  </block>
  <block class="Magento\Checkout\Block\Cart\Item\Renderer" as="simple" template="XYZ_Checkout::cart/item/default.phtml" />  
  <block class="Magento\Checkout\Block\Cart\Item\Renderer" as="default" template="XYZ_Checkout::cart/item/default.phtml" />  
</referenceBlock>
0

Use this code in checkout_cart_item_renderers.xml

    <referenceBlock name="checkout.cart.item.renderers.configurable">
        <action method="setTemplate">
            <argument name="template" xsi:type="string">Xyz_Abc::cart/item/default.phtml</argument>
        </action>
    </referenceBlock>
0

Add this overridden template in the layout XML file. It's only for configurable products.

<referenceBlock name="checkout.cart.item.renderers">
        <block class="Magento\ConfigurableProduct\Block\Cart\Item\Renderer\Configurable" name="checkout.cart.item.renderers.configurable" as="configurable" template="YOURMODULE_CustomCart::cart/item/default.phtml">
            <block class="Magento\Checkout\Block\Cart\Item\Renderer\Actions" name="checkout.cart.item.renderers.configurable.actions" as="actions">
                <block class="Magento\Checkout\Block\Cart\Item\Renderer\Actions\Edit" name="checkout.cart.item.renderers.configurable.actions.edit" template="YOURMODULE_CustomCart::cart/item/renderer/actions/edit.phtml"/>
                <block class="Magento\Checkout\Block\Cart\Item\Renderer\Actions\Remove" name="checkout.cart.item.renderers.configurable.actions.remove" template="YOURMODULE_CustomCart::cart/item/renderer/actions/remove.phtml"/>
            </block>
        </block>
    </referenceBlock>

It's working for me 100% tested. If this help to you give upwards. Thank you.

Your Answer

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

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