2

My question is similar to this post :- https://stackoverflow.com/questions/28952325/magento-retrieve-a-list-of-groups-from-a-attribute-set but there is no answer so.

I have attribute set id - 4 - Default Attribute Set. I want the list of groups created in Default Attribute Set using Soap API.

I checked the API documentation but it seems we can add, remove & rename only.

Basically what I want is to remove the group but for that I need to have already created group's ID so how can I get that using SOAP API?

Thanks.

  • I got the location of attribute group id & I removed the unwanted groups like this : $client->call($session,'product_attribute_set.groupRemove',array($attribute_id)); but still the question exists that how would I know that particular group (id) is existing in magento or not byt SOAP API. Thanks – KA9 Feb 8 '16 at 7:44
  • 1
    Default Magento not provided this SOAP API method. – Abdul Feb 8 '16 at 10:31
  • 1
    If you wand then create new custom method – Abdul Feb 8 '16 at 10:39
  • Thanks Abdul umm, ok so I will search how to create custom method for this & how to call it through API :) – KA9 Feb 8 '16 at 12:00
2

Follow steps for the create new custom SOAP API method

Step : 1 Create file app/etc/modules/AR_CustomApi.xml

<?xml version="1.0"?>
<config>
    <modules>
        <AR_CustomApi>
            <active>true</active>
            <codePool>local</codePool>
        </AR_CustomApi>
    </modules>
</config>

Step : 2 Create file app/code/local/AR/CustomApi/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <AR_CustomApi>
            <version>1.0.0</version>
        </AR_CustomApi>
    </modules>
    <global>
        <models>
        <customapi>
                <class>AR_CustomApi_Model</class>
            </customapi>
            <catalog>
                <rewrite>
                    <product_attribute_set_api>AR_CustomApi_Model_Product_Attribute_Set_Api</product_attribute_set_api>
                </rewrite>
            </catalog>
        </models>
    </global>
</config>

Step : 3 Create file app/code/local/AR/CustomApi/Model/Product/Attribute/Set/Api.php

<?php

class AR_CustomApi_Model_Product_Attribute_Set_Api extends Mage_Catalog_Model_Product_Attribute_Set_Api
{
    /**
     * Retrieve attribute groups
     *
     * @return array
     */
    public function groupList($attributeSetId)
    {

        // check if attribute set with requested id exists
        /** @var $attributeSet Mage_Eav_Model_Entity_Attribute_Set */
        $attributeSet = Mage::getModel('eav/entity_attribute_set')->load($attributeSetId);
        if (!$attributeSet->getId()) {
            $this->_fault('invalid_attribute_set_id');
        }

        $groups = Mage::getModel('eav/entity_attribute_group')
            ->getResourceCollection()
            ->setAttributeSetFilter($attributeSet->getId())
            ->setSortOrder()
            ->load();

        $result = array();
        foreach ($groups as $group) {
            $result[] = array(
                'group_id' =>$group->getAttributeGroupId(),
                'name'   => $group->getAttributeGroupName(),
            );

        }

        return $result;
    }
}

Step : 4 Create file app/code/local/AR/CustomApi/etc/api.xml

<?xml version="1.0"?>
<config>
    <api>
        <resources>
            <catalog_product_attribute_set translate="title" module="catalog">
                <methods>
                    <groupList translate="title" module="catalog">
                        <title>Retrieve groups from attribute set</title>
                        <acl>catalog/product/attribute/set/group_list</acl>
                    </groupList>
                </methods>
            </catalog_product_attribute_set>
        </resources>
        <acl>
            <resources>
                <catalog translate="title" module="catalog">
                    <product translate="title" module="catalog">
                        <attribute translate="title" module="catalog">
                            <set translate="title" module="catalog">
                                <group_list translate="title" module="catalog">
                                    <title>Groups list</title>
                                </group_list>
                            </set>
                        </attribute>
                    </product>
                </catalog>
            </resources>
        </acl>
    </api>
</config>

Step : 5 Create file app/code/local/AR/CustomApi/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">
            <import namespace="http://schemas.xmlsoap.org/soap/encoding/"
                    schemaLocation="http://schemas.xmlsoap.org/soap/encoding/"/>
            <complexType name="catalogProductAttributeSetGroupEntity">
                <all>
                    <element name="group_id" type="xsd:int" minOccurs="0"/>
                    <element name="name" type="xsd:string" minOccurs="0"/>
                </all>
            </complexType>
            <complexType name="catalogProductAttributeSetGroupEntityArray">
                <complexContent>
                    <restriction base="soapenc:Array">
                        <attribute ref="soapenc:arrayType" wsdl:arrayType="typens:catalogProductAttributeSetGroupEntity[]"/>
                    </restriction>
                </complexContent>
            </complexType>
        </schema>
    </types>
    <message name="catalogProductAttributeSetGroupListRequest">
        <part name="sessionId" type="xsd:string"/>
    </message>
    <message name="catalogProductAttributeSetGroupListResponse">
        <part name="result" type="typens:catalogProductAttributeSetGroupEntityArray"/>
    </message>
    <portType name="{{var wsdl.handler}}PortType">
        <operation name="catalogProductAttributeSetGroupList">
            <documentation>Retrieve product attribute groups</documentation>
            <input message="typens:catalogProductAttributeSetGroupListRequest"/>
            <output message="typens:catalogProductAttributeSetGroupListResponse"/>
        </operation>
    </portType>
    <binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
        <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="catalogProductAttributeSetGroupList">
            <soap:operation soapAction="urn:{{var wsdl.handler}}Action"/>
            <input>
                <soap:body namespace="urn:{{var wsdl.name}}" use="encoded"
                           encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </input>
            <output>
                <soap:body namespace="urn:{{var wsdl.name}}" use="encoded"
                           encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </output>
        </operation>
    </binding>
    <service name="{{var wsdl.name}}Service">
        <port name="{{var wsdl.handler}}Port" binding="typens:{{var wsdl.handler}}Binding">
            <soap:address location="{{var wsdl.url}}"/>
        </port>
    </service>
</definitions>

Step : 6 Create file app/code/local/AR/CustomApi/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="catalogProductAttributeSetGroupEntity">
                <xsd:sequence>
                    <xsd:element name="group_id" type="xsd:int" minOccurs="0" />
                    <xsd:element name="name" type="xsd:string" minOccurs="0" />
                </xsd:sequence>
            </xsd:complexType>
            <xsd:complexType name="catalogProductAttributeSetGroupEntityArray">
                <xsd:sequence>
                   <xsd:element minOccurs="0" maxOccurs="unbounded" name="complexObjectArray" type="typens:catalogProductAttributeSetGroupEntity" />
                </xsd:sequence>
            </xsd:complexType>
        </xsd:schema>
    </wsdl:types>
    <wsdl:message name="catalogProductAttributeSetGroupListRequest">
        <wsdl:part name="parameters" element="typens:catalogProductAttributeSetGroupListRequestParam" />
    </wsdl:message>
    <wsdl:message name="catalogProductAttributeSetGroupListResponse">
        <wsdl:part name="parameters" element="typens:catalogProductAttributeSetGroupListResponseParam" />
    </wsdl:message>
    <wsdl:portType name="{{var wsdl.handler}}PortType">
        <wsdl:operation name="catalogProductAttributeSetGroupList">
            <wsdl:documentation>Retrieve product attribute set groups</wsdl:documentation>
            <wsdl:input message="typens:catalogProductAttributeSetGroupListRequest" />
            <wsdl:output message="typens:catalogProductAttributeSetGroupListResponse" />
        </wsdl:operation>

    </wsdl:portType>
    <wsdl:binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="catalogProductAttributeSetGroupList">
            <soap:operation soapAction="" />
            <wsdl:input>
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="{{var wsdl.name}}Service">
        <wsdl:port name="{{var wsdl.handler}}Port" binding="typens:{{var wsdl.handler}}Binding">
            <soap:address location="{{var wsdl.url}}" />
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

Step : 7

  • Go admin side System -> Cache Management and refresh all cache
  • Go admin side System -> Web Services -> Roles and save all roles again

Step : 8 Called custom method like

try {
    $attributeSetId =  4;
    $client = new SoapClient('http://magento.com/test/index.php/api/?wsdl'); // api url
    $sessionId = $client->login('ar123', 'ar123'); // API user name & key 
    $result = $client->call($sessionId, 'catalog_product_attribute_set.groupList',$attributeSetId);
   echo "<pre>";
}
catch (Exception $e) {
   echo $e->getMessage();
}
print_r($result);
  • Oh my god this is awesome :) Thanks Abdul for helping :) Really great one :) – KA9 Feb 8 '16 at 13:36
  • @Abdul how can i get sales order with each products of order, how can i get by API. – zus Jan 19 '18 at 5:22
  • @zus Have you get all orders by API right? – Abdul Jan 19 '18 at 5:34
  • @Abdul yes, right? – zus Jan 19 '18 at 7:57
  • @zus Pls see here devdocs.magento.com/guides/m1x/api/soap/sales/salesOrder/… – Abdul Jan 19 '18 at 9:11

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.