繁体   English   中英

无法在php opencart中为多维数组设置会话

[英]unable to set session for multidimensional array in php opencart

我有以下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

尝试为

$this->session->data['cart'][$bean_sku.$key] = (int)$qty;

尝试

$this->session->data['cart'][$bean_sku][$key]

代替

$this->session->data['cart'][[$bean_sku][$key]]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM