Zdravím,
mám takový problém se kterým si delší dobu nevím rady jelikož xml není moje silná stránka.
Máme xml import dat které získáváme od velkoobchodníka a díky tomu pak data přenášíme do naší databáze ale potřeboval bych pomoci s tím že do importu chceme přidat i EAN který jsem si tam dal ale tento EAN se nahraje pouze u nových produktů ale u těch starých mi to již nedohraje EAN a proto bych se chtěl zeptat zda-li by byl někdo tak ochotný a pomohl mi s tím aby mi to fungovalo jak má.
Přikládám kód který dělá import dat do db
/**
*
* @param type $xml
*/
public function zpracujXmlZbozi($xml) {
$poleLevel1 = [
'Míčové a společenské sporty' => 2,
'Fitness a posilovna' => 2,
'Vodní sporty' => 2,
'Skating' => 2,
'Bojové sporty' => 2,
'Tenis a badminton' => 2,
'Outdoor' => 3,
'Sport. obuv a nazouváky' => 4,
'Termoprádlo' => 4,
'Funkční oblečení' => 4
];
$order = $this->dibi->query("SELECT max(eshop_catalog.order) AS orders FROM [eshop_catalog]")->fetchSingle() + 1;
foreach ($xml->StoItem as $item) {
$idKat = $this->dibi->query(sprintf("SELECT itemid FROM [eshop_catalog_variants] WHERE [catno] = '%s' LIMIT 1", $item->Code))->fetchSingle();
$nazev = $idKat ? $this->dibi->query(sprintf("SELECT name FROM [eshop_catalog] WHERE [id] = %s LIMIT 1", $idKat))->fetchSingle() : false;
if (!$nazev) {
$this->log($item->Id . ': ' . $item->Name);
if ($item->SisName == 'Výprodej')
$action = 1;
if ($item->SisName == 'Novinka')
$news = 1;
$dataCatalog = [
'imp_id' => intval($item->Id),
'imp_idgroup' => NULL,
'idlang' => 1,
'idlang_group' => 0,
'name' => (string) $item->Name,
'shortname' => (string) $item->Name,
'url' => $this->webalize($item->Name),
'addpageid' => 0,
'addmagazin' => '',
'exturl' => NULL,
'ptitle' => (string) $item->Name,
'pdescription' => (string) $item->Note,
'pkeywords' => '',
'shortdescription' => '',
'description' => (string) $item->Note,
'varranty' => '24 měsíců',
'vatflag' => 0,
'idmanufacturer' => NULL,
'iddistributor' => NULL,
'topsales' => 0,
'index' => 0,
'index_ladies' => 0,
'action' => $action,
'sleva' => 0,
'news' => $news,
'megaaction' => 0,
'megaaction_ladies' => 0,
'deleted' => 0,
'idpdprofile' => NULL,
'idfile' => NULL, //ssss
'idmegaactionfile' => NULL,
'idmegaactionfile_ladies' => NULL,
'idgal' => NULL,
'v_simple' => 1,
'v_simpleid' => NULL,
'currency' => 'CZK',
'unit' => '',
'similaritempriceflag' => 1,
'similaritemprice' => 0,
'order' => $order++,
'orderindex' => 0,
'user_note' => '',
'url_import' => '',
'color_import' => '',
'id_import' => 0,
'tempish_id' => '',
'men' => 0,
'women' => 0,
'children' => 0,
'micro_kolobezky_code' => NULL,
'prima_outdoor_code' => NULL,
'aspire_code' => NULL,
'salming_code' => NULL,
'floorballplayer_code' => NULL,
'yate_code' => NULL,
'brand' => 1,
'updated' => date('Y-m-d H:i:s'),
'offdate' => '0000-00-00 00:00:00',
'ondate' => '0000-00-00 00:00:00',
'import_active' => 1,
'taxbox' => -1
];
$this->dibi->query('INSERT INTO [eshop_catalog]', $dataCatalog);
$lastId = $this->dibi->getInsertId();
/* cena */
$dataPrice = [
'itemid' => $lastId,
'imp_idgroup' => NULL,
'params' => '',
'catno' => (string) ($item->Code),
'partno' => '',
'ean' => (string) ($item->PartNo),
'purchaseprice' => intval($item->PriceDea),
'commonprice' => 0,
'pcvflag' => 45,
'price' => intval($item->PriceEU),
'availability' => 3,
'simple' => 1,
'order' => 0,
'deleted' => 0,
'usestorecount' => 0,
'storecount' => 0,
'minordercount' => 0,
'supplier_stock' => 0,
'OznX1' => '',
'PozY1' => '',
'supplier_taken' => 0
];
$this->dibi->query('INSERT INTO [eshop_catalog_variants]', $dataPrice);
/* katerogie */
$prevKatID = NULL;
foreach (['Level1', 'Level2', 'Level3'] AS $_level) {
$tmp = explode(' ', $item->SPresentTree->{$_level});
unset($tmp[0]);
$level = implode(' ', $tmp);
if (is_null($prevKatID)) {
$kategorieId = $this->dibi->query(sprintf('SELECT id FROM [eshop_category] WHERE [parentid] IN (2,3,4) AND [name] = "%s" LIMIT 1', $prevKatID, $level))->fetchSingle();
} else {
$kategorieId = $this->dibi->query(sprintf('SELECT id FROM [eshop_category] WHERE [parentid] = %s AND [name] = "%s" LIMIT 1', $prevKatID, $level))->fetchSingle();
}
if ($kategorieId) {
$prevKatID = $kategorieId;
$dataKat = [
'iditem' => $lastId,
'idcat' => $kategorieId,
'topsales' => 0
];
$this->dibi->query('INSERT INTO [eshop_catalog_bindcat]', $dataKat);
}
}
/* obrazky */
$dataKat = [
'imp_idgroup' => NULL,
'name' => '',
'description' => '',
'file' => '',
'extfile' => NULL,
'ext' => 0,
'type' => 1,
'order' => 0,
'owner_group' => NULL,
'idgal' => NULL,
'watermark' => 0,
'deleted' => 0,
'upload_date' => date('Y-m-d H:i:s')
];
$this->dibi->query('INSERT INTO [files]', $dataKat);
$idFotky = $this->dibi->getInsertId();
/* obrazky */
if (!file_exists($this->slozka . $lastId . '/' . $idFotky . '/'))
mkdir($this->slozka . $lastId . '/' . $idFotky . '/', 0777, true);
if ($item->ImgUrl)
copy($item->ImgUrl, $this->slozka . $lastId . '/' . $idFotky . '/' . $this->webalize($item->Name) . '.jpg');
$this->dibi->query('UPDATE [eshop_catalog] SET idfile = ' . $idFotky . ' WHERE id = ' . $lastId);
$this->dibi->query('UPDATE [files] SET file = "' . ($this->slozkaDb . $lastId . '/' . $idFotky . '/' . $this->webalize($item->Name) . '.jpg') . '" WHERE id = ' . $idFotky);
} else {
$lastId = $this->dibi->query(sprintf("SELECT id FROM [eshop_catalog] WHERE [id] = %s LIMIT 1", $idKat))->fetchSingle();
$prevKatID = NULL;
foreach (['Level1', 'Level2', 'Level3'] AS $_level) {
$tmp = explode(' ', $item->SPresentTree->{$_level});
unset($tmp[0]);
$level = implode(' ', $tmp);
if ($level) {
if (is_null($prevKatID)) {
$kategorieId = $this->dibi->query(sprintf('SELECT id FROM [eshop_category] WHERE [parentid] IN (2,3,4) AND [name] = "%s" LIMIT 1', $level))->fetchSingle();
} else {
$kategorieId = $this->dibi->query(sprintf('SELECT id FROM [eshop_category] WHERE [parentid] = %s AND [name] = "%s" LIMIT 1', $prevKatID, $level))->fetchSingle();
}
if ($kategorieId) {
$prevKatID = $kategorieId;
$bindCat = $this->dibi->query(sprintf("SELECT iditem FROM [eshop_catalog_bindcat] WHERE [iditem] = %s AND [idcat] = %s LIMIT 1", $lastId, $kategorieId))->fetchSingle();
if (!$bindCat) {
$dataKat = [
'iditem' => $lastId,
'idcat' => $kategorieId,
'topsales' => 0
];
$this->dibi->query('INSERT INTO [eshop_catalog_bindcat]', $dataKat);
}
}
}
}
$action = $news = 0;
if ($item->SisName == 'Výprodej')
$action = 1;
if ($item->SisName == 'Novinka')
$news = 1;
$this->dibi->query(sprintf('UPDATE [eshop_catalog] SET action = %s, news = %s WHERE id = %s', $action, $news, $lastId));
}
}
}
Díky všem
S pozdravem
jAk3r