[英]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.