1
|
|
|
<?php |
2
|
|
|
namespace Mongi\Mongicommerce\Http\Controllers\shop; |
3
|
|
|
|
4
|
|
|
use Illuminate\Http\Request; |
5
|
|
|
use Illuminate\Support\Facades\Auth; |
6
|
|
|
use Mongi\Mongicommerce\Http\Controllers\Controller; |
7
|
|
|
use Mongi\Mongicommerce\Models\Cart; |
8
|
|
|
use Mongi\Mongicommerce\Models\ProductItem; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class ShopSummaryController extends Controller |
12
|
|
|
{ |
13
|
|
|
public function page(){ |
14
|
|
|
$products = []; |
15
|
|
|
$note = session('checkout.note_delivery'); |
16
|
|
|
$get_in_shop_checkbox = session('checkout.get_in_shop_checkbox'); |
17
|
|
|
$total = 0; |
18
|
|
|
if (!Auth::check()) { |
19
|
|
|
$ids = []; |
20
|
|
|
$productsCart = session('cart'); |
21
|
|
|
if(isset($productsCart)){ |
22
|
|
|
foreach ($productsCart as $id => $count) { |
23
|
|
|
$product = ProductItem::where('id', $id)->first(); |
24
|
|
|
$ids[] = $id; |
25
|
|
|
$products[] = [ |
26
|
|
|
'detail' => $product, |
27
|
|
|
'single_price' => $product->price, |
28
|
|
|
'count' => $count, |
29
|
|
|
'single_weight' => $product->weight, |
|
|
|
|
30
|
|
|
'sum_weight' => $product->weight * $count, |
31
|
|
|
'total' => $product->price * $count |
32
|
|
|
]; |
33
|
|
|
$total += $product->price * $count; |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
} else { |
37
|
|
|
$productsCart = Cart::where('user_id', Auth::user()->id)->get(); |
|
|
|
|
38
|
|
|
foreach ($productsCart as $element) { |
39
|
|
|
$product = ProductItem::where('id', $element->product_id)->first(); |
|
|
|
|
40
|
|
|
$products[] = [ |
41
|
|
|
'detail' => $product, |
42
|
|
|
'single_price' => floatval($product->price), |
43
|
|
|
'count' => $element->quantity, |
44
|
|
|
'single_weight' => $product->weight, |
45
|
|
|
'sum_weight' => $element->count * $product->weight, |
|
|
|
|
46
|
|
|
'total' => $product->price * $element->count |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
$total += $product->price * $element->count; |
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.