扩展Magento的REST API的自定义模块 [英] Extend Magento REST API in custom module

查看:213
本文介绍了扩展Magento的REST API的自定义模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Magento的REST的API将自定义数据添加到Magento的表。
我加入一个表到Magento的数据库,并与REST API创建模块,使用下面的链接

I want to use Magento Rest-Api to add custom data into Magento table. I have added one table into Magento db and created module with Rest API for that using following link

<一个href=\"http://web.archive.org/web/20130512072025/http://magepim.com/news/Extending-the-Magento-REST-API-part-1_13\" rel=\"nofollow\">http://web.archive.org/web/20130512072025/http://magepim.com/news/Extending-the-Magento-REST-API-part-1_13

现在我想添加使用REST API的数据到Magento的表...

Now I want to add data into Magento table using Rest API...

我需要做什么,在 api.xml / api2.xml 更改或 V1.php 文件。

what I need to changed in api.xml/api2.xml or in V1.php file.

请帮助我,我已经尝试了许多codeS使用产品api2.xml文件的参考。但没有运气。

Kindly help me I have tried many codes using reference of product api2.xml file. but no luck.

当我运行以下网址

http://magento-host/api/rest/magepim/products/count

将执行 V1.php 文件的 _retrieve()功能,但如何调用 _create()使用功能 PHP RESTAPI的OAuth

it will executed V1.php file's _retrieve() function but how to call _create() function using PHP RestApi oauth

推荐答案

Magento的\\程序\\ code \\核心\\法师\\ API2 \\型号\\ Resource.php
只允许集合动作类型创建方法。在api2.xml文件和设置必填字段因此改变了属性标记

magento\app\code\core\Mage\Api2\Model\Resource.php is only allowed collection action type for create method.. so changed in api2.xml file and setup required fields in attribute tag

Magento的\\程序\\ code \\社区\\ MagePim \\ Extapi \\等\\ api2.xml

magento\app\code\community\MagePim\Extapi\etc\api2.xml

<?xml version="1.0"?>
<config>
    <api2>
        <resource_groups>
            <extapi translate="title" module="api2">
                <title>Custom API calls</title>
                <children>
                    <extapi translate="title" module="api2">
                        <title>My Api</title>
                    </extapi>
                </children>
            </extapi>
        </resource_groups>
        <resources>
            <extapi translate="title" module="api2">
                <group>extapi</group>
                <model>extapi/api2</model>
                <working_model>extapi/api2</working_model>
                <title>Custom Api</title>
                <privileges>
                    <admin>
                        <create>1</create>
                        <retrieve>1</retrieve>
                        <update>1</update>
                        <delete>1</delete>
                    </admin>
                </privileges>
                <attributes>
                    <owner_id>Owner ID</owner_id>
                    <identityid>Identity ID</identityid>
                    <social_id>Social ID</social_id>
                    <status>Status</status>
                    <text>Text</text>
                    <request_timestamp>Request Time</request_timestamp>
                    <status_timestamp>Status Time</status_timestamp>
                </attributes>
                <routes>
                    <!-- Call For V1.php _retrieve() -->
                    <route_entity>
                        <route>/scheduler</route>
                        <action_type>entity</action_type>
                    </route_entity>
                    <!-- Call For V1.php _create() -->
                    <route_collection>
                        <route>/scheduler/create</route>
                        <action_type>collection</action_type>
                    </route_collection>
                </routes>
                <versions>1</versions>
            </extapi>
        </resources>
    </api2>
</config>

Magento的\\程序\\ code \\社区\\ MagePim \\ Extapi \\型号\\ API2 \\休息\\管理\\ V1.php

magento\app\code\community\MagePim\Extapi\Model\Api2\Rest\Admin\V1.php

/**
 * Override for Magento's REST API
 */
class Magepim_Extapi_Model_Api2_Rest_Admin_V1 extends Mage_Api2_Model_Resource {

    protected function _retrieve(){
        return json_encode($shedulerData);
    }
    protected function _create($shedulerData){
        return json_encode($shedulerData);
    }
    protected function _retrieveCollection(){
        return json_encode(array('method'=>'_retrieveCollection'));
    }
....................
}

这篇关于扩展Magento的REST API的自定义模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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