Magento-删除1.4.2中的愿望清单链接? [英] Magento - removing wishlist link in 1.4.2?

查看:35
本文介绍了Magento-删除1.4.2中的愿望清单链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前在Magento中,wishlist链接是使用以下内容(在wishlist.xml中)添加的:

Previously in Magento, the wishlist link was added using the following (in wishlist.xml):

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

您可以使用以下内容(在您的local.xml中)覆盖并删除它:

And you could override that and remove it using the following (in your local.xml):

<remove name="wishlist_link"/>

但是,在最新的Magento 1.4.2中,他们更改了将愿望清单链接添加到以下内容的方式:

However, in the newest Magento, 1.4.2, they've changed how the wishlist link is added to the following:

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

现在,任何人都知道如何删除愿望清单链接吗?

Anyone know how to remove the wishlist link now they’ve changed how it’s added?

推荐答案

似乎没有公开可用的方法来可靠地从布局中删除愿望清单链接 block . (您可以跳到最后找到解决方法)

It appears there's no publicly available way to reliably remove the wishlist link block from the layout. (you can skip to the end for a workaround)

addLinkBlock假定存在已传递的块,因此以描述方式使用remove会引发致命错误

The addLinkBlock assumes the presence of the block that's been passed, so using remove in the way you describe results in a fatal error being thrown

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

这是导致该错误的核心代码

Here's the core code that causes that error

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块.

This method assumes its going to be able to pull out a block by whatever name gets passed, so we can't just remove the wishlist_link block as we could in previous versions.

删除链接的唯一机制似乎是同一块类上的以下方法

The only mechanism for removing a link appears to be the following method on the same block class

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.这使得该方法无法满足我们的需求.

However, this is done using string comparison, and there's no reliable way (that I know of) to generate a URL Object from a layout file, cast it as a string, and pass it into the method (this would be required, as there are numerous configuration settings that can change what the final string URL will be). That makes this method not helpful for our needs.

因此,我们可以执行的操作将现有的wishlist_link块修改为使用空白或不存在的模板.这样,该块仍然呈现,但是它呈现为空字符串.最终结果是我们避免了上述致命错误,但仍然设法从我们选择的页面中删除了该链接.

So, what we can do it modify the existing wishlist_link block to use a blank or non-existant template. This way the block still renders, but it renders as an empty string. The end result is we avoid the fatal error mentioned above, but still manage to remove the link from our selected pages.

以下内容将使用默认手柄从所有页面中删除链接.

The following would remove the link from all the pages using the default handle.

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

这篇关于Magento-删除1.4.2中的愿望清单链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆