magentomagento-1.7magento-rest-api

Magento rest api url to retrieve products from specific websites


My setup looks like this

Now I want to know how to retrieve products only from Website1->Store1 or Website1->Store2. I thought of using normal url like www.mysite.com/api/rest/products/ and filter the products by storeId, but the problem is I am not getting any products from Website1. I am getting products only from default website.

Can anyone give any insight into why this is happening?


Solution

  • Looking at: Mage_Catalog_Model_Api2_Product_Rest::_retrieveCollection():

    $collection = Mage::getResourceModel('catalog/product_collection');
    $store = $this->_getStore();
    //[...]
    $collection->addStoreFilter($store->getId()) 
    

    So, the collection takes into consideration a store view filter. Let's dig deepr in _getStore() method:

    Mage_Api2_Model_Resource::_getStore():

    protected function _getStore()
        {
            $store = $this->getRequest()->getParam('store');
            try {
                if ($this->getUserType() != Mage_Api2_Model_Auth_User_Admin::USER_TYPE) {
                    // customer or guest role
                    if (!$store) {
                        $store = Mage::app()->getDefaultStoreView();
                    } else {
                        $store = Mage::app()->getStore($store);
                    }
                } else {
                    // admin role
                    if (is_null($store)) {
                        $store = Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID;
                    }
                    $store = Mage::app()->getStore($store);
                }
            } catch (Mage_Core_Model_Store_Exception $e) {
                // store does not exist
                $this->_critical('Requested store is invalid', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
            }
            return $store;
        }
    

    Based on this, I believe you can specify: your_request_url?param...&store=STORE_ID