使用自定义模块显示块

时间:2013-01-14 05:27:27

标签: magento

我创建了一个自定义模块,用于处理会员系统的各种任务。我现在正在尝试修改模块,这样我就可以在任何地方放入一个块。我一直在关注Gravitywell.com上的教程,但我感觉我已经在某处掉了下来。

应用的/ etc /模块/ Hatclub_MembershipHandler.xml

<config>
<modules>
    <Hatclub_MembershipHandler>
        <active>true</active>
        <codePool>local</codePool>
    </Hatclub_MembershipHandler>
</modules>

应用/代码/本地/ Hatclub / MembershipHandler /砌块/ lookup.php

<?php

class Hatclub_MembershipHandler_Block_Lookup extends Mage_Core_Block_Template {    

}

应用/代码/本地/ Hatclub / MembershipHandler的/ etc / config.xml中

<modules>
    <Hatclub_MembershipHandler>
        <version>1.0.0</version>
    </Hatclub_MembershipHandler>
</modules>

<global>

    <models>
        <hatclub_membership_handler>
            <class>Hatclub_MembershipHandler_Model</class>
        </hatclub_membership_handler>
    </models>

    <blocks>
        <hatclub_membership_handler>
            <class>Hatclub_MembershipHandler_Block</class>
        </hatclub_membership_handler>
    </blocks>

    <events>

        <customer_register_success>
            <observers>
                <registration_success_observer>
                    <class>hatclub_membership_handler/observer</class>
                    <method>registrationSuccess</method>
                    <type>singleton</type>
                </registration_success_observer>
            </observers>
        </customer_register_success>

    </events>

</global>

应用/代码/本地/ Hatclub / MembershipHandler /型号/ Observer.php

<?php

class Hatclub_MembershipHandler_Model_Observer {

    // members group id
    const GROUP_ID = 4;

    // called when a customer registers for the site
    public function registrationSuccess(Varien_Event_Observer $observer) {

        // extract customer data from event
        $customer = $observer->getCustomer();

        // a cookie should have been set with the membership id
        if (isset($_COOKIE['membership_account_id'])) {

            $customer
                ->setGroupId(self::GROUP_ID)
                ->setRmsId($_COOKIE['membership_account_id']);

        }

        return $this;

    }

}

/app/design/frontend/enterprise/hatclub/template/persistent/customer/form/register.phtml

<?php 
    echo $this->getLayout()->createBlock('hatclub_membership_handler/lookup')->setTemplate('membership_lookup/lookup.phtml')->toHtml(); ?>

1 个答案:

答案 0 :(得分:1)

app / code / local / Hatclub / MembershipHandler / etc / config.xml 阻止节点下的代码应如下所示

<blocks>
            <membershiphandler>
                <class>Hatclub_MembershipHandler_Block</class>
            </membershiphandler>
</blocks>

membershiphandler 表示模块名称的小写版本和

<?php 
    echo $this->getLayout()->createBlock('hatclub_membership_handler/lookup')->setTemplate('membership_lookup/lookup.phtml')->toHtml(); ?>

应该是

<?php 
        echo $this->getLayout()->createBlock('membershiphandler/lookup')->setTemplate('path to the template file')->toHtml(); ?>