Magento1.6版本中已经集成了订单的查询功能,不过早期的版本要实现订单查询还得花点心思。网上也有对应的插件就是了,hellokeykey的 订单查询插件,不过要 50刀,感觉贵了点,不过一分钱一分货  这边还是得对那些开发者表示支持的。

这边分享一个订单查询的api方法,详细的测试没做,不过1.5下是确定可用的。

废话不多说,先介绍下使用说明吧(涉及一个代码文件,稍后贴出来)

进入后台,
System——>Web Service
新建一个api用户 (记住用户名密码)
(用户角色赋予 Order相关的权限)

新建一个cms页面用于Order查询
调用代码
{{block type="core/template" template="cms/order-status-api.phtml"}}


修改order-status-api.phtml 文件中的
$proxy = new SoapClient('http://www.magentoeasy.com/index.php/api/soap?wsdl');
域名为目标网站域名

修改如下代码中的用户名密码为新建的api 用户名密码
//change to your API username/password
$sessionId = $proxy->login('orderviewer', 'orderviewer');
 

OK至于cms页面的链接要怎么放,样式修改,以及新建api用户新建页面清理缓存之类的这边就略过了

下面是 order-status-api.phtml 文件的源码

 

 
  
  1. <style type="text/css"> 
  2. .orderStatusTable { 
  3.     border:1px solid #CCCCCC; 
  4.     font-size:11px; 
  5. .track-order-table td { padding:3px;} 
  6. .orderStatusTable td { 
  7. padding:8px; 
  8. .currentStatus { 
  9.     font-size: 11px; 
  10.     background-color: #eee; 
  11.     padding: 10px; 
  12.     margin: 0 0 15px 0; 
  13.     line-height: 15px; 
  14.     border: 1px solid #ccc; 
  15.     color: #333; 
  16. .currentStatus span { 
  17.     font-size: 14px; 
  18.     line-height: 23px; 
  19.     color: #000; 
  20. </style> 
  21. <div> 
  22.     <h3>Check My Order Status</h3> 
  23. </div> 
  24.  
  25. <p>Please enter your order number and email address to see the status of your order.</p> 
  26.  
  27. <form name="" action="<?php echo $this->getUrl('track-order');?>" method="get"> 
  28. <table class="track-order-table" border="0" cellspacing="0" cellpadding="0"> 
  29.     <tr style="padding:3px 0;display:block;"> 
  30.         <td><strong>Order Number:</strong></td> 
  31.         <td><input type="text" name="order_id" id="order_id" value="<?php echo (isset($_GET['order_id'])) ? $_GET['order_id'] : ''; ?>" /></td> 
  32.     </tr> 
  33.     <tr style="padding:3px 0;display:block;"> 
  34.         <td><strong>Email Address:</strong></td> 
  35.         <td><input name="email_address" type="text" id="email_address" value="<?php echo (isset($_GET['email_address'])) ? $_GET['email_address'] : ''; ?>" size="30" /></td> 
  36.     </tr> 
  37.     <tr style="padding:5px 0;display:block;clear:both;margin-top:10px;"> 
  38.         <td>&nbsp;</td> 
  39.         <td><button class="button" title="Subscribe" type="submit"><span><span>Submit</span></span></button></td> 
  40.     </tr> 
  41. </table> 
  42.  
  43. </form> 
  44.  
  45. <div></div> 
  46.  
  47. <?php 
  48.  
  49.     $live = true; //determines verbosity of errors 
  50.  
  51.     $error = ''
  52.     $statusMessage = ''
  53.     $trackingNumberMessage = ''
  54.     $shippingMessage = ''
  55.  
  56.     $orderID = ''
  57.     $emailAddress = ''
  58.  
  59.     if(isset($_GET['order_id'])) { 
  60.  
  61.         //$orderID = trim(preg_replace('/[^0-9]*/', '', $_GET['order_id'])); 
  62.         $orderID = trim(preg_replace('/[^0-9a-zA-Z]*/', '', $_GET['order_id']));  
  63.         $emailAddress = trim($_GET['email_address']);  
  64.         try { 
  65.  
  66.             ini_set("soap.wsdl_cache", "0"); 
  67.             ini_set("soap.wsdl_cache_enabled", "0"); 
  68.  
  69.             //******************************************************************/ 
  70.  
  71.             // change to match your domain name 
  72.             //$siteapiurl= $this->getUrl('index.php/api/soap?wsdl'); 
  73.             //$proxy = new SoapClient($siteapiurl); 
  74.             $proxy = new SoapClient('http://www.magentoeasy.com/index.php/api/soap?wsdl'); 
  75.             //change to your API username/password 
  76.             $sessionId = $proxy->login('orderviewer', 'orderviewer'); 
  77.  
  78.             //******************************************************************/ 
  79.  
  80.             //find all orders related to this id 
  81.             $orderById = $proxy->call($sessionId, 'sales_order.info', $orderID); 
  82.             //print_r($orderById); 
  83.             //echo "<hr>"; 
  84.             $items = $orderById['items']; 
  85.             //print_r($items); 
  86.             if($orderById['customer_email'] == $emailAddress) { 
  87.                 //we are setting this variable for use later 
  88.                 $orderLookup = "success"
  89.                 if (strtolower($orderById['status']) == "holded") { 
  90.                     $orderById['status'] = "On Hold"; 
  91.                 } 
  92.                 $statusMessage = '<span>Your order status is: <strong>'.ucwords(str_replace('_', ' ', $orderById['status'])).'</strong></span>'; 
  93.  
  94.                 if(ucwords(str_replace('_', ' ', $orderById['status'])) == "Processing"){ 
  95.                     $statusMessage .'<br/><br/><strong>What does this mean?</strong><br/>Processing Time is the time it takes from when you submit your order to when the product leaves the Distribution Center.'
  96.                 } 
  97.  
  98.             } else { 
  99.                 $orderLookup = "failure"
  100.                 echo "We were unable to find your order information. Please verify your Order Number and Email Address are correct."; 
  101.             } 
  102.             //echo $orderById['status']."<hr>"; 
  103.             //if the order status is complete we look up shipping information 
  104.             if(strtolower($orderById['status']) == "complete" && $orderLookup == "success") {  
  105.                 //we look for all shipments related to this order id using internal magento order id 
  106.                 $findShipments = $proxy->call($sessionId, 'sales_order_shipment.list', array(array('order_id'=>array('like'=>$orderById['order_id'])))); 
  107.                 //print_r($findShipments); 
  108.                 if (count($findShipments) < 1) { //if $findShipments is not an array 
  109.  
  110.                     echo "There was an unknown error and your shipment information could not be found. Please contact Customer Service to get the current status of your order."; 
  111.  
  112.                 } else { 
  113.  
  114.                     //we pull the increment id for the shipment 
  115.                     $thisShipmentID = $findShipments[0]['increment_id']; 
  116.                     
  117.                     //now we pull all shipment info that specific shipment id 
  118.                     if(!$proxy->call($sessionId, 'sales_order_shipment.info', $thisShipmentID)){ 
  119.                         $trackingNumberMessage = "Shipment ID: <strong>".$thisShipmentID."</strong>"; 
  120.                         $shippingMessage = "Your order was shipped on " . $findShipments[0]['created_at'] . ".<br/><br/>"; 
  121.                     }  
  122.                     else { 
  123.                         $getShipmentInfo = $proxy->call($sessionId, 'sales_order_shipment.info', $thisShipmentID);  
  124.                         //print_r($getShipmentInfo);  
  125.                             //set each variable 
  126.                         $shipDate = $getShipmentInfo['created_at'];  
  127.                         $defaultTimeZone = date_default_timezone_get();  
  128.                         date_default_timezone_set('EST');   
  129.                         //and echo the data to screen 
  130.                         $shippingMessage = "Your order was shipped on " . date("l, F jS, Y \\a\\t g:i:s a T", strtotime($shipDate . ' ' . $defaultTimeZone)) .".<br/>"; 
  131.                         if(count($getShipmentInfo['tracks']) > 0){ 
  132.                             foreach($getShipmentInfo['tracks'] as $temp_track) 
  133.                             {  $shippingMessage ."Shipped By : ".$temp_track['title']."  ,Tracking Number :".$temp_track['number']."<br/>"; }  
  134.                             $shippingMessage .= 'Check your shipment state by tracking number~.<br>By Fedex : <a target="_blank" href="http://www.fedex.com/Tracking">Fedex Express</a><br/> 
  135. By DHL : <a target="_blank" href="http://www.dhl.com/en/express/tracking.html">DHL</a><br/> 
  136. By UPS : <a target="_blank" href="http://www.ups.com/tracking/tracking.html">UPS</a><br/>'; 
  137.                         }  
  138.                         $shippingMessage ."<br/>"
  139.                     } 
  140.  
  141.                 } //no errors 
  142.  
  143.             } 
  144.   
  145.             if($orderLookup != "failure"){ 
  146.  
  147.                 echo '<p style="padding: 10px; background:#eee; margin: 10px 0;">'.$statusMessage.'<br/>'.$trackingNumberMessage.'</p>'; 
  148.  
  149.                 echo $shippingMessage; 
  150.  
  151.                 echo "<h4>Products in your order:</h4><ul>"; 
  152.                         foreach($items as $item){ 
  153.                             $temp_sku = $item['sku']; 
  154.                             if(strpos($temp_sku,'-')) 
  155.                             { 
  156.                                 $temp_sku=substr($temp_sku,0,strpos($temp_sku,'-')); 
  157.                             } 
  158.                             echo "<li>".number_format($item['qty_invoiced'], 0) . " x <strong>" . strtoupper($temp_sku) . "</strong> " . $item['name'] . "</li>"; 
  159.                         } 
  160.                 echo "</ul>"; 
  161.             } 
  162.  
  163.         } catch (SoapFault $fault) { 
  164.             //this is a basic implementation of error checking. I am using try to stop the error from showing a nasty magento error page 
  165.             if($fault->faultcode == "100") { 
  166.                 echo "That Order Number was not found in our system."; 
  167.             } elseif ($fault->faultcode == "http") { 
  168.                 echo "Request timed out. Please try again later."; 
  169.             } else { 
  170.                 //leave this on for testing so we can see SOAP status codes; turn off for live 
  171.                 if ($live == false) { 
  172.                     echo "Error $fault->faultcode: $fault->faultstring"; 
  173.                 } else { 
  174.                     echo "Error $fault->faultcode: $fault->faultstring"."<hr>"; 
  175.                     //echo "There was an unknown error. Please try again later, or contact us."; 
  176.                 } 
  177.             } 
  178.         } 
  179.  
  180.     } // end if 
  181.  
  182. ?> 
  183. <p><br /><br /><em>For detailed information regarding the status of your order, please contact our helpful Customer Service Experts.</em></p> 

代码比较杂乱,没用的注释也没删,大家凑合着看吧,希望能派上用场 :-)