1
|
|
|
<?php |
2
|
|
|
namespace Mongi\Mongicommerce\Http\Controllers\shop; |
3
|
|
|
|
4
|
|
|
use Illuminate\Support\Facades\Auth; |
5
|
|
|
use Mongi\Mongicommerce\Http\Controllers\Controller; |
6
|
|
|
use Mongi\Mongicommerce\Models\Cart; |
7
|
|
|
use Mongi\Mongicommerce\Models\ProductItem; |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
class ShopSummaryController extends Controller |
11
|
|
|
{ |
12
|
|
|
public function page(){ |
13
|
|
|
$products = []; |
14
|
|
|
$note = session('checkout.note_delivery'); |
15
|
|
|
$get_in_shop_checkbox = session('checkout.get_in_shop_checkbox'); |
16
|
|
|
$total = 0; |
17
|
|
|
if (!Auth::check()) { |
18
|
|
|
$ids = []; |
19
|
|
|
$productsCart = session('cart'); |
20
|
|
|
if(isset($productsCart)){ |
21
|
|
|
foreach ($productsCart as $id => $count) { |
22
|
|
|
$product = ProductItem::where('id', $id)->first(); |
23
|
|
|
$ids[] = $id; |
24
|
|
|
$products[] = [ |
25
|
|
|
'detail' => $product, |
26
|
|
|
'single_price' => $product->price, |
27
|
|
|
'count' => $count, |
28
|
|
|
'single_weight' => $product->weight, |
|
|
|
|
29
|
|
|
'sum_weight' => $product->weight * $count, |
30
|
|
|
'total' => $product->price * $count |
31
|
|
|
]; |
32
|
|
|
$total += $product->price * $count; |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
} else { |
36
|
|
|
$productsCart = Cart::where('user_id', Auth::user()->id)->get(); |
|
|
|
|
37
|
|
|
foreach ($productsCart as $element) { |
38
|
|
|
$product = ProductItem::where('id', $element->product_item_id)->first(); |
39
|
|
|
|
40
|
|
|
$products[] = [ |
41
|
|
|
'detail' => $product, |
42
|
|
|
'single_price' => floatval($product->price), |
43
|
|
|
'count' => $element->quantity, |
44
|
|
|
'single_weight' => $product->weight, |
45
|
|
|
'sum_weight' => $element->quantity * $product->weight, |
46
|
|
|
'total' => $product->price * $element->quantity |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
$total += $product->price * $element->quantity; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
$shipping_price = 0; |
53
|
|
|
session()->put('checkout.total', $total + $shipping_price); |
54
|
|
|
return view('mongicommerce.pages.summary',compact('products','total','shipping_price','note','get_in_shop_checkbox')); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.