4

我正在尝试通过 API 添加以下 2 个附加属性。我没有收到任何错误,但是没有上传。如果有人能给我一个建议,那就太好了。

catalogProductAdditionalAttributesEntity AdAtrributeEntity = new catalogProductAdditionalAttributesEntity();

associativeEntity[] AdditionalAttributes = new associativeEntity[2];
associativeEntity AdditionalAttributeOne = new associativeEntity();
associativeEntity AdditionalAttributeTwo = new associativeEntity();

AdditionalAttributeOne.key = "color";
AdditionalAttributeOne.value = "green";
AdditionalAttributeTwo.key = "size";
AdditionalAttributeTwo.value = "xl";

AdditionalAttributes[0] = AdditionalAttributeOne;
AdditionalAttributes[1] = AdditionalAttributeTwo;

AdAtrributeEntity.single_data = AdditionalAttributes;
ProductEntity.additional_attributes = AdAtrributeEntity;

MyService.catalogProductUpdate(Mylogin, SKU, ProductEntity, null, null)
4

3 回答 3

3

我知道这是旧的,但我找到了解决方案。'single_data' 和 'multi_data' 需要在其中有一个包含属性数组的数组。

product_data = {
          'name' => self.get_attribute_value('name'),
          'description' => self.get_attribute_value('description'),
          'short_description' => self.get_attribute_value('short_description'),
          'weight' => self.get_attribute_value('weight'),
          'status' => self.get_attribute_value('status'),
          'categories' => compose_categories,
          'url_key' => self.get_attribute_value('url_key'),
          'price' => self.get_attribute_value('price'),
          'additional_attributes' => { 'single_data' => { items: compose_attribute_values }}
}

在示例中,我将附加数组命名为“item”,但是,您可以随意调用它。我使用了“item”,因为 API 返回了许多类似的值。附加属性在 PHP 中如下所示:

...
'additional_attributes' = array(
    'single_data' => array(
        'item' => array(
            [0] => array(
                'key' => 'some_attribute_code',
                'value' => 'some_attribute_value'
            )
            [1] => array(
                'key' => 'some_other_attribute_code',
                'value' => 'some_other_attribute_value'
            )
        )
    )
)
...
于 2013-05-09T15:00:31.677 回答
2

这项工作添加additional_attributes

'additional_attributes' => array(
    'single_data' => array(
        array(
            'key' =>'manufacturer',
            'value' => '10'
        )
    )
)
于 2015-08-01T15:14:09.967 回答
0

Java 示例Apache XML-RPC客户端 + Gson):

我有manufacturer带有选项的属性:Adidas(ID:318)

产品实体:

...
@SerializedName("additional_attributes")
private Map<String,Map<String,String>> additionalAttributes;
...
// getters + setters
...

代码:

...
Map<String,String> attribute = new HashMap<>();
attribute.put("manufacturer", "318");

Map<String,Map<String,String>> additionalAttributes = new HashMap<>();
additionalAttributes.put("single_data", attribute);

product.setAdditionalAttributes(additionalAttributes);
...

然后做product.update api 请求

ps:当然有点奇怪,但是你可以用一些门面来包裹它

于 2016-05-05T18:44:17.753 回答