Magento API v2 and C # - setting custom attributes when adding a product

I added a custom attribute with the code "my_price" with "Directory entry type for the store owner" set to "Price" and assigned it to the "Default" attribute (only).

Now I want to set its value, every time I add / update a product with API v2 (C #). Here is the code that does not work (value not 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 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?

+6
source share
3 answers

Magento 1.6.1.0 has an error that leads to the error of additional attributes.

I upgraded my Magento to version 1.6.2.0 and the problem went away and the additional attributes work fine.

A 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 this helps someone.

+5
source

Try this and let me know the result.

 AdditionalAttributes.key = "myPrice"; 
+2
source
 handler.catalogProductCreate(session_id, "simple", attributeset_id, sku, mageProduct, "default"); 

Specify a valid storage instead of the default , for example. try the following:

 handler.catalogProductCreate(session_id, "simple", attributeset_id, sku, mageProduct, "1"); 
0
source

Source: https://habr.com/ru/post/905138/


All Articles