5

I am working on a custom extension and I want to add additional block to the /checkout/cart/ page.

Take a look: enter image description here

Here is my config:

<?xml version="1.0"?>
<config>
  <modules>
    <VivasIndustries_ExpressDelivery>
      <version>1.0.0</version>
    </VivasIndustries_ExpressDelivery>
  </modules>
  <global>
    <models>
        <expressdelivery>
            <class>VivasIndustries_ExpressDelivery_Model</class>
            <resourceModel>vivasindustries_expressdelivery_resource</resourceModel>
        </expressdelivery>
        <vivasindustries_expressdelivery_resource>
        <class>VivasIndustries_ExpressDelivery_Model_Resource</class>
        <entities>
            <expressdelivery>
            <table>VivasIndustries_ExpressDelivery</table>
            </expressdelivery>
        </entities>
        </vivasindustries_expressdelivery_resource>
    </models>
    <resources>
        <expressdelivery_setup>
            <setup>
                <module>VivasIndustries_ExpressDelivery</module>
            </setup>
            <connection>
                 <use>core_setup</use>
             </connection>
        </expressdelivery_setup>
        <expressdelivery_read>
            <connection>
                <use>core_read</use>
            </connection>
        </expressdelivery_read>
        <expressdelivery_write>
            <connection>
                <use>core_write</use>
            </connection>
        </expressdelivery_write>
    </resources>    
    <helpers>
        <expressdelivery>
            <class>VivasIndustries_ExpressDelivery_Helper</class>
        </expressdelivery>
    </helpers>
    <blocks>
        <expressdelivery>
             <class>VivasIndustries_ExpressDelivery_Block</class>
        </expressdelivery>
    </blocks>
  </global>
  <adminhtml>
    <acl>
        <resources>
            <all>
                <title>Allow Everything</title>
            </all>
            <admin>
                <children>
                    <system>
                        <children>
                            <config>
                                <children>
                                    <expressdeliveryadmin>
                                        <title>Vivas - All</title>
                                    </expressdeliveryadmin>
                                </children>
                            </config>
                        </children>
                    </system>
                </children>
            </admin>
        </resources>
    </acl>
    <layout>
        <updates>
            <expressdelivery>
                <file>expressdelivery.xml</file>
            </expressdelivery>
        </updates>
    </layout>   
    </adminhtml>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <VivasIndustries_ExpressDelivery before="Mage_Adminhtml">VivasIndustries_ExpressDelivery_Adminhtml</VivasIndustries_ExpressDelivery>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
</config> 

Here is my layout:

<?xml version="1.0"?>
<layout version="1.0.0">
    <checkout_cart_index>
         <reference name="checkout.cart">
            <block type="core/template" name="expressdelivery_ccart" template="expressdelivery/cart.phtml" />
        </reference>
    </checkout_cart_index>
</layout>

Here is my phtml Block located in /app/design/frontend/base/default/template/expressdelivery/cart.phtml:

This is a test!

And this simple text does not appear, why ?

My /checkout/cart.phtml :

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to [email protected] so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     rwd_default
 * @copyright   Copyright (c) 2014 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
/**
 * Shopping cart template
 *
 * @var $this Mage_Checkout_Block_Cart
 */
?>
<?php $_priceDisplay = ($this->helper('tax')->displayCartBothPrices()) ? 'display-both-prices' : 'display-single-price'; ?>
<div class="cart <?php echo $_priceDisplay; ?>">
    <div class="page-title title-buttons">
        <h1><?php echo $this->__('Shopping Cart') ?></h1>
        <?php if(!$this->hasError()): ?>
        <ul class="checkout-types top">
        <?php foreach ($this->getMethods('top_methods') as $method): ?>
            <?php if ($methodHtml = $this->getMethodHtml($method)): ?>
            <li><?php echo $methodHtml; ?></li>
            <?php endif; ?>
        <?php endforeach; ?>
        </ul>
        <?php endif; ?>
    </div>
    <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
    <?php echo $this->getChildHtml('form_before') ?>
    <form action="<?php echo $this->getUrl('checkout/cart/updatePost') ?>" method="post">
        <?php echo $this->getBlockHtml('formkey'); ?>
        <table id="shopping-cart-table" class="cart-table data-table">
            <col width="1" />
            <col width="1" />
            <col width="1" />
            <col width="1" />
            <col width="1" />
            <col width="1" />
            <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
            <col width="1" />
            <col width="1" />
            <?php endif; ?>

        <?php $mergedCells = ($this->helper('tax')->displayCartBothPrices() ? 2 : 1); ?>
            <thead>
                <tr>
                    <th rowspan="<?php echo $mergedCells; ?>"><span class="nobr"><?php echo $this->__('Product') ?></span></th>

                    <th rowspan="<?php echo $mergedCells; ?>">&nbsp;</th>

                    <th class="a-center cart-price-head" colspan="<?php echo $mergedCells; ?>">
<!--                            <div class="cart-price-placeholder">-->
                            <span class="nobr"><?php echo $this->__('Price') ?></span>
<!--                            </div>-->
                    </th>

                    <th rowspan="<?php echo $mergedCells; ?>" class="a-center">
                        <?php echo $this->__('Qty') ?>

                        <?php /*if ($this->helper('wishlist')->isAllowInCart()) : ?>
                            <span class="nobr"><?php echo $this->__('Move to Wishlist') ?></span>
                        <?php endif*/ ?>

                    </th>

                    <th class="a-center cart-total-head" colspan="<?php echo $mergedCells; ?>">
<!--                            <div class="cart-total-placeholder">-->
                            <?php echo $this->__('Subtotal') ?>
<!--                            </div>-->
                    </th>

                    <th class="a-center" rowspan="<?php echo $mergedCells; ?>">&nbsp;</th>

                </tr>
                <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
                <tr>
                    <th class="a-center cart-price-head"><?php echo $this->helper('tax')->getIncExcTaxLabel(false) ?></th>
                    <th class="a-center cart-price-head"><?php echo $this->helper('tax')->getIncExcTaxLabel(true) ?></th>
                    <th class="a-center cart-total-head"><?php echo $this->helper('tax')->getIncExcTaxLabel(false) ?></th>
                    <th class="a-center cart-total-head"><?php echo $this->helper('tax')->getIncExcTaxLabel(true) ?></th>
                </tr>
                <?php endif; ?>
            </thead>
            <tfoot>
                <tr>
                    <td colspan="50" class="a-right cart-footer-actions">

                        <!-- Make this button the first responder rather than empty cart -->
                        <button type="submit" style="visibility:hidden;" name="update_cart_action" value="update_qty" title="<?php echo $this->__('Update Shopping Cart'); ?>" class="button2 btn-update"><span><span><?php echo $this->__('Update Shopping Cart'); ?></span></span></button>

                        <button type="submit" name="update_cart_action" value="empty_cart" title="<?php echo $this->__('Empty Cart'); ?>" class="button2 btn-empty" id="empty_cart_button"><span><span><?php echo $this->__('Empty Cart'); ?></span></span></button>

                        <button type="submit" name="update_cart_action" value="update_qty" title="<?php echo $this->__('Update Shopping Cart'); ?>" class="button2 btn-update"><span><span><?php echo $this->__('Update Shopping Cart'); ?></span></span></button>

                        <!--<span class="or">-or-</span>-->

                        <?php if($this->getContinueShoppingUrl()): ?>
                            <a href="./../../" style="font-family:Verdana; display:block; text-transform:uppercase; text-decoration:none;"><?php echo $this->__('Continue Shopping') ?></a>
                        <?php endif; ?>
                        <!--[if lt IE 8]>
                        <input type="hidden" id="update_cart_action_container" />
                        <script type="text/javascript">
                        //<![CDATA[
                            Event.observe(window, 'load', function()
                            {
                                // Internet Explorer (lt 8) does not support value attribute in button elements
                                $emptyCartButton = $('empty_cart_button');
                                $cartActionContainer = $('update_cart_action_container');
                                if ($emptyCartButton && $cartActionContainer) {
                                    Event.observe($emptyCartButton, 'click', function()
                                    {
                                        $emptyCartButton.setAttribute('name', 'update_cart_action_temp');
                                        $cartActionContainer.setAttribute('name', 'update_cart_action');
                                        $cartActionContainer.setValue('empty_cart');
                                    });
                                }

                            });
                        //]]>
                        </script>
                        <![endif]-->
                    </td>
                </tr>
            </tfoot>
            <tbody>
            <?php foreach($this->getItems() as $_item): ?>
                <?php echo $this->getItemHtml($_item) ?>
            <?php endforeach ?>
            </tbody>
        </table>
        <script type="text/javascript">decorateTable('shopping-cart-table')</script>
    </form>

    <?php echo $this->getChildHtml('shopping.cart.table.after'); ?>
    <div class="cart-forms">
        <?php /* Extensions placeholder */ ?>
        <?php echo $this->getChildHtml('checkout_cart_widget') ?>
        <?php echo $this->getChildHtml('coupon') ?>
        <?php echo $this->getChildHtml('checkout.cart.extra') ?>
    </div>
    <div class="cart-totals-wrapper">
        <div class="cart-totals">
            <?php echo $this->getChildHtml('totals'); ?>
            <?php if(!$this->hasError()): ?>
            <ul class="checkout-types bottom">
            <?php foreach ($this->getMethods('methods') as $method): ?>
                <?php if ($methodHtml = $this->getMethodHtml($method)): ?>
                <li class="method-<?php echo preg_replace("/[^_a-zA-Z0-9-]/", '-', $method); ?>"><?php echo $methodHtml; ?></li>
                <?php endif; ?>
            <?php endforeach; ?>
            </ul>
            <?php endif; ?>
        </div>
    </div>
    <?php echo $this->getChildHtml('expressdelivery_ccart'); ?>
    <?php echo $this->getChildHtml('crosssell') ?>
</div>

How can I add a custom block below that block? Can anybody please help me out?

Thanks in advance!

2
  • show you update layout xml. You need write like <checkout_cart_index><reference name='content'><block name='blabla' type='yourmoduel/block' etc...></reference></checkout_cart_index>
    – Naumov
    Commented Jul 11, 2016 at 9:49
  • Can you form a complete answer so i can mark it ? Commented Jul 11, 2016 at 9:55

1 Answer 1

6

First you need to add the following to your config.xml under the <config> tag:

<frontend>
    <layout>
        <updates>
            <expressdelivery>
                <file>expressdelivery.xml</file>
            </expressdelivery>
        </updates>
    </layout>
</frontend>

Then you need to create your layout file app/design/frontend/base/default/layout/expressdelivery.xml with the following content:

<?xml version="0.1.0">
<layout version="0.1.0">

    <checkout_cart_index>
         <reference name="checkout.cart">
              <block type="core/template" name="extra_block" template="link/to/your/template" />
         </reference>
    </checkout_cart_index>

</layout>

Then in your app/design/frontend/<your_package>/<your_theme>/template/checkout/cart.phtml you'll need to add the following code:

<?php echo $this->getChildHtml('extra_block'); ?>

Before this code:

<?php echo $this->getChildHtml('crosssell') ?>
5
  • if added output='toHtml' in block when render to be automaticaly.
    – Naumov
    Commented Jul 11, 2016 at 10:07
  • I have done all what you say but it is not working. Anything does not appear. Commented Jul 11, 2016 at 10:10
  • @TonyStark what did you write in your template ? Commented Jul 11, 2016 at 10:13
  • @TonyStark this answer correct, but you need determine reference block. You can enable show block hits in admin->system->configuration->for develop chose store view and enable block hints option. After refrash page and look in when block you whant past you block. Find this block in layouts file in layout/ directory rwd themes, get the name. And correct reference name=''needed_block' and write options output='toHtml' in you layout update file... p.s. sorry for my English.
    – Naumov
    Commented Jul 11, 2016 at 10:15
  • @TonyStark I've updated my answer, a part of XML is missing in your config Commented Jul 11, 2016 at 10:19

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.