【发布时间】:2014-05-14 14:22:02
【问题描述】:
在 Magento 1.7 中,每当我在单页结帐过程结束时以访客身份完成结帐过程时,我都会收到 Magento 错误:
Customer email is required
使用 xDebug 来分析我在观察者中的代码问题,该代码在 sales_order_place_after 观察者上执行,我有一个名为 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();
}
问题出在函数的最后一行——由于某种原因,它似乎不喜欢客户对象上的 save()。这将进入 save() 内第 161 行的 Mage\Core\Model\Resource\Transaction.php 中的核心文件 - 见下文:
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;
}
谁能指出我的观察者可能遇到的问题以及为什么它似乎不喜欢将自定义组织 ID 保存到客户对象?
【问题讨论】:
标签: magento magento-1.7