0

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

应用程序/etc/modules/Hatclub_MembershipHandler.xml

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

应用程序/代码/本地/Hatclub/MembershipHandler/Block/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>

app/code/local/Hatclub/MembershipHandler/Model/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(); ?>
4

1 回答 1

1

文件app/code/local/Hatclub/MembershipHandler/etc/config.xml中blocks节点下的代码应如下所示

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

memberhandler代表你的模块名称的小写版本和

<?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(); ?>
于 2013-01-14T05:55:22.877 回答