douyanxing6054 2013-09-24 05:19 采纳率: 0%
浏览 101

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

How to create custom Api and Api2 in magento and give a permission for those Api and Api2?

Can you anyone give a example for those?

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dpxbc88022 2013-09-24 06:36
    关注

    Please look at my below custom code, may be its help you,

    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>
    

    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}}">
    
        <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>
    

    Api.php inside module's model folder

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

    V2.php file inside model/Objectmodel/api/ folder

    <?php
    class Namespace_Modulename_Model_Objectmodel_Api_V2 extends Companyname_Modulename_Model_Objectmodel_Api
    {    
    
    }
    ?>
    

    after you can call your method like below Here you create object of api after call method like this

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

    here "agentgallery.gettaxrule" is Custom Method.

    Try this

    评论

报告相同问题?

悬赏问题

  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决