Php 如何在magento中创建自定义Api和Api2,并为这些Api和Api2授予权限?

Php 如何在magento中创建自定义Api和Api2,并为这些Api和Api2授予权限?,php,magento,Php,Magento,如何在magento中创建自定义Api和Api2,并为这些Api和Api2授予权限 你能举个例子吗 提前感谢。请查看我下面的自定义代码,可能会对您有所帮助 api.xml <config> <modules> <Agentgallery> <version>0.1.0</version> </Agentgallery> </modules>

如何在magento中创建自定义Api和Api2,并为这些Api和Api2授予权限

你能举个例子吗


提前感谢。

请查看我下面的自定义代码,可能会对您有所帮助

api.xml

<config>
    <modules>
        <Agentgallery>
            <version>0.1.0</version>
        </Agentgallery>
    </modules>
    <api>
        <resources>
            <agentgallery translate="title" module="agentgallery">
                <model>agentgallery/api</model>
                <title>Tax Rule Api</title>
                <acl>agentgallery</acl>
                <methods>
                    <gettaxrule translate="title" module="agentgallery">
                        <title>Retrieve tax rule data</title>
                        <acl>agentgallery/gettaxrule</acl>
                    </gettaxrule>                    
                </methods>              
            </agentgallery>
        </resources>
        <acl>
            <resources>
                <agentgallery translate="title" module="agentgallery">
                    <title>Tax Rule</title>
                    <gettaxrule translate="title" module="agentgallery">
                        <title>Get tax rule</title>
                    </gettaxrule>                    
                </agentgallery>
                <all>
                </all>
            </resources>
        </acl>
    </api>
</config>
<?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}}">

    <message name="agentgalleryGettaxruleRequest">
        <part name="sessionId" type="xsd:string" />
        <part name="arg" type="xsd:string" />
    </message>    
    <message name="agentgalleryGettaxruleResponse">
        <part name="result" type="xsd:string" />
    </message>   
    <portType name="{{var wsdl.handler}}PortType">
        <operation name="agentgalleryGettaxrule">
            <documentation>Test Method</documentation>
            <input message="typens:agentgalleryGettaxruleRequest" />
            <output message="typens:agentgalleryGettaxruleResponse" />
        </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="agentgalleryGettaxrule">
            <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>
这里的“agentgallery.gettaxrule”是自定义方法

试试这个

<?php
class Namespace_Modulename_Model_Api extends Mage_Api_Model_Resource_Abstract
{

     public function gettaxrule($customerTaxClass,$productTaxClass)
     {                        
        $result = Mage::getResourceModel('tax/calculation')->getRatesForWebservices($customerTaxClass,$productTaxClass);

        //here you can paste your code whatever you need instead of $result variable

        return $result;
     }

}
?>
<?php
class Namespace_Modulename_Model_Objectmodel_Api_V2 extends Companyname_Modulename_Model_Objectmodel_Api
{    

}
?>
$result = $checkData->proxyObj()->call($sessionId, 'agentgallery.gettaxrule',array($customerTaxClass,$productTaxClass));