// 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 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; }
public function savePicture($src_file, $products_id, $nazev, $position) { global $db, $logger; $appendix_number = $position == "0" ? "" : "-{$position}"; $src_file = str_replace(" ", "%20", $src_file); $src_file = str_replace(" ", "%20", $src_file); $dest = IMPORT_ABS_PATH . IMAGE_ABS_PATH; $src_file_temp = $dest . "temp{$products_id}.pix"; @file_put_contents($src_file_temp, @file_get_contents($src_file)); $image_dir = implode('/', str_split($products_id)) . "/"; @mkdir(IMPORT_ABS_PATH . IMAGE_ABS_PATH . $image_dir, 0777, true); $type = @end(explode(".", $src_file)); if (strpos($type, "jpg")) { imagejpeg(imagecreatefromjpeg($src_file_temp), $src_file_temp, 80); } if (strpos($type, "png")) { imagejpeg(imagecreatefrompng($src_file_temp), $src_file_temp, 80); } if (strpos($type, "gif")) { imagejpeg(imagecreatefromgif($src_file_temp), $src_file_temp, 80); } if (@filesize($src_file_temp) > 100) { copy($src_file_temp, IMPORT_ABS_PATH . IMAGE_ABS_PATH . $image_dir . $products_id . $appendix_number . ".jpg"); $dest_pix_file = IMPORT_ABS_PATH . IMAGE_ABS_PATH . "/" . $image_dir . $products_id . $appendix_number . ".jpg"; imageResize($src_file_temp, $dest_pix_file, 400, 400); $logger->LogCron(" - IMG inserted | ID={$products_id} | {$src_file}, {$position} | " . ImpLib::convert(filesize($dest_pix_file))); if ($position == "0") { $db->query("UPDATE " . _DB_PREFIX_ . "product SET image = '" . IMAGE_ABS_PATH_SHORT . $image_dir . "{$products_id}.jpg' WHERE product_id = {$products_id}"); $db->query("INSERT INTO " . _DB_PREFIX_ . "product_image (product_id, image, sort_order) VALUES ({$products_id},'" . IMAGE_ABS_PATH_SHORT . $image_dir . "{$products_id}" . $appendix_number . ".jpg','1')"); } else { $db->query("INSERT INTO " . _DB_PREFIX_ . "product_image (product_id, image, sort_order) VALUES ({$products_id},'" . IMAGE_ABS_PATH_SHORT . $image_dir . "{$products_id}" . $appendix_number . ".jpg','1')"); } } else { $logger->LogCron(" - NO IMG for {$nazev}, ID={$products_id} src={$src_file}"); } @unlink($src_file_temp); return true; }
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 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 save_picture_woo($src_file, $products_id, $nazev, $position) { global $db, $logger; $nazev = addslashes($nazev); $appendix_number = $position == "0" ? "" : "-{$position}"; $src_file = str_replace(" ", "%20", $src_file); $dest = IMPORT_ABS_PATH . WOO_IMG_DIR; $src_file_temp = $dest . "temp{$products_id}.pix"; @file_put_contents($src_file_temp, file_get_contents($src_file)); $image_dir = implode('/', str_split($products_id)); @mkdir(IMPORT_ABS_PATH . WOO_IMG_DIR . $image_dir, 0777, true); $type = @end(explode(".", $src_file)); if (strpos($type, "jpg")) { imagejpeg(imagecreatefromjpeg($src_file_temp), $src_file_temp, 80); } if (strpos($type, "png")) { imagejpeg(imagecreatefrompng($src_file_temp), $src_file_temp, 80); } if (strpos($type, "gif")) { imagejpeg(imagecreatefromgif($src_file_temp), $src_file_temp, 80); } $fname = $products_id . $appendix_number . ".jpg"; $dest_pix_file = IMPORT_ABS_PATH . WOO_IMG_DIR . $image_dir . $fname; $guid = IMPORT_BASE_URL . WOO_IMG_DIR . $image_dir . $fname; $admin_author = ""; $meta_data = ""; //echo "pix=$dest_pix_file | guid = $guid"; if (filesize($src_file_temp) > 100) { $db->query("INSERT INTO `" . _DB_PREFIX_ . "posts` (`post_author`, `post_date`, `post_date_gmt`,`post_content`, post_title, `post_excerpt`, `post_status`,\n\t comment_status, ping_status, post_name, post_modified, post_modified_gmt, post_parent , post_type, menu_order, post_mime_type, guid)\n\t VALUES\n\t ('{$admin_author}',NOW(),NOW(),'{$nazev}','{$nazev}','{$nazev}','inherit',\n\t 'open', 'closed', '" . ImpLib::tourl($nazev) . "', NOW(), NOW(), {$products_id}, 'attachment', 0, 'image/jpeg', '{$guid}')"); $img_id = mysql_insert_id(); $meta_data = 'a:5:{s:5:"width";i:3264;s:6:"height";i:2448;s:4:"file";s:20:"' . WOO_IMG_DIR_SHORT . $image_dir . $fname . '";s:5:"sizes";a:7:{ s:9:"thumbnail";a:4:{s:4:"file";s:20:"' . $fname . '-150x150.jpg";s:5:"width";i:150;s:6:"height";i:150;s:9:"mime-type";s:10:"image/jpeg";} s:6:"medium";a:4:{s:4:"file";s:20:"' . $fname . '-300x225.jpg";s:5:"width";i:300;s:6:"height";i:225;s:9:"mime-type";s:10:"image/jpeg";} s:5:"large";a:4:{s:4:"file";s:21:"' . $fname . '-1024x768.jpg";s:5:"width";i:1024;s:6:"height";i:768;s:9:"mime-type";s:10:"image/jpeg";} s:14:"post-thumbnail";a:4:{s:4:"file";s:18:"' . $fname . '-58x43.jpg";s:5:"width";i:58;s:6:"height";i:43;s:9:"mime-type";s:10:"image/jpeg";} s:14:"shop_thumbnail";a:4:{s:4:"file";s:18:"' . $fname . '-90x90.jpg";s:5:"width";i:90;s:6:"height";i:90;s:9:"mime-type";s:10:"image/jpeg";} s:12:"shop_catalog";a:4:{s:4:"file";s:20:"' . $fname . '-150x150.jpg";s:5:"width";i:150;s:6:"height";i:150;s:9:"mime-type";s:10:"image/jpeg";} s:11:"shop_single";a:4:{s:4:"file";s:20:"' . $fname . '-200x150.jpg";s:5:"width";i:200;s:6:"height";i:150;s:9:"mime-type";s:10:"image/jpeg";}} s:10:"image_meta";a:10:{s:8:"aperture";d:2.6;s:6:"credit";s:0:"";s:6:"camera"; s:5:"' . $nazev . '";s:7:"caption";s:0:"";s:17:"created_timestamp";i:1397583127;s:9:"copyright";s:0:"";s:12:"focal_length";s:3:"4.1";s:3:"iso";s:3:"500"; s:13:"shutter_speed";s:5:"0.025";s:5:"title";s:0:"";}}'; $db->query("INSERT INTO " . _DB_PREFIX_ . "postmeta (post_id, meta_key, meta_value) VALUES ('{$img_id}', '_wp_attachment_metadata', '{$meta_data}')"); $db->query("INSERT INTO " . _DB_PREFIX_ . "postmeta (post_id, meta_key, meta_value) VALUES ('{$img_id}', '_wp_attached_file', '" . WOO_IMG_DIR_SHORT . $image_dir . $fname . "')"); if ($position == 0) { $db->query("INSERT INTO " . _DB_PREFIX_ . "postmeta (post_id, meta_key, meta_value) VALUES ('{$products_id}', '_thumbnail_id', '{$img_id}')"); } if ($img_id != "") { copy($src_file_temp, $dest_pix_file); // main image $formats = array(array(300, 225), array(150, 150), array(58, 43), array(90, 90), array(200, 150), array(1024, 768)); foreach ($formats as $format) { imageResize($src_file_temp, str_replace(".jpg", "-" . $format[0] . "x" . $format[1] . ".jpg", $dest_pix_file), $format[0], $format[1]); } $logger->LogCron(" - IMG inserted | ID={$products_id} | {$src_file} | {$position} | " . ImpLib::convert(filesize($dest_pix_file))); @unlink($src_file_temp); return $img_id; } } else { $logger->LogCron(" - NO IMG for {$nazev}, ID={$products_id} src={$src_file}"); } @unlink($src_file_temp); return false; }