php 从 Magento 出口订单发货

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/617360/
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-24 23:16:36  来源:igfitidea点击:

Export Orders from Magento for shipment

phpmagentoexportshipping

提问by theandym

I am working on an online store on the Magento platform and have hit a major roadblock: For some reason I cannot figure out how to export current orders (with shipping information/shipment type/etc).Does anyone have any suggestions? This seems as if it should be one of the most basic things for a system like this to do, but I have not been able to find out how.

我正在 Magento 平台上的在线商店工作,遇到了一个主要障碍:由于某种原因,我无法弄清楚如何导出当前订单(包括运输信息/运输类型/等)。有没有人有什么建议?对于像这样的系统来说,这似乎应该是最基本的事情之一,但我一直无法找到方法。

Thank you in advance for your help,

预先感谢您的帮助,

Andy

安迪

回答by Manos Dilaverakis

Seeing as you want this for shipping you might want to ask whoever handles your shipping whether they have some sort of API so you can build/buy/download an appropriate shipping module and spare yourself the hassle of mucking about with CSV files.

看到您想要这个用于运输,您可能想询问处理您的运输的人是否有某种 API,以便您可以构建/购买/下载适当的运输模块,并免除自己处理 CSV 文件的麻烦。

If you really want a CSV file however I can show you how to create it. You didn't mention where this script will run so I'll assume it's an external script (which will make it easier to use with a cron job). You want to do the following:

如果你真的想要一个 CSV 文件,我可以告诉你如何创建它。你没有提到这个脚本将在哪里运行,所以我假设它是一个外部脚本(这将使它更容易与 cron 作业一起使用)。您想要执行以下操作:

//External script - Load magento framework
require_once("C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\magento\app\Mage.php");
Mage::app('default');

$myOrder=Mage::getModel('sales/order'); 
$orders=Mage::getModel('sales/mysql4_order_collection');

//Optional filters you might want to use - more available operations in method _getConditionSql in Varien_Data_Collection_Db. 
$orders->addFieldToFilter('total_paid',Array('gt'=>0)); //Amount paid larger than 0
$orders->addFieldToFilter('status',Array('eq'=>"processing"));  //Status is "processing"

$allIds=$orders->getAllIds();
foreach($allIds as $thisId) {
    $myOrder->reset()->load($thisId);
    //echo "<pre>";
    //print_r($myOrder);
    //echo "</pre>";

    //Some random fields
    echo "'" . $myOrder->getBillingAddress()->getLastname() . "',";
    echo "'" . $myOrder->getTotal_paid() . "',";
    echo "'" . $myOrder->getShippingAddress()->getTelephone() . "',";
    echo "'" . $myOrder->getPayment()->getCc_type() . "',";
    echo "'" . $myOrder->getStatus() . "',";
    echo "\r\n";
}

For the sake of brevity (and sanity) I haven't listed all the available order information. You can find out what fields are available by dumping the relevant objects and taking a look at their fields.

为了简洁(和理智),我没有列出所有可用的订单信息。您可以通过转储相关对象并查看它们的字段来找出哪些字段可用。

For example if you were to do print_r($myOrder->getBillingAddress()); you'd see fields like "address_type" and "lastname". You can use these with $myOrder->getBillingAddress()->getAddress_type() and $myOrder->getBillingAddress()->getLastname() respectively.

例如,如果您要执行 print_r($myOrder->getBillingAddress()); 你会看到像“address_type”和“lastname”这样的字段。您可以分别将它们与 $myOrder->getBillingAddress()->getAddress_type() 和 $myOrder->getBillingAddress()->getLastname() 一起使用。

Edit: Changed code according to craig.michael.morris's answer

编辑:根据 craig.michael.morris 的回答更改了代码

回答by morrislaptop

I was in the process of implementing your solution and noticed that it was only returning the first values for all the foreign keys such as billing address, shipping address, payment etc...

我正在实施您的解决方案并注意到它只返回所有外键的第一个值,例如帐单地址、送货地址、付款等...

This can be fixed by changing

这可以通过更改来解决

$myOrder->load($thisId);

$myOrder->load($thisId);

to

$myOrder->reset()->load($thisId);

$myOrder->reset()->load($thisId);

回答by morrislaptop

You may also want to look at this extension: http://www.magentocommerce.com/extension/1158/manual-order-export

您可能还想查看此扩展程序:http: //www.magentocommerce.com/extension/1158/manual-order-export

Also you can connect via soap: This example is set up for localhost and assumes you have set up a web services user and role under system>>web services in the admin.

你也可以通过soap连接:这个例子是为localhost设置的,并假设你已经在admin的system>>web services下设置了一个web服务用户和角色。

    <?php 
$time = microtime(); 
$time = explode(' ', $time); 
$time = $time[1] + $time[0]; 
$begintime = $time; 
?> 
<?php 
ini_set('error_reporting', E_ALL); 
ini_set('display_errors', 1); 
// hostname 
$host= '127.0.0.1'; 
// if store in /magento change /shop, if store in root remove /shop 
$client= new SoapClient('http://'.$host.'/magento/index.php/api/soap/?wsdl'); 

// Can be added in Magento-Admin -> Web Services with role set to admin 
$apiuser= 'soap'; 
// API key is password 
$apikey = '******'; 
$sess_id= $client->login($apiuser, $apikey); 
echo "<html>"; 
echo "<head>"; 
echo "<LINK REL=StyleSheet HREF=\"style.css\" TYPE=\"text/css\" MEDIA=screen>"; 
echo "</head>"; 
echo "<body>";

$result= $client->call($sess_id, 'sales_order.list',  array(array('status'=>array('='=>'Pending'))));
echo '<pre>';
print_r($result);
echo '<pre>';


?> 
<?php 
// Let's see how long this took… 
$time = microtime(); 
$time = explode(" ", $time); 
$time = $time[1] + $time[0]; 
$endtime = $time; 
$totaltime = ($endtime - $begintime); 
echo '<br /><br /><em>This Magento SOAP API script took ' .$totaltime. ' seconds, precisely.</em>'; 
// ...and close the HTML document 
echo "</body>"; 
echo "</html>"; 
?>

回答by Jase Clamp

In case this helps any one, you can use the invoice table as a key. An invoice in magento with a auth+capture credit card setup means the money has come in. In our case we only needed a sql query to run in phpmyadmin that would export order numbers and invoice numbers for us to reconcile to check that the order export extension from xtento was working. This is what we used:

如果这对任何人有帮助,您可以使用发票表作为关键字。magento 中带有 auth+capture 信用卡设置的发票意味着钱已经到账。在我们的例子中,我们只需要在 phpmyadmin 中运行一个 sql 查询,该查询将导出订单号和发票号,以便我们协调以检查订单导出xtento 的扩展正在运行。这是我们使用的:

 SELECT sales_flat_order.increment_id AS 'order', sales_flat_invoice.increment_id AS 'invoice'
   FROM sales_flat_order
  RIGHT JOIN sales_flat_invoice ON sales_flat_invoice.order_id = sales_flat_order.entity_id
  WHERE sales_flat_invoice.updated_at >= "2011-07-01 00:00:00"
  ORDER BY sales_flat_order.increment_id DESC 

回答by Sonam

Saho's suggestion for using SOAP is great, but it may take a long time (Apache can only assign a limited CPU resource to tread to handle that request)

Saho 对使用 SOAP 的建议很好,但可能需要很长时间(Apache 只能分配有限的 CPU 资源来处理该请求)

Suggest you to write a php script and then run it through terminal.

建议您编写一个php脚本,然后通过终端运行它。

Sonam

索南

回答by Matt Haley

If the system doesn't support any direct way to export orders, you could create a view in the database that lists the orders you need to export. Then use something like phpMyAdmin to export the data from the view as CSV.

如果系统不支持任何直接导出订单的方式,您可以在数据库中创建一个视图,列出您需要导出的订单。然后使用类似 phpMyAdmin 的工具将视图中的数据导出为 CSV。