首先假设你的目录结构:
配置文件放在etc目录,所以 我下面讲到的配置文件都是在etc目录下。
假设我们要重写product api(注:如果不是重写magento core api请自行去掉注释下面的表签:紫色背景部分)
注意首字母大小写!
1,config.xml
2,api.xml
3,wsdl.xml
Ok,that's all,thank you!
希望能给你一点帮助!
-- PackageName
-- ModuleName
-- etc
-- Model
-- Scope
-- Api.php
-- Api
-- v2.php
-- controllers
-- Block
配置文件放在etc目录,所以 我下面讲到的配置文件都是在etc目录下。
假设我们要重写product api(注:如果不是重写magento core api请自行去掉注释下面的表签:紫色背景部分)
注意首字母大小写!
1,config.xml
<?xml version="1.0"?>
<config>
<modules>
<PackageName_ModuleName>
<version>0.1.0</version>
<!-- if you rewrite magento core module,add depends tag -->
<depends>
<Mage_ModuleName />
</depends>
</PackageName_ModuleName>
</modules>
<!-- ... -->
<global>
<models>
<moduleName>
<!-- if you rewrite magento core module ,add rewrite tag-->
<rewrite>
<product_api>PackageName_ModuleName_Model_Product_Api</product_api>
<product_api_v2>PackageName_ModuleName_Model_Product_Api_v2</product_api_v2>
</rewrite>
</moduleName>
</models>
<!-- ... -->
</global>
<!-- ... -->
</config>
2,api.xml
<?xml version="1.0"?>
<config>
<api>
<resources>
<moduleName_product translate="title" module="moduleName">
<title>Product API</title>
<model>moduleName/product_api</model>
<acl>moduleName/product</acl>
<methods>
<apiMethod translate="title" module="catalog">
<title>Api Title</title>
<acl>moduleName/product/apiMethod</acl>
</apiMethod>
<!-- other api methodes ... -->
</methods>
<faults module="moduleName">
<store_not_exists>
<code>100</code>
<message>Requested store view not found.</message>
</store_not_exists>
<product_not_exists>
<code>101</code>
<message>Product not exists.</message>
</product_not_exists>
<data_invalid>
<code>102</code>
<message>Invalid data given. Details in error message.</message>
</data_invalid>
<not_deleted>
<code>103</code>
<message>Product not deleted. Details in error message.</message>
</not_deleted>
<product_type_not_exists>
<code>104</code>
<message>Product type is not in allowed types.</message>
</product_type_not_exists>
<product_attribute_set_not_exists>
<code>105</code>
<message>Product attribute set is not existed</message>
</product_attribute_set_not_exists>
<product_attribute_set_not_valid>
<code>106</code>
<message>Product attribute set is not belong catalog product entity type</message>
</product_attribute_set_not_valid>
</faults>
</moduleName_product>
</resources>
<resources_alias>
<product>moduleName_product</product>
</resources_alias>
<v2>
<resources_function_prefix>
<product>catalogProduct</product>
</resources_function_prefix>
</v2>
<acl>
<resources>
<moduleName translate="title" module="moduleName">
<title>ModuleName</title>
<product translate="title" module="moduleName">
<title>Product</title>
<apiMethod translate="title" module="moduleName">
<title>Api Title</title>
</apiMethod>
<!-- other api methodes ... -->
</product>
</moduleName >
</resources>
</acl>
</api>
</config>
3,wsdl.xml
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:typens="urn:{{var wsdl.name}}" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"
name="{{var wsdl.name}}" targetNamespace="urn:{{var wsdl.name}}">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" />
<complexType name="moduleNameProductApiMethod">
<all>
<!-- your custom return params,please modification it according to demand -->
<element name="image_resize640" type="xsd:string"/>
<element name="parent_id" type="xsd:int"/>
<element name="price" type="xsd:int"/>
<element name="special_price" type="xsd:int"/>
<element name="minimal_price" type="xsd:int"/>
<element name="tier_price" type="xsd:int"/>
<element name="other_design" type="xsd:array"/>
<element name="guess_you_like" type="xsd:array"/>
</all>
</complexType>
</schema>
</types>
<message name="moduleNameProductApiMethodRequest">
<!-- your custom request params,please modification it according to demand -->
<part name="productSku" type="xsd:string"/>
<part name="storeView" type="xsd:int"/>
<part name="attribute" type="xsd:array"/>
<part name="identifierType" type="xsd:string"/>
</message>
<message name="moduleNameProductApiMethodResponse">
<part name="apiMethod" type="typens:moduleNameProductApiMethod"/>
</message>
<portType name="{{var wsdl.handler}}PortType">
<operation name="moduleNameProductApiMethod">
<documentation>Api function description</documentation>
<input message="typens:moduleNameProductApiMethodRequest"/>
<output message="typens:moduleNameProductApiMethodResponse"/>
</operation>
</portType>
<binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="moduleNameProductApiMethod">
<soap:operation soapAction="urn:{{var wsdl.handler}}Action"/>
<input>
<soap:body namespace="urn:{{var wsdl.name}}" use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body namespace="urn:{{var wsdl.name}}" use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="{{var wsdl.name}}Service">
<port name="{{var wsdl.handler}}Port" binding="typens:{{var wsdl.handler}}Binding">
<soap:address location="{{var wsdl.url}}" />
</port>
</service>
</definitions>
Ok,that's all,thank you!
希望能给你一点帮助!