Cómo reemplazar Mage_Checkout_Block_Links
-
16-10-2019 - |
Pregunta
¿Cuál es la forma correcta de reemplazar un método, por ejemplo, el método Mage_Checkout_Block_Links::addCartLink()
.
Mi objetivo es añadir algo de HTML antes de que el método Mage_Checkout_Block_Links::addCartLink()
. Sin embargo, no sé por dónde empezar o qué archivo a copiar y editar bajo mi tema personalizado.
Estoy pensando en algo como esto:
public function addLink($beforeText='<i class="icon-shopping-cart"></i>')
Solución
Aquí hay un pequeño tutorial sobre cómo reemplazar un bloque de un modelo o un ayudante: http://magedev.com/2009/06/03/magento-overriding-model-block-or-helper/
Mantener este enlace Guardar ... que lo necesitará en el futuro.
Ahora para su problema ... siguiendo el tutorial en el foro
Crear su propia extensión. Lets' llaman 'Easylife_Checkout'. Necesitará los siguientes archivos:
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>
y 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;
}
}
Borrar la caché y que se debe hacer.