0

I've created a custom module, that looks like this:

config.xml

<config>
    <modules>
        <Mycode_GroupRegister>
            <version>0.1.0</version>
        </Mycode_GroupRegister>
    </modules>
    <global>
        <models>
            <groupregister>
                <class>Mycode_GroupRegister_Model</class>
            </groupregister>
        </models>
        <events>
            <customer_register_success>
                <observers>
                    <Mycode_GroupRegister_Model_Observer>
                        <type>singleton</type>
                        <class>Mycode_GroupRegister_Model_Observer</class>
                        <method>CustomerRegister</method>
                    </Mycode_GroupRegister_Model_Observer>
                </observers>
            </customer_register_success>
        </events>
    </global>
    <frontend>
        <routers>
            <customer>
                <args>
                    <modules>
                        <Mycode_GroupRegister before="Mage_Customer">Mycode_GroupRegister</Mycode_GroupRegister>
                    </modules>
                </args>
            </customer>
        </routers>
    </frontend>
</config>

Observer.php

<?php
Class Mycode_GroupRegister_Model_Observer extends Mage_Core_Model_Abstract
{
    public function CustomerRegister($observer)
    {
        die();
        Mage::log('IN CustomerRegister()', null, 'test_register.log');
        $data = Mage::getSingleton('core/app')->getRequest();
        $customer_type = $data->getParam('customer_type');
        try {
            $customer = $observer->getCustomer();

            if ($customer_type == 'wholesale') {
                $customer->setData('group_id',2);
                $customer->setCustomerActivated(0);
                $customer->save();
            } else {
                $customer->setData('group_id',3);
                $customer->save();
            }
            $customer->save();
        } catch (Exception $e) {
            Mage::log("Mycode_GroupRegister_Model_Observer failed: " . $e->getMessage());
        }
    }
}

It seems that the observer is never called. I have used this extension in another website before and it was working ok. But it's not working on this one. Could you help me fix it?

  • Is it normal registration from magento frontend? – sv3n Jul 26 '17 at 12:52
  • Yes it is for normal registration – zekia Jul 27 '17 at 11:08
2

I've tested your code and it works.

You should just remove die(); from your observer class.

In addition i would recommend to change

<class>Mycode_GroupRegister_Model_Observer</class>

to

<class>groupregister/observer</class>

... to avoid problems when using rewrites on you observer class.

  • @zekia ... did it work for you? – sv3n Oct 16 '18 at 20:52
1

Try to change your config.xml code like this.

<frontend>
    <events>
            <customer_register_success>
                <observers>
                    <Mycode_GroupRegister_Model_Observer>
                        <type>model</type>
                        <class>Mycode_GroupRegister_Model_Observer</class>
                        <method>CustomerRegister</method>
                    </Mycode_GroupRegister_Model_Observer>
                </observers>
            </customer_register_success>
        </events>
</frontend>
  • I tried moving event to frontend, as you suggested, but still not working – zekia Jul 27 '17 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.