doulian7305 2013-09-24 12:12
浏览 9
已采纳

Magento 1.7 - 自定义模块,通话功能

I created a custom module where i want to show some information about an product. In config.xml i added

<blocks>
    <mymodule>
        <class>Namespace_MyModule_Block</class>
    </mymodule>
</blocks>

The block class extends Mage_Catalog_Block_Product_View. But i can't call

$this->getProduct()

in the *.phtml file according to the module (mymodule.phtml). The xmls are configured well, so i can call the .phtml with

<?php echo $this->getChildHtml('mymodule'); ?>

but $product is always null. According to the configuration in modules config.xml $this->getProduct() should access Mynamespace_MyModule_Block_View and call the function. I tried with a dummy function which simply returns a string value, but this doesn't work either.

I hope someone can give me a hint weather there is some missing or wrong configuration.

EDIT 1: Content of layout.xml

<?xml version="1.0"?>
<layout>
    <catalog_product_view>
        <reference name="product.info">
            <block type="core/template" name="product_available_price" as="product_available_price"
                   template="productavailable/price.phtml"/>
            <block type="core/template" name="product_available_info" as="product_available_info"
                   template="productavailable/info.phtml"/>
            <block type="core/template" name="product_available_button" as="product_available_button"
                   template="productavailable/button.phtml"/>
        </reference>
    </catalog_product_view>
</layout>

In button.phtml i call $this->getProduct() and the method is in Mynamespace_MyModule_Block_Button

  • 写回答

2条回答 默认 最新

  • dsxz84851 2013-09-24 12:16
    关注

    in one of my custom module i have used like below

    class Yournamespace_Brand_Block_View extends Mage_Catalog_Block_Product_Abstract

    And i have also used all product features with magento default functionality like

    pagination and toolbar etc.

    Edit

    Block type change from core/template to productavailable/button

     <block type="productavailable/button" name="product_available_button" as="product_available_button"                       template="productavailable/button.phtml"/>
    

    hope this will sure solve your issue.

    let me know if i could help you more.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题