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)"); }
public function download_feeds() { global $logger; return true; $filetxt = FEED_PATH . "synnex.csv"; $file2 = FEED_PATH . "/feedssynnex.csv.txt.zip"; $fdiff = (date("U") - @filemtime($filetxt)) / 3600; if ($fdiff > 4) { $zip = new ZipArchive(); $res = $zip->open($file2); if ($res === TRUE) { $zip->extractTo(FEED_PATH . "/"); $zip->close(); } else { echo "error during unzip process"; } } return true; $cont = file_get_contents(""); file_put_contents($file, $cont); $logger->LogCron("DATAFEED DOWNLOADED (" . ImpLib::convert(filesize($file)) . ")"); $zip = new ZipArchive(); $res = $zip->open($file); if ($res === TRUE) { $zip->extractTo(FEED_PATH . "/" . $this->name . "/"); $zip->close(); } else { echo "error during unzip process"; } return true; }
// select count(sku) as cnt, sku from import_icecat group by sku having cnt>2 ORDER BY cnt if (true) { $logger->LogCron("ICECAT START | DOWNLOAD | mem=" . ini_get("memory_limit") . ", max_execution_time=" . ini_get("max_execution_time") . "s"); $store_items = IceCat::IceCat_GetStoreItems(); IceCat::downloadIceCatFiles($store_items, $lang_dir); $logger->LogCron("ICECAT END | usage:" . ImpLib::convert(memory_get_usage(true)) . " peak: " . ImpLib::convert(memory_get_peak_usage(true))); $logger->LogCron("----------------------------------------------------------------------------------"); // header("Location: http://smartbuy.nz/shop/ib2b/?IMNZ-ice"); exit; } if (true) { $logger->LogCron("ICECAT START | UPDATE | mem=" . ini_get("memory_limit") . ", max_execution_time=" . ini_get("max_execution_time") . "s"); // die("sss"); $store_items = IceCat::IceCat_GetStoreItems(); // echo count($store_items);exit ; IceCat::updateIceCatItems($store_items, $lang_dir); $logger->LogCron("ICECAT END | usage:" . ImpLib::convert(memory_get_usage(true)) . " peak: " . ImpLib::convert(memory_get_peak_usage(true))); $logger->LogCron("----------------------------------------------------------------------------------"); // header("Location: http://smartbuy.nz/shop/ib2b/?IMNZ-ice"); exit; // echo "s"; exit; } die("IceCat done."); } if ($do == "orders") { echo '<link rel="stylesheet" media="screen" href="assets/order2.css">'; $order_ids = $b2b->getAllOrdersByStatus(); echo "<h2>Orders</h2><ul>"; foreach ($order_ids as $order) { $b2b->sendOrder($order); exit; $customer_order_id = "TSS_" . $order->get_order_number(); if ($customer_order_id == "TSS_770409") {
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 function slugifyManufacturers() { global $db; foreach ($db->query("SELECT * FROM " . _DB_PREFIX_ . "manufacturer") as $row) { $fff = ImpLib::tourl($row['name']); $db->query("DELETE FROM oc_url_alias WHERE query='manufacturer_id={$row['manufacturer_id']}'"); $db->query("INSERT INTO oc_url_alias SET query='manufacturer_id={$row['manufacturer_id']}', keyword ='{$fff}'"); } }
$categories = @array_unique($categories); foreach ($categories as $category_oc_id) { $db->query("INSERT INTO import_category_settings (feed_category_id, store_category_id, supplier_id) VALUES ('{$category_feed_id}', '{$category_oc_id}', '{$supplier}')"); } } else { $db->query("INSERT INTO import_category_settings (feed_category_id, store_category_id, supplier_id) VALUES ('{$category_feed_id}', '{$category_oc_id}', '{$supplier}')"); } echo "ok"; } if ($to_do == "ADD_NEW_CATEGORY") { $newcatname = explode(" > ", mysql_real_escape_string($_REQUEST['newcatname'])); $newcatid = mysql_real_escape_string($_REQUEST['newcatid']); $lvl = 0; $id_parent = ID_CATEGORY_ROOT; foreach ($newcatname as $catname) { $s = ImpLib::gt(); $store_category_id = $b2b->getCategory($catname, $id_parent); // echo "$catname=>$store_category_id t=".ImpLib::grt($s)."\n"; // echo "before : $catname, par=$id_parent, lvl=$lvl = $store_category_id \n"; // exit; if (!$store_category_id) { $id_cat_new = $b2b->createCategory($catname, $id_parent, $lvl); //echo $catname . " par=$id_parent => $id_cat_new \n"; $store_category_id = $id_cat_new; $id_parent = $id_cat_new; } else { $id_parent = $store_category_id; // for next iteration } $lvl++; }
public static function tourl2($str) { $str = ImpLib::utf2ascii($str); $str = preg_replace("~[^\\w\\d]+~", '_', strtolower($str)); $str = trim($str, "-"); $str = preg_replace('~[^-\\w\\d]+~', '', $str); return $str; }
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 timer($step) { // dump($this->timer_tmp); // echo $this->timer_tmp + $step ; // exit; if (date("U") > $this->timer_tmp + $step) { $this->LogCron(" ping {$step}s | total=" . round($this->timer_start - date("U")) . "s | MEM: " . ImpLib::convert(memory_get_usage(true)) . " | Peak: " . ImpLib::convert(memory_get_peak_usage(true))); $this->timer_tmp = date("U"); } }
public function createCategory($newcatname, $parent_id, $lvl) { global $db; $newcatname = addslashes($newcatname); // echo $newcatname . " => $parent_id \n";exit; $top = $lvl == 1 ? 1 : 0; $rewrite = ImpLib::tourl($newcatname); $db->query("INSERT INTO " . _DB_PREFIX_ . "terms (name, `slug`) VALUES ('{$newcatname}', '{$rewrite}')"); $term_id = mysql_insert_id(); $db->query("INSERT INTO " . _DB_PREFIX_ . "term_taxonomy (term_id, `taxonomy`, parent) VALUES ('{$term_id}', 'product_cat', {$parent_id})"); $category_id = mysql_insert_id(); return $category_id; }