[英]Magento Custom Api Code can't pass in parameters (Undefined variable error)
您好Magento黑客,
我正在嘗試創建一個自定義API處理程序,雖然我可以運行該函數,但由於某種原因傳入變量不起作用,我得到一個名為in的空參數.System.log返回錯誤:DEBUG(7):Undefined變量:inputvar。 請幫忙!
首先,我在app / code / local的目錄結構如下:
Company
-Customapi
-etc
-api.xml
-config.xml
-wsdl.xml
-Model
-Order
-Api.php
-Api
-V2.php
現在為代碼。
Api.php
class Company_Customapi_Model_Order_Api extends Mage_Api_Model_Resource_Abstract
{
public function test($inputvar){
echo $inputvar;
$result = $inputvar;
return $result;
}
}
V2.php
class Company_Customapi_Model_Order_Api_V2 extends Company_Customapi_Model_Order_Api {}
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/"/>
</schema>
</types>
<message name="getTestRequest">
<part name="inputvar" type="xsd:string"/>
</message>
<message name="getTestResponse">
<part name="result" type="xsd:string"/>
</message>
<portType name="{{var wsdl.handler}}PortType">
<operation name="customapiOrderTest">
<documentation>Test the API.</documentation>
<input message="typens:getTestRequest"/>
<output message="typens:getTestResponse"/>
</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="customapiOrderTest">
<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>
api.xml:
<?xml version="1.0"?>
<config>
<api>
<resources>
<customapi_order translate="title" module="company_customapi">
<model>company_customapi_model_order_api</model>
<title>company Order API</title>
<acl>order</acl>
<methods>
<test translate="title" module="company_customapi">
<title>A test function.</title>
<acl>test</acl>
</test>
</methods>
</customapi_order>
</resources>
<v2>
<resources_function_prefix>
<customapi_order>customapiOrder</customapi_order>
<!-- prefix+functionname = customapiOrderTest -->
</resources_function_prefix>
</v2>
</api>
</config>
config.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Company_Customapi>
<version>0.1.0</version>
</Company_Customapi>
</modules>
<global>
<models>
<Company_Customapi>
<class>Company_Customapi_Model</class>
</Company_Customapi>
</models>
</global>
</config>
test.php的:
$session = $client->login(SOAP_USER, SOAP_PASS);
$result = $client->customapiOrderTest($session, "inputvaluehere");
var_dump ( $result);
找到了答案。 在Wsdl.xml中,您必須將會話參數指定為您的輸入之一(您在服務器上的功能無法看到它,但您確實從客戶端傳入了它)
<message name="getTestRequest">
<part name="sessionId" type="xsd:string"/>
<part name="inputvar" type="xsd:string"/>
</message>
我花了2天才找到答案。 難道你不喜歡Magento!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.