Import products magento

This section is the part of the tutorial which explains how to import products magento. Please click here to find out the main tutorial.The data reads from the CSV and create the simple and configurable products accordingly.

The function importproducts() get the CSV data in the $arrResult array and based the options in $optionsarr it decides whether to create simple and configurable products.

  1. Import Simple Products – click here
  2. Import Configurable Products – click here
function importProducts($arrResult,  $options_arr, $dir, $new_cats,$discount_arr)
{

    $dummy_sku = 'PKSKU';
    $dummy_sku_counter = 0;
    $new_product_related = array();


    foreach ($arrResult as $import_product) {

        $migrated_categories = getMigratedCategory($import_product[2], $new_cats);

        if ($import_product[3] == '' || $import_product[3] == null) {
            $sku = $dummy_sku . $dummy_sku_counter++;
        } else {
            $sku = $import_product[3] . $dummy_sku_counter++;
        }

        if (strtolower($import_product[22]) == true) { //status
            $enabled = 1;
        } else {
            $enabled = 2;
        }
        if(isset($options_arr[$import_product[0]]))
        {
            $visible = Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE;
            $simple_products = array();

            foreach($options_arr[$import_product[0]] as $optionsArray) {
               $simple_products[] = saveSingleProducts($import_product,$sku,$enabled,$optionsArray,$visible,$migrated_categories,$dir);
            }
           
            $new_product_related[$import_product[0]] = saveConfigureProducts($import_product,$sku,$enabled,$migrated_categories, $simple_products,$discount_arr,$dir);
        }            
        else
        {
            $visible = Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH;
            $new_product_related[$import_product[0]] = saveSingleProduct($import_product,$sku,$enabled,$visible,$migrated_categories,$discount_arr,$dir);
        }
    }  
//        $related_id[] = array
        return  $new_product_related;
            
   
}

Share this Tutorial