[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path Zen Cart 源代码 functions_prices.php
$specials = $db->Execute("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$product_id . "' and status='1'");
if ($specials->RecordCount() > 0) {
// if ($product->fields['products_priced_by_attribute'] == 1) {
$special_price = $specials->fields['specials_new_products_price'];
} else {
$special_price = false;
}
if(substr($product->fields['products_model'], 0, 4) == 'GIFT') { //Never apply a salededuction to Ian Wilson's Giftvouchers
if (zen_not_null($special_price)) {
return $special_price;
} else {
return false;
}
}
// return special price only
if ($specials_price_only==true) {
if (zen_not_null($special_price)) {
return $special_price;
} else {
return false;
}
} else {
// get sale price
// changed to use master_categories_id
// $product_to_categories = $db->Execute("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$product_id . "'");
// $category = $product_to_categories->fields['categories_id'];
////
// computes products_price + option groups lowest attributes price of each group when on
function zen_get_products_base_price($products_id) {
global $db;
$product_check = $db->Execute("select products_price, products_priced_by_attribute from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
// is there a products_price to add to attributes
$products_price = $product_check->fields['products_price'];
// do not select display only attributes and attributes_price_base_included is true
$product_att_query = $db->Execute("select options_id, price_prefix, options_values_price, attributes_display_only, attributes_price_base_included, round(concat(price_prefix, options_values_price), 5) as value from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and attributes_display_only != '1' and attributes_price_base_included='1'". " order by options_id, value");
$the_options_id= 'x';
$the_base_price= 0;
// add attributes price to price
if ($product_check->fields['products_priced_by_attribute'] == '1' and $product_att_query->RecordCount() >= 1) {
while (!$product_att_query->EOF) {
if ( $the_options_id != $product_att_query->fields['options_id']) {
$the_options_id = $product_att_query->fields['options_id'];
$the_base_price += (($product_att_query->fields['price_prefix'] == '-') ? -1 : 1) * $product_att_query->fields['options_values_price'];
}
$product_att_query->MoveNext();
}
////
// Display Price Retail
// Specials and Tax Included
function zen_get_products_display_price($products_id) {
global $db, $currencies;
// never mask prices in admin
if (false) {
// 0 = normal shopping
// 1 = Login to shop
// 2 = Can browse but no prices
// verify display of prices
switch (true) {
case (CUSTOMERS_APPROVAL == '1' and $_SESSION['customer_id'] == ''):
// customer must be logged in to browse
return '';
break;
case (CUSTOMERS_APPROVAL == '2' and $_SESSION['customer_id'] == ''):
// customer may browse but no prices
return '';
break;
default:
// proceed normally
break;
}
// show case only
if (STORE_STATUS != '0') {
if (STORE_STATUS == '1') {
return '';
}
}
}
// $new_fields = ', product_is_free, product_is_call, product_is_showroom_only';
$product_check = $db->Execute("select products_tax_class_id, products_price, products_priced_by_attribute, product_is_free, product_is_call from " . TABLE_PRODUCTS . " where products_id = '" . $products_id . "'" . " limit 1");
////
// Find quantity discount quantity mixed and not mixed
function zen_get_products_quantity_discount_mixed($product_id, $qty) {
global $db;
global $cart;
$product_discounts = $db->Execute("select products_price, products_quantity_mixed, product_is_free from " . TABLE_PRODUCTS . " where products_id = '" . $product_id . "'");
if ($product_discounts->fields['products_quantity_mixed']) {
if ($new_qty = $_SESSION['cart']->count_contents_qty($product_id)) {
$qty = $new_qty;
}
}
return $qty;
}
////
// Return a product's quantity box status
// TABLES: products
function zen_get_products_qty_box_status($product_id) {
global $db;
////
// Return quantity buy now
function zen_get_buy_now_qty($product_id) {
global $cart;
$check_min = zen_get_products_quantity_order_min($product_id);
$check_units = zen_get_products_quantity_order_units($product_id);
$buy_now_qty=1;
// works on Mixed ON
switch (true) {
case ($_SESSION['cart']->in_cart_mixed($product_id) == 0 ):
if ($check_min >= $check_units) {
$buy_now_qty = $check_min;
} else {
$buy_now_qty = $check_units;
}
break;
case ($_SESSION['cart']->in_cart_mixed($product_id) < $check_min):
$buy_now_qty = $check_min - $_SESSION['cart']->in_cart_mixed($product_id);
break;
case ($_SESSION['cart']->in_cart_mixed($product_id) > $check_min):
// set to units or difference in units to balance cart
$new_units = $check_units - fmod_round($_SESSION['cart']->in_cart_mixed($product_id), $check_units);
//echo 'Cart: ' . $_SESSION['cart']->in_cart_mixed($product_id) . ' Min: ' . $check_min . ' Units: ' . $check_units . ' fmod: ' . fmod($_SESSION['cart']->in_cart_mixed($product_id), $check_units) . '<br />';
$buy_now_qty = ($new_units > 0 ? $new_units : $check_units);
break;
default:
$buy_now_qty = $check_units;
break;
}
if ($buy_now_qty <= 0) {
$buy_now_qty = 1;
}
return $buy_now_qty;
}
////
// compute product discount to be applied to attributes or other values
function zen_get_discount_calc($product_id, $attributes_id = false, $attributes_amount = false, $check_qty= false) {
global $discount_type_id, $sale_maker_discount;
global $cart;
// no charge
if ($attributes_id > 0 and $attributes_amount == 0) {
return 0;
}
// percentage adjustment of discount
if (($discount_type_id == 120 or $discount_type_id == 1209) or ($discount_type_id == 110 or $discount_type_id == 1109)) {
$sale_maker_discount = ($sale_maker_discount != 0 ? (100 - $sale_maker_discount)/100 : 1);
}
$qty = $check_qty;
// fix here
// BOF: percentage discounts apply to price
switch (true) {
case (zen_get_discount_qty($product_id, $qty) and !$attributes_id):
// discount quanties exist and this is not an attribute
// $this->contents[$products_id]['qty']
$check_discount_qty_price = zen_get_products_discount_price_qty($product_id, $qty, $attributes_amount);
//echo 'How much 1 ' . $qty . ' : ' . $attributes_amount . ' vs ' . $check_discount_qty_price . '<br />';
return $check_discount_qty_price;
break;
case (zen_get_discount_qty($product_id, $qty) and zen_get_products_price_is_priced_by_attributes($product_id)):
// discount quanties exist and this is not an attribute
// $this->contents[$products_id]['qty']
$check_discount_qty_price = zen_get_products_discount_price_qty($product_id, $qty, $attributes_amount);
//echo 'How much 2 ' . $qty . ' : ' . $attributes_amount . ' vs ' . $check_discount_qty_price . '<br />';
return $check_discount_qty_price;
break;
case ($discount_type_id == 5):
// No Sale and No Special
// $sale_maker_discount = 1;
if (!$attributes_id) {
$sale_maker_discount = $sale_maker_discount;
} else {
// compute attribute amount
if ($attributes_amount != 0) {
if ($special_price_discount != 0) {
$calc = ($attributes_amount * $special_price_discount);
} else {
$calc = $attributes_amount;
}
$sale_maker_discount = $calc;
} else {
$sale_maker_discount = $sale_maker_discount;
}
}
//echo 'How much 3 - ' . $qty . ' : ' . $product_id . ' : ' . $qty . ' x ' . $attributes_amount . ' vs ' . $check_discount_qty_price . ' - ' . $sale_maker_discount . '<br />';
break;
case ($discount_type_id == 59):
// No Sale and Special
// $sale_maker_discount = $special_price_discount;
if (!$attributes_id) {
$sale_maker_discount = $sale_maker_discount;
} else {
// compute attribute amount
if ($attributes_amount != 0) {
$calc = ($attributes_amount * $special_price_discount);
$sale_maker_discount = $calc;
} else {
$sale_maker_discount = $sale_maker_discount;
}
}
break;
// EOF: percentage discount apply to price
// BOF: percentage discounts apply to Sale
case ($discount_type_id == 120):
// percentage discount Sale and Special without a special
if (!$attributes_id) {
$sale_maker_discount = $sale_maker_discount;
} else {
// compute attribute amount
if ($attributes_amount != 0) {
$calc = ($attributes_amount * $sale_maker_discount);
$sale_maker_discount = $calc;
} else {
$sale_maker_discount = $sale_maker_discount;
}
}
break;
case ($discount_type_id == 1209):
// percentage discount on Sale and Special with a special
if (!$attributes_id) {
$sale_maker_discount = $sale_maker_discount;
} else {
// compute attribute amount
if ($attributes_amount != 0) {
$calc = ($attributes_amount * $special_price_discount);
$calc2 = $calc - ($calc * $sale_maker_discount);
$sale_maker_discount = $calc - $calc2;
} else {
$sale_maker_discount = $sale_maker_discount;
}
}
break;
// EOF: percentage discounts apply to Sale
// BOF: percentage discounts skip specials
case ($discount_type_id == 110):
// percentage discount Sale and Special without a special
if (!$attributes_id) {
$sale_maker_discount = $sale_maker_discount;
} else {
// compute attribute amount
if ($attributes_amount != 0) {
$calc = ($attributes_amount * $sale_maker_discount);
$sale_maker_discount = $calc;
} else {
// $sale_maker_discount = $sale_maker_discount;
if ($attributes_amount != 0) {
// $calc = ($attributes_amount * $special_price_discount);
// $calc2 = $calc - ($calc * $sale_maker_discount);
// $sale_maker_discount = $calc - $calc2;
$calc = $attributes_amount - ($attributes_amount * $sale_maker_discount);
$sale_maker_discount = $calc;
} else {
$sale_maker_discount = $sale_maker_discount;
}
}
}
break;
case ($discount_type_id == 1109):
// percentage discount on Sale and Special with a special
if (!$attributes_id) {
$sale_maker_discount = $sale_maker_discount;
} else {
// compute attribute amount
if ($attributes_amount != 0) {
$calc = ($attributes_amount * $special_price_discount);
// $calc2 = $calc - ($calc * $sale_maker_discount);
// $sale_maker_discount = $calc - $calc2;
$sale_maker_discount = $calc;
} else {
$sale_maker_discount = $sale_maker_discount;
}
}
break;
// EOF: percentage discounts skip specials
// BOF: flat amount discounts
case ($discount_type_id == 20):
// flat amount discount Sale and Special without a special
if (!$attributes_id) {
$sale_maker_discount = $sale_maker_discount;
} else {
// compute attribute amount
if ($attributes_amount != 0) {
$calc = ($attributes_amount - $sale_maker_discount);
$sale_maker_discount = $calc;
} else {
$sale_maker_discount = $sale_maker_discount;
}
}
break;
case ($discount_type_id == 209):
// flat amount discount on Sale and Special with a special
if (!$attributes_id) {
$sale_maker_discount = $sale_maker_discount;
} else {
// compute attribute amount
if ($attributes_amount != 0) {
$calc = ($attributes_amount * $special_price_discount);
$calc2 = ($calc - $sale_maker_discount);
$sale_maker_discount = $calc2;
} else {
$sale_maker_discount = $sale_maker_discount;
}
}
break;
// EOF: flat amount discounts
// BOF: flat amount discounts Skip Special
case ($discount_type_id == 10):
// flat amount discount Sale and Special without a special
if (!$attributes_id) {
$sale_maker_discount = $sale_maker_discount;
} else {
// compute attribute amount
if ($attributes_amount != 0) {
$calc = ($attributes_amount - $sale_maker_discount);
$sale_maker_discount = $calc;
} else {
$sale_maker_discount = $sale_maker_discount;
}
}
break;
case ($discount_type_id == 109):
// flat amount discount on Sale and Special with a special
if (!$attributes_id) {
$sale_maker_discount = 1;
} else {
// compute attribute amount based on Special
if ($attributes_amount != 0) {
$calc = ($attributes_amount * $special_price_discount);
$sale_maker_discount = $calc;
} else {
$sale_maker_discount = $sale_maker_discount;
}
}
break;
// EOF: flat amount discounts Skip Special
// BOF: New Price amount discounts
case ($discount_type_id == 220):
// New Price amount discount Sale and Special without a special
if (!$attributes_id) {
$sale_maker_discount = $sale_maker_discount;
} else {
// compute attribute amount
if ($attributes_amount != 0) {
$calc = ($attributes_amount * $special_price_discount);
$sale_maker_discount = $calc;
//echo '<br />attr ' . $attributes_amount . ' spec ' . $special_price_discount . ' Calc ' . $calc . 'Calc2 ' . $calc2 . '<br />';
} else {
$sale_maker_discount = $sale_maker_discount;
}
}
break;
case ($discount_type_id == 2209):
// New Price amount discount on Sale and Special with a special
if (!$attributes_id) {
// $sale_maker_discount = $sale_maker_discount;
$sale_maker_discount = $sale_maker_discount;
} else {
// compute attribute amount
if ($attributes_amount != 0) {
$calc = ($attributes_amount * $special_price_discount);
//echo '<br />attr ' . $attributes_amount . ' spec ' . $special_price_discount . ' Calc ' . $calc . 'Calc2 ' . $calc2 . '<br />';
$sale_maker_discount = $calc;
} else {
$sale_maker_discount = $sale_maker_discount;
}
}
break;
// EOF: New Price amount discounts
// BOF: New Price amount discounts - Skip Special
case ($discount_type_id == 210):
// New Price amount discount Sale and Special without a special
if (!$attributes_id) {
$sale_maker_discount = $sale_maker_discount;
} else {
// compute attribute amount
if ($attributes_amount != 0) {
$calc = ($attributes_amount * $special_price_discount);
$sale_maker_discount = $calc;
//echo '<br />attr ' . $attributes_amount . ' spec ' . $special_price_discount . ' Calc ' . $calc . 'Calc2 ' . $calc2 . '<br />';
} else {
$sale_maker_discount = $sale_maker_discount;
}
}
break;
case ($discount_type_id == 2109):
// New Price amount discount on Sale and Special with a special
if (!$attributes_id) {
// $sale_maker_discount = $sale_maker_discount;
$sale_maker_discount = $sale_maker_discount;
} else {
// compute attribute amount
if ($attributes_amount != 0) {
$calc = ($attributes_amount * $special_price_discount);
//echo '<br />attr ' . $attributes_amount . ' spec ' . $special_price_discount . ' Calc ' . $calc . 'Calc2 ' . $calc2 . '<br />';
$sale_maker_discount = $calc;
} else {
$sale_maker_discount = $sale_maker_discount;
}
}
break;
// EOF: New Price amount discounts - Skip Special
case ($discount_type_id == 0 or $discount_type_id == 9):
// flat discount
return $sale_maker_discount;
break;
default:
$sale_maker_discount = 7000;
break;
}
return $sale_maker_discount;
}
////
// look up discount in sale makers - attributes only can have discounts if set as percentages
// this gets the discount amount this does not determin when to apply the discount
function zen_get_products_sale_discount_type($product_id = false, $categories_id = false, $return_value = false) {
global $currencies;
global $db;
/*
0 = flat amount off base price with a special
1 = Percentage off base price with a special
2 = New Price with a special
5 = No Sale or Skip Products with Special
special options + option * 10
0 = Ignore special and apply to Price
1 = Skip Products with Specials switch to 5
2 = Apply to Special Price
If a special exist * 10+9
0*100 + 0*10 = flat apply to price = 0 or 9
0*100 + 1*10 = flat skip Specials = 5 or 59
0*100 + 2*10 = flat apply to special = 20 or 209
1*100 + 0*10 = Percentage apply to price = 100 or 1009
1*100 + 1*10 = Percentage skip Specials = 110 or 1109 / 5 or 59
1*100 + 2*10 = Percentage apply to special = 120 or 1209
2*100 + 0*10 = New Price apply to price = 200 or 2009
2*100 + 1*10 = New Price skip Specials = 210 or 2109 / 5 or 59
2*100 + 2*10 = New Price apply to Special = 220 or 2209
*/
// get products category
if ($categories_id == true) {
$check_category = $categories_id;
} else {
$check_category = zen_get_products_category_id($product_id);
}
////
// look up discount in sale makers - attributes only can have discounts if set as percentages
// this gets the discount amount this does not determin when to apply the discount
function zen_get_products_sale_discount($product_id = false, $categories_id = false, $display_type = false) {
global $currencies;
global $db;
// get products category
if ($categories_id == true) {
$check_category = $categories_id;
} else {
$check_category = zen_get_products_category_id($product_id);
}
////
// return attributes_qty_prices or attributes_qty_prices_onetime based on qty
function zen_get_attributes_qty_prices_onetime($string, $qty) {
$attribute_qty = preg_split("/[:,]/" , $string);
$size = sizeof($attribute_qty);
for ($i=0, $n=$size; $i<$n; $i+=2) {
$new_price = $attribute_qty[$i+1];
if ($qty <= $attribute_qty[$i]) {
$new_price = $attribute_qty[$i+1];
break;
}
}
return $new_price;
}
////
// Check specific attributes_qty_prices or attributes_qty_prices_onetime for a given quantity price
function zen_get_attributes_quantity_price($check_what, $check_for) {
// $check_what='1:3.00,5:2.50,10:2.25,20:2.00';
// $check_for=50;
$attribute_table_cost = preg_split("/[:,]/" , $check_what);
$size = sizeof($attribute_table_cost);
for ($i=0, $n=$size; $i<$n; $i+=2) {
if ($check_for >= $attribute_table_cost[$i]) {
$attribute_quantity_check = $attribute_table_cost[$i];
$attribute_quantity_price = $attribute_table_cost[$i+1];
}
}
// echo '<br>Cost ' . $check_for . ' - ' . $attribute_quantity_check . ' x ' . $attribute_quantity_price;
return $attribute_quantity_price;
}
////
// attributes final price
function zen_get_attributes_price_final($attribute, $qty = 1, $pre_selected, $include_onetime = 'false') {
global $db;
global $cart;
if ($pre_selected == '' or $attribute != $pre_selected->fields["products_attributes_id"]) {
$pre_selected = $db->Execute("select pa.* from " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_attributes_id= '" . $attribute . "'");
} else {
// use existing select
}
////
// attributes final price onetime
function zen_get_attributes_price_final_onetime($attribute, $qty= 1, $pre_selected_onetime) {
global $db;
global $cart;
if ($pre_selected_onetime == '' or $attribute != $pre_selected_onetime->fields["products_attributes_id"]) {
$pre_selected_onetime = $db->Execute("select pa.* from " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_attributes_id= '" . $attribute . "'");
} else {
// use existing select
}
// one time charges
// onetime charge
$attributes_price_final_onetime += $pre_selected_onetime->fields["attributes_price_onetime"];