Das ist die Funktion für den Einkaufswagen: class.shopping_cart.php
<?php
/* -----------------------------------------------------------------------------------------
$Id: class.shopping_cart.php 3669 2010-02-02 18:25:19Z hhgag $
H.H.G. multistore
http://www.hhg-multistore.com/
Copyright (c) 2005-2010 H.H.G. group
-----------------------------------------------------------------------------------------
based on:
(c) 2000-2001 The Exchange Project (earlier name of osCommerce)
(c) 2002-2003 osCommerce(shopping_cart.php,v 1.32 2003/02/11); www.oscommerce.com
(c) 2003 nextcommerce (shopping_cart.php,v 1.21 2003/08/17); www.nextcommerce.org
(c) 2003-2005 xt:commerce (shopping_cart.php 1534 2006-08-20); www.xt-commerce.com
Released under the GNU General Public License
-----------------------------------------------------------------------------------------
Third Party contributions:
Customers Status v3.x (c) 2002-2003 Copyright Elari elari@free.fr | www.unlockgsm.com/dload-osc/ | CVS : http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/elari/?sortby=date#dirlist
Credit Class/Gift Vouchers/Discount Coupons (Version 5.10)
http://www.oscommerce.com/community/contributions,282
Copyright (c) Strider | Strider@oscworks.com
Copyright (c Nick Stanko of UkiDev.com, nick@ukidev.com
Copyright (c) Andre ambidex@gmx.net
Copyright (c) 2001,2002 Ian C Wilson http://www.phesis.org
Released under the GNU General Public License
---------------------------------------------------------------------------------------*/
// include needed functions
require_once (DIR_FS_CORE_INC . 'inc.hhg_create_random_value.php');
require_once (DIR_FS_CORE_INC . 'inc.hhg_get_prid.php');
require_once (DIR_FS_CORE_INC . 'inc.hhg_draw_form.php');
require_once (DIR_FS_CORE_INC . 'inc.hhg_draw_input_field.php');
require_once (DIR_FS_CORE_INC . 'inc.hhg_image_submit.php');
require_once (DIR_FS_CORE_INC . 'inc.hhg_get_tax_description.php');
require_once (DIR_FS_CORE_INC . 'inc.hhg_get_products_name.php');
require_once (DIR_FS_CORE_INC . 'inc.hhg_get_store_name.php');
class shopping_cart
{
var $contents, $total, $weight, $cartID, $content_type;
function __construct()
{
$this->cleanup_cart();
}
//------------------------------------------------------------------------------------------------------------------------------
function add_cart($products_id, $qty = 1, $tmp_store_id = STORE_ID, $optionCategs = false)
{
global $xtPrice;
$compare_option = '';
if (is_array($optionCategs)) {
foreach($optionCategs as $key => $option_id) {
foreach($_SESSION['variants_config'][$products_id] as $_key => $options) {
if (array_key_exists($key, $options)) {
$_SESSION['variants_config'][$products_id][$_key][$key]['selected'] = $option_id;
}
}
if (is_array($option_id)) {
foreach($option_id as $__option_id) {
$compare_option.= $key . ',' . $__option_id . ';';
}
} else {
$compare_option.= $key . ',' . $option_id . ';';
}
}
} // merge options to string
if (isset($_SESSION['customer_id'])) {
$basket_table = TABLE_MS_CUSTOMERS_BASKET;
$basket_table_option = TABLE_MS_CUSTOMERS_BASKET_OPTIONS;
$insert_sql = " SELECT customers_basket_id, products_id, products_model, products_options, products_owner, products_price, products_price_ek, products_quantity, products_final_price, products_weight, products_shippingtime
FROM " . $basket_table . "
WHERE products_id='" . $products_id . "' and
customers_id = '" . $_SESSION['customer_id'] . "' and
products_options = '" . $compare_option . "' AND
store_id = '" . $tmp_store_id . "'";
$cart = hhg_db_query($insert_sql);
} else {
$basket_table = TABLE_MS_CUSTOMERS_BASKET_TMP;
$basket_table_option = TABLE_MS_CUSTOMERS_BASKET_OPTIONS_TMP;
$sid = session_id();
$insert_sql = "select customers_basket_id, sid, products_id, products_model, products_options, products_owner, products_price, products_price_ek, products_quantity, products_final_price, products_weight, products_shippingtime
from " . $basket_table . "
where
products_id='" . $products_id . "' and
products_options = '" . $compare_option . "' AND
sid = '" . $sid . "' and
store_id = '" . $tmp_store_id . "'";
$cart = hhg_db_query($insert_sql);
}
if ($cart->RecordCount() == 0) {
$c_action = 'insert';
$qty = $qty;
} else {
$c_action = 'update';
$qty = $qty + $cart->fields['products_quantity'];
}
$product = hhg_db_query(" SELECT products_id, products_model, products_owner, products_price, products_price_ek, products_tax_class_id, products_weight, products_shippingtime
FROM " . TABLE_PRODUCTS . "
WHERE products_id='" . $products_id . "'");
if ($product->RecordCount() > 0) {
$price = $xtPrice->xtcGetPrice($products_id, false, $qty, 0, $product->fields['products_price'], 0, 0, $product->fields['products_owner'], $tmp_store_id);
$final_price = ($price * $qty);
if (isset($_SESSION['customer_id'])) {
$sid = $_SESSION['customer_id'];
} else {
$sid = $sid;
}
$sql_data_array = array(
'customers_id' => $sid,
'products_id' => $products_id,
'products_model' => $product->fields['products_model'],
'products_options' => $compare_option,
'products_owner' => $product->fields['products_owner'],
'products_quantity' => $qty,
'products_price' => $price,
'products_price_ek' => $product->fields['products_price_ek'],
'products_tax_class' => $product->fields['products_tax_class_id'],
'products_final_price' => $final_price,
'products_weight' => $product->fields['products_weight'],
'products_shippingtime' => $product->fields['products_shippingtime'],
'customers_basket_date_added' => date('Ymd') ,
'store_id' => $tmp_store_id
);
if ($c_action == 'insert') {
if (!isset($_SESSION['customer_id'])) {
$sid_array = array(
'sid' => $sid
);
$sql_data_array = array_merge($sql_data_array, $sid_array);
}
$basket_id = hhg_db_perform($basket_table, $sql_data_array);
if (is_array($optionCategs) && $basket_id != false) {
foreach($optionCategs as $key => $option_id) {
if (is_array($option_id)) {
foreach($option_id as $__option_id) {
$sql_data_options_array = array(
'customers_basket_id' => $basket_id,
'products_id' => $products_id,
'option_categ' => $key,
'option_id' => $__option_id,
'store_id' => $tmp_store_id
);
hhg_db_perform($basket_table_option, $sql_data_options_array);
}
} else {
$sql_data_options_array = array(
'customers_basket_id' => $basket_id,
'products_id' => $products_id,
'option_categ' => $key,
'option_id' => $option_id,
'store_id' => $tmp_store_id
);
hhg_db_perform($basket_table_option, $sql_data_options_array);
}
}
}
} elseif ($c_action == 'update') {
if (isset($_SESSION['customer_id'])) {
hhg_db_perform($basket_table, $sql_data_array, 'update', 'products_options="' . $compare_option . '" AND products_id = ' . hhg_db_prepare($products_id) . ' and customers_id = ' . hhg_db_prepare($_SESSION['customer_id']) . ' and store_id = ' . hhg_db_prepare($tmp_store_id) . '');
} else {
hhg_db_perform($basket_table, $sql_data_array, 'update', 'products_options="' . $compare_option . '" AND products_id = ' . hhg_db_prepare($products_id) . ' and sid = ' . hhg_db_prepare($sid) . ' and store_id = ' . hhg_db_prepare($tmp_store_id) . '');
}
}
}
$this->cartID = $this->generate_cart_id();
}
//------------------------------------------------------------------------------------------------------------------------------
function update_product($products_id, $cart_id, $qty = 1, $tmp_store_id = STORE_ID)
{
global $xtPrice;
$store_qry = $this->get_store_filter($tmp_store_id);
if (isset($_SESSION['customer_id'])) {
$basket_table = TABLE_MS_CUSTOMERS_BASKET;
$cart_query = "
SELECT
customers_basket_id,
products_id,
products_model,
products_owner,
products_price,
products_price_ek,
products_quantity,
products_final_price,
products_weight,
products_shippingtime
FROM
" . $basket_table . "
WHERE
products_id = '" . $products_id . "'
AND customers_id = '" . $_SESSION['customer_id'] . "'
" . $store_qry . "
";
} else {
$basket_table = TABLE_MS_CUSTOMERS_BASKET_TMP;
$sid = session_id();
$cart_query = "
SELECT
customers_basket_id,
sid,
products_id,
products_model,
products_owner,
products_price,
products_price_ek,
products_quantity,
products_final_price,
products_weight,
products_shippingtime
FROM
" . $basket_table . "
WHERE
products_id = '" . $products_id . "'
AND sid = '" . $sid . "'
" . $store_qry . "
";
}
$cart = hhg_db_query($cart_query);
$product_query = "
SELECT
products_id,
products_model,
products_owner,
products_price,
products_price_ek,
products_tax_class_id,
products_weight,
products_shippingtime
FROM
" . TABLE_PRODUCTS . "
WHERE
products_id='" . $products_id . "'
";
$product = hhg_db_query($product_query);
if ($product->RecordCount()) {
if ($qty < 0) {
$qty = 0;
}
$base_raw_price = $product->fields['products_price'];
$price = $xtPrice->xtcGetPrice($products_id, false, $qty, 0, $product->fields['products_price'], '', '', $product->fields['products_owner'], $tmp_store_id, false);
$final_price = ($price * $qty);
$sql_data_array = array(
'products_quantity' => $qty,
'products_price' => $price,
'products_price_ek' => $product->fields['products_price_ek']*$qty,
'products_final_price' => $final_price,
'customers_basket_date_added' => date('Ymd')
);
if (isset($_SESSION['customer_id'])) {
$customer = " AND customers_id = " . hhg_db_prepare($_SESSION['customer_id']) . " ";
} else {
$customer = " AND sid = " . hhg_db_prepare($sid) . " ";
}
if ($qty == 0) {
$sql = "
DELETE
FROM
" . $basket_table . "
WHERE
products_id = " . hhg_db_prepare($products_id) . "
AND customers_basket_id = " . hhg_db_prepare($cart_id) . "
" . $customer . "
" . $store_qry . "
";
hhg_db_query($sql);
} else {
hhg_db_perform($basket_table, $sql_data_array, 'update', 'products_id = ' . hhg_db_prepare($products_id) . ' AND customers_basket_id = ' . hhg_db_prepare($cart_id) . $customer . $store_qry . '');
}
}
$this->cartID = $this->generate_cart_id();
}
//------------------------------------------------------------------------------------------------------------------------------
function sync_cart($tmp_store_id = STORE_ID, $old_session = "")
{
global $xtPrice;
$store_qry = $this->get_store_filter($tmp_store_id);
if ($old_session != "") {
$sid = $old_session;
} else {
$sid = session_id();
}
$tmp_cart_query = "
SELECT
*
FROM
" . TABLE_MS_CUSTOMERS_BASKET_TMP . "
WHERE
sid = '" . $sid . "'
" . $store_qry . "
";
$tmp_cart = hhg_db_query($tmp_cart_query);
while (!$tmp_cart->EOF) {
$check_query = "
SELECT
*
FROM
" . TABLE_MS_CUSTOMERS_BASKET . "
WHERE
products_id='" . $tmp_cart->fields['products_id'] . "'
AND customers_id = '" . $_SESSION['customer_id'] . "'
AND products_options = '" . $tmp_cart->fields['products_options'] . "'
" . $store_qry . "
";
$check = hhg_db_query($check_query);
$this->cartID = $this->generate_cart_id();
if ($check->RecordCount() >= 1 && $tmp_cart->fields['products_options'] == $check->fields['products_options']) { // product available, just update
$product = hhg_db_query("select products_id, products_model, products_owner, products_price, products_tax_class_id, products_weight, products_shippingtime from " . TABLE_PRODUCTS . " where products_id='" . $tmp_cart->fields['products_id'] . "'");
$qty = $tmp_cart->fields['products_quantity'] + $check->fields['products_quantity'];
$price = $xtPrice->xtcGetPrice($tmp_cart->fields['products_id'], 'false', $qty, '', $product->fields['products_price'], '', '', $product->fields['products_owner'], $tmp_store_id, false);
$final_price = ($price * $qty);
$sql_data_array = array(
'products_model' => $product->fields['products_model'],
'products_weight' => $product->fields['products_weight'],
'products_shippingtime' => $product->fields['products_shippingtime'],
'products_quantity' => $qty,
'products_price' => $price,
'products_price_ek' => $product->fields['products_price_ek']*$qty,
'products_final_price' => $final_price,
'customers_basket_date_added' => date('Ymd')
);
$this->contents[$tmp_cart->fields['products_id']] = array(
'qty' => $tmp_cart->fields['products_quantity']
);
hhg_db_perform(TABLE_MS_CUSTOMERS_BASKET, $sql_data_array, 'update', 'customers_basket_id = ' . hhg_db_prepare($check->fields['customers_basket_id']) . ' and customers_id = ' . hhg_db_prepare($_SESSION['customer_id']) . ' and store_id = ' . hhg_db_prepare($tmp_store_id) . '');
} else { // new product
$sql_data_array = array(
'customers_id' => $_SESSION['customer_id'],
'products_id' => $tmp_cart->fields['products_id'],
'products_model' => $tmp_cart->fields['products_model'],
'products_options' => $tmp_cart->fields['products_options'],
'products_owner' => $tmp_cart->fields['products_owner'],
'products_alternate_name' => $tmp_cart->fields['products_alternate_name'],
'products_alternate_desc' => $tmp_cart->fields['products_alternate_desc'],
'products_quantity' => $tmp_cart->fields['products_quantity'],
'products_price' => $tmp_cart->fields['products_price'],
'products_price_ek' => $tmp_cart->fields['products_price_ek'],
'products_tax_class' => $tmp_cart->fields['products_tax_class'],
'products_final_price' => $tmp_cart->fields['products_final_price'],
'products_weight' => $tmp_cart->fields['products_weight'],
'products_shippingtime' => $tmp_cart->fields['products_shippingtime'],
'customers_basket_date_added' => date('Ymd') ,
'store_id' => $tmp_store_id
);
$this->contents[$tmp_cart->fields['products_id']] = array(
'qty' => $tmp_cart->fields['products_quantity']
);
$insert_id = hhg_db_perform(TABLE_MS_CUSTOMERS_BASKET, $sql_data_array);
if ($tmp_cart->fields['products_options'] != "") {
$options = hhg_db_query(" select *
from " . TABLE_MS_CUSTOMERS_BASKET_OPTIONS_TMP . "
where
customers_basket_id='" . $tmp_cart->fields['customers_basket_id'] . "' and
store_id = '" . $_SESSION['actual_store'] . "'");
while (!$options->EOF) {
$sql_data_array = array(
'customers_basket_id' => $insert_id,
'products_id' => $options->fields['products_id'],
'option_categ' => $options->fields['option_categ'],
'option_id' => $options->fields['option_id'],
'store_id' => $options->fields['store_id'],
);
hhg_db_perform(TABLE_MS_CUSTOMERS_BASKET_OPTIONS, $sql_data_array);
$options->MoveNext();
}
}
}
hhg_db_query("delete from " . TABLE_MS_CUSTOMERS_BASKET_TMP . " where customers_basket_id = '" . $tmp_cart->fields['customers_basket_id'] . "'");
hhg_db_query("delete from " . TABLE_MS_CUSTOMERS_BASKET_OPTIONS_TMP . " where customers_basket_id = '" . $tmp_cart->fields['customers_basket_id'] . "' and store_id=" . $_SESSION['actual_store']);
$tmp_cart->MoveNext();
}
}
//------------------------------------------------------------------------------------------------------------------------------
function del_cart($customers_basket_id)
{
if (!isset($_SESSION['customer_id'])) {
hhg_db_query("delete from " . TABLE_MS_CUSTOMERS_BASKET_TMP . " where customers_basket_id = '" . $customers_basket_id . "'");
hhg_db_query("delete from " . TABLE_MS_CUSTOMERS_BASKET_OPTIONS_TMP . " where customers_basket_id = '" . $customers_basket_id . "'");
} else {
hhg_db_query("delete from " . TABLE_MS_CUSTOMERS_BASKET . " where customers_basket_id = '" . $customers_basket_id . "'");
hhg_db_query("delete from " . TABLE_MS_CUSTOMERS_BASKET_OPTIONS . " where customers_basket_id = '" . $customers_basket_id . "'");
}
}
//------------------------------------------------------------------------------------------------------------------------------
function cleanup_cart()
{
$cleanup_query = "
SELECT
customers_basket_id
FROM
" . TABLE_MS_CUSTOMERS_BASKET_TMP . "
WHERE
customers_basket_date_added < " . date('Ymd', time() - get_cfg_var('session.gc_maxlifetime')) . "
";
$cleanup = hhg_db_query($cleanup_query);
if ($cleanup->RecordCount()) {
while (!$cleanup->EOF) {
hhg_db_query("DELETE FROM " . TABLE_MS_CUSTOMERS_BASKET_TMP . " WHERE customers_basket_id = '" . $cleanup->fields['customers_basket_id'] . "'");
hhg_db_query("DELETE FROM " . TABLE_MS_CUSTOMERS_BASKET_OPTIONS_TMP . " WHERE customers_basket_id = '" . $cleanup->fields['customers_basket_id'] . "'");
$cleanup->MoveNext();
}
}
}
//------------------------------------------------------------------------------------------------------------------------------
function get_products($tmp_store_id = STORE_ID, $tmp_owner = null)
{
global $xtPrice, $shipping_status;
$store_qry = $this->get_store_filter($tmp_store_id, $tmp_owner);
if (isset($_SESSION['customer_id'])) {
$basket_table = TABLE_MS_CUSTOMERS_BASKET;
$products_query = "
SELECT
customers_basket_id,
products_id,
products_model,
products_owner,
products_alternate_name,
products_alternate_desc,
products_price,
products_price_ek,
products_tax_class,
products_quantity,
products_final_price,
products_weight,
products_shippingtime,
store_id
FROM
" . $basket_table . "
WHERE
customers_id = '" . $_SESSION['customer_id'] . "'
" . $store_qry . "
";
} else {
$basket_table = TABLE_MS_CUSTOMERS_BASKET_TMP;
$sid = session_id();
$products_query = "
SELECT
customers_basket_id,
sid,
products_id,
products_model,
products_owner,
products_alternate_name,
products_alternate_desc,
products_price,
products_price_ek,
products_tax_class,
products_quantity,
products_final_price,
products_weight,
products_shippingtime,
store_id
FROM
" . $basket_table . "
WHERE
sid = '" . $sid . "'
" . $store_qry . "
";
}
$products = hhg_db_query($products_query);
while (!$products->EOF) {
$total_price = 0;
$price_ek = 0;
$_options = $this->get_product_options($products->fields['customers_basket_id'], $products->fields['products_id']);
$base_price = $xtPrice->xtcGetPrice($products->fields['products_id'], false, $products->fields['products_quantity'], $products->fields['products_tax_class'], '');
$weight = $products->fields['products_weight'];
if ($_options != false) {
$total_price = $xtPrice->xtcFormat($products->fields['products_price'], false, $products->fields['products_tax_class'], '', '', $products->fields['products_id']);
$price_ek = $products->fields['products_price_ek'];
$weight = $products->fields['products_weight'];
foreach($_options as $_option_product) {
$total_price+= $xtPrice->xtcGetPrice($_option_product['products_id'], false, '', $_option_product['products_tax_class'], $_option_product['product_raw_price']);
$price_ek+= $_option_product['products_price_ek'];
$weight+= $_option_product['products_weight'];
}
$_total_price = $xtPrice->xtcFormat($total_price, true);
} else {
$total_price = $xtPrice->xtcFormat($products->fields['products_price'], false, $products->fields['products_tax_class'], '', '', $products->fields['products_id']);
$_total_price = $base_price;
$_total_price = $xtPrice->xtcFormat($total_price, true);
$price_ek = $products->fields['products_price_ek'];
$weight = $products->fields['products_weight'];
}
// einzelpreis - formatiert
$base_price = $xtPrice->xtcFormat($base_price, true);
$price_ek = $xtPrice->xtcFormat($price_ek, false, $products->fields['products_tax_class']) * $products->fields['products_quantity'];
// gesamtpreis - raw
$final_price = $products->fields['products_quantity'] * $total_price;
// gesamtpreis - formatiert
$_final_price = $xtPrice->xtcFormat($final_price, true);
$name = hhg_get_products_name($products->fields['products_id'], $_SESSION['languages_id']);
$_shipping_name = $shipping_status->getShippingStatusName($products->fields['products_shippingtime']);
if (HHG_MS_SEO_URLS == 'true') {
$url_text_query = hhg_db_query("SELECT url_text from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . $products->fields['products_id'] . "' AND language_id = '" . $_SESSION['languages_id'] . "'");
$url_text = $url_text_query->fields['url_text'];
} else {
$url_text = '';
}
$products_array[] = array(
'cart_id' => $products->fields['customers_basket_id'],
'id' => $products->fields['products_id'],
'owner' => $products->fields['products_owner'],
'name' => $name,
'model' => $products->fields['products_model'],
'price' => $base_price,
'products_price_ek' => $price_ek,
'quantity' => $products->fields['products_quantity'],
'weight' => $weight,
'total_price' => $_total_price,
'final_price' => $_final_price,
'raw_price' => $total_price,
'raw_final_price' => $final_price,
'tax_class_id' => $products->fields['products_tax_class'],
'store_id' => $products->fields['store_id'],
'shipping_time' => $_shipping_name,
'url_text' => $url_text
);
$products->MoveNext();
}
return $products_array;
}
//------------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------------
function get_product_options($cart_id, $products_id)
{
global $xtPrice, $shipping_status;
$option_array = array();
if (isset($_SESSION['customer_id'])) {
$basket_table = TABLE_MS_CUSTOMERS_BASKET;
$basket_options_table = TABLE_MS_CUSTOMERS_BASKET_OPTIONS;
} else {
$basket_table = TABLE_MS_CUSTOMERS_BASKET_TMP;
$basket_options_table = TABLE_MS_CUSTOMERS_BASKET_OPTIONS_TMP;
} // customer_id CHECK end
$_options_qry = "
SELECT
cbo.option_id,
cbo.option_categ,
cbo.store_id,
cb.products_quantity
FROM
" . $basket_options_table . " AS cbo,
" . $basket_table . " AS cb
WHERE
cbo.customers_basket_id = '" . $cart_id . "'
AND cbo.customers_basket_id = cb.customers_basket_id
AND cbo.products_id = '" . $products_id . "'
";
$_options = hhg_db_query($_options_qry);
if ($_options->RecordCount() > 0) {
while (!$_options->EOF) {
$_product = new product($_options->fields['option_id']);
if (STOCK_CHECK == 'true') {
$mark_stock = hhg_check_stock($_product->data['products_id'], $_options->fields['products_quantity'], $_options->fields['store_id']);
if ($mark_stock) {
$_SESSION['any_out_of_stock' . $_options->fields['store_id'] . ''] = 1;
} else {
$_SESSION['any_out_of_stock' . $_options->fields['store_id'] . ''] = 0;
}
}
if (HHG_MS_SEO_URLS == 'true') {
$url_text_query = hhg_db_query("SELECT url_text from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . $_product->data['products_id'] . "' AND language_id = '" . $_SESSION['languages_id'] . "'");
$url_text = $url_text_query->fields['url_text'];
} else {
$url_text = '';
}
$unit_price_raw = $xtPrice->xtcGetPrice($_product->pID, false, $_options->fields['products_quantity'], $_product->data['products_tax_class_id']);
$unit_price = $xtPrice->xtcFormat($unit_price_raw, true);
$option_array[] = array(
'products_id' => $_options->fields['option_id'],
'products_name' => $_product->data['products_name'],
'OUT_OF_STOCK_MARK' => $mark_stock,
'product_raw_price' => $_product->data['products_price'],
'products_tax_class' => $_product->data['products_tax_class_id'],
'products_price' => $unit_price,
'products_price_ek' => $_product->data['products_price_ek'],
'products_owner' => $_product->data['products_owner'],
'products_model' => $_product->data['products_model'],
'products_weight' => $_product->data['products_weight'],
'products_tax_class_id' => $_product->data['products_tax_class_id'],
'store_id' => $_options->fields['store_id'],
'shipping_time' => $shipping_status->getShippingStatusName($_product->data['products_shippingtime']) ,
'url_text' => $url_text
);
$_options->MoveNext();
}
return $option_array;
}
return false;
}
//------------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------------
function count_contents($tmp_store_id = STORE_ID)
{
// get total number of items in cart
$store_qry = $this->get_store_filter($tmp_store_id);
if (isset($_SESSION['customer_id'])) {
$basket_table = TABLE_MS_CUSTOMERS_BASKET;
$cart_query = "
SELECT
products_id,
products_quantity
FROM
" . $basket_table . "
WHERE
customers_id = '" . $_SESSION['customer_id'] . "'
" . $store_qry . "
";
} else {
$basket_table = TABLE_MS_CUSTOMERS_BASKET_TMP;
$sid = session_id();
$cart_query = "
SELECT
products_id,
products_quantity
FROM
" . $basket_table . "
WHERE
sid = '" . $sid . "'
" . $store_qry . "
";
}
$total_items = 0;
$cart = hhg_db_query($cart_query);
while (!$cart->EOF) {
$total_items+= $cart->fields['products_quantity'];
$cart->MoveNext();
}
return $total_items;
}
//------------------------------------------------------------------------------------------------------------------------------
function get_quantity($products_id, $tmp_store_id = STORE_ID)
{
if (isset($_SESSION['customer_id'])) {
$basket_table = TABLE_MS_CUSTOMERS_BASKET;
$product = hhg_db_query("select products_id, products_quantity from " . $basket_table . " where products_id='" . $products_id . "' and customers_id = '" . $_SESSION['customer_id'] . "' and store_id = '" . $tmp_store_id . "'");
} else {
$basket_table = TABLE_MS_CUSTOMERS_BASKET_TMP;
$sid = session_id();
$product = hhg_db_query("select products_id, products_quantity from " . $basket_table . " where products_id='" . $products_id . "' and sid = '" . $sid . "' and store_id = '" . $tmp_store_id . "'");
}
return $product->fields['products_quantity'];
}
//------------------------------------------------------------------------------------------------------------------------------
function in_cart($products_id, $tmp_store_id = STORE_ID)
{
if (isset($_SESSION['customer_id'])) {
$basket_table = TABLE_MS_CUSTOMERS_BASKET;
$product = hhg_db_query("select products_id from " . $basket_table . " where products_id='" . $products_id . "' and customers_id = '" . $_SESSION['customer_id'] . "' and store_id = '" . $tmp_store_id . "'");
} else {
$basket_table = TABLE_MS_CUSTOMERS_BASKET_TMP;
$sid = session_id();
$product = hhg_db_query("select products_id from " . $basket_table . " where products_id='" . $products_id . "' and sid = '" . $sid . "' and store_id = '" . $tmp_store_id . "'");
}
if ($product->RecordCount()) {
return true;
} else {
return false;
}
}
//------------------------------------------------------------------------------------------------------------------------------
function get_product_id_list($tmp_store_id = STORE_ID)
{
if (isset($_SESSION['customer_id'])) {
$basket_table = TABLE_MS_CUSTOMERS_BASKET;
$products = hhg_db_query("select products_id from " . $basket_table . " where customers_id = '" . $_SESSION['customer_id'] . "' and store_id = '" . $tmp_store_id . "'");
} else {
$basket_table = TABLE_MS_CUSTOMERS_BASKET_TMP;
$sid = session_id();
$products = hhg_db_query("select products_id from " . $basket_table . " where sid = '" . $sid . "' and store_id = '" . $tmp_store_id . "'");
}
$product_id_list = '';
while (!$products->EOF) {
$product_id_list.= ', ' . $products->fields['products_id'];
$products->MoveNext();
}
return substr($product_id_list, 2);
}
//------------------------------------------------------------------------------------------------------------------------------
function calculate($tmp_store_id = STORE_ID, $tmp_owner = '')
{
global $xtPrice;
$this->total = 0;
$this->weight = 0;
$this->tax = array();
$store_qry = $this->get_store_filter($tmp_store_id, $tmp_owner);
if (isset($_SESSION['customer_id'])) {
$basket_table = TABLE_MS_CUSTOMERS_BASKET;
$product_query = "
SELECT
customers_basket_id,
products_id,
products_model,
products_owner,
products_alternate_name,
products_alternate_desc,
products_price,
products_price_ek,
products_tax_class,
products_quantity,
products_final_price,
products_weight,
products_shippingtime
FROM
" . $basket_table . "
WHERE
customers_id = '" . $_SESSION['customer_id'] . "'
" . $store_qry . "
";
} else {
$basket_table = TABLE_MS_CUSTOMERS_BASKET_TMP;
$sid = session_id();
$product_query = "
SELECT
customers_basket_id,
sid,
products_id,
products_model,
products_owner,
products_alternate_name,
products_alternate_desc,
products_price,
products_price_ek,
products_tax_class,
products_quantity,
products_final_price,
products_weight,
products_shippingtime
FROM
" . $basket_table . "
WHERE
sid = '" . $sid . "'
" . $store_qry . "
";
}
$product = hhg_db_query($product_query);
while (!$product->EOF) {
$qty = $product->fields['products_quantity'];
$_options = $this->get_product_options($product->fields['customers_basket_id'], $product->fields['products_id']);
if ($_options != false) {
$total_price = $xtPrice->xtcFormat($product->fields['products_price'], false, $product->fields['products_tax_class'], '', '', $product->fields['products_id']);
$weight = $product->fields['products_weight'];
foreach($_options as $_option_product) {
$total_price+= $xtPrice->xtcGetPrice($_option_product['products_id'], false, '', $_option_product['products_tax_class'], $_option_product['product_raw_price']);
$weight+= $_option_product['products_weight'];
}
} else {
$total_price = $xtPrice->xtcFormat($product->fields['products_price'], false, $product->fields['products_tax_class'], '', '', $product->fields['products_id']);
$weight = $product->fields['products_weight'];
}
$products_price = $total_price;
$this->total+= $products_price * $qty;
$this->weight+= ($qty * $weight);
if ($product->fields['products_tax_class'] != 0) {
if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1) {
$products_price_tax = $products_price - ($products_price / 100 * $_SESSION['customers_status']['customers_status_ot_discount']);
}
$products_tax = $xtPrice->TAX[$product->fields['products_tax_class']];
$products_tax_description = hhg_get_tax_description($product->fields['products_tax_class']);
// price incl tax
if ($_SESSION['customers_status']['customers_status_show_price_tax'] == '1') {
if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1) {
$this->tax[$product->fields['products_tax_class']]['value']+= ((($products_price_tax) / (100 + $products_tax)) * $products_tax) * $qty;
$this->tax[$product->fields['products_tax_class']]['desc'] = TAX_ADD_TAX . "$products_tax_description";
} else {
$this->tax[$product->fields['products_tax_class']]['value']+= ((($products_price) / (100 + $products_tax)) * $products_tax) * $qty;
$this->tax[$product->fields['products_tax_class']]['desc'] = TAX_ADD_TAX . "$products_tax_description";
}
}
// excl tax + tax at checkout
if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) {
if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1) {
$this->tax[$product->fields['products_tax_class']]['value']+= (($products_price_tax) / 100) * ($products_tax) * $qty;
$this->total+= (($products_price_tax) / 100) * ($products_tax) * $qty;
$this->tax[$product->fields['products_tax_class']]['desc'] = TAX_NO_TAX . "$products_tax_description";
} else {
$this->tax[$product->fields['products_tax_class']]['value']+= (($products_price) / 100) * ($products_tax) * $qty;
$this->total+= (($products_price) / 100) * ($products_tax) * $qty;
$this->tax[$product->fields['products_tax_class']]['desc'] = TAX_NO_TAX . "$products_tax_description";
}
}
}
$product->MoveNext();
}
$this->get_content_type();
}
//------------------------------------------------------------------------------------------------------------------------------
function generate_cart_id($length = 5)
{
return hhg_create_random_value($length, 'digits');
}
//------------------------------------------------------------------------------------------------------------------------------
function show_total($tmp_store_id = STORE_ID, $tmp_owner = '')
{
$this->calculate($tmp_store_id, $tmp_owner);
return $this->total;
}
//------------------------------------------------------------------------------------------------------------------------------
function show_weight($tmp_store_id = STORE_ID, $tmp_owner = '')
{
$this->calculate($tmp_store_id, $tmp_owner);
return $this->weight;
}
//------------------------------------------------------------------------------------------------------------------------------
function show_tax($format = true, $tmp_store_id = STORE_ID, $tmp_owner = '')
{
global $xtPrice;
$this->calculate($tmp_owner, '');
$output = "";
$val = 0;
foreach($this->tax as $key => $value) {
if ($this->tax[$key]['value'] > 0) {
$output.= $this->tax[$key]['desc'] . ": " . $xtPrice->xtcFormat($this->tax[$key]['value'], true) . "<br />";
$val = $this->tax[$key]['value'];
}
}
if ($format) {
return $output;
} else {
return $val;
}
}
//------------------------------------------------------------------------------------------------------------------------------
function get_content_type()
{
$this->content_type = false;
$this->content_type = 'physical';
}
//------------------------------------------------------------------------------------------------------------------------------
function reset($reset_database = false, $tmp_store_id = '')
{
if ($tmp_store_id != '') {
$store_qry = $this->get_store_filter($tmp_store_id);
}
$this->contents = array();
$this->total = 0;
$this->weight = 0;
$this->content_type = false;
if (isset($_SESSION['customer_id']) && ($reset_database == true)) {
hhg_db_query("
DELETE
FROM
" . TABLE_MS_CUSTOMERS_BASKET . "
WHERE
customers_id = '" . $_SESSION['customer_id'] . "'
" . $store_qry . "
");
}
unset($this->cartID);
if (isset($_SESSION['cartID'])) unset($_SESSION['cartID']);
}
//------------------------------------------------------------------------------------------------------------------------------
function get_owner($tmp_store_id = STORE_ID)
{
if (USE_SINGLE_SESSIONS == 'false' && (USE_SINGLE_CHECKOUT == 'true' || USE_SINGLE_STORE_CHECKOUT == 'true')) {
if (USE_SINGLE_CHECKOUT == 'false' && USE_SINGLE_STORE_CHECKOUT == 'true') {
$column = 'store_id';
} elseif (USE_SINGLE_CHECKOUT == 'true' && USE_SINGLE_STORE_CHECKOUT == 'false') {
$column = 'products_owner';
}
// Warenkörbe zusammen
if (isset($_SESSION['customer_id'])) {
$owner_query = "
SELECT DISTINCT
" . $column . "
FROM
" . TABLE_MS_CUSTOMERS_BASKET . "
WHERE
customers_id = '" . $_SESSION['customer_id'] . "'
";
} else {
$sid = session_id();
$owner_query = "
SELECT DISTINCT
" . $column . "
FROM
" . TABLE_MS_CUSTOMERS_BASKET_TMP . "
WHERE
sid = '" . $sid . "'
";
}
$owner = hhg_db_query($owner_query);
while (!$owner->EOF) {
$store_name = hhg_get_store_name($owner->fields[$column]);
$owner_array[] = array(
'id' => $owner->fields[$column],
'text' => $store_name
);
$owner->MoveNext();
}
return $owner_array;
} else {
// Warenkörbe getrennt
$store_name = hhg_get_store_name($tmp_store_id);
$owner_array[] = array(
'id' => $tmp_store_id,
'text' => $store_name
);
return $owner_array;
}
}
//------------------------------------------------------------------------------------------------------------------------------
function get_store_filter($tmp_store_id = STORE_ID, $tmp_owner = null)
{
$store_qry = '';
$shopping_malls = explode(';', SHOPPING_MALLS);
if (in_array($tmp_store_id, $shopping_malls)) {
if (USE_SINGLE_SESSIONS == 'false') {
if (USE_SINGLE_CHECKOUT == 'true' && USE_SINGLE_STORE_CHECKOUT == 'false') {
if (!empty($tmp_owner)) {
$store_qry.= " AND products_owner = " . (int)$tmp_owner . " ";
} else {
$store_qry.= " AND products_owner = " . (int)$tmp_store_id . " ";
}
} elseif (USE_SINGLE_CHECKOUT == 'false' && USE_SINGLE_STORE_CHECKOUT == 'true') {
$store_qry.= " AND store_id = " . (int)$tmp_store_id . " ";
} elseif (USE_SINGLE_CHECKOUT == 'false' && USE_SINGLE_STORE_CHECKOUT == 'false') {
$store_qry.= " AND store_id IN (" . implode(',', $shopping_malls) . ") ";
}
} else {
if (USE_SINGLE_CHECKOUT == 'true' && USE_SINGLE_STORE_CHECKOUT == 'false') {
if (!empty($tmp_owner)) {
$store_qry.= " AND products_owner = " . (int)$tmp_owner . " ";
} else {
$store_qry.= " AND products_owner = " . (int)$_SESSION['actual_store'] . " ";
}
$store_qry.= " AND store_id = " . (int)$_SESSION['actual_store'] . " ";
} elseif (USE_SINGLE_CHECKOUT == 'false' && USE_SINGLE_STORE_CHECKOUT == 'true') {
$store_qry.= " AND store_id = " . (int)$_SESSION['actual_store'] . " ";
} else {
$store_qry.= '';
}
}
} else {
$store_qry = " AND store_id = '" . $tmp_store_id . "'";
}
return $store_qry;
}
//------------------------------------------------------------------------------------------------------------------------------
}
?>