例如,覆盖方法的正确方法是什么 Mage_Checkout_Block_Links::addCartLink() 方法。

我的目标是在 Mage_Checkout_Block_Links::addCartLink() 方法。但是,我不知道从哪里开始或以我的自定义主题复制和编辑哪个文件。

我正在考虑这样的事情:

public function addLink($beforeText='<i class="icon-shopping-cart"></i>')
有帮助吗?

解决方案

这是一个有关如何覆盖模型或助手的小教程: http://magedev.com/2009/06/03/magento-overriding-model-block-or-helper/保存此链接...将来您将需要它。现在出于您的问题...关注上面链接中的教程,创建您自己的扩展名。让我们称其为“ easylife_checkout”。您需要以下文件:app/etc/modules/Easylife_Checkout.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Checkout>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Checkout />
            </depends>
        </Easylife_Checkout>
    </modules>
</config>

app/code/local/Easylife/Checkout/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Checkout>
            <version>0.0.1</version>
        </Easylife_Checkout>
    </modules>
        <global>
        <blocks>
            <checkout>
                <rewrite>
                    <links>Easylife_Checkout_Block_Links</links>
                </rewrite>
            </checkout>
        </blocks>
        </global>
</config>

app/code/local/Easylife/Checkout/Block/Links.php

<?php
class Easylife_Checkout_Block_Links extends Mage_Checkout_Block_Links{
    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');
            }

            $parentBlock->removeLinkByUrl($this->getUrl('checkout/cart'));
            $parentBlock->addLink($text, 'checkout/cart', $text, true, array(), 50, null, 'class="top-link-cart"', '<i class="icon-shopping-cart"></i>');//this will add the link. The last parameter is the 'before text'. You can add an other parameter after that that means $afterText
        }
        return $this;
    } 
}

清除缓存,您应该完成。

许可以下: CC-BY-SA归因
scroll top