📄 shopping_cart.php
字号:
function show_weight() {
$this->calculate();
return $this->weight;
}
/**
* Method to generate a cart ID
*
* @param length of ID to generate
* @return string cart ID
*/
function generate_cart_id($length = 5) {
return zen_create_random_value($length, 'digits');
}
/**
* Method to calculate the content type of a cart
*
* @param boolean whether to test for Gift Vouchers only
* @return string
*/
function get_content_type($gv_only = 'false') {
global $db;
$this->content_type = false;
$gift_voucher = 0;
// if ( (DOWNLOAD_ENABLED == 'true') && ($this->count_contents() > 0) ) {
if ( $this->count_contents() > 0 ) {
reset($this->contents);
while (list($products_id, ) = each($this->contents)) {
$free_ship_check = $db->Execute("select products_virtual, products_model, products_price, product_is_always_free_shipping from " . TABLE_PRODUCTS . " where products_id = '" . zen_get_prid($products_id) . "'");
$virtual_check = false;
if (ereg('^GIFT', addslashes($free_ship_check->fields['products_model']))) {
$gift_voucher += ($free_ship_check->fields['products_price'] + $this->attributes_price($products_id)) * $this->contents[$products_id]['qty'];
}
// product_is_always_free_shipping = 2 is special requires shipping
// Example: Product with download
if (isset($this->contents[$products_id]['attributes']) and $free_ship_check->fields['product_is_always_free_shipping'] != 2) {
reset($this->contents[$products_id]['attributes']);
while (list(, $value) = each($this->contents[$products_id]['attributes'])) {
$virtual_check_query = "select count(*) as total
from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, "
. TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
where pa.products_id = '" . (int)$products_id . "'
and pa.options_values_id = '" . (int)$value . "'
and pa.products_attributes_id = pad.products_attributes_id";
$virtual_check = $db->Execute($virtual_check_query);
if ($virtual_check->fields['total'] > 0) {
switch ($this->content_type) {
case 'physical':
$this->content_type = 'mixed';
if ($gv_only == 'true') {
return $gift_voucher;
} else {
return $this->content_type;
}
break;
default:
$this->content_type = 'virtual';
break;
}
} else {
switch ($this->content_type) {
case 'virtual':
if ($free_ship_check->fields['products_virtual'] == '1') {
$this->content_type = 'virtual';
} else {
$this->content_type = 'mixed';
if ($gv_only == 'true') {
return $gift_voucher;
} else {
return $this->content_type;
}
}
break;
case 'physical':
if ($free_ship_check->fields['products_virtual'] == '1') {
$this->content_type = 'mixed';
if ($gv_only == 'true') {
return $gift_voucher;
} else {
return $this->content_type;
}
} else {
$this->content_type = 'physical';
}
break;
default:
if ($free_ship_check->fields['products_virtual'] == '1') {
$this->content_type = 'virtual';
} else {
$this->content_type = 'physical';
}
}
}
}
} else {
switch ($this->content_type) {
case 'virtual':
if ($free_ship_check->fields['products_virtual'] == '1') {
$this->content_type = 'virtual';
} else {
$this->content_type = 'mixed';
if ($gv_only == 'true') {
return $gift_voucher;
} else {
return $this->content_type;
}
}
break;
case 'physical':
if ($free_ship_check->fields['products_virtual'] == '1') {
$this->content_type = 'mixed';
if ($gv_only == 'true') {
return $gift_voucher;
} else {
return $this->content_type;
}
} else {
$this->content_type = 'physical';
}
break;
default:
if ($free_ship_check->fields['products_virtual'] == '1') {
$this->content_type = 'virtual';
} else {
$this->content_type = 'physical';
}
}
}
}
} else {
$this->content_type = 'physical';
}
if ($gv_only == 'true') {
return $gift_voucher;
} else {
return $this->content_type;
}
}
/**
* Method to unserialize a cart object
*
* @deprecated
* @private
*/
function unserialize($broken) {
for(reset($broken);$kv=each($broken);) {
$key=$kv['key'];
if (gettype($this->$key)!="user function")
$this->$key=$kv['value'];
}
}
/**
* Method to calculate item quantity, bounded the mixed/min units settings
*
* @param boolean product id of item to check
* @return deciaml
*/
function in_cart_mixed($products_id) {
global $db;
// if nothing is in cart return 0
if (!is_array($this->contents)) return 0;
// check if mixed is on
// $product = $db->Execute("select products_id, products_quantity_mixed from " . TABLE_PRODUCTS . " where products_id='" . (int)$products_id . "' limit 1");
$product = $db->Execute("select products_id, products_quantity_mixed from " . TABLE_PRODUCTS . " where products_id='" . zen_get_prid($products_id) . "' limit 1");
// if mixed attributes is off return qty for current attribute selection
if ($product->fields['products_quantity_mixed'] == '0') {
return $this->get_quantity($products_id);
}
// compute total quantity regardless of attributes
$in_cart_mixed_qty = 0;
$chk_products_id= zen_get_prid($products_id);
// reset($this->contents); // breaks cart
$check_contents = $this->contents;
while (list($products_id, ) = each($check_contents)) {
$test_id = zen_get_prid($products_id);
if ($test_id == $chk_products_id) {
$in_cart_mixed_qty += $check_contents[$products_id]['qty'];
}
}
return $in_cart_mixed_qty;
}
/**
* Method to calculate item quantity, bounded the mixed/min units settings
*
* @param boolean product id of item to check
* @return deciaml
*/
function in_cart_mixed_discount_quantity($products_id) {
global $db;
// if nothing is in cart return 0
if (!is_array($this->contents)) return 0;
// check if mixed is on
// $product = $db->Execute("select products_id, products_mixed_discount_quantity from " . TABLE_PRODUCTS . " where products_id='" . (int)$products_id . "' limit 1");
$product = $db->Execute("select products_id, products_mixed_discount_quantity from " . TABLE_PRODUCTS . " where products_id='" . zen_get_prid($products_id) . "' limit 1");
// if mixed attributes is off return qty for current attribute selection
if ($product->fields['products_mixed_discount_quantity'] == '0') {
return $this->get_quantity($products_id);
}
// compute total quantity regardless of attributes
$in_cart_mixed_qty_discount_quantity = 0;
$chk_products_id= zen_get_prid($products_id);
// reset($this->contents); // breaks cart
$check_contents = $this->contents;
while (list($products_id, ) = each($check_contents)) {
$test_id = zen_get_prid($products_id);
if ($test_id == $chk_products_id) {
$in_cart_mixed_qty_discount_quantity += $check_contents[$products_id]['qty'];
}
}
return $in_cart_mixed_qty_discount_quantity;
}
/**
* Method to calculate the number of items in a cart based on an abitrary property
*
* $check_what is the fieldname example: 'products_is_free'
* $check_value is the value being tested for - default is 1
* Syntax: $_SESSION['cart']->in_cart_check('product_is_free','1');
*
* @param string product field to check
* @param mixed value to check for
* @return integer number of items matching restraint
*/
function in_cart_check($check_what, $check_value='1') {
global $db;
// if nothing is in cart return 0
if (!is_array($this->contents)) return 0;
// compute total quantity for field
$in_cart_check_qty=0;
reset($this->contents);
while (list($products_id, ) = each($this->contents)) {
$testing_id = zen_get_prid($products_id);
// check if field it true
$product_check = $db->Execute("select " . $check_what . " as check_it from " . TABLE_PRODUCTS . " where products_id='" . $testing_id . "' limit 1");
if ($product_check->fields['check_it'] == $check_value) {
$in_cart_check_qty += $this->contents[$products_id]['qty'];
}
}
return $in_cart_check_qty;
}
/**
* Method to check whether cart contains only Gift Vouchers
*
* @return mixed value of Gift Vouchers in cart
*/
function gv_only() {
$gift_voucher = $this->get_content_type(true);
return $gift_voucher;
}
/**
* Method to return the number of free shipping items in the cart
*
* @return decimal
*/
function free_shipping_items() {
$this->calculate();
return $this->free_shipping_item;
}
/**
* Method to return the total price of free shipping items in the cart
*
* @return decimal
*/
function free_shipping_prices() {
$this->calculate();
return $this->free_shipping_price;
}
/**
* Method to return the total weight of free shipping items in the cart
*
* @return decimal
*/
function free_shipping_weight() {
$this->calculate();
return $this->free_shipping_weight;
}
/**
* Method to handle cart Action - update product
*
* @param string forward destination
* @param url parameters
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -