Magento2:REST API:每个商店视图保存产品详细信息不起作用 [英] Magento2: REST API : Save Product Detail per store view not working

查看:206
本文介绍了Magento2:REST API:每个商店视图保存产品详细信息不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Magento2.1.0-rc1分支 带有样本数据

Using Magento2.1.0-rc1 Branch With Sample Data

使用REST API catalogProductRepositoryV1参考: http://devdocs.magento.com/swagger/index. html 从管理员令牌API获取密钥 并使用该键

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

POST/V1/产品

POST /V1/products

&

PUT/V1/products/{sku}

PUT /V1/products/{sku}

带参数的两个参数一一尝试

with parameter tried with both parameter one by one

  • store_id = 0
  • storeId = 0 使用以下JSON
  • store_id=0
  • storeId=0 using 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"
    }
}

不支持store_id/storeId字段, 但是产品中的信息不会保存到存储中 它会保存到默认的商店ID

Does not support store_id / storeId field , but the information in product does not save to store it save to default Store ID

获取/V1/产品具有参数storeId 我在PUT&中尝试过的相同开机自检,但不能与PUT&开机自检

GET /V1/products has parameter storeId same i had tried with PUT & POST but not working with PUT & POST

推荐答案

在Magento2上进行了大量调试后,发现Magento2没有任何功能可以按照StoreID存储来自REST API的数据 StoreManager 中的 getStore 函数只是检查会话中是否存在存储,否则返回default,这就是为什么所有 REST API调用都存储在默认存储ID中的原因

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

我已经过度骑行 Magento \ Store \ Model \ StoreManager 如下:

etc/di.xml

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模型/EmizenStoreManager.php

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

}

在此文件中,我已检查请求类型是否为 PUT 和URL参数 storeId 存在,而不是设置为Store否则调用 parent :: getStore()

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()

REST API PUT 调用中,我在所有需要设置信息以按照以下方式存储的请求中添加了 storeId 商店ID和它就像一个魅力:) 对于管理员中的商店值,我对所有PUT请求都使用 storeID = 0 默认.

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.

这篇关于Magento2:REST API:每个商店视图保存产品详细信息不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆