drqn5418 2014-07-03 15:50
浏览 42
已采纳

使用REST API将产品分配到Magento中的特定类别

I'm using code below to POST a product to Magento which works fine however I need know how to assign the product to a specific category. Anyone knows a solution?

Thanks in advance.

$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);
  • 写回答

1条回答 默认 最新

  • dongni1892 2014-07-04 14:55
    关注

    Solved. This goes after adding the products into magento process.

    $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();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?