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); }
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; }
public function formatProductPropertiesWhenSearch(&$product) { $tagService = new tagService(); $product->image = AWS_CDN_URL . $product->image; $productGalleryModel = new productGalleryModel(); $productPropertiesModel = new productPropertiesModel(); $productProperties = $productPropertiesModel->getPropertiesByProductId($product->id); $properties = array(); $propertiesSize = array(); foreach ($productProperties as $property) { if (isset($property->product->status) && $property->product->status == KACANA_PRODUCT_STATUS_ACTIVE) { if (!isset($properties[$property->tag_color_id])) { $properties[$property->tag_color_id] = new \stdClass(); $properties[$property->tag_color_id]->color_name = $property->color->name; $properties[$property->tag_color_id]->color_id = $property->tag_color_id; $properties[$property->tag_color_id]->product_gallery_id = $property->product_gallery_id; $properties[$property->tag_color_id]->product_gallery = $productGalleryModel->getById($property->product_gallery_id); $properties[$property->tag_color_id]->product_gallery_array = $productGalleryModel->getById($property->product_gallery_id) ? $productGalleryModel->getById($property->product_gallery_id)->toArray() : 0; } if (!isset($properties[$property->tag_color_id]->size)) { $properties[$property->tag_color_id]->size = []; $properties[$property->tag_color_id]->sizeIds = []; } if ($property->tag_size_id) { $tagSize = $tagService->getTagById($property->tag_size_id, TAG_RELATION_TYPE_SIZE); $size = new \stdClass(); $size->name = $tagSize->name; $size->id = $tagSize->id; if (!isset($propertiesSize[$property->tag_size_id])) { $propertiesSize[$property->tag_size_id] = new \stdClass(); $propertiesSize[$property->tag_size_id]->color = []; $propertiesSize[$property->tag_size_id]->colorIds = []; } $propertiesSize[$property->tag_size_id]->name = $tagSize->name; $propertiesSize[$property->tag_size_id]->id = $property->tag_size_id; $colorSize = new \stdClass(); $colorSize->name = $property->name; $colorSize->id = $property->tag_color_id; array_push($propertiesSize[$property->tag_size_id]->color, $colorSize); array_push($propertiesSize[$property->tag_size_id]->colorIds, $property->tag_color_id); array_push($properties[$property->tag_color_id]->size, $size); array_push($properties[$property->tag_color_id]->sizeIds, $size->id); } } } if (count($propertiesSize)) { $product->propertiesSize = $propertiesSize; } $product->properties = $properties; return $product; }