Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get CustomerName from an Order?

Tags:

php

magento

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();
}
like image 647
sanjay kumar Avatar asked Jan 02 '12 08:01

sanjay kumar


2 Answers

try this

$order->getCustomerName()
like image 177
Anton S Avatar answered Nov 05 '22 16:11

Anton S


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();
like image 31
Magento Guy Avatar answered Nov 05 '22 17:11

Magento Guy