I am trying to build in a customer discount into my page. All pricing comes from a priceformatter.php page (see code below) and I need to call the specific discount which will come from the table customers and the row customers_discount. I can't seem to get it
Here is the code for priceformatter.php:
<?php
/*
$Id: PriceFormatter.php,v 1.7 2006/12/23 JanZ 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!)
*/
class PriceFormatter {
var $hiPrice;
var $lowPrice;
var $quantity;
var $hasQuantityPrice;
function PriceFormatter($prices=NUL
L) {
$this->productsID = -1;
$this->hasQuantityPrice=fa
lse;
$this->hasSpecialPrice=fal
se;
$this->hiPrice=-1;
$this->lowPrice=-1;
for ($i=1; $i<=8; $i++){
$this->quantity[$i] = -1;
$this->prices[$i] = -1;
}
$this->thePrice = -1;
$this->specialPrice = -1;
$this->qtyBlocks = 1;
if($prices)
$this->parse($prices);
}
/* encode and decode is not used in osC so why load this code?
function encode() {
$str = $this->productsID . ":"
. (($this->hasQuantityPrice == true) ? "1" : "0") . ":"
. (($this->hasSpecialPrice == true) ? "1" : "0") . ":"
. $this->quantity[1] . ":"
. $this->quantity[2] . ":"
. $this->price[1] . ":"
. $this->price[2] . ":"
. $this->specialPrice . ":"
. $this->qtyBlocks . ":"
. $this->taxClass;
return $str;
}
function decode($str) {
list($this->productsID,
$this->hasQuantityPrice,
$this->hasSpecialPrice,
$this->quantity[1],
$this->quantity[2],
$this->price[1],
$this->price[2],
$this->thePrice,
$this->specialPrice,
$this->qtyBlocks,
$this->taxClass) = explode(":", $str);
$this->hasQuantityPrice = (($this->hasQuantityPrice == 1) ? true : false);
$this->hasSpecialPrice = (($this->hasSpecialPrice == 1) ? true : false);
} */
function parse($prices) {
$this->productsID = $prices['products_id'];
$this->hasQuantityPrice=fa
lse;
$this->hasSpecialPrice=fal
se;
$this->quantity[1]=$prices
['products
_price1_qt
y'];
$this->quantity[2]=$prices
['products
_price2_qt
y'];
$this->thePrice=$prices['p
roducts_pr
ice'];
$this->specialPrice=$price
s['special
s_new_prod
ucts_price
'];
$this->hasSpecialPrice=tep
_not_null(
$this->spe
cialPrice)
;
$this->price[1]=$prices['p
roducts_pr
ice1'];
$this->price[2]=$prices['p
roducts_pr
ice2'];
/*
Change support special prices
If any price level has a price greater than the special
price lower it to the special price
*/
if ($this->hasSpecialPrice == true) {
for($i=1; $i<=8; $i++) {
if ($this->price[$i] > $this->specialPrice)
$this->price[$i] = $this->specialPrice;
}
}
//end changes to support special prices
$this->qtyBlocks=$prices['
products_q
ty_blocks'
];
$this->taxClass=$prices['p
roducts_ta
x_class_id
'];
if ($this->quantity[1] > 0) {
$this->hasQuantityPrice = true;
$this->hiPrice = $this->thePrice;
$this->lowPrice = $this->thePrice;
for($i=1; $i<=8; $i++) {
if($this->quantity[$i] > 0) {
if ($this->price[$i] > $this->hiPrice) {
$this->hiPrice = $this->price[$i];
}
if ($this->price[$i] < $this->lowPrice) {
$this->lowPrice = $this->price[$i];
}
}
}
}
}
function loadProduct($product_id, $language_id=1)
{
global $pfs;
$pricebreak = $pfs->getPriceBreak($produ
ct_id);
// returns false if the price break information is not yet stored
if ($pricebreak != false) {
$product_info = $pricebreak;
} else {
$sql = "select pd.products_name, p.products_model, p.products_image, p.products_id," .
" p.manufacturers_id, p.products_price, p.products_weight, p.products_quantity, " .
" p.products_price1, p.products_price2, p.products_price3,p.produc
ts_price4,
" .
" p.products_price5, p.products_price6, p.products_price7, p.products_price8," .
" p.products_price1_qty, p.products_price2_qty, p.products_price3_qty, p.products_price4_qty, " .
" p.products_price5_qty, p.products_price6_qty, p.products_price7_qty, p.products_price8_qty," .
" p.products_qty_blocks, p.products_tax_class_id," .
" IF(s.status, s.specials_new_products_pr
ice, NULL) as specials_new_products_pric
e " .
" from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.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($produc
t_info_que
ry);
$pfs->addPriceBreakData(te
p_get_prid
($product_
id), $product_info);
}
$this->parse($product_info
);
return $product_info;
}
function computePrice($qty)
{
$qty = $this->adjustQty($qty);
// Compute base price, taking into account the possibility of a special
$price = ($this->hasSpecialPrice === TRUE) ? $this->specialPrice : $this->thePrice;
for ($i=1; $i<=8; $i++)
if (($this->quantity[$i] > 0) && ($qty >= $this->quantity[$i]))
$price = $this->price[$i];
return $price;
}
function adjustQty($qty) {
// Force QTY_BLOCKS granularity
$qb = $this->getQtyBlocks();
if ($qty < 1)
$qty = 1;
if ($qb >= 1)
{
if ($qty < $qb)
$qty = $qb;
if (($qty % $qb) != 0)
$qty += ($qb - ($qty % $qb));
}
return $qty;
}
function getQtyBlocks() {
return $this->qtyBlocks;
}
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 getPriceString($style='"pr
oductPrice
InBox"') {
global $currencies;
if ($this->hasSpecialPrice == true) {
$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->th
ePrice,
tep_get_tax_rate($this->ta
xClass))
. '</s> <span class="productSpecialPrice
">'
. $currencies->display_price
($this->sp
ecialPrice
,
tep_get_tax_rate($this->ta
xClass))
. '</span> '
.'</td></tr>';
}
else
{
$lc_text = '<table align="top" border="0" cellspacing="0" cellpadding="4">';
$lc_text .= '<tr><td align="center" class=' . $style. ' colspan="2"></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.
//I Need to call to the table to fetch the customers id and their associated discount rate here
if($this->hasQuantityPrice
== true) {
for($i=1; $i<=1; $i++) {
if($this->quantity[$i] > 0) {
$lc_text .= '<tr><td class='.$style.'>'
. $this->quantity[1]
.'x (Half Boxes)</td><td class='.$style.'>'
. $currencies->display_price
($this->pr
ice[$i],
tep_get_tax_rate($this->ta
xClass))
.' each</td><tr><td class='.$style.'>'
. $this->quantity[2]
.'x (Full Boxes)</td><td class='.$style.'>'
. $currencies->display_price
($this->pr
ice[2],
tep_get_tax_rate($this->ta
xClass))
.' each</td></tr></tr>';
}
}
$lc_text .= '</table>';
}
else {
if ($this->hasSpecialPrice == true) {
$lc_text = ' <s>'
. $currencies->display_price
($this->th
ePrice, tep_get_tax_rate($this->ta
xClass))
. '</s> <span class="productSpecialPrice
">'
. $currencies->display_price
($this->sp
ecialPrice
, tep_get_tax_rate($this->ta
xClass))
. '</span> ';
}
else {
$lc_text = ' '
. $currencies->display_price
($this->th
ePrice,
tep_get_tax_rate($this->ta
xClass))
. ' ';
}
}
return $lc_text;
}
function getPriceStringShort() {
global $currencies;
if ($this->hasSpecialPrice == true) {
$lc_text = ' <s>'
. $currencies->display_price
($this->th
ePrice,
tep_get_tax_rate($this->ta
xClass))
. '</s> <span class="productSpecialPrice
">'
. $currencies->display_price
($this->sp
ecialPrice
,
tep_get_tax_rate($this->ta
xClass))
. '</span> ';
}
else {
if($this->hasQuantityPrice
== true) {
$lc_text = ' '
. $currencies->display_price
($this->lo
wPrice,
tep_get_tax_rate($this->ta
xClass))
. ' - '
. $currencies->display_price
($this->hi
Price,
tep_get_tax_rate($this->ta
xClass))
. ' ';
}
else {
$lc_text = ' '
. $currencies->display_price
($this->th
ePrice,
tep_get_tax_rate($this->ta
xClass))
. ' ';
}
}
return $lc_text;
}
}
?>
Start Free Trial