升级后我一直在为客户端重新实现此脚本,但我被卡住了(也许大脑被炸了)。其中大部分与您无关。我遇到问题的部分在这里:
try
{
$customer_exists = $client->call($sess_id, 'sales_order.info', $ShippedOrderId);
}
catch (exception $e)
{
echo 'Exception: ' . $e . "<br/>";
}
它抛出以下异常:
“异常:SoapFault 异常:[100] 请求的订单不存在。在 /home/ab71714/public_html/exporter/importer-sftp.php:140 堆栈跟踪:#0 /home/ab71714/public_html/exporter/importer-sftp.php (140): SoapClient->__call('call', Array) #1 /home/ab71714/public_html/exporter/importer-sftp.php(140): SoapClient->call('9cafc83722b06f2...', 'sales_order. inf...', '100015822') #2 {main}"
整个事情都在跟随。非常感谢任何帮助!
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
var_dump(extension_loaded('ssh2'));
// URL to Magento SOAP API
$client = new SoapClient('http://animalnecessity.com/api/soap?wsdl');
$apiuser = '';
$apikey = '';
// FTP info
$ftp_server = 'ftp.3plworldwide.com';
$ftp_user_name = '';
$ftp_user_pass = '';
// Address to mail report to
$mail_to = '';
$mail_content = "Checking for 3PL shipping import files on " . date('m/d/Y') . "\n\n";
/*** Begin FTP ***/
// Set up SFTP connection
$conn_id = ssh2_connect($ftp_server, 22);
$login_result = ssh2_auth_password($conn_id, $ftp_user_name, $ftp_user_pass);
$sftp = ssh2_sftp($conn_id);
// Check connection results
if ((!$conn_id) || (!$login_result)) {
$mail_content .= "SFTP connection has failed.\n";
$mail_content .= "Attempted to connect to $ftp_server under user '$ftp_user_name', password '$ftp_user_pass'.\n\n";
} else {
$mail_content .= "Successfully connected to $ftp_server with an SFTP secure connection, under user '$ftp_user_name', password '$ftp_user_pass'.\n\n";
}
// Download the files in the SHIPMENTS folder
$download = true;
$dirHandle = opendir("ssh2.sftp://$sftp/SHIPMENTS/");
if ($dirHandle)
{
$filelist = '';
$downarray = array();
while (false !== ($file = readdir($dirHandle)))
{
if (strpos($file, 'OCU_SHP_') !== false)
{
// Choose only shipment files up to 7 days back
$datetag = substr($file, 8, 6);
$year = substr($datetag, 0, 2);
$month = substr($datetag, 2, 2);
$day = substr($datetag, 4, 2);
if (!is_numeric($year)) { continue; }
$datestamp = mktime(0, 0, 0, $month, $day, $year);
if ($datestamp > strtotime('-7 days'))
{
$fileName = 'SHIPMENTS/' . $file;
// Remote stream
if (!$remoteStream = @fopen("ssh2.sftp://$sftp/$fileName", 'r'))
{
$mail_content .= "Unable to open remote file: $fileName\n";
$download = false;
}
// Local stream
if (!$localStream = @fopen("./$fileName", 'w'))
{
$mail_content .= "Unable to open local file for writing: ./$fileName\n";
$download = false;
}
// Write from our remote stream to our local stream
$read = 0;
$fileSize = filesize("ssh2.sftp://$sftp/$fileName");
while ($read < $fileSize && ($buffer = fread($remoteStream, $fileSize - $read)))
{
// Increase our bytes read
$read += strlen($buffer);
// Write to our local file
if (fwrite($localStream, $buffer) === FALSE)
{
$mail_content .= "Unable to write to local file: /localdir/$fileName\n";
$download = false;
}
}
// Close our streams
fclose($localStream);
fclose($remoteStream);
// Update file lists for mail content and imports
$filelist .= $file . "\n";
array_push($downarray, './SHIPMENTS/' . $file);
}
}
}
}
// check download status
if (!$download) {
$mail_content .= "Some file download(s) failed.\n\n";
}
else
{
$mail_content .= "Successfully downloaded all of the following files from $ftp_server:\n\n";
$mail_content .= $filelist . "\n";
}
/*** End FTP ***/
/*** Begin Import ***/
// Read data from downloaded files into array
$lines = array();
foreach ($downarray as $file)
{
$linesnew = file($file);
$lines = array_merge($lines, $linesnew);
}
var_dump($lines);
// Connect to Magento Web Services API
$sess_id = $client->login($apiuser, $apikey);
$mail_content .= "Importing the following shipments:\n\n===\n\n";
$dupecount = 0;
$importcount = 0;
$result = $client->call($sess_id, 'sales_order.list');
echo ($result[1]["order_id"]);
//var_dump($result);
foreach ($lines as $line)
{
set_time_limit(60);
$fields = explode("\t", $line);
$ShippedOrderId = $fields[0];
echo $ShippedOrderId . "<br/>";
if (strlen($ShippedOrderId) == 4) { $ShippedOrderId = '10000' . $ShippedOrderId; }
if (is_numeric($ShippedOrderId))
{
// Check if customer exists
$customer_exists = null;
try
{
$customer_exists = $client->call($sess_id, 'sales_order.info', $ShippedOrderId);
}
catch (exception $e)
{
echo 'Exception: ' . $e . "<br/>";
}
if (($customer_exists != null) && ($customer_exists != ''))
{
echo 'In with ' . $ShippedOrderId . "<br/>";
$order_info = $client->call($sess_id, 'sales_order.info', $ShippedOrderId);
?><pre><?php print_r($order_info); ?></pre><?php
// Skip order if already completed or shipped
if (($order_info['status'] != 'processing') && ($order_info['status'] != 'pending'))
{
$dupecount++;
continue;
}
$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])); }
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++;
}
}
}
$mail_content .= "\n===\n\n";
$mail_content .= $dupecount . " shipments already in cart.\n\n" . $importcount . " new shipments imported on " . date('m/d/Y') . " at " . date('g:ia', strtotime('+1 hour')) . " EST.\n\n";
// Close API session
$client->endSession($sess_id);
mail($mail_to, 'Magento Shipping Import for ' . date('m/d/Y'), $mail_content);
mail($mail_to2, 'Magento Shipping Import for ' . date('m/d/Y'), $mail_content);
mail($mail_to3, 'Magento Shipping Import for ' . date('m/d/Y'), $mail_content);
mail($mail_to4, 'Magento Shipping Import for ' . date('m/d/Y'), $mail_content);
//mail($mail_to5, 'Magento Shipping Import for ' . date('m/d/Y'), $mail_content);
?>
<pre><?php echo $mail_content; ?></pre>
当我在循环中回显 $shippedOrderId 时,我得到了这个(示例):
“订单号为:字符串(9)“100015822”异常:SoapFault 异常:[100] 请求的订单不存在。在 /home/ab71714/public_html/exporter/importer-sftp.php:140 堆栈跟踪:#0 /home /ab71714/public_html/exporter/importer-sftp.php(140): SoapClient->__call('call', Array) #1 /home/ab71714/public_html/exporter/importer-sftp.php(140): SoapClient-> call('0f128ddbbbfc007...', 'sales_order.inf...', '100015822') #2 {main} 订单号为:string(9) "100015842" 异常:SoapFault 异常:[100] 未请求订单存在。在 /home/ab71714/public_html/exporter/importer-sftp.php:140 堆栈跟踪:#0 /home/ab71714/public_html/exporter/importer-sftp.php(140):SoapClient->__call('call' , 数组) #1 /home/ab71714/public_html/exporter/importer-sftp.php(140): SoapClient->call('0f128ddbbbfc007...', 'sales_order.inf...', '100015842') #2 {main} 订单号为:string(9) "100015878" "