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?

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

3 Answers 3

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.

1
  • @zekia ... did it work for you?
    – sv3n
    Commented Oct 16, 2018 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>
1
  • I tried moving event to frontend, as you suggested, but still not working
    – zekia
    Commented Jul 27, 2017 at 11:06
0

You're extending wrong class. Try extending "Varien_Event_Observer" class. This will help you access the observer event in the Observer php code.

1
  • Please add more content
    – Msquare
    Commented Apr 8, 2020 at 3:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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