/** * @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); }
public function updateProductImageType(Request $request) { $productId = $request->input('productId'); $imageId = $request->input('imageId'); $action = $request->input('action'); $productGallery = new productGalleryModel(); $productGalleryService = new productGalleryService(); $return['ok'] = 0; try { $image = $productGallery->getImageById($imageId); if ($action == 'setPrimaryImage') { $return['data'] = $productGallery->setPrimaryImage($imageId, $productId); } elseif ($action == 'deleteImage') { $productGalleryService->deleteImage($imageId); $return['data'] = true; } elseif ($action == 'setSlideImage') { $return['data'] = $productGallery->setSlideImage($imageId); } $return['ok'] = 1; } catch (\Exception $e) { // @codeCoverageIgnoreStart $return['errorMsg'] = $e->getMessage(); // @codeCoverageIgnoreEnd } return response()->json($return); }