<?php
session_start();
/*
asaancart - easy shopping cart solution
---------------------------------------
Copyright 2009 Nasir Ahmad Khan
Email: hide@address.com
This file is part of asaancart - open source easy shopping cart solution.
asaancart is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
asaancart is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with asaancart. If not, see <http://www.gnu.org/licenses/>.
*/
include("../config/config.php");
if (session_id() == "") session_start();
$product_id = $_GET['product_id'];
$page_heading = "My Shoping Cart";
$product_name = $_GET['product_name'];
$mode = $_GET['mode'];
//get pro image
$sql_img = "SELECT * FROM product_images WHERE product_id='".$product_id."' ORDER BY is_main DESC";
$results_img = mysql_query($sql_img);
$img_cnt = 0;
while($row_img = mysql_fetch_assoc($results_img) )
{
if($img_cnt<1){
$product_image = $row_img['image_filename'];
}
}
// end pro img
//get product price
//products
$sql = "SELECT * FROM products WHERE product_id = '$product_id' ORDER BY product_name";
$results = mysql_query($sql);
$total_products = mysql_num_rows($results);
$smarty->assign('total_products', $total_products);
while($row = mysql_fetch_assoc($results) )
{
$product_price = $row['product_price'];
$product_description = $row['product_description'];
}
//end get price
//add to cart
if($mode == "add"){
//$product_qty = $_GET[''];
$session_id = session_id();
$product_qty = 1;
$total = $product_price*$product_qty;
$is_found = 0;
$sql_chk_pro = "SELECT * FROM my_cart WHERE product_id = '$product_id' AND session_id='$session_id'";
$results_chk_pro = mysql_query($sql_chk_pro);
$is_found = mysql_num_rows($results_chk_pro);
if ($is_found==0){
$sql = "INSERT INTO my_cart (session_id, product_id, product_name, product_description, product_price, product_image, product_qty, total) VALUES ('$session_id', '$product_id', '$product_name', '$product_description', $product_price, '$product_image', $product_qty, $total)";
$results = mysql_query($sql);
$smarty->assign('msg',"<div style='color:black; font-weight:normal;'>Done, <strong>$product_name</strong> added successfully into your cart</div>");
}else{
$smarty->assign('msg',"<div style='color:red; font-weight:bold;'>Sorry, <strong>$product_name</strong> already in your cart. Please update quantity if you want to add more.</div>");
}// found chk
}
//end add to cart
?>