Magento2: REST API: saving product details in view mode does not work

Using the Magento2.1.0-rc1 Branch With Sample Data

Using the REST directory APIProductRepositoryV1 REF: http://devdocs.magento.com/swagger/index.html Get the key from the API cursor API and use this key in

POST / V1 / Products

&

PUT / V1 / products / {sku}

with a parameter that tried both parameters one after another

  • store_id = 0
  • StoreID = 0 using the following JSON

{ "saveOptions": "true", "product": { "name": "Test11_11", "sku": "TESTOPP_111", "attributeSetId": "15", "price": "10", "weight": "10", "status": "1", "visibility": "3", "customAttributes": [ { "attributeCode": "manufacturer", "value": "222" }, { "attributeCode": "tax_class_id", "value": "0" }, { "attributeCode": "specialPrice", "value": "10" }, { "attributeCode": "description", "value": "44332211" }, { "attributeCode": "eco_collection", "value": "1" } ], "typeId": "simple" } } 

Does not support the name store_id / storeId, but the information in the product is not saved for storage; it retains the store identifier by default

GET / V1 / products has the storeId parameter. I tried the same with PUT and POST, but did not work with PUT and POST

+7
rest api product magento2
source share
3 answers

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; /** * @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 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.

+4
source share

I came across a similar scenario where I want to update website prices. Therefore, to update the price, I used

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

This works great.

Therefore, I assume that you can use this to update product data for each store.

+5
source share

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

It works, you can use

  • everything
  • Default

for storage codes

+4
source share

All Articles