public static function addProductImage($productId, $nameImage, $thumb, $type = PRODUCT_IMAGE_TYPE_NORMAL)
 {
     $productGallery = new productGalleryModel();
     $productGallery->product_id = $productId;
     $productGallery->image = $nameImage;
     $productGallery->thumb = $thumb;
     $productGallery->type = $type;
     $productGallery->save();
     return $productGallery;
 }
 public function deleteImage($id)
 {
     $productGallery = new productGalleryModel();
     $gallery = $productGallery->getById($id);
     if ($gallery->getOriginal('image')) {
         $this->deleteFromS3($gallery->getOriginal('image'));
     }
     if ($gallery->getOriginal('thumb')) {
         $this->deleteFromS3($gallery->getOriginal('thumb'));
     }
     return $productGallery->deleteImage($id);
 }
Example #3
0
 public function productDetail($domain, $slug, $id, $tagId, Request $request)
 {
     $productService = new productService();
     $tagService = new tagService();
     $productGallery = new productGalleryModel();
     $userId = \Kacana\Util::isLoggedIn() ? $this->_user->id : 0;
     try {
         $product = $productService->getProductById($id, $userId);
         $tagIdRelateds = [];
         $product->metaKeyword = $tagService->formatMetaKeyword($product->tag, $tagIdRelateds);
         $data['productRelated'] = [];
         $productRelationIds = [];
         foreach ($tagIdRelateds as $tagIdRelated => $numberProductByTagId) {
             $productRelations = $productService->getProductByTagId($tagIdRelated, 100);
             foreach ($productRelations as $productRelation) {
                 if (!in_array($productRelation->id, $productRelationIds)) {
                     array_push($data['productRelated'], $productRelation);
                     array_push($productRelationIds, $productRelation->id);
                 }
                 if (count($data['productRelated']) > 8) {
                     break;
                 }
             }
             if (count($data['productRelated']) > 8) {
                 break;
             }
         }
         $data['product'] = $product;
         $data['tag'] = $tagService->getTagById($tagId, false);
         $data['productSlide'] = $productGallery->getImagesProductByProductId($id, PRODUCT_IMAGE_TYPE_SLIDE);
         return view('client.product.detail', $data);
     } catch (\Exception $e) {
         if ($request->ajax()) {
             $result['error'] = $e->getMessage();
             return $result;
         } else {
             return view('errors.404', ['error_message' => $e->getMessage()]);
         }
     }
 }
Example #4
0
 public function superPostToSocial($userId, $socials, $products, $desc)
 {
     $productModel = new productModel();
     $productGalleryModel = new productGalleryModel();
     $socialPostModel = new socialPostModel();
     $socialProductPostModel = new socialProductPostModel();
     $socialGalleryPostModel = new socialGalleryPostModel();
     $bootType = SOCIAL_BOOT_TYPE_SUPER;
     if (count($products) == 1) {
         $bootType = SOCIAL_BOOT_TYPE_NORMAL;
     }
     foreach ($socials as $social) {
         $socialPost = $socialPostModel->addItem($userId, $social['socialId'], $social['type'], $bootType, $this->trimDescPostToFacebook($desc), '');
         $arrayImage = [];
         foreach ($products as $product) {
             if ($this->isValidProduct($userId, $product['productId'])) {
                 $socialProductPost = $socialProductPostModel->addItem($socialPost->id, $product['productId']);
                 $productImageIds = $product['images'];
                 for ($i = 0; $i < count($productImageIds); $i++) {
                     $urlImage = '';
                     if ($productImageIds[$i] == 'image') {
                         $productTemp = $productModel->getProductById($product['productId'], false);
                         $urlImage = $productTemp->image;
                     } else {
                         $gallery = $productGalleryModel->getById($productImageIds[$i], $product['productId']);
                         $urlImage = $gallery->image;
                     }
                     $socialGalleryPost = $socialGalleryPostModel->addItem($socialProductPost->id, $productImageIds[$i], $urlImage, $this->trimDescPostToFacebook($product['caption']), '');
                     array_push($arrayImage, ['socialGalleryPostId' => $socialGalleryPost->id, 'url' => $this->trimImageLinkForSocial($urlImage), 'caption' => $this->trimDescPostToFacebook($product['caption'])]);
                 }
             }
         }
         $job = ["socialPostId" => $socialPost->id, "userId" => $userId, "social" => $social, "images" => $arrayImage, "desc" => $this->trimDescPostToFacebook($desc)];
         // push process to post to queue and response for user is processing
         Queue::push(new PostToSocial(base64_encode(json_encode($job))));
     }
     return true;
 }
Example #5
0
 /**
  * @param $description
  * @param $id
  */
 public function trimImageDesc($description, $id)
 {
     $productGallery = new productGalleryModel();
     $productGalleryService = new productGalleryService();
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $dom->strictErrorChecking = false;
     preg_match_all('/src="(.*?)"/', $description, $items);
     $images = $items[1];
     $productImageDesc = $productGallery->getImagesProductByProductId($id, PRODUCT_IMAGE_TYPE_DESC);
     foreach ($productImageDesc as $image) {
         if (!in_array($image->image, $images)) {
             $productGalleryService->deleteImage($image->id);
         }
     }
 }
Example #6
0
 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);
 }