0
我有一個購物車,它工作得很好,但我想存儲商品類型(例如顏色,大小等)。將另一個維度添加到陣列購物車
這裏是指添加項目到購物車
public static function addToCart($data) {
$id = $data['id'];
$quantity = $data['qty'];
$varianta = $data['varianty']; //THIS IS WHAT I NEED TO ADD TO SESSION ARRAY
if(!isset($_SESSION['cart'])) {
$_SESSION['cart'] = array();
}
if(isset($_SESSION['cart'][$id])) {
$_SESSION['cart'][$id] += $quantity;
} else {
$_SESSION['cart'][$id] = $quantity;
}
}
有一些簡單的方法來做到這一點的函數從購物
public static function getCart() {
if((isset($_SESSION['cart'])) && count($_SESSION['cart'])>0) {
$ids = "";
foreach($_SESSION['cart'] as $id => $quantity) {
$ids = $ids . $id . ",";
}
$ids = rtrim($ids, ',');
$dotaz = dibi::fetchAll("SELECT * FROM eshop_products WHERE idProduct IN ({$ids})");
return $dotaz;
} else {
//do nothing
}
}
得到項目和功能?我搜索了一些教程,但仍然沒有成功。
謝謝。
我不明白。你有什麼問題?只需要像'cart'一樣保存'varianty'值? –