Example #1
0
 public function AddItem($productId, $quantity = 1, $variationDetails = null, $configurableOptions = array(), $cartItemId = null, $options = array())
 {
     $itemId = parent::AddItem($productId, $quantity, $variationDetails, $configurableOptions, $cartItemId, $options);
     if ($itemId === false) {
         return false;
     }
     $item =& $this->cartSession['ITEMS'][$itemId];
     // load up product data for the new item
     $query = "\n\t\t\t\tSELECT p.productid, prodcurrentinv, prodinvtrack, prodweight, prodwidth, prodheight, prodvariationid,\n\t\t\t\t\tproddepth, prodname, prodprice, prodretailprice, prodsaleprice, prodcalculatedprice,\n\t\t\t\t\tprodavailability, prodtype, prodcostprice, prodfixedshippingcost, prodfreeshipping, prodoptionsrequired,\n\t\t\t\t\timageisthumb, imagefile, prodistaxable, prodwrapoptions, prodvendorid, prodeventdaterequired, prodeventdatefieldname, " . GetProdCustomerGroupPriceSQL() . ",\n\t\t\t\t\t(SELECT group_concat(ca.categoryid SEPARATOR ',') FROM [|PREFIX|]categoryassociations ca WHERE p.productid=ca.productid) AS categoryids\n\t\t\t\tFROM [|PREFIX|]products p\n\t\t\t\tLEFT JOIN [|PREFIX|]product_images pi ON (p.productid=pi.imageprodid AND pi.imageisthumb=1)\n\t\t\t\tWHERE p.productid = " . $GLOBALS['ISC_CLASS_DB']->Quote($productId);
     $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
     $item['data'] = $GLOBALS['ISC_CLASS_DB']->Fetch($result);
     // If this item is a variation, load in the weight etc
     if ($variationDetails) {
         $query = "SELECT combinationid, vcproductid, vcthumb, vcweight, vcweightdiff, vcstock\n\t\t\t\t\tFROM [|PREFIX|]product_variation_combinations\n\t\t\t\t\tWHERE combinationid = " . $GLOBALS['ISC_CLASS_DB']->Quote($variationDetails);
         $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
         $variationInfo = $GLOBALS['ISC_CLASS_DB']->Fetch($result);
         // Override the thumbnail for this item with the variation thumbnail
         if ($variationInfo['vcthumb']) {
             $item['data']['imagefile'] = $variationInfo['vcthumb'];
         }
         if ($variationInfo['vcweight'] != 0) {
             $item['data']['prodweight'] = CalcProductVariationWeight($item['data']['prodweight'], $variationInfo['vcweightdiff'], $variationInfo['vcweight']);
         }
         // Store the # of this combination we have in stock
         if ($item['data']['prodinvtrack'] == 2) {
             $item['data']['prodcurrentinv'] = $variationInfo['vcstock'];
         }
     }
     $this->cartProducts = array();
     return $itemId;
 }
Example #2
0
	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;
	}
Example #3
0
 public function GetProductVariationCombinationJavascript()
 {
     if (empty($this->_prodvariationcombinations)) {
         return '';
     }
     $script = "<script type=\"text/javascript\">\n";
     $script .= " var VariationList = new Array();\n";
     foreach ($this->_prodvariationcombinations as $variation) {
         $variationPrice = CurrencyConvertFormatPrice(CalcProductVariationPrice($this->_prodcalculatedprice, $variation['vcpricediff'], $variation['vcprice'], $this->_product));
         $youSave = $this->_prodretailprice - CalcProductVariationPrice($this->_prodcalculatedprice, $variation['vcpricediff'], $variation['vcprice'], $this->_product);
         $variationSaveAmount = '';
         if ($youSave > 0) {
             $variationSaveAmount = CurrencyConvertFormatPrice($youSave);
         }
         $variationWeight = FormatWeight(CalcProductVariationWeight($this->_prodweight, $variation['vcweightdiff'], $variation['vcweight']), true);
         if ($variation['vcthumb'] != '') {
             $thumb = $GLOBALS['ShopPath'] . "/" . GetConfig('ImageDirectory') . "/" . $variation['vcthumb'];
         } else {
             $thumb = '';
         }
         if ($variation['vcimage'] != '') {
             $image = $GLOBALS['ShopPath'] . '/' . GetConfig('ImageDirectory') . '/' . $variation['vcimage'];
         } else {
             $image = '';
         }
         $ids = explode(",", $variation['vcoptionids']);
         $optionList = array();
         foreach ($ids as $id) {
             $key = $this->_prodvariationslookup[$id];
             $optionList[$key] = $id;
         }
         ksort($optionList);
         $optionList = implode(",", $optionList);
         $script .= " VariationList[" . $variation['combinationid'] . "] = {";
         $script .= " combination: '" . $optionList . "', ";
         $script .= " saveAmount: '" . $variationSaveAmount . "', ";
         $script .= " price: '" . $variationPrice . "', ";
         $script .= " sku: '" . isc_html_escape($variation['vcsku']) . "', ";
         $script .= " weight: '" . $variationWeight . "', ";
         $script .= " thumb: '" . $thumb . "', ";
         $script .= " image: '" . $image . "', ";
         // Tracking inventory on a product variation level
         if ($this->_prodinvtrack == 2) {
             if (GetConfig('ShowInventory') == 1) {
                 $script .= "stock: '" . $variation['vcstock'] . "', ";
             }
             if ($variation['vcstock'] <= 0) {
                 $script .= " instock: false";
             } else {
                 $script .= " instock: true";
             }
         } else {
             $script .= " instock: true";
         }
         $script .= "};\n";
     }
     $script .= "</script>";
     return $script;
 }
Example #4
0
		/**
		* Gets an array of formatted details for a specific combination row such as pricing, weight, images
		*
		* @param array Database row of combination information
		* @param int The customer group to use to determine the final product price (used when getting variation details from back end quote system)
		* @return array The formatted combination details
		*/
		public function GetCombinationDetails($combination, $customerGroupId = null)
		{
			$thumb = '';
			$image = '';

			$priceOptions = array(
				'variationModifier'		=> $combination['vcpricediff'],
				'variationAdjustment'	=> $combination['vcprice'],
			);

			if (!is_null($customerGroupId)) {
				$priceOptions['customerGroup'] = $customerGroupId;
			}

			if($this->GetProductCallForPricingLabel()) {
				$variationPrice = $GLOBALS['ISC_CLASS_TEMPLATE']->ParseGL($this->GetProductCallForPricingLabel());
			}
			else {
				$variationPrice = formatProductDetailsPrice($this->_product, $priceOptions);
			}

			$calculatedPrice = calculateFinalProductPrice($this->_product, $this->_prodcalculatedprice, $priceOptions);
			$calculatedPrice = getClass('ISC_TAX')->getPrice(
				$calculatedPrice,
				$this->_product['tax_class_id'],
				getConfig('taxDefaultTaxDisplayProducts')
			);

			$variationSaveAmount = '';
			if($this->_prodretailprice > 0) {
				$rrp = calculateFinalProductPrice($this->_product, $this->_prodretailprice, $priceOptions);
				$rrp = getClass('ISC_TAX')->getPrice(
					$rrp,
					$this->_product['tax_class_id'],
					getConfig('taxDefaultTaxDisplayProducts')
				);

				$youSave = $rrp - $calculatedPrice;
				if($youSave > 0) {
					$variationSaveAmount = CurrencyConvertFormatPrice($youSave);
				}
			}

			$variationWeight = FormatWeight(CalcProductVariationWeight($this->_prodweight, $combination['vcweightdiff'], $combination['vcweight']), true);

			// use the product image class for automatic resizing
			$productImage = new ISC_PRODUCT_IMAGE;
			if ($combination['vcimage']) {
				$productImage->setSourceFilePath($combination['vcimage']);

				if ($combination['vcimagestd']) {
					$productImage->setResizedFilePath(ISC_PRODUCT_IMAGE_SIZE_STANDARD, $combination['vcimagestd']);
					$thumb = $productImage->getResizedUrl(ISC_PRODUCT_IMAGE_SIZE_STANDARD, true, false);
				}

				if ($combination['vcimagezoom']) {
					//check if zoom image is large enough for image zoomer
					try {
						$productImage->setResizedFilePath(ISC_PRODUCT_IMAGE_SIZE_ZOOM, $combination['vcimagezoom']);
						list($zoomWidth, $zoomHeight) = $productImage->getResizedFileDimensions(ISC_PRODUCT_IMAGE_SIZE_ZOOM, true, false);
						if ($zoomWidth >= ISC_PRODUCT_IMAGE_MIN_ZOOM_WIDTH || $zoomHeight >= ISC_PRODUCT_IMAGE_MIN_ZOOM_HEIGHT) {
							$image = $productImage->getResizedUrl(ISC_PRODUCT_IMAGE_SIZE_ZOOM, true, false);
						}
					} catch (Exception $exception) {
						// do nothing, will result in returning blank string, which is fine
					}
				}
			}

			// Tracking inventory on a product variation level
			if($this->_prodinvtrack == 2) {
				$stock = $combination['vcstock'];
			}
			else {
				$stock = $this->_prodcurrentinv;
			}

			if($stock <= 0 && $this->_prodinvtrack != 0) {
				$instock = false;
			}
			else {
				$instock = true;
			}

			$return = array(
				'combinationid'			=> $combination['combinationid'],
				'saveAmount'			=> $variationSaveAmount,
				'price'					=> $variationPrice,
				'unformattedPrice'      => formatPrice($calculatedPrice, false, false),
				'sku'					=> $combination['vcsku'],
				'weight'				=> $variationWeight,
				'thumb'					=> $thumb,
				'image'					=> $image,
				'instock'				=> $instock
			);

			if (GetConfig('ShowInventory') == 1 && (!$this->IsPreOrder() || GetConfig('ShowPreOrderInventory') == 1)) {
				$return['stock'] = $stock;
			}
			return $return;
		}