如何找到与每个订单关联的跟踪号?我创建了一个脚本来输出数据。我尝试了很多变体,但它们都返回空白/空。
目前,它输出
103236290 United States Postal Service - First-Class Mail Parcel Mar 23, 2013 10:12:59 PM
请注意,输出是制表符分隔的,因此在订单 ID 和发货方式之间有两个制表符。
<?php
//External script - Load magento framework
require_once($_SERVER['DOCUMENT_ROOT'] . "/store/app/Mage.php");
Mage::app('default');
$myOrder=Mage::getModel('sales/order');
$ship = Mage::getModel('sales/order_shipment');
$orders=Mage::getModel('sales/mysql4_order_collection');
$trackings=Mage::getResourceModel('sales/order_shipment_track_collection')->addAttributeToSelect('*')->addAttributeToFilter('parent_id',$ship->getId());
$trackings->getSelect()->order('entity_id desc')->limit(1);
$trackData = $trackings->getData();
$trackID = $trackData[0]['entity_id'];
$from = "2013-03-24 00:00:00"; // orders from date
$to= "2013-06-20 00:00:00"; // orders to date
//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'=>"Complete")); //Status is: "complete", "processing" "canceled" etc.
$orders->addAttributeToFilter('created_at', array(
'from' => $from,
'to' => $to,
));
$allIds=$orders->getAllIds();
foreach($allIds as $thisId) {
$myOrder->reset()->load($thisId);
echo "<pre>";
//print_r($myOrder);
//Fields to print
echo $myOrder->getRealOrderId() . " ";
echo $trackID . " ";
echo $myOrder->getShippingDescription() . " ";
echo $myOrder->getCreatedAtDate() . " ";
echo "\r\n";
echo "</pre>";
}
?>