我的csv包含跟踪号,跟踪链接,运营商代码,订单号。我可以将跟踪号码,运营商代码设置为特定订单,但无法为同一订单设置跟踪网址。请建议我一些代码片段或任何解决此查询的方法。
if (($handle = fopen("".$webshopimport_path."\\CSV\\trackandtrace.csv", "r")) !== FALSE)
{
while (($data = fgetcsv($handle, 100000, ",")) !== FALSE)
{
Mage::init();
$comment = null;
$email = false;
$includeComment = false;
$orderId = '100000065'; //get ordernumber from csv
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
$convertor = Mage::getModel('sales/convert_order');
$shipment = $convertor->toShipment($order);
foreach ($order->getAllItems() as $orderItem)
{
if (!$orderItem->getQtyToShip()) {
continue;
}
if ($orderItem->getIsVirtual()) {
continue;
}
$item = $convertor->itemToShipmentItem($orderItem);
$qty = $orderItem->getQtyToShip();
$item->setQty($qty);
$shipment->addItem($item);
}
$trackdata = array();
$trackdata['carrier_code'] = $data[2]; //get carrier_code from csv
$trackdata['title'] = $data[2]; //get title from csv
$trackdata['number'] = $data[3]; //get track number from csv
$track = Mage::getModel('sales/order_shipment_track')->addData($trackdata);
$shipment->addTrack($track);
Mage::register('current_shipment', $shipment);
$shipment->register();
$shipment->addComment($comment, $email && $includeComment);
$shipment->setEmailSent(true);
$shipment->getOrder()->setIsInProcess(true);
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($shipment)
->addObject($shipment->getOrder())
->save();
$shipment->sendEmail($email, ($includeComment ? $comment : ''));
}
fclose($handle);
$retVar = true;
}
答案 0 :(得分:0)
您不应为订单设置任何跟踪网址,因为跟踪网址是使用订单跟踪编号和送货服务跟踪网址结构自动生成的。
例如,UPS跟踪网址为:http://wwwapps.ups.com/WebTracking/track?track=yes&trackNums= {tracking_number}