创建新的Magento REST API来获得在Magento分类列表 [英] Create new magento Rest api to get category list in magento

查看:200
本文介绍了创建新的Magento REST API来获得在Magento分类列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何创建新的Magento的REST API获取类上市。

Does anyone know how to create new magento rest api to get category listing.

我已经看到这个链接
Magento的REST API 但这不取分类列表。

I already saw this link magento rest api but this not fetch category listings.

如果那么任何人知道,请解决这个问题。

If any one knows then please solve this..

推荐答案

首先创建一个使用基本模块 http://www.silksoftware.com/magento-module-creator/ 这一点,那么你必须创建以下文件,并在给定的路径中添加该文件。

First create basic module using http://www.silksoftware.com/magento-module-creator/ this and then you have to create following file and add this file in given path.

模块路径= 应用程序/ code /本地/ RESTAPI /类别

1)应用/ code /本地/ RESTAPI /分类/等/ api2.xml

<?xml version="1.0"?>
<config>
<api2>
    <resource_groups>
        <catalog translate="title" module="api2">
            <title>Catalog</title>
            <sort_order>10</sort_order>       
        </catalog>
    </resource_groups>
    <resources>
        <categories translate="title" module="api2">
            <group>catalog</group>
            <model>categories/api2_category</model>
            <title>Categories</title>
            <sort_order>10</sort_order>
            <privileges>
                <admin>
                    <retrieve>1</retrieve>
              <!--  <create>1</create>
                    <update>1</update>
                    <delete>1</delete>  --> 
                </admin>
                <customer>
                    <retrieve>1</retrieve>
              <!--  <create>1</create>
                    <update>1</update>
                    <delete>1</delete>  --> 
                </customer>
                <guest>
                    <retrieve>1</retrieve>
              <!--  <create>1</create>
                    <update>1</update>
                    <delete>1</delete>  --> 
                </guest>
            </privileges>
            <attributes>
                <category_id>Category ID</category_id>
                <name>Name</name>
                <parent_id>Category Parent ID</parent_id>
                <child_id>Category Child List</child_id>
                <active>Active</active>
                <level>Level</level>
                <position>Position</position>
            </attributes>
            <routes>
                <route>
                    <route>/categories/:cat_id</route>
                    <action_type>collection</action_type>
                </route>
            </routes>
            <versions>1</versions>
        </categories>
    </resources>
</api2>
</config>

下面是CAT_ID类别ID,我们传递给孩子取类。

Here cat_id is category id which we pass to fetch child category.

2)应用/ code /本地/ RESTAPI /分类/型号/ API2 /分类/ REST /客户/ V1.php

<?php
class Restapi_Categories_Model_Api2_Category_Rest_Customer_V1 extends Restapi_Categories_Model_Api2_Category
{
/**
 * Retrieve list of category list.
 *
 * @return array
 */
protected function _retrieveCollection()
{   
    $ruleId = $this->getRequest()->getParam('cat_id');

//  $cat_mod = Mage::getModel('catalog/category')->load($ruleId)->toArray();
    $cats = Mage::getModel('catalog/category')->load($ruleId);
    $subcats  = Mage::getModel('catalog/category')->load($ruleId)->getChildren();

    $cur_category = array();

    $node['category_id'] = $ruleId;
    $node['name'] = $cats->getName();
    $node['parent_id'] = $cats->getParentId();
    $node['child_id'] = $subcats;
    if($cats->getIsActive()){
        $node['active'] = 1;
    }else{
        $node['active'] = 0;
    }
    $node['level'] = $cats->getLevel();
    $node['position'] = $cats->getPosition();

    $cur_category[] = $node;

//  $subcats  = Mage::getModel('catalog/category')->load($ruleId)->getAllChildren();
//  $subcats  = Mage::getModel('catalog/category')->load($ruleId)->getChildren();

    if($subcats != '') 
    {
        foreach(explode(',',$subcats) as $subCatid)
        {
            $_category = Mage::getModel('catalog/category')->load($subCatid);
            $childcats  = Mage::getModel('catalog/category')->load($subCatid)->getChildren();

            $node['category_id'] = $subCatid;
            $node['name'] = $_category->getName();
            $node['parent_id'] = $_category->getParentId();
            $node['child_id'] = $childcats;
            if($_category->getIsActive()){
                $node['active'] = 1;
            }else{
                $node['active'] = 0;
            }
            $node['level'] = $_category->getLevel();
            $node['position'] = $_category->getPosition();

            $cur_category[] = $node;

        }
    }

    return $cur_category;       
}

您还如果你有其他用户如管理员和来宾添加此相同V1.php文件中的这条道路。

you also add this same V1.php file in this path if you have other user like admin and guest.

应用程序/ code /本地/ RESTAPI /分类/型号/ API2 /分类/ REST /行政/ V1.php

应用程序/ code /本地/ RESTAPI /分类/型号/ API2 /分类/ REST /客户/ V1.php

只是要改变V1.php类文件的路径,如客户管理=

Just you want to change the class path in V1.php file like Customer = Admin.

这篇关于创建新的Magento REST API来获得在Magento分类列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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