Magento Themes and Magento Extensions

How to import configurable products from CSV File into Magento System

Share

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/.

    01 < ?php
    02
    03 require_once ('lib/magento_import.php');
    04
    05 $import = new Magento_Import();
    06 /**
    07 * Set the essential Configuration
    08 */
    09 $import->setDefaultConfiguration();
    10
    11 // Create MainFeed Table
    12 $import->createFeedTable("MainFeed");
    13 $import->readTheCsv("\t", "lib/your_catalog.csv" );
    14 $import->saveFeedToDatabase();
    15 ....
    16
    17 ?>
    1 < ?php
    2 if(isset($_GET['cat_name']) != ""){
    3 $import->generateCsvFromDatabase($_GET['cat_name'],$_GET['cat_id']);
    4 }
    5 ?>

Import Class:

001 < ?php
002
003 /**************************************************
004 * Ayasoftware.com: Copyright (c) 2010. All rights reserved.
005 * Author: EL Hassan Matar   support@Ayasoftware.com
006 * Project name: Import module for Magento.
007 * Updated  : 12 April 2010
008 ***************************************************/
009
010 class Magento_Import  {
011
012 public $SQL_HOTE = NULL;
013 public $SQL_LOGIN = NULL;
014 public $SQL_SECRET = NULL;
015 public $SQL_BASE = NULL;
016 public $tax_class_id= NULL; //
017
018 .......
019 /**
020 *  Check Whether the Given File is valid one or not
021 *  @param NULL
022 *  $return boolean
023 */
024 function isFileExists ($file_name)
025 {
026 $boolFileExists =     false;
027 if ( file_exists ( $file_name ) ) {
028 $boolFileExists =     true;
029 }
030 return $boolFileExists;
031 }
032
033 /**
034 * Set a default configuration if user left blank
035 * @param NULL
036 * $return boolean
037 */
038 function setDefaultConfiguration ()
039 {
040 $this->FeedPath ="your_catalogue.txt";
041 $this->SQL_HOTE = "localhost";
042 $this->SQL_LOGIN = "SQL_LOGIN";
043 $this->SQL_SECRET = "SQL_SECRET";
044 $this->SQL_BASE = "SQL_BASE";
045 $this->tax_class_id= "Taxable Goods"; //
046
047 // API Configuration
048 $this->APIUrl= "http://yourdomain.com/api/soap/?wsdl";
049 $this->APIUser="Magento_API_User";
050 $this->APIKey= "Magento_API_Key";
051 $this->MediaPath= "/home/XXXX/yourdomain.com/html/media/import/";
052 $this->size_attribut = "size_letter";
053 $this->attribut_set  = "Apparel";
054 $this->MySQL_Connect();
055
056 $boolSetConfig =     false;
057 /**
058 * Change your file delimiter here
059 */
060 if ( NULL == $this->fileDelimiter ) {
061 $this->fileDelimiter     = "\t";
062 }
063
064 /**
065 * Change your import  file path here
066 */
067 if ( NULL == $this->importFilePath ) {
068
069 $this->importFilePath     = "/home/XXXX/yourdomain.com/html/var/import/productsFeed.csv";
070 }
071
072 }
073
074
075 /**
076 * Will generate import file from database...
077 * @param String $category_name
078 * @param String $category_id
079 * @return boolean
080 */
081 function generateCsvFromDatabase($category_name,$category_id){
082 $fileName = $this->importFilePath;
083 if ( file_exists( $fileName ) )
084 unlink( $fileName );
085 $sql ="SELECT * FROM $category_name" ;
086 $resultat=mysql_query($sql) or die("SQL Error". $sql. " ".mysql_error());
087 $fh = fopen($fileName, 'w') or die("can't open file ");
088 $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";
089 fwrite($fh, $header);
090 //simple product
091 /** $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";

092 */
093 // configurable product
094 /**
095 $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.'"';

096
097 */
098
099 while ($row = mysql_fetch_array($resultat)) {
100 //Get type from database
101 $row= $this->retrieveAssociatedItems($row['CONFIG_TITLE'],$category_id);
102 if( $row != ""){
103 fwrite($fh,$row."\n");
104 }
105 }
106 fclose($fh);
107 return true;
108 }
109
110
111 /**
112 * Copy Images from Remote Server
113 * @param String $imageURL
114 * @param String $imageName
115 * @return boolean
116 */
117
118 function copyImagesFromRemoteServer($imageURL,$imageName){
119 if(copy($imageURL, $this->MediaPath.$this->removeSpecialCharacterFromName($imageName).'.jpeg')){
120 return true;
121 }
122
123 }
124 ?>

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.

Leave a Reply

You must be logged in to post a comment.