/** * Returns a placeholder image url with the specified size * @param int $width maximum width. * @param int $height maximum height. * @return str the image url (eg.: http://static.boutiquekem.com/img-1-2-3-0000.png) */ public static function placehoderForSize($width, $height) { if ($width <= 300 && $height <= 280) { // We can display thumbnails without the store's watermark. Cleaner for end users and easier on the server. $url = ProductImage::getImageGeneratorBaseUrl() . $width . "-" . $height . "-0000.png"; } else { $url = ProductImage::getImageGeneratorBaseUrl() . Yii::app()->params['outbound_api_user'] . "-" . $width . "-" . $height . "-0000.png"; } return $url; }
/** * Returns an array of the current product with the current language description. Will always use an alternative language if necessary. * Use this function to serialize the product into JSON * @return str the static model as a json dict. */ public function getStructuredProductArray() { $cache_id = $this->getProductArrayCacheIdForLanguage(Yii::app()->language); $cache_duration = 300; //10800; $productArray = Yii::app()->cache->get($cache_id); if (!$productArray) { $localization = $this->localizationForLanguage(Yii::app()->language, $accept_substitute = true); if ($localization === null) { return null; } $is_product_available_in_current_language = true; if ($this->productLocalization === null) { $is_product_available_in_current_language = false; } $productArray = array("price" => floatval($this->getCurrentPrice()), "available_in_current_language" => $is_product_available_in_current_language, "name" => $localization->name, "short_description" => $localization->short_description, "long_description" => $localization->long_description, "visible" => $this->visible == 1 ? true : false, "taxable" => $this->taxable == 1 ? true : false, "weight" => floatval($this->weight), "discontinued" => $this->discontinued == 1 ? true : false, "barcode" => $this->barcode, "parent_id" => $this->parent_product_id, "sku" => $this->sku, "product_id" => intval($this->id), "localization_id" => intval($localization->id), "slug" => $localization->slug, "categories" => array()); // Load the videos $productArray["videos"] = $this->getVideosForLanguage(Yii::app()->language); // Find the brand $brand = $this->brand; $brand_localization = $this->brand->localizationForLanguage(Yii::app()->language, $accept_substitute = true); $productArray["brand"] = array("id" => intval($this->brand_id), "name" => $brand_localization ? $brand_localization->name : null, "visible" => $brand ? $brand->visible == 1 ? true : false : false); $main_image = $localization->getMainImage(); $productArray["image"] = array("id" => null, "extension" => null, "locale_id" => null, "small" => ProductImage::placehoderForSize(200, 200), "large" => ProductImage::placehoderForSize(800, 800), "base_url" => ProductImage::getImageGeneratorBaseUrl()); if ($main_image !== null) { $productArray["image"]["id"] = intval($main_image->identifier); $productArray["image"]["extension"] = $main_image->extension; $productArray["image"]["locale_id"] = $main_image->locale_id; $productArray["image"]["small"] = $main_image->getImageURL(200, 200); $productArray["image"]["large"] = $main_image->getImageURL(800, 800); } // Loop through the categories to return the appropriate product categories foreach ($this->categories as $category) { $category_localization = $category->localizationForLanguage(Yii::app()->language, $accept_substitute = false); if ($category_localization !== null) { $productArray["categories"][] = array("id" => intval($category->id), "name" => $localization->name, "visible" => $category->visible == 1 ? true : false); } } Yii::app()->cache->set($cache_id, $productArray, $cache_duration); } return $productArray; }