1

We created configurable products based on size attribute. say A is configurable product having children of different sizes like S, M, XL.

How to get available size like S,M,XL from parent product using SOAP in Magento CE 1.7.0.2.

2

In this case,you need to create extension.

Step1: Create module file at app/etc/modules/Stackexchange_Magento61215.xml

Code:

<?xml version="1.0"?>
<config>
  <modules>
    <Stackexchange_Magento61215>
      <active>true</active>
      <codePool>local</codePool>            
            <depends>
                <Mage_Api />
            </depends>
      <version>0.1.0</version>
    </Stackexchange_Magento61215>
  </modules>
</config>

Step2:Create Module api files:

StepA: Create config.xml file at

app\code\local\Stackexchange\Magento61215\etc 

Code:

<?xml version="1.0"?>
<config>
  <modules>
    <Stackexchange_Magento61215>
      <version>0.1.0</version>
    </Stackexchange_Magento61215>
  </modules>
  <global>
    <helpers>
      <magento61215>
        <class>Stackexchange_Magento61215_Helper</class>
      </magento61215>
    </helpers>
    <models>
      <magento61215>
        <class>Stackexchange_Magento61215_Model</class>
        <resourceModel>magento61215_mysql4</resourceModel>
      </magento61215>
    </models>
  </global>
</config> 

StepB: xml code for api,file is api.xml app\code\local\Stackexchange\Magento61215\etc\

<?xml version="1.0"?>
<config>
    <api>
        <resources>
            <magento61215_api translate="title" module="magento61215">
                <title>Myapi</title>
                <acl>magento61215/api</acl>
                <model>magento61215/api</model>
                <methods>                    
        <getoptionbyparent translate="title" module="magento61215">
            <title>Fetchconfig</title>
        </getoptionbyparent>
                </methods>
            </magento61215_api>
        </resources>
        <acl>
            <resources>
                <magento61215 translate="title" module="magento61215">
                    <title>Magento61215</title>
                    <sort_order>2000</sort_order>                    
                    <getoptionbyparent translate="title" module="magento61215">
                        <title>Fetchconfig</title>
                    </getoptionbyparent>
                </magento61215>
            </resources>
        </acl>
    </api>
</config>

StepC: Define Model file from where you get Data:

<?php
class Stackexchange_Magento61215_Model_Api extends Mage_Api_Model_Resource_Abstract
{        
public function getoptionbyParent($parentProId = null)
{

    $Product=Mage::getModel('catalog/product')->load($parentProId);
    $result=array();                
    $apiHelper = Mage::helper('api');
    if($Product->getId()){
               $allProducts = $Product->getTypeInstance(true)
                    ->getUsedProducts(null, $Product);

    try {
        foreach ($allProducts as $product) {
            $result[]=$product->getResource()->getAttribute('size')->getFrontend()->getValue($product);
        }
        $data=array_unique($result);
    } catch (Mage_Core_Exception $e) {
        $this->_fault('filters_invalid', $e->getMessage());
    }
    }
    return $result;
}


}

StepD: create Helper file Data.php at app\code\local\Stackexchange\Magento61215\Helper

<?php
class Stackexchange_Magento61215_Helper_Data extends Mage_Core_Helper_Abstract
{
}

Now you can get data by

$client = new SoapClient('http://yourhost/api/soap/?wsdl');
$session = $client->login('******', '******');
$date = $client->call($session, 'magento61215_api.getoptionbyParent');

XML-RPC 
$client = new Zend_XmlRpc_Client('http://yourhost/api/xmlrpc/');
$session = $client->call('login', array('******', '******'));
$date=$client->call('call', array($session, 'magento61215_api.getoptionbyParent'));

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.