簡體   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