public function Action_GetProduct() { if(empty($this->router->request->details->productId)) { $this->BadRequest('The details->productId node is missing'); } $image = new ISC_PRODUCT_IMAGE(); // autoload helper so we can use exceptions defined in the product image class file unset($image); $productId = (int)$this->router->request->details->productId; $productClass = new ISC_PRODUCT($productId); $product = $productClass->_product; // stuff that comes directly from the database may be incomplete -- use the image library to make sure try { if (!$product['imageid']) { // no image present in data so throw an exception just to force the removal of data below in the catch{} block throw new ISC_PRODUCT_IMAGE_EXCEPTION(); } $image = new ISC_PRODUCT_IMAGE(); $image->populateFromDatabaseRow($product); // call the image library to make sure resized images are present and then add full urls so they're useful for remote users $product['imagefiletiny'] = $image->getResizedUrl(ISC_PRODUCT_IMAGE_SIZE_TINY, true, true, false); $product['imagefilethumb'] = $image->getResizedUrl(ISC_PRODUCT_IMAGE_SIZE_THUMBNAIL, true, true, false); $product['imagefilestd'] = $image->getResizedUrl(ISC_PRODUCT_IMAGE_SIZE_STANDARD, true, true, false); $product['imagefilezoom'] = $image->getResizedUrl(ISC_PRODUCT_IMAGE_SIZE_ZOOM, true, true, false); // call the image library to make sure resized images are present and the sizes are correct $product['imagefiletinysize'] = implode('x', $image->getResizedFileDimensions(ISC_PRODUCT_IMAGE_SIZE_TINY)); $product['imagefilethumbsize'] = implode('x', $image->getResizedFileDimensions(ISC_PRODUCT_IMAGE_SIZE_THUMBNAIL)); $product['imagefilestdsize'] = implode('x', $image->getResizedFileDimensions(ISC_PRODUCT_IMAGE_SIZE_STANDARD)); $product['imagefilezoomsize'] = implode('x', $image->getResizedFileDimensions(ISC_PRODUCT_IMAGE_SIZE_ZOOM)); } catch (Exception $exception) { // some sort of problem when dealing with product images - remove image info from the response unset( $product['imagefiletiny'], $product['imagefilethumb'], $product['imagefilestd'], $product['imagefilezoom'], $product['imagefiletinysize'], $product['imagefilethumbsize'], $product['imagefilestdsize'], $product['imagefilezoomsize'], $product['imagedesc'], $product['imagedateadded'] ); } // direct data feed also includes some fields that are irrelevant or unwanted unset( $product['imagefile'], // don't provide a link to the non-water-marked image $product['imageprodid'], $product['imageprodhash'], $product['imageisthumb'], $product['imagesort'] ); if(empty($product)) { return array(); } $product['prodlink'] = ProdLink($product['prodname']); // Fetch any images for the product $images = new ISC_PRODUCT_IMAGE_ITERATOR(ISC_PRODUCT_IMAGE::generateGetProductImagesFromDatabaseSql((int)$productId)); foreach ($images as $image) { /** @var $image ISC_PRODUCT_IMAGE */ $imageisthumb = 0; if ($image->getIsThumbnail()) { $imageisthumb = 1; } try { $product['images']['item'][] = array( 'imageid' => $image->getProductImageId(), 'imagefiletiny' => $image->getResizedUrl(ISC_PRODUCT_IMAGE_SIZE_TINY, true, true, false), 'imagefilethumb' => $image->getResizedUrl(ISC_PRODUCT_IMAGE_SIZE_THUMBNAIL, true, true, false), 'imagefilestd' => $image->getResizedUrl(ISC_PRODUCT_IMAGE_SIZE_STANDARD, true, true, false), 'imagefilezoom' => $image->getResizedUrl(ISC_PRODUCT_IMAGE_SIZE_ZOOM, true, true, false), 'imagefiletinysize' => implode('x', $image->getResizedFileDimensions(ISC_PRODUCT_IMAGE_SIZE_TINY)), 'imagefilethumbsize' => implode('x', $image->getResizedFileDimensions(ISC_PRODUCT_IMAGE_SIZE_THUMBNAIL)), 'imagefilestdsize' => implode('x', $image->getResizedFileDimensions(ISC_PRODUCT_IMAGE_SIZE_STANDARD)), 'imagefilezoomsize' => implode('x', $image->getResizedFileDimensions(ISC_PRODUCT_IMAGE_SIZE_ZOOM)), 'imageisthumb' => $imageisthumb, 'imagesort' => $image->getSort(), 'imagedesc' => $image->getDescription(), 'imagedateadded' => $image->getDateAdded(), ); } catch (Exception $exception) { // skip this image and bring down the count of product images obtained from ISC_PRODUCT $product['numimages']--; } } // Fetch the categories this product belongs to $trailCategories = array(); $crumbList = array(); $query = " SELECT c.categoryid, c.catparentlist FROM [|PREFIX|]categoryassociations ca JOIN [|PREFIX|]categories c ON (c.categoryid=ca.categoryid) WHERE ca.productId='".(int)$productId."' "; $result = $GLOBALS['ISC_CLASS_DB']->Query($query); while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) { if ($row['catparentlist'] == '') { $row['catparentlist'] = $row['categoryid']; } $cats = explode(",", $row['catparentlist']); $trailCategories = array_merge($trailCategories, $cats); $crumbList[$row['categoryid']] = $row['catparentlist']; } $trailCategories = implode(",", array_unique($trailCategories)); $categories = array(); if ($trailCategories != '') { // Now load the names for the parent categories from the database $query = " SELECT categoryid, catname FROM [|PREFIX|]categories WHERE categoryid IN (".$trailCategories.") "; $result = $GLOBALS['ISC_CLASS_DB']->Query($query); while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) { $categories[$row['categoryid']] = $row['catname']; } } // Now we have all of the information we need to build the trails, lets actually build them foreach ($crumbList as $productcatid => $trail) { $cats = explode(',', $trail); $catName = ''; $catLink = CatLink($productcatid, $categories[$productcatid]); foreach ($cats as $categoryid) { if(isset($categories[$categoryid])) { if($catName) { $catName .= ' » '; } $catName .= $categories[$categoryid]; } } $product['categories']['item'][] = array( 'name' => $catName, 'link' => $catLink, 'id' => $productcatid ); } if($product['prodvariationid'] > 0) { if ($product['prodsaleprice'] != 0) { $variationBasePrice = $product['prodsaleprice']; } else { $variationBasePrice = $product['prodprice']; } $vop = $productClass->_prodvariationoptions; $vval = $productClass->_prodvariationvalues; foreach($productClass->_prodvariationcombinations as $variation) { $variationPrice = CurrencyConvertFormatPrice(CalcProductVariationPrice($variationBasePrice, $variation['vcpricediff'], $variation['vcprice'], $product)); $variationWeight = FormatWeight(CalcProductVariationWeight($product['prodweight'], $variation['vcweightdiff'], $variation['vcweight']), true); $variationName = array(); $options = explode(',', $variation['vcoptionids']); foreach($options as $k => $optionId) { $label = $vop[$k]; $variationName[] = $label.': '.$vval[$label][$optionId]; } $variationName = implode(', ', $variationName); $variationRow = array( 'name' => $variationName, 'id' => $variation['combinationid'], 'price' => $variationPrice, 'sku' => $variation['vcsku'], 'weight' => $variationWeight, ); if($product['prodinvtrack'] == 2) { $variationRow['stock'] = $variation['vcstock']; } if ($variation['vcimage']) { try { $image = new ISC_PRODUCT_IMAGE; $image->setSourceFilePath($variation['vcimage']); if($variation['vcimagethumb']) { $image->setResizedFilePath(ISC_PRODUCT_IMAGE_SIZE_THUMBNAIL, $variation['vcimagethumb']); $variationRow['thumb'] = $image->getResizedFilePath(ISC_PRODUCT_IMAGE_SIZE_THUMBNAIL, true, false); } if($variation['vcimagestd']) { $image->setResizedFilePath(ISC_PRODUCT_IMAGE_SIZE_STANDARD, $variation['vcimagestd']); $variationRow['standard'] = $image->getResizedFilePath(ISC_PRODUCT_IMAGE_SIZE_STANDARD, true, false); } if($variation['vcimagezoom']) { $image->setResizedFilePath(ISC_PRODUCT_IMAGE_SIZE_ZOOM, $variation['vcimagezoom']); $variationRow['image'] = $image->getResizedFilePath(ISC_PRODUCT_IMAGE_SIZE_ZOOM, true, false); } } catch (Exception $exception) { // nothing } } $product['variations']['item'][] = $variationRow; } } return $product; }
private function _SetImageData() { $this->_prodid = (int)$_GET['product_id']; // Load the product name $query = sprintf("select prodname from [|PREFIX|]products where productid='%d'", $GLOBALS['ISC_CLASS_DB']->Quote($this->GetProductId())); $result = $GLOBALS['ISC_CLASS_DB']->Query($query); $this->_prodname = $GLOBALS['ISC_CLASS_DB']->FetchOne($result, "prodname"); // Are we showing the image for a particular variation? if(isset($_GET['variation_id'])) { $this->_variationid = (int)$_GET['variation_id']; $query = "SELECT vcimage, vcimagezoom FROM [|PREFIX|]product_variation_combinations WHERE vcproductid='".$this->_prodid."' AND combinationid='".$this->_variationid."'"; $result = $GLOBALS['ISC_CLASS_DB']->Query($query); if (!$variation = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) { // Invalid variation exit; } if ($variation['vcimage'] && $variation['vcimagezoom']) { // use the product image library to get the url which will trigger a resize if necessary try { $productImage = new ISC_PRODUCT_IMAGE; $productImage->setSourceFilePath($variation['vcimage']); $productImage->setResizedFilePath(ISC_PRODUCT_IMAGE_SIZE_ZOOM, $variation['vcimagezoom']); $this->_variationImage = $productImage->getResizedUrl(ISC_PRODUCT_IMAGE_SIZE_ZOOM, true, false); } catch (Exception $exception) { // nothing } } } // Otherwise, just load general images for a product //else { // Load the images into an array $productImages = ISC_PRODUCT_IMAGE::getProductImagesFromDatabase($this->GetProductId()); if(!empty($productImages)) { $i = 0; foreach ($productImages as $productImage) { $imgDesc = ''; $zoomImg = ''; $tinyImg = ''; $thumbImg = ''; try{ $zoomImg = $productImage->getResizedUrl(ISC_PRODUCT_IMAGE_SIZE_ZOOM, true); } catch (Exception $exception) { // do nothing, will result in returning blank string, which is fine } try{ $thumbImg = $productImage->getResizedUrl(ISC_PRODUCT_IMAGE_SIZE_STANDARD, true); //$GLOBALS['ProductThumbURL'] = $thumbURL; } catch (Exception $exception) { } // if both standard image and zoom image not exist, go to the next image. if($thumbImg == '' && $zoomImg == '') { continue; } try{ $tinyImg = $productImage->getResizedUrl(ISC_PRODUCT_IMAGE_SIZE_TINY, true); } catch (Exception $exception) { // do nothing, will result in returning blank string, which is fine } $imgDesc = $productImage->getDescription(); if ($imgDesc == '') { $imgIndex= $i+1; $imgDesc = GetLang("Image")." ".$imgIndex; } if($zoomImg!= '' ) { $this->_prodimages['zoom'][] = $zoomImg; //use standard image if zoom image not exist. } else { $this->_prodimages['zoom'][] = $thumbImg; } $this->_prodimages['tiny'][] = $tinyImg; $this->_prodImagesDescriptions[] = $imgDesc; $i++; } //} // How many images are there? $this->_prodnumimages = count($this->_prodimages['zoom']); } // Which image should we show? if(isset($_GET['current_image'])) { $this->_prodcurrentimage = (int)$_GET['current_image']; } elseif(isset($_GET['variation_id'])) { $this->_prodcurrentimage = 'variation'; } }
/** * Build the HTML for the thumbnail image of a product. * * @todo refactor * @param string The filename of the thumbnail. * @param string The URL that the thumbnail should link to. * @param string The optional target for the link. * @return string The built HTML for the thumbnail. */ function ImageThumb($imageData, $link='', $target='', $class='') { $altText = ""; if(!is_array($imageData)) { $thumb = $imageData; } else { $image = new ISC_PRODUCT_IMAGE; $image->populateFromDatabaseRow($imageData); $altText = $image->getDescription(); if(empty($altText) && !empty($imageData['prodname'])) { $altText = $imageData['prodname']; } try { $thumb = $image->getResizedUrl(ISC_PRODUCT_IMAGE_SIZE_THUMBNAIL, true); } catch (Exception $exception) { $thumb = ''; } unset($image); } if(!$thumb) { switch(GetConfig('DefaultProductImage')) { case 'template': $thumb = $GLOBALS['IMG_PATH'].'/ProductDefault.gif'; break; case '': $thumb = ''; break; default: $thumb = GetConfig('ShopPath').'/'.GetConfig('DefaultProductImage'); } } /* else { $thumbPath = APP_ROOT.'/'.GetConfig('ImageDirectory').'/'.$thumb; $thumb = $GLOBALS['ShopPath'].'/'.GetConfig('ImageDirectory').'/'.$thumb; } */ if(!$thumb) { return ''; } if($target != '') { $target = 'target="'.$target.'"'; } if($class != '') { $class = 'class="'.$class.'"'; } $imageThumb = ''; if($link != '') { $imageThumb .= '<a href="'.$link.'" '.$target.' '.$class.'>'; } $imageSize = @getimagesize($thumbPath); if(is_array($imageSize) && !empty($imageSize)) { $imageThumb .= '<img src="'.$thumb.'" alt="'.$altText.'" ' . $imageSize[3] . ' />'; }else{ $imageThumb .= '<img src="'.$thumb.'" alt="'.$altText.'" />'; } if($link != '') { $imageThumb .= '</a>'; } return $imageThumb; }