Magento自定义API代码无法传入参数(未定义变量错误)

qlckcl4x  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(143)

我试图创建一个自定义的API处理程序,虽然我可以让函数运行,但由于某种原因,传入变量不起作用,我得到一个空参数。System.log返回错误:
DEBUG(7):Undefined variable: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);

bvjveswy

bvjveswy1#

找到答案了。在Wsdl.xml中,您必须指定会话参数作为输入之一(服务器上的函数看不到它,但您可以从客户端传入它)

<message name="getTestRequest">
   <part name="sessionId" type="xsd:string"/>
   <part name="inputvar" type="xsd:string"/>
</message>

字符串
我只花了2天就找到了答案。你不只是爱Magento!

相关问题