/*
A simple shopping cart class that I wacked up ages ago when i was bored.
No payment function has been written mainly because it depends on the implementation.
I leave the payment function up to the programmer :)
*/
//Run global functions ---------------
$HomeGlobal->cat_menu();
$HomeGlobal->get_sp_noibait_trangtrong();
//------------------------------------
include("includes/cls_paypal.php");
$cart = new clsCart();
class clsCart
{
var $data = array();
function clsCart(){
global $HomeGlobal, $Func;
$act = $Func->get_vars('act', 1);
$product_id = intval($_POST['id']);
$product_num = $_POST['pnum']?intval($_POST['pnum']):0;
$product_price = intval($_POST['pprice']);
/* $product_id = intval($Func->get_vars('id', $this->cat_pos_var + 2));
$product_num = intval($Func->get_vars('pnum', $this->cat_pos_var + 3));
$product_price = intval($Func->get_vars('pprice', $this->cat_pos_var + 4));
*/ $mod = $Func->get_vars('mod', 0);
switch ($act){
case 'add':
$this->addItem($product_id,$product_price,$product_num);
break;
case 'update':
$this->updateItem($product_id,$product_num);
break;
case 'empty':
$this->clearCart();
break;
case 'checkout':
if($_POST['BillFirst'])$this->do_checkout();
else
$this->checkout();
break;
case 'shipping':
if($_POST['shipping'])$this->do_shipping();
else
$this->shipping();
break;
case 'payment':
$this->payment_preview();
break;
case 'print_order':
$this->ClsPrintOrder();
break;
case 'send_order':
$this->ClsSend_Order();
break;
default:
$this->contents() ;
}
}
function cut_string($str,$len,$more){
if ($str=="" || $str==NULL) return $str;
if (is_array($str)) return $str;
$str = trim($str);
if (strlen($str) <= $len) return $str;
$str = substr($str,0,$len);
if ($str != "") {
if (!substr_count($str," ")) {
if ($more) $str .= " ...";
return $str;
}
while(strlen($str) && ($str[strlen($str)-1] != " ")) {
$str = substr($str,0,-1);
}
$str = substr($str,0,-1);
if ($more) $str .= " ...";
}
return $str;
}
function ClsPrintOrder() {
global $DB,$Template,$Info,$Func;
$Info->tpl_main = 'print_orderDetail';
$Info->tpl_header="none";
$Info->tpl_left="none";
$Info->tpl_footer="none";
$Info->tpl_right="none";
$date_format = $Info->option['full_date_time_format'];
$timezone = $Info->option['timezone'] * 3600;
$count = 0;
$query = "SELECT * FROM ". $DB->prefix ."payment WHERE session='".$this->getSession()."' ORDER BY payment_id DESC LIMIT 0,1";
$DB->query($query);
$billing_info = $DB->fetch_array();
$Template -> set_vars(array(
"B_NAME" => 'Họ tên:'.' '.$billing_info['billing_firstname'],
"B_ADDRESS1" => 'Số CMND:'.' '.html_entity_decode($billing_info['billing_add1']),
"B_ADDRESS2" => 'Địa chỉ giao hàng:'.' '.html_entity_decode($billing_info['billing_add2']),
"B_PHONE" => 'Điện thoại:'.' '.$billing_info['billing_phone'],
"B_EMAIL" => 'Email:'.' '.$billing_info['billing_email'],
"B_COUNTRY" => 'Thành phố:'.' '.$billing_info['billing_country'],
"B_YEUCAU" => 'Yêu cầu:'.' '.$billing_info['billing_city'],
"S_YEUCAU" => 'Yêu cầu:'.' '.$billing_info['shipping_city'],
"S_EMAIL" => 'Email:'.' '.$billing_info['shipping_email'],
"S_NAME" => 'Họ tên:'.' '.$billing_info['shipping_firstname'],
"S_PHONE" => 'Điện thoại:'.' '.$billing_info['shipping_phone'],
"S_ADDRESS1" => 'Địa chỉ 1:'.' '.html_entity_decode($billing_info['shipping_add1']),
"S_ADDRESS2" => 'Địa chỉ 2:'.' '.html_entity_decode($billing_info['shipping_add2']),
"S_COUNTRY" => 'Thành phố:'.''.$billing_info['shipping_country'],
"SHIP_METHOD" => ($billing_info['shipping_method']==1)?"Vận chuyển khu vực Hà Nội":"Vận chuyển ngoại thành và các tỉnh khác",
"date" => date('d/m/Y'),
"ID" => $billing_info['payment_id'],
));
// $ship_price = ($billing_info['shipping_method']==1)?20:40;
$sql = "SELECT * FROM ". $DB->prefix ."cart WHERE (session='".$this->getSession()."') ORDER BY cart_id DESC";
$query = $DB->query($sql);
$total = 0;
$count_id=1;
while($row = $DB->fetch_array($query)) {
$result = $this -> getProductById($row['product_id']);
//Get images products
// $subTotal = ($result["RatePrice"]) ? $result["product_price"]* $result["RatePrice"]* $row['product_quantity'] : $result['product_price'] * $row['product_quantity'];
$subTotal = $row['pro_price'] * $row['product_quantity'];
$total += $subTotal;
$Template->set_block_vars("cartrow", array(
"Count_ID" => $count_id,
"ID" => $row["product_id"],
"item_id" => $result["products_code"],
"name" => $result["title"],
// "IMG" => $images,
"unitprice" => number_format($row["pro_price"],0,',','.'),
// "unitprice" => ($result["RatePrice"]) ? number_format($result["product_price"]* $result["RatePrice"],2,'.',','):number_format($result["product_price"],2,'.',','),
"quantity" => $row["product_quantity"],
"price" => number_format($subTotal,0,',','.'),
"U_CART" => $Func->compile_url(array('mod' => MOD_CART,'act'=>'update')),
));
// $button->AddItem($result["title"],$row["product_quantity"],$result["product_price"],$result["products_code"]);
$count_id+=1;
}
// $button->AddItem('Shipping',1,$ship_price);
$query2 = "SELECT * FROM ". $DB->prefix ."editprofile ";
$DB->query($query2);
$billing_info2 = $DB->fetch_array();
$tongtien= $billing_info2["tygia"] * $total;
$Template -> set_vars(array(
'total'=> number_format($total,0,',','.'),
'tong'=> number_format($tongtien,0,',','.'),
));
}
function ClsSend_Order() {
global $DB,$Template,$Info,$Func;
// $this->do_send_email();
$Info->tpl_main = 'msg_sendorder';
/*$query = "SELECT * FROM ". $DB->prefix ."payment WHERE session='".$this->getSession()."' ORDER BY payment_id DESC";
$DB->query($query);
$billing_info = $DB->fetch_array();
$pro_nl = 'Mã ID: '.$billing_info['payment_id'] ;
$pay = $billing_info['shipping_method'];
if($pay=="3"){
$sql = "SELECT * FROM ". $DB->prefix ."cart WHERE (session='".$this->getSession()."') ORDER BY cart_id DESC";
$query = $DB->query($sql);
$total = 0;
$count_id=1;
while($row = $DB->fetch_array($query)) {
$result = $this -> getProductById($row['product_id']);
$subTotal = $result['product_price'] * $row['product_quantity'];
$total += $subTotal;
$count_id+=1;
}
/*$mail_nl="xuyennt@anhvumobile.vn";
$pri_nl=$total;
$pri_nl =preg_replace('/[\D]+/','',$pri_nl);
$cur_nl="vnd";
$return = str_replace("www.","",$_SERVER['HTTP_HOST']);
$varURL = "https://www.nganluong.vn/button_payment.php?currency=".$cur_nl."&receiver=".$mail_nl."&product_name=".$pro_nl." Mua hàng tại website ".$return." (".date("d/m/Y").")&price=".$pri_nl."&return_url=http://".$return;//."&ref_code=";
echo '';
exit();
}
$Template -> set_vars(array(
"ID" => $billing_info['payment_id'],
)); */
}
function payment_preview()
{
global $DB,$Template,$Info,$Func;
//General paypal button
$button = new PayPalButton; //initiate the class instance
$button->accountemail = 'duyly99@hotmail.com'; //the account that is registered with paypal where money will be sent to
$button->custom = 'my custom passthrough variable'; //a custom string that gets passed through paypals pages, back to your IPN page and Return URL as $_POST['custom'] . useful for database id's or invoice numbers. WARNING: does have a max string limit, don't go over 150 chars to be safe
$button->currencycode = 'USD'; //currency code
$button->target = '_top'; //Frame Name, usually '_blank','_self','_top' . Comment out to use current frame.
$button->class = 'paypalbutton'; //CSS class to apply to the button. Comes in very handy
$button->width = '150'; //button width in pixels. Will apply am Inline CSS Style to the button. Comment if not needed.
$button->image = 'http://www.adonggems.com/home/images/logo.jpg'; //image 150px x 50px that can be displayed on your paypal pages.
//$button->buttonimage = '/paypal/purchase.jpg'; //img to use for this button
$button->buttontext = 'I agree, proceed to Payment'; //text to use if image not found or not specified
$button->askforaddress = false; //wether to ask for mailing address or not
//$button->return_url = 'http://www.aussiehorsebrokers.com.au/paypal.php'; //url of the page users are sent to after successful payment
//$button->ipn_url = 'http://www.aussiehorsebrokers.com.au/paypal/ipn.php'; //url of the IPN page (this overrides account settings, IF IPN has been setup at all.
//$button->cancel_url = 'http://www.aussiehorsebrokers.com.au/paypal_cancel.php'; //url of the page users are sent to if they cancel through the paypal process
//paypal
$Info->tpl_main = 'payment';
$count = 0;
$query = "SELECT * FROM ". $DB->prefix ."payment WHERE session='".$this->getSession()."' ORDER BY payment_id DESC";
$DB->query($query);
$billing_info = $DB->fetch_array();
$abc= "haivuong";
$efd= "haivuong 2";
/*if($billing_info['shipping_method']==1){
$Template->set_block_vars("shipping_method1", array(
"abc" => $abc,
));
} else if($billing_info['shipping_method']==2){
$Template->set_block_vars("shipping_method2", array(
"efd" => $efd,
));
}*/
if($billing_info['shipping_method']==1){
$ship_method = "Tiền mặt trực tiếp";
} else if($billing_info['shipping_method']==2){
$ship_method = "Chuyển khỏan";
} else if($billing_info['shipping_method']==3){
$ship_method = "Thanh toán trực tuyến an toàn qua NgânLượng.vn";
}
$Template -> set_vars(array(
"ID" => $billing_info['payment_id'],
"B_NAME" => $billing_info['billing_firstname'],
"B_ADDRESS" => $billing_info['billing_add1'],
"B_ADDRESS2" => $billing_info['billing_add2'],
"B_CITY" => $billing_info['billing_country'],
"B_PHONE" => $billing_info['billing_phone'],
"B_EMAIL" => $billing_info['billing_email'],
"B_YEUCAU" => $billing_info['billing_city'],
"S_YEUCAU" => $billing_info['shipping_city'],
"S_NAME" => $billing_info['shipping_firstname'],
"S_ADDRESS" => $billing_info['shipping_add1'].(empty($billing_info['shipping_add2'])?'':"
Địa chỉ nhận hàng: ".$billing_info['shipping_add2']),
"S_CITY" => $billing_info['shipping_country'],
"S_PHONE" => $billing_info['shipping_phone'],
"S_EMAIL" => $billing_info['shipping_email'],
//"SHIP_METHOD" => ($billing_info['shipping_method']==1) ? 'Tiền mặt trực tiếp' :($billing_info['shipping_method']==3) ? 'Thanh toán trực tuyến an toàn qua NgânLượng.vn' : 'Chuyển khoản',
"SHIP_METHOD" => $ship_method,
"TT" => $tt,
"U_PRINT_ORDER" => $Func->compile_url(array('mod' => MOD_CART,'act'=>'print_order')),
"U_SENDE_ORDER" => $Func->compile_url(array('mod' => MOD_CART,'act'=>'send_order')),
));
$ship_price = ($billing_info['shipping_method']==1)?0: number_format(50000,0,',','.');
$sql = "SELECT * FROM ". $DB->prefix ."cart WHERE (session='".$this->getSession()."') ORDER BY cart_id DESC";
$query = $DB->query($sql);
$total = 0;
$j;
while($row = $DB->fetch_array($query)) {
$j++;
$result = $this -> getProductById($row['product_id']);
//Get images products
$subTotal = $row['pro_price'] * $row['product_quantity'];
$total += $subTotal;
if ( substr($result["img_large"], 0, 7) != 'http://' )
{
$result["img_large"] = './images/products/'. $result["img_large"];
}
$images = 'set_block_vars("cartrow", array(
"ID" => $row["product_id"],
"item_id" => $result["products_code"],
"name" => $result["title"],
"IMG" => $images,
"J" => $j,
"unitprice" => number_format($row['pro_price'],0,',','.'),
"quantity" => $row["product_quantity"],
"price" => number_format($subTotal,0,',','.'),
"U_CART" => $Func->compile_url(array('mod' => MOD_CART,'act'=>'update')),
));
$button->AddItem($result["title"],$row["product_quantity"],$result["product_price"],$result["products_code"]);
}
$query2 = "SELECT * FROM ". $DB->prefix ."editprofile ";
$DB->query($query2);
$billing_info2 = $DB->fetch_array();
$tongtien= $billing_info2["tygia"] * $total;
$tygia1 = $billing_info2["tygia"];
$button->AddItem('Shipping',1,$ship_price);
$Template -> set_vars(array(
'total' => number_format($total,0,',','.'),
"SHIP_PRICE" => $ship_price,
"ORDER_TOTAL" => number_format($total,0,',','.'),
"U_EMPTY" => $Func->compile_url(array('mod' => MOD_CART,'act'=>'empty')),
"U_CHECKOUT" => $Func->compile_url(array('mod' => MOD_CART,'act'=>'checkout')),
'PAYPAL_BUTTON' => $button->OutputButton(),
"TYGIA" => number_format($tygia1,0,',','.'),
"VND" => number_format($tongtien,0,',','.'),
'tong' => number_format($tongtien,0,',','.'),
));
// $this->do_send_email();
}
function shipping(){
global $DB,$Template,$Info,$Func;
$Info->tpl_main = 'shipping';
$Template -> set_vars(array(
"U_CHECKOUT" => $Func->compile_url(array('mod' => MOD_CART,'act'=>'payment')),
));
}
function do_shipping(){
global $DB,$Template,$Info,$Func;
$this->data["shipping"] = isset($_POST["shipping"]) ? intval($_POST["shipping"]) : 1;
$DB->query("UPDATE ". $DB->prefix ."payment SET shipping_method='".$this->data["shipping"]."' WHERE session='".$this->getSession()."'");
$Template->fast_transfer($Func->compile_url(array('mod'=>MOD_CART,'act'=>'payment')));
}
function checkout(){
global $DB,$Template,$Info,$Func;
$Info->tpl_main = 'billing_view';
$Template -> set_vars(array(
"U_CHECKOUT" => $Func->compile_url(array('mod' => MOD_CART,'act'=>'checkout')),
));
}
function do_checkout(){
global $DB,$Template,$Info,$Func;
$this->data["BillFirst"] = isset($_POST["BillFirst"]) ? htmlspecialchars($_POST["BillFirst"]) : '';
$this->data["BillAddress1"] = isset($_POST["BillAddress1"]) ? htmlspecialchars($_POST["BillAddress1"]) : '';
$this->data["BillAddress2"] = isset($_POST["BillAddress2"]) ? htmlspecialchars($_POST["BillAddress2"]) : '';
$this->data["BillCountry"] = isset($_POST["BillState"]) ? htmlspecialchars($_POST["BillState"]) : '';
$this->data["BillCity"] = isset($_POST["BillCity"]) ? htmlspecialchars($_POST["BillCity"]) : '';
$this->data["BillPostalcode"] = isset($_POST["Bill_Postalcode"]) ? htmlspecialchars($_POST["Bill_Postalcode"]) : '';
$this->data["BillPhone"] = isset($_POST["Bill_Phone"]) ? htmlspecialchars($_POST["Bill_Phone"]) : '';
$this->data["BillEmail"] = isset($_POST["BillEmail"]) ? htmlspecialchars($_POST["BillEmail"]) : '';
$this->data["ShipFirst"] = isset($_POST["ShipFirst"]) ? htmlspecialchars($_POST["ShipFirst"]) : '';
$this->data["ShipAddress1"] = isset($_POST["ShipAddress1"]) ? htmlspecialchars($_POST["ShipAddress1"]) : '';
$this->data["ShipAddress2"] = isset($_POST["ShipAddress2"]) ? htmlspecialchars($_POST["ShipAddress2"]) : '';
$this->data["ShipCountry"] = isset($_POST["ShipState"]) ? htmlspecialchars($_POST["ShipState"]) : '';
$this->data["ShipCity"] = isset($_POST["ShipCity"]) ? htmlspecialchars($_POST["ShipCity"]) : '';
$this->data["ShipProvince"] = isset($_POST["Ship_Province"]) ? htmlspecialchars($_POST["Ship_Province"]) : '';
$this->data["ShipPostalcode"] = isset($_POST["Ship_Postalcode"]) ? htmlspecialchars($_POST["Ship_Postalcode"]) : '';
$this->data["ShipPhone"] = isset($_POST["Ship_Phone"]) ? htmlspecialchars($_POST["Ship_Phone"]) : '';
$this->data["ShipEmail"] = isset($_POST["ShipEmail"]) ? htmlspecialchars($_POST["ShipEmail"]) : '';
$this->data["shipping_method"] = isset($_POST["shipping_method"]) ? htmlspecialchars($_POST["shipping_method"]) : '';
$query = "SELECT * FROM ". $DB->prefix ."payment WHERE session='".$this->getSession()."'";
$DB->query($query);
if($DB->num_rows()) {
$sql = "UPDATE ". $DB->prefix ."payment SET
billing_firstname='".$this->data["BillFirst"]."',
billing_add1='".$this->data["BillAddress1"]."',
billing_add2='".$this->data["BillAddress2"]."',
billing_country='".$this->data["BillCountry"]."',
billing_city='".$this->data["BillCity"]."',
billing_postcode='".$this->data["BillPostalcode"]."',
billing_phone='".$this->data["BillPhone"]."',
billing_email='".$this->data["BillEmail"]."',
shipping_firstname='".$this->data["ShipFirst"]."',
shipping_add1='".$this->data["ShipAddress1"]."',
shipping_add2='".$this->data["ShipAddress2"]."',
shipping_country='".$this->data["ShipCountry"]."',
shipping_city='".$this->data["ShipCity"]."',
shipping_postcode='".$this->data["ShipPostalcode"]."',
shipping_phone='".$this->data["ShipPhone"]."',
shipping_email='".$this->data["ShipEmail"]."'
WHERE session='".$this->getSession()."'";
/*$sql = "INSERT INTO ". $DB->prefix ."payment(
billing_firstname,
billing_add1,
billing_add2,
billing_country,
billing_city,
billing_postcode,
billing_phone,
billing_email,
shipping_firstname,
shipping_add1,
shipping_add2,
shipping_country,
shipping_city,
shipping_postcode,
shipping_phone,
shipping_email,
shipping_method,
time,
session
) VALUES(
'".$this->data["BillFirst"]."',
'".$this->data["BillAddress1"]."',
'".$this->data["BillAddress2"]."',
'".$this->data["BillCountry"]."',
'".$this->data["BillCity"]."',
'".$this->data["BillPostalcode"]."',
'".$this->data["BillPhone"]."',
'".$this->data["BillEmail"]."',
'".$this->data["ShipFirst"]."',
'".$this->data["ShipAddress1"]."',
'".$this->data["ShipAddress2"]."',
'".$this->data["ShipCountry"]."',
'".$this->data["ShipCity"]."',
'".$this->data["ShipPostalcode"]."',
'".$this->data["ShipPhone"]."',
'".$this->data["ShipEmail"]."',
'".$this->data["shipping_method"]."',
'".time()."',
'".$this->getSession()."'
)";*/
}else{
$sql = "INSERT INTO ". $DB->prefix ."payment(
billing_firstname,
billing_add1,
billing_add2,
billing_country,
billing_city,
billing_postcode,
billing_phone,
billing_email,
shipping_firstname,
shipping_add1,
shipping_add2,
shipping_country,
shipping_city,
shipping_postcode,
shipping_phone,
shipping_email,
shipping_method,
time,
session
) VALUES(
'".$this->data["BillFirst"]."',
'".$this->data["BillAddress1"]."',
'".$this->data["BillAddress2"]."',
'".$this->data["BillCountry"]."',
'".$this->data["BillCity"]."',
'".$this->data["BillPostalcode"]."',
'".$this->data["BillPhone"]."',
'".$this->data["BillEmail"]."',
'".$this->data["ShipFirst"]."',
'".$this->data["ShipAddress1"]."',
'".$this->data["ShipAddress2"]."',
'".$this->data["ShipCountry"]."',
'".$this->data["ShipCity"]."',
'".$this->data["ShipPostalcode"]."',
'".$this->data["ShipPhone"]."',
'".$this->data["ShipEmail"]."',
'".$this->data["shipping_method"]."',
'".time()."',
'".$this->getSession()."'
)";
}
$DB->query($sql);
$Template->fast_transfer($Func->compile_url(array('act'=>'payment')));
}
function getSession()
{
//return str_replace("PHPSESSID=", "", SID);
@session_start();
if(empty($_SESSION['CARTID'])){
//setcookie ("CARTID", md5(uniqid(microtime()) . rand(100, 10000)), 3600);
$_SESSION['CARTID'] = md5(uniqid(microtime()) . rand(100, 10000));
}
$sid = $_SESSION['CARTID'];
return $sid;
}
function checkItem($pid){
global $DB;
$query = "SELECT * FROM ". $DB->prefix ."cart WHERE session='".$this->getSession()."' AND product_id='$pid' ";
$result = $DB->query($query);
if(!$result)
{
return 0;
}
$numRows = $DB->num_rows();
if($numRows == 0)
{
return 0;
} else {
$row = $DB->fetch_array();
return $row['product_quantity'];
}
}
function updateItem($pid, $quantity)
{
global $DB,$Template,$Func;
$qty = $this->checkItem($pid);
if($quantity == 0)
{
$query = "DELETE FROM ". $DB->prefix ."cart WHERE session='".$this->getSession()."' AND ";
$query .= " product_id='$pid' ";
} else {
$query = "UPDATE ". $DB->prefix ."cart SET product_quantity='$quantity' WHERE session='".$this->getSession()."' AND ";
$query .= " product_id='$pid' ";
}
$DB->query($query);
$Template->fast_transfer($Func->compile_url(array('mod'=>MOD_CART)));
}
function addItem($pid, $price, $quantity)
{
global $DB,$Template,$Func;
$price = floatval($_POST['pprice']);
$qty = $this->checkItem($pid);
if($qty == 0)
{
$query = "INSERT INTO ". $DB->prefix ."cart (session, product_id,pro_price, product_quantity) VALUES ";
$query .= "('".$this->getSession()."', '$pid', '$price', '$quantity') ";
} else {
$quantity += $qty;
$query = "UPDATE ". $DB->prefix ."cart SET product_quantity='$quantity' WHERE session='".$this->getSession()."' AND ";
$query .= " product_id='$pid' ";
}
$DB->query($query);
$Template->fast_transfer($Func->compile_url(array('mod'=>MOD_CART)));
}
function removeItem($pid)
{
global $DB;
$query = "DELETE FROM ". $DB->prefix ."cart WHERE session='".$this->getSession()."' AND product_id='$pid' ";
$DB->query($query);
}
function modifyQuantity($pid, $quantity)
{
global $DB;
if($quantity<1)$this->removeItem($pid);
$query = "UPDATE ". $DB->prefix ."cart SET product_quantity='$quantity' WHERE session='".$this->getSession()."' ";
$query .= "AND product_id='$pid' ";
$DB->query($query);
}
function clearCart()
{
global $DB,$Template,$Func;
$query = "DELETE FROM ". $DB->prefix ."cart WHERE session='".$this->getSession()."' ";
$DB->query($query);
$Template->fast_transfer($Func->compile_url(array('mod'=>MOD_CART)));
}
function getTotal()
{
global $DB;
$sql = "SELECT sum(". $DB->prefix ."article.price * ". $DB->prefix ."cart.product_quantity) as price FROM ". $DB->prefix ."article, ". $DB->prefix ."cart WHERE (". $DB->prefix ."cart.session='".$this->getSession()."') AND (". $DB->prefix ."article.article_id = ". $DB->prefix ."cart.product_id)";
$result = $DB->query($query);
$row = $DB->sql_get($result);
return $row['price'];
}
function contents()
{
global $DB,$Template,$Info,$Func;
$Info->tpl_main = 'shoppingcart';
$Info->tpl_main_intro = "none";
$count = 0;
$sql = "SELECT * FROM ". $DB->prefix ."cart WHERE (session='".$this->getSession()."') ORDER BY cart_id DESC";
$query = $DB->query($sql);
$total = 0;
$j=0;
while($row = $DB->fetch_array($query)) {
$j++;
$result = $this -> getProductById($row['product_id']);
//Get images products
if ( substr($result["img_large"], 0, 7) != 'http://' )
{
$result["img_large"] = './images/products/'. $result["img_large"];
}
$images = 'set_block_vars("cartrow", array(
"ID" => $row["product_id"],
"j" => $j,
"item_id" => $result["products_code"],
"name" => $this->cut_string($result["title"],60,"..."),
"IMG" => $images,
"unitprice" => number_format($row["pro_price"],0,',','.'),
"Order_ID" => $this->random_item(4),
"quantity" => $row["product_quantity"],
"price" => number_format($subTotal,0,',','.'),
"U_CART" => $Func->compile_url(array('mod' => MOD_CART,'act'=>'update')),
));
}
$query2 = "SELECT * FROM ". $DB->prefix ."editprofile ";
$DB->query($query2);
$billing_info2 = $DB->fetch_array();
$tongtien= $billing_info2["tygia"] * $total;
$Template -> set_vars(array(
"VND" => number_format($tongtien,0,',','.'),
'total' => number_format($total,0,',','.'),
"U_EMPTY" => $Func->compile_url(array('mod' => MOD_CART,'act'=>'empty')),
"U_CHECKOUT" => $Func->compile_url(array('mod' => MOD_CART,'act'=>'checkout')),
));
}
function numItems()
{
global $DB;
$num_rows = $DB->count( $DB->prefix ."cart"," session='".$this->getSession()."' ");
return $num_rows;
}
function getQuantity()
{
global $DB;
$query = "SELECT sum(product_quantity) as quantity FROM ". $DB->prefix ."cart WHERE session='".$this->getSession()."' ";
$result = $DB->query($query);
$row = $DB->sql_get($result);
if($row)return $row['quantity'];
return 0;
}
function getProductById($id){
global $DB;
$DB->query("SELECT * FROM ". $DB->prefix ."article WHERE article_id='".$id."'");
$products_info = $DB->fetch_array();
$DB->free_result();
return $products_info;
}
function do_send_email(){
global $Func, $Info, $Template, $DB, $Lang;
$mail_subject = $Lang->data['payment_mail_subject'];
$mail_subject = str_replace('{PAYMENT_ID}',date('Y/m/d').'-'.$this->random_item(5), $mail_subject);
$mail_content = $Lang->data['payment_mail'];
$query = "SELECT * FROM ". $DB->prefix ."payment WHERE session='".$this->getSession()."' ORDER BY payment_id DESC";
$DB->query($query);
$billing_info = $DB->fetch_array();
$mail_content = str_replace('{B_FIRSTNAME}',$billing_info['billing_firstname'],$mail_content);
// $mail_content = str_replace('{B_LASTNAME}',$billing_info['billing_lastname'],$mail_content);
$mail_content = str_replace('{B_ADDRESS}',$billing_info['billing_add1'],$mail_content);
$mail_content = str_replace('{B_COUNTRY}',$billing_info['billing_country'],$mail_content);
$mail_content = str_replace('{B_YEUCAU}',$billing_info['billing_city'],$mail_content);
$mail_content = str_replace('{B_CITY}',$billing_info['billing_city'],$mail_content);
$mail_content = str_replace('{B_STATE}',$billing_info['biiling_state'],$mail_content);
// $mail_content = str_replace('{B_PROVINCE}',$billing_info['billing_province'],$mail_content);
$mail_content = str_replace('{B_POSTCODE}',$billing_info['billing_postcode'],$mail_content);
$mail_content = str_replace('{B_PHONE}',$billing_info['billing_phone'],$mail_content);
$mail_content = str_replace('{B_EMAIL}',$billing_info['billing_email'],$mail_content);
$mail_content = str_replace('{S_FIRSTNAME}',$billing_info['shipping_firstname'],$mail_content);
// $mail_content = str_replace('{S_LASTNAME}',$billing_info['shipping_lastname'],$mail_content);
$mail_content = str_replace('{S_ADDRESS}',$billing_info['shipping_add1'],$mail_content);
$mail_content = str_replace('{S_COUNTRY}',$billing_info['shipping_country'],$mail_content);
$mail_content = str_replace('{S_YEUCAU}',$billing_info['shipping_city'],$mail_content);
// $mail_content = str_replace('{S_STATE}',$billing_info['shipping_state'],$mail_content);
// $mail_content = str_replace('{S_PROVINCE}',$billing_info['shipping_province'],$mail_content);
$mail_content = str_replace('{S_POSTCODE}',$billing_info['shipping_postcode'],$mail_content);
$mail_content = str_replace('{S_PHONE}',$billing_info['shipping_phone'],$mail_content);
$mail_content = str_replace('{S_EMAIL}',$billing_info['shipping_email'],$mail_content);
$mail_content = str_replace('{SHIP_PRICE}',($billing_info['shipping_method']==1)?'0':'50,000 $',$mail_content);
$mail_content = str_replace('{SHIP_METHOD}',($billing_info['shipping_method']==1)?'Tiền mặt':'Chuyển khoản',$mail_content);
$query = "SELECT * FROM ". $DB->prefix ."payment WHERE (session='".$this->getSession()."') ORDER BY payment_id DESC";
$DB->query($query);
$billing_info = $DB->fetch_array();
$sql = "SELECT * FROM ". $DB->prefix ."cart WHERE (session='".$billing_info['session']."') ORDER BY cart_id DESC";
$query_cart = $DB->query($sql);
$total = 0;
$product_list = "";
while($row = $DB->fetch_array($query_cart)) {
$result = $this -> getProductById($row['product_id']);
//Get images products
$quantity = $row["product_quantity"];
$total += $result["product_price"]*$row["product_quantity"];
$product_list .= $result["title"].' $ '.number_format($result["product_price"],0,',','.').'x'.$row["product_quantity"].'=$ '.number_format($result["product_price"]*$row["product_quantity"],0,',','.')."
";
}
$mail_content = str_replace('{PRODUCT_LIST}',$product_list,$mail_content);
$mail_content = str_replace('{TOTAL}',number_format($total+(($billing_info['shipping_method']==1)?0:50000),0,',','.'),$mail_content);
// $Func->send_email($this->data['friend_email'], $mail_subject, $mail_content, $this->data['your_name'] ."<" . $this->data['your_email'] .">");
//SMTP -------------------------------
echo $mail_subject.$mail_content;
include('includes/smtp'. PHP_EX);
$SMTP = new SMTP($Info->option['smtp_host'], $Info->option['smtp_username'], $Info->option['smtp_password']);
$SMTP->email_from($Info->option['admin_email']);
$SMTP->email_to($Info->option['admin_email']);
$SMTP->email_cc($billing_info['billing_email']);
$SMTP->message_charset($Lang->charset);
$SMTP->message_subject($mail_subject);
$SMTP->message_subject("ID khach hang: ".stripslashes($billing_info['payment_id']));
$SMTP->message_content($mail_content);
$SMTP->message_content('
XÁC NHẬN ĐƠN HÀNG |
Kính gửi quý khách hàng! |
Hệ thống bán hàng http://dtrend.vn/ xin xác nhận đơn hàng của khách hàng: '.$billing_info['billing_firstname'].' mua hàng trên website: dtrend.vn đã được lưu vào hệ thống: |
|
Thông tin đơn hàng |
° Họ tên : '.$billing_info['billing_firstname'].' |
° Mã ID : '.$billing_info['payment_id'].' |
° Địa chỉ giao hàng : '.$billing_info['billing_add2'].' |
° Số ĐT : '.$billing_info['billing_phone'].' |
° Email : '.$billing_info['billing_email'].' |
° Ghi chú : '.$billing_info['billing_city'].' |
|
Danh sách mua hàng |
Mã ID |
Sản phẩm |
Số lượng |
Giá |
Thành tiền |
'.$billing_info['payment_id'].' |
'.$result['title'].' |
'. $quantity.' |
'.number_format($result['product_price'],0,',','.').' VNĐ |
'.number_format($total,0,',','.').' VNĐ |
|
|
|
|
|
|
Phương thức thanh toán |
'.$thanhtoan.' |
|
Quý khách vui lòng thanh toán tiền hàng để chúng tôi chuyển hàng cho quý khách.
Cảm ơn quý khách đã tin tưởng sử dụng dịch vụ bán hàng của D-TREND.Chúng tôi luôn mong muốn mang lại những dịch vụ tốt nhất cho bạn. Xin vui lòng không xóa email xác nhận này! |
|
');
$SMTP->send();
$SMTP->reset_email();
//------------------------------------
return true;
}
function random_item($length){
$haystack = '0123456789';
$needle ="";
while(strlen($needle) < $length) {
$needle .= substr($haystack,rand(0,strlen($haystack)),1);
}
return($needle);
}
}
?>
Template Error:
./templates/tranthanh/clsCart.tpl does not exist