2 回答
TA贡献1843条经验 获得超7个赞
您的问题不是大问题。您可能只想if在代码中添加一个正确的代码,以便对++您可能得到的那个新项目执行操作。
我不太确定您的某些变量。但是,我的猜测是,您可能只需要在if之前添加一个array_push,也许类似于以下内容:
if ((int) $newproduct['id'] == (int) $value["id"]) {
$_SESSION['shopping_cart'][$key]['quantity'] = (int) $_SESSION['shopping_cart'][$key]['quantity'] + 1;
}
如果您添加一个正确的if,而不是将s++加到所有$values上,您的问题将得到解决。这也可能起作用:
if ((int) $newproduct['id'] == (int) $value["id"]) {
$_SESSION['shopping_cart'][$key]['quantity'] = (int) $value['quantity'] + 1;
}
$_SESSION['shopping_cart'] = array
(
"0" => array
(
"id" => "2",
"title" => "Vewlix 1080p (red and white)",
"image" => "amazing-modern-villa-Freshome-02.jpg",
"variants" => array
(
"0" => array
(
"option_id" => "1",
"option_name" => "Panel 1 player",
"option_price" => "0.00",
),
),
"quantity" => "1",
"unit_price" => "1950.00",
"price" => "1950",
),
"1" => array
(
"id" => "2",
"title" => "Vewlix 1080p (red and white)",
"image" => "amazing-modern-villa-Freshome-02.jpg",
"variants" => array
(
"0" => array
(
"option_id" => "1",
"option_name" => "Panel 2 players (+50 euros)",
"option_price" => "50.00",
),
),
"quantity" => "1",
"unit_price" => "1950.00",
"price" => "2000",
),
);
foreach ($_SESSION['shopping_cart'] as $key => $value) {
if (in_array($newproduct['id'], $shopping_ids) && empty($variants_diff)) {
if ((int) $newproduct['id'] == (int) $value["id"]) {
$_SESSION['shopping_cart'][$key]['quantity'] = (int) $_SESSION['shopping_cart'][$key]['quantity'] + 1;
}
} else {
array_push($_SESSION['shopping_cart'], $newproduct);
}
}
- 2 回答
- 0 关注
- 175 浏览
添加回答
举报