$db_path = $_SERVER['DOCUMENT_ROOT'];
$db_path .= "/assets/php/script/db_auth.php";
require_once($db_path);
if(isset($_SESSION['wwel_customer_id'])) {
$userID = $_SESSION['wwel_customer_id'];
$time = date("Y-m-d H:i:s");
$active = "UPDATE `accounts` SET `LastActivity`='$time' WHERE `id`='$userID'";
mysqli_query($conn,$active);
}
$ip = $_SERVER['REMOTE_ADDR'];
$country_info = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?k=2be37f3fe718693b&ip='.$ip));
$country_code = $country_info['geoplugin_countryCode'];
$country_name = $country_info['geoplugin_countryName'];
if($country_code=="CA") {
$country_cur = "CAD";
$currency_country = "CA";
$_SESSION['ssl_transaction_currency'] = $country_cur;
}
if($country_code!=="CA") {
$country_cur = "USD";
$currency_country = "US";
}
$country_cur_sym = '$';
if (isset($_GET['addtocart']) && $_GET['addtocart']!=""){
if ($_GET['addtocart']=='BT200SprayBottle') {
if($country_code!=="CA") {
$added_sku = 'U4-4716S';
$code = 'U4-4716S';
$sku_price = '11.79';
} else {
$added_sku = 'C4-4716S';
$code = 'C4-4716S';
$skuprice = $_row['sku_price'];
$sku_price = '14.99';
}
}
if ($_GET['addtocart']=='FreshCareSprayBottle') {
if($country_code!=="CA") {
$added_sku = 'U4-4686S';
$code = 'U4-4686S';
$sku_price = '11.79';
} else {
$added_sku = 'C4-4686S';
$code = 'C4-4686S';
$skuprice = $_row['sku_price'];
$sku_price = '14.99';
}
}
if ($_GET['addtocart']=='SuperSRV') {
if($country_code!=="CA") {
$added_sku = 'U4-4848S';
$code = 'U4-4848S';
$sku_price = '53.00';
} else {
$added_sku = 'C4-4848S';
$code = 'C4-4848S';
$sku_price = '54.00';
}
}
// START ADD TO CART TRIGGER
$quantity = 1;
$result = mysqli_query($conn,"SELECT * FROM `product_skus` WHERE `product_sku`='$added_sku'");
while($row = mysqli_fetch_assoc($result)) {
$form_name = $row['sku_desc'];
$in_region = $row['in_region'];
$out_region = $row['out_region'];
$one_day = $row['1_day'];
$two_day = $row['2_day'];
$length = $row['sku_length'];
$width = $row['sku_width'];
$height = $row['sku_height'];
$weight = $row['sku_weight'];
$image = $row['sku_image'];
$size = $row['sku_size'];
$id_code = $row['product_code'];
}
//echo $size;
$result2 = mysqli_query($conn,"SELECT * FROM `product_parents` WHERE `product_code`='$id_code'");
$row2 = mysqli_fetch_assoc($result2);
$name = $form_name;
$link = $row2['permalink'];
$slogan = $row2['product_slogan'];
$cartArray = array(
$added_sku=>array(
'code'=>$id_code,
'sku'=>$added_sku,
'size'=>$size,
'length'=>$length,
'width'=>$width,
'height'=>$height,
'weight'=>$weight,
'name'=>$name,
'price'=>$sku_price,
'currency'=>$country_cur,
'inregion'=>$in_region,
'outregion'=>$out_region,
'oneday'=>$one_day,
'twoday'=>$two_day,
'quantity'=>$quantity,
'image'=>$image,
'slogan'=>$slogan,
'link'=>$link)
);
if (isset($_GET['addtocart']) && $_GET['addtocart']!="") {
if(!empty($_SESSION['shopping_cart'])) {
foreach( $_SESSION['shopping_cart'] as $key => $value ) {
if( $_GET['addtocart']=== $key) {
$_SESSION['shopping_cart'][$key]['quantity'] = $_SESSION['shopping_cart'][$key]['quantity'] + $_POST['product_quantity'];
$status = "
Product quantity updated
";
$cartArray = '';
break;
}
}
if($_SESSION['shopping_cart']!=='' && $_GET['addtocart']!==$key){
$_SESSION["shopping_cart"] = array_merge($_SESSION["shopping_cart"],$cartArray);
$status = "Product added to cart
";
$cartArray = '';
}
}
if ($_SESSION['shopping_cart']=='') {
$_SESSION["shopping_cart"] = $cartArray;
$status = "Product added to cart
";
$cartArray = '';
}
}
//END ADD TO CART TRIGGER
}
$status="";
if (isset($_POST['product_sku']) && $_POST['product_sku']!=""){
$code = $_POST['product_code'];
if(isset($_POST['product_quantity'])) { $quantity = $_POST['product_quantity']; }
if(isset($_POST['quantity'])) { $quantity = $_POST['quantity']; }
$form_name = $_POST['product_name'];
$added_sku = $_POST['product_sku'];
if(isset($_POST['product_price'])) { $sku_price = $_POST['product_price']; }
if(isset($_POST['sku_price'])) { $sku_price = $_POST['sku_price']; }
$result = mysqli_query($conn,"SELECT * FROM `product_skus` WHERE `product_sku`='$added_sku'");
while($row = mysqli_fetch_assoc($result)) {
$in_region = $row['in_region'];
$out_region = $row['out_region'];
$one_day = $row['1_day'];
$two_day = $row['2_day'];
$length = $row['sku_length'];
$width = $row['sku_width'];
$height = $row['sku_height'];
$weight = $row['sku_weight'];
$image = $row['sku_image'];
$size = $row['sku_size'];
$id_code = $row['product_code'];
}
$result2 = mysqli_query($conn,"SELECT * FROM `product_parents` WHERE `product_code`='$code'");
$row2 = mysqli_fetch_assoc($result2);
$name = $form_name;
$slogan = $row2['product_slogan'];
$link = $row2['permalink'];
$cartArray = array(
$added_sku=>array(
'code'=>$id_code,
'sku'=>$added_sku,
'size'=>$size,
'length'=>$length,
'width'=>$width,
'height'=>$height,
'weight'=>$weight,
'name'=>$name,
'price'=>$sku_price,
'currency'=>$country_cur,
'inregion'=>$in_region,
'outregion'=>$out_region,
'oneday'=>$one_day,
'twoday'=>$two_day,
'quantity'=>$quantity,
'image'=>$image,
'slogan'=>$slogan,
'link'=>$link)
);
if (isset($_POST['action']) && $_POST['action']=="remove"){
if(!empty($_SESSION["shopping_cart"])) {
foreach($_SESSION["shopping_cart"] as $key => $value) {
if($_POST["product_sku"]=== $key){
unset($_SESSION["shopping_cart"][$key]);
$status = "
Product is removed from your cart!
";
}
if($key===''){
unset($_SESSION["shopping_cart"]);
$status = "
Product is removed from your cart!
";
}
if(empty($_SESSION["shopping_cart"]))
unset($_SESSION["shopping_cart"]);
$status = "
Product is removed from your cart!
";
}
}
}
if (isset($_POST['action']) && $_POST['action']=="change"){
foreach($_SESSION["shopping_cart"] as &$value){
if($value['sku'] === $_POST["product_sku"]){
$value['quantity'] = $_POST["quantity"];
$status = "
Product quantity has been updated
";
break; // Stop the loop after we've found the product
}
}
}
if (isset($_POST['action']) && $_POST['action']=="additem") {
if(!empty($_SESSION['shopping_cart'])) {
foreach( $_SESSION['shopping_cart'] as $key => $value ) {
if( $_POST['product_sku']=== $key) {
$_SESSION['shopping_cart'][$key]['quantity'] = $_SESSION['shopping_cart'][$key]['quantity'] + $_POST['product_quantity'];
$status = "Product quantity updated
";
$cartArray = '';
break;
}
}
if($_SESSION['shopping_cart']!=='' && $_POST['product_sku']!==$key){
$_SESSION["shopping_cart"] = array_merge($_SESSION["shopping_cart"],$cartArray);
$status = "Product added to cart
";
$cartArray = '';
}
}
if (empty($_SESSION['shopping_cart'])) {
$_SESSION["shopping_cart"] = $cartArray;
$status = "Product added to cart
";
$cartArray = '';
}
}
}
if(isset($_POST['action'])) {
if(!empty($_SESSION['shopping_cart']) && $_POST['action']=="") {
foreach( $_SESSION['shopping_cart'] as $key => $value ) {
if ($value['currency']!== $country_cur) {
unset($_SESSION["shopping_cart"]);
}
}
}
}
if(isset($_POST['error']) && !$_POST['error']=="") {
$status = "".$_POST['error']."
";
}
if(isset($_POST['error']) && $_POST['error']==="cardnumber") {
$status = "The credit card supplied appears to be invalid.
";
}
if(isset($_POST['error']) && $_POST['error']==="address") {
$status = "".$_POST['error']."
";
}
if(isset($_POST['error']) && $_POST['error']==="PICK UP CARD") {
$status = "The credit card supplied has been reported lost or stolen by the card issuer. Your IP address and information have been retained.
";
}
if(isset($_POST['error']) && $_POST['error']==="EXPIRED CARD") {
$status = "The credit card supplied is expired.
";
}
if(isset($_POST['error']) && $_POST['error']==="SERV NOT ALLOWED") {
$status = "The credit card supplied is not authorized for this transaction. A business credit card may prevent personal transactions.
";
}
if(isset($_POST['error']) && $_POST['error']==="DECLINED CVV2") {
$status = "The CVV2 Code entered does not match what is on the card. Please re-enter the CVV2 code and try again.
";
}
if(isset($_POST['error']) && $_POST['error']==="DECLINED") {
$status = "The credit card supplied declined the transaction. Please try again.
";
}
if(isset($_POST['account']) && $_POST['account']==="username") {
$status = "User does not exist. Please try again.
";
}
if(isset($_POST['account']) && $_POST['account']==="password") {
$status = "Password was incorrect. Please try again.
";
}
if(isset($_POST['account']) && $_POST['account']==="server") {
$status = "There was a server error. Please try again.
";
}
if(isset($_POST['account']) && $_POST['account']==="reactivated") {
$status = "Account reactivated. Please log in.
";
}
// Print array contents
//print_r($_SESSION['shopping_cart']);
if(isset($_SESSION['wwel_customer_id'])) {
if ($_SESSION['wwel_customer_id'] != NULL) {
}};
if(isset($_SESSION['shopping_cart'])) {
$cart_count = count(array_keys($_SESSION["shopping_cart"]));
} else {
$cart_count = 0;
}
?>