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']; // -> OSC-94 - Prix par palier reservé aux professionnels $this->price_breaks_allowed = true; } function setCustomerId($customer_id=NULL) { if ( is_pro_customer($customer_id) ) $this->price_breaks_allowed = true; else $this->price_breaks_allowed = false; } // <- OSC-94 - Prix par palier reservé aux professionnels function loadProduct($product_id, $products_price, $products_tax_class_id, $qtyBlocks, $price_breaks_array = NULL) { //Collect required data //Price-breaks if (!tep_not_null($price_breaks_array)) { $price_breaks_array = array(); $price_breaks_query = tep_db_query("select products_price, products_qty from " . TABLE_PRODUCTS_PRICE_BREAK . " where products_id = '" . tep_db_input($product_id) . "' order by products_qty"); while ($price_break = tep_db_fetch_array($price_breaks_query)) { $price_breaks_array[] = $price_break; } } //Specials $products_special_price = NULL; $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . tep_db_input($product_id) . "'"); if($special = tep_db_fetch_array($specials_query)) { $products_special_price = $special['specials_new_products_price']; } //Compose cachable structure $price_formatter_data = array( 'products_price' => $products_price, 'products_special_price' => $products_special_price, 'products_tax_class_id' => $products_tax_class_id, 'price_breaks' => $price_breaks_array, 'qtyBlocks' => $qtyBlocks); //Assign members $this->thePrice = $price_formatter_data['products_price']; $this->taxClass = $price_formatter_data['products_tax_class_id']; $this->qtyBlocks = $price_formatter_data['qtyBlocks']; $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 (true == $this->hasSpecialPrice) { foreach($this->price_breaks as $price_break) { $price_break['products_price'] = min($price_break['products_price'], $this->specialPrice); } } //end changes to support special prices } // -> VD : ajout de la possibilité d'ajuster ou non la quantité function computePrice($qty, $nof_other_items_in_cart_same_cat = 0, $ajust=true) { if ( $adjust == true ) $qty = $this->adjustQty($qty); // <- VD // 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; // -> OSC-94 - Prix par palier reservé aux professionnels if (is_array($this->price_breaks) && count($this->price_breaks) > 0 && $this->price_breaks_allowed ) // <- OSC-94 - Prix par palier reservé aux professionnels foreach($this->price_breaks as $price_break) { if($qty >= $price_break['products_qty']) { $price = $price_break['products_price']; } } 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 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 = '
'; $lc_text .= ''; foreach($this->price_breaks as $price_break) { $lc_text .= ''; } $lc_text .= ''; } else { $lc_text .= '' . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass)) . ''; } foreach($this->price_breaks as $price_break) { $lc_text .= ''; } $lc_text .= ''; // Begin saving calculation $lc_text .= ''; if (true == $this->hasSpecialPrice) { $lc_text .= ''; } else { $lc_text .= ''; } foreach($this->price_breaks as $price_break) { $lc_text .= ''; } $lc_text .= '
' . TEXT_ENTER_QUANTITY .'1+' . '' . $price_break['products_qty'] .'+ 
' . TEXT_PRICE_PER_PIECE . ''; if (true == $this->hasSpecialPrice) { $lc_text .= '' . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass)) . '  ' . $currencies->display_price($this->specialPrice, tep_get_tax_rate($this->taxClass)) . ' ' .'' . $currencies->display_price($price_break['products_price'], tep_get_tax_rate($this->taxClass)) .'
' . TEXT_SAVINGS . '' . $this->getDiscountSaving($this->thePrice, $this->specialPrice) .'- ' . $this->getDiscountSaving($this->thePrice, $price_break['products_price']) .'
'; } else { if (true == $this->hasSpecialPrice) { $lc_text = ' ' . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass)) . '  ' . $currencies->display_price($this->specialPrice, tep_get_tax_rate($this->taxClass)) . ' '; } else { $lc_text = ' ' . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass)) . ' '; } } return $lc_text; } function getPriceStringShort() { global $currencies; if(true == $this->hasQuantityPrice) { $lc_text = ' ' . TEXT_PRICE_BREAKS . ' ' . $currencies->display_price($this->lowPrice, tep_get_tax_rate($this->taxClass)) . ' 


'; } else { if (true == $this->hasSpecialPrice) { $lc_text = ' ' . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass)) . '  
' . TEXT_ON_SALE . ' ' . $currencies->display_price($this->specialPrice, tep_get_tax_rate($this->taxClass)) . '
 


'; } else { $lc_text = ' ' . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass)) . ' 


'; } } return $lc_text; } /* Old (original formatting) function getPriceString($style='"productPriceInBox"') { global $currencies; if (true == $this->hasSpecialPrice) { $lc_text = ''; $lc_text .= ''; } else { $lc_text = '
'; $lc_text .= ' ' . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass)) . '  ' . $currencies->display_price($this->specialPrice, tep_get_tax_rate($this->taxClass)) . ' ' .'
'; $lc_text .= ''; } // 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 .= ''; } $lc_text .= '
' . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass)) . '
' . $price_break['products_qty'] .'+ ' . $currencies->display_price($price_break['products_price'], tep_get_tax_rate($this->taxClass)) .'
'; } else { if (true == $this->hasSpecialPrice) { $lc_text = ' ' . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass)) . '  ' . $currencies->display_price($this->specialPrice, tep_get_tax_rate($this->taxClass)) . ' '; } 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 = ' ' . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass)) . '  ' . $currencies->display_price($this->specialPrice, tep_get_tax_rate($this->taxClass)) . ' '; } 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; } */ } ?>