我正在尝试通过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)
答案 0 :(得分: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'
)
)
)
)
...
答案 1 :(得分:2)
这项工作可以添加additional_attributes
:
'additional_attributes' => array(
'single_data' => array(
array(
'key' =>'manufacturer',
'value' => '10'
)
)
)
答案 2 :(得分: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请求
p.s:当然它有点奇怪,但你可以用一些外观包裹它