Question

I'm trying to add a block to my Header that displays Cart information.
I'm not getting any display from this block as of yet.

Here's my checkout.xml:

<reference name="header">
    <block type="checkout/cart_sidebar" name="checkout.basket" as="checkoutBasket" />
</reference>

Here's my basket.phtml:

<script>alert("TEST");</script>
<div class="block checkout-basket">
    TEST
</div>

Here's my header.phtml:

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

I'm fairly new to Magento and it's Block system so I'm not sure I've joined up all the dots correctly to get this block to display.

Was it helpful?

Solution

There template file is missing in the code of xml

 <block type="checkout/cart_sidebar" name="checkout.basket" as="checkoutBasket" template="pathoftemplate/basket.phtml" />

if you want to show all cart item just like default then

<block type="checkout/cart_sidebar" name="checkout.basket" as="checkoutBasket" template="pathoftemplate/basket.phtml">
<action method="addItemRender"><type>simple</type><block>checkout/cart_item_renderer</block><template>checkout/cart/sidebar/default.phtml</template></action>
                <action method="addItemRender"><type>grouped</type><block>checkout/cart_item_renderer_grouped</block><template>checkout/cart/sidebar/default.phtml</template></action>
                <action method="addItemRender"><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>checkout/cart/sidebar/default.phtml</template></action>
                <block type="core/text_list" name="cart_sidebar.extra_actions" as="extra_actions" translate="label" module="checkout">
                    <label>Shopping Cart Sidebar Extra Actions</label>
                </block>

And code must be add in basket.phtml

<?php if ($this->getIsNeedToDisplaySideBar()):?>
<div class="block block-cart">
    <?php $_cartQty = $this->getSummaryCount() ?>
    <div class="block-title">
        <strong><span><?php echo $this->__('My Cart') ?></span></strong>
    </div>
    <div class="block-content">
    <?php if ($_cartQty>0): ?>
        <div class="summary">
            <?php if ($_cartQty==1): ?>
                <p class="amount"><?php echo $this->__('There is <a href="%s">1 item</a> in your cart.', $this->getUrl('checkout/cart')) ?></p>
            <?php else: ?>
                <p class="amount"><?php echo $this->__('There are <a href="%s">%s items</a> in your cart.', $this->getUrl('checkout/cart'), $_cartQty) ?></p>
            <?php endif ?>
            <p class="subtotal">
                <?php if ($this->canApplyMsrp()): ?>
                    <span class="map-cart-sidebar-total"><?php echo $this->__('ORDER TOTAL WILL BE DISPLAYED BEFORE YOU SUBMIT THE ORDER'); ?></span>
                <?php else: ?>
                    <span class="label"><?php echo $this->__('Cart Subtotal:') ?></span> <?php echo Mage::helper('checkout')->formatPrice($this->getSubtotal()) ?>
                    <?php if ($_subtotalInclTax = $this->getSubtotalInclTax()): ?>
                        <br />(<?php echo Mage::helper('checkout')->formatPrice($_subtotalInclTax) ?> <?php echo Mage::helper('tax')->getIncExcText(true) ?>)
                    <?php endif; ?>
                <?php endif; ?>
            </p>
        </div>
    <?php endif ?>
    <?php if($_cartQty && $this->isPossibleOnepageCheckout()): ?>
    <div class="actions">
        <?php echo $this->getChildHtml('extra_actions') ?>
        <button type="button" title="<?php echo $this->__('Checkout') ?>" class="button" onclick="setLocation('<?php echo $this->getCheckoutUrl() ?>')"><span><span><?php echo $this->__('Checkout') ?></span></span></button>
    </div>
    <?php endif ?>
    <?php $_items = $this->getRecentItems() ?>
    <?php if(count($_items)): ?>
        <p class="block-subtitle"><?php echo $this->__('Recently added item(s)') ?></p>
        <ol id="cart-sidebar" class="mini-products-list">
        <?php foreach($_items as $_item): ?>
            <?php echo $this->getItemHtml($_item) ?>
        <?php endforeach; ?>
        </ol>
        <script type="text/javascript">decorateList('cart-sidebar', 'none-recursive')</script>
    <?php else: ?>
        <p class="empty"><?php echo $this->__('You have no items in your shopping cart.') ?></p>
    <?php endif ?>
    </div>
</div>
<?php endif;?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top