一部の元プログラマーは、Magento SOAP API V1 を使用してこのプログラムを作成し、出荷済みの注文を出荷済みとしてマークしました。以前の Magento vs 1.5 プラットフォームでは問題なく動作しましたが、vs 1.7 では追跡番号自体がインポートされていません。途中でわかるように、私の名前はコメントアウトされています //Caitlin. その上の行は元プログラマーが書いたもので、その次の 2 行は Magento と 1.7 のコードであると思われるものですが、前回このスニペットを試したとき、彼らの操作を停止しました。これは正しいように見えますか? 何か案は?
$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++;
}
//}
}
2013 年 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++;
}
//}
}