For all pages besides the actual shopping cart, it uses the global template index.tpl and for the shopping cart it uses the cart.tpl. All templates have an associated .php file that encompasses the back-end PHP code. Currently, as mentioned, when you go around on the website, the index.tpl file is the template being loaded, and acts as a page container for all other minor templates (i.e. inside the index.tpl template, it calls a menu template, and a header and footer template just to name a few. However, if you click to view your "shopping cart" it loads the cart.tpl template. At this point the index.tpl template is no longer in play, and the cart.tpl is the page container for all other minor templates.
I have attached the index templates associated include .php file below, the cart include PHP file, as well as the include php file for the 'small' shopping cart (This 'shopping cart' is the one you would see from page to page that tells you how many items you have in your shopping cart. But clicking "view basket" it loads the cart.tpl as mentioned).
Can someone help me understand how the global templates (index.tpl or cart.tpl gets called/used depending on whether your viewing the contents of the shopping cart (i.e. ready to check out) or anywhere else on the site????
Code: Select all
<?php
/*
+--------------------------------------------------------------------------
+--------------------------------------------------------------------------
| index.inc.php
| ========================================
| Main pages of the store
+--------------------------------------------------------------------------
*/
if (!defined('CC_INI_SET')) die("Access Denied");
$body = new XTemplate ("global".CC_DS."index.tpl");
## Extra Events
$extraEvents = "";
if (isset($_GET['added']) && !empty($_GET['added'])) {
if ($cc_session->ccUserData['customer_id'] == false && $config['hide_prices'] == 1) {
## have a break, have a KitKat
} else {
$extraEvents = "flashBasket(6);";
}
}
$body->assign("EXTRA_EVENTS",$extraEvents);
if (isset($_GET['searchStr'])) {
$body->assign("SEARCHSTR", sanitizeVar($_GET['searchStr']));
} else {
$body->assign("SEARCHSTR","");
}
$body->assign("CURRENCY_VER",$currencyVer);
## Incluse langauge config
include("language".CC_DS.LANG_FOLDER.CC_DS."config.php");
$body->assign("VAL_ISO",$charsetIso);
## START CONTENT BOXES
require_once"includes".CC_DS."boxes".CC_DS."searchForm.inc.php";
$body->assign("SEARCH_FORM",$box_content);
require_once"includes".CC_DS."boxes".CC_DS."session.inc.php";
$body->assign("SESSION",$box_content);
require_once"includes".CC_DS."boxes".CC_DS."categories.inc.php";
$body->assign("CATEGORIES",$box_content);
require_once"includes".CC_DS."boxes".CC_DS."randomProd.inc.php";
$body->assign("RANDOM_PROD",$box_content);
require_once"includes".CC_DS."boxes".CC_DS."info.inc.php";
$body->assign("INFORMATION",$box_content);
require_once"includes".CC_DS."boxes".CC_DS."language.inc.php";
$body->assign("LANGUAGE",$box_content);
require_once"includes".CC_DS."boxes".CC_DS."currency.inc.php";
$body->assign("CURRENCY",$box_content);
require_once"includes".CC_DS."boxes".CC_DS."shoppingCart.inc.php";
$body->assign("SHOPPING_CART",$box_content);
require_once"includes".CC_DS."boxes".CC_DS."popularProducts.inc.php";
$body->assign("POPULAR_PRODUCTS",$box_content);
require_once"includes".CC_DS."boxes".CC_DS."saleItems.inc.php";
$body->assign("SALE_ITEMS",$box_content);
require_once"includes".CC_DS."boxes".CC_DS."mailList.inc.php";
$body->assign("MAIL_LIST",$box_content);
require_once"includes".CC_DS."boxes".CC_DS."siteDocs.inc.php";
$body->assign("SITE_DOCS",$box_content);
require_once"includes".CC_DS."boxes".CC_DS."skin.inc.php";
$body->assign("SKIN",$box_content);
## END CONTENT BOXES
require_once"includes".CC_DS."content".CC_DS."hdrImage.inc.php";
$body->assign("HDRIMAGE",$hdr_image);
## START MAIN CONTENT
if (!empty($_GET['_a'])) {
#if ($_GET['_a'] == 'search') $_GET['_a'] = 'viewCat';
if (file_exists("includes".CC_DS."content".CC_DS.sanitizeVar($_GET['_a']).".inc.php")) {
require_once"includes".CC_DS."content".CC_DS.sanitizeVar($_GET['_a']).".inc.php";
} else {
require_once"includes".CC_DS."content".CC_DS."index.inc.php";
}
} else {
require_once"includes".CC_DS."content".CC_DS."index.inc.php";
}
## END MAIN CONTENT
## Start DaisyBlossoms Content
require_once"includes".CC_DS."content".CC_DS."hdrImage.inc.php";
## End DaisyBlossoms Content
## START META DATA
if (isset($meta)) {
$meta['title'] = sefMetaTitle();
$meta['description'] = sefMetaDesc();
$meta['keywords'] = sefMetaKeywords();
} else {
$meta['title'] = htmlspecialchars(str_replace("'","'",$config['siteTitle']));
$meta['description'] = $config['metaDescription'];
$meta['keywords'] = $config['metaKeyWords'];
}
$body->assign("META_TITLE", stripslashes($meta['title']));
$body->assign("META_DESC", stripslashes($meta['description']));
$body->assign("META_KEYWORDS", stripslashes($meta['keywords']));
?>
Code: Select all
<?php
/*
+--------------------------------------------------------------------------
| CubeCart 4
|
| cart.inc.php
| ========================================
| Controls Cart Actions
+--------------------------------------------------------------------------
*/
if (!defined('CC_INI_SET')) die("Access Denied");
$body = new XTemplate("global".CC_DS."cart.tpl");
if (isset($_GET['searchStr'])) {
$body->assign("SEARCHSTR", sanitizeVar($_GET['searchStr']));
} else {
$body->assign("SEARCHSTR", "");
}
$body->assign("CURRENCY_VER",$currencyVer);
## Incluse langauge config
include("language".CC_DS.LANG_FOLDER.CC_DS."config.php");
$body->assign("VAL_ISO",$charsetIso);
## START META DATA
$body->assign("META_TITLE", stripslashes(htmlspecialchars(str_replace("'", "'", $config['siteTitle']))));
$body->assign("META_DESC", stripslashes($config['metaDescription']));
$body->assign("META_KEYWORDS", stripslashes($config['metaKeyWords']));
$returnPage = urlencode(currentPage());
## START MAIN CONTENT
switch (sanitizeVar($_GET['_a'])) {
case "step1":
require_once "includes".CC_DS."content".CC_DS."step1.inc.php";
break;
case "cart":
case "step2":
require_once "includes".CC_DS."content".CC_DS."cart.inc.php";
break;
case "step3":
require_once "includes".CC_DS."content".CC_DS."gateway.inc.php";
break;
case "reg":
require_once "includes".CC_DS."content".CC_DS."reg.inc.php";
break;
case "viewOrders":
require_once "includes".CC_DS."content".CC_DS."viewOrders.inc.php";
break;
case "viewOrder":
require_once "includes".CC_DS."content".CC_DS."viewOrder.inc.php";
break;
case "error":
require_once "includes".CC_DS."content".CC_DS."error.inc.php";
break;
case "confirmed":
require_once "includes".CC_DS."content".CC_DS."confirmed.inc.php";
break;
default:
httpredir("index.php");
}
## START CONTENT BOXES
require_once "includes".CC_DS."boxes".CC_DS."searchForm.inc.php";
$body->assign("SEARCH_FORM", $box_content);
require_once "includes".CC_DS."boxes".CC_DS."session.inc.php";
$body->assign("SESSION", $box_content);
require_once "includes".CC_DS."boxes".CC_DS."siteDocs.inc.php";
$body->assign("SITE_DOCS", $box_content);
require_once "includes".CC_DS."boxes".CC_DS."cartNavi.inc.php";
$body->assign("CART_NAVI", $box_content);
## added in 4.0.3 - not part of templates, but designers can use them if they want
require_once"includes".CC_DS."boxes".CC_DS."currency.inc.php";
$body->assign("CURRENCY",$box_content);
require_once"includes".CC_DS."boxes".CC_DS."categories.inc.php";
$body->assign("CATEGORIES",$box_content);
require_once"includes".CC_DS."boxes".CC_DS."mailList.inc.php";
$body->assign("MAIL_LIST",$box_content);
require_once"includes".CC_DS."boxes".CC_DS."shoppingCart.inc.php";
$body->assign("SHOPPING_CART",$box_content);
require_once"includes".CC_DS."boxes".CC_DS."randomProd.inc.php";
$body->assign("RANDOM_PROD",$box_content);
require_once"includes".CC_DS."boxes".CC_DS."info.inc.php";
$body->assign("INFORMATION",$box_content);
require_once"includes".CC_DS."boxes".CC_DS."language.inc.php";
$body->assign("LANGUAGE",$box_content);
require_once"includes".CC_DS."boxes".CC_DS."popularProducts.inc.php";
$body->assign("POPULAR_PRODUCTS",$box_content);
require_once"includes".CC_DS."boxes".CC_DS."saleItems.inc.php";
$body->assign("SALE_ITEMS",$box_content);
require_once"includes".CC_DS."boxes".CC_DS."skin.inc.php";
$body->assign("SKIN",$box_content);
## END CONTENT BOXES
?>
Code: Select all
<?php
/*
+--------------------------------------------------------------------------
| CubeCart 4
+--------------------------------------------------------------------------
| 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) {
## Problem relating to #807 here?
if ($config['sef']) {
## Generate a SEO URL
//$productUrl = sef_get_base_url().generateProductUrl($_POST['add']).'?notice=1';
$productUrl = generateProductUrl($_POST['add']).'?notice=1';
} else {
$productUrl = 'index.php?_a=viewProd&productId='.$_POST['add'].'¬ice=1';
}
## Lose notice for product options
httpredir(str_replace("¬ice=1","",$_SERVER['HTTP_REFERER']).$addedStr);
exit;
}
}
## add product to the cart
$quantity = (is_numeric($_POST['quan']) && $_POST['quan'] > 0) ? $_POST['quan'] : 1;
## Allow for integer AND float quantities
$quantity = (isset($prodType[0]['prodType']) && $prodType[0]['prodType'] == 2) ? $quantity : ceil($quantity);
$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 {
$allowedVars = array('_a', 'category', 'catId', 'docId', 'page', 'priceMax', 'priceMin', 'prodId', 'productId', 'review', 'searchStr');
## Stay on same page but get rid of those pesky post variables
parse_str(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY), $query);
if (isset($query['searchStr'])) {
## Rehash this later - could benefit from the code used below
if (is_array($query) && !empty($query)) {
foreach ($query as $key => $value) {
if (in_array($key, $allowedVars) && !empty($value)) {
#$append[$key] = $value;
if (is_array($value)) {
foreach ($value as $val) {
$queryArray[] = sprintf('%s[]=%d', $key, $val);
}
} else {
$queryArray[] = sprintf('%s=%s', $key, urlencode($value));
}
}
}
## Add flash basket
$queryArray[] = "added=1";
$querystring = '?'.implode('&', $queryArray);
}
httpredir($glob['storeURL'].'/index.php'.$querystring);
} else {
## need to add added=1, as well as any allowed vars - PHP5 compatible
if (!preg_match('#^'.$GLOBALS['storeURL'].'#', $_SERVER['HTTP_REFERER']) || empty($_SERVER['HTTP_REFERER'])) {
httpredir('index.php');
} else {
$return_url = parse_url($_SERVER['HTTP_REFERER']);
if (is_array($query)) {
foreach ($query as $key => $value) {
if (in_array($key, $allowedVars) && !empty($value)) {
$append[$key] = $value;
}
}
}
$append['added'] = 1;
$redirect_to = sprintf('%s/%s?%s', $GLOBALS['storeURL'], substr($return_url['path'], strlen($GLOBALS['rootRel'])), http_build_query($append));
httpredir($redirect_to);
}
}
}
} 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']) && $_POST['gc']['delivery'] == 'e')) {
## Empty fields
$errorGCMsg = 1;
} else if ($_POST['gc']['delivery'] == 'e' && !validateEmail($_POST['gc']['recipEmail'])) {
## Invalid email address
$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) {
## Split on separator
$value_data = explode('@', $value);
$option_top = $db->select(sprintf("SELECT T.* FROM %1\$sCubeCart_options_top AS T WHERE T.option_id = %2\$s", $glob['dbprefix'], $value_data[0]));
if ($option_top) {
$option_name = $option_top[0]['option_name'];
if ($option_top[0]['option_type'] == 0) {
$option = $db->select(sprintf("SELECT M.*, B.* FROM %1\$sCubeCart_options_mid AS M, %1\$sCubeCart_options_bot AS B WHERE M.value_id = B.value_id AND B.assign_id = %2\$d", $glob['dbprefix'], $value_data[1]));
if ($option) {
$option_price = $option[0]['option_price'];
$option_symbol = $option[0]['option_symbol'];
$option_value = $option[0]['value_name'];
}
} else {
$option = $db->select(sprintf("SELECT B.* FROM %1\$sCubeCart_options_bot AS B WHERE B.option_id = %2\$d AND B.product = %3\$d LIMIT 1", $glob['dbprefix'], $value_data[0], $productId));
if ($option) {
$option_price = $option[0]['option_price'];
$option_symbol = $option[0]['option_symbol'];
$option_value = $value_data[1];
}
}
}
if ($option_price > 0) {
if ($option_symbol == "+") {
$optionsCost = $optionsCost + $option_price;
} else if ($option_symbol == "-") {
$optionsCost = $optionsCost - $option_price;
} else if ($option_symbol == "~") {
$optionsCost = 0;
}
}
}
}
$price = (salePrice($product[0]['price'], $product[0]['sale_price']) == false) ? $price = $product[0]['price'] : salePrice($product[0]['price'], $product[0]['sale_price']);
$price += $optionsCost;
if ($price < 0) $price = 0;
$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;
}
?>