0

I am trying to create product attributes by SOAPV2 with method catalogProductAttributeCreate / Magento Community ver. 1.7.0.2

I have already debugged /core/Mage/Catalog/Model/Product/Attribute/Api.php` where this API call, string attribute_code & array frontend_label are fields that may not be empty.

Magento returns fault code 104 (Incorrect attribute type) with this XML:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <catalogProductAttributeCreate xmlns="urn:Magento">
            <sessionId xsi:type="xsd:string">a30c8633e591dad15a3eb67d8912f7c3</sessionId>
            <data xsi:type="ns1:catalogProductAttributeEntityToCreate">
                <attribute_code xsi:type="xsd:string">testattribute</attribute_code>
                <scope xsi:type="xsd:string">store</scope>
                <default_value xsi:type="xsd:string"/>
                <frontend_label xsi:type="ns1:catalogProductAttributeFrontendLabelEntity">
                    <store_id xsi:type="enc:string">0</store_id>
                    <label xsi:type="enc:string">Test label</label>
                </frontend_label>
            </data>
        </catalogProductAttributeCreate>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Why does Magento returns fault code 104? How can I created a attribute by SOAPV2 XML?

UPDATE

Still one question left for method catalogProductAttributeUpdate similar to catalogProductAttributeCreate

The product attribute label is updating with value "0", I expect "testlabel".

What is the correct XML / SOAPV2 ?

XML updating Attribute Label

  • Can you add the code you use to call the api with? It looks like you are missing the attribute type. – Vladimir Kerkhoff Dec 28 '13 at 22:02
2

A little extra debugging should get you where you need to be.

First, your error string/code, (104 (Incorrect attribute type)), can be traced to the following API exception.

#File: app/code/core/Mage/Catalog/etc/api.xml
<invalid_frontend_input>
    <code>104</code>
    <message>Incorrect attribute type.</message>
</invalid_frontend_input>

This means the API code used to trigger the exception will look something like this

$this->_fault('invalid_frontend_input');

That is, the name of the configured node in api.xml is used as a shortcut for the exception. As you hinted in your question, this can be traced to the following bit of PHP code

#File: app/code/core/Mage/Catalog/Model/Product/Attribute/Api.php
//validate frontend_input
$allowedTypes = array();
foreach ($this->types() as $type) {
    $allowedTypes[] = $type['value'];
}
if (!in_array($data['frontend_input'], $allowedTypes)) {
    $this->_fault('invalid_frontend_input');
}

Here Magento's API code is checking the method's data paramater for a frontend_input key. The "frontend input" is the type of UI form Magento will generate for editing this attribute's value in the Magento admin. Based on your soap request, it looks like your code failed to submit a value for frontend_input.

<!-- no frontend input -->
<data xsi:type="ns1:catalogProductAttributeEntityToCreate">
    <attribute_code xsi:type="xsd:string">testattribute</attribute_code>
    <scope xsi:type="xsd:string">store</scope>
    <default_value xsi:type="xsd:string"/>
    <frontend_label xsi:type="ns1:catalogProductAttributeFrontendLabelEntity">
        <store_id xsi:type="enc:string">0</store_id>
        <label xsi:type="enc:string">Test label</label>
    </frontend_label>
</data>

That's why Magento raised an exception. You need your SOAP calling code to submit a value that is both not blank and matches the one of the values returned by the $this->types() method call (which populates the $allowedTypes array). If you trace the call to types, you'll see

public function types()
{
    return Mage::getModel('catalog/product_attribute_source_inputtype')->toOptionArray();
}

Which, in turn, leads you to the catalog/product_attribute_source_inputtype model (Mage_Catalog_Model_Product_Attribute_Source_Inputtype), etc. Probably the quickest way to get a list of values here is to write some quick one off code to peek at the results of the toOptionArray call.

In a stock system the following

$options = Mage::getModel('catalog/product_attribute_source_inputtype')->toOptionArray();
var_dump($options);    

results in

array (size=8)
  0 => 
    array (size=2)
      'value' => string 'text' (length=4)
      'label' => string 'Text Field' (length=10)
  1 => 
    array (size=2)
      'value' => string 'textarea' (length=8)
      'label' => string 'Text Area' (length=9)
  2 => 
    array (size=2)
      'value' => string 'date' (length=4)
      'label' => string 'Date' (length=4)
  3 => 
    array (size=2)
      'value' => string 'boolean' (length=7)
      'label' => string 'Yes/No' (length=6)
  4 => 
    array (size=2)
      'value' => string 'multiselect' (length=11)
      'label' => string 'Multiple Select' (length=15)
  5 => 
    array (size=2)
      'value' => string 'select' (length=6)
      'label' => string 'Dropdown' (length=8)
  6 => 
    array (size=2)
      'value' => string 'price' (length=5)
      'label' => string 'Price' (length=5)
  7 => 
    array (size=2)
      'value' => string 'media_image' (length=11)
      'label' => string 'Media Image' (length=11)

Meaning the valid values for frontend_input are

text
textarea
date
boolean
multiselect
select
price
media_image

If you're curious how Magento chooses these values, checkout the aforementioned toOptionArray in

app/code/core/Mage/Catalog/Model/Product/Attribute/Source/Inputtype.php

and its parent class Mage_Eav_Model_Adminhtml_System_Config_Source_Inputtype

app/code/core/Mage/Eav/Model/Adminhtml/System/Config/Source/Inputtype.php
  • what does frontend-label not defined mean? – Refilon Nov 30 '15 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.