簡體   English   中英

使用REST API將產品分配到Magento中的特定類別

[英]Assign a product to a specific category in Magento with REST API

我正在使用下面的代碼將產品發布到Magento,效果很好,但是我需要知道如何將產品分配到特定類別。 有人知道解決方案嗎?

提前致謝。

$oauthClient->setToken($_SESSION['token'], $_SESSION['secret']);
$resourceUrl = "$apiUrl/products";

$productData = json_encode(array(
            'type_id'           => 'simple',
            'attribute_set_id'  => 4,
            'sku'               => 'simple' . uniqid(),
            'weight'            => 1,
            'status'            => 1,
            'visibility'        => 4,
            'name'              => 'Name of the product',
            'description'       => 'Description',
            'short_description' => 'Short Description',
            'price'             => 6.99,
            'tax_class_id'      => 0
        ));
        $headers = array('Content-Type' => 'application/json');
        $oauthClient->fetch($resourceUrl, $productData, OAUTH_HTTP_METHOD_POST, $headers);

解決了。 這是在將產品添加到magento過程之后進行的。

$productId = 100; //Extracted from the previous response
$categoryId = 4;
$resourceUrl = "$apiUrl/products/$productId/categories";
$productData = json_encode(array('category_id' => $categoryId));
$headers = array('Content-Type' => 'application/json');
$oauthClient->fetch($resourceUrl, $productData, OAUTH_HTTP_METHOD_POST, $headers);
$response = $oauthClient->getLastResponseInfo();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM