/** * Updates product image in Prestashop. * * @param integer $id_product, integer $id_img, string $url, string $name_photo * @return integer * @see $this->copyImg * */ public function updateImageInPrestashop($id_product, $id_img, $url, $name_photo) { if (empty($id_img)) { return (int) $this->insertImageInPrestashop($id_product, $url, $name_photo); } else { $shops = Shop::getShops(true, null, true); $image = new ImageCore((int) $id_img); $image->id_product = $id_product; $tmp = explode(".", $name_photo); $name_photo_product = ""; $name_for_legend = ""; if (count($tmp) == 1) { $name_photo_product = trim($url) . $name_photo . ".jpg"; $name_for_legend = $name_photo . ".jpg"; } else { $name_photo_product = trim($url) . $name_photo; $name_for_legend = $name_photo; } $image->legend = array('1' => trim($name_for_legend)); if ($image->validateFields(false, true) === true && $image->validateFieldsLang(false, true) === true && $image->update()) { $image->associateTo($shops); if (!$this->copyImg($id_product, $id_img, $name_photo_product, 'products')) { $image->delete(); } } return (int) $image->id; } }
/** * Update image legend and cover * * @param int $idImage * @param array $data * * @return object image */ public function ajaxProcessUpdateImage($idImage, $data) { $img = new \ImageCore((int) $idImage); if ($data['cover']) { \ImageCore::deleteCover((int) $img->id_product); $img->cover = 1; } $img->legend = $data['legend']; $img->update(); return $img; }