Пример #1
0
    }
    // 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();
Пример #2
0
 public function process_xml($type = "FOR_INSERT")
 {
     global $logger, $db;
     $this->store_products = $this->get_imported($this->name);
     $this->updatedIceCatItems = IceCat::getUpdatedIceCatItemsOK();
     $this->import_settings = Settings::get_import_settings($this->name);
     $cached_ancestors = array();
     $fh = @fopen(FEED_PATH . "/215841.csv", "r");
     $art = fgetcsv($fh, null, "\t");
     //    dump($art) ;
     $i = 0;
     $bz = 0;
     $this->all = 0;
     while (($art = fgetcsv($fh, null, ",")) !== false) {
         //        	dump($art);exit;
         $sku = (int) trim($art[0]);
         if ($sku == "1520519") {
             continue;
         }
         $store_product_id = @$this->store_products[$sku];
         $this->all++;
         if ($type == "FOR_INSERT" && $store_product_id) {
             continue;
         }
         if ($type == "FOR_UPDATE" && !$store_product_id) {
             continue;
         }
         //  exit;
         if ($type == "FOR_UPDATE") {
             // if ( !$this->updatedIceCatItems[$sku] ) continue;
         }
         $item = new stdClass();
         $item->category_XML = $art[12];
         if (@$this->category_mapping[$item->category_XML]) {
             foreach ($this->category_mapping[$item->category_XML] as $catstore) {
                 if (isset($cached_ancestors[$catstore])) {
                     $d = $cached_ancestors[$catstore];
                 } else {
                     //                           	     $logger->LogCron(" - $catstore");
                     $cached_ancestors[$catstore] = $this->get_category_ancestors($catstore);
                     $d = $cached_ancestors[$catstore];
                     //							  $logger->LogCron(" - ok => " . print_r($d, true));
                 }
                 //                            dump($d);exit;
                 foreach ($d as $cc) {
                     $item->category_ids[] = (int) $cc;
                 }
                 $item->category_ids[] = (int) $catstore;
             }
         }
         if (@count($item->category_ids) == 0) {
             //echo $bz++ . ". {$sku} NO CATEGORY ({$item->category_XML}) <Br>";
             continue;
         }
         //$item->category_ids = array_unique($item->category_ids);
         //  dump($item->category_ids) ;exit;
         $item->sku = $sku;
         // part number
         // dump(explode(",",$this->import_settings['NOT_IMPORT_NAME']));exit;
         //if (in_array($item->sku, explode(",",$this->import_settings['NOT_IMPORT_SKU']))) continue;
         // 33,34
         $item->quantity = $art[16];
         if (!$item->quantity) {
             continue;
         }
         //                    if ($item->quantity < 10) continue;
         $item->title = $art[1];
         $item->desc_short = ImpLib::limitString($art[23]);
         $item->desc_long = $art[23];
         /*
           ['0'] = String(18) "Ingram Part Number"
         
                         |    ['2'] = String(20) "Customer Part Number" = 0
                         |    ['3'] = String(18) "Vendor Part Number"
                         |    ['6'] = String(13) "Vendor Number"
         *
         */
         $item->vendor = $art[7];
         $item->plant = $art[5];
         $item->manufacturer = $art[7];
         $item->manufacturer_sku = $art[3];
         $item->meta_desc = $item->desc_short;
         $item->meta_keywords = $item->desc_short;
         $item->tags = $item->desc_short;
         //$item->supplier_reference = $art[3];
         $item->manufacturer_sku_2 = $art[6];
         $item->store_product_id = $store_product_id;
         $item->supplier = "IM";
         //$db->query("UPDATE "._DB_PREFIX_."product_supplier SET id_supplier='{$item->id_supplier}' WHERE id_product='{$store_product_id}'");
         $item->manufacturer_id = $this->get_manufacturer_id($item->manufacturer);
         //dump($item);exit;
         if ($type == "FOR_INSERT") {
             //$item->id_manufacturer = $this->get_manufacturer_id($item->manufacturer);
             //$item->id_supplier = $this->get_supplier_id($art[4]);
         }
         $item->ean_upc = $art[4];
         $item->online_only = 0;
         $item->price = $art[13];
         $item->rrp = $art[14];
         $item->raw_price = $art[13];
         // customer price
         if ($item->price < 0.1) {
             continue;
         }
         // echo Settings::get_margin_from_price($item->price);exit;
         if ($i == 1500) {
             $db->query('UPDATE imported SET processed = 0 WHERE supplier="IMNZ"');
         }
         if ($i == 3000) {
             $db->query('UPDATE imported SET processed = 0 WHERE supplier="IMNZ"');
         }
         $margin = @$this->import_settings['MARGIN'][$item->category_XML];
         //                    dump($this->import_settings['MARGIN']);exit;
         //dump($this->import_settings);
         $item->margin = $margin > 0 ? $margin : (int) $this->import_settings['GLOBALPROFITMARGIN'];
         //                    dump($item);exit;
         /// $item->margin  = ($margin !="") ? $margin : Settings::get_margin_from_price($item->price);
         $item->price_raw = $item->price;
         $item->price = $item->price * (1 + $item->margin / 100);
         $item->price = $item->price;
         /// 1.15;
         //                     * 1.15;
         //                    $item->rrp = $item->rrp * 1.15;
         echo "{$item->sku} | {$item->category_XML} | {$item->price_raw} + {$item->margin}% => {$item->price}<br>";
         $item->wholesale_price = $art[13];
         if ($item->wholesale_price == 0) {
             continue;
         }
         $item->weight = (double) $art[9];
         $item->length = (double) $art[24];
         $item->width = (double) $art[25];
         $item->height = (double) $art[26];
         //                         dump($item);exit;
         $item->active = 1;
         $item->status = 1;
         $item->images = array();
         //if ($item->active == 0) continue;
         if ($sku == "2307809") {
             //                       dump($art);
             //                        dump($item);exit;
         }
         $articles_final[$sku] = $item;
         $i++;
         //                    echo $i . " | ";
         //break;
     }
     //  dump($articles_final);
     //  exit;
     return @$articles_final;
 }
Пример #3
0
 public function process_xml($type = "FOR_INSERT")
 {
     global $logger, $db;
     $this->store_products = $this->get_imported($this->name);
     $this->updatedIceCatItems = IceCat::getUpdatedIceCatItemsOK();
     $this->import_settings = Settings::get_import_settings($this->name);
     $fh = @fopen(FEED_PATH . $this->name . ".csv", "r");
     $art = fgetcsv($fh, null, ",");
     $i = 0;
     $bz = 0;
     $this->all = 0;
     //        dump($art);exit;
     while (($art = fgetcsv($fh, null, ",")) !== false) {
         //            print_r($art);exit;
         $sku = substr((string) trim($art[0]), 0, 31);
         if (strpos($sku, "'")) {
             continue;
         }
         $store_product_id = @$this->store_products[$sku];
         $this->all++;
         if ($type == "FOR_INSERT" && $store_product_id) {
             continue;
         }
         if ($type == "FOR_UPDATE" && !$store_product_id) {
             continue;
         }
         $item = new stdClass();
         $item->sku = $sku;
         $item->category_XML = @$art[4];
         if (@$this->category_mapping[$item->category_XML]) {
             foreach ($this->category_mapping[$item->category_XML] as $catstore) {
                 // $d = $this->get_ps_category_ancestors($catstore);
                 // dump($d);exit;
                 // $item->category_ids[] = $this->get_ps_category_ancestors($catstore);
                 $item->category_ids[] = (int) $catstore;
             }
         }
         if (@count($item->category_ids) == 0) {
             //                echo $bz++ . ". {$sku} NO CATEGORY ({$item->category_XML}) <Br>";
             continue;
         }
         //$item->category_ids = array_unique($item->category_ids);
         //  dump($item->category_ids) ;exit;
         // part number
         // dump(explode(",",$this->import_settings['NOT_IMPORT_NAME']));exit;
         //if (in_array($item->sku, explode(",",$this->import_settings['NOT_IMPORT_SKU']))) continue;
         // 33,34
         $item->quantity = (int) $art[5];
         if (!$item->quantity) {
             //                echo $bz2++ . ". {$sku} QTY=0<Br>";
             continue;
         }
         //            if ($item->quantity < 10 ) continue;
         //                    if ($item->quantity < 10) continue;
         $item->title = $art[1];
         $item->desc_short = ImpLib::limitString($art[1]);
         $item->meta_desc = ImpLib::limitString($art[1]);
         $item->tags = "";
         $item->meta_keywords = "";
         $item->desc_long = $art[1];
         $item->vendor = $art[7];
         $item->plant = $art[7];
         $item->manufacturer = $art[7];
         $item->manufacturer_sku = $art[0];
         //$item->supplier_reference = $art[3];
         $item->manufacturer_sku_2 = $art[0];
         $item->store_product_id = $store_product_id;
         $item->supplier = "EX";
         //            if ($type=="FOR_INSERT") {
         $item->id_manufacturer = $this->get_manufacturer_id($item->manufacturer);
         $item->manufacturer_id = $item->id_manufacturer;
         //            }
         $item->ean_upc = "";
         $item->price = str_replace("\$", "", $art[3]);
         $item->price = (double) str_replace(",", "", $item->price);
         //            $item->rrp = (float) (str_replace("$", "", $art[3]));;
         $item->raw_price = $item->price;
         if ($item->price < 0.1) {
             continue;
         }
         // echo Settings::get_margin_from_price($item->price);exit;
         $margin = @$this->import_settings['MARGIN'][$item->category_XML];
         //                    dump($this->import_settings['MARGIN']);exit;
         //dump($this->import_settings);
         $item->margin = $margin > 0 ? $margin : (int) $this->import_settings['GLOBALPROFITMARGIN'];
         //                    dump($item);exit;
         /// $item->margin  = ($margin !="") ? $margin : Settings::get_margin_from_price($item->price);
         $item->price_raw = $item->price;
         $item->price = $item->price * (1 + $item->margin / 100);
         $item->price = $item->price;
         $item->wholesale_price = $item->price_raw;
         $item->weight = "";
         $item->length = "";
         $item->width = "";
         $item->height = "";
         $item->active = 1;
         $item->status = 1;
         $item->images = array();
         if ($sku == "PTH-851-K1-CX") {
             dump($item);
             dump($art);
             //                exit;
         }
         //              print_r($art);
         //            dump($item);exit;
         //            dump($item);exit;
         echo "{$item->sku} | {$item->store_product_id} | {$item->category_XML} | {$item->price_raw} + {$item->margin}% => {$item->price}<br>";
         $articles_final[$sku] = $item;
         $i++;
     }
     //         dump($articles_final);exit;
     return @$articles_final;
 }
Пример #4
0
 public static function getICEcatProductSpecsDetails($data)
 {
     if (strpos($data, "Requested_prod_id")) {
         $output = "CSV " . IceCat::getCSVresult($data);
         //            dump($output);
         $c = current(IceCat::csv_to_array($data, ",", '"', "\r"));
         //            dump($c);exit;
         if ($c['ErrorMessage'] == "") {
             $art['title'] = $c['ProductTitle'];
             $art['supplier'] = $c['Supplier'];
             $art['ean'] = $c['GTIN(EAN/UPC)'];
             $art['desc_short'] = @$art['desc_short'] == "" ? @$c['ShortSummaryDescription'] : $art['desc_short'];
             $art['desc_sum_long'] = $c['ShortSummaryDescription'];
             $art['desc_long'] = @$art['desc_long'] == "" ? $c['LongSummaryDescription'] : $art['desc_long'];
             $art['desc_sum_short'] = $c['LongSummaryDescription'];
             $art['images'][] = $c['HighPic'];
             $i = 1;
             $features_html = "<table class='productspecs'>";
             //                dump($c);
             //                dump($art); exit;
             while (@$c['Spec ' . $i] != "") {
                 $val = explode(": ", $c['Spec ' . $i]);
                 if (isset($val[1])) {
                     $art['features'][$val[0]] = $val[1];
                     $features_html .= "<tr class='speccategory'><td>{$val[0]}: </td><td>{$val[1]}</td></tr>\n";
                 }
                 if ($i > 200) {
                     break;
                 }
                 $i++;
             }
             //                  dump($art); //exit;
             $features_html .= "<table>";
             $art['features_html'] = $features_html;
             //dump($art);exit;
             //features_html
             $output = "READY FOR IMPORT";
             //                 dump($art);
             return array($c['Icecat_id'], $output, $art);
         } else {
         }
         //            dump($output);exit;
         return @array($c['Icecat_id'], $output, $art);
     }
     if (strpos($data, "rrorMessage: Reque")) {
         return array("", "BAD XML or CSV FILE", "");
     }
     //  echo "2";
     if (strpos($data, "ernal Server Err")) {
         return array("", "BAD XML or CSV FILE", "");
     }
     //  echo "2";
     if (strpos($data, "02 Bad Gat")) {
         return array("", "BAD XML or CSV FILE", "");
     }
     //  echo "2";
     if ($data == "") {
         return array("", "BAD XML or CSV FILE", "");
     }
     try {
         $xml = new SimpleXMLElement($data);
     } catch (Exception $e) {
         echo "<pre>{$data}</pre>";
         exit;
         return array("", "BAD XML or CSV FILE", "");
     }
     if (!$xml) {
         echo "problem";
     }
     $art = array();
     // Create arrays of item elements from the XML feed
     $product = $xml->xpath("//Product");
     $productDescription = $xml->xpath("//ProductDescription");
     $categories = $xml->xpath("//CategoryFeatureGroup");
     $summaryDescription = $xml->xpath("//SummaryDescription");
     $spec_items = $xml->xpath("//ProductFeature");
     $pictures = $xml->xpath("//ProductPicture");
     $ean = $xml->xpath("//EANCode");
     $related = $xml->xpath("//ProductRelated");
     //$productDescription = $product[0]->ProductDescription;
     //print_r($productDescription);
     if (!isset($product[0])) {
         return "";
     }
     $productattr = @$product[0]->attributes();
     $id_icecat = (string) $product[0]->attributes()->ID;
     $output = "READY FOR IMPORT";
     $productattr = $product[0]->attributes();
     if ((string) $productattr['ErrorMessage'] != "") {
         $id_icecat = 0;
         $output = (string) $productattr['ErrorMessage'];
     }
     if ((string) $productattr['ErrorMessage'] == "No xml data for this product or product code is incorrect") {
         $id_icecat = 0;
         $output = "NO DATA";
     }
     if ((string) $productattr['ErrorMessage'] == "Product was replaced with") {
         $id_icecat = 0;
         $output = "REPLACED with " . (string) $productattr['Map_product_id'];
     }
     if ((string) $productattr['ErrorMessage'] == "Language should be necessarily specified") {
         $id_icecat = 0;
         $output = "NO LANG";
     }
     if ((string) $productattr['ErrorMessage'] == "You are not allowed to have Full ICEcat access") {
         $id_icecat = 0;
         $output = "NO ACCESS";
     }
     if ((string) $productattr['ErrorMessage'] == "No xml data for this product or product code incorrect") {
         $id_icecat = 0;
         $output = "NO DATA";
     }
     if ((string) $productattr['ErrorMessage'] == "The specified vendor does not exist") {
         $id_icecat = 0;
         $output = "NO VENDOR";
     }
     if ((string) $productattr['ErrorMessage'] == "Access to this product and language are restricted") {
         $id_icecat = 0;
         $output = "RESTRICTED ACCESS";
     }
     if ((string) $product[0]->attributes()->HighPicWidth > MAX_ICECAT_IMAGE_WIDTH) {
         $art['images'][] = (string) $product[0]->attributes()->Pic500x500;
     } else {
         $art['images'][] = (string) $product[0]->attributes()->HighPic;
     }
     foreach ($pictures as $picture) {
         $pics = $picture->attributes();
         if ((string) $pics->PicWidth > MAX_ICECAT_IMAGE_WIDTH) {
             $art['images'][] = (string) $pics->Pic500x500;
         } else {
             $art['images'][] = (string) $pics->Pic;
         }
         // $art['images'][] = (string) $pics->{Pic500x500};
     }
     $art['relations'] = array();
     foreach ($related as $relate) {
         foreach ($relate->Product as $p) {
             $art['relations'][] = (string) $p[0]->attributes()->ID;
         }
     }
     $art['title'] = IceCat::replaceUS_EN((string) $product[0]->attributes()->Title);
     $art['icecat_ID'] = (string) $product[0]->attributes()->ID;
     $art['supplier'] = (string) @$product[0]->Supplier->attributes()->Name;
     $art['supplierID'] = (string) @$product[0]->Supplier->attributes()->ID;
     $art['desc_short'] = "";
     $art['desc_long'] = "";
     $art['url'] = "";
     if (@$ean[0]) {
         $art['ean'] = (string) $ean[0]->attributes()->EAN;
     }
     if (@$productDescription[0]) {
         $art['desc_short'] = IceCat::replaceUS_EN(IceCat::cleanDetails((string) $productDescription[0]->attributes()->ShortDesc));
         $art['desc_long'] = IceCat::replaceUS_EN(IceCat::cleanDetails((string) $productDescription[0]->attributes()->LongDesc));
         $art['url'] = (string) $productDescription[0]->attributes()->URL;
     }
     if (@$summaryDescription[0]) {
         $art['desc_sum_short'] = IceCat::replaceUS_EN((string) $summaryDescription[0]->ShortSummaryDescription);
         $art['desc_sum_long'] = IceCat::replaceUS_EN((string) $summaryDescription[0]->LongSummaryDescription);
     }
     //return $art;
     //'title' => $specs['title'], 'images' => $specs['images'], 'desc_short' => $specs['desc_short'], 'desc_long' => $specs['desc_long']
     //print_r($spec_items);exit;
     //Draw product specifications table if any specs available for the product
     if ($spec_items != null) {
         $categoryList = array();
         foreach ($categories as $categoryitem) {
             $catId = intval($categoryitem->attributes());
             $titleXML = new SimpleXMLElement($categoryitem->asXML());
             $title = $titleXML->xpath("//Name");
             //print_r($title);
             if (count($title) > 0) {
                 $catName = $title[0]->attributes();
                 //echo $catId . $catName['Value']. "<br />";
                 $categoryList[$catId] = $catName['Value'];
             } else {
                 break;
             }
         }
         $specs = "<table class='productspecs' cellspadding='3'>";
         $i = 0;
         $drawnCategories = array();
         $features = array();
         foreach ($spec_items as $item) {
             $specValue = $item->attributes();
             $titleXML = new SimpleXMLElement($item->asXML());
             $title = $titleXML->xpath("//Name");
             $specName = $title[0]->attributes();
             $specCategoryId = intval($specValue['CategoryFeatureGroup_ID']);
             if ($specName['Value'] != "Source data-sheet") {
                 $class = $i % 2 == 0 ? "odd" : "even";
                 $specs .= "<tr class='" . $class . "'>\r\n                            <td class='speccategory'>\r\n                                ";
                 if (!in_array($specCategoryId, $drawnCategories)) {
                     $specs .= "\r\n                                        <h4>" . @$categoryList[$specCategoryId] . "</h4>\r\n                                    </td></tr>";
                     $drawnCategories[$i] = $specCategoryId;
                 }
                 $val = $specValue['Presentation_Value'];
                 $val = str_replace('\\n', '<br />', $val);
                 $value_feat = utf8_decode($specName['Value']);
                 if (strpos($value_feat, "talleerde")) {
                     continue;
                 }
                 if (strpos($value_feat, "ntegreerde kaartlezer")) {
                     continue;
                 }
                 $features[(string) @$categoryList[$specCategoryId] . "||{$specCategoryId}"][$value_feat . "||" . (int) $specValue['CategoryFeature_ID']] = $val;
                 // . "||" . $specValue['ID']; /// xxx odmas
                 //$features_ids[  (string) $categoryList[$specCategoryId] . "|$specCategoryId"  ][  utf8_decode( $specName['Value'])] = (string) $specName['Value'] ; /// xxx odmas
                 $specs .= "        <tr>\r\n                                        <td>" . $specName['Value'] . ":</td>\r\n\r\n                                        <td>";
                 if ($specValue['Presentation_Value'] == "Y") {
                     $specs .= "Yes";
                 } else {
                     if ($specValue['Presentation_Value'] == "N") {
                         $specs .= "No";
                     } else {
                         $specs .= str_replace('\\n', '<br />', $specValue['Presentation_Value']);
                     }
                 }
                 $specs .= "</td>\r\n\r\n                        </tr>";
             }
             $i++;
         }
         $specs .= "</table>";
         $art['features_html'] = $specs;
         // dump($features) ;exit;
         /*
         $description = utf8_decode(str_replace('\n', '', $productValues['LongDesc']));
         $description = str_replace('<b>', '<strong>', $description);
         $description = str_replace('<B>', '<strong>', $description);
         $description = str_replace('</b>', '</strong>', $description);
         */
         //$art['features_html'] = $specs;
         $art['features'] = $features;
         //  dump($art);exit;
     } else {
         //return array($id_icecat, $output, $art);
     }
     return array($id_icecat, $output, $art);
 }