如何找到与每个订单相关联的跟踪编号?我创建了一个输出数据的脚本。我尝试了很多变化,但它们都返回空白/空。
目前,它输出
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>";
}
?>
答案 0 :(得分:1)
这是工作脚本。我们想通了: - )
<?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);
$carrierInstances = Mage::getSingleton('shipping/config')->getAllCarriers();
$carriers['custom'] = Mage::helper('sales')->__('Custom Value');
foreach ($carrierInstances as $code => $carrier) {
if ($carrier->isTrackingAvailable()) {
$carriers[$code] = $carrier->getConfigData('title');
}
}
$from = "2013-03-24 00:00:00"; // orders from date
$to= "2013-06-21 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);
//Some random fields
echo $myOrder->getRealOrderId() . " ";
$trackings = Mage::getResourceModel('sales/order_shipment_track_collection')
->setOrderFilter($myOrder)
->getData();
foreach ($trackings as $tracking) {
echo $tracking['track_number'] . " ";
}
echo $carriers[$tracking['carrier_code']] . " ";
echo $myOrder->getCreatedAtDate() . " ";
// echo "'" . $myOrder->getStatus() . "',";
// echo "'" . $myOrder->getBillingAddress()->getLastname() . "',";
// echo "'" . $myOrder->getTotal_paid() . "',";
// echo "'" . $myOrder->getShippingAddress()->getTelephone() . "',";
// echo "'" . $myOrder->getPayment()->getCc_type() . "',"; // bad code
echo "\r\n";
echo "</pre>";
}
?>