cancel
Showing results for 
Search instead for 
Did you mean: 

how to create an new observer on the event “customer_register_success” from the top

how to create an new observer on the event “customer_register_success” from the top

I'm quite newbie in magento. I'm trying to create observer on the event "customer_register_success". I follow the tutorial about how to compose the files in local module. But it didn't work.

 

 

When customer register on our website, customer should select the country where they live and it is saved as billing address. The goal i want to meet is that if customer live in United State, their group is standard group(just default group). If not, like live in Jamaica, Spain, they are assigned to international group automatically.

 

 

I know that GROUP exist because of tax class tho. but i must make it.

 

 

our website's customer group information is, enter image description here

 

 

I'm willing to set the groupid based on their country name,id. As you see the following,

 

 

1)Directory

enter image description here

2)app/etc/modules/Kbethos_CustomerGrouped.xml

First of all, I added a module configuration file to the app/etc/modules directory.

 

 

<?xml version="1.0"?>
<config>
    <modules>
    <Kbethos_CustomerGrouped>
        <active>true</active>
        <codePool>local</codePool>
    </Kbethos_CustomerGrouped>
    </modules>
</config>

 

3) app/code/local/Kbethos/CustomerGrouped/etc/config.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Kbethos_CustomerGrouped>
            <version>0.1.0</version>
        </Kbethos_CustomerGrouped>
    </modules>
    <global>
        <helpers>
            <customergrouped>
                <class>Kbethos_CustomerGrouped_Helper</class>
            </customergrouped>
        </helpers>
        <models>
            <kbethos_customergrouped>
                <class>Kbethos_CustomerGrouped_Model</class>
            </kbethos_customergrouped>
        </models>
        <events>
            <customer_register_success>
                <observers>
                    <kbethos_customergrouped>
                        <class>kbethos_customergrouped/observer</class>
                        <method>customerRegisterSuccess</method>
                    </kbethos_customergrouped>
                </observers>
            </customer_register_success>
    </events>
    </global> 
</config>

4)app/code/local/Kbethos/CustomerGrouped/Model/Observer.php

<?php
  class Kbethos_CustomerGrouped_Model_Observer {
  public function customerRegisterSuccess(Varien_Event_Observer $observer) {

 $event = $observer->getEvent();
    $customer = $event->getCustomer();
    $billingAddress = $customer->getPrimaryBillingAddress();

    if ($billingAddress) {
        $countryId = $billingAddress->getCountryId();
        switch ($countryId) {
            case 'US':
                $customer->setData('group_id', 1);
                $customer->save();
                break;
            default:
                $customer->setData('group_id', 27);
                $customer->save();
        }
    }

  }
}


?>

5) /wh-clone/app/code/local/Kbethos/CustomerGrouped/Helper/Data.php

 

<?php 

class Kbethos_CustomerGrouped_Helper_Data extends Mage_Core_Helper_Abstract
{
}

What sould i do more? please let me know. Thank you.

1 REPLY 1

Re: how to create an new observer on the event “customer_register_success” from the top

For that you have to load the Customer object and and add the website id too

$custid=$customer->getId();
$customeragain = Mage::getModel("customer/customer")->load($custid);
$website_id = Mage::app()->getWebsite()->getId();   
$customeragain->setData('group_id', 1);
$customeragain->setWebsiteId($website_id); 
$customeragain->save();  
Find helpful ? Consider Giving Kudos to this post.
Problem solved? Click Accept as Solution!"
Qaisar Satti