2016-06-10 46 views
7

Utilizzando Magento2.1.0-rc1 Branch dati campioneMagento2: API REST: salvare i dettagli del prodotto per view negozio non lavora

Utilizzando API REST catalogProductRepositoryV1 REF: http://devdocs.magento.com/swagger/index.html ottenere la chiave da Admin token API e utilizzare la chiave in

POST/V1/prodotti

&

PUT/V1/prodotti/{sku}

con parametro provato con entrambi parametro uno per uno

  • STORE_ID = 0
  • storeId = 0 utilizzando seguente 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" 
 
    } 
 
}

Non supporta STORE_ID/campo storeId, ma le informazioni in prodotti non salva per memorizzare si salva per impostazione predefinita Codice del negozio

GET/V1/prodotti ha parametro storeId stesso i aveva provato con PUT & POST, ma non funziona con PUT & POST

risposta

4

dopo il debug molto su Magento2, ha rilevato che Magento2 non ha alcuna funzionalità per memorizzare i dati da API REST come p er StoreID getStore funzione in StoreManager basta controllare se il negozio è esiste in sessione predefinita altro ritorno, è per questo che tutti i REST chiamate API vengono memorizzati in archivio predefinito ID

Ho più di Rided Magento \ Conservare \ modello \ StoreManager come di seguito:

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 questo file Ho controllo che, se richiesta tipo è PUT e URL paramater storeId esistono di Set che memorizzano altro chiamare parent :: getStore()

e in REST API PUT Chiama, ho aggiunto storeId in tutte le richieste in cui è necessario impostare le informazioni da memorizzare come per StoreID & funziona come un fascino :) per i valori di negozio in admin sto usando storeID = 0 ByDefault per tutte le richieste PUT.

5

Ho riscontrato uno scenario simile in cui desidero aggiornare i prezzi per sito web. Quindi per aggiornare il prezzo, ho usato

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

Questo ha funzionato bene.

Quindi presumo che è possibile utilizzare questo per aggiornare i dati del prodotto per negozio.

4

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

Questo funziona, è possibile utilizzare

  • tutti
  • predefinita

per codici negozio

+1

Grazie per questa risposta. C'è un problema (https://github.com/magento/magento2/issues/4952) segnalato per questo, ma questo sembra aiutare. Per migliorare la tua domanda: "tutti" equivale a store_id = 0 (admin), ma "default" può essere variabile. È vero, in una nuova installazione è di default, ma in multistore questo può essere 'en', 'de', 'fr', ecc. –