5

I had added a custom option Complete in action dropdown(sales->orders). It's working fine and order status changes to complete successfully.

I am integrating all orders with Salesforce. I have need of all of order details by orderid. Item details and grand total is fetched successfully.

Can anyone please help to fetch Customer name and his/her company name how submitted order. Below is my complete code to fetch order details:

$order = Mage::getModel('sales/order')->load($orderId);
$items = $order->getAllItems();
$_totalData = $order->getData();
$_grand = $_totalData['grand_total'];
$custname = $_totalData->getCustomerName();
$itemcount=count($items);
foreach ($items as $itemId => $item)
{
    $sObject2->Item_name__c = $item->getName();
    $sObject2->Unit_price__c = $item->getPrice();
    $sObject2->Sku__c = $item->getSku();
    $sObject2->Quantity__c = $item->getQtyToInvoice();
}
STW
  • 44,917
  • 17
  • 105
  • 161
sanjay kumar
  • 69
  • 1
  • 2
  • 9

3 Answers3

16

try this

$order->getCustomerName()
Anton S
  • 12,750
  • 2
  • 35
  • 37
  • Thanks Anton, its working for me. I need customerid and i am fetching them easily with your suggetion. – sanjay kumar Jan 04 '12 at 14:24
  • 2
    If it is a guest checkout order this will not return the name! – steros Feb 01 '18 at 15:03
  • When order is edited - can not get data - $order->getCustomerFirstname() becouse not exist. better use $order->getBillingAddress()-> getFirstname(); – Alex Oct 11 '18 at 11:46
4

You probably don't need to cast $order->getData() to a new variable. This will only serve to chew up memory, especially since there is only one element you need from that data, which can be retrieved with a less intensive method.

Instead, try it this way:

$order = Mage::getModel('sales/order')->load($orderId);
$_grand = $order->getGrandTotal();
$custname = $order->getCustomerName();
foreach ($order->getAllItems() as $itemId => $item)
{
  // Do stuff
}

if $order->getCustomerName() doesn't work for you, try:

$order->getBillingAddress()->getName();
Magento Guy
  • 2,493
  • 1
  • 16
  • 13
-1
$custname = $Order->getCustomer()->getName();
ShaunOReilly
  • 2,186
  • 22
  • 34