public function update($products) { global $logger; global $db; $s = ImpLib::gt(); $i = $deitem = 0; $db->query('UPDATE imported SET processed = 0 WHERE supplier="' . $this->name . '"'); $db->query('SET autocommit = 0'); foreach ($products as $a) { $i++; // $logger->LogCron(" - $i => ".$a->sku); $this->update_article_base($a); $db->query('UPDATE imported SET processed = 1, date_update = NOW() WHERE store_product_id=' . $a->store_product_id); } $db->query('COMMIT'); $logger->LogCron(" - SYNCED ({$i} items), last=" . $a->sku . ", ID=" . $a->store_product_id . " (" . ImpLib::grt($s) . "s) "); if (true) { // deactivation $s = ImpLib::gt(); // $db->query('SET autocommit = 0'); foreach ($db->query("SELECT * FROM imported WHERE processed = 0 AND supplier='{$this->name}'") as $product) { $deitem++; $sql = "UPDATE " . _DB_PREFIX_ . "product SET status = 0, quantity = 0 WHERE product_id={$product['store_product_id']};"; $db->query($sql); } // $db->query('COMMIT'); if ($deitem > 0) { $last = " , last={$product['sku']}"; $logger->LogCron(" - DEACTIVATED {$deitem} items {$last} (" . ImpLib::grt($s) . "s) "); } } if (isset($this->settings['DISABLED_PRODUCTS'])) { foreach (explode(",", $this->settings['DISABLED_PRODUCTS']) as $dis) { $db->query("UPDATE " . _DB_PREFIX_ . "product SET status = 0, quantity = 0 WHERE model='" . trim($dis) . "';"); $logger->LogCron(" - Disabled => {$dis}"); } } $logger->LogCron(" - MEMORY | Usage:" . ImpLib::convert(memory_get_usage(true)) . " Peak: " . ImpLib::convert(memory_get_peak_usage(true))); $logger->LogCron("------------------------------------------------------------------"); return true; }
public static function automapCategory($newcatname_orig, $newcatid, $id_parent = ID_CATEGORY_ROOT) { global $db, $b2b, $logger; $lvl = 0; $s = ImpLib::gt(); $newcatname = explode(" > ", mysql_real_escape_string($newcatname_orig)); $newcatid = mysql_real_escape_string($newcatid); foreach ($newcatname as $catname) { $s = ImpLib::gt(); $store_category_id = $b2b->getCategory($catname, $id_parent, false); if (!$store_category_id) { $id_cat_new = $b2b->createCategory($catname, $id_parent, $lvl); $store_category_id = $id_cat_new; $id_parent = $id_cat_new; } else { $id_parent = $store_category_id; } $lvl++; } $db->query("DELETE FROM import_category_settings WHERE feed_category_id = '{$newcatid}' AND supplier_id='{$b2b->name}'"); $db->query("INSERT INTO import_category_settings (feed_category_id, store_category_id, supplier_id)\n\t VALUES ('{$newcatid}', '{$store_category_id}', '{$b2b->name}')"); $logger->LogCron(" - Automapped category [{$newcatname_orig}] => store_category_id={$store_category_id} (" . ImpLib::grt($s) . "s)"); }
if (true) { $s = ImpLib::gt(); $logger->LogCron(" - INSERT"); $products = $b2b->process_xml("FOR_INSERT"); $logger->LogCron(" - FEED PROCESSED => " . count($products) . " items (" . ImpLib::grt($s) . "s) "); if (count($products) > 0) { $b2b->insert($products); header("Location: " . IMPORT_BASE_URL . "ib2b/?" . $b2b->name); exit; } } if (true) { $s = ImpLib::gt(); $logger->LogCron(" - UPDATE"); $products = $b2b->process_xml("FOR_UPDATE"); $logger->LogCron(" - FEED PROCESSED => " . count($products) . " items (" . ImpLib::grt($s) . "s) "); $b2b->update($products); } $logger->LogCron("------------------------------------------------------------------"); echo "Sync done."; exit; } if ($do == "icecat") { //if (1) ImpLib::rrmdir(ICE_FEED_PATH); // echo getcwd(); if (false) { // echo exec("du -h --max-depth=2 ".PS_ABS_PATH."ib2b-feeds/"); // REMOVE ICECAT RECORDS BY ICECAT STATUS foreach (IceCat::getUpdatedIceCatItemsState("RESTRICTED ACCESS") as $store_product_id => $sku) { $db->query("DELETE FROM `import_icecat` WHERE store_product_id={$store_product_id}"); unlink(ICE_FEED_PATH . $lang_dir . "/" . implode('/', str_split($store_product_id)) . "/" . $store_product_id . ".gz");
public function counter($step) { $this->count_total++; $this->count_tmp++; if ($this->count_tmp >= $step) { $this->count_tmp = 0; $this->LogCron(" #{$this->count_total} | MEM: " . ImpLib::convert(memory_get_usage(true)) . " | Peak: " . ImpLib::convert(memory_get_peak_usage(true)) . " | time=" . ImpLib::grt($this->counter_start)); $this->counter_start = ImpLib::gt(); } }
public static function updateIceCatItems($products, $lang_dir) { global $b2b, $db, $logger; $s = ImpLib::gt(); $import_icecat = IceCat::getUpdatedIceCatItems(); $i = 0; $ttl = 0; // mysql_query('SET autocommit = 0') or die(mysql_error()); foreach ($products as $product) { if (@$import_icecat[$product['sku']]) { continue; } // uz je zpracovano $xmldir = implode('/', str_split((string) $product['store_product_id'])); $xmlOK = true; foreach (getImportedLangs() as $lang_dir => $id_lang) { $file = ICE_FEED_PATH . $lang_dir . "/" . $xmldir . "/" . $product['store_product_id'] . ".gz"; $logger->LogCron(" - processing {$file}"); if (!@filesize($file)) { @unlink($file); // for zero files $xmlOK = false; $logger->LogCron(" - {$product['sku']} incorrect size. skipped"); continue; } $gzdata = file_get_contents($file); $data = IceCat::gzdecode($gzdata); $logger->LogCron(" - {$product['sku']} product data loaded [lang={$lang_dir}]" . strlen($data)); list($article['id_icecat'][$lang_dir], $article['icecat_state'][$lang_dir], $article['icecat_specs'][$lang_dir]) = IceCat::getICEcatProductSpecsDetails($data); if ($article['icecat_state'] == "BAD XML FILE") { unlink($file); } $logger->LogCron(" - {$product['sku']} [{$lang_dir}] product data parsed."); } $logger->LogCron(" - {$product['sku']} product data parsed."); if (!$xmlOK) { $logger->LogCron(" - {$product['sku']} bad XML."); continue; } $logger->LogCron(" - {$product['sku']} to be continued ?"); $import_icecat_feature = ""; if ($xmlOK && $article['icecat_state'][$lang_dir] == "READY FOR IMPORT") { $i++; $logger->LogCron(" - {$product['sku']} updating... "); // dump($article);exit; $b2b->update_article_icecat($product, $article['icecat_specs'], @$import_icecat_feature); } else { $logger->LogCron(" - {$product['sku']} no." . print_R($article, true)); // $pu->DeactivateItem($product['store_product_id']); } $ttl++; // die("stopped"); foreach (getImportedLangs() as $lang_dir => $id_lang) { $db->query("INSERT INTO import_icecat (sku, ean_upc , part_number , icecat_state, date_add, shop_status,vendor_id, id_icecat, store_product_id, id_lang) VALUES (\r\n '{$product['sku']}','{$product['ean']}','{$product['supplier_sku']}','{$article['icecat_state'][$lang_dir]}', NOW(), 'UPDATED','{$product['manufacturer']}'\r\n ,'{$article['id_icecat'][$lang_dir]}', '" . $product['store_product_id'] . "', " . $id_lang . ")"); } // die("stopped"); $last = "ID=" . $product['store_product_id'] . " sku=" . $product['sku']; if ($i >= 20) { $db->query('COMMIT'); $logger->LogCron("ICECAT UPDATED: {$i}/{$ttl} items in " . ImpLib::grt($s) . "s (last => {$last})"); $logger->LogCron("ICECAT END | usage:" . ImpLib::convert(memory_get_usage(true)) . " peak: " . ImpLib::convert(memory_get_peak_usage(true))); $logger->LogCron("-------------------------------------------------------------------------------------"); exit; break; } // die("Stopped"); } if (@$last) { $logger->LogCron("ICECAT UPDATED: {$i}/{$ttl} items in " . ImpLib::grt($s) . "s (last => {$last})"); } else { $logger->LogCron("ICECAT UPDATED: 0/{$ttl} items"); } $db->query('COMMIT'); return $i; }
public function update($products) { global $logger, $db; $s = ImpLib::gt(); $i = $deitem = 0; $this->product_shipping_class = array(99999); foreach ($db->query("SELECT * FROM " . _DB_PREFIX_ . "term_taxonomy WHERE taxonomy = 'product_shipping_class'") as $product) { // not to delete $this->product_shipping_class[] = $product['term_taxonomy_id']; } if (false) { $this->update_manufacturer_logos($products); exit; } foreach ($db->query("SELECT sku FROM imported_images;") as $word) { $this->imported_images[$word['sku']] = true; } // dump($this->product_shipping_class); // $this->set_attributes_ids($products); // update $this->DONT_UPDATE_THE_PRICE = array_flip(explode("\n", @$this->settings['DONT_UPDATE_THE_PRICE'])); $db->query('UPDATE imported SET processed = 0'); $db->query('SET autocommit = 0'); $logger->counterReset(); foreach ($products as $a) { $i++; // echo "."; $this->update_article_base($a); $logger->counter(500); $db->query('UPDATE imported SET processed = 1, date_update = NOW() WHERE store_product_id=' . $a->store_product_id); } if ($this->counts) { foreach ($this->counts as $count => $cnt) { $db->query("UPDATE " . _DB_PREFIX_ . "term_taxonomy SET count='{$cnt}' WHERE term_taxonomy_id = {$count}"); } } $db->query('COMMIT'); $logger->LogCron(" - UPDATE | SYNCED ({$i} items), last=" . $a->sku . ", ID=" . $a->store_product_id . " (" . ImpLib::grt($s) . "s) "); //dump($this->counts); if (true) { // deactivation $s = ImpLib::gt(); $db->query('SET autocommit = 0'); $deitem = 0; foreach ($db->query("SELECT * FROM imported WHERE processed = 0") as $product) { $deitem++; $db->query("UPDATE " . _DB_PREFIX_ . "posts SET post_status='publish' WHERE ID={$product['store_product_id']}"); $this->updateMeta("_visibility", "visible", $product['store_product_id']); // visible $this->updateMeta("_stock_status", "outofstock", $product['store_product_id']); // instock $this->updateMeta("_stock", 0, $product['store_product_id']); /* $db->query("UPDATE "._DB_PREFIX_."posts SET post_status='draft' WHERE ID={$product['store_product_id']}"); $this->updateMeta("_visibility", "hidden", $product['store_product_id']); // visible $this->updateMeta("_stock_status", "outofstock", $product['store_product_id']); // instock */ } $db->query('COMMIT'); if ($deitem > 0) { $logger->LogCron(" - DEACTIVATED {$deitem} items, last={$product['sku']} (" . ImpLib::grt($s) . "s) "); } } return true; }