📄 shopping_cart.php
字号:
$this->free_shipping_item = 0;
$this->free_shipping_price = 0;
$this->free_shipping_weight = 0;
if (!is_array($this->contents)) return 0;
reset($this->contents);
while (list($products_id, ) = each($this->contents)) {
$qty = $this->contents[$products_id]['qty'];
// products price
$product_query = "select products_id, products_price, products_tax_class_id, products_weight,
products_priced_by_attribute, product_is_always_free_shipping, products_discount_type, products_discount_type_from,
products_virtual, products_model
from " . TABLE_PRODUCTS . "
where products_id = '" . (int)$products_id . "'";
if ($product = $db->Execute($product_query)) {
$prid = $product->fields['products_id'];
$products_tax = zen_get_tax_rate($product->fields['products_tax_class_id']);
$products_price = $product->fields['products_price'];
// adjusted count for free shipping
if ($product->fields['product_is_always_free_shipping'] != 1 and $product->fields['products_virtual'] != 1) {
$products_weight = $product->fields['products_weight'];
} else {
$products_weight = 0;
}
$special_price = zen_get_products_special_price($prid);
if ($special_price and $product->fields['products_priced_by_attribute'] == 0) {
$products_price = $special_price;
} else {
$special_price = 0;
}
if (zen_get_products_price_is_free($product->fields['products_id'])) {
// no charge
$products_price = 0;
}
// adjust price for discounts when priced by attribute
if ($product->fields['products_priced_by_attribute'] == '1' and zen_has_product_attributes($product->fields['products_id'], 'false')) {
// reset for priced by attributes
// $products_price = $products->fields['products_price'];
if ($special_price) {
$products_price = $special_price;
} else {
$products_price = $product->fields['products_price'];
}
} else {
// discount qty pricing
if ($product->fields['products_discount_type'] != '0') {
$products_price = zen_get_products_discount_price_qty($product->fields['products_id'], $qty);
}
}
// shipping adjustments
if (($product->fields['product_is_always_free_shipping'] == 1) or ($product->fields['products_virtual'] == 1) or (ereg('^GIFT', addslashes($product->fields['products_model'])))) {
$this->free_shipping_item += $qty;
$this->free_shipping_price += zen_add_tax($products_price, $products_tax) * $qty;
$this->free_shipping_weight += ($qty * $products_weight);
}
$this->total += zen_add_tax($products_price, $products_tax) * $qty;
$this->weight += ($qty * $products_weight);
}
// attributes price
if (isset($this->contents[$products_id]['attributes'])) {
reset($this->contents[$products_id]['attributes']);
while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
/*
products_attributes_id, options_values_price, price_prefix,
attributes_display_only, product_attribute_is_free,
attributes_discounted
*/
$attribute_price_query = "select *
from " . TABLE_PRODUCTS_ATTRIBUTES . "
where products_id = '" . (int)$prid . "'
and options_id = '" . (int)$option . "'
and options_values_id = '" . (int)$value . "'";
$attribute_price = $db->Execute($attribute_price_query);
$new_attributes_price = 0;
$discount_type_id = '';
$sale_maker_discount = '';
// bottom total
// if ($attribute_price->fields['product_attribute_is_free']) {
if ($attribute_price->fields['product_attribute_is_free'] == '1' and zen_get_products_price_is_free((int)$prid)) {
// no charge for attribute
} else {
// + or blank adds
if ($attribute_price->fields['price_prefix'] == '-') {
if ($attribute_price->fields['attributes_discounted'] == '1') {
// calculate proper discount for attributes
$new_attributes_price = zen_get_discount_calc($product->fields['products_id'], $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price'], $qty);
$this->total -= $qty * zen_add_tax( ($new_attributes_price), $products_tax);
// appears to confuse products priced by attributes
// $this->free_shipping_price -= $qty * zen_add_tax( ($new_attributes_price), $products_tax);
} else {
$this->total -= $qty * zen_add_tax($attribute_price->fields['options_values_price'], $products_tax);
}
} else {
if ($attribute_price->fields['attributes_discounted'] == '1') {
// calculate proper discount for attributes
$new_attributes_price = zen_get_discount_calc($product->fields['products_id'], $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price'], $qty);
$this->total += $qty * zen_add_tax( ($new_attributes_price), $products_tax);
// appears to confuse products priced by attributes
// $this->free_shipping_price += $qty * zen_add_tax( ($new_attributes_price), $products_tax);
} else {
$this->total += $qty * zen_add_tax($attribute_price->fields['options_values_price'], $products_tax);
}
}
////////////////////////////////////////////////
// calculate additional attribute charges
$chk_price = zen_get_products_base_price($products_id);
$chk_special = zen_get_products_special_price($products_id, false);
// products_options_value_text
if (zen_get_attributes_type($attribute_price->fields['products_attributes_id']) == PRODUCTS_OPTIONS_TYPE_TEXT) {
$text_words = zen_get_word_count_price($this->contents[$products_id]['attributes_values'][$attribute_price->fields['options_id']], $attribute_price->fields['attributes_price_words_free'], $attribute_price->fields['attributes_price_words']);
$text_letters = zen_get_letters_count_price($this->contents[$products_id]['attributes_values'][$attribute_price->fields['options_id']], $attribute_price->fields['attributes_price_letters_free'], $attribute_price->fields['attributes_price_letters']);
$this->total += $qty * zen_add_tax($text_letters, $products_tax);
$this->total += $qty * zen_add_tax($text_words, $products_tax);
}
// attributes_price_factor
$added_charge = 0;
if ($attribute_price->fields['attributes_price_factor'] > 0) {
$added_charge = zen_get_attributes_price_factor($chk_price, $chk_special, $attribute_price->fields['attributes_price_factor'], $attribute_price->fields['attributes_price_factor_offset']);
$this->total += $qty * zen_add_tax($added_charge, $products_tax);
}
// attributes_qty_prices
$added_charge = 0;
if ($attribute_price->fields['attributes_qty_prices'] != '') {
$added_charge = zen_get_attributes_qty_prices_onetime($attribute_price->fields['attributes_qty_prices'], $qty);
$this->total += $qty * zen_add_tax($added_charge, $products_tax);
}
//// one time charges
// attributes_price_onetime
if ($attribute_price->fields['attributes_price_onetime'] > 0) {
$this->total += zen_add_tax($attribute_price->fields['attributes_price_onetime'], $products_tax);
}
// attributes_price_factor_onetime
$added_charge = 0;
if ($attribute_price->fields['attributes_price_factor_onetime'] > 0) {
$chk_price = zen_get_products_base_price($products_id);
$chk_special = zen_get_products_special_price($products_id, false);
$added_charge = zen_get_attributes_price_factor($chk_price, $chk_special, $attribute_price->fields['attributes_price_factor_onetime'], $attribute_price->fields['attributes_price_factor_onetime_offset']);
$this->total += zen_add_tax($added_charge, $products_tax);
}
// attributes_qty_prices_onetime
$added_charge = 0;
if ($attribute_price->fields['attributes_qty_prices_onetime'] != '') {
$chk_price = zen_get_products_base_price($products_id);
$chk_special = zen_get_products_special_price($products_id, false);
$added_charge = zen_get_attributes_qty_prices_onetime($attribute_price->fields['attributes_qty_prices_onetime'], $qty);
$this->total += zen_add_tax($added_charge, $products_tax);
}
////////////////////////////////////////////////
}
}
} // attributes price
// attributes weight
if (isset($this->contents[$products_id]['attributes'])) {
reset($this->contents[$products_id]['attributes']);
while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
$attribute_weight_query = "select products_attributes_weight, products_attributes_weight_prefix
from " . TABLE_PRODUCTS_ATTRIBUTES . "
where products_id = '" . (int)$prid . "'
and options_id = '" . (int)$option . "'
and options_values_id = '" . (int)$value . "'";
$attribute_weight = $db->Execute($attribute_weight_query);
// adjusted count for free shipping
if ($product->fields['product_is_always_free_shipping'] != 1) {
$new_attributes_weight = $attribute_weight->fields['products_attributes_weight'];
} else {
$new_attributes_weight = 0;
}
// + or blank adds
if ($attribute_weight->fields['products_attributes_weight_prefix'] == '-') {
$this->weight -= $qty * $new_attributes_weight;
} else {
$this->weight += $qty * $new_attributes_weight;
}
}
} // attributes weight
}
}
/**
* Method to calculate price of attributes for a given item
*
* @param mixed the product ID of the item to check
* @return decimal the pice of the items attributes
* @global object access to the db object
*/
function attributes_price($products_id) {
global $db;
$attributes_price = 0;
$qty = $this->contents[$products_id]['qty'];
if (isset($this->contents[$products_id]['attributes'])) {
reset($this->contents[$products_id]['attributes']);
while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
$attribute_price_query = "select *
from " . TABLE_PRODUCTS_ATTRIBUTES . "
where products_id = '" . (int)$products_id . "'
and options_id = '" . (int)$option . "'
and options_values_id = '" . (int)$value . "'";
$attribute_price = $db->Execute($attribute_price_query);
$new_attributes_price = 0;
$discount_type_id = '';
$sale_maker_discount = '';
// if ($attribute_price->fields['product_attribute_is_free']) {
if ($attribute_price->fields['product_attribute_is_free'] == '1' and zen_get_products_price_is_free((int)$products_id)) {
// no charge
} else {
// + or blank adds
if ($attribute_price->fields['price_prefix'] == '-') {
// calculate proper discount for attributes
if ($attribute_price->fields['attributes_discounted'] == '1') {
$discount_type_id = '';
$sale_maker_discount = '';
$new_attributes_price = zen_get_discount_calc($products_id, $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price'], $qty);
$attributes_price -= ($new_attributes_price);
} else {
$attributes_price -= $attribute_price->fields['options_values_price'];
}
} else {
if ($attribute_price->fields['attributes_discounted'] == '1') {
// calculate proper discount for attributes
$discount_type_id = '';
$sale_maker_discount = '';
$new_attributes_price = zen_get_discount_calc($products_id, $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price'], $qty);
$attributes_price += ($new_attributes_price);
} else {
$attributes_price += $attribute_price->fields['options_values_price'];
}
}
//////////////////////////////////////////////////
// calculate additional charges
// products_options_value_text
if (zen_get_attributes_type($attribute_price->fields['products_attributes_id']) == PRODUCTS_OPTIONS_TYPE_TEXT) {
$text_words = zen_get_word_count_price($this->contents[$products_id]['attributes_values'][$attribute_price->fields['options_id']], $attribute_price->fields['attributes_price_words_free'], $attribute_price->fields['attributes_price_words']);
$text_letters = zen_get_letters_count_price($this->contents[$products_id]['attributes_values'][$attribute_price->fields['options_id']], $attribute_price->fields['attributes_price_letters_free'], $attribute_price->fields['attributes_price_letters']);
$attributes_price += $text_letters;
$attributes_price += $text_words;
}
// attributes_price_factor
$added_charge = 0;
if ($attribute_price->fields['attributes_price_factor'] > 0) {
$chk_price = zen_get_products_base_price($products_id);
$chk_special = zen_get_products_special_price($products_id, false);
$added_charge = zen_get_attributes_price_factor($chk_price, $chk_special, $attribute_price->fields['attributes_price_factor'], $attribute_price->fields['attributes_price_factor_offset']);
$attributes_price += $added_charge;
}
// attributes_qty_prices
$added_charge = 0;
if ($attribute_price->fields['attributes_qty_prices'] != '') {
$chk_price = zen_get_products_base_price($products_id);
$chk_special = zen_get_products_special_price($products_id, false);
$added_charge = zen_get_attributes_qty_prices_onetime($attribute_price->fields['attributes_qty_prices'], $this->contents[$products_id]['qty']);
$attributes_price += $added_charge;
}
//////////////////////////////////////////////////
}
// Validate Attributes
if ($attribute_price->fields['attributes_display_only']) {
$_SESSION['valid_to_checkout'] = false;
$_SESSION['cart_errors'] .= zen_get_products_name($attribute_price->fields['products_id'], $_SESSION['languages_id']) . ERROR_PRODUCT_OPTION_SELECTION . '<br />';
}
/*
//// extra testing not required on text attribute this is done in application_top before it gets to the cart
if ($attribute_price->fields['attributes_required']) {
$_SESSION['valid_to_checkout'] = false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -