2014-07-23 73 views
1

我想为所有顶部链接添加id属性。我得到了一个解决方案如下Magento将id属性添加到顶部链接

<action method="addLink" translate="label title" module="customer"><label>My Account</label><url helper="customer/getAccountUrl"/><title>My Account</title><prepare/><urlParams/><position>10</position><liParams>id="myaccount"</liParams></action> 

添加liParams适用于我的帐户链接只有这种解决方案并不适用于我的车和结算环节。

+0

哪个magento版??? –

回答

3

结帐链路使用下面位于app/code/core/Mage/Checkout/Block/Links.php功能

public function addCartLink() 
    { 
     ////..... 
     $parentBlock->addLink($text, 'checkout/cart', $text, true, array(), 50, null, 'class="top-link-cart"'); 
     return $this; 
    } 

你可以看到,它不包含任何<liParams><aParams>。虽然addLink()方法位于Mage_Page_Block_Template_Links包含PARAMS如下图所示

public function addLink($label, $url='', $title='', $prepare=false, $urlParams=array(), 
     $position=null, $liParams=null, $aParams=null, $beforeText='', $afterText='') 

因此,你可以在本地执行下列操作

  1. 覆盖的addCartLink(),并添加PARAMS为 需要

  2. 删除结帐链接,然后再添加明确的URL和 params

例如在local.xml,通过local.xml中添加自定义链接到首页链接:

<reference name="top.links"> 
    <action method="addLink" translate="label title"> 
     <label>My Link</label> 
     <url>path/to/page</url> 
     <title>My link tooltip</title> 
     <prepare>true</prepare> 
     <urlParams/> 
     <position>150</position> 
     <liParams>id="my-custom-id"</liParams> 
    </action> 
</reference> 
+0

谢谢!我会仔细看看的!如果它有效,你会得到一个很好的复选标记! –

+0

感谢队友,它工作 –

3

@Nilesh亚达夫,车和结算环节都使用不同的方法来创建顶部链接

<action method="addCartLink"></action> 
    <action method="addCheckoutLink"></action> 

其他使用addLink功能

结帐和车用类Mage_Checkout_Block_Links功能addCheckoutLink and addCartLink

修改XML代码

<reference name="top.links"> 
      <block type="checkout/links" name="checkout_cart_link"> 
       <action method="addCartLink"><liParams>id="my-custom-id"</liParams></action> 
       <action method="addCheckoutLink"> <liParams>id="my-custom-id"</liParams></action> 
      </block> 
     </reference> 

Copy app/code/core/Mage/Checkout/Block/Links.php

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

转到功能修改逻辑在addCartLink

public function addCartLink($liparams=null) 
{ 
..... 
if(is_null()) 
{ $parentBlock->addLink($text, 'checkout/cart', $text, true, array(), 50, null, 'class="top-link-cart"'); 
}else 
{ 
$parentBlock->addLink($text, 'checkout/cart', $text, true, array(), 50, $liparams, 'class="top-link-cart"'); 
} 

....

另外

public function addCheckoutLink($liparams=null) 
    { 
.... 
     if ($parentBlock && Mage::helper('core')->isModuleOutputEnabled('Mage_Checkout')) { 
      $text = $this->__('Checkout'); 
     if(is_null()){ 
      $parentBlock->addLink(
       $text, 'checkout', $text, 
       true, array('_secure' => true), 60, null, 
       'class="top-link-checkout"' 
      ); 
    }else{ 
      $parentBlock->addLink(
       $text, 'checkout', $text, 
       true, array('_secure' => true), 60, $liparams=null, 
       'class="top-link-checkout"' 
      ); 

     } 
     } 
.. 
    } 
0

addCartLink()函数用于创建在Magento顶级车的链接。 要么重写Mage_Checkout_Block_Links类和改变addCartLink()函数如下 或简单地复制应用程序/代码/核心/法师/结帐/砌块/ Links.php应用程序/代码/本地/法师/结帐/块/链接。php and edit

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->__('Cart (%s)', $count); 
     } elseif ($count > 0) { 
      $text = $this->__('Cart (%s)', $count); 
     } else { 
      $text = $this->__('Cart (0)'); 
     } 

     $parentBlock->removeLinkByUrl($this->getUrl('checkout/cart')); 
     $parentBlock->addLink($text, 'checkout/cart', $text, true, array(), 50, 'id="top_cart"', 'class="top-link-cart"'); //add your custom class or id here 
    } 
    return $this; 
}