php 如何从订单中获取 CustomerName?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8698781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 05:18:12  来源:igfitidea点击:

How do I get CustomerName from an Order?

phpmagento

提问by sanjay kumar

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

Complete在操作下拉菜单(销售->订单)中添加了一个自定义选项。它工作正常,订单状态更改以成功完成。

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.

我正在将所有订单与Salesforce. 我需要所有订单详细信息orderid。项目详细信息和总计已成功获取。

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

任何人都可以帮助获取Customer姓名和他/她的公司名称如何提交订单。以下是我获取订单详细信息的完整代码:

$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();
}

回答by Anton S

try this

尝试这个

$order->getCustomerName()

回答by Magento Guy

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.

您可能不需要强制$order->getData()转换为新变量。这只会消耗内存,特别是因为您只需要从该数据中获取一个元素,可以使用强度较低的方法检索该元素。

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->getCustomerName()不适合您,请尝试:

$order->getBillingAddress()->getName();

回答by ShaunOReilly

$custname = $Order->getCustomer()->getName();