after repeatedly debugging Magento2, we found that Magento2 has no functions for storing data from the REST API according to the StoreID getStore in the StoreManager, just check if the storage exists in the else session, they are returned by default, therefore all REST API calls are stored in the storage identifier by default
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; class EmizenStoreManager extends \Magento\Store\Model\StoreManager { protected $_request; 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; } 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 verify that if the PUT request type and URL Paramater storeId exist, than Set Store else to call parent :: getStore ()
and in the REST API PUT Call, I added storeId to the entire request, in which I need to set the information that will be stored according to StoreID and works like a charm :) to store values ββin admin I use storeID = 0 ByDefault for all PUT requests.
Emizen tech
source share