如果购物车为空,则在购物车页面上隐藏块
-
16-10-2019 - |
题
在Checkout.xml中我看到
<action method="setCartTemplate"><value>checkout/cart.phtml</value></action>
<action method="setEmptyTemplate"><value>checkout/cart/noItems.phtml</value></action>
<action method="chooseTemplate"/>
我只是想在购物车中有一个物品时才出现一个块,而当它空着时不会出现。我该如何完成?
解决方案
正常广告您的块,并将显示器html包裹在条件下,检查购物车项目。
这将起作用,
Mage::helper('checkout/cart')->getCart()->getItemsCount();
不必重写任何核心块,甚至不必创建自己的块。
然后,您的PHTML块可以是核心模板块,除非您需要在模板中使用更多的购物车逻辑,否Mage_Checkout_Block_Cart_Abstract
),这将使您访问所有核心购物车方法。
然后,只需将块添加到XML中,只有在有项目的情况下,它才会输出其代码。
根据您的预期显示,您可以在这些核心块列表中添加块,然后您不需要更改基础 cart.phtml
归档以回应您的块
<block type="core/text_list" name="checkout.cart.top_methods" as="top_methods" translate="label">
[ add your block here ]
</block>
<block type="core/text_list" name="checkout.cart.methods" as="methods" translate="label">
[ add your block here ]
</block>