Files
bobsleighphotos.com/production/includes/boxes/shoppingCart.inc.php
2017-03-02 20:30:40 -06:00

202 lines
7.8 KiB
PHP

<?php
/*
+--------------------------------------------------------------------------
| CubeCart 4
| ========================================
| CubeCart is a registered trade mark of Devellion Limited
| Copyright Devellion Limited 2006. All rights reserved.
| Devellion Limited,
| 5 Bridge Street,
| Bishops Stortford,
| HERTFORDSHIRE.
| CM23 2JU
| UNITED KINGDOM
| http://www.devellion.com
| UK Private Limited Company No. 5323904
| ========================================
| Web: http://www.cubecart.com
| Email: info (at) cubecart (dot) com
| License Type: CubeCart is NOT Open Source Software and Limitations Apply
| Licence Info: http://www.cubecart.com/site/faq/license.php
+--------------------------------------------------------------------------
| shoppingCart.inc.php
| ========================================
| Shopping Cart Box
+--------------------------------------------------------------------------
*/
if (!defined('CC_INI_SET')) die("Access Denied");
if (!$cc_session->user_is_search_engine() || !$config['sef']) {
## include lang file
$lang = getLang("includes".CC_DS."boxes".CC_DS."shoppingCart.inc.php");
$box_content = new XTemplate("boxes".CC_DS."shoppingCart.tpl");
$box_content->assign("LANG_SHOPPING_CART_TITLE",$lang['shoppingCart']['shopping_cart']);
require_once "classes".CC_DS."cart".CC_DS."shoppingCart.php";
$cart = new cart();
$basket = ($_GET['_a'] != 'logout') ? $cart->cartContents($cc_session->ccUserData['basket']) : null;
if (isset($_POST['add']) && $_POST['add']>0) {
if (!isset($_POST['productOptions'])) {
## check product options are selected if they are required
$prodOpts = $db->select("SELECT count(product) as noOpts FROM ".$glob['dbprefix']."CubeCart_options_bot WHERE product=".$db->mySQLSafe($_POST['add']));
## if they are required redirect to product view page
if ($prodOpts[0]['noOpts'] >0) {
httpredir($config['rootRel']."index.php?_a=viewProd&productId=".$_POST['add']."&added=1");
}
}
## add product to the cart
$quantity = (is_numeric($_POST['quan']) && $_POST['quan'] >= 1) ? ceil($_POST['quan']) : 1;
$basket = (isset($_POST['productOptions'])) ? $basket = $cart->add($_POST['add'], $quantity, $_POST['productOptions']) : $cart->add($_POST['add'], $quantity, '');
## Go to cart or back to same page
if ($config['add_to_basket_act'] == true) {
## Go to the cart
if ($cc_session->ccUserData['customer_id']>0) {
httpredir($config['rootRel']."index.php?_g=co&_a=step2");
} else {
httpredir($config['rootRel']."index.php?_g=co&_a=cart");
}
} else {
## Stay on same page but get rid of those pesky post variables
$url = explode('?', $_SERVER['HTTP_REFERER']);
$query = explode('&', $url[1]);
if (is_array($query) && !empty($query)) {
$allowedVars = array('_a', 'catId', 'docId', 'prodId', 'productId', 'review');
foreach ($query as $key => $getvars) {
$temp = explode('=', $getvars);
if (in_array($temp[0], $allowedVars)) {
$querystring[] = $temp[0].'='.$temp[1];
}
}
if (is_array($querystring)) {
$querystring = '?'.implode('&', $querystring).'&added=1';
} else {
$querystring = '?added=1';
}
}
httpredir($url[0].$querystring);
}
} else if (isset($_POST['gc']['cert']) && $_POST['gc']['cert'] == true) {
$gc = fetchDbConfig('gift_certs');
if (empty($_POST['gc']['amount']) && empty($_POST['gc']['recipName']) && empty($_POST['gc']['recipEmail'])) {
$errorGCMsg = 1;
} else if ($_POST['gc']['delivery'] == 'e' && !validateEmail($_POST['gc']['recipEmail'])) {
$errorGCMsg = 2;
} else {
if (!isset($gc['min']) || empty($gc['min'])) $gc['min'] = 1;
if ($_POST['gc']['amount'] < $gc['min']) $errorGCMsg = 3;
if (isset($gc['max']) && !empty($gc['max']) && $_POST['gc']['amount'] > $gc['max']) $errorGCMsg = 3;
if (!isset($errorGCMsg)) {
$basket = $cart->addCert($_POST['gc']);
## Go to cart or back to same page
if ($config['add_to_basket_act']) {
## Go to the cart
httpredir(basename($_SERVER['PHP_SELF'])."?_g=co&_a=cart");
} else {
// stay on same page but dump those mingy post vars
httpredir(basename($_SERVER['PHP_SELF'])."?_a=giftCert&added=1");
}
}
}
}
$cartTotal = NULL;
if (is_array($basket['conts']) && !empty($basket['conts'])) {
foreach ($basket['conts'] as $key => $value) {
if ($basket['conts'][$key]['custom'] == true) {
$price = $basket['conts'][$key]['gcInfo']['amount'];
$name = $lang['shoppingCart']['gift_cert'];
} else {
$productId = $cart->getProductId($key);
## Get product details
$product = $db->select("SELECT name, price, sale_price, productId FROM ".$glob['dbprefix']."CubeCart_inventory WHERE productId=".$db->mySQLSafe($productId));
if (($val = prodAltLang($product[0]['productId'])) == true) {
$product[0]['name'] = $val['name'];
}
## Build the product options
$optionKeys = $cart->getOptions($key);
$optionsCost = 0;
if (!empty($optionKeys)) {
$options = explode("|", $optionKeys);
foreach ($options as $value) {
## Look up options in database
$option = $db->select("SELECT ".$glob['dbprefix']."CubeCart_options_bot.option_id, ".$glob['dbprefix']."CubeCart_options_bot.value_id, option_price, option_symbol, assign_id FROM `".$glob['dbprefix']."CubeCart_options_bot` INNER JOIN `".$glob['dbprefix']."CubeCart_options_mid` ON ".$glob['dbprefix']."CubeCart_options_mid.value_id = ".$glob['dbprefix']."CubeCart_options_bot.value_id INNER JOIN `".$glob['dbprefix']."CubeCart_options_top` ON ".$glob['dbprefix']."CubeCart_options_bot.option_id = ".$glob['dbprefix']."CubeCart_options_top.option_id WHERE assign_id = ".$value);
if ($option[0]['option_price']>0) {
if ($option[0]['option_symbol'] == "+") {
$optionsCost += $option[0]['option_price'];
} else if ($option[0]['option_symbol'] == "-") {
$optionsCost -= $option[0]['option_price'];
}
}
}
}
$price = (salePrice($product[0]['price'], $product[0]['sale_price']) == false) ? $price = $product[0]['price'] : salePrice($product[0]['price'], $product[0]['sale_price']);
$price += $optionsCost;
$name = $product[0]['name'];
}
$box_content->assign("PRODUCT_PRICE",priceFormat($price,true));
$box_content->assign("VAL_NO_PRODUCT",$cart->cartArray['conts'][$key]["quantity"]);
$box_content->assign("PRODUCT_ID",$productId);
## Chop name if too long
if (strlen($name) > 15) $name = substr($name,0,15)."..";
$box_content->assign("VAL_PRODUCT_NAME", validHTML($name));
$box_content->parse("shopping_cart.contents_true");
$cartTotal = $cartTotal + ($price * $cart->cartArray['conts'][$key]["quantity"]);
}
} else {
$box_content->assign("LANG_CART_EMPTY",$lang['shoppingCart']['basket_empty']);
$box_content->parse("shopping_cart.contents_false");
}
$box_content->assign("VAL_CART_ITEMS", $cart->noItems());
$box_content->assign("LANG_ITEMS_IN_CART", $lang['shoppingCart']['items_in_cart']);
if (isset($cartTotal) && $cartTotal>0) {
$box_content->assign("VAL_CART_TOTAL", priceFormat($cartTotal,true));
} else {
$box_content->assign("VAL_CART_TOTAL", priceFormat(0, TRUE));
}
$box_content->assign("LANG_TOTAL_CART_PRICE",$lang['shoppingCart']['total']);
$box_content->assign("LANG_VIEW_CART",$lang['shoppingCart']['view_basket']);
if ($cc_session->ccUserData['customer_id']>0) {
$box_content->assign("CART_STEP", "step2");
} else {
$box_content->assign("CART_STEP", "cart");
}
if ($config['hide_prices'] && !$cc_session->ccUserData['customer_id'] && !$GLOBALS[CC_ADMIN_SESSION_NAME]) {
// have a break, have a KitKat
} else {
$box_content->parse("shopping_cart.view_cart");
}
$box_content->parse("shopping_cart");
$box_content = $box_content->text("shopping_cart");
} else {
$box_content = null;
}
?>