sales/etc/api.xml
- <?xml version="1.0"?>
- <config>
- <api>
- <resources>
- <sales_order translate="title" module="sales">
- <model>sales/order_api</model>
- <title>Order API</title>
- <acl>sales/order</acl>
- <methods>
- <list translate="title" module="sales">
- <title>Retrieve list of orders by filters</title>
- <method>items</method>
- <acl>sales/order/info</acl>
- </list>
- <info translate="title" module="sales">
- <title>Retrieve order information</title>
- <acl>sales/order/info</acl>
- </info>
- </methods>
- <faults module="sales">
- <not_exists>
- <code>100</code>
- <message>Requested order not exists.</message>
- </not_exists>
- <filters_invalid>
- <code>101</code>
- <message>Invalid filters given. Details in error message.</message>
- </filters_invalid>
- <data_invalid>
- <code>102</code>
- <message>Invalid data given. Details in error message.</message>
- </data_invalid>
- <status_not_changed>
- <code>103</code>
- <message>Order status not changed. Details in error message.</message>
- </status_not_changed>
- </faults>
- </sales_order>
- </resources>
- <acl> <!-- 后台管理中显示权限 -->
- <resources>
- <sales translate="title" module="sales">
- <title>Sales</title>
- <sort_order>2</sort_order>
- <order translate="title" module="sales">
- <title>Order</title>
- <change translate="title" module="sales">
- <title>改变状态,添加备注</title>
- </change>
- <info translate="title" module="sales">
- <title>获取订单信息</title>
- </info>
- </order>
- </sales>
- </resources>
- </acl>
- </api>
- </config>
sales/model/order/api.php服务端代码 有<method>items</method>
- public function items($filters = null){
- ..................
- return $result;
- }
- public function info($orderIncrementId){
- ..................
- return $result;
- }
后台配置client的访问用户和权限,直接用api的方法
- Mage::getModel('sales/order_api')->items();
系统->网络服务->用户
系统->网络服务->角色 角色资源
client端代码
- public function actionView()
- {
- define("TEST_API_URL", "http://www.test.com/api/?wsdl");
- $client = new SoapClient(TEST_API_URL, array("trace" => 0, "exceptions" => 0));
- $client->soap_defencoding = 'utf-8';
- $client->decode_utf8 = false;
- $session = $client->login(API_USER,API_KEY); //需后台配置
- $order_id = Yii::app()->request->getParam('id');
- $result = $client->call($session, 'sales_order.list', array($order_id));
- //print_r($result);
- $client->endSession($session);
- }