【问题标题】:Customer email is required error on Checkout when going through as a guest以访客身份办理结账时需要客户电子邮件错误
【发布时间】: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


    【解决方案1】:

    对于来宾用户,您为什么要尝试在客户资料中保存组织 ID,因为 Magento 不会在客户实体中为来宾用户创建客户,所以没有要保存的客户资料。您需要在上面的函数中添加条件来解决问题

    if(!$order->getCustomerIsGuest()){
       // 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();
    }
    

    希望以上帮助

    干杯 S

    【讨论】:

    • +1 用于返回没有答案的旧帖子,我自己找到了答案但忘记将其添加到此页面,因为它是很久以前的并且忘记了这个问题。
    • 别担心,反正我认为它会帮助别人!
    猜你喜欢
    • 1970-01-01
    • 2023-02-08
    • 2012-07-28
    • 1970-01-01
    • 2012-01-21
    • 1970-01-01
    • 2021-03-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多