How to get CustomerName from an order?

I added the custom option Complete in the drop-down list of actions (sales-> orders). It works great and changing order status completes successfully.

I integrate all orders with Salesforce . I need all order details on orderid . Product details and total amount successfully uploaded.

Someone can help get the name Customer and his / her company name, how the order is sent. Below is the full code for ordering information:

 $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(); } 
+4
source share
3 answers

try it

 $order->getCustomerName() 
+14
source

You probably don't need to throw $order->getData() into a new variable. This will only be to chew on the memory, especially since from this data only one element is required, which can be obtained using a less intensive method.

Instead, try this:

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

If $order->getCustomerName() does not work for you, try:

 $order->getBillingAddress()->getName(); 
+2
source
 $custname = $Order->getCustomer()->getName(); 
-1
source

Source: https://habr.com/ru/post/1388898/


All Articles