Magento - 删除1.4.2中的心愿单链接?

时间:2010-12-12 19:44:28

标签: magento

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

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

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

<remove name="wishlist_link"/>

然而,在最新的Magento 1.4.2中,他们改变了wishlist链接添加到以下内容的方式:

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

任何人都知道如何删除心愿单链接现在他们已经改变了添加方式吗?

5 个答案:

答案 0 :(得分:9)

似乎没有公开的方法可以从布局中可靠地删除心愿单链接阻止。 (您可以跳到最后找到解决方法)

addLinkBlock假定存在已经传递的块,因此使用remove描述的方式会导致抛出致命错误

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>
所有页面中删除链接

答案 1 :(得分:3)

在local.xml文件中,

<?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>

答案 2 :(得分:1)

您可以从管理面板系统&gt;中删除心愿单链接。配置&gt;愿望清单&gt;启用=“否”

答案 3 :(得分:1)

将以下内容添加到local.xml文件中。

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

这个有效!我已经从Toplinks中删除了Wishlink,并希望将其添加回另一个块,但是当您以这种方式删除它时似乎不可能。不幸的是

答案 4 :(得分:0)

我知道我在这里已经很晚了,但对于所有那些仍在寻找答案的人来说。

我有办法解决这个问题,这只是一些额外的工作,但它不是hacky,它可以让你完全控制你的top.links块。

只需取消设置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 InLog Out,您需要在相应的top.links<customer_logged_out>句柄中引用<customer_logged_in>块,而不是在<default>内,您可以查看Magento的customer.xml文件。

重要提示:如果您的项目中包含添加top.links块链接的任何模块,那么这些链接将不会显示,因为local.xml已被处理最后,所以在使用这种方法时请记住这一点:)

我是经过认证的Magento前端开发人员,拥有超过3年的经验,我已经克服了许多布局XML问题,以至于我们成为了最好的朋友。

相关问题