3
votes

I have a custom field in my onepage checkout, that is used in a Model\Observer.php to set the customer group using the following:

$customer = Mage::getSingleton("customer/session")->getCustomer();
$customer->setGroupId($newGroupId)->save();

This all works great, and I'm doing this to change the Tax in the cart.

However, for people checking out as a guest it throws an error:

customer email is required

Is there a way of setting a customer group for a guest, a second NOT LOGGED IN group for example?

1

1 Answers

5
votes

check user session then set customer email address.

  $session = Mage::getSingleton('customer/session');  
  $customer = $session->getCustomer();  
  if($session->isLoggedIn()) {  
     $customer->setGroupId($newGroupId)->save();  
  } else {  
     $customer->setEmail($customer->getData('email')); 
     $customer->setGroupId('2'); // I am assuming 'guest' groupd id is 2
     $customer->save();
  }