扩展 Magento 的 API Soap V2(不是此服务的有效方法) [英] Extending Magento's API Soap V2 (is not a valid method for this service)

查看:19
本文介绍了扩展 Magento 的 API Soap V2(不是此服务的有效方法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个扩展 magento V2 肥皂调用的自定义模块.我的大部分资源都来自这篇文章

I am trying to create a custom module that extends magento V2 soap calls. Most of my sources came from this post

如何使用 SOAP 为 Magento 设置自定义 apiV2?

这是我迄今为止尝试让它工作的步骤.

This is the steps I've done to try to get it to work so far.

<?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>

/app/code/local/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

这里我写了一些现有的模块声明,但你会在底部找到我的自定义模块声明

/app/code/local/Namespace/ImportExport/etc/wsdl.xml

Here I over wrote some existing modules declarations but you will find my custom module declarations at the bottom

<?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;
    }
}
?>

然后我打电话,就像这样......

And I make the call, like so...

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

据我所知,这是让我的自定义 api V2 模块正常工作的必要条件.那么我可能做错了什么?

This to my knowledge is the bare necessities to get my custom api V2 module working. So what could I possibly be doing wrong ?

我收到这个是因为错误

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

推荐答案

我刚刚遇到了这种问题.

I've just had this kind of issue.

在调用 API 时检查 $config['from']['soap_url'] 的值.如果该值看起来像 http://example.com/api/soap?wsdl,那么您仍在调用 V1.将其更新为如下所示 http://example.com/api/v2_soap/?wsdl.

Check the value of $config['from']['soap_url'] when making the API call. If the value looks like http://example.com/api/soap?wsdlthen you are still making a call to V1. Update it to look like this http://example.com/api/v2_soap/?wsdl.

这篇关于扩展 Magento 的 API Soap V2(不是此服务的有效方法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆