| Server IP : 103.48.194.25 / Your IP : 216.73.216.74 Web Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.33 System : Linux VMHostDefault 3.10.0-1160.42.2.el7.x86_64 #1 SMP Tue Sep 7 14:49:57 UTC 2021 x86_64 User : sieuthimay ( 1016) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/hocthongminh.net-bk/public_html/site/components/sanpham/controllers/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Cart extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('cart_model','cart');
}
public function index()
{
$res['token'] = '';
$res['items'] = array();
$res['note'] = '';
$res['free_shipping'] = false;
$res['total_price'] = 0;
$res['total_weight'] = 0;
$res['item_count'] = 0;
$res['requires_shipping'] = false;
$res['sub_total_price'] = 0;
$res['total_line_item_price'] = 0;
$res['discount'] = 0;
$res['shipping_fee'] = 0;
$res['attributes'] = array();
$res['referring_site'] = "https://za.zalo.me/v3/verifyv2/pc?token=OMxnnTHyLmfW1_F9sHPVRMK0-RZQ4K9mPnlckJW\u0026continue=https//huynhgiatradng.com";
$res['reference'] = '';
$res['landing_site'] = '';
$res['landing_site_ref'] = '';
echo json_encode($res);
}
function add()
{
$str = $this->_get_form();
echo json_encode($str);
}
function _get_form()
{
$ses_cart = get_ses_cart() ;
$proid = (int) $this->input->post('proid');
$quantity = (int) $this->input->post('quantity');
if(empty($proid)) return ;
$rs = $this->cart->get_product_detail($proid);
$item = map_product($rs);
$item->shipping_status = '';
$products = !empty($ses_cart['items']) ? $ses_cart['items'] : array();
if(!empty($products)):
for($i=0;$i<count($products);$i++):
if($products[$i]->id == $item->id):
$products[$i]->quantity = $products[$i]->quantity + $quantity;
$ses_cart['total_price'] = $ses_cart['total_price'] + ($item->price * $quantity);
$ses_cart['item_count'] = $ses_cart['item_count'] + $quantity;
$ses_cart['total_weight'] = $ses_cart['total_weight'] + ($item->weight * $quantity);
else:
$item->quantity = $quantity;
$ses_cart['total_price'] = $ses_cart['total_price'] + ($item->price * $quantity);
$ses_cart['item_count'] = $ses_cart['item_count'] + $quantity;
$ses_cart['total_weight'] = $ses_cart['total_weight'] + ($item->weight * $quantity);
array_push($products,$item);
endif;
break;
endfor;
else:
$item->quantity = $quantity;
$ses_cart['total_price'] = $ses_cart['total_price'] + ($item->price * $quantity);
$ses_cart['item_count'] = $ses_cart['item_count'] + $quantity;
$ses_cart['total_weight'] = $ses_cart['total_weight'] + ($item->weight * $quantity);
array_push($products,$item);
endif;
$ses_cart['items'] = $products;
$ses_cart['subtotal_price'] = 0;
$ses_cart['shipping_fee'] = $ses_cart['shipping_fee'];
$ses_cart['free_shipping'] = false;
$ses_cart['requires_shipping'] = false;
$ses_cart['attributes'] = array();
$ses_cart['token'] = "";
$ses_cart['note'] = "";
$ses_cart['discount'] = 0;
$_SESSION['cart'] = $ses_cart;
//return a product current
$pro = $this->map_product($rs);
return $pro;
}
function map_product($rs)
{
$obj = new stdClass();
$obj->id = $rs->proid;
$obj->product_id = $rs->proid;
$obj->title = $rs->pro_name;
$obj->url = site."san-pham/".alias($rs->pro_name).'-'.$rs->proid.'.html';
$obj->image = urlimg."products/800/".$rs->proimg;
$obj->price = $rs->price;
$obj->variant_id = $rs->proid;
$obj->name = $rs->pro_name;
return $obj;
}
/**
* Ver : 1.0
* Date : 01-01-2020
* Desc : Lấy thông tin giỏ hàng hiện tại từ session hoặc data hoặc cache file
* Params :
*/
function get()
{
$ses_cart = get_ses_cart();
echo json_encode($ses_cart);
}
/**
* Ver : 1.0
* Date : 01-01-2020
* Desc : Xóa sản phẩm trong giỏ hàng
* Params :
*/
function remove($proid=0)
{
$proid = $this->input->post('proid');
$quantity = $this->input->post('quantity');
$new_cart = array();
$ses_cart = get_ses_cart();
$ses_cart_items = $ses_cart['items'];
foreach($ses_cart_items as $cart):
if($cart->id == $proid)
{
$ses_cart['total_price'] = $ses_cart['total_price'] - ($cart->price * $cart->quantity);
$ses_cart['item_count'] = $ses_cart['item_count'] - $cart->quantity;
$ses_cart['total_weight'] = $ses_cart['total_weight'] - ($cart->weight * $cart->weight);
continue;
}
array_push($new_cart,$cart);
endforeach ;
$ses_cart['items'] = $new_cart;
$_SESSION['cart'] = $ses_cart;
echo json_encode($ses_cart);
}
/*function _get_form()
{
$str = '{
"token": "a29bea908e686022f93609357b845edc",
"items": [
{
"id": 2,
"shipping_status": null,
"wait_to_ship_quantity": 0,
"grams": 0,
"price": 15990000.0000,
"line_price": 15990000.0000,
"price_old": 0,
"line_price_orginal": 0,
"line_price_original": 0,
"product_id": 13870660,
"quantity": 1,
"requires_shipping": true,
"sku": null,
"title": "Samsung Galaxy S10e",
"variant_id": 23363788,
"variant_title": "\u0110en",
"vendor": "Samsung",
"name": "Samsung Galaxy S10e - \u0110en",
"gift_card": false,
"total_discount": 0,
"shipping_service": null,
"product_exist": true,
"image": "'.skin.'temp/636863622278818137-ss-galaxy-s10e-den-1.png",
"url": "/samsung-galaxy-s10e",
"properties": {
"Khuy\u1EBFn m\u00E3i": "Phi\u1EBFu mua h\u00E0ng Samsung 4 tri\u1EC7u. \r\n Tr\u1EA3 g\u00F3p l\u00E3i su\u1EA5t 0% qua c\u00F4ng ty t\u00E0i ch\u00EDnh v\u00E0 th\u1EBB t\u00EDn d\u1EE5ng. \r\n B\u1EA3o hi\u1EC3m r\u01A1i v\u1EE1 1 n\u0103m. \r\n \u01AFu \u0111\u00E3i ph\u00F2ng ch\u1EDD h\u1EA1ng th\u01B0\u01A1ng gia."
},
"promotion_ref": null,
"promotion_by": [
]
}
],
"note": "",
"free_shipping": false,
"total_price": 15990000.0000,
"total_weight": 0,
"item_count": 1,
"requires_shipping": false,
"sub_total_price": 0,
"total_line_item_price": 0,
"discount": 0,
"shipping_fee": 0,
"attributes": [
],
"referring_site": "",
"reference": null,
"landing_site": "/",
"landing_site_ref": null
}';
return $str;
}*/
//cap nhat so luong sản phẩm sẽ mua
function change()
{
$proid = $this->input->post('proid');
$quantity = $this->input->post('quantity');
$ses_cart = get_ses_cart();
$products = $ses_cart['items'];
if(!empty($products)):
for($i=0;$i<count($products);$i++):
if($products[$i]->id == $proid):
if($products[$i]->quantity > $quantity){
$a = $products[$i]->quantity - $quantity;
$products[$i]->quantity = $quantity;
$ses_cart['item_count'] = $ses_cart['item_count'] - $a;
$ses_cart['total_price'] = $ses_cart['total_price'] - ($products[$i]->price * $a);
$ses_cart['total_weight'] = $ses_cart['total_weight'] - ($products[$i]->weight * $a);
}
else
{
$a = $quantity - $products[$i]->quantity;
$products[$i]->quantity = $quantity;
$ses_cart['item_count'] = $ses_cart['item_count'] + $a;
$ses_cart['total_price'] = $ses_cart['total_price'] + ($products[$i]->price * $a);
$ses_cart['total_weight'] = $ses_cart['total_weight'] + ($products[$i]->weight * $a);
}
break;
endif;
endfor;
endif;
$_SESSION['cart'] = $ses_cart;
echo json_encode($ses_cart);
}
}
?>