当购物车为空时,如何在顶部菜单上隐藏结帐按钮。对我来说,当客户没有添加任何产品时,按钮出现是没有意义的。
解决了!
多谢你们。在这里,我的代码看起来如何(Links.php):
public function addCartLink()
{
$parentBlock = $this->getParentBlock();
if ($parentBlock && Mage::helper('core')->isModuleOutputEnabled('Mage_Checkout')) {
$count = $this->getSummaryQty() ? $this->getSummaryQty()
: $this->helper('checkout/cart')->getSummaryCount();
if ($count == 1) {
$text = $this->__('My Cart (%s item)', $count);
} elseif ($count > 0) {
$text = $this->__('My Cart (%s items)', $count);
} else {
//$text = $this->__('My Cart');
//added
$text = '';
}
$parentBlock->removeLinkByUrl($this->getUrl('checkout/cart'));
//$parentBlock->addLink($text, 'checkout/cart', $text, true, array(), 50, null, 'class="top-link-cart"');
//added
if($text != ""){
$parentBlock->addLink($text, 'checkout/cart', $text, true, array(), 50, null, 'class="top-link-cart"');
}
}
return $this;
}
/**
* Add link on checkout page to parent block
*
* @return Mage_Checkout_Block_Links
*/
public function addCheckoutLink()
{
if (!$this->helper('checkout')->canOnepageCheckout()) {
return $this;
}
$parentBlock = $this->getParentBlock();
//if ($parentBlock && Mage::helper('core')->isModuleOutputEnabled('Mage_Checkout')) {
if ($parentBlock && Mage::helper('core')->isModuleOutputEnabled('Mage_Checkout') && count(Mage::getModel('checkout/cart')->getQuote()->getAllItems())) {
$text = $this->__('Checkout');
$parentBlock->addLink(
$text, 'checkout', $text,
true, array('_secure' => true), 60, null,
'class="top-link-checkout"'
);
}
return $this;
}