Magento API v2 之webservice

  1. 云栖社区>
  2. 博客>
  3. 正文

Magento API v2 之webservice

航空母舰 2016-05-12 17:08:38 浏览1062
展开阅读全文

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/500
评论
航空母舰
+ 关注