2010-12-12 58 views
1

此前在Magento,使用加入心愿单链接如下(以wishlist.xml):Magento - 删除1.4.2中的心愿单链接?

<action method="addWishlistLink"></action> 

而且你可以重写,并使用以下(在你的local.xml中)将其删除:

<remove name="wishlist_link"/> 

然而,在最新的Magento,1.4.2,他们已经改变了心愿链接是如何加入到以下几点:

<action method="addLinkBlock"><blockName>wishlist_link</blockName></action> 

有谁知道如何牛逼o现在删除愿望清单链接,他们已经改变了它的添加方式?

回答

9

这似乎有可靠地从布局中删除的心愿链接没有公开可用的方法。 (你可以跳到最终的解决方法,)

addLinkBlock假定一个已经通过了块的存在,所以在使用中被抛出

Fatal error: Call to a member function getPosition() on a non-object in /Users/alanstorm/Sites/magento1point4.2.dev/app/code/core/Mage/Page/Block/Template/Links.php on line 112 

这里是你描述一个致命的错误结果的方式去除核心代码导致该错误

app/code/core/Mage/Page/Block/Template/Links.php 
public function addLinkBlock($blockName) 
{ 
    $block = $this->getLayout()->getBlock($blockName); 
    $this->_links[$this->_getNewPosition((int)$block->getPosition())] = $block;   
    return $this; 
} 

这种方法假定它要能拉出不论其名称被传递块,所以我们不能只删除wishlist_link块,因为我们可以在以前的版本。

用于移除链接的唯一机制似乎是相同的块级

app/code/core/Mage/Page/Block/Template/Links.php 
public function removeLinkByUrl($url) 
{ 
    foreach ($this->_links as $k => $v) { 
     if ($v->getUrl() == $url) { 
      unset($this->_links[$k]); 
     } 
    } 
    return $this; 
} 

但是下面的方法,这是使用字符串比较完成的,而且也没有可靠的方法(即我所知道的),以从布局文件生成URL对象,将其转换为字符串,并将其传递到方法中(这将是必需的,因为有许多配置设置可以更改最终的字符串URL)。这使得这种方法对我们的需求没有帮助。

那么,我们可以它修改现有的wishlist_link块使用空白或不存在的模板。这种方法块仍然呈现,但它呈现为空字符串。最终的结果是我们避免了上面提到的致命错误,但仍然设法从我们选定的页面中删除链接。

下面将使用default handle.

<!-- file: local.xml --> 
<layout> 
    <default> 
     <reference name="wishlist_link"> 
      <action method="setTemplate"><template>blank-link.phtml</template></action>   
     </reference>    
    </default> 
</layout> 
+0

为此欢呼。有点怪异,但这对于Magento来说并不是什么新东西,所以我现在不得不选择这个。任何想法为什么改变? – 2010-12-13 00:46:03

+0

其实只是尝试这样做,并没有喜悦,仍然能看到的链接。还有什么想法? – 2010-12-13 00:54:44

+0

我会说这是没有这么多的变化,通过新功能创建一个无意的错误。这适用于默认安装,所以我会检查你的local.xml是否被加载,并且所有东西都被正确的句柄包围。一旦你确认了,添加一些调试代码的基本模板类的setTemplate方法,以确保操作方法真的被调用。也许你有另一个布局更新覆盖这个新的? – 2010-12-13 02:51:27

1

您可以删除管理面板系统>配置>收藏心愿列表链接>已启用=“否”

+0

我不想禁用心愿功能,只需移除某些网页的链接。 – 2010-12-13 00:44:51

3

In your local.xml file,

<?xml version="1.0"?> 
<layout version="0.1.0"> 
    <default> 
    <reference name="root"> 
     <reference name="top.links"> 
     <!-- Remove wishlist link in magento 1.4.x and newer --> 
     <remove name="wishlist_link"/> 
     </reference> 
    </reference> 
    </default> 
</layout> 
1

Add the following to your local.xml file.

<reference name="top.links"> 
    <remove name="wishlist_link"/> 
</reference> 

This works! I have removed Wishlink from Toplinks and wanted to add it back into another block but that doesn't seem possible when you remove it in this way. Sadly.

0

I know I'm years late here, but for all of those people who are still looking for answers to this.

I have a way to work around this issue that is only a bit of extra work but it's not hacky and it gives you FULL control of your top.links block.

Simply unset the top.links块从删除链接的所有页面并重新创建它,这将是空的(没有更多wishlist_link块),所有你需要做的就是添加你想要的内部为准链接它! (当然,在你的theme/layout/local.xml文件中完成所有这些)。

<layout version="0.1.0"> 
<default> 
    <!-- HEADER --> 
    <reference name="header"> 

     <!-- Unsetting the already existing top links block --> 
     <action method="unsetChild"> 
      <name>topLinks</name> 
     </action> 

     <!-- Re-creating a new top links block --> 
     <block type="page/template_links" name="top.links" as="topLinks"> 
      <!-- EXAMPLE: Account Dashboard Link --> 
      <action method="addLink" translate="label title" module="catalog"> 
       <label>Account Dashboard</label> 
       <url helper="customer/getAccountUrl"/> 
       <title>Account Dashboard</title> 
      </action> 
      <!-- You can add any other links that you want --> 
     </block> 

    </reference> 
</default> 
</layout> 

还记得像Sign In一些链接和Log Out你需要引用相应的<customer_logged_out><customer_logged_in>里面你top.links块处理的,而不是<default>内为这个你可以看看Magento的customer.xml文件的指南。

重要:如果有包含在你的项目中添加链接到top.links块中的任何模块,这些链接将不会显示出来,因为local.xml最后处理,因此使用这种方法时,只是记住这一点:)

我是一个认证Magento的前端开发有3年以上的经验,我已经克服了布局XML头痛的地方,我们成了最好的朋友点的地段。

相关问题