Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How do I attach a simple product to a configurable product using the SOAP API? 
 
Discovery
Enthusiast
 
Total Posts:  767
Joined:  2007-12-29
 

I have all of my products in the store but not all the simple products are hooked up to the configurables. I just need a reasonably sensible method that can make sure they are all attached. My SKU’s for the simple products are the same as the configurables but with the ‘autogenerated size/colour’ suffix. Does anyone know how to get child/parent properties through the API or mysql?

 
Magento Community Magento Community
Magento Community
Magento Community
 
LeeSaferite
Guru
 
Avatar
Total Posts:  322
Joined:  2007-08-31
Lake City, FL
 

See:  /app/code/core/Mage/Catalog/Model/Product/Link/Api.php

 
Magento Community Magento Community
Magento Community
Magento Community
 
Discovery
Enthusiast
 
Total Posts:  767
Joined:  2007-12-29
 

Thanks for the link - as luck would have it I wrote hack code to do it myself and it worked!!!

In a subdirectory /hacks I wrote add_simple.php and on calling http://store.com/hacks/add_simple.php I discovered that I had 7000 products floating around without being part of their respective configurables. I am now glad that I went through the script writing technique!

For future reference...:

This script is looking for SKU’s of products that have two underscores in the base product and even more underscores in the simple SKU’s

<html>
<
head>
<
title>Add Simple Products to Configurables</title>
</
head>
<
body>
<?php {
// Database connection - hope you remembered your user, pass and db
  
$res mysql_pconnect('localhost''USER''PASS');
  
mysql_select_db('MAGENTO_DB');
// Product selector - here all products of type simple with a selection of underscores in the sku
  
$res mysql_query('select entity_id from catalog_product_entity where type_id = \'simple\' and sku like \'%\_%\_%\'');
// Flag to test code set to 1 to modify db
  
$go_for_it=0;
  
$missing=0;
  
$with_parent=0;
// Go through all the products that match the selection
  
while ($o mysql_fetch_array($res)) {
    $result 
mysql_query('select sku from catalog_product_entity where entity_id='.$o['entity_id']);
    
$row mysql_fetch_assoc($result);
        
$sku=$row['sku'];
        if (
ereg ("([^_]+)_([^_]+)_([^_]+)_([^_]+)"$sku$master)) {
          $configurable
=$master[1].'_'.$master[2].'_'.$master[3];
          
$configurable_row mysql_query('select * from catalog_product_entity where sku=\''.$configurable.'\'');
          
$configurable_product mysql_fetch_array($configurable_row);
          
$configurable_product_id=$configurable_product['entity_id'];
          
$super_row mysql_query('select product_id, parent_id from catalog_product_super_link where product_id='.$o['entity_id']);
          if(
$super_retrieved mysql_fetch_array($super_row)) {
            
echo $row['sku'].' ('.$o['entity_id'].') is part of configurable product '.$configurable.'('.$super_retrieved['parent_id'].')<br />';
            
$with_parent++;
          
else {
            $missing
++;
            echo 
'<b>'.$row['sku'].' ('.$o['entity_id'].') should be part of configurable product '.$configurable.'('.$configurable_product['entity_id'].')'.$super_retrieved['parent_id'].'</b><br />';
            if (
$go_for_it!=0{
              mysql_query
('insert into catalog_product_super_link (product_id, parent_id) values ('.$o['entity_id'].', '.$configurable_product['entity_id'].')');
            
}
          }
        }
        mysql_free_result
($result);
  
}
  $total_products
=$missing+$with_parent;
  echo 
'<b>Simple products that were not attached to configurables '.$missing.' out of a total of '.$total_products.'</b><br />';
}
?>
</body>
</
html>
 
Magento Community Magento Community
Magento Community
Magento Community
 
LeeSaferite
Guru
 
Avatar
Total Posts:  322
Joined:  2007-08-31
Lake City, FL
 

Well, glad to know.  I’m fairly certain I was wrong anyway. =( Will teach me for not testing before I post.

 
Magento Community Magento Community
Magento Community
Magento Community
 
shobipersonal
Jr. Member
 
Total Posts:  4
Joined:  2013-07-16
 

I want to attach simple product with configurable product using SOAP request via XML , please guide.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top