Magento Order Search使用api查询订单
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 文件的源码
- <style type="text/css">
- .orderStatusTable {
- border:1px solid #CCCCCC;
- font-size:11px;
- }
- .track-order-table td { padding:3px;}
- .orderStatusTable td {
- padding:8px;
- }
- .currentStatus {
- font-size: 11px;
- background-color: #eee;
- padding: 10px;
- margin: 0 0 15px 0;
- line-height: 15px;
- border: 1px solid #ccc;
- color: #333;
- }
- .currentStatus span {
- font-size: 14px;
- line-height: 23px;
- color: #000;
- }
- </style>
- <div>
- <h3>Check My Order Status</h3>
- </div>
- <p>Please enter your order number and email address to see the status of your order.</p>
- <form name="" action="<?php echo $this->getUrl('track-order');?>" method="get">
- <table class="track-order-table" border="0" cellspacing="0" cellpadding="0">
- <tr style="padding:3px 0;display:block;">
- <td><strong>Order Number:</strong></td>
- <td><input type="text" name="order_id" id="order_id" value="<?php echo (isset($_GET['order_id'])) ? $_GET['order_id'] : ''; ?>" /></td>
- </tr>
- <tr style="padding:3px 0;display:block;">
- <td><strong>Email Address:</strong></td>
- <td><input name="email_address" type="text" id="email_address" value="<?php echo (isset($_GET['email_address'])) ? $_GET['email_address'] : ''; ?>" size="30" /></td>
- </tr>
- <tr style="padding:5px 0;display:block;clear:both;margin-top:10px;">
- <td> </td>
- <td><button class="button" title="Subscribe" type="submit"><span><span>Submit</span></span></button></td>
- </tr>
- </table>
- </form>
- <div></div>
- <?php
- $live = true; //determines verbosity of errors
- $error = '';
- $statusMessage = '';
- $trackingNumberMessage = '';
- $shippingMessage = '';
- $orderID = '';
- $emailAddress = '';
- if(isset($_GET['order_id'])) {
- //$orderID = trim(preg_replace('/[^0-9]*/', '', $_GET['order_id']));
- $orderID = trim(preg_replace('/[^0-9a-zA-Z]*/', '', $_GET['order_id']));
- $emailAddress = trim($_GET['email_address']);
- try {
- ini_set("soap.wsdl_cache", "0");
- ini_set("soap.wsdl_cache_enabled", "0");
- //******************************************************************/
- // change to match your domain name
- //$siteapiurl= $this->getUrl('index.php/api/soap?wsdl');
- //$proxy = new SoapClient($siteapiurl);
- $proxy = new SoapClient('http://www.magentoeasy.com/index.php/api/soap?wsdl');
- //change to your API username/password
- $sessionId = $proxy->login('orderviewer', 'orderviewer');
- //******************************************************************/
- //find all orders related to this id
- $orderById = $proxy->call($sessionId, 'sales_order.info', $orderID);
- //print_r($orderById);
- //echo "<hr>";
- $items = $orderById['items'];
- //print_r($items);
- if($orderById['customer_email'] == $emailAddress) {
- //we are setting this variable for use later
- $orderLookup = "success";
- if (strtolower($orderById['status']) == "holded") {
- $orderById['status'] = "On Hold";
- }
- $statusMessage = '<span>Your order status is: <strong>'.ucwords(str_replace('_', ' ', $orderById['status'])).'</strong></span>';
- if(ucwords(str_replace('_', ' ', $orderById['status'])) == "Processing"){
- $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.';
- }
- } else {
- $orderLookup = "failure";
- echo "We were unable to find your order information. Please verify your Order Number and Email Address are correct.";
- }
- //echo $orderById['status']."<hr>";
- //if the order status is complete we look up shipping information
- if(strtolower($orderById['status']) == "complete" && $orderLookup == "success") {
- //we look for all shipments related to this order id using internal magento order id
- $findShipments = $proxy->call($sessionId, 'sales_order_shipment.list', array(array('order_id'=>array('like'=>$orderById['order_id']))));
- //print_r($findShipments);
- if (count($findShipments) < 1) { //if $findShipments is not an array
- 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.";
- } else {
- //we pull the increment id for the shipment
- $thisShipmentID = $findShipments[0]['increment_id'];
- //now we pull all shipment info that specific shipment id
- if(!$proxy->call($sessionId, 'sales_order_shipment.info', $thisShipmentID)){
- $trackingNumberMessage = "Shipment ID: <strong>".$thisShipmentID."</strong>";
- $shippingMessage = "Your order was shipped on " . $findShipments[0]['created_at'] . ".<br/><br/>";
- }
- else {
- $getShipmentInfo = $proxy->call($sessionId, 'sales_order_shipment.info', $thisShipmentID);
- //print_r($getShipmentInfo);
- //set each variable
- $shipDate = $getShipmentInfo['created_at'];
- $defaultTimeZone = date_default_timezone_get();
- date_default_timezone_set('EST');
- //and echo the data to screen
- $shippingMessage = "Your order was shipped on " . date("l, F jS, Y \\a\\t g:i:s a T", strtotime($shipDate . ' ' . $defaultTimeZone)) .".<br/>";
- if(count($getShipmentInfo['tracks']) > 0){
- foreach($getShipmentInfo['tracks'] as $temp_track)
- { $shippingMessage .= "Shipped By : ".$temp_track['title']." ,Tracking Number :".$temp_track['number']."<br/>"; }
- $shippingMessage .= 'Check your shipment state by tracking number~.<br>By Fedex : <a target="_blank" href="http://www.fedex.com/Tracking">Fedex Express</a><br/>
- By DHL : <a target="_blank" href="http://www.dhl.com/en/express/tracking.html">DHL</a><br/>
- By UPS : <a target="_blank" href="http://www.ups.com/tracking/tracking.html">UPS</a><br/>';
- }
- $shippingMessage .= "<br/>";
- }
- } //no errors
- }
- if($orderLookup != "failure"){
- echo '<p style="padding: 10px; background:#eee; margin: 10px 0;">'.$statusMessage.'<br/>'.$trackingNumberMessage.'</p>';
- echo $shippingMessage;
- echo "<h4>Products in your order:</h4><ul>";
- foreach($items as $item){
- $temp_sku = $item['sku'];
- if(strpos($temp_sku,'-'))
- {
- $temp_sku=substr($temp_sku,0,strpos($temp_sku,'-'));
- }
- echo "<li>".number_format($item['qty_invoiced'], 0) . " x <strong>" . strtoupper($temp_sku) . "</strong> " . $item['name'] . "</li>";
- }
- echo "</ul>";
- }
- } catch (SoapFault $fault) {
- //this is a basic implementation of error checking. I am using try to stop the error from showing a nasty magento error page
- if($fault->faultcode == "100") {
- echo "That Order Number was not found in our system.";
- } elseif ($fault->faultcode == "http") {
- echo "Request timed out. Please try again later.";
- } else {
- //leave this on for testing so we can see SOAP status codes; turn off for live
- if ($live == false) {
- echo "Error $fault->faultcode: $fault->faultstring";
- } else {
- echo "Error $fault->faultcode: $fault->faultstring"."<hr>";
- //echo "There was an unknown error. Please try again later, or contact us.";
- }
- }
- }
- } // end if
- ?>
- <p><br /><br /><em>For detailed information regarding the status of your order, please contact our helpful Customer Service Experts.</em></p>
代码比较杂乱,没用的注释也没删,大家凑合着看吧,希望能派上用场 :-)
转载于:https://blog.51cto.com/vsfor/774082
Magento Order Search使用api查询订单相关推荐
- java微信支付v3系列——6.微信支付查询订单API
目录 java微信支付v3系列--1.微信支付准备工作 java微信支付v3系列--2.微信支付基本配置 java微信支付v3系列--3.订单创建准备操作 java微信支付v3系列--4.创建订单的封 ...
- 微信查询订单API与商派ecstore订单状态对接
2019独角兽企业重金招聘Python工程师标准>>> 今天一个项目用微信扫码支付,客户扫码后卡死在前台.但是金额已经支付成功了.通过百度发现https://pay.weixin.q ...
- 在线支付系列【15】微信支付实战篇之集成查询订单、支付通知API
有道无术,术尚可求,有术无道,止于术. 文章目录 前言 主动调用 商户订单号查询 回调通知 1. 添加通知回调地址 2. 通知处理 3. 通知接口 4. 测试 前言 在上篇文档中,我们简单实现了Nat ...
- ElasticSearch: Search API 查询用法详解
Search API ElasticSearch 为了搜索提供了一些原始的 API,主要是有两大类 URL Search URL Search 类似 http 的get请求,是将请求参数放到 URL ...
- PHP App Store Server API 苹果API退款 查询订单 历史订单 PHP校验签名解码
本文使用是基于thinkPHP 实现相关的功能,Python.java等实现的网上都有相关的实现连接.不说废话,直接开始. 一.安装jwt. 1.composer 安装[强烈推荐]本文用这种方式: c ...
- Magento教程 22:如何确认订单报表?
欢迎使用Magento购物车系统 ,上次介绍过如何审核.发布客户评论 ,这次要教的是查询订单报表,借此获取详细的订单数据. Magento内建报表功能,在订单报表中,商家可清楚得知商品项目.销售数量. ...
- java编程根据订单编号查询订单状态_Java微信订单查询
Java 通过统一下单 API 进行订单支付后,除等待微信通过 notify_url 进行回调通知外,还可以主动查询订单状态 更多精彩 前置条件 可参考 Java 微信扫码支付 如果实现微信支付 官网 ...
- 淘宝客订单API获取订单代码
Trade 数据结构 名称 类型 是否隐私 描述 seller_nick String Y 卖家昵称 buyer_nick String Y 买家昵称 title String Y 商品标题 type ...
- 托众导购网 淘宝客订单API获取订单代码
本文介绍如何使用淘宝客API获取淘宝客订单 ,获取到订单后 ,将订单记录插入到 OenJWeb的淘宝客订单表 ,下面 是代码 : package org.openjweb.core.taobao.se ...
最新文章
- HTML中Css详细介绍
- 面试题 08.03. Magic Index LCCI 魔术索引
- linux下source命令使用详解
- 博客真的停止维护了,找我请@我。
- sql大小写 效率_【SQL】单行函数
- 查看java运行时参数_查看JVM运行时参数
- 向下滑动动画android_Android SwipeRefreshLayout – Android向下拉动/向下滑动即可刷新
- Menu控件在IE8中子菜单不能正常显示的解决方案(转)
- Cockroachdb 三、副本设置
- web前端进阶<7>:3d图像翻转效果
- ADGUARD——去除广告利器
- NLP Prompting for Text Classification(1)
- 开源软件总体拥有成本指南
- NIST:生成安全密码密钥
- 右侧追击(一)——东方财富
- mysql不能持久存储数据的是_数据持久化存储
- 《 中国高校鄙视链大全 》
- C#项目实战——YModem协议文件传输【实例】
- 好用的日历插件(三款常用的日历插件)
- 数字与罗马数字之间转换
热门文章
- Android Service--通信方式(IBinder回调、Messenger)
- 购买什么样的天猫转让网店才有优势
- 求求各位帮忙找个人,这个盾叔到底是谁?
- 基于SSH的宾馆管理系统系统结构图_ER图_数据字典
- 【java】java获取ip地址(读取QQWry.dat文件形式)
- Android 代码混淆之-群魔乱舞的字符串
- 全面解析Android性能优化,含腾讯、阿里、百度、京东、美团、爱奇艺等大厂实战解析
- python控制系统进程_python 监控windows进程
- 楼中楼应该怎么写 php,什么是楼中楼?楼中楼怎么样?
- 【Android】Android应用开发模板