如何保存用于结帐的客户名称?


9

客户名称未保存在onestepcheckout模块中。我在保存订单时错过了步骤吗?

$shippingInfo = array(
        'city'=> (string)$shippingAddress->City,
        'country_id' => (string)$shippingAddress->CountryCode,
        'email' => (string)$customerInfo->Email,
        'firstname' => (string)$firstname,
        'lastname' => (string)$lastname,
        'postcode' => (string)$shippingAddress->PostalCode,
        'street' => array(   (string)$shippingAddress->AddressLine1, ),
        'telephone' => (string)$shippingAddress->Phone,
        'use_for_shipping' => '1',
        'name'=>'hello there'
    );
    if(!empty($regionId)){
        $shippingInfo['region_id'] = $regionId;
    }
    else{
        $shippingInfo['region'] = $regionCode;
    }

$quote = $this->getOnepage()->getQuote();  
$quote->collectTotals()->save();
$quote->getBillingAddress()
    ->addData($shippingInfo);

$quote->getShippingAddress()
    ->addData($shippingInfo);
$quote->setCheckoutMethod('guest')
        ->setCustomerId(null)
        ->setCustomerEmail('test@example.com')
        ->setCustomerIsGuest(true)
        ->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID)->save();
    $this->getOnepage()->saveOrder();
    $this->getOnepage()->getQuote()->save();

在此处输入图片说明

Answers:


9

遗憾的是您没有错过任何一步。在管理部分模板中,/app/design/adminhtml/default/default/template/sales/order/view/info.phtml您可以看到订单上对getCustomerName的调用。

在订单类中Mage_Sales_Model_Order,getCustomerName函数如下:

public function getCustomerName()
{
    if ($this->getCustomerFirstname()) {
        $customerName = $this->getCustomerFirstname() . ' ' . $this->getCustomerLastname();
    }
    else {
        $customerName = Mage::helper('sales')->__('Guest');
    }
    return $customerName;
}

当系统准备好客户报价时,​​它永远不会设置名字和姓氏,因此永远不会保存到订单中:

protected function _prepareGuestQuote()
{
    $quote = $this->getQuote();
    $quote->setCustomerId(null)
        ->setCustomerEmail($quote->getBillingAddress()->getEmail())
        ->setCustomerIsGuest(true)
        ->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
    return $this;
}

因此,遗憾的是,所有客人订单都将在“管理员”部分中显示为客人。您可以在此处执行以下操作之一。

  1. 如果代码不在标准过程中,请使用以下$quote->setCustomerFirstname($firstname)$quote->setCustomerLastname($lastname)
  2. 镜像前端订单电子邮件显示,并采用帐单地址中设置的名称。 $customerName = $this->getBillingAddress()->getName();
  3. 在操作上设置客户的名字和姓氏(来自地址)sales_order_place_beforesales_convert_quote_to_order

观察员sales_convert_quote_to_order不起作用。可能我做错了class Amazon_Payments_Model_Observer extends Varien_Object { public function salesQuoteSaveAfter($observer) { $order = $observer->getEvent()->getOrder(); $order->setCustomerFirstname('ljslkdfjds'); $order->save();
Vlad Vinnikov

你有任何错误吗?
David Manners

getMethodInstance() 在中的非对象上调用成员函数app/code/core/Mage/Payment/Model/Observer.php
Vlad Vinnikov

3

更新结帐代码解决了我的问题: app/code/local/AW/Onestepcheckout/controllers/AjaxController.php

$quote = $this->getOnepage()->getQuote();
$quote->collectTotals()->save();
$quote->getBillingAddress()
        ->addData($shippingInfo);

$quote->getShippingAddress()
        ->addData($shippingInfo);

$quote->setCustomerFirstname('first')->setCustomerLastname('last');
$this->getOnepage()->saveOrder();
$this->getOnepage()->getQuote()->save();
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.