HOWTO get a list of configurable products that lack simple daughter products

Last modified by Discovery on Fri, June 25, 2010 09:43
Source|Old Revisions  

This is an old revision of the document!


This script goes through every product in your Magento site and identifies the configurable products that do not have simple children.

  1. <?php
  2.  
  3. // if store not in /magento change to your directory, e.g. /shop or /store.
  4. $client= new SoapClient('http://www.store.com/index.php/api/soap/?wsdl');
  5.  
  6. // Can be added in Magento-Admin -> Web Services with role set to admin
  7.  
  8. $sess_id= $client->login('USER', 'PASSKEY');
  9.  
  10. // Also login via mySQL for what cannot be done with SOAP - shop is your db name
  11.  
  12. $res = mysql_pconnect('localhost', 'shop', 'DB_PASSWORD_MYSQL');
  13. mysql_select_db('shop');
  14.  
  15. // Get the product list through SOAP
  16. $all_products=$client->call($sess_id, 'product.list');
  17.  
  18. // Go for configurable parents with no simple children
  19.  
  20. foreach($all_products as $product)
  21. { // var_dump($product);
  22.   if ($product['type']=="configurable")
  23.   { $sql = mysql_query('select * from catalog_product_super_link where parent_id='.$product['product_id']);
  24.     if (mysql_num_rows($sql)==0)
  25.     { $empties++;
  26.       echo $product['sku']."t".$product['name']."n";
  27.     }
  28.   }
  29. }
  30. echo "n".$empties." configurable products lacking simple children.nn";
  31. ?>

Clearly the code can be changed to identify ‘orphaned’ configurables, i.e. the products that are configurable but only have one option left for sale. With these you get a silly drop-down for size/colour. It may be better to make these products as ‘simple’ if they are end of range and in need of promotion.




 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs