0

我的设置看起来像这样

  • 默认 -> 主商店 -> MainStoreView
  • 网站 1 -> 商店 1 -> StoreView1 商店 2 -> StoreView2

现在我想知道如何仅从 Website1->Store1 或 Website1->Store2 检索产品。我想使用像 www.mysite.com/api/rest/products/ 这样的普通网址并按 storeId 过滤产品,但问题是我没有从 Website1 获得任何产品。我只从默认网站获取产品。

任何人都可以深入了解为什么会这样吗?

4

1 回答 1

0

看着Mage_Catalog_Model_Api2_Product_Rest::_retrieveCollection()::

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

因此,该集合考虑了商店视图过滤器。让我们更深入地研究_getStore()方法:

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

基于此,我相信您可以指定:your_request_url?param...&store=STORE_ID

于 2012-12-31T09:24:24.193 回答