Magento API v2 之webservice

http://yourserver.com/api/v2_soap /?wsdl v2是java,.net等语言可调用,可模仿Customer

 

Basic steps:

1. Create Magento Extension (we are not going explain here how to do it)
2. Create Model for API method
3. Create and configure api.xml file
4. Create wsdl.xml file (with proper definitions)
5. Create wsi.xml file (with proper definitions) (OPTIONAL)

Creating Model for API v2

After properly configuring our config.xml it looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?xml version= "1.0" ?>
 
<config>
    <modules>
       <Inchoo_Mapy>
          <version>1.0.1</version>
       </Inchoo_Mapy>
    </modules>
    < global >
       <models>
          <inchoo_mapy>
              < class >Inchoo_Mapy_Model</ class >
          </inchoo_mapy>
       </models>
    </ global >
</config>

Let’s navigate through Magento core files to see where Magento API models are in file-system:

Since we are going to use API v2 only, We will create our model like this:



Creating and configuring api.xml

The easiest way is to copy/paste one of Magento’s api.xml files in our etc folder and make changes there to suit our needs. Our final api.xml should look like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?xml version= "1.0" ?>
<config>
    <api>
      <resources>
      <!-- START GUSTOMER GROUP RESOURCES -->
        <mapy_customer_group>
             <model>inchoo_mapy/customer_group_api</model>
             <title>Inchoo Customer's Groups API</title>
             <acl>mapy_data</acl>
             <methods>
               <list translate= "title" module= "inchoo_mapy" >
                   <title>Retrieve customer groups</title>
                   <method>mapyItems</method>
               </list>
             </methods>
        </mapy_customer_group>
      <!-- END CUSTOMER GROUP RESOURCES -->
     </resources>
     <v2>
       <resources_function_prefix>
            <mapy_customer_group>mapy_customerGroup</mapy_customer_group>
            </resources_function_prefix>
     </v2>
     <acl>
        <resources>
            <mapy_data translate= "title" module= "inchoo_mapy" >
               <title>Mapy data</title>
               <sort_order>3</sort_order>
            </mapy_data>
        </resources>
     </acl>
   </api>
</config>

Here is logic that has to be implemented in api.xml file. Api.xml file basically connects API calls with php methods inside specific models. Also, the ACL resources are defined here for specific api call.

Creating wsdl.xml file

When working with wsdl.xml and wsi.xml later, if you are happy NetBeans user, I strongly suggest you to search on Google and download the XML Tools plug-in that can make life much easier …

There are few things that we have to fill-in when creating wsdl.xml.

  • Bindings
  • Port types
  • Messages
  • Types / Complex types

Also, it’s easier to copy one of Magento’s wsdl files, paste it in our etc folder and remove unnecessary things and add our own inside.

Here is NetBeans – XML Tools screen-shot how this look like:

This  image is showing logic and direction how should we fill-in wsdl.xml:

Let’s now look at real xml source:

After we finished with wsdl, let’s go to http://ourmagento/api/v2_soap/?wsdl=1 to see changes in global wsdl we made. (Don’t forget to clear cache first! ).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值