📄 functions_prices.php
字号:
// 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);
}
$deduction_type_array = array(array('id' => '0', 'text' => DEDUCTION_TYPE_DROPDOWN_0),
array('id' => '1', 'text' => DEDUCTION_TYPE_DROPDOWN_1),
array('id' => '2', 'text' => DEDUCTION_TYPE_DROPDOWN_2));
$sale_exists = 'false';
$sale_maker_discount = '';
$sale_maker_special_condition = '';
$salemaker_sales = $db->Execute("select sale_id, sale_status, sale_name, sale_categories_all, sale_deduction_value, sale_deduction_type, sale_pricerange_from, sale_pricerange_to, sale_specials_condition, sale_categories_selected, sale_date_start, sale_date_end, sale_date_added, sale_date_last_modified, sale_date_status_change from " . TABLE_SALEMAKER_SALES . " where sale_status='1'");
while (!$salemaker_sales->EOF) {
$categories = explode(',', $salemaker_sales->fields['sale_categories_all']);
while (list($key,$value) = each($categories)) {
if ($value == $check_category) {
$sale_exists = 'true';
$sale_maker_discount = $salemaker_sales->fields['sale_deduction_value'];
$sale_maker_special_condition = $salemaker_sales->fields['sale_specials_condition'];
$sale_maker_discount_type = $salemaker_sales->fields['sale_deduction_type'];
break;
}
}
$salemaker_sales->MoveNext();
}
$check_special = zen_get_products_special_price($product_id, true);
if ($sale_exists == 'true' and $sale_maker_special_condition != 0) {
$sale_maker_discount_type = (($sale_maker_discount_type * 100) + ($sale_maker_special_condition * 10));
} else {
$sale_maker_discount_type = 5;
}
if (!$check_special) {
// do nothing
} else {
$sale_maker_discount_type = ($sale_maker_discount_type * 10) + 9;
}
switch (true) {
case (!$return_value):
return $sale_maker_discount_type;
break;
case ($return_value == 'amount'):
return $sale_maker_discount;
break;
default:
return 'Unknown Request';
break;
}
}
////
// 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);
}
$deduction_type_array = array(array('id' => '0', 'text' => DEDUCTION_TYPE_DROPDOWN_0),
array('id' => '1', 'text' => DEDUCTION_TYPE_DROPDOWN_1),
array('id' => '2', 'text' => DEDUCTION_TYPE_DROPDOWN_2));
$sale_maker_discount = 0;
$salemaker_sales = $db->Execute("select sale_id, sale_status, sale_name, sale_categories_all, sale_deduction_value, sale_deduction_type, sale_pricerange_from, sale_pricerange_to, sale_specials_condition, sale_categories_selected, sale_date_start, sale_date_end, sale_date_added, sale_date_last_modified, sale_date_status_change from " . TABLE_SALEMAKER_SALES . " where sale_status='1'");
while (!$salemaker_sales->EOF) {
$categories = explode(',', $salemaker_sales->fields['sale_categories_all']);
while (list($key,$value) = each($categories)) {
if ($value == $check_category) {
$sale_maker_discount = $salemaker_sales->fields['sale_deduction_value'];
$sale_maker_discount_type = $salemaker_sales->fields['sale_deduction_type'];
break;
}
}
$salemaker_sales->MoveNext();
}
switch(true) {
// percentage discount only
case ($sale_maker_discount_type == 1):
$sale_maker_discount = (1 - ($sale_maker_discount / 100));
break;
case ($sale_maker_discount_type == 0 and $display_type == true):
$sale_maker_discount = $sale_maker_discount;
break;
case ($sale_maker_discount_type == 0 and $display_type == false):
$sale_maker_discount = $sale_maker_discount;
break;
case ($sale_maker_discount_type == 2 and $display_type == true):
$sale_maker_discount = $sale_maker_discount;
break;
default:
$sale_maker_discount = 1;
break;
}
if ($display_type == true) {
if ($sale_maker_discount != 1 and $sale_maker_discount !=0) {
switch(true) {
case ($sale_maker_discount_type == 0):
$sale_maker_discount = $currencies->format($sale_maker_discount) . ' ' . $deduction_type_array[$sale_maker_discount_type]['text'];
break;
case ($sale_maker_discount_type == 2):
$sale_maker_discount = $currencies->format($sale_maker_discount) . ' ' . $deduction_type_array[$sale_maker_discount_type]['text'];
break;
case ($sale_maker_discount_type == 1):
$sale_maker_discount = number_format( (1.00 - $sale_maker_discount),2,".","") . ' ' . $deduction_type_array[$sale_maker_discount_type]['text'];
break;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -