gpt4 book ai didi

php - Magento - 在购物车页面上使用自定义模块添加自定义 block

转载 作者:数据小太阳 更新时间:2023-10-29 02:45:51 26 4
gpt4 key购买 nike

我已经创建了一个自定义模块,并试图在购物车表之后和总计框之前包括一个 block 。但我无法在那个确切的地方得到它。我可以让我的区 block 出现在内容部分的正下方,而不是介于两者之间。

如果我覆盖 checkout.xml 和 cart.phtml,那么我可以实现我想要显示我的 block 的位置,但我不想覆盖现有文件,因此我的自定义模块。有人能指出我遗漏或做错了什么吗?

这是我的模块代码,

app/code/local/CM/Test/etc/config.xml

<?xml version="1.0"?>
<config>
<modules>
<CM_Test>
<version>0.1.0</version>
</CM_Test>
</modules>
<frontend>
<routers>
<test>
<use>standard</use>
<args>
<module>CM_Test</module>
<frontName>test</frontName>
</args>
</test>
</routers>
<layout>
<updates>
<cm_test module="CM_Test">
<file>test.xml</file>
</cm_test>
</updates>
</layout>
</frontend>
<global>
<blocks>
<test>
<class>CM_Test_Block</class>
</test>
</blocks>
</global>
</config>

app/code/local/CM/Test/Block/Somblock.php

  <?php
class CM_Test_Block_Somblock extends Mage_Core_Block_Template
{
protected function _construct()
{
parent::_construct();
$this->setTemplate('test/testing.phtml');
}

public function methodBlock()
{
return 'informations about my block !!' ;
}
}

app/code/local/CM/Test/controllers/IndexController.php

 <?php
class CM_Test_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
public function somethingAction()
{
echo 'test mamethode';
}
}

app/design/frontend/mytheme/layout/test.xml

   <layout version="0.1.0">
<default></default>
<test_index_index>
<reference name="root">
<action method="setTemplate"><template>page/2columns-right.phtml</template>
</action>
</reference>
<reference name="content">
<block type="test/somblock" name="test.somblock" template="test/testing.phtml"/>
</reference>
</test_index_index>

<checkout_cart_index>
<reference name="checkout.cart.form.before">
<block type="test/somblock" name="test.somblock">
<action method="setTemplate"><template>test/testing.phtml</template></action>
</block>
<block type="test/somblock" name="test.somblock" template="test/smtesting.phtml"/>
</reference>
</checkout_cart_index>
</layout>

app/design/frontend/default/mytheme/template/test/testing.phtml

 TESTING <br/>
<?php
echo $this->getChildHtml('testing.somblock');
echo "HELLO";

app/design/frontend/default/mytheme/template/test/smtesting.phtml

 <?php
echo $this->methodBlock();

app/etc/modules/CM_Test.xml

 <?xml version="1.0"?>
<config>
<modules>
<CM_Test>
<codePool>local</codePool>
<active>true</active>
</CM_Test>
</modules>
</config>

当我访问 http://mydomain.com/test/index/index 时它给了我以下 o/p

测试
你好

当我访问 http://mydomain.com/checkout/cart/index 时它给了我以下 o/p

output of my module

但是我需要在购物车表之后和小计框上方输出关于我的 block 的信息,我该怎么做?

最佳答案

<checkout_cart_index>
<reference name="checkout.cart">
<block type="test/somblock" name="test.somblock" before="checkout.cart.totals" template="test/testing.phtml" />
<block type="test/somblock" name="test.somblock" after="test.somblock" template="test/smtesting.phtml"/>
</reference>
</checkout_cart_index>

您指的是购物车之前的表格,而您希望它在购物车中。更改您的引用并将其添加到总计之前(如果您愿意,也可以添加到折扣之前)。

关于php - Magento - 在购物车页面上使用自定义模块添加自定义 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13767656/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com