laravel - 如何在 darryldecode/laravelshoppingcart 中添加自定义(不同尺寸)产品?
问题描述
我正在为我的购物车使用darryldecode/laravelshoppingcart,我有一些尺寸不同的产品(可订购的高度和宽度),价格会随着尺寸的变化而变化,但是当我尝试从购物车中的产品中添加两种不同尺寸时,数量增加,但我需要创建一个具有新尺寸的新产品行(例如 3×4 日光壁纸和 2×3 日光壁纸{在我的购物车中:是我添加的最后一个尺寸的 2 日光壁纸它})。另外,有正常的产品
public function Add($id){
$product = Product::find($id);
$id = $product->id;
$name = $product->barcode;
$order = $product->orderable;
$price = $product->price;
$image = $product->FImage;
$code = $product->barcode;
if (Auth::check()){
$userId = Auth::id();
Cart::session($userId)->add(array(
array(
'id' => $id,
'name' => $name,
'price' => $price,
'quantity' => 1,
'attributes' => array(
'image' => $image,
'width' => null,
'height' => null,
'code' => $code
)
),
));
}else{
Cart::add(array(
array(
'id' => $id,
'name' => $name,
'price' => $price,
'quantity' => 1,
'attributes' => array(
'image' => $image,
'width' => null,
'height' => null,
'code' => $code
)
),
));
}
return redirect()->route('Cart');
}
public function AddOrderable(Request $request,$id){
$p = Product::find($id);
$id = $p->id;
$name = $p->barcode;
$priceperunit = $p->priceperunit;
$width = $request->width;
$height = $request->height;
$count = $request->count;
$side = $request->side;
$mounting = $request->mounting;
$baseprice = 50;
if ($width >= 1 && $height >=1) {
if ($mounting == 'wall') {
$price = (($width * $height * $count) * $priceperunit) + ($count *$baseprice);
}else{
$price = (($width * $height * $count) * $priceperunit);
}
}elseif ($width>= 1 && $height<1) {
if ($mounting == 'wall') {
$price = (($width * $count)*$priceperunit) + ($count *$baseprice);
}else{
$price = (($width * $count)*$priceperunit);
}
}elseif ($width< 1 && $height>=1) {
if ($mounting == 'wall') {
$price = (($height * $count)*$priceperunit) + ($count *$baseprice);
}else{
$price = (($height * $count)*$priceperunit);
}
}elseif ($width < 1 && $height<1) {
if ($mounting == 'wall') {
$price = ($count*$priceperunit) + ($count *$baseprice);
}else{
$price = ($count*$priceperunit);
}
}
$image = $p->FImage;
$code = $p->barcode;
if (Auth::check()){
$userId = Auth::id();
Cart::session($userId)->add(array(
array(
'id' => $id,
'name' => $name,
'price' => $price,
'quantity' => $count,
'attributes' => array(
'order' => true,
'image' => $image,
'width' => $width,
'height' => $height,
'side' => $side,
'mounting' =>$mounting,
'code' => $code
)
),
));
}
}
解决方案
推荐阅读
- kotlin - Kotlin 错误:我是 Kotlin 编程的初学者并提出了这个错误
- html - 如何以适当的间距从网站中提取描述部分?
- php - 如何使用 PDO 准备语句/位置占位符来运行此 PHP 注册脚本?
- java - 无法将 CSS 类添加到我的 JavaFX 标签
- spring - 在我的 spring mvc 项目中添加 requestmapping 注释
- python - Altair - 在 x = y 的绘图中画一条线
- python - 从 python 脚本执行命令行程序(Abaqus-python 脚本)
- r - 使用 R 中的 ggplot2 按顺序循环打印大量图形 (PDF)
- entity-framework - System.TypeInitializationException 发生
- sqlite - 连接多个表 Sqlite Flutter