克里斯的OP已經回答了這個問題,但只是爲此增加一些額外的價值Q &這是我工作的代碼。
作爲一些背景,我使用Transaction ID的原因是因爲它們被Paypal使用。我正在編寫一個cron作業,將Paypal API訂單從過去的24小時中提取出來,然後我們通過SOAP將所有訂單從過去24小時的SOAP中提取出來,獲取交易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;
}
}
}
+1感謝您的指針。絕對荒謬的是,我們必須從銷售訂單歷史記錄中的評論中挖掘訂單的交易ID。 – McNab