예제 #1
0
 public function firstStep()
 {
     $new_products_manager = new ViewManager();
     $tmp_manager = new UpdateTmpTables();
     $insert_product = new PrestashopProduct();
     $product_update = new ProductUpdate();
     //prendo tutti i prodotti
     $all_products = $new_products_manager->getAllProducts();
     foreach ($all_products as $product) {
         $array_reference = $product[0];
         $key = $array_reference['Reference'];
         asort($product[1]);
         asort($product[2]);
         $result = $product_update->productExists($key);
         if (gettype($result) === "integer") {
             foreach ($product[1] as $triple) {
                 $tmp_combination = $product[2];
                 $array_combination = $tmp_combination[$triple];
                 $tmp_code = $array_combination['Codici'];
                 $tmp_explode_code = explode(',', $tmp_code);
                 if ($product_update->colorSizeExists($key, $result, $tmp_explode_code[0], $tmp_explode_code[1]) == 1) {
                     $array_product = $insert_product->updateProductForPrestashop($product[0], (int) $result, $this->url_photo, $product[1], $product[2]);
                     $tmp_manager->insertTmpProducts($result, $key);
                     if (!empty($array_product[2])) {
                         foreach ($array_product[2] as $new_img) {
                             $new_photo_infos = explode(';', $new_img);
                             $tmp_manager->insertImageField($this->url_photo . $new_photo_infos[1], $array_product[0], $new_photo_infos[0]);
                         }
                     }
                 }
             }
             $url = $this->formatUrlPhoto($key);
             $this->_updatePsImages($result, $url);
         }
     }
     //prendo i prodotti nuovi
     $newProducts = $new_products_manager->getNewProduct();
     if (!empty($newProducts)) {
         foreach ($newProducts as $product) {
             $array_reference = $product[0];
             $key = $array_reference['Reference'];
             asort($product[1]);
             asort($product[2]);
             $array_product = $insert_product->insertProductForPrestashop($product[0], $this->url_photo, $product[1], $product[2]);
             $array_images_id = $array_product[1];
             for ($i = 0; $i < sizeof($array_images_id); $i++) {
                 $tmp = explode(';', $array_images_id[$i]);
                 if (empty($tmp)) {
                     break;
                 }
                 $tmp_manager->insertImageField($this->url_photo . $tmp[1], $array_product[0], $tmp[0]);
             }
             $tmp_manager->insertTmpProducts((int) $array_product[0], $key);
         }
     }
     //differenze nei prodotti
     $products_differences = $new_products_manager->getProductDifferences();
     if (!empty($products_differences)) {
         foreach ($products_differences as $product) {
             $array_reference = $product[0];
             $key = $array_reference['Reference'];
             asort($product[1]);
             asort($product[2]);
             $array_product = $insert_product->updateProductForPrestashop($product[0], (int) $product[3], $this->url_photo, $product[1], $product[2]);
             if (!empty($array_product[2])) {
                 foreach ($array_product[2] as $new_img) {
                     $new_photo_infos = explode(';', $new_img);
                     $tmp_manager->insertImageField($this->url_photo . $new_photo_infos[1], $array_product[0], $new_photo_infos[0]);
                 }
             }
             $tmp_manager->updateTmpProducts((int) $array_product[0], $key);
         }
     }
     $this->logger->postMessage("Update finished! Cleaning up...", "DEBUG");
     $buffer_manager = new ProductBufferTables();
     $buffer_manager->freeBufferTable();
 }