MINI Sh3ll
<?
$formtype = isset($_REQUEST['formtype']) ? $_REQUEST['formtype'] : '';
if($formtype != '')
{
switch($formtype)
{
case "rate-product":
$rating = $_REQUEST;
$rating['user_id'] = $loginUser['id'];
$objProduct->addUserRating($rating);
$_SESSION['notify_success'] = "Product rating is recorded successfully.";
header("Location:".SITE_ROOT_URL."products/");
die;
break;
case "add-to-cart":
$product = $_REQUEST;
$strcart = isset($_SESSION['cart']) ? $_SESSION['cart'] : "";
$cart = $strcart != "" ? json_decode($strcart, true) : [];
// $cart[] = ["code" => $product['code'], "quantity" => $product['quantity']];
$cart[$product['code']] = ($cart[$product['code']] > 0 ? $cart[$product['code']] : 0) + $product['quantity'];
$strcart = json_encode($cart);
$_SESSION['cart'] = $strcart;
if($product['prating'] != ''){
$rating = [];
$rating['code'] = $product['code'];
$rating['rating'] = $product['prating'];
$rating['user_id'] = $loginUser['id'];
$objProduct->addUserRating($rating);
}
$_SESSION['notify_success'] = "Product is added to your cart successfully.";
header("Location:".SITE_ROOT_URL."products/");
die;
break;
case "remove-from-cart":
//x($_REQUEST);
$strcart = isset($_SESSION['cart']) ? $_SESSION['cart'] : "";
$cart = $strcart != "" ? json_decode($strcart, true) : [];
unset($cart[$_REQUEST['code']]);
$strcart = json_encode($cart);
$_SESSION['cart'] = $strcart;
$_SESSION['notify_success'] = "Product is removed from your cart.";
header("Location:".SITE_ROOT_URL."products/");
die;
break;
case "place-order":
$cdata = $_REQUEST['quantity'];
$codes = array_keys($cdata);
$order = [];
$order['order_id'] = uniqid().rand(1000, 9999);
$order['user_id'] = $loginUser['id'];
$order['total_amount'] = 0;
$order['order_items'] = json_encode($cdata);
$products = $objProduct->getUserProducts($loginUser['id'], "");
foreach($products as $p){
if(in_array($p['code'], $codes)){
$oitem = [];
$oitem['user_id'] = $loginUser['id'];
$oitem['order_id'] = $order['order_id'];
$oitem['product_code'] = $p['code'];
$oitem['cost'] = $p['cost'];
$oitem['quantity'] = $cdata[$p['code']];
$oitem['amount'] = $oitem['quantity'] * $p['cost'];
if($oitem['quantity'] > 0)
$oitem['id'] = $objOrder->addOrderItem($oitem);
if($oitem['id'] > 0){
$order['total_amount'] += $oitem['amount'];
}
}
}
if($order['total_amount'] > 0){
$order['id'] = $objOrder->addUserOrder($order);
if($order['id'] > 0){
unset($_SESSION['cart']);
$_SESSION['notify_success'] = "Your order is placed successfully.";
}
else {
$_SESSION['notify_error'] = "Unable to place your order. Please contact admin!";
}
}
else {
$_SESSION['notify_error'] = "Unable to place your order. Please contact admin!";
}
header("Location:".SITE_ROOT_URL."products/");
die;
break;
}
}
?>
OHA YOOOO