<?php
function show_price( $product_id, $hide_tax = false ) {
global $VM_LANG, $CURRENCY_DISPLAY,$vendor_mail; $auth = $_SESSION['auth'];
$tpl = new $GLOBALS['VM_THEMECLASS']();
$product_name = htmlentities( $this->get_field($product_id, 'product_name'), ENT_QUOTES
); $tpl->set( 'product_id', $product_id );
$tpl->set( 'product_name', $product_name );
$tpl->set( 'vendor_mail', $vendor_mail );
$discount_info = $base_price = array(); $text_including_tax = '';
if( $auth['show_prices'] ) {
// Get the DISCOUNT AMOUNT
$discount_info = $this->get_discount( $product_id );
if( !$discount_info["is_percent"] && $discount_info["amount"] != 0 ) {
$discount_info["amount"] = $GLOBALS['CURRENCY']->convert($discount_info["amount"]);
}
// Get the Price according to the quantity in the Cart
$price_info = $this->get_price( $product_id );
$tpl->set( 'price_info', $price_info );
// Get the Base Price of the Product
$base_price_info = $this->get_price($product_id, true );
$tpl->set( 'base_price_info', $base_price_info );
if( $price_info === false ) {
$price_info = $base_price_info;
}
$html = "";
$undiscounted_price = 0;
if (isset($price_info["product_price_id"])) { if( $base_price_info["product_price"]== $price_info["product_price"] ) {
$price = $base_price = $GLOBALS['CURRENCY']->convert( $base_price_info["product_price"], $price_info['product_currency'] );
} else {
$base_price = $GLOBALS['CURRENCY']->convert( $base_price_info["product_price"], $price_info['product_currency'] );
$price = $GLOBALS['CURRENCY']->convert( $price_info["product_price"], $price_info['product_currency'] );
}
if ($auth["show_price_including_tax"] == 1) {
$my_taxrate = $this->get_product_taxrate($product_id);
$base_price += ($my_taxrate * $base_price);
}
else {
$my_taxrate = 0;
}
// Calculate discount
if( !empty($discount_info["amount"])) { $undiscounted_price = $base_price;
switch( $discount_info["is_percent"] ) {
case 0:
// If we subtract discounts BEFORE tax
if( PAYMENT_DISCOUNT_BEFORE == '1' ) {
// and if our prices are shown with tax
if( $auth["show_price_including_tax"] == 1) {
// then we add tax to the (untaxed) discount
$discount_info['amount'] += ($my_taxrate*$discount_info['amount']);
}
// but if our prices are shown without tax
// we just leave the (untaxed) discount amount as it is
}
// But, if we subtract discounts AFTER tax
// and if our prices are shown with tax
// we just leave the (untaxed) discount amount as it is
// but if prices are shown without tax
// we just leave the (untaxed) discount amount as it is
// even though this is not really a good combination of settings
$base_price -= $discount_info["amount"];
break;
case 1:
$base_price *= (100 - $discount_info["amount"])/100;
break;
}
}
$text_including_tax = "";
if (!empty($my_taxrate)) { $tax = $my_taxrate * 100;
// only show "including x % tax" when it shall
// not be hidden
if( !$hide_tax && $auth["show_price_including_tax"] == 1 && VM_PRICE_SHOW_INCLUDINGTAX) {
$text_including_tax = $VM_LANG->_('PHPSHOP_INCLUDING_TAX');
eval ("$text_including_tax = \"$text_including_tax\";"); }
}
// Check if we need to display a Table with all Quantity <=> Price Relationships
if( $base_price_info["product_has_multiple_prices"] && !$hide_tax ) {
$db = new ps_DB;
// Quantity Discount Table
$q = "SELECT product_price, product_currency, price_quantity_start, price_quantity_end
FROM #__{vm}_product_price
WHERE product_id='$product_id'
AND shopper_group_id='".$auth["shopper_group_id"]."'
ORDER BY price_quantity_start";
$db->query( $q );
// $prices_table = "<table align=\"right\">
$prices_table = "<table width=\"100%\">
<thead><tr class=\"sectiontableheader\">
<th>".$VM_LANG->_('PHPSHOP_CART_QUANTITY')."</th>
<th>".$VM_LANG->_('PHPSHOP_CART_PRICE')."</th>
</tr></thead>
<tbody>";
$i = 1;
if ($db->num_rows()==0) {
// get the vendor ID
$q = "SELECT vendor_id FROM #__{vm}_product WHERE product_id='$product_id'";
$db->setQuery($q); $db->query();
$db->next_record();
$vendor_id = $db->f("vendor_id");
// get the default shopper group ID
$q = "SELECT shopper_group_id FROM #__{vm}_shopper_group WHERE `vendor_id`='$vendor_id' AND `default`='1'";
$db->setQuery($q); $db->query();
$db->next_record();
$default_shopper_group_id = $db->f("shopper_group_id");
// get the current shopper group discount
$q = "SELECT * FROM #__{vm}_shopper_group WHERE shopper_group_id=" . $auth["shopper_group_id"];
$db->setQuery($q); $db->query();
$db->next_record();
$shopper_group_discount = $db->f("shopper_group_discount");
// check for prices in default shopper group
$q = "SELECT product_price, price_quantity_start, price_quantity_end FROM #__{vm}_product_price
WHERE product_id='$product_id' AND shopper_group_id='".$default_shopper_group_id."' ORDER BY price_quantity_start";
$db->query( $q );
while( $db->next_record() ) {
$prices_table .= "<tr class=\"sectiontableentry$i\"><td>".$db->f("price_quantity_start")." - ".$db->f("price_quantity_end")."</td>";
$prices_table .= "<td>";
$prices_table .= $CURRENCY_DISPLAY->getFullValue( ($my_taxrate+1)*$db->f("product_price")*((100-$shopper_group_discount)/100) );
else
$prices_table .= $CURRENCY_DISPLAY->getFullValue( $db->f("product_price")*((100-$shopper_group_discount)/100) );
$prices_table .= "</td></tr>";
$i == 1 ? $i++ : $i--;
}
} else {
// get the current shopper group discount
$dbsg = new ps_DB();
$q = "SELECT * FROM #__{vm}_shopper_group WHERE shopper_group_id=" . $auth["shopper_group_id"];
$dbsg->setQuery($q);
$dbsg->query();
$dbsg->next_record();
$shopper_group_discount = $dbsg->f("shopper_group_discount");
while( $db->next_record() ) {
$price = $GLOBALS['CURRENCY']->convert( $db->f("product_price"), $db->f("product_currency") );
$prices_table .= "<tr class=\"sectiontableentry$i\"><td>".$db->f("price_quantity_start")." - ".$db->f("price_quantity_end")."</td>";
$prices_table .= "<td>";
if (!empty($my_taxrate)) { $prices_table .= $CURRENCY_DISPLAY->getFullValue( ($my_taxrate+1)*$price*((100-$shopper_group_discount)/100) );
}
else {
$prices_table .= $CURRENCY_DISPLAY->getFullValue( $price*((100-$shopper_group_discount)/100) );
}
$prices_table .= "</td></tr>";
$i == 1 ? $i++ : $i--;
}
}
$prices_table .= "</tbody></table>";
if( @$_REQUEST['page'] != "shop.product_details" ) {
$html .= vmToolTip( $prices_table );
}
else
$html .= $prices_table;
}
}
}
$tpl->set( 'discount_info', $discount_info );
$tpl->set( 'text_including_tax', $text_including_tax );
$tpl->set( 'undiscounted_price', @$undiscounted_price );
$tpl->set( 'base_price', $base_price );
$tpl->set( 'price_table', $html);
return $tpl->fetch( 'common/price.tpl.php');
}
?>