1

I tried to create a layout and phtml template and a block for add something to cart view page.

I added something, but When I want to choose referenceBlock the content disappear.

Actually I'm going to add some column like price and number to cart table view, but I think it could not find the block! I appreciate any help of you

Here is my code:

MagenCheckout/CheckoutField/Block/Productpoint.php`

<?php

namespace MagenCheckout\CheckoutField\Block;

class Productpoint extends \Magento\Framework\View\Element\Template
{

   public function __construct(
    \Magento\Framework\View\Element\Template\Context $context,
    array $data = [])
    {
       parent::__construct($context, $data);
    }
}

MagenCheckout/CheckoutField/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="MagenCheckout_CheckoutField" setup_version="0.0.8">
    <sequence>
        <module name="Magento_Customer"/>
    </sequence>
</module>

MagenCheckout/CheckoutField/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 name="checkout.cart.form">
        <block class="MagenCheckout\CheckoutField\Block\Productpoint" name="cart_item_addional_info" template="MagenCheckout_CheckoutField::checkout/cart/productpoint.phtml"/>
    </referenceBlock>
   </body>
</page>

MagenCheckout/CheckoutField/view/frontend/templates/checkout/cart/productpoint.phtml

<p>
   <?php echo 'Your Discount'; ?>
</p>

MagenCheckout/CheckoutField/registration.php

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE, 'MagenCheckout_CheckoutField',
__DIR__
);
2

You can try this.

  1. Update MagenCheckout/CheckoutField/etc/module.xml to

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
        <module name="MagenCheckout_CheckoutField" setup_version="0.0.8">
           <sequence>
            <module name="Magento_Customer"/>
            <module name="Magento_Checkout"/>
           </sequence>
        </module>
    </config>
    
  2. Update MagenCheckout/CheckoutField/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 name="checkout.cart.form">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">MagenCheckout_CheckoutField::cart/form.phtml</argument>
            </action>
            <block class="MagenCheckout\CheckoutField\Block\Productpoint" name="cart_item_addional_info" template="MagenCheckout_CheckoutField::checkout/cart/productpoint.phtml"/>
           </referenceBlock>
       </body>
    </page>
    
  3. Copy vendor/magento/module-checkout/view/frontend/templates/cart/form.phtml to MagenCheckout/CheckoutField/view/frontend/templates/cart/form.phtml, and place this code to the end of file

    <?php echo $block->getChildHtml('cart_item_addional_info'); ?>
    
| improve this answer | |
  • You mean I should edit form.phtml file in magento core? – M Taheri Sep 26 '17 at 7:39
  • @MTaheri of course not :) you should override it in your own module or in your theme. – Quan Le Sep 26 '17 at 7:45
  • Actually I'm new to magento. :-| Could you please explain more about how should I override form.phtml in my module? – M Taheri Sep 26 '17 at 7:55
  • @MTaheri I've updated the answer, could you try it and tell me the result :) – Quan Le Sep 26 '17 at 8:23
  • quan-le Thank you for your reply, my cart table disappeared now! I don't know the problem – M Taheri Sep 26 '17 at 8:44

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.