2013-02-13 74 views
1

我想創建一個擴展magento V2 soap調用的自定義模塊。我的大部分來源從這個帖子擴展Magento的API Soap V2(不是這種服務的有效方法)

How to setup custom api for Magento with SOAP V2?

來到這就是我對我所做的努力得到它的工作至今的步驟。

/app/etc/modules/Namespace_ImportExport.xml
<?xml version="1.0"?> 
<config> 
    <modules> 
     <Namespace_ImportExport> 
      <active>true</active> 
      <codePool>local</codePool> 
      <depends> 
       <Mage_Core /> 
      </depends> 
     </Namespace_ImportExport> 
    </modules> 
</config> 

/app/code/local/Namespace/ImportExport/etc/api.xml
<?xml version="1.0"?> 
<config> 
    <api> 
    <resources> 
     <importexport> 
      <model>namespace_importexport/api</model> 
      <title>api test</title> 
      <methods> 
       <foo translate="title" module="importexport"> 
        <title>Foo Test</title> 
        <method>foo</method> 
       </foo> 
      </methods> 
     </importexport> 
    </resources> 
    <v2> 
     <resources_function_prefix> 
      <importexport>importexport</importexport> 
     </resources_function_prefix> 
    </v2> 
    </api> 
</config> 

/應用程序/代碼/本地/Namespace/ImportExport/etc/config.xml

<config> 
    <modules> 
     <Namespace_ImportExport> 
      <version>0.0.1</version> 
     </Namespace_ImportExport> 
    </modules> 
    <global> 
     <models> 
      <importexport><class>Namespace_ImportExport_Model</class></importexport> 
     </models> 
     <models> 
      <catalog> 
       <rewrite> 
        <product_api_v2>Namespace_ImportExport_Model_Product_Api_V2</product_api_v2> 
       </rewrite> 
      </catalog> 
     </models> 
    </global> 
</config> 

/app/code/local/Namespace/ImportExport/etc/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="catalogProductCreateEntity"> 
       <all> 
        <element name="categories" type="typens:ArrayOfString" minOccurs="0" /> 
        <element name="websites" type="typens:ArrayOfString" minOccurs="0" /> 
        <element name="associated" type="typens:ArrayOfString" minOccurs="0" /> 
        <element name="name" type="xsd:string" minOccurs="0" /> 
        <element name="description" type="xsd:string" minOccurs="0" /> 
        <element name="short_description" type="xsd:string" minOccurs="0" /> 
        <element name="weight" type="xsd:string" minOccurs="0" /> 
        <element name="status" type="xsd:string" minOccurs="0" /> 
        <element name="url_key" type="xsd:string" minOccurs="0" /> 
        <element name="url_path" type="xsd:string" minOccurs="0" /> 
        <element name="visibility" type="xsd:string" minOccurs="0" /> 
        <element name="category_ids" type="typens:ArrayOfString" minOccurs="0" /> 
        <element name="website_ids" type="typens:ArrayOfString" minOccurs="0" /> 
        <element name="has_options" type="xsd:string" minOccurs="0" /> 
        <element name="gift_message_available" type="xsd:string" minOccurs="0" /> 
        <element name="price" type="xsd:string" minOccurs="0" /> 
        <element name="special_price" type="xsd:string" minOccurs="0" /> 
        <element name="special_from_date" type="xsd:string" minOccurs="0" /> 
        <element name="special_to_date" type="xsd:string" minOccurs="0" /> 
        <element name="tax_class_id" type="xsd:string" minOccurs="0" /> 
        <element name="tier_price" type="typens:ArrayOfString" minOccurs="0" /> 
        <element name="meta_title" type="xsd:string" minOccurs="0" /> 
        <element name="meta_keyword" type="xsd:string" minOccurs="0" /> 
        <element name="meta_description" type="xsd:string" minOccurs="0" /> 
        <element name="custom_design" type="xsd:string" minOccurs="0" /> 
        <element name="custom_layout_update" type="xsd:string" minOccurs="0" /> 
        <element name="options_container" type="xsd:string" minOccurs="0" /> 
        <element name="additional_attributes" type="typens:associativeArray" minOccurs="0" /> 
       </all> 
      </complexType> 
      <complexType name="catalogProductReturnEntity"> 
       <all> 
        <element name="product_id" type="xsd:string" minOccurs="0" /> 
        <element name="sku" type="xsd:string" minOccurs="0" /> 
        <element name="set" type="xsd:string" minOccurs="0" /> 
        <element name="type" type="xsd:string" minOccurs="0" /> 
        <element name="categories" type="typens:ArrayOfString" minOccurs="0" /> 
        <element name="websites" type="typens:ArrayOfString" minOccurs="0" /> 
        <element name="associated" type="typens:ArrayOfString" minOccurs="0" /> 
        <element name="created_at" type="xsd:string" minOccurs="0" /> 
        <element name="updated_at" type="xsd:string" minOccurs="0" /> 
        <element name="type_id" type="xsd:string" minOccurs="0" /> 
        <element name="name" type="xsd:string" minOccurs="0" /> 
        <element name="description" type="xsd:string" minOccurs="0" /> 
        <element name="short_description" type="xsd:string" minOccurs="0" /> 
        <element name="weight" type="xsd:string" minOccurs="0" /> 
        <element name="status" type="xsd:string" minOccurs="0" /> 
        <element name="url_key" type="xsd:string" minOccurs="0" /> 
        <element name="url_path" type="xsd:string" minOccurs="0" /> 
        <element name="visibility" type="xsd:string" minOccurs="0" /> 
        <element name="category_ids" type="typens:ArrayOfString" minOccurs="0" /> 
        <element name="website_ids" type="typens:ArrayOfString" minOccurs="0" /> 
        <element name="has_options" type="xsd:string" minOccurs="0" /> 
        <element name="gift_message_available" type="xsd:string" minOccurs="0" /> 
        <element name="price" type="xsd:string" minOccurs="0" /> 
        <element name="special_price" type="xsd:string" minOccurs="0" /> 
        <element name="special_from_date" type="xsd:string" minOccurs="0" /> 
        <element name="special_to_date" type="xsd:string" minOccurs="0" /> 
        <element name="tax_class_id" type="xsd:string" minOccurs="0" /> 
        <element name="tier_price" type="typens:ArrayOfString" minOccurs="0" /> 
        <element name="meta_title" type="xsd:string" minOccurs="0" /> 
        <element name="meta_keyword" type="xsd:string" minOccurs="0" /> 
        <element name="meta_description" type="xsd:string" minOccurs="0" /> 
        <element name="custom_design" type="xsd:string" minOccurs="0" /> 
        <element name="custom_layout_update" type="xsd:string" minOccurs="0" /> 
        <element name="options_container" type="xsd:string" minOccurs="0" /> 
        <element name="additional_attributes" type="typens:associativeArray" minOccurs="0" /> 
       </all> 
      </complexType> 
     </schema> 
    </types> 
    <message name="importexportFooRequest"> 
     <part name="sessionId" type="xsd:string" /> 
    </message> 
    <message name="importexportFooResponse"> 
     <part name="result" type="typens:boolean" /> 
    </message> 
    <portType name="{{var wsdl.handler}}PortType"> 
     <operation name="importexportFoo"> 
      <documentation>ImportExport Foo</documentation> 
      <input message="typens:importexportFooRequest" /> 
      <output message="typens:importexportFooResponse" /> 
     </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="importexportFoo"> 
      <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> 
</definitions> 

/app/code/local/Namespace/ImportExport/Model/Api.php

<?php 
class Namespace_ImportExport_Model_Api extends Mage_Api_Model_Resource_Abstract 
{ 
    /** 
    * Returns version of the installed magento 
    * @return String 
    */ 

    public function foo() { 
     return true; 
    } 
} 
?> 
找到我的自定義模塊聲明

/app/code/local/Namespace/ImportExport/Model/API/V2.php

<?php 
class Namespace_ImportExport_Model_Api_V2 extends Namespace_ImportExport_Model_Api 
{ 
    public function foo() { 
     return true; 
    } 
} 
?> 

我打這個電話,是這樣的...

$fclient = new SoapClient($config['from']['soap_url']); 
$fsession = $fclient->login($config['from']['username'], $config['from']['api_key']); 
var_dump($fclient->importexportFoo($fsession)); 

這是我的知識是讓我的自定義API模塊工作的必需品。那麼我可能會做錯什麼?

我正在此爲錯誤

Function ("importexportFoo") is not a valid method for this service 

回答

1

我剛喝了這種問題。

進行API調用時請檢查$config['from']['soap_url']的值。如果該值看起來像http://example.com/api/soap?wsdl那麼你仍然在打電話給V1。更新它看起來像這樣http://example.com/api/v2_soap/?wsdl

相關問題