9

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('[email protected]')
        ->setCustomerIsGuest(true)
        ->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID)->save();
    $this->getOnepage()->saveOrder();
    $this->getOnepage()->getQuote()->save();

enter image description here

2 Answers 2

9

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:

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

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:

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;
}

So sadly all guest orders will be displayed as guest in the admin section. You could do one of the following things here.

  1. If the code is not in the standard process just use the following $quote->setCustomerFirstname($firstname) and $quote->setCustomerLastname($lastname).
  2. Mirror the front end order email display and take the name set in the billing address. $customerName = $this->getBillingAddress()->getName();
  3. Set the customer first and last name (from the address) on the action sales_order_place_before or sales_convert_quote_to_order
3
  • Observer sales_convert_quote_to_order doesn't work. probably I'm doing something wrong class Amazon_Payments_Model_Observer extends Varien_Object { public function salesQuoteSaveAfter($observer) { $order = $observer->getEvent()->getOrder(); $order->setCustomerFirstname('ljslkdfjds'); $order->save(); Commented Nov 1, 2013 at 22:57
  • Do you get any errors with that? Commented Nov 2, 2013 at 6:49
  • Call to a member function getMethodInstance() on a non-object in app/code/core/Mage/Payment/Model/Observer.php. Commented Nov 3, 2013 at 13:32
3

updating checkout code solved my problem: 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();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.