Example #1
0
 /**
  * Gets the products within the cart and the total price
  * @return array
  * @throws \Exception
  */
 public function getCartProducts()
 {
     if (isset($this->userSelectedProducts)) {
         return $this->userSelectedProducts;
     }
     $cartItems = $this->session->get('cart');
     $product_id_in_cart = $this->getProductIdsInCart();
     $products = $this->product->getCartProducts($product_id_in_cart);
     $userSelectedProducts = [];
     $grandTotal = 0.0;
     foreach ($products as $item) {
         foreach ($cartItems as $cartItem) {
             if ($cartItem['product_id'] == $item->product_id) {
                 $item->quantity = $cartItem['quantity'];
                 $userSelectedProducts[] = $item;
                 $item->total = $cartItem['quantity'] * $item->price;
                 $grandTotal += $item->total;
             }
         }
     }
     $this->grandTotal = $grandTotal;
     $this->userSelectedProducts = $userSelectedProducts;
     return $userSelectedProducts;
 }