1

Custom REST Api Magento 1.9 return only <magento_api/>

api2.xml

<config>
<api2>
    <resource_groups>
        <custom_restapi translate="title" module="Custom_Restapi">
            <title>Custom Rest API</title>
            <sort_order>10</sort_order>
        </custom_restapi>
    </resource_groups>
    <resources>
        <custom_restapi translate="title" module="Custom_Restapi">
            <group>custom_restapi</group>
            <model>custom_restapi/api2_restapi</model>
            <title>Testing My Rest API</title>
            <sort_order>100</sort_order>
            <privileges>
                <admin>
                    <create>1</create>
                    <retrieve>1</retrieve>
                    <update>1</update>
                    <delete>1</delete>
                </admin>
                <customer>
                    <retrieve>1</retrieve>
                </customer>
                <guest>
                    <retrieve>1</retrieve>
                </guest>
            </privileges>
            <attributes
                    translate="entity_id type_id attribute_set_id stock_data image_url is_saleable total_reviews_count url buy_now_url has_custom_options is_in_stock regular_price_with_tax regular_price_without_tax final_price_with_tax final_price_without_tax use_config_gift_message_available use_config_gift_wrapping_available url_key_create_redirect"
                    module="Custom_Restapi">
                <entity_id>Product ID</entity_id>
                <type_id>Product Type</type_id>
                <attribute_set_id>Attribute Set</attribute_set_id>
                <stock_data>Inventory Data</stock_data>
                <image_url>Default Image</image_url>
                <is_saleable>Salability Status</is_saleable>
                <total_reviews_count>Total Reviews Count</total_reviews_count>
                <url>Product URL</url>
                <buy_now_url>Buy Now URL</buy_now_url>
                <has_custom_options>Has Custom Options</has_custom_options>
                <is_in_stock>Stock Status</is_in_stock>
                <regular_price_with_tax>Regular Price With Tax</regular_price_with_tax>
                <regular_price_without_tax>Regular Price Without Tax</regular_price_without_tax>
                <final_price_with_tax>Final Price With Tax</final_price_with_tax>
                <final_price_without_tax>Final Price Without Tax</final_price_without_tax>
                <use_config_gift_message_available>Use Config Settings for Allow Gift Message
                </use_config_gift_message_available>
                <use_config_gift_wrapping_available>Use Config Settings for Allow Gift Wrapping
                </use_config_gift_wrapping_available>
                <url_key_create_redirect>Create Permanent Redirect for old URL</url_key_create_redirect>
            </attributes>
            <entity_only_attributes>
                <guest>
                    <read>
                        <has_custom_options>1</has_custom_options>
                        <tier_price>1</tier_price>
                        <total_reviews_count>1</total_reviews_count>
                        <url>1</url>
                        <buy_now_url>1</buy_now_url>
                        <has_custom_options>1</has_custom_options>
                        <is_in_stock>1</is_in_stock>
                    </read>
                </guest>
            </entity_only_attributes>
            <exclude_attributes>
                <guest>
                    <read>
                        <attribute_set_id>1</attribute_set_id>
                        <stock_data>1</stock_data>
                        <use_config_gift_message_available>1</use_config_gift_message_available>
                        <use_config_gift_wrapping_available>1</use_config_gift_wrapping_available>
                        <url_key_create_redirect>1</url_key_create_redirect>
                    </read>
                </guest>
            </exclude_attributes>
            <routes>
                <route_entity>
                    <route>test/products</route>
                    <action_type>entity</action_type>
                </route_entity>

            </routes>
            <versions>1</versions>
        </custom_restapi>
    </resources>
</api2>

V1.php

    public function _retrieve()
    {
        /** @var $collection Mage_Catalog_Model_Resource_Product_Collection */
        $collection = Mage::getResourceModel('catalog/product_collection');
        $store = $this->_getStore();
        $collection->setStoreId($store->getId());
        $collection->addAttributeToSelect(array_keys(
            $this->getAvailableAttributes($this->getUserType(), Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ)
        ));
        $products = $collection->load()->toArray();

        return $products;
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.