📄 functions_prices.php
字号:
} else {
$the_products_priced_by_attribute = false;
}
return $the_products_priced_by_attribute;
}
////
// Return a product's minimum quantity
// TABLES: products
function zen_get_products_quantity_order_min($product_id) {
global $db;
$the_products_quantity_order_min = $db->Execute("select products_id, products_quantity_order_min from " . TABLE_PRODUCTS . " where products_id = '" . $product_id . "'");
return $the_products_quantity_order_min->fields['products_quantity_order_min'];
}
////
// Return a product's minimum unit order
// TABLES: products
function zen_get_products_quantity_order_units($product_id) {
global $db;
$the_products_quantity_order_units = $db->Execute("select products_id, products_quantity_order_units from " . TABLE_PRODUCTS . " where products_id = '" . $product_id . "'");
return $the_products_quantity_order_units->fields['products_quantity_order_units'];
}
////
// Return a product's maximum quantity
// TABLES: products
function zen_get_products_quantity_order_max($product_id) {
global $db;
$the_products_quantity_order_max = $db->Execute("select products_id, products_quantity_order_max from " . TABLE_PRODUCTS . " where products_id = '" . (int)$product_id . "'");
return $the_products_quantity_order_max->fields['products_quantity_order_max'];
}
////
// 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;
$the_products_qty_box_status = $db->Execute("select products_id, products_qty_box_status from " . TABLE_PRODUCTS . " where products_id = '" . (int)$product_id . "'");
return $the_products_qty_box_status->fields['products_qty_box_status'];
}
////
// Return a product mixed setting
// TABLES: products
function zen_get_products_quantity_mixed($product_id) {
global $db;
$the_products_quantity_mixed = $db->Execute("select products_id, products_quantity_mixed from " . TABLE_PRODUCTS . " where products_id = '" . $product_id . "'");
if ($the_products_quantity_mixed->fields['products_quantity_mixed'] == '1') {
$look_up = true;
} else {
$look_up = false;
}
return $look_up;
}
////
// Return a products quantity minimum and units display
function zen_get_products_quantity_min_units_display($product_id, $include_break = true, $shopping_cart_msg = false) {
$check_min = zen_get_products_quantity_order_min($product_id);
$check_units = zen_get_products_quantity_order_units($product_id);
$the_min_units='';
if ($check_min > 1 or $check_units > 1) {
if ($check_min > 1) {
$the_min_units .= PRODUCTS_QUANTITY_MIN_TEXT_LISTING . ' ' . $check_min;
}
if ($check_units > 1) {
$the_min_units .= ($the_min_units ? ' ' : '' ) . PRODUCTS_QUANTITY_UNIT_TEXT_LISTING . ' ' . $check_units;
}
if (($check_min > 0 or $check_units > 0) and !zen_get_products_quantity_mixed($product_id)) {
if ($include_break == true) {
$the_min_units .= '<br />' . ($shopping_cart_msg == false ? TEXT_PRODUCTS_MIX_OFF : TEXT_PRODUCTS_MIX_OFF_SHOPPING_CART);
} else {
$the_min_units .= ' ' . ($shopping_cart_msg == false ? TEXT_PRODUCTS_MIX_OFF : TEXT_PRODUCTS_MIX_OFF_SHOPPING_CART);
}
} else {
if ($include_break == true) {
$the_min_units .= '<br />' . ($shopping_cart_msg == false ? TEXT_PRODUCTS_MIX_ON : TEXT_PRODUCTS_MIX_ON_SHOPPING_CART);
} else {
$the_min_units .= ' ' . ($shopping_cart_msg == false ? TEXT_PRODUCTS_MIX_ON : TEXT_PRODUCTS_MIX_ON_SHOPPING_CART);
}
}
}
// quantity max
$check_max = zen_get_products_quantity_order_max($product_id);
if ($check_max != 0) {
if ($include_break == true) {
$the_min_units .= ($the_min_units != '' ? '<br />' : '') . PRODUCTS_QUANTITY_MAX_TEXT_LISTING . ' ' . $check_max;
} else {
$the_min_units .= ($the_min_units != '' ? ' ' : '') . PRODUCTS_QUANTITY_MAX_TEXT_LISTING . ' ' . $check_max;
}
}
return $the_min_units;
}
////
// 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;
}
$new_products_price = zen_get_products_base_price($product_id);
$new_special_price = zen_get_products_special_price($product_id, true);
$new_sale_price = zen_get_products_special_price($product_id, false);
$discount_type_id = zen_get_products_sale_discount_type($product_id);
if ($new_products_price != 0) {
$special_price_discount = ($new_special_price != 0 ? ($new_special_price/$new_products_price) : 1);
} else {
$special_price_discount = '';
}
$sale_maker_discount = zen_get_products_sale_discount_type($product_id, '', 'amount');
// 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 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -