1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
<?php
require_once "DBController.php";
class ShoppingCart extends DBController
{
function getAllProduct()
{
$query = "SELECT * FROM tbl_product";
$productResult = $this->getDBResult($query);
return $productResult;
}
function getMemberCartItem($member_id)
{
$query = "SELECT tbl_product.*, tbl_cart.id as cart_id,tbl_cart.quantity FROM tbl_product, tbl_cart WHERE
tbl_product.id = tbl_cart.product_id AND tbl_cart.member_id = ?";
$params = array(
array(
"param_type" => "i",
"param_value" => $member_id
)
);
$cartResult = $this->getDBResult($query, $params);
return $cartResult;
}
function getProductByCode($product_code)
{
$query = "SELECT * FROM tbl_product WHERE code=?";
$params = array(
array(
"param_type" => "s",
"param_value" => $product_code
)
);
$productResult = $this->getDBResult($query, $params);
return $productResult;
}
function getCartItemByProduct($product_id, $member_id)
{
$query = "SELECT * FROM tbl_cart WHERE product_id = ? AND member_id = ?";
$params = array(
array(
"param_type" => "i",
"param_value" => $product_id
),
array(
"param_type" => "i",
"param_value" => $member_id
)
);
$cartResult = $this->getDBResult($query, $params);
return $cartResult;
}
function addToCart($product_id, $quantity, $member_id)
{
$query = "INSERT INTO tbl_cart (product_id,quantity,member_id) VALUES (?, ?, ?)";
$params = array(
array(
"param_type" => "i",
"param_value" => $product_id
),
array(
"param_type" => "i",
"param_value" => $quantity
),
array(
"param_type" => "i",
"param_value" => $member_id
)
);
$this->updateDB($query, $params);
}
function updateCartQuantity($quantity, $cart_id)
{
$query = "UPDATE tbl_cart SET quantity = ? WHERE id= ?";
$params = array(
array(
"param_type" => "i",
"param_value" => $quantity
),
array(
"param_type" => "i",
"param_value" => $cart_id
)
);
$this->updateDB($query, $params);
}
function deleteCartItem($cart_id)
{
$query = "DELETE FROM tbl_cart WHERE id = ?";
$params = array(
array(
"param_type" => "i",
"param_value" => $cart_id
)
);
$this->updateDB($query, $params);
}
function emptyCart($member_id)
{
$query = "DELETE FROM tbl_cart WHERE member_id = ?";
$params = array(
array(
"param_type" => "i",
"param_value" => $member_id
)
);
$this->updateDB($query, $params);
}
} |
Partager