Magento API v2 and C# - set custom attributes whilst adding product
Asked Answered
E

3

6

I have added custom attribute with the code "my_price" with "Catalog Input Type for Store Owner" set to "Price" and assigned it to the "Default" (only) attribute set.

Now, I want to set its value, everytime I add/update product with API v2 (C#). Here is the code which does not work (the value is not being set):

// Connect & Auth:
Mage_Api_Model_Server_V2_HandlerPortTypeClient handler = new Mage_Api_Model_Server_V2_HandlerPortTypeClient();
session_id = handler.login(username, api_key);

// Getting attributes set:
catalogProductAttributeSetEntity[] attributeSets;
attributeSets = handler.catalogProductAttributeSetList(session_id);
attributeSet = attributeSets[0];
string attributeset_id = attributeSet.set_id.ToString();

// Adding product:
catalogProductCreateEntity mageProduct = new catalogProductCreateEntity();
// (...) setting product's name, sku, etc.
associativeEntity AdditionalAttributes = new associativeEntity();
AdditionalAttributes.key = "my_price";
AdditionalAttributes.value = "12,33";
associativeEntity[] AssociativeEntity = new associativeEntity[1];
AssociativeEntity[0] = AdditionalAttributes;
mageProduct.additional_attributes = AssociativeEntity;
handler.catalogProductCreate(session_id, "simple", attributeset_id, sku, mageProduct, "default");

What am I doing wrong?

Elegist answered 4/1, 2012 at 20:26 Comment(2)
how about myPrice instead of my_price? Did you tried?Impresa
I have the same problem, did you figure it out. My catalogProductCrateEntity never passes any data,Fatma
E
5

Magento 1.6.1.0 has a bug which results with additional attributes error.

I have upgraded my Magento to 1.6.2.0 and the problem disappeared and additional attributes works perfectly.

Quick example of how it works:

associativeEntity[] AdditionalAttributes = new associativeEntity[1];
associativeEntity AdditionalAttribute = new associativeEntity();
AdditionalAttribute.key = "myprice";
AdditionalAttribute.value = getOriginalPrice(prices).ToString();
AdditionalAttributes[0] = AdditionalAttribute;
catalogProductAdditionalAttributesEntity AdditionalAttributesEntity = new catalogProductAdditionalAttributesEntity();
AdditionalAttributesEntity.single_data = AdditionalAttributes;

mageProduct.additional_attributes = AdditionalAttributesEntity;

Hope it helps someone.

Elegist answered 6/2, 2012 at 10:1 Comment(0)
M
2

Try this and let me know the result.

AdditionalAttributes.key = "myPrice";
Matted answered 4/1, 2012 at 20:40 Comment(3)
Still nothing... Do I have to refresh the service reference maybe? I really wouldn't like to do that, because there is some kind of bug and Visual Studio doesn't generate required code properly.Elegist
@Spyro I would give you a link which is old but I am definitely sure can you help to get and set product attributes. .net C# API to Magento via XML-RPCImpresa
this is other link .NET C# Object Library for Magento's XML-RPC APIImpresa
G
0
handler.catalogProductCreate(session_id, "simple", attributeset_id, sku, mageProduct, "default");

Give valid storeview instead of default e.g. try this:

handler.catalogProductCreate(session_id, "simple", attributeset_id, sku, mageProduct, "1");
Gentes answered 19/11, 2014 at 6:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.