private function getTotalByCart($cartId) { $cartItems = CartItem::where('cart_id', $cartId)->get(); $total = 0; foreach ($cartItems as $item) { $unitPrice = $item['unit_price']; $quantity = $item['quantity']; $productDiscount = $item['discount_percentage'] / 100; $senior = $item['senior_citizen']; if ($productDiscount) { $discountAmount = $total * $productDiscount; $total += $total - $discountAmount; } else { if ($senior) { $discountAmount = $total * $productDiscount; $vat = $unitPrice / 1.12 * 0.12; $unitPrice = $unitPrice - $vat; $tmpTotal = $unitPrice * $quantity; $total += $tmpTotal - $discountAmount; } else { $total += $unitPrice * $quantity; } } } return $total; }
public function removeItemFromCart($cartId, $productId) { \Log::info("Deleting cartId " . $cartId . " with product " . $productId); $item = CartItem::where('cart_id', $cartId)->where('product_id', $productId)->forceDelete(); return $this->responseOk($item); }
public function completeOrder($cartItemId) { $item = CartItem::where('id', $cartItemId)->update(['status' => 'completed']); $items = CartItem::with('product', 'cart.table')->where('status', 'pending')->get(); return $this->responseOk($this->parseItems($items->toArray())); }