Пример #1
0
 public function __construct()
 {
     $category = new Category();
     $categories = $category->all();
     $cart = new Cart(new SessionStorage('starwars'));
     $this->cart = $cart;
     composite('partials.menu', 'menu', compact('categories'));
     composite('partials.header_cart', 'cart', compact('cart'));
 }
 public function showCart()
 {
     $storage = $this->cart->all();
     $products = [];
     $category = new Category();
     $categories = $category->all();
     foreach ($storage as $id => $total) {
         $p = new Product();
         // product du Model pas du Cart
         $stmt = $p->find($id);
         $products[$stmt->title]['price'] = (double) $stmt->price;
         $products[$stmt->title]['total'] = $total;
         $products[$stmt->title]['quantity'] = $total / $stmt->price;
         $products[$stmt->title]['product_id'] = $id;
     }
     $image = new Image();
     view('front.cart', compact('products', 'image', 'categories'));
 }