Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Change customergroupid for not logged in customers
 
keijers
Jr. Member
 
Total Posts:  15
Joined:  2012-10-15
 

I know I can change the customer group with this code:

$session  Mage::getSingleton(\'customer/session\');
$customer $session->getCustomer();
if(
$customer->getId()) {
 $customer
->setEmail($customer->getData(\'email\'));
 
$customer->setGroupId(\'2\'); // custom group id
 
$customer->save();
 
Mage::getSingleton(\'customer/session\')->loginById($customer->getId());
 
}

But that doesn\’t work if the customer isn\’t logged in. How to change te customergroupid for not logged in customers?

I want to assign them after filling in a zip code on the homepage to display the products that belong to their zip code / customer group!

 
Magento Community Magento Community
Magento Community
Magento Community
 
keijers
Jr. Member
 
Total Posts:  15
Joined:  2012-10-15
 

I\’ve found this code to change the group_id, a lot shorter than the one above:

Mage::getSingleton(\'customer/session\')->getCustomer()->setGroupId(2);

but it still doesn\’t work for customers that er not logged in, they keep groupid 0.

How to change it? Someone??

 
Magento Community Magento Community
Magento Community
Magento Community
 
keijers
Jr. Member
 
Total Posts:  15
Joined:  2012-10-15
 

Found the solution:

Mage::getSingleton('customer/session')->setCustomerGroupId(1);
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top