2

I have created a module with Custom/Module as {Namespace/Modulename},

app/code/Custom/Module/etc/di.xml

file,

<type name="Magento\Checkout\Block\Cart\AbstractCart">
        <plugin name="qty_hide" type="Custom\Module\Plugin\Cart\AbstractCart" sortOrder="1"/>
    </type>

Create plugin file at below location in your module,

app/code/Custom/Module/Plugin/Cart/AbstractCart.php

<?php
namespace deca\Servicefee\Plugin\Cart;
class AbstractCart
{
    /*
    *   Override cart/item/default.phtml file
    *   \Magento\Checkout\Block\Cart\AbstractCart $subject
    *   $result
    */
    public function afterGetItemRenderer(\Magento\Checkout\Block\Cart\AbstractCart $subject, $result)
    {
        $result->setTemplate('Custom_Module::cart/item/default.phtml');
        return $result;
    }
}

Finally created default.phtml template file in my module view folder,

app/code/Custom/Module/view/frontend/templates/cart/item/default.phtml

But geting below error `

1 exception(s):
Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: 'Custom_Module::cart/item/default.phtml' in module: 'Magento_Checkout' block's name: 'checkout.cart.item.renderers.simple'

Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: 'Custom_Module::cart/item/default.phtml' in module: 'Magento_Checkout' block's name: 'checkout.cart.item.renderers.simple'
#0 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Element/Template.php(300): Magento\Framework\View\Element\Template->fetchView(false)
#1 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Element/AbstractBlock.php(667): Magento\Framework\View\Element\Template->_toHtml()
#2 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/module-checkout/Block/Cart/AbstractCart.php(134): Magento\Framework\View\Element\AbstractBlock->toHtml()
#3 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/module-checkout/view/frontend/templates/cart/form.phtml(37): Magento\Checkout\Block\Cart\AbstractCart->getItemHtml(Object(Magento\Quote\Model\Quote\Item))
#4 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/home/193246.cl...')
#5 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Element/Template.php(270): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Checkout\Block\Cart\Grid\Interceptor), '/home/193246.cl...', Array)
#6 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Element/Template.php(300): Magento\Framework\View\Element\Template->fetchView('/home/193246.cl...')
#7 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Element/AbstractBlock.php(667): Magento\Framework\View\Element\Template->_toHtml()
#8 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(558): Magento\Framework\View\Element\AbstractBlock->toHtml()
#9 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(534): Magento\Framework\View\Layout->_renderBlock('checkout.cart.f...')
#10 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout->renderNonCachedElement('checkout.cart.f...')
#11 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('checkout.cart.f...')
#12 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(536): Magento\Framework\View\Layout->_renderContainer('checkout.cart.c...')
#13 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout->renderNonCachedElement('checkout.cart.c...')
#14 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('checkout.cart.c...')
#15 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(536): Magento\Framework\View\Layout->_renderContainer('checkout.cart.i...')
#16 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout->renderNonCachedElement('checkout.cart.i...')
#17 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Element/AbstractBlock.php(507): Magento\Framework\View\Layout->renderElement('checkout.cart.i...', true)
#18 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/module-checkout/view/frontend/templates/cart.phtml(15): Magento\Framework\View\Element\AbstractBlock->getChildHtml('with-items')
#19 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/home/193246.cl...')
#20 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Element/Template.php(270): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Checkout\Block\Cart\Interceptor), '/home/193246.cl...', Array)
#21 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Element/Template.php(300): Magento\Framework\View\Element\Template->fetchView('/home/193246.cl...')
#22 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Element/AbstractBlock.php(667): Magento\Framework\View\Element\Template->_toHtml()
#23 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(558): Magento\Framework\View\Element\AbstractBlock->toHtml()
#24 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(534): Magento\Framework\View\Layout->_renderBlock('checkout.cart')
#25 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout->renderNonCachedElement('checkout.cart')
#26 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('checkout.cart')
#27 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(536): Magento\Framework\View\Layout->_renderContainer('content')
#28 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout->renderNonCachedElement('content')
#29 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('content')
#30 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(536): Magento\Framework\View\Layout->_renderContainer('main')
#31 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout->renderNonCachedElement('main')
#32 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('main')
#33 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(536): Magento\Framework\View\Layout->_renderContainer('columns')
#34 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout->renderNonCachedElement('columns')
#35 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('columns')
#36 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(536): Magento\Framework\View\Layout->_renderContainer('main.content')
#37 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout->renderNonCachedElement('main.content')
#38 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('main.content')
#39 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(536): Magento\Framework\View\Layout->_renderContainer('page.wrapper')
#40 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout->renderNonCachedElement('page.wrapper')
#41 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('page.wrapper')
#42 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(536): Magento\Framework\View\Layout->_renderContainer('root')
#43 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout->renderNonCachedElement('root')
#44 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Layout.php(954): Magento\Framework\View\Layout->renderElement('root')
#45 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\Layout->getOutput()
#46 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\Layout\Interceptor->___callParent('getOutput', Array)
#47 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\Layout\Interceptor->Magento\Framework\Interception\{closure}()
#48 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/generated/code/Magento/Framework/View/Layout/Interceptor.php(39): Magento\Framework\View\Layout\Interceptor->___callPlugins('getOutput', Array, Array)
#49 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Result/Page.php(257): Magento\Framework\View\Layout\Interceptor->getOutput()
#50 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/View/Result/Layout.php(170): Magento\Framework\View\Result\Page->render(Object(Magento\Framework\App\Response\Http\Interceptor))
#51 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\Result\Layout->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#52 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\Result\Page\Interceptor->___callParent('renderResult', Array)
#53 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Response\Http\Interceptor))
#54 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/generated/code/Magento/Framework/View/Result/Page/Interceptor.php(26): Magento\Framework\View\Result\Page\Interceptor->___callPlugins('renderResult', Array, Array)
#55 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/App/Http.php(139): Magento\Framework\View\Result\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#56 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/vendor/magento/framework/App/Bootstrap.php(256): Magento\Framework\App\Http->launch()
#57 /home/193246.cloudwaysapps.com/zqesqtynyy/public_html/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))
#58 {main}

`

  • Have you created the template file (default.phtml) in following path custom/module/view/frontend/templates/cart/item/default.phtml – aravind Mar 6 at 4:31
  • Given answer it will work try it and let me know :) – Prathap Gunasekaran Mar 6 at 5:05
  • In the above code you namespace seem wrong instead of namespace deca\Servicefee\Plugin\Cart; it should be namespace Custom\Module\Plugin\Cart; May be you might have edited while adding question, I guess – Prathap Gunasekaran Mar 6 at 5:06
2

Try this,

Add checkout_cart_item_renderers.xml in the following path

app/code/Custom/Module/view/frontend/layout/checkout_cart_item_renderers.xml

then add the below code in it

<?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 name="checkout.cart.item.renderers.bundle" template="Custom_Module::cart/item/default.phtml" />
    <referenceBlock name="checkout.cart.item.renderers.virtual" template="Custom_Module::cart/item/default.phtml" />
    <referenceBlock name="checkout.cart.item.renderers.default" template="Custom_Module::cart/item/default.phtml" />
    <referenceBlock name="checkout.cart.item.renderers.simple" template="Custom_Module::cart/item/default.phtml" />
    <referenceBlock name="checkout.cart.item.renderers.configurable" template="Custom_Module::cart/item/default.phtml" />
    <referenceBlock name="checkout.cart.item.renderers.grouped" template="Custom_Module::cart/item/default.phtml" />                  
 </body>                                                                
</page>

then copy and file from vendor to your custom module in the below path

app/code/Custom/Module/view/frontend/templates/cart/item/default.phtml

Hope this helps :)

  • this solution is working for me also. But I need to overwrite through the plugin. And I already change the class name also. Still, it is not working for me. – Nilava Chakraborty Mar 6 at 5:30
0

To override the block containing the cart/item/default.phtml template can be found in

Magento/Checkout/view/frontend/layout/checkout_cart_item_renderers.xml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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