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 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多