deivisonarthur
5/23/2013 - 4:16 PM

import.php

<?php
require_once("magmi/inc/magmi_defs.php");
 require_once("magmi/integration/inc/magmi_datapump.php");
 

 /** Define a logger class that will receive all magmi logs **/
 class TestLogger
 {
   /**
 	 * logging methos
 	 * @param string $data : log content
 	 * @param string $type : log type
 	 */
 	public function log($data,$type)
 	{
 		echo "$type:$data\n";
 	}
 }



 /**
  * create a Product import Datapump using Magmi_DatapumpFactory
  */
 $dp=Magmi_DataPumpFactory::getDataPumpInstance("productimport");




 $dp->beginImportSession("default","create",new TestLogger());


 for($sku=0;$sku<=5;$sku++)
 {

    $item=array(
                  "store"=>"admin",
                  "type"=>"simple",
                  "sku"=>str_pad($sku,5,"0",STR_PAD_LEFT),
                  "name"=>"item".$sku,
                  //"short_description"=>"test".$sku,
                  //"description"=>"test".$sku,
                  //"cost"=>$cost,
                  "price"=>rand(1,500),
                  "min_qty"=>3,
                  "qty"=>"+7",
                  "status"=>1,
                  "visibility"=>1,
                  "weight"=>"0.400",
                  "tax_class_id"=>"Nenhum"
                  //"material"=>"Gelatinosa (Alphafilcon A),Gelatinosa (Etafilcon A),Gelatinosa (Hema - NVP - Glicerol)",
                  //"category_ids"=>"2,6,5",    //"category_ids"=>implode(",",array_unique($cat_list)),  "7,12,23"
                  //"manufacturer"=>"CibaVision"
              );


 	//color : radom c0/c10
 	$item["color"]="c".strval(rand(0, 10));

 	//now some fun, every 100 items, create some relations
 	if($sku>4)
 	{
 		//first, we'll remove all existing relations (upsell/cross sell / related)
        $subskus=array();
 		for($i=$sku-4;$i<$sku;$i++)
 		{
 			//related item sku
 			$subskus[]=str_pad($i,5,"0",STR_PAD_LEFT);
 		}


        $item=array(
                      "store"=>"admin",
                      "type"=>"configurable",
                      "sku"=>"teste",
                      "name"=>"teste".$sku,
                      "short_description"=>"test".$sku,
                      "description"=>"test".$sku,
                      "price"=>rand(1,500),
                      //"min_qty"=>3,
                      //"qty"=>"+7",
                      "status"=>1,
                      "visibility"=>4,
                      "weight"=>"0.400",
                      "tax_class_id"=>"Nenhum",
                      "configurable_attributes"=>"color",
                      "choice_pair_single"=>"Sim",
                      "material"=>"Gelatinosa (Alphafilcon A),Gelatinosa (Etafilcon A),Gelatinosa (Hema - NVP - Glicerol)",
                      //"xre_skus"=>"re::.*2$",
                      //"*re_skus"=>"re::.*1$",
                      "category_ids"=>"2,6,5",    //"category_ids"=>implode(",",array_unique($cat_list)),  "7,12,23"
                      "manufacturer"=>"CibaVision"
                  );





 	}

 	/* import current item */
 	$dp->ingest($item);
 }
 /* end import session, will run post import plugins */
 $dp->endImportSession();