Magento向3PL发出出口订单

mwkjh3gx  于 2022-11-12  发布在  其他
关注(0)|答案(1)|浏览(114)

我在升级后为一个客户端重新实现了这个脚本,但我被卡住了(可能是脑子烧坏了)。大部分都不关你的事。我有问题的部分在这里:

try

         {

            $customer_exists = $client->call($sess_id, 'sales_order.info', $ShippedOrderId);
         }

         catch (exception $e)

         {

            echo 'Exception: ' . $e . "<br/>";

         }

它抛出以下异常:
“异常:SoapFault异常:[100]请求的订单不存在。在/home/ab 71714/public_html/exporter/importer-sftp.php中:140堆栈跟踪:(140)请输入您要的网址:(140)请输入您的密码:”“”“”“”“”“”“”“”“
整个事情就在下面。任何帮助都将不胜感激!

<?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/ab 71714/public_html/exporter/importer-sftp.php中:140堆栈跟踪:(140)请输入您要的网址:(140)请输入您的密码:SoapClient-〉call('0 f128 ddbbbfc 007...','sales_order. inf...','100015822')#2 {main}订单编号为:字符串(9)“100015842”异常:SoapFault异常错误:[100]请求的订单不存在。在/home/ab 71714/public_html/exporter/importer-sftp.php中:140堆栈跟踪:(140)请输入您要的网址:(140)请输入您的密码:SoapClient-〉call('0 f128 ddbbbfc 007...','sales_order. inf...','100015842')#2 {main}订单编号为:字符串(9)“100015878”“

mxg2im7a

mxg2im7a1#

这就是你的使命(/app/code/core/Mage/Sales/Model/Order/Api.php):

public function info($orderIncrementId)

请确保在设置$shippedOrderId时使用增量ID:

$ShippedOrderId = $order->getIncrementId();

看起来你连接成功了,但是API出错,订单不存在。不确定是什么原因导致了这个问题。如果不起作用,试着调试session_id和client参数。

相关问题