1

I'm importing products from Magento using with the SOAP API V2. Everything is Ok but I get simple products and configurable products as unrelated objects.

How can I get the association between configurable and simple products?

This is NOT repeated. Other questions here are about creating configurable products, not reading.

EDIT: The problem is to solve that only through Magento built-in API. A third party extension is not an option because that Magento instance is only accessible through API.

2

I have create new extension which is give the relational diagram of simple products and parent Configurable product.

Step1>: Create Api.php at app\code\local\Amit\SimpleConfigRelation\Model

this give simple product ids and it reverent variance value and attribute id and option id and label

code is

<?php
class Amit_SimpleConfigRelation_Model_Api extends Mage_Catalog_Model_Api_Resource
{        
            public function getRelationship($productId, $storeId = null){

             $result = array();
             $this->_configProductId =$productId;
                $product = $this->_getProduct($productId, $storeId);
             $this->_getProduct = Mage::getModel('catalog/product');
            // $this->_getProduct->setStoreId($storeId);
             $this->_getProduct->load($productId);

             if($this->_getProduct->getId()){
                $result['dropdata']=$this->alldropdownData();

             }
            return $result; 
         }
            public function getChildsByParentId()
        {
        }        
        public function getVarienPrice()
        {
        }

        public function alldropdownData()
        {
            $attributes = array();
            $options    = array();

            $currentProduct = $this->_getProduct;

            $products = array();


            $skipSaleableCheck = Mage::helper('catalog/product')->getSkipSaleableCheck();
            /* getting all all simple products */
            $allProducts = $this->_getProduct->getTypeInstance(true)
                    ->getUsedProducts(null, $this->_getProduct);

            foreach ($allProducts as $product) {
                $products[] =  $product;
            }

            /* getting all configurable attribute of that products */
            $AllowAttributes=$this->_getProduct->getTypeInstance(true)
                ->getConfigurableAttributes($this->_getProduct);

           $producVarien=array();


            foreach ($products as $product) {

                $productsData[$product->getId()]=$product->getData();

                foreach ($AllowAttributes as $attribute) {

                    $productAttribute   = $attribute->getProductAttribute();
                    $productAttributeId = $productAttribute->getId();
                    $attributeValue     = $product->getData($productAttribute->getAttributeCode());
                    /* Simple Product data */

                    if (!isset($producVarien[$product->getId()])) {

                        $producVarien[$product->getId()] = array();
                    }
                     if (!isset($producVarien[$product->getId()][$productAttributeId])) {
                       $producVarien[$product->getId()][$productAttributeId] = array();
                    }

                    /* getting option text value */
                    if ($productAttribute->usesSource()) {
                         $MYabel = $productAttribute->getSource()->getOptionText($attributeValue );
                    }else{
                         $MYabel='';
                    }
                    $info = array(
                       'id'        => $productAttribute->getId(),
                       'code'      => $productAttribute->getAttributeCode(),
                       'label'     => $attribute->getLabel(),
                       'optionslabel'   => $MYabel
                  );

                     $producVarien[$product->getId()][$productAttributeId] = array('value'=>$attributeValue,'all'=>$info );
                    /* end of simple product data */
                    if (!isset($options[$productAttributeId])) {
                        $options[$productAttributeId] = array();
                    }

                    if (!isset($options[$productAttributeId][$attributeValue])) {
                        $options[$productAttributeId][$attributeValue] = array();
                    }


                    $options[$productAttributeId][$attributeValue][] = $productId;
                }
            }


            return $producVarien;
        }

}

[Result]

enter image description here

Step2: Create api.xml at app\code\local\Amit\SimpleConfigRelation\etc for getting their relation by api access

SOAP

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


XML-RPC

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

And code of this file

<?xml version="1.0"?>
<config>
    <api>
        <resources>
            <simpleconfigrelation_api translate="title" module="simpleconfigrelation">
                <title>Myapi</title>
                <acl>simpleconfigrelation/api</acl>
                <model>simpleconfigrelation/api</model>
                <methods>                    
                        <getrelationship translate="title" module="simpleconfigrelation">
                            <title>Relation Between</title>
                            <acl>simpleconfigrelation/getrelationship</acl>
                        </getrelationship>                    
                        <getchildsbyparentid translate="title" module="simpleconfigrelation">
                            <title>Child Product iDs</title>
                            <acl>simpleconfigrelation/getchildsbyparentid</acl>
                        </getchildsbyparentid>                    
                        <getvarienprice translate="title" module="simpleconfigrelation">
                            <title>Get Extra price on Varien</title>
                            <acl>simpleconfigrelation/getvarienprice</acl>
                        </getvarienprice>
                </methods>
            </simpleconfigrelation_api>
        </resources>
        <acl>
            <resources>
                <simpleconfigrelation translate="title" module="simpleconfigrelation">
                    <title>SimpleConfigRelation</title>
                    <sort_order>2000</sort_order>                    
                    <getrelationship translate="title" module="simpleconfigrelation">
                        <title>Relation Between</title>
                    </getrelationship>                    
                    <getchildsbyparentid translate="title" module="simpleconfigrelation">
                        <title>Child Product iDs</title>
                    </getchildsbyparentid>                    
                    <getvarienprice translate="title" module="simpleconfigrelation">
                        <title>Get Extra price on Varien</title>
                    </getvarienprice>
                </simpleconfigrelation>
            </resources>
        </acl>
    </api>
</config>

Step3: Create config.xml at app\code\local\Amit\SimpleConfigRelation\etc and

code is

<?xml version="1.0"?>
<config>
  <modules>
    <Amit_SimpleConfigRelation>
      <version>0.1.0</version>
    </Amit_SimpleConfigRelation>
  </modules>
  <global>
    <helpers>
      <simpleconfigrelation>
        <class>Amit_SimpleConfigRelation_Helper</class>
      </simpleconfigrelation>
    </helpers>
    <models>
      <simpleconfigrelation>
        <class>Amit_SimpleConfigRelation_Model</class>
        <resourceModel>simpleconfigrelation_mysql4</resourceModel>
      </simpleconfigrelation>
    </models>
  </global>
</config> 

Step4:create module file at Amit_SimpleConfigRelation.xml at app\etc\modules and code is

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

Study on How can I create a Custom SOAP/XML-RPC v1 & V2 Api in magento?

  • Thanks for the detailed explanation and hardwork. Unfortunately this is not pure API based solution as the source Magento system might not be accessible and it's not allowed to install extensions. The problem is to solve that only through Magento built-in API. – doc_id Nov 6 '14 at 19:17

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.