OP Chris 已经回答了这个问题,但只是为了给这个问答增加一些额外的价值,这是我正在工作的代码。
作为一些背景,我完全使用交易 ID 的原因是因为它们被 Paypal 使用。我正在编写一个 cron 作业,它在过去 24 小时内从 Paypal API 拉出 Paypal 订单,然后我们在过去 24 小时内通过 SOAP 从 Magento 拉出所有订单,获取交易 ID 并将它们与 Paypal 列表匹配。这是为了确保没有不在 Magento 上的 Paypal 订单,有时我们会遇到 IPN 故障,这会阻止 Magento 报价转换为订单,并且客户会通过 Paypal 向他们收费,但由于从未创建订单,因此没有产品被运送给他们。如果不匹配,则会向客户服务发送电子邮件警报。
$startDate = gmdate('Y-m-d H:i:s', strtotime('-1 day', time()));
$complex_params =array(
array('key'=>'created_at','value'=>array('key' =>'from','value' => $startDate))
);
$result = $client_v2->salesOrderList($session_id, array('complex_filter' => $complex_params));
// We've got all the orders, now we need to run through them and get the transaction id from the order info
// We create an array just to hold the transaction Ids
$ikoTransactionIds = array();
foreach ($result as $invoice) {
$invoiceInfo = $client_v2->salesOrderInfo($session_id, $invoice->increment_id);
$history = $invoiceInfo->status_history;
$comments = $history[0]->comment;
// Only the Paypal based records have transaction Ids in the comments, orders placed via credit card do not. In these cases $comments are null
if ($comments) {
// Check if the text 'Transaction ID:' exists at all
if ((strpos($comments, "Transaction ID:")) !== FALSE) {
list($before, $transactionId) = explode('Transaction ID: ', $comments);
// Remove the trailing period
$transactionId = rtrim($transactionId ,".");
// Remove the quotes
$transactionId = str_replace('"', '', $transactionId);
// We add the id to our array of ids for this Magento install
$ikoTransactionIds[] = $transactionId;
}
}
}