Ejemplo n.º 1
0
 /** 
  *Updates images if it change
  *@params string $ps_product_id, string $images_url
  */
 private function _updatePsImages($ps_product_id, $images_url)
 {
     $image_manager = new PrestashopImageHandler();
     for ($i = 0; $i < sizeof($images_url); $i++) {
         $image_id = $image_manager->getIdImageByName($images_url[$i]);
         $tmp_manager = new UpdateTmpTables();
         if ($image_id === "") {
             //primo inserimento dell'immagine
         } else {
             //update immagine già esistente
             $result = $tmp_manager->updateImageField($this->url_photo . $images_url[$i], $ps_product_id, $image_id);
             if ($result) {
                 $image_manager->updateImageInPrestashop($ps_product_id, $image_id, $this->url_photo, $images_url[$i]);
                 //update su prestashop
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Updates product combinations on Prestashop.
  * 
  * @param integer $id_product
  * @param string $url_photo
  * @param array $triple_cod_col_siz
  * @param array $array_combinations
  * @param integer $language
  * @return bool
  * @see $this->createAttributeGroups
  * @see $this->setArrayElementForLinkRewrite
  * @see $this->getCodeColor
  * @see PrestashopImageHandler getIdImageByName()
  * @see PrestashopImageHandler insertImageInPrestashop()
  *
  */
 private function updateCombinantionsForPrestashop($id_product, $url_photo, $triple_cod_col_siz, $array_combinations, $language = 1)
 {
     $product = new Product((int) $id_product);
     $id_new_images = array();
     $price = '0.000';
     //(float)$product->price;
     $reference = $product->reference;
     $id_supplier = (int) $product->id_supplier;
     foreach ($triple_cod_col_siz as $triple) {
         $array_attributes_and_values = $array_combinations[$triple];
         $attributes = $array_attributes_and_values["Attributi"];
         $values = $array_attributes_and_values["Valori"];
         $image = trim($array_attributes_and_values["Immagine"]);
         $quantity = (int) $array_attributes_and_values["Qta"];
         $variable_tmp_attributes = explode(",", $attributes);
         $variable_tmp_values = explode(",", $values);
         $id_attributes_for_combinations = array();
         $flag_just_exist_color = 1;
         $flag_just_exist_size = 1;
         for ($i = 0; $i < sizeof($variable_tmp_attributes); $i++) {
             $code = "";
             if ($variable_tmp_values[$i] != "") {
                 $id_attribute_group = $this->createAttributeGroups($variable_tmp_attributes[$i], $language);
                 $id_attributes_for_not_repeat = $this->getAttributeColorAndSize($variable_tmp_values[$i], $language);
                 if (strtolower($variable_tmp_attributes[$i]) === "colore" || strtolower($variable_tmp_attributes[$i]) === "colori") {
                     $product_attribute_for_not_reply = $product->getAttributeCombinations($language);
                     if (empty($product_attribute_for_not_reply)) {
                         if ($id_attributes_for_not_repeat === '-1') {
                             $code = $this->getCodeColor(strtolower($variable_tmp_values[$i]));
                             if ($code != "") {
                                 $code = "#" . $code;
                                 $attribute_for_product = new Attribute();
                                 $attribute_for_product->name = $this->setArrayElementForLinkRewrite($variable_tmp_values[$i], true, $language);
                                 $attribute_for_product->color = $code;
                                 $attribute_for_product->id_attribute_group = $id_attribute_group;
                                 $attribute_for_product->add();
                                 array_push($id_attributes_for_combinations, $attribute_for_product->id);
                             }
                         } else {
                             array_push($id_attributes_for_combinations, (int) $id_attributes_for_not_repeat);
                         }
                     } else {
                         $flag = 1;
                         foreach ($product_attribute_for_not_reply as $more_attributes) {
                             if ($more_attributes['attribute_name'] === $variable_tmp_values[$i]) {
                                 array_push($id_attributes_for_combinations, (int) $more_attributes['id_attribute']);
                                 $flag = 0;
                                 $flag_just_exist_color = 0;
                                 break;
                             }
                         }
                         if ($flag) {
                             if ($id_attributes_for_not_repeat === '-1') {
                                 $code = $this->getCodeColor(strtolower($variable_tmp_values[$i]));
                                 if ($code != "") {
                                     $code = "#" . $code;
                                     $attribute_for_product = new Attribute();
                                     $attribute_for_product->name = $this->setArrayElementForLinkRewrite($variable_tmp_values[$i], true, $language);
                                     $attribute_for_product->color = $code;
                                     $attribute_for_product->id_attribute_group = $id_attribute_group;
                                     $attribute_for_product->add();
                                     array_push($id_attributes_for_combinations, $attribute_for_product->id);
                                 }
                             } else {
                                 array_push($id_attributes_for_combinations, (int) $id_attributes_for_not_repeat);
                             }
                         }
                     }
                 }
                 if (strtolower($variable_tmp_attributes[$i]) === "taglia" || strtolower($variable_tmp_attributes[$i]) === "taglie") {
                     $product_attribute_for_not_reply = $product->getAttributeCombinations($language);
                     if (empty($product_attribute_for_not_reply)) {
                         if ($id_attributes_for_not_repeat === '-1') {
                             $attribute_for_product = new Attribute();
                             $attribute_for_product->name = $this->setArrayElementForLinkRewrite($variable_tmp_values[$i], true, $language);
                             $attribute_for_product->id_attribute_group = $id_attribute_group;
                             $attribute_for_product->add();
                             array_push($id_attributes_for_combinations, $attribute_for_product->id);
                         } else {
                             array_push($id_attributes_for_combinations, (int) $id_attributes_for_not_repeat);
                         }
                     } else {
                         $flag = 1;
                         foreach ($product_attribute_for_not_reply as $more_attributes) {
                             $vrbls_1 = trim($more_attributes['attribute_name']);
                             $vrbls_2 = trim($variable_tmp_values[$i]);
                             if (gettype($vrbls_1) === "string" && gettype($vrbls_2) === "string") {
                                 if ($vrbls_1 === $vrbls_2) {
                                     array_push($id_attributes_for_combinations, (int) $more_attributes['id_attribute']);
                                     $flag = 0;
                                     $flag_just_exist_size = 0;
                                     break;
                                 }
                             }
                             if (gettype($vrbls_1) === "integer" && gettype($vrbls_2) === "integer") {
                                 if ($vrbls_1 == $vrbls_2) {
                                     array_push($id_attributes_for_combinations, (int) $more_attributes['id_attribute']);
                                     $flag = 0;
                                     $flag_just_exist_size = 0;
                                     break;
                                 }
                             }
                         }
                         if ($flag) {
                             if ($id_attributes_for_not_repeat === '-1') {
                                 $attribute_for_product = new Attribute();
                                 $attribute_for_product->name = $this->setArrayElementForLinkRewrite($variable_tmp_values[$i], true, $language);
                                 $attribute_for_product->id_attribute_group = $id_attribute_group;
                                 $attribute_for_product->add();
                                 array_push($id_attributes_for_combinations, $attribute_for_product->id);
                             } else {
                                 array_push($id_attributes_for_combinations, (int) $id_attributes_for_not_repeat);
                             }
                         }
                     }
                 }
             } else {
                 if (strtolower($variable_tmp_attributes[$i]) === "colore" || strtolower($variable_tmp_attributes[$i]) === "colori") {
                     $flag_just_exist_color = 0;
                 }
                 if (strtolower($variable_tmp_attributes[$i]) === "taglia" || strtolower($variable_tmp_attributes[$i]) === "taglie") {
                     $flag_just_exist_size = 0;
                 }
             }
         }
         if ($flag_just_exist_color || $flag_just_exist_size) {
             $id_images = array();
             $tmp_photo = explode(".jpg,", $image);
             for ($i = 0; $i < sizeof($tmp_photo); $i++) {
                 if (!empty($tmp_photo[$i])) {
                     $image_for_prestashop = new PrestashopImageHandler();
                     $id_image = $image_for_prestashop->getIdImageByName(trim($tmp_photo[$i]));
                     if (!empty($id_image)) {
                         array_push($id_images, $id_image);
                     } else {
                         $id_image = $image_for_prestashop->insertImageInPrestashop($id_product, trim($url_photo), trim($tmp_photo[$i]));
                         array_push($id_images, $id_image);
                         array_push($id_new_images, $id_image . ";" . trim($tmp_photo[$i]) . '.jpg');
                     }
                 }
             }
             $id_product_attributes = $product->addProductAttribute($price, 0, 0, 0, $quantity, "", $reference, $id_supplier, 0, 1);
             $combinations = new CombinationCore((int) $id_product_attributes);
             $combinations->setAttributes($id_attributes_for_combinations);
             $combinations->setImages($id_images);
         } else {
             $id_images = array();
             $tmp_photo = explode(".jpg,", $image);
             for ($i = 0; $i < sizeof($tmp_photo); $i++) {
                 if (!empty($tmp_photo[$i])) {
                     $image_for_prestashop = new PrestashopImageHandler();
                     $id_image = $image_for_prestashop->getIdImageByName(trim($tmp_photo[$i]));
                     if (empty($id_image)) {
                         $id_image = $image_for_prestashop->insertImageInPrestashop($id_product, trim($url_photo), trim($tmp_photo[$i]));
                         array_push($id_images, $id_image);
                         array_push($id_new_images, $id_image . ";" . trim($tmp_photo[$i]) . ".jpg");
                     }
                 }
             }
             if (!empty($id_images)) {
                 $array_product_attribute_combinations_get = $product->getCombinationImages($language);
                 for ($i = 0; $i < sizeof($id_images); $i++) {
                     $id_della_immagine = $id_images[$i];
                     foreach ($array_product_attribute_combinations_get as $single_array_of_attribute_product) {
                         foreach ($single_array_of_attribute_product as $array_di_combinazioni) {
                             $id_arr_comb = $array_di_combinazioni['id_product_attribute'];
                             $combinazioni_attributi = new CombinationCore((int) $id_arr_comb);
                             $attribute_combinations = $combinazioni_attributi->getAttributesName($language);
                             $attr_comb1 = $attribute_combinations[0];
                             $attr_comb2 = $attribute_combinations[1];
                             $id_attr_comb1 = $attr_comb1['id_attribute'];
                             $id_attr_comb2 = $attr_comb2['id_attribute'];
                             $id_attributi_input = $id_attributes_for_combinations;
                             $id_color_or_size = $id_attributi_input[0];
                             $id_size_or_color = $id_attributi_input[1];
                             if ($id_color_or_size == $id_attr_comb1 || $id_color_or_size == $id_attr_comb2) {
                                 if ($id_size_or_color == $id_attr_comb1 || $id_size_or_color == $id_attr_comb2) {
                                     $new_image = array();
                                     $new_array_image = $combinazioni_attributi->getWsImages();
                                     for ($j = 0; $j < sizeof($new_array_image); $j++) {
                                         $tmp_image_ = $new_array_image[$j];
                                         array_push($new_image, (int) $tmp_image_['id']);
                                     }
                                     array_push($new_image, $id_della_immagine);
                                     $fff = $product->updateProductAttribute($id_arr_comb, 0, $price, 0, 0, 0, $new_image, $reference, $id_supplier, 0, 1, null, null, 1, '0000-00-00');
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $id_new_images;
 }