How to import configurable products from CSV File into Magento System

Unlikely the default Magento import module, this fully customizable bulk import module allows you to import configurable products through CSV feed.
Module features:

  • Import from CSV feed
  • Create CSV for import
  • Import configurable products and their associated simple products.
  • Import images / multiple images / gallery images from remote server.
  • Supports cron job
  • Copy the file Productwithconfigurablesandcategories.php located in
    Productwithconfigurablesandcategories.zip (file attached to this post) to the folder /app/code/core/Mage/Catalog/Model/Convert/Adapter/.

    < ?php
    
    require_once ('lib/magento_import.php');
    
    $import     =     new Magento_Import();
    /**
    * Set the essential Configuration
    */
    $import->setDefaultConfiguration();
    
    // Create MainFeed Table
    $import->createFeedTable("MainFeed"); 
    $import->readTheCsv("\t", "lib/your_catalog.csv" );
    $import->saveFeedToDatabase();
     ....
    
    ?>
    
    < ?php
    if(isset($_GET['cat_name']) != ""){
    $import->generateCsvFromDatabase($_GET['cat_name'],$_GET['cat_id']);
    }
    ?>
    
    

Import Class:


< ?php

/************************************************** 
* Ayasoftware.com: Copyright (c) 2010. All rights reserved.
* Author: EL Hassan Matar   support@Ayasoftware.com
* Project name: Import module for Magento.
* Updated  : 12 April 2010
***************************************************/

class Magento_Import  {

	public $SQL_HOTE = NULL;
	public $SQL_LOGIN = NULL;
	public $SQL_SECRET = NULL;
	public $SQL_BASE = NULL;
	public $tax_class_id= NULL; //
       
       ....... 
/**
     *  Check Whether the Given File is valid one or not
     *  @param NULL
     *  $return boolean
     */
	function isFileExists ($file_name)
	{
		$boolFileExists     =     false;
		if ( file_exists ( $file_name ) ) {
			$boolFileExists     =     true;
		}
		return $boolFileExists;
	}

	/**
     * Set a default configuration if user left blank
     * @param NULL
     * $return boolean
     */    
	function setDefaultConfiguration ()
	{
		$this->FeedPath ="your_catalogue.txt";
		$this->SQL_HOTE = "localhost";
		$this->SQL_LOGIN = "SQL_LOGIN";
		$this->SQL_SECRET = "SQL_SECRET";
		$this->SQL_BASE = "SQL_BASE";
		$this->tax_class_id= "Taxable Goods"; //

		// API Configuration
		$this->APIUrl= "http://yourdomain.com/api/soap/?wsdl";
		$this->APIUser="Magento_API_User";
		$this->APIKey= "Magento_API_Key";
		$this->MediaPath= "/home/XXXX/yourdomain.com/html/media/import/";
		$this->size_attribut = "size_letter";
		$this->attribut_set  = "Apparel";
		$this->MySQL_Connect();

		$boolSetConfig     =     false;
		/**
	      * Change your file delimiter here
	    */
		if ( NULL == $this->fileDelimiter ) {
			$this->fileDelimiter     =     "\t";
		}

		/**
	      * Change your import  file path here
	    */
		if ( NULL == $this->importFilePath ) {

			$this->importFilePath     =     "/home/XXXX/yourdomain.com/html/var/import/productsFeed.csv";
		}

	}

	
/**
	 * Will generate import file from database...
	 * @param String $category_name
	 * @param String $category_id
	 * @return boolean
	 */
function generateCsvFromDatabase($category_name,$category_id){
		$fileName = $this->importFilePath;
		if ( file_exists( $fileName ) )
		unlink( $fileName );		
		$sql ="SELECT * FROM $category_name" ;
		$resultat=mysql_query($sql) or die("SQL Error". $sql. " ".mysql_error());
		$fh = fopen($fileName, 'w') or die("can't open file ");
		$header = '"websites","type","msrp","special_price","gender","attribute_set","tax_class_id","weight","name","'.$this->size_attribut.'","color","sku","manufacturer","price","description","meta_description","meta_keyword","short_description","url_key","category_ids","image","small_image","thumbnail","has_options","visibility","required_options","is_in_stock","qty","status","associated","config_attributes","backorder_date","on_sale"'."\n";
		fwrite($fh, $header);
//simple product 
/**	$csvBlock= $csvBlock.'"base","simple","'.$msrp.'","'.$special_price.'",,"'.$this->attribut_set.'","Taxable Goods","0","'.$product_name." ".$color." ".$size.'","'.$size.'","'.$color.'","'.$row['SKU'].'","'.$row['MANUFACTURER'].'","'.$row['STORE_PRICE'].'","'.$row['DESCRIPTION'].'",,,,"'.$row['DESCRIPTION'].'",,,,,"1","Nowhere","0","1","'.$inventory.'","Enabled",,,,"'.$sale.'"'."\n";	
*/
// configurable product
/**
$csvBlock= $csvBlock.'"base","configurable","'.$msrp.'","'.$special_price.'","'.$gender.'","'.$this->attribut_set.'","Taxable Goods","0","'.$product_name.'",,,"'.$sku.'","'.$manufacturer.'","'.$price.'","-","'.$description.'","'.$meta_keyword.'","'.$description.'","'.$configurl.'","'.$category_id.'","'.$imageName1.'","'.$imageName1.'","'.$imageName1.'","1","Catalog, Search","1","1","10","Enabled", "'.$skus.'","color,'.$this->size_attribut.'",,"'.$sale.'"';
	
*/
		
		while ($row  = mysql_fetch_array($resultat)) {
			//Get type from database
			$row= $this->retrieveAssociatedItems($row['CONFIG_TITLE'],$category_id);
			if( $row != ""){
				fwrite($fh,$row."\n");
			}
		}
		fclose($fh);
		return true;
	}

	
/**
	 * Copy Images from Remote Server
	 * @param String $imageURL
	 * @param String $imageName
	 * @return boolean
	 */

function copyImagesFromRemoteServer($imageURL,$imageName){
		if(copy($imageURL, $this->MediaPath.$this->removeSpecialCharacterFromName($imageName).'.jpeg')){
			return true;
		}

	}
?>

Go to Admin->System->Advanced Profiles and create a new profile with the following information:
Profile Name * : Productwithconfigurablesandcategories
Actions XML * : Paste the XML code attached to this post (import_xml.txt)
and click on Run profile to start importing your products.

AttachmentSize
your_catalogue.xls13.5 KB
Productwithconfigurablesandcategories.zip3.5 KB
import_xml.txt737 bytes