-1

下面是添加到产品代码。但我没有得到值的存储位置。请帮助找出解决方案。我想知道这段代码背后的逻辑

public function add($product_id, $qty = 1, $option = array(), $recurring_id = 0) {
    $this->data = array();

    $product['product_id'] = (int)$product_id;

    if ($option) {
        $product['option'] = $option;
    }

    if ($recurring_id) {
        $product['recurring_id'] = (int)$recurring_id;
    }

    $key = base64_encode(serialize($product));

    if ((int)$qty && ((int)$qty > 0)) {
        if (!isset($this->session->data['cart'][$key])) {
            $this->session->data['cart'][$key] = (int)$qty;
        } else {
            $this->session->data['cart'][$key] += (int)$qty;
        }
    }
}
4

1 回答 1

1

带有选项的产品详细信息存储在$key = base64_encode(serialize($product));. 其中$this->session->data['cart'][$key]包含客户添加的数量。

有关更多详细信息,请检查getProducts()同一页面上的功能。在哪里可以找到

foreach ($this->session->data['cart'] as $key => $quantity) { 
  .... 
  $product = unserialize(base64_decode($key));
  ....
}
于 2015-12-28T12:41:53.220 回答