【发布时间】:2020-06-06 16:30:51
【问题描述】:
我在 laravel 中创建了一个购物车页面,现在我想在 laravel 中添加折扣代码部分,以便每个折扣代码减去购物车页面中每个产品的价格。
我的任何产品的购物车会话保存在这样的会话中:
// product with id 1
"cart_1" => [
"id" => "1"
"product" => "accounting"
"quantity" => 5
"price" => 50000
"attr" => [
// product options that some user choose this
"torfehnegar_evidence" => "true"
]
]
// product with id 3
"cart_3" => [
"id" => "3"
"product" => "programming"
"quantity" => 2
"price" => 600
"attr" => [
// product options that some user choose this
]
]
现在,当用户插入价格为 500 的折扣代码时,我希望这个数组像这样更改
// product with id 1
"cart_1" => [
"id" => "1"
"product" => "accounting"
"quantity" => 5
"price" => 49500 // the main price minus from discount price
"attr" => [
// product options
"torfehnegar_evidence" => "true"
]
]
// product with id 3
"cart_3" => [
"id" => "3"
"product" => "programming"
"quantity" => 2
"price" => 100 // the main price minus from discount price
"attr" => [
// product options
]
]
此更改必须替换 laravel 中的同一会话
【问题讨论】:
-
到目前为止,您为实现目标做了哪些尝试?