Magento-使用“购物车"页面上的自定义模块添加自定义块 [英] Magento - Add custom block using custom module on Shopping Cart page

查看:119
本文介绍了Magento-使用“购物车"页面上的自定义模块添加自定义块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个自定义模块,并尝试在购物车表之后和总计"框之前添加一个块.但是我无法在那个地方找到它.我可以让我的广告块显示在内容部分中的所有其他内容的正下方,但不能位于两者之间.

I have created a custom module and am trying to include a block just after Shopping cart table and before Totals box. But I am unable to get it in that exact place. I can get my block to appear in content section just below everything else but not in between.

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

If I override checkout.xml and cart.phtml then I can achieve where I want to display my block but I dont want to override the existing files, hence my custom module. Could some one point out what is it that I' missing or doing wrong.

这是我的模块代码,

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

When I accessed http://mydomain.com/test/index/index it gave me the following o/p

TESTING HELLO

TESTING HELLO

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

When I accessed http://mydomain.com/checkout/cart/index it gave me the following o/p

但是我仅在购物车表之后和小计"框上方需要输出information about my block,我该怎么做?

But I need the output information about my block just after shopping cart table and above Subtotals box, how do i do that?

推荐答案

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

您要在购物车之前引用表格,但要在购物车中填写该表格.更改您的参考,然后将其添加到总计之前(或根据需要在折扣之前).

You are referring to the form before the cart, while you want it in the cart. Change your reference and add it before the totals (or before the discount if you like).

这篇关于Magento-使用“购物车"页面上的自定义模块添加自定义块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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