2

How to assign customer group automatically following by address information

When customer register on our website, customer write the country where they live. If customer live in United State, we would set the standard group(just default group). If not like live in Jamaica, Spain, we'd like to assign to international group automatically.

So, it would show like this, enter image description here

It seems like if-else statement on any languages but i didn't touch the code because i fix it myself one by one.

How can i do it? app/code/core/Mage/Customer/Model have the information about that i guess.

0

Not sure what you're trying to get at here, but this sounds like something Customer Segments would be useful for here. You can create a segment which looks at the "Country" of the "Customer Address" to find a match. You'd create one segment for each country (or groups of countries) you want. The segment is updated automatically. You can then use the segment in price rules or whatever you want.

If you can describe what your end goal is with putting users in different groups based on country, a better solution may be provided.

Edit: Based on his comment, here's how to do that.

Log in to your admin and go to Customer --> Customer Segments and click "Add Segment". Then fill in the information and click "Save and Continue Edit". Then click the "Conditions" tab and follow along.

  1. Click the green "(+)" icon and choose "Customer Address" from the dropdown. Select "Customer Address"
  2. From the new menu, select "Country". Select "Country"
  3. And finally select the single country you want. enter image description here
  4. To have it be a group of countries (like all of United Kingdom) click on the "ALL" in the sentence If Customer Addresses match ALL of these Conditions

When you save, you can view the tab "Matched Customers" and see who all is included in these conditions.

Since these are dynamic groups, they change all the time and you can adjust the conditions as necessary to get the correct grouping you want. You can also export the results easily from the "Matched Customers" tab.

  • yeah that's what i'm saying – 3CE Feb 15 '17 at 22:59
  • Edited to show you how to do customer segments. – Brett Feb 17 '17 at 1:56
  • There is no such menu in my magento 1.9.3 ??? – Black Feb 19 at 16:34
0

Try to implement below process, hope it will help you

  1. app\etc\modules\Aman_Customergroup.xml
<?xml version="1.0"?>
<config>
  <modules>
    <Aman_Customergroup>
      <active>true</active>
      <codePool>local</codePool>
    </Aman_Customergroup>
  </modules>
</config>
  1. app\code\local\Aman\Customergroup\etc\config.xml
<?xml version="1.0"?>
<config>
  <modules>
    <Aman_Customergroup>
      <version>0.1.0</version>
    </Aman_Customergroup>
  </modules>
  <global>
  <events>
    <customer_register_success>
      <observers>
        <Aman_Customergroup_customer_register_success>
          <type>singleton</type>
          <class>Aman_Customergroup_Model_Observer</class>
          <method>customerRegisterSuccess</method>
        </Aman_Customergroup_customer_register_success>
     </observers>
    </customer_register_success>
  </events>
  </global>
</config>
  1. app\code\local\Aman\Customergroup\Model\Observer.php
<?php
class Aman_Customergroup_Model_Observer {
    public function customerRegisterSuccess(Varien_Event_Observer     $observer) {
    $event = $observer->getEvent();
    $customer = $event->getCustomer();
    $country = $customer->getCountry(); //get value of your country attribute

    if($country=="US") {
         $customer->setGroupId(5); // or whatever the group id should be
        $customer->save();
    }
}

} ?>

  • if( $country_id != "US"){ // if country is not US $customer->setData('group_id',27); //set groupid to 27(international group) $customer->save(); } – 3CE Feb 16 '17 at 14:58
  • so are you able to achieve what you are looking for? – aman Feb 17 '17 at 15:58
  • Not yet. I'm still struggling with this stuff.. – 3CE Feb 17 '17 at 16:00
  • So you only want to assign customer group automatically after registration to Standard if its country of residence is US else International right? – aman Feb 19 '17 at 4:50
  • Have updated the answer with detailed steps so please have a look – aman Feb 19 '17 at 5:59

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.