cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with additional attribute in SOAP API C#

Problem with additional attribute in SOAP API C#

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:

Any help please??

 

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();
        }
3 REPLIES 3

Re: Problem with additional attribute in SOAP API C#

You have to extend WSDL file that describes Magento API to track additional attributes. XSD definition of object catalogProductReturnEntity limits what objects are beeing send in reponse. Just adding them to definition in app/code/core/Mage/Catalog/etc/wsdl.xml (Keep in mind that modifiing this file is bad idea, since wsdl.xml is beeing constructed same way as all the order mangeto config files I would suggest create new module that just provides own wsdl.xml with additional records for product entities).

Re: Problem with additional attribute in SOAP API C#

Wow! How much work to perform a quite simple problem??? SOAP documentation on Magento lacks info about this.

Re: Problem with additional attribute in SOAP API C#

First step is to create new module that will register extension for your WSDL file. You can autogenerate base Magento module using nice tools like n98-magerun.

 

Second step requires from You unserstanding what objects You are sending over SOAP API. In Your newly created module add wsdl.xml file in path like app/code/<codePool>/<vendorName>/MySoapExtendingModule/etc/wsdl.xml. Within that file You can add partial WSDL definition for entities You require for example adding field my_field to catalogProductList response: (You only need to extend WSDL file because Magento is fetching this data but does not know how to convert it into proper SOAP response)

 

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:typens="urn:{{var wsdl.name}}" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"
    name="{{var wsdl.name}}" targetNamespace="urn:{{var wsdl.name}}" xmlns:ns0="urn:Magento">
    <types>
        <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
            <import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" />
            <complexType name="catalogProductReturnEntity">
                <all>
                    <element name="my_field" type="xsd:string" minOccurs="0"/>
                </all>
            </complexType>
        </schema>
    </types>
</definitions>

 

Now enable module, clear all cachces (note that WSDL cache is not a Magento cache but PHP cache and it requires to manually remove *.wsdl files from temporary directory).

 

Final step is to regenerate SOAP API client. You have to generate it again beacuse module You just created caused modification to WSDL file describing Magento SOAP API.

 

After word: using Magento SOAP API v1 instead of SOAP API v2 will not require You to extend WSDL files but building objects for communication will be painfull (there are only two methods in SOAP API v1 - login and call, all the data is passed as associatve array. In Magento2 WSDL files will be generated automatically based on service contracts and this problem would be non existant.