{{-- Note: This page (view) is rendered by the checkout() method in the Front/ProductsController.php --}} @extends('front.layout.layout') @section('content')

Checkout

{{-- Showing the following HTML Form Validation Errors: (check checkout() method in Front/ProductsController.php) --}} {{-- Determining If An Item Exists In The Session (using has() method): https://laravel.com/docs/9.x/session#determining-if-an-item-exists-in-the-session --}} @if (Session::has('error_message')) @endif
{{-- We created this id="deliveryAddresses" to use it as a handle for jQuery AJAX to refresh this page, check front/js/custom.js --}} @include('front.products.delivery_addresses')
{{-- The complete HTML Form of the user submitting their Delivery Address and Payment Method --}}
@csrf {{-- Preventing CSRF Requests: https://laravel.com/docs/9.x/csrf#preventing-csrf-requests --}} @if (count($deliveryAddresses) > 0) {{-- Checking if there are any $deliveryAddreses for the currently authenticated/logged-in user --}} {{-- $deliveryAddresses variable is passed in from checkout() method in Front/ProductsController.php --}}

Delivery Addresses

@foreach ($deliveryAddresses as $address)
{{-- We'll use the Custom HTML data attributes: shipping_charges , total_price , coupon_amount , codpincodeCount and prepaidpincodeCount to use them as handles for jQuery to change the calculations in "Your Order" section using jQuery. Check front/js/custom.js file --}} {{-- $total_price variable is passed in from checkout() method in Front/ProductsController.php --}} {{-- We created the Custom HTML Attribute id="address{{ $address['id'] }}" to get the UNIQUE ids of the addresses in order for the
@endforeach
@endif

Your Order

{{-- We'll place this $total_price inside the foreach loop to calculate the total price of all products in Cart. Check the end of the next foreach loop before @endforeach --}} @php $total_price = 0 @endphp @foreach ($getCartItems as $item) {{-- $getCartItems is passed in from cart() method in Front/ProductsController.php --}} @php $getDiscountAttributePrice = \App\Models\Product::getDiscountAttributePrice($item['product_id'], $item['size']); // from the `products_attributes` table, not the `products` table // dd($getDiscountAttributePrice); @endphp {{-- This is placed here INSIDE the foreach loop to calculate the total price of all products in Cart --}} @php $total_price = $total_price + ($getDiscountAttributePrice['final_price'] * $item['quantity']) @endphp @endforeach
Product Total
Product
{{ $item['product']['product_name'] }}
{{ $item['size'] }}/{{ $item['product']['product_color'] }}
x {{ $item['quantity'] }}
EGP{{ $getDiscountAttributePrice['final_price'] * $item['quantity'] }}
{{-- price of all products (after discount (if any)) (= price (after discoutn) * no. of products) --}}

Subtotal

EGP{{ $total_price }}

Shipping Charges
EGP0
Coupon Discount
@if (\Illuminate\Support\Facades\Session::has('couponAmount')) {{-- We stored the 'couponAmount' in a Session Variable inside the applyCoupon() method in Front/ProductsController.php --}} EGP{{ \Illuminate\Support\Facades\Session::get('couponAmount') }} @else EGP0 @endif

Grand Total

EGP{{ $total_price - \Illuminate\Support\Facades\Session::get('couponAmount') }} {{-- We create the 'grand_total' CSS class to use it as a handle for AJAX inside $('#applyCoupon').submit(); function in front/js/custom.js --}} {{-- We stored the 'couponAmount' a Session Variable inside the applyCoupon() method in Front/ProductsController.php --}}

{{-- We added the codMethod CSS class to disable that payment method (check front/js/custom.js) if the PIN code of that user's Delivery Address doesn't exist in our `cod_pincodes` database table --}}
{{-- We added the prepaidMethod CSS class to disable that payment method (check front/js/custom.js) if the PIN code of that user's Delivery Address doesn't exist in our `prepaid_pincodes` database table --}}
{{-- iyzico Payment Gateway integration in/with Laravel --}}
{{-- We added the prepaidMethod CSS class to disable that payment method (check front/js/custom.js) if the PIN code of that user's Delivery Address doesn't exist in our `prepaid_pincodes` database table --}}
{{-- Show our Preloader/Loader/Loading Page/Preloading Screen while the is submitted using the id="placeOrder" HTML attribute. Check front/js/custom.js --}}
@endsection