duanhe1976 2012-12-07 17:04
浏览 60
已采纳

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.

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.

Here's my module code,

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>

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

TESTING HELLO

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

output of my module

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

  • 写回答

1条回答 默认 最新

  • douyi6290 2012-12-10 07:46
    关注
    <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).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?