magento:在另一个街区移动购物车

时间:2013-06-17 13:43:55

标签: magento

我是Magento的新手,我正试图将我的购物车链接与导航栏中的其他链接分开。

我做了以下步骤: 1)在etc/modules

下配置了一个新模块
<?xml version="1.0"?>
<config>
    <modules>
        <Marco_TopRightLinks>
            <active>true</active>
            <codePool>local</codePool>
        </Marco_TopRightLinks>
    </modules>
</config>

2)添加到app/code/local/Marco/TopRightLinks/Block Links.php文件,包含以下内容:

class Marco_TopRightLinks_Block_Links extends Mage_Checkout_Block_Links
{
    protected function _construct()
    {
        $this->setTemplate('page/template/logged-links.phtml');
    }
}

3)添加到app/code/local/Marco/TopRightLinks/etc config.xml文件,包含以下内容:

<config>
    <modules>
        <Marco_TopRightLinks>
            <version>0.1.0</version>
        </Marco_TopRightLinks>
    </modules>
    <global>
        <blocks>
            <topright>
                <class>Marco_TopRightLinks_Block</class>
            </topright>
        </blocks>
    </global>
</config>

4)改变了page.xml

<block type="page/html_header" name="header" as="header">
  <block type="page/template_links" name="top.links" as="topLinks"/>

到此:

<block type="page/html_header" name="header" as="header">
  <block type="page/template_links" name="top.links" as="topLinks"/>
  <block type="topright/links" name="top.right_links" as="topRightLinks"/>

5)改变了checkout.xml:                                                                              

到此:

<!-- Mage_Checkout -->
<reference name="top.right_links">
  <block type="topright/links" name="checkout_cart_link">
    <action method="addCartLink"></action>
    <!--<action method="addCheckoutLink"></action>-->
  </block>
</reference>

[my_template]/page/template下添加 right-links.phtml文件

这会导致Magento异常:

Invalid method Marco_TopRightLinks_Block_Links::removeLinkByUrl(Array
(
  [0] => http://mysitecom/checkout/cart/
)

你能帮我理解发生了什么,我能做些什么吗? (我不想触及任何内在的magento方法,我确信addCartLink的工作原理非常好:D)我的目标只是将另一个地方的购物车链接移动到我的html中

编辑: 如果,而不是扩展Mage_Checkout_Block_Links

class Marco_TopRightLinks_Block_Links extends Mage_Checkout_Block_Links

我延伸Mage_Page_Block_Template_Links

class Marco_TopRightLinks_Block_Links extends Mage_Page_Block_Template_Links

中的异常更改
Invalid method Marco_TopRightLinks_Block_Links::addCartLink

3 个答案:

答案 0 :(得分:0)

尝试将crightfig .xml

中的topright替换为toprightlinks
<config>
    <modules>
        <Marco_TopRightLinks>
            <version>0.1.0</version>
        </Marco_TopRightLinks>
    </modules>
    <global>
        <blocks>
            <toprightlinks>
                <class>Marco_TopRightLinks_Block</class>
            </toprightlinks>
        </blocks>
    </global>
</config>

答案 1 :(得分:0)

在这里,我建议您使用自定义块将模板从一个更改为另一个

您可以通过布局系统添加您的块(这也是正常内容的添加方式)?

如果您还没有为模块定义布局XML文件:

<frontend>
    <layout>
        <updates>
            <your_module module="Your_Module">
                <file>your/module.xml</file>
            </your_module>
        </updates>
    </layout>
</frontend>

使用您的布局文件(app / design / frontend / base / default / layout / your / module.xml)将块添加到布局更新句柄。例如:

<?xml version="1.0"?>
<layout>
    <a_handle_for_you>
        <reference name="content">
            <block type="core/text" name="yourblock">
                <action method="setText">
                    <arg>You should see this text.</arg>
                </action>
            </block>
        </reference>
    </a_handle_for_you>
    <checkout_onepage_success>
        <update handle="a_handle_for_you" />
    </checkout_onepage_success>
    <checkout_multishipping_success>
        <update handle="a_handle_for_you" />
    </checkout_multishipping_success>
</layout>

你也可以参考Magento Knowledge Base。深入思考解决问题

答案 2 :(得分:0)

错误是checkout.xml我不应该替换块类型。 Magento应该使用它自己的。我应该只更改page.xml中的块类型,因此容器正在更改,而内容保持不变