/** * @param $id * @param $parentId * @param $typeId * @param $imageName * @return int */ public function updateImage($id, $parentId, $typeId, $imageName) { $productGalleryService = new productGalleryService(); $tagModel = new tagModel(); $tag = $tagModel->getTagRelation($id, $typeId); if ($tag->image) { $productGalleryService->deleteFromS3($tag->image); } if ($imageName) { $newPath = '/images/tag/kacana_tag_' . $tag->parent_id . '_' . $tag->child_id . '_' . $tag->tag_type_id . '_' . time() . '.jpg'; $productGalleryService->uploadToS3($imageName, $newPath); $imageName = $newPath; } $tag = $tagModel->updateImage($id, $parentId, $typeId, $imageName); return $tag; }
/** * @param $productId * @param $imageName * @return mixed */ public function updateImage($productId, $imageName) { $productModel = new productModel(); $productGalleryService = new productGalleryService(); $prefixPath = '/images/product/'; $product = $productModel->getProductById($productId, false); $newImageName = $imageName; if ($product->getOriginal('image')) { $productGalleryService->deleteFromS3($product->getOriginal('image')); } if ($imageName) { $imageNameFinal = explode('.', $imageName); $typeImage = $imageNameFinal[count($imageNameFinal) - 1]; $newImageName = $prefixPath . $product->name . ' ' . time() . '.' . $typeImage; $productGalleryService->uploadToS3($imageName, $newImageName); } return $productModel->updateImage($productId, $newImageName); }