In Magento 1.7, whenever I go through the checkout process as guest at the end of the onepage checkout process I get the Magento error:
Customer email is required
Having used xDebug to profile the problem the code I have in my observer which is executed on the sales_order_place_after observer I have a function called afterOrderPlaced()
public function afterOrderPlaced($observer)
{
$organisation_id = Mage::getSingleton('customer/session')->getOrganisationId(); #$organisation_id = 25679;
$this->_order = $observer->getEvent()->getOrder();
$this->_order->setOrganisationId($organisation_id)->save();
// Customer stuff
$this->_customer_id = $this->_order->getCustomerId();
$this->_customer = $this->_order->getCustomer();
// problem on the next line below #PROBLEM HERE#
$this->_customer->setOrganisationId($organisation_id)->save();
}
The issue is on the last line of the function - for some reason it doesn't seem to like the save() on the customer object. This goes into the core files in Mage\Core\Model\Resource\Transaction.php on line 161 within the save() - see below:
public function save()
{
$this->_startTransaction();
$error = false;
try {
foreach ($this->_objects as $object) {
$object->save();
}
} catch (Exception $e) {
$error = $e;
}
if ($error === false) {
try {
$this->_runCallbacks();
} catch (Exception $e) {
$error = $e; ## ERROR IS HAPPENING HERE?! ##
}
}
if ($error) {
$this->_rollbackTransaction();
throw $error;
} else {
$this->_commitTransaction();
}
return $this;
}
Can anyone indicate what my problem maybe within my observer and why it doesn't seem to like to save the custom organisation_id to the customer object?