Magento2: REST API : Save Product Detail per store view not working

后端 未结 3 1036

Using Magento2.1.0-rc1 Branch With Sample Data

Using REST API catalogProductRepositoryV1 REF: http://devdocs.magento.com/swagger/index.html Get Key from Admin token API

相关标签:
3条回答
  • 2021-02-15 04:40

    after debugging a lot on Magento2, Found that Magento2 does not have any functionality to Store Data from REST API as per StoreID getStore function in StoreManager just check if store is exist in session else return default , that is why all REST API Calls are stored in default store ID

    I have Over Rided Magento\Store\Model\StoreManager as below :

    etc/di.xml

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
        <preference for="Magento\Store\Model\StoreManager" type="Emizentech\MobileAdmin\Model\EmizenStoreManager" />
    </config>
    

    vim Model/EmizenStoreManager.php

    <?php
    namespace Emizentech\MobileAdmin\Model;
    
    use Magento\Store\Api\StoreResolverInterface;
    use Magento\Framework\App\RequestInterface;
    
    /**
     * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
     */
    class EmizenStoreManager extends \Magento\Store\Model\StoreManager
    {
            /**
         * Request instance
         *
         * @var \Magento\Framework\App\RequestInterface
         */
        protected $_request;
    
             /**
         * @param \Magento\Store\Api\StoreRepositoryInterface $storeRepository
         * @param \Magento\Store\Api\GroupRepositoryInterface $groupRepository
         * @param \Magento\Store\Api\WebsiteRepositoryInterface $websiteRepository
         * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
         * @param StoreResolverInterface $storeResolver
         * @param \Magento\Framework\Cache\FrontendInterface $cache
         * @param bool $isSingleStoreAllowed
         */
        public function __construct(
            \Magento\Store\Api\StoreRepositoryInterface $storeRepository,
            \Magento\Store\Api\GroupRepositoryInterface $groupRepository,
            \Magento\Store\Api\WebsiteRepositoryInterface $websiteRepository,
            \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
            StoreResolverInterface $storeResolver,
            \Magento\Framework\Cache\FrontendInterface $cache,
            RequestInterface $request,
            $isSingleStoreAllowed = true
        ) {
            $this->storeRepository = $storeRepository;
            $this->websiteRepository = $websiteRepository;
            $this->groupRepository = $groupRepository;
            $this->scopeConfig = $scopeConfig;
            $this->storeResolver = $storeResolver;
            $this->cache = $cache;
            $this->_request = $request;
            $this->isSingleStoreAllowed = $isSingleStoreAllowed;
        }
        /**
         * {@inheritdoc}
         */
        public function getStore($storeId = null)
        {
    
                    if($this->_request->isPut() && strlen($this->_request->getParam('storeId')))
                    {
                            return parent::getStore($this->_request->getParam('storeId'));
                    }
                    return parent::getStore($storeId);
        }
    
    }
    

    in this file i have check that if Request type is PUT and URL Paramater storeId exist than Set that Store else call parent::getStore()

    and in REST API PUT Call, I have added storeId in all request in which I need to set information to be stored as per StoreID & it works like a charm :) for store values in admin i am using storeID=0 ByDefault for all PUT Requests.

    0 讨论(0)
  • 2021-02-15 04:42

    I've encountered a similar scenario where I want to update prices per website. So to update the price, I've used

    /rest/<store_code>/V1/products/<sku>
    

    This worked fine.

    So I assume you can use this to update product data per store.

    0 讨论(0)
  • 2021-02-15 04:42

    /rest/<store_code>/V1/products/<sku>

    This one works, you can use

    • all
    • default

    for store codes

    0 讨论(0)
提交回复
热议问题