将Checkout块添加到标题

时间:2014-02-17 11:18:51

标签: magento layout block checkout

我正在尝试在显示购物车信息的标题中添加一个块 我还没有从这个区块中获得任何显示。

这是我的checkout.xml:

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

这是我的basket.phtml:

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

这是我的header.phtml:

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

我对Magento很新,而且它是Block系统所以我不确定我是否正确加入了所有的点以显示这个块。

1 个答案:

答案 0 :(得分:1)

xml

的代码中缺少模板文件
 <block type="checkout/cart_sidebar" name="checkout.basket" as="checkoutBasket" template="pathoftemplate/basket.phtml" />

如果您想显示所有购物车项目,就像默认一样  然后

<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>

并且必须在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;?>