Kuna toodete import magento süsteemi on väga aeglane siis abiks on Magmi. Selle abil on võimalik näiteks kogu andmebaas (üle 20000 toote) vaid 10 sekundiga.
Enne alljärgneva koodi kasutamist on vaja seadistada ka Magmi.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | // setup include PATH's $in=array(); $in[]= PATH . 'magmi'; $in[]= PATH . 'magmi/inc'; $in[]= PATH . 'magmi/integration/inc'; $in[]= PATH . 'magmi/engines'; $inpath=""; foreach ($in as $i){ $inpath .= $i .':'; } $inpath .= '.'; set_include_path($inpath); // end include PATH's require_once("magmi_datapump.php"); // call Datapump $dp=Magmi_DataPumpFactory::getDataPumpInstance("productimport"); $dp->beginImportSession("default","create"); // default- name of profile , create - we want to create and update items $file='/var/www/import/web/catalog/microline.xml'; // absolute path $microline = new SimpleXMLElement($file, null, true); // load XML foreach ($microline->item as $item){ $newProductData = array( 'name' => (string)$item->name, // name 'sku' => (string)$item->key, // sku 'special_price' => ((real)$item->priceWithDiscount), // special price 'price' => ((real)$item->priceWithDiscount * 1.09), // price 'attribute_set' => 'Microline', // attribute_set 'store' => 'admin', 'description' => (string)$item->description, // full description 'short_description' => (string)$item->sdescription, // short description 'qty' => (string) $item->freeOnStock, // qty 'category_ids' => '2,15,87', // ID of categories 'weight' => (string) $item->mass, // weight 'tax_class_id' => '2', // tax class id (check your ids) 'manufacturer' => (string) $item->tradeMark, // manufacturer 'meta_title' => (string) $item->name, // meta title 'meta_description' => (string)$item->description, // meta description 'meta_keyword' => (string)$item->description // meta keywords ); $newProductData['image']='+'.(string)$item->pictureURLHighResolution; // + show picture, - dont show picture $newProductData['small_image']='+'.(string)$item->pictureURL; // small img $newProductData['thumbnail']='+'.(string)$item->pictureURL; // thumbnail $dp->ingest($newProductData); echo '' . ' mem:'.memory_get_usage() . " ... Done! <br />\n"; //memory usage check $newProductData=null; //clear memory unset($newProductData); //clear memory } unset($microline); $dp->endImportSession(); // end import exec("php -f /var/www/import/web/shell/indexer.php reindexall"); - |