Magento 1.9 SOAP API C# – Problem with Additional Attribute

magento-1.9soap

I'm using SOAP API v2 for Magento. I have a problem with product creation.

All fields are correctly set, but custom attributes that I've defined. These fields remains empty when I show it in panel. This is my code:

var mservice = new Mage_Api_Model_Server_Wsi_HandlerPortTypeClient();
        string mlogin = mservice.login("me", "*************");

        catalogProductCreateEntity newProduct = new catalogProductCreateEntity();

        newProduct.name = "Title here";
        newProduct.description = "Blabla bla bla";
        newProduct.short_description = "blalblalbla";
        newProduct.weight = "0";
        newProduct.status = "1";
        newProduct.price = "13.50";
        newProduct.tax_class_id = "2";

        associativeEntity[] AdditionalAttributes = new associativeEntity[1];
        associativeEntity AdditionalAttribute = new associativeEntity();
        AdditionalAttribute.key = "ean13";
        AdditionalAttribute.value = "978883226238";                       

        AdditionalAttributes[0] = AdditionalAttribute;       

        newProduct.additional_attributes = AdditionalAttributes;                                                                  

        try
        {
            mservice.catalogProductCreate(mlogin, "simple", "4", "93bffellag44fh1ll24-x", newProduct, null);                                
        }
        catch (Exception merror)
        {
            Console.WriteLine("Errore soap magento: " + merror.Message);
            Console.Read();
        }

Best Answer

Probably you use SOAPv2 with WS-I

The problem: SOAPv2 with WS-I does not use the single_data and multi_data attributes. You must change Magento file app/code/core/Mage/Catalog/Model/Product/Api/V2.php

In block if (property_exists($productData, 'additional_attributes')) {...}

after 265 line paste

if (gettype($productData->additional_attributes) == 'array') {
    foreach ($productData->additional_attributes as $k => $v) {
        $_attrCode = $k;
        $productData->$_attrCode = $v;
    }
}

More info on site https://www.rastating.com/adding-additional-attributes-in-magento-v2-api-in-ws-i-compliance-mode/

Related Topic