I would like to add a custom block next to each item displayed in the shopping cart, which has access to the properties of the specific product it has access to.

Since, this is a part of a plugin, I need to do so without hardcoding anything into core files, i.e. only through the use of layout.xml/event handlers. Any other way which does not involve modifying Magento files.

For example: adding a button which displays itself next to each item in the shopping cart, and performs an action on the SKU of the particular product it is displayed next to.

I will post a screenshot of what I mean shortly.

Just to be clear I do not want to override the existing block, I want to "add" to it

  • anyone have any working ideas? – anant Nov 24 '16 at 11:29

In your module's layout xml file:

    <reference name="checkout.cart">
        <action method="addItemRender"><type>simple</type><block>checkout/cart_item_renderer</block><template>custom/cart/item/default.phtml</template></action>
        <action method="addItemRender"><type>grouped</type><block>checkout/cart_item_renderer_grouped</block><template>custom/cart/item/default.phtml</template></action>
        <action method="addItemRender"><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>custom/cart/item/default.phtml</template></action>

And then override the magento cart render template by copying checkout/cart/item/default.phtml to custom/cart/item/default.phtml. Now you have access to the product by using $_item->getProduct() in your phtml.

  • but doesnt this involve changing core functionality, or can it be packed inside a plugin too? – anant Oct 6 '16 at 12:15
  • In this case we are not changing any core files, what we are doing is just overriding the template with a new one. Also, Yes, you can pack this in an extension by a adding the above xml to that modules layout file. – Nidheesh Oct 6 '16 at 12:23
  • but since we are copying files from one location to another, and modifying the default.phtml file, if there are updates to magento, or other changes made to the default.phtml file in the original folder, wont there be clashes? for instance if the user decides to hardcode stuff into the default.phtml file in the checkout/cart/item/default.phtml, but since our plugin is now using custom/cart/item/default.phtml, the changes wont show up now right? – anant Oct 6 '16 at 12:25
  • also i guess we have to include the default.phtml file manually right?, what if the installers default.phtml file differs from the one i include inside the plugin? – anant Oct 6 '16 at 12:28
  • The one in plugin will override installed default.html – Nidheesh Oct 6 '16 at 12:54

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.