Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Warning: Division by zero error


KJ666

Recommended Posts

Posted

Help im getting this error

Warning: Division by zero in /home/****/public_html/*****/admin/includes/classes/PriceFormatter.php on line 161

 

This was after placing the add on (which inculded that file).

Code from that page, middle function has the problem.

 

  function hasQuantityPrice() {
   return $this->hasQuantityPrice;
 }

 function getDiscountSaving($original_price, $discount_price) {
   $difference = $original_price - $discount_price;
   return round (($difference / $original_price) * 100) . '%';
 }

 function getPriceString($style='productPriceInBox') {
   global $currencies;

Posted

Can you tell what function getDiscountSaving() is being called with for $original_price? Is is a 0 somewhere? Is it a formatted string rather than a number (e.g., "$985.95" rather than "985.95")? At worst, you could put in an echo "original price = $original_price <br>"; temporary first line in the function, to see what's being fed to the function.

  • 2 years later...
Posted

Just for future references when i need to duplicate my site again and run into this issue...again, I'm posting what worked for me when I got the

Warning: Division by zero in /home/****/public_html/*****/admin/includes/classes/PriceFormatter.php on line...

function getDiscountSaving($original_price, $discount_price) {

echo "original price = $original_price <br>";

$difference = $original_price - $discount_price;

return round (($difference / $original_price) * 100) . '%';

}

Posted

Well, that's not really a fix. It's a diagnostic. We want to see what $original_price looks like... is it 0, or null, or not a pure number, or what? Then we have to find out who's calling getDiscountSaving() to see where the first argument (original price) came from, etc., down the line until the source of the problem is discovered.

Posted

Ok...it didn't work... it worked last night, but for some reason it stopped... UGh!

Posted

If anyone can figure out what I'm missing, I'd really appreciate it! :) Here's my PriceFormatter.php code... I have the qpbpp and the msrp contributions installed. The calculations in the QPBPP is actually based off MSRP now.

 

I'm getting my error with this line:

function getDiscountSaving($original_price, $discount_price) {

$difference = $original_price - $discount_price;

return round (($difference / $original_price) * 100) . '%';

 

<?php
/*
 $Id: PriceFormatter.php,v 1.9 2008/05/13 Exp $
 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com
 Copyright (c) 2003 osCommerce
 Released under the GNU General Public License
*/
/*
   PriceFormatter.php - module to support quantity pricing
   Created 2003, Beezle Software based on some code mods by WasaLab Oy (Thanks!)
   Refactored 2008, Moved pricebreak data into dedicated table
*/
class PriceFormatter {
 function PriceFormatter() {
   $this->thePrice = -1;
   $this->taxClass = -1;
   $this->qtyBlocks = 1;
   $this->price_breaks = array();
   $this->hasQuantityPrice = false; 
   $this->hiPrice = -1;
   $this->lowPrice = -1;
   $this->hasSpecialPrice = false; //tep_not_null($this->specialPrice);
   $this->specialPrice = NULL; //$prices['specials_new_products_price'];
 }
 function loadProduct($product_id, $language_id = 1, $listing = NULL, $price_breaks_from_listing = NULL) {
   global $pfs;

   $product_id = tep_get_prid($product_id); // only use integers here

   // returns NULL if the price break information is not yet stored
   $price_formatter_data = $pfs->getPriceFormatterData($product_id);
   if (tep_not_null($price_formatter_data)) {

  //Use data from the cache with some conversions
  $price_formatter_data['products_special_price'] = $price_formatter_data['specials_new_products_price'];
  $price_formatter_data['qtyBlocks'] = $price_formatter_data['products_qty_blocks'];
   } elseif ($listing == NULL) {

  //Collect required data
   $sql = "select pd.products_name, p.products_model, p.products_image, p.products_id," .
  " p.manufacturers_id, p.products_msrp, p.products_price, p.products_weight, p.products_quantity," .
  " p.products_qty_blocks, p.products_tax_class_id," .
  " IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price," .
  " ptdc.discount_categories_id from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on " .
  " p.products_id = s.products_id left join " . TABLE_PRODUCTS_TO_DISCOUNT_CATEGORIES . " ptdc on " .
  " p.products_id = ptdc.products_id, " .
  " " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1'" .
  " and pd.products_id = p.products_id " .
  " and p.products_id = '" . (int)$product_id . "'" .
  " and pd.language_id = '". (int)$language_id ."'";
  $product_info_query = tep_db_query($sql);
  $product_info = tep_db_fetch_array($product_info_query);
  //Price-breaks
    $price_breaks_array = array();
    $price_breaks_query = tep_db_query("select products_price, products_qty from " . TABLE_PRODUCTS_PRICE_BREAK . " where products_id = '" . (int)$product_id . "' order by products_qty");
    while ($price_break = tep_db_fetch_array($price_breaks_query)) {
	  $price_breaks_array[] = $price_break;
    }

  //Compose cachable structure
  $price_formatter_data = array(
    'products_msrp' => $product_info['products_msrp'],
    'products_price' => $product_info['products_price'],
    'products_special_price' => $product_info['specials_new_products_price'],
    'products_tax_class_id' => $product_info['products_tax_class_id'],
    'discount_categories_id' => $product_info['discount_categories_id'],
    'products_name' => $product_info['products_name'],
    'products_model' => $product_info['products_model'],
    'products_image' => $product_info['products_image'],
    'products_weight' => $product_info['products_weight'],
    'products_quantity' => $product_info['products_quantity'],
    'price_breaks' => $price_breaks_array,
    'qtyBlocks' => $product_info['products_qty_blocks']);
  //Add to cache
  $pfs->addPriceFormatterData(tep_get_prid($product_id), $price_formatter_data);
   } else { // data from product listing
  //Compose cachable structure
  $price_formatter_data = array(
    'products_msrp' => $listing['products_msrp'],
    'products_price' => $listing['products_price'],
    'products_special_price' => $listing['specials_new_products_price'],
    'products_tax_class_id' => $listing['products_tax_class_id'],
    'discount_categories_id' => $listing['discount_categories_id'],
    'products_name' => $listing['products_name'],
    'products_model' => $listing['products_model'],
    'products_image' => $listing['products_image'],
    'products_weight' => $listing['products_weight'],
    'products_quantity' => $listing['products_quantity'],
    'price_breaks' => $price_breaks_from_listing,
    'qtyBlocks' => $listing['products_qty_blocks']);
   //Add to cache
  $pfs->addPriceFormatterData(tep_get_prid($product_id), $price_formatter_data);
   }
   //Assign members
   $this->theMSRP = $price_formatter_data['products_msrp'];
   $this->thePrice = $price_formatter_data['products_price'];
   $this->taxClass = $price_formatter_data['products_tax_class_id'];
   $this->qtyBlocks = $price_formatter_data['qtyBlocks'];
   $this->discount_categories_id = $price_formatter_data['discount_categories_id'];
   $this->price_breaks = $price_formatter_data['price_breaks'];
   $this->specialPrice = $price_formatter_data['products_special_price'];
   $this->hasSpecialPrice = tep_not_null($this->specialPrice);
   //Custom	 
   $this->hasQuantityPrice = false;
   $this->hiPrice = $this->thePrice;
   $this->lowPrice = $this->thePrice;
   if (count($this->price_breaks) > 0) {
  $this->hasQuantityPrice = true;
  foreach($this->price_breaks as $price_break) {
    $this->hiPrice = max($this->hiPrice, $price_break['products_price']);
    $this->lowPrice = min($this->lowPrice, $price_break['products_price']);
  }
   }

   /*
   Change support special prices
   If any price level has a price greater than the special
   price lower it to the special price
   If product is in the shopping_cart $this->price_breaks can be empty
   */
   if (true == $this->hasSpecialPrice && is_array($this->price_breaks)) {
  foreach($this->price_breaks as $key => $price_break) {
    $this->price_breaks[$key]['products_price'] = min($price_break['products_price'], $this->specialPrice);
  }
   }
   //end changes to support special prices
 }

 function computePrice($qty, $nof_other_items_in_cart_same_cat = 0)
 {
   $qty = $this->adjustQty($qty);
   // Add the number of other items in the cart from the same category to see if a price break is reached
   $qty += $nof_other_items_in_cart_same_cat;
   // Compute base price, taking into account the possibility of a special
   $price = (true == $this->hasSpecialPrice) ? $this->specialPrice : $this->thePrice;
   if (is_array($this->price_breaks) && count($this->price_breaks) > 0) {
  foreach($this->price_breaks as $price_break) {
    if ($qty >= $price_break['products_qty']) {
	  $price = $price_break['products_price'];
    }
  }
   } // end if (is_array($this->price_breaks) && count($this->price_breaks) > 0)
   return $price;
 }
 function adjustQty($qty, $qtyBlocks = NULL) {
   // Force QTY_BLOCKS granularity
   if(!tep_not_null($qtyBlocks))
   {
  $qtyBlocks = $this->getQtyBlocks();
   }

   if ($qty < 1)
  $qty = 1;
   if ($qtyBlocks >= 1)
   {
  if ($qty < $qtyBlocks)
    $qty = $qtyBlocks;
  if (($qty % $qtyBlocks) != 0)
    $qty += ($qtyBlocks - ($qty % $qtyBlocks));
   }
   return $qty;
 }

 function getQtyBlocks() {
   return $this->qtyBlocks;
 }
 function get_discount_category() {
   return $this->discount_categories_id;
 }
function getMSRP() {
return $this->theMSRP;
}
 function getPrice() {
   return $this->thePrice;
 }
 function getLowPrice() {
   return $this->lowPrice;
 }
 function getHiPrice() {
   return $this->hiPrice;
 }
 function hasSpecialPrice() {
   return $this->hasSpecialPrice;
 }
 function hasQuantityPrice() {
   return $this->hasQuantityPrice;
 }

 function getDiscountSaving($original_price, $discount_price) {
   $difference = $original_price - $discount_price;
   return round (($difference / $original_price) * 100) . '%';
 }
 function getPriceString($style='productPriceInBox') {
   global $currencies;
   // If you want to change the format of the price/quantity table
   // displayed on the product information page, here is where you do it.
   if(true == $this->hasQuantityPrice) {
  $lc_text = '<table border="0" cellspacing="0" cellpadding="0">
  <tr valign="center">
  <td class="BuyMoreSaveMore">BUY MORE!  SAVE MORE!</td>
  </tr>

  <tr valign="top">
  <td>
  <table border="0" cellspacing="0" cellpadding="4" class="infobox">';
		  $lc_text .= '<tr valign="top">
		  <td width="120" style="border-left:1px solid #8d8d8d;" class="qtyInfoBoxHeading">' . 'Quantity:' .'</td>
		  <td align="center" class="qtyInfoBoxHeading">MSRP:'. '</td>';  
  foreach($this->price_breaks as $price_break) {
    $lc_text .= '<td align="center" width="50" class="qtyInfoBoxHeading">'
	  . $price_break['products_qty']
	  .'+</td>';
  }
  //$lc_text .= '<tr valign="top"><td width="120" style="border-left:1px solid #8d8d8d;" class="qtyInfoBoxContents">' . TEXT_PRICE_PER_PIECE . '</td><td align="center" width="50" class="qtyInfoBoxContents">';
    $lc_text .= '<tr valign="top"><td width="120" style="border-left:1px solid #8d8d8d;" class="qtyInfoBoxContents">' . TEXT_PRICE_PER_PIECE . '</td><td align="center" width="50" class="qtyInfoBoxContents">' . $currencies->display_price($this->theMSRP, tep_get_tax_rate($this->taxClass)) . '</td>';
  if (true == $this->hasSpecialPrice) {
    $lc_text .= '<s>'
    . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass))
    . '</s>  <span class="productSpecialPrice">'
    . $currencies->display_price($this->specialPrice, tep_get_tax_rate($this->taxClass))
    . '</span> '
    .'</td>';
  } else {
    $lc_text .= ''
    . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass))
    . '</td>';
  }
  foreach($this->price_breaks as $price_break) {
    $lc_text .= '<td align="center" width="50" class="qtyInfoBoxContents">'
	  . $currencies->display_price($price_break['products_price'], tep_get_tax_rate($this->taxClass))
	  .'</td>';
  }
  $lc_text .= '</tr>';

  // Begin saving calculation
  $lc_text .= '<tr valign="top"><td width="120" style="border-left:1px solid #8d8d8d;" class="qtyInfoBoxContents">' . 'Savings:' . '</td>';

  if (true == $this->hasSpecialPrice) {
    $lc_text .= '<td align="center" class="qtyInfoBoxContents">'
    . $this->getDiscountSaving($this->theMSRP, $this->specialPrice)
    .'</td>';
  } else {
    $lc_text .= '<td align="center" class="qtyInfoBoxContents">- </td>';
  }
  foreach($this->price_breaks as $price_break) {
    $lc_text .= '<td align="center" width="50" class="qtyInfoBoxContents">'
    . $this->getDiscountSaving($this->theMSRP, $price_break['products_price'])
    .'</td>';
  }
  $lc_text .= '</tr></table></td></tr></table>';
   } else {
  if (true == $this->hasSpecialPrice) {
    $lc_text = ' <s>'
    . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass))
    . '</s>  <span class="productSpecialPrice">'
    . $currencies->display_price($this->specialPrice, tep_get_tax_rate($this->taxClass))
    . '</span> ';
  } else {
    $lc_text = ' '
    . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass))
    . ' ';
  }
   }
   return $lc_text;
 }
 function getPriceStringShort() {
   global $currencies;
   if (true == $this->hasSpecialPrice) {
    $lc_text = ' <big><s>'
    . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass))
    . '</s>  <br><span class="productSpecialPrice">' . TEXT_ON_SALE . ' '
    . $currencies->display_price($this->specialPrice, tep_get_tax_rate($this->taxClass))
    . '</big></span> <br><br><br>';
   } elseif (true == $this->hasQuantityPrice) {
  $lc_text = ' <big>' . TEXT_PRICE_BREAKS . ' '
  . $currencies->display_price($this->lowPrice, tep_get_tax_rate($this->taxClass))
  . ' </big><br><br><br>';
   } else {
    $lc_text = ' <big>'
    . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass))
    . ' </big><br><br><br>';
   }
   return $lc_text;
 }
/* Old (original formatting)
 function getPriceString($style='"productPriceInBox"') {
   global $currencies;
   if (true == $this->hasSpecialPrice) {
  $lc_text = '<table align="top" border="1" cellspacing="0" cellpadding="0">';
  $lc_text .= '<tr><td align="center" class=' . $style. ' colspan="2">';
  $lc_text .= ' <s>'
    . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass))
    . '</s>  <span class="productSpecialPrice">'
    . $currencies->display_price($this->specialPrice, tep_get_tax_rate($this->taxClass))
    . '</span> '
    .'</td></tr>';
   }
   else
   {
  $lc_text = '<table align="top" border="1" cellspacing="0" cellpadding="0">';
  $lc_text .= '<tr><td align="center" class=' . $style. ' colspan="2">'
    . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass))
    . '</td></tr>';
   }

   // If you want to change the format of the price/quantity table
   // displayed on the product information page, here is where you do it.
   if(true == $this->hasQuantityPrice) {
  foreach($this->price_breaks as $price_break) {
    $lc_text .= '<tr><td class='.$style.'>'
	  . $price_break['products_qty']
	  .'+ </td><td class='.$style.'>'
	  . $currencies->display_price($price_break['products_price'], tep_get_tax_rate($this->taxClass))
	  .'</td></tr>';
  }
  $lc_text .= '</table>';
   } else {
  if (true == $this->hasSpecialPrice) {
    $lc_text = ' <s>'
	  . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass))
	  . '</s>  <span class="productSpecialPrice">'
	  . $currencies->display_price($this->specialPrice, tep_get_tax_rate($this->taxClass))
	  . '</span> ';
  } else {
    $lc_text = ' '
	  . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass))
	  . ' ';
  }
   }
   return $lc_text;
 }
 function getPriceStringShort() {
   global $currencies;
   if (true == $this->hasSpecialPrice) {
  $lc_text = ' <s>'
    . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass))
    . '</s>  <span class="productSpecialPrice">'
    . $currencies->display_price($this->specialPrice, tep_get_tax_rate($this->taxClass))
    . '</span> ';
   } else {
  if(true == $this->hasQuantityPrice) {
    $lc_text = ' '
	  . $currencies->display_price($this->lowPrice, tep_get_tax_rate($this->taxClass))
	  . ' - '
	  . $currencies->display_price($this->hiPrice, tep_get_tax_rate($this->taxClass))
	  . ' ';
  } else {
    $lc_text = ' '
	  . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass))
	  . ' ';
  }
   }
   return $lc_text;
 }
 */
}
?>

Posted

It appears that $this->theMSRP is not properly defined. You'll need to look at where it's defined (from $price_formatter_data['products_msrp'] etc. up the food chain) to see where it failed to get a good value, or even lost its value once assigned.

Posted

Got it! Thanks to my developer! Yay!

 

&--#60;?php
/*
 $Id: PriceFormatter.php,v 1.9 2008/05/13 Exp $
 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com
 Copyright (c) 2003 osCommerce
 Released under the GNU General Public License
*/
/*
PriceFormatter.php - module to support quantity pricing
Created 2003, Beezle Software based on some code mods by WasaLab Oy (Thanks!)
Refactored 2008, Moved pricebreak data into dedicated table
*/
class PriceFormatter {
 function PriceFormatter() {
$this-&--#62;thePrice = -1;
$this-&--#62;taxClass = -1;
$this-&--#62;qtyBlocks = 1;
$this-&--#62;price_breaks = array();
$this-&--#62;hasQuantityPrice = false;
$this-&--#62;hiPrice = -1;
$this-&--#62;lowPrice = -1;
$this-&--#62;hasSpecialPrice = false; //tep_not_null($this-&--#62;specialPrice);
$this-&--#62;specialPrice = NULL; //$prices['specials_new_products_price'];
 }
 function loadProduct($product_id, $language_id = 1, $listing = NULL, $price_breaks_from_listing = NULL) {
global $pfs;

$product_id = tep_get_prid($product_id); // only use integers here

// returns NULL if the price break information is not yet stored
$price_formatter_data = $pfs-&--#62;getPriceFormatterData($product_id);
if (tep_not_null($price_formatter_data)) {

  //Use data from the cache with some conversions
  $price_formatter_data['products_special_price'] = $price_formatter_data['specials_new_products_price'];
  $price_formatter_data['qtyBlocks'] = $price_formatter_data['products_qty_blocks'];
} elseif ($listing == NULL) {

  //Collect required data
   $sql = "select pd.products_name, p.products_model, p.products_image, p.products_id," .
  " p.manufacturers_id, p.products_msrp, p.products_price, p.products_weight, p.products_quantity," .
  " p.products_qty_blocks, p.products_tax_class_id," .
  " IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price," .
  " ptdc.discount_categories_id from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on " .
  " p.products_id = s.products_id left join " . TABLE_PRODUCTS_TO_DISCOUNT_CATEGORIES . " ptdc on " .
  " p.products_id = ptdc.products_id, " .
  " " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1'" .
  " and pd.products_id = p.products_id " .
  " and p.products_id = '" . (int)$product_id . "'" .
  " and pd.language_id = '". (int)$language_id ."'";
  $product_info_query = tep_db_query($sql);
  $product_info = tep_db_fetch_array($product_info_query);
  //Price-breaks
	$price_breaks_array = array();
	$price_breaks_query = tep_db_query("select products_price, products_qty from " . TABLE_PRODUCTS_PRICE_BREAK . " where products_id = '" . (int)$product_id . "' order by products_qty");
	while ($price_break = tep_db_fetch_array($price_breaks_query)) {
	  $price_breaks_array[] = $price_break;
	}

  //Compose cachable structure
  $price_formatter_data = array(
	'products_msrp' =&--#62; $product_info['products_msrp'],
	'products_price' =&--#62; $product_info['products_price'],
	'products_special_price' =&--#62; $product_info['specials_new_products_price'],
	'products_tax_class_id' =&--#62; $product_info['products_tax_class_id'],
	'discount_categories_id' =&--#62; $product_info['discount_categories_id'],
	'products_name' =&--#62; $product_info['products_name'],
	'products_model' =&--#62; $product_info['products_model'],
	'products_image' =&--#62; $product_info['products_image'],
	'products_weight' =&--#62; $product_info['products_weight'],
	'products_quantity' =&--#62; $product_info['products_quantity'],
	'price_breaks' =&--#62; $price_breaks_array,
	'qtyBlocks' =&--#62; $product_info['products_qty_blocks']);
  //Add to cache
  $pfs-&--#62;addPriceFormatterData(tep_get_prid($product_id), $price_formatter_data);
} else { // data from product listing
  //Compose cachable structure
  $price_formatter_data = array(
	'products_msrp' =&--#62; $listing['products_msrp'],
	'products_price' =&--#62; $listing['products_price'],
	'products_special_price' =&--#62; $listing['specials_new_products_price'],
	'products_tax_class_id' =&--#62; $listing['products_tax_class_id'],
	'discount_categories_id' =&--#62; $listing['discount_categories_id'],
	'products_name' =&--#62; $listing['products_name'],
	'products_model' =&--#62; $listing['products_model'],
	'products_image' =&--#62; $listing['products_image'],
	'products_weight' =&--#62; $listing['products_weight'],
	'products_quantity' =&--#62; $listing['products_quantity'],
	'price_breaks' =&--#62; $price_breaks_from_listing,
	'qtyBlocks' =&--#62; $listing['products_qty_blocks']);
//Add to cache
  $pfs-&--#62;addPriceFormatterData(tep_get_prid($product_id), $price_formatter_data);
}
// echo "&--#60;pre&--#62;".print_r($price_formatter_data,true)."&--#60;/pre&--#62;";
//Assign members
$this-&--#62;theMSRP = $price_formatter_data['products_msrp'];
// $this-&--#62;theMSRP = $price_formatter_data['products_price'];
$this-&--#62;thePrice = $price_formatter_data['products_price'];
$this-&--#62;taxClass = $price_formatter_data['products_tax_class_id'];
$this-&--#62;qtyBlocks = $price_formatter_data['qtyBlocks'];
$this-&--#62;discount_categories_id = $price_formatter_data['discount_categories_id'];
$this-&--#62;price_breaks = $price_formatter_data['price_breaks'];
$this-&--#62;specialPrice = $price_formatter_data['products_special_price'];
$this-&--#62;hasSpecialPrice = tep_not_null($this-&--#62;specialPrice);
//Custom	
$this-&--#62;hasQuantityPrice = false;
$this-&--#62;hiPrice = $this-&--#62;thePrice;
$this-&--#62;lowPrice = $this-&--#62;thePrice;
if (count($this-&--#62;price_breaks) &--#62; 0) {
  $this-&--#62;hasQuantityPrice = true;
  foreach($this-&--#62;price_breaks as $price_break) {
	$this-&--#62;hiPrice = max($this-&--#62;hiPrice, $price_break['products_price']);
	$this-&--#62;lowPrice = min($this-&--#62;lowPrice, $price_break['products_price']);
  }
}

/*
Change support special prices
If any price level has a price greater than the special
price lower it to the special price
If product is in the shopping_cart $this-&--#62;price_breaks can be empty
*/
if (true == $this-&--#62;hasSpecialPrice && is_array($this-&--#62;price_breaks)) {
  foreach($this-&--#62;price_breaks as $key =&--#62; $price_break) {
	$this-&--#62;price_breaks[$key]['products_price'] = min($price_break['products_price'], $this-&--#62;specialPrice);
  }
}
//end changes to support special prices
 }

 function computePrice($qty, $nof_other_items_in_cart_same_cat = 0)
 {
$qty = $this-&--#62;adjustQty($qty);
// Add the number of other items in the cart from the same category to see if a price break is reached
$qty += $nof_other_items_in_cart_same_cat;
// Compute base price, taking into account the possibility of a special
$price = (true == $this-&--#62;hasSpecialPrice) ? $this-&--#62;specialPrice : $this-&--#62;thePrice;
if (is_array($this-&--#62;price_breaks) && count($this-&--#62;price_breaks) &--#62; 0) {
  foreach($this-&--#62;price_breaks as $price_break) {
	if ($qty &--#62;= $price_break['products_qty']) {
	  $price = $price_break['products_price'];
	}
  }
} // end if (is_array($this-&--#62;price_breaks) && count($this-&--#62;price_breaks) &--#62; 0)
return $price;
 }
 function adjustQty($qty, $qtyBlocks = NULL) {
// Force QTY_BLOCKS granularity
if(!tep_not_null($qtyBlocks))
{
  $qtyBlocks = $this-&--#62;getQtyBlocks();
}

if ($qty &--#60; 1)
  $qty = 1;
if ($qtyBlocks &--#62;= 1)
{
  if ($qty &--#60; $qtyBlocks)
	$qty = $qtyBlocks;
  if (($qty % $qtyBlocks) != 0)
	$qty += ($qtyBlocks - ($qty % $qtyBlocks));
}
return $qty;
 }

 function getQtyBlocks() {
return $this-&--#62;qtyBlocks;
 }
 function get_discount_category() {
return $this-&--#62;discount_categories_id;
 }
function getMSRP() {
return $this-&--#62;theMSRP;
}
 function getPrice() {
return $this-&--#62;thePrice;
 }
 function getLowPrice() {
return $this-&--#62;lowPrice;
 }
 function getHiPrice() {
return $this-&--#62;hiPrice;
 }
 function hasSpecialPrice() {
return $this-&--#62;hasSpecialPrice;
 }
 function hasQuantityPrice() {
return $this-&--#62;hasQuantityPrice;
 }
 function getDiscountSaving($original_price, $discount_price) {
$difference = $original_price - $discount_price;
return round (($difference / $original_price) * 100) . '%';
 }
 function getPriceString($style='productPriceInBox') {
global $currencies;
// If you want to change the format of the price/quantity table
// displayed on the product information page, here is where you do it.
if(true == $this-&--#62;hasQuantityPrice) {
  $lc_text = '
 &--#60;table border="0" cellspacing="0" cellpadding="0"&--#62;
  &--#60;tr valign="center"&--#62;
&--#60;td class="BuyMoreSaveMore"&--#62;BUY MORE!  SAVE MORE!&--#60;/td&--#62;
  &--#60;/tr&--#62;

  &--#60;tr valign="top"&--#62;
&--#60;td&--#62;
 &--#60;table border="0" cellspacing="0" cellpadding="4" class="infobox"&--#62;';
  $lc_text .= '
  &--#60;tr valign="top"&--#62;
   &--#60;td width="120" style="border-left:1px solid #8d8d8d;" class="qtyInfoBoxHeading"&--#62;' . 'Quantity:' .'&--#60;/td&--#62;
   &--#60;td align="center" class="qtyInfoBoxHeading"&--#62;MSRP:'. '&--#60;/td&--#62;';  
  foreach($this-&--#62;price_breaks as $price_break) {
	$lc_text .= '&--#60;td align="center" width="50" class="qtyInfoBoxHeading"&--#62;'
	  . $price_break['products_qty']
	  .'+&--#60;/td&--#62;';
  }
  //$lc_text .= '&--#60;tr valign="top"&--#62;&--#60;td width="120" style="border-left:1px solid #8d8d8d;" class="qtyInfoBoxContents"&--#62;' . TEXT_PRICE_PER_PIECE . '&--#60;/td&--#62;&--#60;td align="center" width="50" class="qtyInfoBoxContents"&--#62;';
	// $lc_text .= '
  // &--#60;tr valign="top"&--#62;
// &--#60;td width="120" style="border-left:1px solid #8d8d8d;" class="qtyInfoBoxContents"&--#62;' . TEXT_PRICE_PER_PIECE . '&--#60;/td&--#62;
// &--#60;td align="center" width="50" class="qtyInfoBoxContents"&--#62;' . $currencies-&--#62;display_price($this-&--#62;theMSRP, tep_get_tax_rate($this-&--#62;taxClass)) . '&--#60;/td&--#62;';
  if (true == $this-&--#62;hasSpecialPrice) {
	$lc_text .= '
  &--#60;tr valign="top"&--#62;
&--#60;td width="120" style="border-left:1px solid #8d8d8d;" class="qtyInfoBoxContents"&--#62;' . TEXT_PRICE_PER_PIECE . '&--#60;/td&--#62;
&--#60;td align="center" width="50" class="qtyInfoBoxContents"&--#62;&--#60;s&--#62;' . $currencies-&--#62;display_price($this-&--#62;thePrice, tep_get_tax_rate($this-&--#62;taxClass)) . '&--#60;/s&--#62;&--#60;span class="productSpecialPrice"&--#62;'.$currencies-&--#62;display_price($this-&--#62;specialPrice, tep_get_tax_rate($this-&--#62;taxClass)).'&--#60;/span&--#62;&--#60;/td&--#62;';
 // $lc_text .= '&--#60;s&--#62;'
	// . $currencies-&--#62;display_price($this-&--#62;thePrice, tep_get_tax_rate($this-&--#62;taxClass))
	// . '&--#60;/s&--#62;  &--#60;span class="productSpecialPrice"&--#62;'
	// . $currencies-&--#62;display_price($this-&--#62;specialPrice, tep_get_tax_rate($this-&--#62;taxClass))
	// . '&--#60;/span&--#62; '
	// .'&--#60;/td&--#62;';
  } else {
	$lc_text .= '
  &--#60;tr valign="top"&--#62;
&--#60;td width="120" style="border-left:1px solid #8d8d8d;" class="qtyInfoBoxContents"&--#62;' . TEXT_PRICE_PER_PIECE . '&--#60;/td&--#62;
&--#60;td align="center" width="50" class="qtyInfoBoxContents"&--#62;' . $currencies-&--#62;display_price($this-&--#62;theMSRP, tep_get_tax_rate($this-&--#62;taxClass)) . '&--#60;/td&--#62;';
  }
  foreach($this-&--#62;price_breaks as $price_break) {
	$lc_text .= '&--#60;td align="center" width="50" class="qtyInfoBoxContents"&--#62;'
	  . $currencies-&--#62;display_price($price_break['products_price'], tep_get_tax_rate($this-&--#62;taxClass))
	  .'&--#60;/td&--#62;';
  }
  $lc_text .= '&--#60;/tr&--#62;';

  // Begin saving calculation
  $lc_text .= '&--#60;tr valign="top"&--#62;&--#60;td width="120" style="border-left:1px solid #8d8d8d;" class="qtyInfoBoxContents"&--#62;' . 'Savings:' . '&--#60;/td&--#62;';

  if (true == $this-&--#62;hasSpecialPrice) {
	$lc_text .= '&--#60;td align="center" class="qtyInfoBoxContents"&--#62;'
	. $this-&--#62;getDiscountSaving($this-&--#62;theMSRP, $this-&--#62;specialPrice)
	.'&--#60;/td&--#62;';
  } else {
	$lc_text .= '&--#60;td align="center" class="qtyInfoBoxContents"&--#62;- &--#60;/td&--#62;';
  }
  foreach($this-&--#62;price_breaks as $price_break) {
	$lc_text .= '&--#60;td align="center" width="50" class="qtyInfoBoxContents"&--#62;'
	. $this-&--#62;getDiscountSaving($this-&--#62;theMSRP, $price_break['products_price'])
	.'&--#60;/td&--#62;';
  }
  $lc_text .= '&--#60;/tr&--#62;&--#60;/table&--#62;&--#60;/td&--#62;&--#60;/tr&--#62;&--#60;/table&--#62;';
} else {
  if (true == $this-&--#62;hasSpecialPrice) {
	$lc_text = ' &--#60;s&--#62;'
	. $currencies-&--#62;display_price($this-&--#62;thePrice, tep_get_tax_rate($this-&--#62;taxClass))
	. '&--#60;/s&--#62;  &--#60;span class="productSpecialPrice"&--#62;'
	. $currencies-&--#62;display_price($this-&--#62;specialPrice, tep_get_tax_rate($this-&--#62;taxClass))
	. '&--#60;/span&--#62; ';
  } else {
	$lc_text = ' '
	. $currencies-&--#62;display_price($this-&--#62;thePrice, tep_get_tax_rate($this-&--#62;taxClass))
	. ' ';
  }
}
return $lc_text;
 }
 function getPriceStringShort() {
global $currencies;
if (true == $this-&--#62;hasSpecialPrice) {
	$lc_text = ' &--#60;big&--#62;&--#60;s&--#62;'
	. $currencies-&--#62;display_price($this-&--#62;thePrice, tep_get_tax_rate($this-&--#62;taxClass))
	. '&--#60;/s&--#62;  &--#60;br&--#62;&--#60;span class="productSpecialPrice"&--#62;' . TEXT_ON_SALE . ' '
	. $currencies-&--#62;display_price($this-&--#62;specialPrice, tep_get_tax_rate($this-&--#62;taxClass))
	. '&--#60;/big&--#62;&--#60;/span&--#62; &--#60;br&--#62;&--#60;br&--#62;&--#60;br&--#62;';
} elseif (true == $this-&--#62;hasQuantityPrice) {
  $lc_text = ' &--#60;big&--#62;' . TEXT_PRICE_BREAKS . ' '
  . $currencies-&--#62;display_price($this-&--#62;lowPrice, tep_get_tax_rate($this-&--#62;taxClass))
  . ' &--#60;/big&--#62;&--#60;br&--#62;&--#60;br&--#62;&--#60;br&--#62;';
} else {
	$lc_text = ' &--#60;big&--#62;'
	. $currencies-&--#62;display_price($this-&--#62;thePrice, tep_get_tax_rate($this-&--#62;taxClass))
	. ' &--#60;/big&--#62;&--#60;br&--#62;&--#60;br&--#62;&--#60;br&--#62;';
}
return $lc_text;
 }
/* Old (original formatting)
 function getPriceString($style='"productPriceInBox"') {
global $currencies;
if (true == $this-&--#62;hasSpecialPrice) {
  $lc_text = '&--#60;table align="top" border="1" cellspacing="0" cellpadding="0"&--#62;';
  $lc_text .= '&--#60;tr&--#62;&--#60;td align="center" class=' . $style. ' colspan="2"&--#62;';
  $lc_text .= ' &--#60;s&--#62;'
	. $currencies-&--#62;display_price($this-&--#62;thePrice, tep_get_tax_rate($this-&--#62;taxClass))
	. '&--#60;/s&--#62;  &--#60;span class="productSpecialPrice"&--#62;'
	. $currencies-&--#62;display_price($this-&--#62;specialPrice, tep_get_tax_rate($this-&--#62;taxClass))
	. '&--#60;/span&--#62; '
	.'&--#60;/td&--#62;&--#60;/tr&--#62;';
}
else
{
  $lc_text = '&--#60;table align="top" border="1" cellspacing="0" cellpadding="0"&--#62;';
  $lc_text .= '&--#60;tr&--#62;&--#60;td align="center" class=' . $style. ' colspan="2"&--#62;'
	. $currencies-&--#62;display_price($this-&--#62;thePrice, tep_get_tax_rate($this-&--#62;taxClass))
	. '&--#60;/td&--#62;&--#60;/tr&--#62;';
}

// If you want to change the format of the price/quantity table
// displayed on the product information page, here is where you do it.
if(true == $this-&--#62;hasQuantityPrice) {
  foreach($this-&--#62;price_breaks as $price_break) {
	$lc_text .= '&--#60;tr&--#62;&--#60;td class='.$style.'&--#62;'
	  . $price_break['products_qty']
	  .'+ &--#60;/td&--#62;&--#60;td class='.$style.'&--#62;'
	  . $currencies-&--#62;display_price($price_break['products_price'], tep_get_tax_rate($this-&--#62;taxClass))
	  .'&--#60;/td&--#62;&--#60;/tr&--#62;';
  }
  $lc_text .= '&--#60;/table&--#62;';
} else {
  if (true == $this-&--#62;hasSpecialPrice) {
	$lc_text = ' &--#60;s&--#62;'
	  . $currencies-&--#62;display_price($this-&--#62;thePrice, tep_get_tax_rate($this-&--#62;taxClass))
	  . '&--#60;/s&--#62;  &--#60;span class="productSpecialPrice"&--#62;'
	  . $currencies-&--#62;display_price($this-&--#62;specialPrice, tep_get_tax_rate($this-&--#62;taxClass))
	  . '&--#60;/span&--#62; ';
  } else {
	$lc_text = ' '
	  . $currencies-&--#62;display_price($this-&--#62;thePrice, tep_get_tax_rate($this-&--#62;taxClass))
	  . ' ';
  }
}
return $lc_text;
 }
 function getPriceStringShort() {
global $currencies;
if (true == $this-&--#62;hasSpecialPrice) {
  $lc_text = ' &--#60;s&--#62;'
	. $currencies-&--#62;display_price($this-&--#62;thePrice, tep_get_tax_rate($this-&--#62;taxClass))
	. '&--#60;/s&--#62;  &--#60;span class="productSpecialPrice"&--#62;'
	. $currencies-&--#62;display_price($this-&--#62;specialPrice, tep_get_tax_rate($this-&--#62;taxClass))
	. '&--#60;/span&--#62; ';
} else {
  if(true == $this-&--#62;hasQuantityPrice) {
	$lc_text = ' '
	  . $currencies-&--#62;display_price($this-&--#62;lowPrice, tep_get_tax_rate($this-&--#62;taxClass))
	  . ' - '
	  . $currencies-&--#62;display_price($this-&--#62;hiPrice, tep_get_tax_rate($this-&--#62;taxClass))
	  . ' ';
  } else {
	$lc_text = ' '
	  . $currencies-&--#62;display_price($this-&--#62;thePrice, tep_get_tax_rate($this-&--#62;taxClass))
	  . ' ';
  }
}
return $lc_text;
 }
 */
}
?&--#62;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...