0

当购物车为空时,如何在顶部菜单上隐藏结帐按钮。对我来说,当客户没有添加任何产品时,按钮出现是没有意义的。

解决了!

多谢你们。在这里,我的代码看起来如何(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;
}
4

2 回答 2

1
if ( count(Mage::getModel('checkout/cart')->getQuote()->getAllItems()) ) {

YOUR LINK TO CART

}
于 2013-07-10T19:06:52.113 回答
1

您可以为此编写一个新的扩展,这是最佳实践。但如果您认为这对您来说没什么大不了的,也可以对核心文件进行更改。在

app\code\core\Mage\Checkout\Block\Links.php

添加用整个 addCartLink 函数替换以下行代码

 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'); 
                    $text = ''; //change this line
                }

                $parentBlock->removeLinkByUrl($this->getUrl('checkout/cart'));
                //$parentBlock->addLink($text, 'checkout/cart', $text, true, array(), 50, null, 'class="top-link-cart"');
                if($text != ""){
                $parentBlock->addLink($text, 'checkout/cart', $text, true, array(), 50, null, 'class="top-link-cart"');
                 }
            }
            return $this;
        }
于 2013-07-11T01:56:15.867 回答