0

I got a project In which I have to make a store in which when customer registered email id yourname@yourname.com domain then he/she will be consider as premium customer and I have to assign them particular product which only Premium customer can Access and other customer registered with other domain Email id will be general customer and they can not have access to premium product

For this I follow this link How to assign a group to user based on their email id on registration

and created an module based on code but it is not working Here is my Code of

app\etc\modules/Xyz.xml

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

Then Code for my app\code\local\Xyz\Catalog\etc/config.xml

<?xml version="1.0"?>
<config>
  <global>
    <models>
        <xyzcatalog>
             <class>Xyz_Catalog_Model</class>
        </xyzcatalog>
    </models>
    <events>
      <customer_save_after>
        <observers>
          <change_customer_group>
            <type>singleton</type>
            <class>magento63798/observer</class>
            <method>ChangeCustomerGroup</method>
          </change_customer_group>
        </observers>
      </customer_save_after>    
    </events>
  </global>
</config> 

And code for my observer is in app\code\local\Xyz\Catalog\Model\Observer/Observer.php

    <?php
    class Stackexchange_Magento63798_Model_Observer
    {
        public function ChangeCustomerGroup(Varien_Event_Observer $observer){

            $customer=$observer->getEvent()->getCustomer();
            Mage::log('My log entry'.$customer->getId(), null, 'Magento63798.log');

            $premiummember=4;// 4 is the id of customer group I have created 
            $Guestmember=5;
            list($user, $domain) = explode('@',$customer->getEmail());

            if ($domain == 'gmail.com'):
                /* set Customer group as Stiudent */
                $customer->setData('group_id',$StudentGroup);   
            // use gmail
            else:
                $customer->setData('group_id',$GuestGroupId);   
            endif;
 }

But when I registered the user with email id of like of premium member it is not goes into premium member group but goes to general Group

1

You need to change the customergroup before_save

Beside this, you better use customer_register_success. Unfortunately the customer is saved also, so you have to call $customer->save() again.

0

I have used following codes in my project you can try

app\code\local\Paras\Headerchanger\etc\config.xml

<?xml version="1.0"?>
    <config>
      <modules>
        <Paras_Headerchanger>
          <version>0.1.0</version>
        </Paras_Headerchanger>
      </modules>
      <frontend>
        <routers>

          <customer>
                    <args>
                        <modules>
                            <paras_headerchanger before="Mage_Customer">Paras_Headerchanger</paras_headerchanger>
                        </modules>
                    </args>
           </customer>
        </routers>

      </frontend> 
    </config> 

app\code\local\Paras\Headerchanger\controllers\AccountController.php

<?php

require_once Mage::getModuleDir('controllers', 'Mage_Customer').DS.'AccountController.php';

class Paras_Headerchanger_AccountController extends Mage_Customer_AccountController
{
       /**
     * Get Customer Model
     *
     * @return Mage_Customer_Model_Customer
     */
    protected function _getCustomer()
    {
        $customer = $this->_getFromRegistry('current_customer');
        if (!$customer) {
            $customer = $this->_getModel('customer/customer')->setId(null);
        }
        if ($this->getRequest()->getParam('is_subscribed', false)) {
            $customer->setIsSubscribed(1);
        }
        /**
         * Initialize customer group id
         Get group id
         */
        if($this->getRequest()->getPost('group_id')){ 

                $customer->setGroupId($this->getRequest()->getPost('group_id'));
            } else {
                $customer->getGroupId(); 
            } 

        return $customer;
    }
}

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.