-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaddToCart.php
46 lines (36 loc) · 1.36 KB
/
addToCart.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
pacakge name: bumbummen99/shoppingcart
use Gloudemans\Shoppingcart\Facades\Cart;
public function AddToCart(Request $request, $id)
{
$product = Product::findOrFail($id);
$product_name = $product->product_name_en;
if ($product->discount_price == NULL) {
Cart::add([
'id' => $id,
'name' => $product_name,
'qty' => $request->quantity,
'price' => $product->selling_price,
'weight' => 1,
'options' => [
'size' => $product->size,
'color' => $product->color,
'image' => $product->product_thumbnail,
]
]);
return response()->json(['success' => 'Product added to cart successfully!']);
} else {
Cart::add([
'id' => $id,
'name' => $product_name,
'qty' => $request->quantity,
'price' => $product->discount_price,
'weight' => 1,
'options' => [
'size' => $product->size,
'color' => $product->color,
'image' => $product->product_thumbnail,
]
]);
return response()->json(['success' => 'Product added to cart successfully!']);
}
}