magentomagento-soap-api

Set Attribute Option in Magento SOAP API XML


Does only one attribute option can be set at a time using SOAP Magento API 1.9? I tried to set multiple options using below XML but no success. Can anyone help?

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Magento" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:catalogProductAttributeAddOption soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <sessionId xsi:type="xsd:string">8e72f087a574773ba0dc017e8268d268</sessionId>
         <attribute xsi:type="xsd:string">215</attribute>
         <data xsi:type="urn:catalogProductAttributeOptionEntityToAdd">
            <!--You may enter the following 3 items in any order-->
            <label soapenc:arrayType="urn:catalogProductAttributeOptionLabelEntity[3]" xsi:type="urn:catalogProductAttributeOptionLabelArray">
            <item xsi:type="ns1:catalogProductAttributeOptionLabelEntity">
                  <store_id xsi:type="xsd:string">0</store_id>
                  <value xsi:type="xsd:string">steel6</value>
               </item>
                <item xsi:type="ns1:catalogProductAttributeOptionLabelEntity">
                  <store_id xsi:type="xsd:string">0</store_id>
                  <value xsi:type="xsd:string">steel1</value>
               </item>
                <item xsi:type="ns1:catalogProductAttributeOptionLabelEntity">
                  <store_id xsi:type="xsd:string">0</store_id>
                  <value xsi:type="xsd:string">steel2</value>
               </item>
            </label>
            <order xsi:type="xsd:int">0</order>
            <is_default xsi:type="xsd:int">0</is_default>
         </data>
      </urn:catalogProductAttributeAddOption>
   </soapenv:Body>
</soapenv:Envelope>


Solution

  • I have finally found an answer to my above question, Magento API "catalogProductAttributeAddOption" is used to set just one option at a time, however API can be extended to set multiple options.

    So API to set option would be

    <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Magento" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
       <soapenv:Header/>
       <soapenv:Body>
          <urn:catalogProductAttributeAddOption soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
             <sessionId xsi:type="xsd:string">8e72f087a574773ba0dc017e8268d268</sessionId>
             <attribute xsi:type="xsd:string">215</attribute>
             <data xsi:type="urn:catalogProductAttributeOptionEntityToAdd">
                <!--You may enter the following 3 items in any order-->
                <label soapenc:arrayType="urn:catalogProductAttributeOptionLabelEntity[1]" xsi:type="urn:catalogProductAttributeOptionLabelArray">
                <item xsi:type="ns1:catalogProductAttributeOptionLabelEntity">
                      <store_id xsi:type="xsd:string">0</store_id>
                      <value xsi:type="xsd:string">steel1</value>
                   </item>
                </label>
                <order xsi:type="xsd:int">0</order>
                <is_default xsi:type="xsd:int">0</is_default>
             </data>
          </urn:catalogProductAttributeAddOption>
       </soapenv:Body>
    </soapenv:Envelope>