Я хотел бы сопоставить категории xml с моими пурпурными категориями.
Я собрал сценарий импорта, который работает, но он не импортирует ни в какие категории в magento.
В сценарии im testting я хотел бы импортировать продукт, который имеет в xml
<izdelekKategorija>Komponente</izdelekKategorija>
в пурпурный номер 738.
Im, просящий некоторую помощь Im начинающий в PHP.
Спасибо.
<?php $kat = array( 'Komponente' => '738', ); class TestLogger { /** * logging methos * * @param string $data * : log content * @param string $type * : log type */ public function log($data, $type) { echo "$type:$data\n"; } } // setup include PATH's set_include_path('magmi' . PATH_SEPARATOR . 'magmi/inc' . PATH_SEPARATOR . 'magmi/integration/inc' . PATH_SEPARATOR . 'magmi/engines'); // end include PATH's require_once("magmi_datapump.php"); // call Datapump $dp=Magmi_DataPumpFactory::getDataPumpInstance("productimport"); $dp->beginImportSession("123", "create", new TestLogger()); // default- name of profile , create - we want to create and update items $file="test.xml"; $microline = new SimpleXMLElement($file, null, true); // load XML $izdelek = array ((string)$item->izdelekKategorija); global $kat; $izdelek = array ((string)$item->izdelekKategorija); $kategorija = (isset($kat[$izdelek]) ? $kat[$izdelek] : $kategorija); foreach ($microline as $item){ $newProductData = array( "sku" => (string)$item->izdelekID .=' inbbt', "name" => (string)$item->izdelekIme, // name "attribute_set" => "test", // attribute_set "store" => "test", "category_ids" => $kategorija, "tax_class_id" => "3", ); $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 ?>
с<?php $kat = array( 'Komponente' => '738', ); class TestLogger { /** * logging methos * * @param string $data * : log content * @param string $type * : log type */ public function log($data, $type) { echo "$type:$data\n"; } } // setup include PATH's set_include_path('magmi' . PATH_SEPARATOR . 'magmi/inc' . PATH_SEPARATOR . 'magmi/integration/inc' . PATH_SEPARATOR . 'magmi/engines'); // end include PATH's require_once("magmi_datapump.php"); // call Datapump $dp=Magmi_DataPumpFactory::getDataPumpInstance("productimport"); $dp->beginImportSession("123", "create", new TestLogger()); // default- name of profile , create - we want to create and update items $file="test.xml"; $microline = new SimpleXMLElement($file, null, true); // load XML $izdelek = array ((string)$item->izdelekKategorija); global $kat; $izdelek = array ((string)$item->izdelekKategorija); $kategorija = (isset($kat[$izdelek]) ? $kat[$izdelek] : $kategorija); foreach ($microline as $item){ $newProductData = array( "sku" => (string)$item->izdelekID .=' inbbt', "name" => (string)$item->izdelekIme, // name "attribute_set" => "test", // attribute_set "store" => "test", "category_ids" => $kategorija, "tax_class_id" => "3", ); $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 ?>
с<?php $kat = array( 'Komponente' => '738', ); class TestLogger { /** * logging methos * * @param string $data * : log content * @param string $type * : log type */ public function log($data, $type) { echo "$type:$data\n"; } } // setup include PATH's set_include_path('magmi' . PATH_SEPARATOR . 'magmi/inc' . PATH_SEPARATOR . 'magmi/integration/inc' . PATH_SEPARATOR . 'magmi/engines'); // end include PATH's require_once("magmi_datapump.php"); // call Datapump $dp=Magmi_DataPumpFactory::getDataPumpInstance("productimport"); $dp->beginImportSession("123", "create", new TestLogger()); // default- name of profile , create - we want to create and update items $file="test.xml"; $microline = new SimpleXMLElement($file, null, true); // load XML $izdelek = array ((string)$item->izdelekKategorija); global $kat; $izdelek = array ((string)$item->izdelekKategorija); $kategorija = (isset($kat[$izdelek]) ? $kat[$izdelek] : $kategorija); foreach ($microline as $item){ $newProductData = array( "sku" => (string)$item->izdelekID .=' inbbt', "name" => (string)$item->izdelekIme, // name "attribute_set" => "test", // attribute_set "store" => "test", "category_ids" => $kategorija, "tax_class_id" => "3", ); $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 ?>
Редактировать: мне удалось запустить скрипт, и он импортирует ok, но он не импортирует изображения из url …
Новый рабочий код:
<?php $spisekKategorij = array( 'Komponente' => '738', 'Prenosniki' => '742', 'Monitorji' => '737', ); class TestLogger { /** * logging methos * * @param string $data * : log content * @param string $type * : log type */ public function log($data, $type) { echo "$type:$data\n"; } } // setup include PATH's set_include_path('magmi' . PATH_SEPARATOR . 'magmi/inc' . PATH_SEPARATOR . 'magmi/integration/inc' . PATH_SEPARATOR . 'magmi/engines'); // end include PATH's require_once("magmi_datapump.php"); // call Datapump $dp=Magmi_DataPumpFactory::getDataPumpInstance("productimport"); $dp->beginImportSession("123", "create"); // default- name of profile , create - we want to create and update items $file="test.xml"; $microline = new SimpleXMLElement($file, null, true); // load XML // $kategorija = $izdelek; // $kategorija = (isset($spisekKategorij[$izdelek]) ? $spisekKategorij[$izdelek] : $kategorija); foreach ($microline as $item){ $izdelek = ((string)$item->izdelekKategorija); $kategorija = (($spisekKategorij[$izdelek]) ? $spisekKategorij[$izdelek] : $kategorija); $newProductData = array( "sku" => (string)$item->izdelekID .=' abbt', "name" => (string)$item->izdelekIme, 'price' => ((real)$item->cenaBrezddv), 'description' => (string)$item->izdelekOpis . (string)$item->izdelekDodatenOpis, 'short_description' => (string)$item->izdelekDodatenOpis, 'diagonala_rshop' => (string)$item->velikost_zaslona, 'procesor_rshop' => (string)$item->procesor, 'ram_rshop' => (string)$item->ram, 'hdd_rshop' => (string)$item->disk, 'operacijski_rshop' => (string)$item->licencna_nalepka, 'locljivost_rshop' => (string)$item->locljivost, 'grafika_rshop' => (string)$item->grafika, "attribute_set" => "test", "store" => "rshop", "category_ids" => $kategorija, ); $newProductData["image"]='+'.(string)$item->slike->slika1; // + show picture, - dont show picture $newProductData['small_image']='+'.(string)$item->slike->slika1; // small img $newProductData['thumbnail']='+'.(string)$item->slike->slika1; echo $izdelek; echo $kategorija; echo $slika; echo '<pre>'; print_r($newProductData); echo '</pre>'; $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 ?>
с<?php $spisekKategorij = array( 'Komponente' => '738', 'Prenosniki' => '742', 'Monitorji' => '737', ); class TestLogger { /** * logging methos * * @param string $data * : log content * @param string $type * : log type */ public function log($data, $type) { echo "$type:$data\n"; } } // setup include PATH's set_include_path('magmi' . PATH_SEPARATOR . 'magmi/inc' . PATH_SEPARATOR . 'magmi/integration/inc' . PATH_SEPARATOR . 'magmi/engines'); // end include PATH's require_once("magmi_datapump.php"); // call Datapump $dp=Magmi_DataPumpFactory::getDataPumpInstance("productimport"); $dp->beginImportSession("123", "create"); // default- name of profile , create - we want to create and update items $file="test.xml"; $microline = new SimpleXMLElement($file, null, true); // load XML // $kategorija = $izdelek; // $kategorija = (isset($spisekKategorij[$izdelek]) ? $spisekKategorij[$izdelek] : $kategorija); foreach ($microline as $item){ $izdelek = ((string)$item->izdelekKategorija); $kategorija = (($spisekKategorij[$izdelek]) ? $spisekKategorij[$izdelek] : $kategorija); $newProductData = array( "sku" => (string)$item->izdelekID .=' abbt', "name" => (string)$item->izdelekIme, 'price' => ((real)$item->cenaBrezddv), 'description' => (string)$item->izdelekOpis . (string)$item->izdelekDodatenOpis, 'short_description' => (string)$item->izdelekDodatenOpis, 'diagonala_rshop' => (string)$item->velikost_zaslona, 'procesor_rshop' => (string)$item->procesor, 'ram_rshop' => (string)$item->ram, 'hdd_rshop' => (string)$item->disk, 'operacijski_rshop' => (string)$item->licencna_nalepka, 'locljivost_rshop' => (string)$item->locljivost, 'grafika_rshop' => (string)$item->grafika, "attribute_set" => "test", "store" => "rshop", "category_ids" => $kategorija, ); $newProductData["image"]='+'.(string)$item->slike->slika1; // + show picture, - dont show picture $newProductData['small_image']='+'.(string)$item->slike->slika1; // small img $newProductData['thumbnail']='+'.(string)$item->slike->slika1; echo $izdelek; echo $kategorija; echo $slika; echo '<pre>'; print_r($newProductData); echo '</pre>'; $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 ?>
с<?php $spisekKategorij = array( 'Komponente' => '738', 'Prenosniki' => '742', 'Monitorji' => '737', ); class TestLogger { /** * logging methos * * @param string $data * : log content * @param string $type * : log type */ public function log($data, $type) { echo "$type:$data\n"; } } // setup include PATH's set_include_path('magmi' . PATH_SEPARATOR . 'magmi/inc' . PATH_SEPARATOR . 'magmi/integration/inc' . PATH_SEPARATOR . 'magmi/engines'); // end include PATH's require_once("magmi_datapump.php"); // call Datapump $dp=Magmi_DataPumpFactory::getDataPumpInstance("productimport"); $dp->beginImportSession("123", "create"); // default- name of profile , create - we want to create and update items $file="test.xml"; $microline = new SimpleXMLElement($file, null, true); // load XML // $kategorija = $izdelek; // $kategorija = (isset($spisekKategorij[$izdelek]) ? $spisekKategorij[$izdelek] : $kategorija); foreach ($microline as $item){ $izdelek = ((string)$item->izdelekKategorija); $kategorija = (($spisekKategorij[$izdelek]) ? $spisekKategorij[$izdelek] : $kategorija); $newProductData = array( "sku" => (string)$item->izdelekID .=' abbt', "name" => (string)$item->izdelekIme, 'price' => ((real)$item->cenaBrezddv), 'description' => (string)$item->izdelekOpis . (string)$item->izdelekDodatenOpis, 'short_description' => (string)$item->izdelekDodatenOpis, 'diagonala_rshop' => (string)$item->velikost_zaslona, 'procesor_rshop' => (string)$item->procesor, 'ram_rshop' => (string)$item->ram, 'hdd_rshop' => (string)$item->disk, 'operacijski_rshop' => (string)$item->licencna_nalepka, 'locljivost_rshop' => (string)$item->locljivost, 'grafika_rshop' => (string)$item->grafika, "attribute_set" => "test", "store" => "rshop", "category_ids" => $kategorija, ); $newProductData["image"]='+'.(string)$item->slike->slika1; // + show picture, - dont show picture $newProductData['small_image']='+'.(string)$item->slike->slika1; // small img $newProductData['thumbnail']='+'.(string)$item->slike->slika1; echo $izdelek; echo $kategorija; echo $slika; echo '<pre>'; print_r($newProductData); echo '</pre>'; $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 ?>
Решение моего вопроса – переместить
$izdelek = ((string)$item->izdelekKategorija); $kategorija = (($spisekKategorij[$izdelek]) ? $spisekKategorij[$izdelek] : $kategorija);
в петлю foreach.