/*****************************************************************************\ +-----------------------------------------------------------------------------+ | X-Cart | | Copyright (c) 2001-2010 Ruslan R. Fazlyev | | All rights reserved. | +-----------------------------------------------------------------------------+ | PLEASE READ THE FULL TEXT OF SOFTWARE LICENSE AGREEMENT IN THE "COPYRIGHT" | | FILE PROVIDED WITH THIS DISTRIBUTION. THE AGREEMENT TEXT IS ALSO AVAILABLE | | AT THE FOLLOWING URL: http://www.x-cart.com/license.php | | | | THIS AGREEMENT EXPRESSES THE TERMS AND CONDITIONS ON WHICH YOU MAY USE | | THIS SOFTWARE PROGRAM AND ASSOCIATED DOCUMENTATION THAT RUSLAN R. | | FAZLYEV (hereinafter referred to as "THE AUTHOR") IS FURNISHING OR MAKING | | AVAILABLE TO YOU WITH THIS AGREEMENT (COLLECTIVELY, THE "SOFTWARE"). | | PLEASE REVIEW THE TERMS AND CONDITIONS OF THIS LICENSE AGREEMENT | | CAREFULLY BEFORE INSTALLING OR USING THE SOFTWARE. BY INSTALLING, | | COPYING OR OTHERWISE USING THE SOFTWARE, YOU AND YOUR COMPANY | | (COLLECTIVELY, "YOU") ARE ACCEPTING AND AGREEING TO THE TERMS OF THIS | | LICENSE AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY THIS | | AGREEMENT, DO NOT INSTALL OR USE THE SOFTWARE. VARIOUS COPYRIGHTS AND | | OTHER INTELLECTUAL PROPERTY RIGHTS PROTECT THE SOFTWARE. THIS | | AGREEMENT IS A LICENSE AGREEMENT THAT GIVES YOU LIMITED RIGHTS TO USE | | THE SOFTWARE AND NOT AN AGREEMENT FOR SALE OR FOR TRANSFER OF TITLE.| | THE AUTHOR RETAINS ALL RIGHTS NOT EXPRESSLY GRANTED BY THIS AGREEMENT. | | | | The Initial Developer of the Original Code is Ruslan R. Fazlyev | | Portions created by Ruslan R. Fazlyev are Copyright (C) 2001-2010 | | Ruslan R. Fazlyev. All Rights Reserved. | +-----------------------------------------------------------------------------+ \*****************************************************************************/ # # $Id: cart.php,v 1.159.2.4 2010/01/21 09:20:26 ferz Exp $ # # This script implements shopping cart facility # require "./auth.php"; if (!empty($active_modules['Wishlist']) && ( in_array($mode, array('add2wl', 'wishlist')) || (!empty($login) && !empty($remember_data) && $mode!="checkout" && (in_array($mode, array('add2wl', 'wishlist')) || in_array($_remember_vars['mode'], array('add2wl', 'wishlist')))) ) ) { $_remember_varnames = array('mode', 'amount', 'cat', 'page', 'productid', 'wlitem', 'action', 'eventid', 'quantity', 'product_options'); require $xcart_dir."/include/remember_user.php"; } x_load('cart','user','order','tests'); require_once $xcart_dir."/include/cart_process.php"; include $xcart_dir."/shipping/shipping.php"; // Checkout One :: www.alteredcart.com // if ($active_modules['Checkout_One']){ // Recover Username and Password // if ($ajax_function == 'recover_password'){ if (function_exists('x_load')) x_load('crypt', 'mail'); if (defined('VERSION44')) $accounts = func_query_first("SELECT id, login, password, email, usertype FROM $sql_tbl[customers] WHERE (login='".mysql_real_escape_string($email)."' OR email='".mysql_real_escape_string($email)."') AND usertype='C' AND status='Y'"); else if(function_exists('func_ajax_convert')) // 4.2 - 4.3 // $accounts = func_query_first("SELECT login, password, usertype FROM $sql_tbl[customers] WHERE email='".mysql_real_escape_string($email)."' AND status='Y' ORDER BY last_login DESC"); else $accounts = func_query("SELECT login, password, usertype FROM $sql_tbl[customers] WHERE email='".mysql_real_escape_string($email)."' and status='Y' ORDER BY last_login DESC"); $xml = ''; if (!$accounts){ $xml .= 'true'; } else { if (defined('VERSION44')){ $account = $accounts; db_query("LOCK TABLES $sql_tbl[change_password] WRITE"); db_query("DELETE FROM $sql_tbl[change_password] WHERE userid='" . $account['id']); do { $account['password_reset_key'] = md5(uniqid(rand(),true)); } while (func_query_first_cell("SELECT COUNT(password_reset_key) FROM $sql_tbl[change_password] WHERE userid='$account[id]' AND password_reset_key='$account[password_reset_key]'")); func_array2insert('change_password', array('userid' => $account['id'], 'password_reset_key' => $account['password_reset_key'], 'password_reset_key_date' => XC_TIME), true); db_query("UNLOCK TABLES"); $mail_smarty->assign('account', $account); $mail_smarty->assign('userpath', DIR_CUSTOMER); } else if (function_exists('func_ajax_convert')){ $account = $accounts; db_query("LOCK TABLES $sql_tbl[change_password] WRITE"); db_query("DELETE FROM $sql_tbl[change_password] WHERE login='".addslashes($username)."'"); do { $account['password_reset_key'] = md5(uniqid(rand(), true)); } while (func_query_first_cell("SELECT COUNT(password_reset_key) FROM $sql_tbl[change_password] WHERE password_reset_key='".$account['password_reset_key']."'")); db_query("DELETE FROM $sql_tbl[change_password] WHERE login='".mysql_real_escape_string($account['login'])."'"); func_array2insert('change_password', array('login' => $account['login'], 'password_reset_key' => $account['password_reset_key'], 'password_reset_key_date' => time())); db_query("UNLOCK TABLES"); $mail_smarty->assign('account', $account); $mail_smarty->assign('userpath', DIR_CUSTOMER); } else { // Decrypt Passwords & filter anonomous orders // foreach($accounts as $k => $v){ if (stristr($v['login'], $anonymous_username_prefix)){ unset($accounts[$k]); continue; } $accounts[$k]['password'] = text_decrypt($accounts[$k]['password']); } } if ($accounts || $account){ $mail_smarty->assign('accounts',$accounts); func_send_mail($email, 'mail/password_recover_subj.tpl', 'mail/password_recover.tpl', $config['Company']['support_department'], false); $xml .= 'true'; } else { $xml .= 'true'; } } $xml .= ''; echo $xml; func_flush(); exit; } require $xcart_dir."/modules/Checkout_One/checkout_one_ajax.php"; } // End Checkout One // x_session_register("cart"); x_session_register("intershipper_rates"); x_session_register("intershipper_recalc"); x_session_unregister("secure_oid"); x_session_register("payment_cc_fields"); x_session_register("current_carrier","UPS"); x_session_register("order_secureid"); x_session_register("is_sns_action"); x_session_register("cart_locked"); x_session_register("dhl_ext_country_store"); x_session_register("ga_track_commerce"); x_session_register("initial_state_orders", array()); x_session_register("initial_state_show_notif", "Y"); x_session_register("enter_as_anonymous", false); x_session_register("enter2cart_as_anonymous", false); if (isset($dhl_ext_country)) { $dhl_ext_country_store = $dhl_ext_country; } else { $dhl_ext_country = $dhl_ext_country_store; } if ($cart_locked && !($mode == 'add2wl' || $mode == "wishlist")) { # User cannot operate with cart while processing order on Google Checkout $_ref = func_query_first_cell("SELECT ref FROM $sql_tbl[cc_pp3_data] WHERE sessionid='$XCARTSESSID' LIMIT 1"); $msg = "Customer returned to the store before Google checkout completed processing the payment transaction. ReferenceID: '$_ref'; sessionid: '$XCARTSESSID'. Transaction declined by the store."; x_log_flag('log_payment_processing_errors', 'PAYMENTS', $msg, true); if (!empty($active_modules['Google_Checkout'])) func_gcheckout_debug("\t+ [Error] " . $msg); db_query("DELETE FROM $sql_tbl[cc_pp3_data] WHERE sessionid='$XCARTSESSID'"); $cart_locked = false; } $intershipper_recalc = "Y"; # # Check if the cart is empty # $func_is_cart_empty = func_is_cart_empty($cart); if ($enter2cart_as_anonymous !== empty($login) && !empty($active_modules["UPS_OnLine_Tools"]) && $REQUEST_METHOD == 'GET' && $current_carrier != 'UPS') { $current_carrier = "UPS"; } $enter2cart_as_anonymous = empty($login); # # Stop list module: check transaction # if (!empty($active_modules["Stop_List"]) && !func_is_allowed_trans() && !$func_is_cart_empty) { if($mode == "checkout" || $mode == "auth") { $top_message["content"] = func_get_langvar_by_name("txt_stop_list_customer_note"); $top_message["type"] = "E"; func_header_location("cart.php"); } $smarty->assign("unallowed_transaction", "Y"); } # # Normalize cart content # if (!$func_is_cart_empty && !in_array($mode, array("wishlist","wl2cart"))) { $cart_changed = func_cart_normalize($cart); } # # Check available payment methods # $payment_methods = array(); if (!$func_is_cart_empty) { $payment_methods = check_payment_methods(@$user_account["membershipid"]); if (empty($payment_methods)) $smarty->assign("std_checkout_disabled", "Y"); $paypal_express_enabled = func_query_first_cell("SELECT $sql_tbl[payment_methods].paymentid FROM $sql_tbl[ccprocessors], $sql_tbl[payment_methods] WHERE $sql_tbl[ccprocessors].processor='ps_paypal_pro.php' AND $sql_tbl[ccprocessors].paymentid=$sql_tbl[payment_methods].paymentid AND $sql_tbl[payment_methods].active='Y'"); } if (($mode == "checkout" || $mode == "auth") && !$func_is_cart_empty) { # # Calculate total number of checkout process steps # if (empty($login) && !$enter_as_anonymous) $enter_as_anonymous = true; $total_checkout_steps = 2; $checkout_step_modifier["anonymous"] = 0; $checkout_step_modifier["payment_methods"] = 0; if ($config["General"]["disable_anonymous_checkout"] != "Y" && (empty($login) || func_is_anonymous($login))) { $total_checkout_steps++; $checkout_step_modifier["anonymous"] = 1; } elseif ($enter_as_anonymous) { $total_checkout_steps++; $checkout_step_modifier["anonymous"] = 1; } if (empty($payment_methods)) { if (!$paypal_express_enabled && empty($active_modules["Google_Checkout"])) { $top_message['content'] = func_get_langvar_by_name("txt_no_payment_methods"); $top_message['type'] = 'E'; } func_header_location("cart.php"); } elseif (count($payment_methods) == 1) { $total_checkout_steps--; $checkout_step_modifier["payment_methods"] = 1; } } if ($mode == "clear_cart") { # # Clear entire cart # $changes = array(); if (!empty($cart["products"])) { foreach($cart["products"] as $p) { $changes[$p['cartid']] = array( 'productid' => $p['productid'], 'quantity' => $p['amount'], 'change' => $p['amount'] * -1 ); } } if (!empty($cart["giftcerts"])) { foreach($cart["products"] as $gid => $g) { $changes[$gid] = array( 'gcindex' => $gid, 'quantity' => 1, 'change' => -1 ); } } if (!empty($active_modules["SnS_connector"]) && !empty($cart["products"])) { foreach ($cart["products"] as $p) { $is_sns_action['DeleteFromCart'][] = $p['productid']; } } $cart = ""; func_register_ajax_message( 'cartChanged', array( 'changes' => $changes, 'isEmpty' => true, 'status' => 1 ) ); func_header_location("cart.php"); } # Disable displaying of a notification about uncompleted orders. if ($mode == 'disable_init_state_notif') { $initial_state_show_notif = ''; func_header_location(func_is_internal_url($HTTP_REFERER) ? $HTTP_REFERER : 'home.php'); } if (!empty($active_modules['Gift_Certificates']) && $mode == "unset_gc" && $gcid) { # # Unset Gift Certificate # func_giftcert_unset($gcid); func_header_location("cart.php?mode=checkout".($paymentid ? "&paymentid=".$paymentid : "")); } # Update Gift wrapping if (!empty($active_modules["Gift_Registry"])) { include $xcart_dir."/modules/Gift_Registry/giftreg_customer_cart.php"; } $smarty->assign("register_script_name",(($config["Security"]["use_https_login"] == "Y") ? $xcart_catalogs_secure["customer"]."/" : "")."cart.php"); # # Register member if not registerred yet # (not a newbie - do not show help messages) # if ($mode == "checkout" && !$func_is_cart_empty) { $usertype = "C"; $old_action = $action; $action = "cart"; $smarty->assign("action", $action); $newbie = "Y"; if (empty($login)) include $xcart_dir."/include/register.php"; if (!empty($auto_login)) { func_header_location("cart.php?mode=checkout®istered="); } $saved_userinfo = isset($userinfo) ? $userinfo : array(); $action = $old_action; $smarty->assign("newbie", $newbie); } if (!empty($login)) { $userinfo = func_userinfo($login, $current_area, false, false, "H"); # # Check required fields # if ($mode == "checkout" && $userinfo['status'] != "A") { $fillerr = func_check_required_fields($userinfo); if ($fillerr) { $top_message["type"] = "E"; $top_message["reg_error"] = "F"; func_header_location("register.php?mode=update&action=cart&paymentid=".$paymentid); } } } $return_url = ""; if ($mode == "add" && !empty($productid)) { # # Add product to the cart # $add_product = array(); $add_product["productid"] = abs(intval($productid)); $add_product["amount"] = abs(intval($amount)); $add_product["product_options"] = isset($product_options) ? $product_options : array(); $add_product["price"] = abs(doubleval(isset($price) ? $price : 0)); if ($active_modules["Special_Offers"]) { include $xcart_dir."/modules/Special_Offers/add_to_cart.php"; } # # Add to cart # $result = func_add_to_cart($cart, $add_product); if ($_GET["redirect_to_referer"] !== "Y" && !empty($result["redirect_to"])) func_header_location($result["redirect_to"]); $intershipper_recalc = "Y"; # Recalculate cart totals after new item added $products = func_products_in_cart($cart, (!empty($user_account["membershipid"]) ? $user_account["membershipid"] : "")); $cart = func_array_merge($cart, func_calculate($cart, $products, $login, $current_area, 0)); if ($active_modules["Special_Offers"]) { include $xcart_dir."/modules/Special_Offers/add_free_products.php"; } if ($_GET["redirect_to_referer"] === "Y") func_header_location($HTTP_REFERER . "&redirect_from_cart=Y"); $func_is_cart_empty = func_is_cart_empty($cart); func_register_ajax_message( 'cartChanged', array( 'changes' => array( $result['productindex'] => array( 'productid' => $add_product["productid"], 'quantity' => $result['quantity'], 'changed' => $result['changed'] ) ), 'isEmpty' => empty($cart['products']) && empty($cart['giftcerts']), 'status' => $result['status'] ) ); # # Redirect # if ($config["General"]["redirect_to_cart"] == "Y") { if (!empty($active_modules["SnS_connector"])) $is_sns_action['AddToCart'][] = $productid; $return_url = 'cart.php'; } else { $products = func_products_in_cart($cart, (!empty($user_account["membershipid"]) ? $user_account["membershipid"] : "")); $cart = func_array_merge($cart, func_calculate($cart, $products, $login, $current_area, 0)); if (!empty($active_modules["SnS_connector"])) func_generate_sns_action("AddToCart", $productid); func_save_customer_cart($login, $cart); if (func_is_internal_url($HTTP_REFERER)) { $tmp = @parse_url($HTTP_REFERER); $return_url = $HTTP_REFERER; if ($config["General"]["return_to_dynamic_part"] == "Y" && $is_hc == "Y" && is_array($tmp) && (strpos($tmp["path"], ".html") !== false || substr($tmp["path"], -1) == "/")) { if (substr($tmp["path"], -1) == "/") { $return_url = 'home.php'; } elseif (strpos($HTTP_REFERER, "-c-") !== false) { $return_url = func_get_resource_url('category', $cat, 'page=' . $page); } else { $return_url = func_get_resource_url('product', $add_product["productid"]); } } } else { $return_url = func_get_resource_url('category', $cat, 'page='. $page); } } } elseif ($mode == "delete" && !empty($productindex)) { # # Delete product from the cart # $productid = 0; $quantity = 0; if (!empty($cart['products']) && is_array($cart['products'])) { list($productid, $quantity) = func_delete_from_cart($cart, $productindex); } if ($productid > 0) { if (!empty($active_modules["SnS_connector"])) $is_sns_action['DeleteFromCart'][] = $productid; $intershipper_recalc = "Y"; # Recalculate cart totals after updating $products = func_products_in_cart($cart, (!empty($user_account["membershipid"]) ? $user_account["membershipid"] : "")); $cart = func_array_merge($cart, func_calculate($cart, $products, $login, $current_area, 0)); } func_register_ajax_message( 'cartChanged', array( 'changes' => array( $productindex => array( 'productid' => $productid, 'quantity' => $quantity, 'changed' => $quantity * -1 ) ), 'isEmpty' => empty($cart['products']) && empty($cart['giftcerts']), 'status' => $productid > 0 ? 1 : 2 ) ); $func_is_cart_empty = func_is_cart_empty($cart); $return_url = 'cart.php'; } if (empty($action)) $action = ""; $changes = false; if ($action != "update" && !$func_is_cart_empty && $mode == "checkout") { # # Check for the min order amount # $productindexes = array(); if (!empty($cart["products"])) foreach ($cart["products"] as $p) $productindexes[$p["cartid"]] = $p["amount"]; if (!empty($productindexes)) { # Update the quantity of products in cart list($min_amount_warns, $changes) = func_update_quantity_in_cart($cart, $productindexes); $top_message = func_generate_min_amount_warning($min_amount_warns, $productindexes, $cart["products"]); if (!empty($top_message)) $return_url = "cart.php"; } # # Update the cart # } elseif ($action == "update" && !$func_is_cart_empty) { # Update Gift registry links, if any if (!empty($active_modules["Gift_Registry"])) { include $xcart_dir."/modules/Gift_Registry/giftreg_customer_cart.php"; } if (!empty($productindexes)) { # Update the quantity of products in cart list($min_amount_warns, $changes) = func_update_quantity_in_cart($cart, $productindexes); $top_message = func_generate_min_amount_warning($min_amount_warns, $productindexes, $cart["products"]); if (!empty($active_modules["SnS_connector"])) $is_sns_action['CartChanged'][] = false; $intershipper_recalc = "Y"; } # # Update shipping method # if ($config["Shipping"]["realtime_shipping"] == "Y" && !empty($active_modules["UPS_OnLine_Tools"]) && $config["Shipping"]["use_intershipper"] != "Y") $current_carrier = $selected_carrier; if (!empty($shippingid)) $cart["shippingid"] = $shippingid; if (!empty($mode)) $url_args[] = "mode=".$mode; if (!empty($paymentid)) $url_args[] = "paymentid=".$paymentid; $return_url = "cart.php".(!empty($url_args) ? "?".implode("&", $url_args) : ""); func_register_ajax_message( 'cartChanged', array( 'changes' => is_array($changes) ? $changes : array(), 'isEmpty' => empty($cart['products']) && empty($cart['giftcerts']), 'status' => 1 ) ); $func_is_cart_empty = func_is_cart_empty($cart); } if (!$func_is_cart_empty) { # # Prepare cart for calculation # $products = func_products_in_cart($cart, (!empty($userinfo["membershipid"]) ? $userinfo["membershipid"] : "")); if (!empty($cart["products"]) && is_array($products) && count($products) != count($cart["products"])) { # # The products array in the cart isn't accords to the store # foreach ($products as $k=>$v) $prodids[] = $v["cartid"]; if (is_array($prodids)) { foreach ($cart["products"] as $k=>$v) { if (in_array($v["cartid"], $prodids)) $cart_prods[$k] = $v; } $cart["products"] = $cart_prods; } else { $cart = ""; } func_header_location("cart.php?$QUERY_STRING"); } if (!empty($active_modules["Subscriptions"])) { $in_cart = true; include $xcart_dir."/modules/Subscriptions/subscription.php"; } if (empty($login) && $config["General"]["apply_default_country"] == "Y") { # Use the default address $userinfo["b_country"] = $userinfo["s_country"] = $config["General"]["default_country"]; $userinfo["b_state"] = $userinfo["s_state"] = $config["General"]["default_state"]; $userinfo["b_zipcode"] = $userinfo["s_zipcode"] = $config["General"]["default_zipcode"]; $userinfo["b_city"] = $userinfo["s_city"] = $config["General"]["default_city"]; $userinfo["b_countryname"] = $userinfo["s_countryname"] = func_get_country($userinfo["s_country"]); $userinfo["b_statename"] = $userinfo["s_statename"] = func_get_state($userinfo["s_state"], $userinfo["s_country"]); } # # Check if shipping cost is need to be calculated # $need_shipping = false; if ($config["Shipping"]["enable_shipping"] == "Y" && is_array($products) && ((!empty($userinfo) || $config["General"]["apply_default_country"] == 'Y') || $config["Shipping"]["enable_all_shippings"] == "Y")) { foreach ($products as $pKey => $product) { if (!empty($active_modules["Special_Offers"])) { $products[$pKey]["free_shipping_used"] = $product["free_shipping_used"] = false; } if (!empty($active_modules["Egoods"]) && !empty($product["distribution"])) continue; if (($product["free_shipping"] == "Y" || $product["free_shipping_used"]) && $config["Shipping"]["do_not_require_shipping"] == "Y") continue; # Check if all products in the cart have shipping freight if ($config["Shipping"]["replace_shipping_with_freight"] == "Y" && $product["shipping_freight"] > 0) continue; $need_shipping = true; break; } } # # Discount coupons # if ($active_modules["Discount_Coupons"]) { include $xcart_dir."/modules/Discount_Coupons/discount_coupons.php"; $cart = func_array_merge($cart, func_calculate($cart, $products, $login, $current_area, (!empty($paymentid) ? intval($paymentid) : 0))); if ($cart["coupon_type"] == "free_ship" && $config["Shipping"]["do_not_require_shipping"] == "Y" && $need_shipping) { $need_shipping = false; } } if ($need_shipping) { # Get the allowed shipping methods list $_current_carrier = $current_carrier; $shipping = func_get_shipping_methods_list($cart, $products, $userinfo); if (empty($shipping)) { if ($_current_carrier == 'UPS' && $empty_other_carriers != 'Y') { $current_carrier = ''; $intershipper_recalc = 'Y'; $shipping = func_get_shipping_methods_list($cart, $products, $userinfo); } elseif ($_current_carrier == '' && $empty_ups_carrier != 'Y' && !empty($active_modules["UPS_OnLine_Tools"])) { $current_carrier = 'UPS'; $intershipper_recalc = 'Y'; $shipping = func_get_shipping_methods_list($cart, $products, $userinfo); } } # If current shipping is empty set it to default (first in shipping array) $shipping_matched = false; if (!empty($shipping) && is_array($shipping)) { foreach ($shipping as $shipping_method) { if (@$cart["shippingid"] == $shipping_method["shippingid"]) $shipping_matched = true; } } if (!$shipping_matched && !empty($shipping)) $cart["shippingid"] = $shipping[0]["shippingid"]; if (!empty($shipping)) { foreach ($shipping as $shipping_method) { if (@$cart["shippingid"] == $shipping_method["shippingid"]) $cart['shipping_warning'] = @$shipping_method['warning']; } } $cart["delivery"] = func_query_first_cell("SELECT shipping FROM $sql_tbl[shipping] WHERE shippingid='$cart[shippingid]'"); // Checkout One :: www.alteredcart.com // if ($active_modules['Checkout_One']) include $xcart_dir."/modules/Checkout_One/checkout_one_shipping.php"; // End Checkout One // $smarty->assign("current_carrier", $current_carrier); } else { $shipping = ""; $cart["delivery"] = ""; $cart["shippingid"] = 0; } if ($active_modules["Special_Offers"]) { include $xcart_dir."/modules/Special_Offers/apply_free_offers.php"; } # # Discount coupons # if ($active_modules["Discount_Coupons"]) include $xcart_dir."/modules/Discount_Coupons/discount_coupons.php"; # # Calculate all prices # $cart = func_array_merge($cart, func_calculate($cart, $products, $login, $current_area, (!empty($paymentid) ? intval($paymentid) : 0))); if (func_is_cart_empty($cart)) { if (!empty($active_modules["SnS_connector"])) func_sns_exec_actions($is_sns_action); $cart = ""; $top_message = array( 'content' => func_get_langvar_by_name("err_product_in_cart_expired_msg"), 'type' => 'E' ); func_header_location($xcart_catalogs['customer']."/cart.php"); } else { $products = func_products_in_cart($cart, (!empty($userinfo["membershipid"])?$userinfo["membershipid"]:0)); } # # For special offers that give free shipping to specified membership. # if (!empty($products) && !empty($need_shipping) && !empty($cart["have_offers"])) { $need_shipping = false; foreach ($products as $product) { if (($product["free_shipping"] == "Y" || $product["free_shipping_used"]) && $config["Shipping"]["do_not_require_shipping"] == "Y") continue; $need_shipping = true; break; } if (empty($need_shipping)) { $cart["delivery"] = ""; $cart["shippingid"] = 0; $shipping = ""; } } # # Check if the Gift wrapping section is needed # if (!empty($products) && !empty($active_modules["Gift_Registry"]) && $config["Gift_Registry"]["enable_gift_wrapping"] == "Y") { $egoods_count = 0; if (!empty($active_modules["Egoods"])) { foreach ($products as $product) { if (!empty($product["distribution"])) $egoods_count++; } } if (count($products) > $egoods_count) { $smarty->assign("display_giftwrap_section", true); } else { $cart["need_giftwrap"] = false; } } $smarty->assign("shipping", $shipping); $smarty->assign("need_shipping", $need_shipping); $smarty->assign("cart",$cart); } if (!empty($active_modules["SnS_connector"])) func_sns_exec_actions($is_sns_action); if ($return_url) func_header_location($return_url); $smarty->assign("main","cart"); # # Wishlist facility # if (!empty($active_modules["Wishlist"]) && $mode != "checkout") { if ($mode == 'move_product' && !empty($active_modules["Gift_Registry"])) include $xcart_dir."/modules/Gift_Registry/giftreg_wishlist.php"; @include $xcart_dir."/modules/Wishlist/wishlist.php"; } if ($mode != "wishlist" || empty($active_modules['Wishlist'])) { if ($mode == "checkout") $location[] = array(func_get_langvar_by_name("lbl_checkout"), ""); else $location[] = array(func_get_langvar_by_name("lbl_your_shopping_cart"), ""); } # # SHOPPING CART FEATURE # if ($mode == "checkout" && !empty($cart["products"]) && empty($shipping) && !empty($login) && $need_shipping && $config["Shipping"]["enable_shipping"] == "Y") { # # ERROR: No shipping methods selected # if (empty($active_modules["Fast_Lane_Checkout"])) func_header_location("error_message.php?error_no_shipping"); } if (($mode == "checkout" || $mode == "gcheckout") && !$func_is_cart_empty && $cart["display_subtotal"] < $config["General"]["minimal_order_amount"] && $config["General"]["minimal_order_amount"] > 0) { # # ERROR: Cart total must exceeds the minimum order total amount (defined in General settings) # func_header_location("error_message.php?error_min_order"); } if (($mode == "checkout" || $mode == "gcheckout") && !$func_is_cart_empty && $config["General"]["maximum_order_amount"] > 0 && $cart["display_subtotal"] > $config["General"]["maximum_order_amount"]) { # # ERROR: Cart total must not exceeds the maximum order total amount (defined in General settings) # func_header_location("error_message.php?error_max_order"); } if (($mode == "checkout" || $mode == "gcheckout") && !$func_is_cart_empty && $config["General"]["maximum_order_items"] > 0 && func_cart_count_items($cart) > $config["General"]["maximum_order_items"]) { # # ERROR: Cart total must not exceeds the maximum total quantity of products in an order (defined in General settings) # func_header_location("error_message.php?error_max_items"); } if ($mode == "gcheckout" && !empty($active_modules['Google_Checkout'])) { # # Start Google Checkout # define('CHECKOUT_STARTED', 1); include $xcart_dir. "/modules/Google_Checkout/gcheckout.php"; } $paypal_expressid = ""; if ($mode == "checkout" && empty($login) && !$func_is_cart_empty) { # # Start the anonymous checkout # $smarty->assign("main","anonymous_checkout"); $smarty->assign("anonymous","Y"); if (empty($userinfo) && !empty($saved_userinfo)) { $userinfo = $saved_userinfo; } $checkout_step = 1; $anonymous_checkout = true; $location[] = array(func_get_langvar_by_name("lbl_your_order"), ""); } elseif ($mode == "checkout" && empty($paymentid) && !$func_is_cart_empty && $cart["total_cost"] == 0) { # # Skip payment routine if cart total is 0 # x_session_unregister('paypal_begin_express'); func_header_location($current_location."/payment/payment_offline.php"); } elseif ($mode == "checkout" && !empty($paymentid) && !$func_is_cart_empty) { if (empty($_GET["paymentid"]) || empty($_GET["mode"])) { func_header_location("cart.php?mode=checkout&paymentid=$paymentid"); } # # Prepare the last step of checkout # # Check if paymentid isn't fake $is_egoods = ($config["Egoods"]["egoods_manual_cc_processing"] == "Y" ? func_esd_in_cart($cart) : false); $membershipid = $user_account["membershipid"]; $paypal_pro_condition = ""; $is_valid_paymentid = func_query_first_cell("SELECT COUNT(*) FROM $sql_tbl[payment_methods] LEFT JOIN $sql_tbl[pmethod_memberships] ON $sql_tbl[pmethod_memberships].paymentid = $sql_tbl[payment_methods].paymentid WHERE $sql_tbl[payment_methods].paymentid='$paymentid'".(($is_egoods && $paymentid == 1) ? "" : " AND $sql_tbl[payment_methods].active='Y'")." AND ($sql_tbl[pmethod_memberships].membershipid IS NULL OR $sql_tbl[pmethod_memberships].membershipid = '$membershipid') ".$paypal_pro_condition); if (!$is_valid_paymentid) { func_header_location("cart.php?mode=checkout&err=paymentid"); } $paypal_expressid = func_query_first_cell("SELECT $sql_tbl[payment_methods].paymentid FROM $sql_tbl[payment_methods], $sql_tbl[ccprocessors] WHERE $sql_tbl[payment_methods].processor_file='ps_paypal_pro.php' AND $sql_tbl[payment_methods].processor_file=$sql_tbl[ccprocessors].processor AND $sql_tbl[payment_methods].paymentid=$sql_tbl[ccprocessors].paymentid AND $sql_tbl[payment_methods].active='Y'"); if (!empty($paypal_expressid) && $paypal_expressid == $paymentid) { if (!empty($active_modules['Fast_Lane_Checkout']) && empty($shipping) && $need_shipping && $config["Shipping"]["enable_shipping"] == "Y") { $top_message["content"] = func_get_langvar_by_name("msg_flc_select_shipping_err"); $top_message["type"] = "E"; func_header_location("cart.php?mode=checkout"); } x_session_register('paypal_begin_express'); x_session_register('paypal_token'); x_session_register("paypal_express_details"); if (($paypal_begin_express !== false && (empty($paypal_token) && empty($paypal_express_details))) || (!empty($paypal_token) && (empty($paypal_express_details) || ($paypal_token != $paypal_express_details['Token'] && $paypal_token != $paypal_express_details['token'])))) { $paypal_begin_express = true; func_header_location($current_location.'/payment/ps_paypal_pro.php?payment_id='.$paymentid.'&mode=express'); } } # Generate uniq orderid which will identify order session $order_secureid = md5(uniqid(rand())); # Show payment details checkout page $payment_cc_data = func_query_first("SELECT * FROM $sql_tbl[ccprocessors] WHERE paymentid='$paymentid'"); if ($is_egoods && $paymentid != 1 && !empty($payment_cc_data)) { $paymentid = 1; $payment_cc_data = array(); } # Generate payment script URL depending on HTTP/HTTPS settings if (empty($cart['shippingid'])) { $payment_data = func_query_first("SELECT $sql_tbl[payment_methods].*, $sql_tbl[payment_methods].payment_method as payment_method_orig, IFNULL(l1.value, $sql_tbl[payment_methods].payment_method) as payment_method, IFNULL(l2.value, $sql_tbl[payment_methods].payment_details) as payment_details FROM $sql_tbl[payment_methods] LEFT JOIN $sql_tbl[languages_alt] as l1 ON l1.name = CONCAT('payment_method_', $sql_tbl[payment_methods].paymentid) AND l1.code = '$shop_language' LEFT JOIN $sql_tbl[languages_alt] as l2 ON l2.name = CONCAT('payment_details_', $sql_tbl[payment_methods].paymentid) AND l2.code = '$shop_language' WHERE $sql_tbl[payment_methods].paymentid='$paymentid'"); } else { $payment_data = func_query_first("SELECT $sql_tbl[payment_methods].*, $sql_tbl[payment_methods].payment_method as payment_method_orig, IFNULL(l1.value, $sql_tbl[payment_methods].payment_method) as payment_method, IFNULL(l2.value, $sql_tbl[payment_methods].payment_details) as payment_details FROM $sql_tbl[payment_methods] LEFT JOIN $sql_tbl[languages_alt] as l1 ON l1.name = CONCAT('payment_method_', $sql_tbl[payment_methods].paymentid) AND l1.code = '$shop_language' LEFT JOIN $sql_tbl[languages_alt] as l2 ON l2.name = CONCAT('payment_details_', $sql_tbl[payment_methods].paymentid) AND l2.code = '$shop_language' LEFT JOIN $sql_tbl[shipping] ON $sql_tbl[shipping].shippingid = '$cart[shippingid]' WHERE $sql_tbl[payment_methods].paymentid='$paymentid' AND ($sql_tbl[payment_methods].is_cod != 'Y' || $sql_tbl[shipping].is_cod = 'Y')"); } if (empty($payment_data)) { func_header_location("cart.php?mode=checkout"); } $cart["paymentid"] = $paymentid; $payment_data["payment_script_url"] = (($payment_data["protocol"] == "https" || $HTTPS) ? $https_location : $http_location)."/payment/".$payment_data["payment_script"]; if (!empty($payment_cc_fields)) { $userinfo = func_array_merge($userinfo, $payment_cc_fields); } if ($checkout_step_modifier["payment_methods"] == 1) $smarty->assign("ignore_payment_method_selection", 1); $checkout_step = 2 + $checkout_step_modifier["anonymous"] - $checkout_step_modifier["payment_methods"]; if ($payment_data["processor_file"] == "ps_paypal_pro.php") { $payment_cc_data = func_query_first("SELECT * FROM $sql_tbl[ccprocessors] WHERE processor='ps_paypal_pro.php'"); $is_emulated_paypal = false; if ($active_modules['XPayments_Connector']) { func_xpay_func_load(); $is_emulated_paypal = xpc_is_emulated_paypal($paymentid); if ($is_emulated_paypal) { $payment_cc_data = xpc_get_module_params($paymentid); $payment_data['payment_template'] = false; } } } if (!empty($active_modules['Google_Analytics']) && $config['Google_Analytics']['ganalytics_e_commerce_analysis'] == 'Y') { $ga_track_commerce = "Y"; } #Check if only one shipping method is available and hide link on the checkout page if (!empty($active_modules["Fast_Lane_Checkout"]) && (count($shipping) > 1 || (count($shipping) == 1 && ($_carriers["UPS"] + $_carriers["other"]) > 1))) $smarty->assign("change_shipping_link","Y"); $payment_data['module_params'] = func_query_first("SELECT * FROM $sql_tbl[ccprocessors] WHERE paymentid = '$payment_data[paymentid]'"); $smarty->assign("payment_cc_data", $payment_cc_data); $smarty->assign("payment_data",$payment_data); $smarty->assign("userinfo",$userinfo); $smarty->assign("main","checkout"); $location[] = array(func_get_langvar_by_name("lbl_payment_details"), ""); } elseif ($mode == "checkout" && !$func_is_cart_empty) { # # Prepare the page for payment method selection # $force_change_shipping = (!empty($active_modules["Fast_Lane_Checkout"]) && (count($shipping) > 1 || (count($shipping) == 1 && ($_carriers["UPS"] + $_carriers["other"]) > 1) || ($need_shipping && empty($shipping)))); if (count($payment_methods) == 1 && !$force_change_shipping) { # Skip payment method selection if only one method is available func_header_location("cart.php?paymentid=".$payment_methods[0]["paymentid"]."&mode=checkout"); } if (!empty($payment_methods)) $payment_methods[0]["is_default"] = 1; $checkout_step = 1 + $checkout_step_modifier["anonymous"] - $checkout_step_modifier["payment_methods"]; $smarty->assign("payment_methods",$payment_methods); $smarty->assign("main","checkout"); $location[] = array(func_get_langvar_by_name("lbl_payment_details"), ""); } elseif ($mode == "order_message") { # # Display the invoice page (order confirmation page) # $orders = array (); if (!empty($orderids)) { if (empty($login)) func_403(32); $_orderids = explode(",", $orderids); foreach ($_orderids as $orderid) { $order_data = func_order_data($orderid); # Security check if current customer is not order's owner if (empty($order_data) || $order_data["order"]["login"] != $login) { unset($order_data); continue; } else { $order_data["products"] = func_translate_products($order_data["products"], $shop_language); } $orders[] = $order_data; } } if (empty($orders)) func_403(59); if (!empty($active_modules['Google_Analytics']) && $config['Google_Analytics']['ganalytics_e_commerce_analysis'] == "Y") { foreach ($orders as $key => $order) { foreach ($order['products'] as $p_key => $product) { $orders[$key]['products'][$p_key]['category'] = func_query_first_cell("SELECT $sql_tbl[categories].category FROM $sql_tbl[categories],$sql_tbl[products_categories] WHERE $sql_tbl[categories].categoryid = $sql_tbl[products_categories].categoryid AND $sql_tbl[products_categories].productid='".$product['productid']."' AND $sql_tbl[products_categories].main='Y'"); } } } $smarty->assign("orders", $orders); $smarty->assign("ga_track_commerce", $ga_track_commerce); $ga_track_commerce = "N"; if ($action == "print") { $smarty->assign("template", "customer/main/order_message.tpl"); func_display("customer/preview.tpl",$smarty); exit; } $smarty->assign("orderids", $orderids); $smarty->assign("main","order_message"); $location[] = array(func_get_langvar_by_name("lbl_order_processed"), ""); } elseif ($mode == "auth" && !$func_is_cart_empty) { # # Display the authentication page # $smarty->assign("main","checkout"); $checkout_step = 1; } require $xcart_dir."/include/categories.php"; if ($active_modules["Manufacturers"]) include $xcart_dir."/modules/Manufacturers/customer_manufacturers.php"; $giftcerts = (!empty($cart["giftcerts"]) ? $cart["giftcerts"] : array()); # # Update minicart # include "./minicart.php"; if (!empty($payment_cc_fields)) { $userinfo = func_array_merge($userinfo, $payment_cc_fields); } if (!empty($login) || $mode != "checkout") { $smarty->assign("userinfo", @$userinfo); } $smarty->assign("products", @$products); $smarty->assign("giftcerts", $giftcerts); $smarty->assign("list_length", count(@$products) + count($giftcerts)); $smarty->assign("products_length", count(@$products)); if ($mode == "checkout" || $mode == "auth") { $smarty->assign("checkout_step", $checkout_step); $smarty->assign("total_checkout_steps", $total_checkout_steps); } func_save_customer_cart($login, $cart); $allow_cod = func_query_first_cell("SELECT COUNT(*) FROM $sql_tbl[payment_methods] WHERE active = 'Y' AND is_cod = 'Y'") > 0; $smarty->assign("allow_cod", $allow_cod); $display_cod = func_query_first_cell("SELECT COUNT(*) FROM $sql_tbl[shipping] WHERE active = 'Y' AND is_cod = 'Y' AND shippingid = '$cart[shippingid]'") > 0; $smarty->assign("display_cod", $display_cod); # # Detect PayPal Pro status # if (test_active_bouncer() && ($config['General']['disable_anonymous_checkout'] != 'Y' || !empty($login)) && $paypal_expressid == $paymentid) { $paypal_express_active = func_query_first_cell("SELECT $sql_tbl[payment_methods].paymentid FROM $sql_tbl[ccprocessors], $sql_tbl[payment_methods] WHERE $sql_tbl[ccprocessors].processor='ps_paypal_pro.php' AND $sql_tbl[ccprocessors].paymentid=$sql_tbl[payment_methods].paymentid AND $sql_tbl[payment_methods].active='Y' ORDER BY $sql_tbl[payment_methods].protocol DESC LIMIT 1"); $smarty->assign("paypal_express_active", $paypal_express_active); x_session_unregister('paypal_begin_express'); if (!empty($paypal_express_active) && $config['paypal_solution'] == 'uk') $smarty->assign("force_uk_ccinfo", true); } if (is_array($initial_state_orders) && !empty($initial_state_orders)) { $oids = array(); foreach ($initial_state_orders as $k => $v) { if (func_query_first_cell("SELECT status FROM $sql_tbl[orders] WHERE orderid = '" . (int)$v . "'") == 'I') { $oids[] = $v; } else { unset($initial_state_orders[$k]); } } if (!empty($oids) && empty($top_message) && !$smarty->get_template_vars("top_message") && $initial_state_show_notif == 'Y') { $lng_var = count($oids) > 1 ? "txt_warn_unfinished_orders" : "txt_warn_unfinished_order"; $message = array( 'content' => func_get_langvar_by_name($lng_var, array("orders" => join(", ", $oids), "customer_area_url" => $xcart_catalogs['customer']), false, true), 'type' => 'W' ); $smarty->assign("top_message", $message); } } x_session_save(); $smarty->assign("dhl_ext_country", $dhl_ext_country); if (isset($dhl_ext_countries)) $smarty->assign("dhl_ext_countries", $dhl_ext_countries); $smarty->assign("partner", $partner); if (!empty($active_modules["Google_Checkout"])) func_gcheckout_check_enable($smarty); // Checkout One :: www.alteredcart.com // if ($active_modules['Checkout_One']) require $xcart_dir."/modules/Checkout_One/checkout_one_cart.php"; // End Checkout One // if (!empty($active_modules["Fast_Lane_Checkout"])) include $xcart_dir."/modules/Fast_Lane_Checkout/cart.php"; # Assign the current location line $smarty->assign("location", $location); func_display("customer/home.tpl", $smarty); ?>