mage_checkout_block_linksをオーバーライドする方法
-
16-10-2019 - |
質問
たとえば、メソッドをオーバーライドする適切な方法は何ですか? Mage_Checkout_Block_Links::addCartLink()
方法。
私の目標は、その前にHTMLを追加することです 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;
}
}
キャッシュをクリアすると、完了する必要があります。
所属していません magento.stackexchange