一些前程序員使用Magento SOAP API V1編寫了該程序,以便將已發貨的訂單標記爲已發貨。在以前的Magento vs 1.5平臺上它運行良好,但是現在在1.7版跟蹤號碼本身並沒有被導入。正如你所看到的一樣,我的名字已被註釋掉// Caitlin。上面這行代碼是前程序員放的,之後的兩行代碼是我認爲代碼應該用於Magento vs 1.7的代碼,但是我最後一次嘗試使用這個代碼段時停止了他們的操作。這對你看起來是否正確?有任何想法嗎?Magento SOAP API sales_order_shipment創建和addTrack問題
$comment = '<b><br>*** Order has shipped. ***</b><br/><br/>' .
'<b>3PL order number:</b> ' . $fields[1] . '<br/>' .
'<b>Weight:</b> ' . $fields[2] . '<br/>' .
'<b>Shipped via:</b> ' . $fields[3] . '<br/>' .
'<b>Tracking number:</b> ' . $fields[4] . '<br/>' .
'<b>Ship date:</b> ' . $fields[5] . '<br/>' .
'<b>Postage:</b> ' . $fields[6] . '<br/>' .
'<b>Fulfillment:</b> ' . $fields[7] . '<br/>' .
'<b>Per packslip:</b> ' . $fields[8];
// Make shipment and add tracking number
if ($fields[3] == 'UPS-RESIDENTIAL') { $shippedby = 'ups'; $shipname = 'UPS Ground'; }
elseif ($fields[3] == 'UPS-2') { $shippedby = 'ups'; $shipname = 'UPS 2nd Day Air'; }
elseif ($fields[3] == 'UPS-OVERNIGHT') { $shippedby = 'ups'; $shipname = 'UPS Next Day Air Saver'; }
elseif ($fields[3] == 'USPS-PRI') { $shippedby = 'usps'; $shipname = 'USPS Priority'; }
elseif ($fields[3] == 'CANADA') { $shippedby = 'custom'; $shipname = 'MSI Canada (Standard) '; }
elseif ($fields[3] == 'MSITRACK') { $shippedby = 'custom'; $shipname = 'MSI Canada (Express)'; }
else { $shippedby = 'custom'; }
// Attempt to create the order, notify on failure
try {
$newShipmentId = $client->call($sess_id, 'sales_order_shipment.create', array($ShippedOrderId, array(), $comment, true, false, $shippedby, $shipname, $fields[4]));
//Caitlin
//$newShipmentId = $client->call($sess_id, 'sales_order_shipment.create', array($ShippedOrderId, array(), $comment, true, false));
//$newTrackId = $proxy->call($sessionId, 'sales_order_shipment.addTrack', array($newShipmentId, $shippedby, $shipname, $fields[4]));
}
catch (Exception $e) { echo 'Shipment creation failed on order '. $ShippedOrderId . ': ', $e->getMessage(); }
// Add comment to order with all the info
$client->call($sess_id, 'sales_order.addComment', array($ShippedOrderId, 'complete', $comment, false));
$mail_content .= $line . "\n";
$importcount++;
}
//}
}
編輯13年2月25日
使用下面的實現。我從運行此腳本錯誤。我還沒有能夠測試它,因爲我不得不在cron在凌晨5點運行。
// Make shipment and add tracking number
if ($fields[3] == 'UPS-RESIDENTIAL') { $shippedby = 'ups'; $shipname = 'UPS Ground'; }
elseif ($fields[3] == 'UPS-2') { $shippedby = 'ups'; $shipname = 'UPS 2nd Day Air'; }
elseif ($fields[3] == 'UPS-OVERNIGHT') { $shippedby = 'ups'; $shipname = 'UPS Next Day Air Saver'; }
elseif ($fields[3] == 'USPS-PRI') { $shippedby = 'usps'; $shipname = 'USPS Priority'; }
elseif ($fields[3] == 'CANADA') { $shippedby = 'custom'; $shipname = 'MSI Canada (Standard) '; }
elseif ($fields[3] == 'MSITRACK') { $shippedby = 'custom'; $shipname = 'MSI Canada (Express)'; }
else { $shippedby = 'custom'; }
/////////////////////////////////////////////
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
$shipment_collection = Mage::getResourceModel('sales/order_shipment_collection');
$shipment_collection->addAttributeToFilter('order_id', $orderId);
$shipment_collection->load();
$firstItem = $shipment_collection->getFirstItem();
if(count($shipment_collection) > 1)
{
$track_no = $fields[4]; // insert tracking # string here
$shipment = Mage::getModel('sales/order_shipment');
$shipment->load($firstItem->getId());
if($shipment->getId() != '')
{
$track = Mage::getModel('sales/order_shipment_track')
->setShipment($shipment)
->setData('title', $shipname) // User syntax correct name here
->setData('number', $track_no)
->setData('carrier_code', $shippedby) // use code that matches DB code for ship method here
->setData('order_id', $shipment->getData('order_id'));
$track->save();
}
return true;
} else {
$orderShip = $order->prepareShipment(); // can take sku => qty array
$orderShip->register();
$orderShip->sendEmail();
$tracker = Mage::getModel('sales/order_shipment_track');
$tracker->setShipment($orderShip);
$tracker->setData('title', $shipname);
$tracker->setData('number', $importData['Tracking Number']);
$tracker->setData('carrier_code', $shippedby);
$tracker->setData('order_id', $orderId);
$orderShip->addTrack($tracker);
$orderShip->save();
$order->setData('state', "complete");
$order->setStatus("complete");
$history = $order->addStatusHistoryComment('Order marked as complete by shipment code.', false);
$history->setIsCustomerNotified(false);
$order->save();
/////////////////////////////////////////////////
// Add comment to order with all the info
$client->call($sess_id, 'sales_order.addComment', array($ShippedOrderId, 'complete', $comment, false));
$mail_content .= $line . "\n";
$importcount++;
}
//}
}
我拿出了試試看,並把我上面的東西(見我的編輯)和克隆沒有運行那天晚上。你有沒有看到任何錯誤? – CaitlinHavener 2013-02-25 17:27:43
嘗試從shell進行手動運行以進行調試。有時Magento的內置cron不能按預期運行。 – mprototype 2013-02-26 08:23:26
我確實在您的實現中看到錯誤,其中一些變量需要用您的數據替換。特別是在注入實際追蹤號碼的地方。 – mprototype 2013-02-26 08:24:12