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('test@example.com')
        ->setCustomerIsGuest(true)
        ->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID)->save();
    $this->getOnepage()->saveOrder();
    $this->getOnepage()->getQuote()->save();

enter image description here

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
  • 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(); – Vlad Vinnikov Nov 1 '13 at 22:57
  • Do you get any errors with that? – David Manners Nov 2 '13 at 6:49
  • Call to a member function getMethodInstance() on a non-object in app/code/core/Mage/Payment/Model/Observer.php. – Vlad Vinnikov Nov 3 '13 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, privacy policy and cookie policy

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