Esempio n. 1
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;
 }
Esempio n. 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;
 }