/** * Generate and calculate a formatted price for a product. This function will * take in a product and a price, apply tax where necessary, convert it to * the displayed currency, format it, and if there's a retail price for the * product, show it struck out. * * Options passed as $options include: * - currencyConvert (true) - Convert the price in to the active currency * - strikeRetail (true) - If there is an RRP, strike it out & show before the product * - displayInclusive (false) - Set to true if the returned price should include tax * - includesTax (null) - Set to true if $price already includes tax * - localeFormat (true) - Perform any locale formatting (formatPrice) * * @param array $product Array containing the product to format the price for. * @param double $price Price of the product to be formatted. * @param array $options Array of options for formatting the price. */ function formatProductPrice($product, $price, array $options = array()) { $defaultOptions = array( 'currencyConvert' => true, 'strikeRetail' => true, 'displayInclusive' => false, 'includesTax' => null, 'localeFormat' => true ); $options = array_merge($defaultOptions, $options); $actualPrice = calculateFinalProductPrice($product, $price, $options); // Apply taxes to the price $actualPrice = getClass('ISC_TAX')->getPrice( $actualPrice, $product['tax_class_id'], $options['displayInclusive'] ); // Convert to the current currency if($options['currencyConvert']) { $actualPrice = convertPriceToCurrency($actualPrice); } $output = ''; if(!$options['localeFormat']) { return $actualPrice; } if($product['prodretailprice'] > 0 && $options['strikeRetail'] && $product['prodretailprice'] > $actualPrice ) { $rrp = calculateFinalProductPrice($product, $product['prodretailprice']); $rrp = getClass('ISC_TAX')->getPrice( $rrp, $product['tax_class_id'], $options['displayInclusive'] ); $rrp = convertPriceToCurrency($rrp); $output .= '<strike class="RetailPriceValue">'.formatPrice($rrp).'</strike> '; } if($product['prodsaleprice'] > 0 && $product['prodsaleprice'] < $product['prodprice']) { $output .= '<span class="SalePrice">'.formatPrice($actualPrice).'</span>'; } else { $output .= formatPrice($actualPrice); } return $output; }
public function recalculateBasePrice() { if ($this->isCustomPrice) { return $this; } $priceOptions = array( 'quantity' => $this->getQuantity(), 'customerGroup' => $this->getQuote()->getCustomerGroupId(), ); $productData = $this->getProductData(); // Tack on the variation if there is one. There may not be, if we just // removed it. if (!empty($this->variationId)) { $priceOptions['variationModifier'] = $productData['variation']['vcpricediff']; $priceOptions['variationAdjustment'] = $productData['variation']['vcprice']; } $price = calculateFinalProductPrice($productData, $productData['prodcalculatedprice'], $priceOptions); $this->basePrice = $price; return $this; }
private function editOrderItemSearchAction() { if(empty($_REQUEST['q']) || empty($_REQUEST['quoteSession'])) { exit; } $quote = getClass('ISC_ADMIN_ORDERS')->getQuoteSession($_REQUEST['quoteSession']); if(!$quote) { exit; } $customerGroupId = $quote->getCustomerGroupId(); $_REQUEST['searchQuery'] = $_REQUEST['q']; // autocomplete plugin can send a limit which will be at most 11 but internally we limit this to 2-11 and // reduce it by 1 to get 1-10 and append the 'virtual' item result as #11 $limit = 11; if (isset($_REQUEST['limit'])) { $limit = max(2, min(10, (int)$_REQUEST['limit'])); } $limit--; $numProducts = 0; $result = getClass('ISC_ADMIN_PRODUCT')->_getProductList( 0, 'p.prodname', 'asc', $numProducts, 'DISTINCT p.*, '.GetProdCustomerGroupPriceSQL($customerGroupId), 10); $results = array(); while($product = $this->db->fetch($result)) { $isConfigurable = false; if($product['prodvariationid'] != 0 || $product['prodconfigfields'] != 0) { $isConfigurable = true; } $options = array( 'customerGroup' => $customerGroupId ); $price = calculateFinalProductPrice($product, $product['prodcalculatedprice'], $options); $price = formatPrice($price); $results[] = array( 'id' => $product['productid'], 'name' => $product['prodname'], 'link' => prodLink($product['prodname']), 'sku' => $product['prodcode'], 'isConfigurable' => $isConfigurable, 'price' => $price ); } $results[] = array( 'id' => 'virtual', 'virtualName' => $_REQUEST['q'], 'name' => GetLang('AddManualProduct'), 'className' => 'recordContentManual', 'price' => GetLang('AddManualProductHelp'), ); echo isc_json_encode($results); }
/** * 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; }