FlyingM
FlyingM

Reputation: 227

Magento 1.7 SOAP v2 Api - Creating products with additional attributes

I have set up a web shop with Magento version 1.7 and my next task is to import products by using the v2 Soap api. So far, everything seems to work except for one thing: All the custom attributes of the created products remain empty. Everything else works fine - the name, sku, price, description and so on. My script runs with asp.net so I don't have any PHP code but I think it looks more or less similar. Here is a snippet that I use where the attributes are assigned to a product:

dim create as new catalogProductCreateEntity
create.name = "Test"
create.price = "11.1100"
create.description = "test description"

dim additional(0) as associativeEntity
dim attribute as new associativeEntity
attribute.key = "manufacturer"
attribute.key = "xyz"
additional(0) = attribute

create.additional_attributes = additional

In this case, a simple text field should receive the value "xyz". I use the very same procedure in other Magento stores that I have set up in the past and it works just fine. The only difference is that these shops use Magento version 1.5. Could this be a bug in the api?

Upvotes: 0

Views: 1189

Answers (2)

user2913305
user2913305

Reputation:

i have successfully done this in C#, below is the code

     private void getAdditionalAttributes()
            {
                string skuNumber="S00001";
                MagentoService mservice = new MagentoService();
                string sessionkey = "";
                try
                {
                    sessionkey = mservice.login("apiuser", "apipassword");


                }
                catch (Exception exp)
                {

                    //Error
                }

                try
                {
                    catalogProductRequestAttributes fetchattrib = new catalogProductRequestAttributes();
                    // it will only populate the attributes that you ask for
                    fetchattrib.attributes = new string[] { "name", "description", "short_description" };
// Additional Attribute
                    fetchattrib.additional_attributes = new string[] { "ismemo","color" };

    catalogProductReturnEntity prod =  MagentoConnectivity.magService.catalogProductInfo(sessionkey, skuNumber, "", fetchattrib, "sku");


                    foreach (var item in prod.additional_attributes)
                    {
                        MessageBox.Show("=> Key: " + item.key + "\t Attribute Value=" + item.value + "\n");
                    }

                }
                catch (Exception exp)
                {

                    MessageBox.Show("=> Exception in getting Additional Attributes \n" + exp.Message + "\n");
                    return;


                }
            }

Upvotes: 0

Dmitry Selitskiy
Dmitry Selitskiy

Reputation: 633

"xyz" needs to go into .value of the associativeEntity:

dim additional(0) as associativeEntity
dim attribute as new associativeEntity
attribute.key = "manufacturer"
attribute.value = "xyz" 
additional(0) = attribute

Hope this helps.

Upvotes: 0

Related Questions