Magento – method to get a custom customer attribute value from a drop-down attribute through the Magento soap API

apicustomer-attributemagento-1.7soap

I have extended the Magento soap API in a custom module via wsi.xml and wsdl.xml to bring in a custom attribute added to my customers. The extension works fine to bring in the custom attributes I add via the back-end. However, if that attribute is a drop-down, the value retrieved through the API is the drop-down's option id.

I am retrieving my custom attributes via customerCustomerInfo. As seen in the Magento API documentation. I have provided my wsi.xml and wsdl.xml below for clarity's sake.

Is there a way to get the actual option name through the soap API instead of the id?

wsi.xml

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:typens="urn:Magento" 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/" name="Magento" targetNamespace="urn:Magento">
    <wsdl:types>
        <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
            <xsd:complexType name="customerCustomerEntity">
                <xsd:sequence>
                    <xsd:element name="customertype" type="xsd:string" minOccurs="0" ></xsd:element>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:schema>
    </wsdl:types>
</wsdl:definitions>

wsdl.xml

<?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}}">
    <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="customerCustomerEntity">
                <all>
                    <element name="customertype" type="xsd:string" minOccurs="0" />
                </all>
            </complexType>
        </schema>
    </types>
</definitions>

Best Answer

There is no method implemented in the standard Magento SOAP API to get the attributes value instead of the id.

The attributes are collected in the info() function of Mage_Customer_Model_Customer_Api: lines 98-104 (as for CE 1.8.1.0)

   foreach ($this->_mapAttributes as $attributeAlias=>$attributeCode) {
       $result[$attributeAlias] = $customer->getData($attributeCode);
   }

   foreach ($this->getAllowedAttributes($customer, $attributes) as attributeCode=>$attribute) {
        $result[$attributeCode] = $customer->getData($attributeCode);
   }

So you might want to extend it there.