Customer name is not being saved in onestepcheckout module. Is there a step I missed in saving order?
$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();
Best Answer
Sadly you have not missed a step. In the admin section template
/app/design/adminhtml/default/default/template/sales/order/view/info.phtml
you can see the call to getCustomerName on the order.In the order class
Mage_Sales_Model_Order
the getCustomerName function is as follows:When a guest quote is prepared by the system it never sets the first and last name and so it never gets saved to the order:
So sadly all guest orders will be displayed as guest in the admin section. You could do one of the following things here.
$quote->setCustomerFirstname($firstname)
and$quote->setCustomerLastname($lastname)
.$customerName = $this->getBillingAddress()->getName();
sales_order_place_before
orsales_convert_quote_to_order