我有以下opencart函数在会话中添加产品
将此视为我的$bean_sku
和$product_id
$bean_id = 'werwer-23423s-sd-01';
$product_id = 120;
public function add($product_id, $bean_sku, $qty = 1, $option = array()) {
if (!$option) {
$key = (int)$product_id;
} else {
$key = (int)$product_id . ':' . base64_encode(serialize($option));
}
if ((int)$qty && ((int)$qty > 0)) {
if (!isset($this->session->data['cart'][[$bean_sku][$key]])) { echo 'not set';
$this->session->data['cart'][[$bean_sku][$key]] = (int)$qty;
} else { echo 'session set';
$this->session->data['cart'][[$bean_sku][$key]] += (int)$qty;
}
}
echo $this->session->cart;
exit;
$this->data = array();
}
在上面的函数中我添加了$bean_sku
但是我无法设置会话。每次我跑步not set
。
答案 0 :(得分:0)
尝试
$this->session->data['cart'][$bean_sku.$key] = (int)$qty;
答案 1 :(得分:0)
尝试
$this->session->data['cart'][$bean_sku][$key]
而不是
$this->session->data['cart'][[$bean_sku][$key]]