Tell me more ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

I am creating attributes using the Magento SOAP API V2, and need a few filterable attributes. I am using the following array:

$array = array(
    "attribute_code" => "testattribute",
    "frontend_input" => "select",   
    "scope" => "store", 
    "default_value" => "",
    "is_unique" => 0,
    "is_required" => 0,
    "apply_to" => "",
    "is_configurable" => 0,
    "is_searchable" => 0,
    "is_visible_in_advanced_search" => 0,
    "is_comparable" => 0,
    "is_used_for_promo_rules" => 1,
    "is_visible_on_front" => 1,
    "used_in_product_listing" => 1,
    "additional_fields" => array(
        "is_filterable" => 1, 
        "is_filterable_in_search" => 1, 
        "position" => 0, 
        "used_for_sort_by" => 0
    ),
    "frontend_label" => array(
        array("store_id" => "0", "label" => "This"), 
        array("store_id" => "1", "label" => "That")
    )
);

$client->catalogProductAttributeCreate($session, $array);

According to the documentation, this should work. It does create a select attribute, but does not make it filterable. To make it filterable i still have to do it manually in Magento. I can do this by hand, and that won't be a big problem, but it is strange that this doesn't work and I'd like to know if I'm doing something wrong or if this is an actual bug.

share|improve this question
Not an answer, but the method Mage_Catalog_Model_Product_Attribute_Api::create`` in app/code/core/Mage/Catalog/Model/Product/Attribute/Api.php` is where this API call is handled. Some debugging in there might point you in the right direction. – Alan Storm May 27 at 17:55

1 Answer

up vote 3 down vote accepted
+50

Your array should look like this:

$array = array(
    "attribute_code" => "testattribute",
    "frontend_input" => "select",   
    "scope" => "store", 
    "default_value" => "",
    "is_unique" => 0,
    "is_required" => 0,
    "apply_to" => "",
    "is_configurable" => 0,
    "is_searchable" => 0,
    "is_visible_in_advanced_search" => 0,
    "is_comparable" => 0,
    "is_used_for_promo_rules" => 1,
    "is_visible_on_front" => 1,
    "used_in_product_listing" => 1,
    "additional_fields" => array(
        array('key'=>'is_filterable', 'value'=>1),
        array('key'=>'is_filterable_in_search', 'value'=>1),
        array('key'=>'position', 'value'=>0),
        array('key'=>'used_for_sort_by', 'value'=>0)
    ),
    "frontend_label" => array(
        array("store_id" => "0", "label" => "This"), 
        array("store_id" => "1", "label" => "That")
    )
);

For some reason the additional_fields must be passed as an array of arrays. The lower level array must have 2 elements: key & value.
If you don't like this method you can extend the wsdl to be able to pass the attribute is_filtrable (and others) just like is_searchable.
You can do this by creating a new module. Let's call it Easylife_Catalog with the following files.
app/etc/modules/Easylife_Catalog.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Catalog>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Catalog />
            </depends>
        </Easylife_Catalog>
    </modules>
</config>

app/code/local/Easylife/Catalog/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Catalog>
            <version>0.0.1</version>
        </Easylife_Catalog>
    </modules>
</config>

app/code/local/Easylife/Catalog/etc/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">
            <complexType name="catalogProductAttributeEntityToCreate">
                <all>
                    <element name="is_filterable" type="xsd:string" minOccurs="0"/>
                    <element name="is_filterable_in_search" type="xsd:string" minOccurs="0"/>
                    <element name="position" type="xsd:string" minOccurs="0"/>
                    <element name="used_for_sort_by" type="xsd:string" minOccurs="0"/>
                </all>
            </complexType>
            <complexType name="catalogProductAttributeEntityToUpdate">
                <all>
                    <element name="is_filterable" type="xsd:string" minOccurs="0"/>
                    <element name="is_filterable_in_search" type="xsd:string" minOccurs="0"/>
                    <element name="position" type="xsd:string" minOccurs="0"/>
                    <element name="used_for_sort_by" type="xsd:string" minOccurs="0"/>
                </all>
            </complexType>
        </schema>
    </types>
</definitions>

After creating this module you will be able to pass the attribute create array like this:

$array = array(
    "attribute_code" => "testattribute",
    "frontend_input" => "select",   
    "scope" => "store", 
    "default_value" => "",
    "is_unique" => 0,
    "is_required" => 0,
    "apply_to" => "",
    "is_configurable" => 0,
    "is_searchable" => 0,
    "is_visible_in_advanced_search" => 0,
    "is_comparable" => 0,
    "is_used_for_promo_rules" => 1,
    "is_visible_on_front" => 1,
    "used_in_product_listing" => 1,
    "is_filterable" => 1, 
    "is_filterable_in_search" => 1, 
    "position" => 0, 
    "used_for_sort_by" => 0
    "frontend_label" => array(
        array("store_id" => "0", "label" => "This"), 
        array("store_id" => "1", "label" => "That")
    )
);

If you want to use WSI Complience you will need an additional file app/code/local/Easylife/Catalog/etc/wsi.xml

<?xml version="1.0" encoding="UTF-8"?>
<wsdl: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/"
             name="{{var wsdl.name}}"
             targetNamespace="urn:{{var wsdl.name}}">
    <wsdl:types>
        <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:{{var wsdl.name}}">
            <xsd:complexType name="catalogProductAttributeEntityToCreate">
                <xsd:sequence>
                    <xsd:element name="is_filterable" type="xsd:string" minOccurs="0" maxOccurs="0" />
                    <xsd:element name="is_filterable_in_search" type="xsd:string" minOccurs="0" maxOccurs="0" />
                    <xsd:element name="position" type="xsd:string" minOccurs="0" maxOccurs="0" />
                    <xsd:element name="used_for_sort_by" type="xsd:string" minOccurs="0" maxOccurs="0" />
                </xsd:sequence>
            </xsd:complexType>
        </xsd:schema>
    </wsdl:types>
</wsdl:definitions>

catalogProductAttributeEntityToUpdate seams to be missing in WSI complience.

share|improve this answer
Thank you, this worked! I only needed the first solution though, but thanks for your extended answer! It will sure help people in the future :) – Rune May 28 at 6:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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