checkout.blade.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. @extends('layouts.front.app')
  2. @section('content')
  3. <div class="container product-in-cart-list">
  4. @if(!$products->isEmpty())
  5. <div class="row">
  6. <div class="col-md-12">
  7. <ol class="breadcrumb">
  8. <li><a href="{{ route('home') }}"> <i class="fa fa-home"></i> Home</a></li>
  9. <li class="active">Shopping Cart</li>
  10. </ol>
  11. </div>
  12. <div class="col-md-12 content">
  13. <div class="box-body">
  14. @include('layouts.errors-and-messages')
  15. </div>
  16. @if(count($addresses) > 0)
  17. <div class="row">
  18. <div class="col-md-12">
  19. @include('front.products.product-list-table', compact('products'))
  20. </div>
  21. </div>
  22. @if(isset($addresses))
  23. <div class="row">
  24. <div class="col-md-12">
  25. <legend><i class="fa fa-home"></i> Addresses</legend>
  26. <table class="table table-striped">
  27. <thead>
  28. <th>Alias</th>
  29. <th>Address</th>
  30. <th>Billing Address</th>
  31. <th>Delivery Address</th>
  32. </thead>
  33. <tbody>
  34. @foreach($addresses as $key => $address)
  35. <tr>
  36. <td>{{ $address->alias }}</td>
  37. <td>
  38. {{ $address->address_1 }} {{ $address->address_2 }} <br />
  39. @if(!is_null($address->province))
  40. {{ $address->city }} {{ $address->province->name }} <br />
  41. @endif
  42. {{ $address->city }} {{ $address->state_code }} <br>
  43. {{ $address->country->name }} {{ $address->zip }}
  44. </td>
  45. <td>
  46. <label class="col-md-6 col-md-offset-3">
  47. <input
  48. type="radio"
  49. value="{{ $address->id }}"
  50. name="billing_address"
  51. @if($billingAddress->id == $address->id) checked="checked" @endif>
  52. </label>
  53. </td>
  54. <td>
  55. @if($billingAddress->id == $address->id)
  56. <label for="sameDeliveryAddress">
  57. <input type="checkbox" id="sameDeliveryAddress" checked="checked"> Same as billing
  58. </label>
  59. @endif
  60. </td>
  61. </tr>
  62. @endforeach
  63. </tbody>
  64. <tbody style="display: none" id="sameDeliveryAddressRow">
  65. @foreach($addresses as $key => $address)
  66. <tr>
  67. <td>{{ $address->alias }}</td>
  68. <td>
  69. {{ $address->address_1 }} {{ $address->address_2 }} <br />
  70. @if(!is_null($address->province))
  71. {{ $address->city }} {{ $address->province->name }} <br />
  72. @endif
  73. {{ $address->city }} {{ $address->state_code }} <br>
  74. {{ $address->country->name }} {{ $address->zip }}
  75. </td>
  76. <td></td>
  77. <td>
  78. <label class="col-md-6 col-md-offset-3">
  79. <input
  80. type="radio"
  81. value="{{ $address->id }}"
  82. name="delivery_address"
  83. @if(old('') == $address->id) checked="checked" @endif>
  84. </label>
  85. </td>
  86. </tr>
  87. @endforeach
  88. </tbody>
  89. </table>
  90. </div>
  91. </div>
  92. @endif
  93. @if(!is_null($rates))
  94. <div class="row">
  95. <div class="col-md-12">
  96. <legend><i class="fa fa-truck"></i> Courier</legend>
  97. <ul class="list-unstyled">
  98. @foreach($rates as $rate)
  99. <li class="col-md-4">
  100. <label class="radio">
  101. <input type="radio" name="rate" data-fee="{{ $rate->amount }}" value="{{ $rate->object_id }}">
  102. </label>
  103. <img src="{{ $rate->provider_image_75 }}" alt="courier" class="img-thumbnail" /> {{ $rate->currency }} {{ $rate->amount }}<br />
  104. {{ $rate->servicelevel->name }}
  105. </li>
  106. @endforeach
  107. </ul>
  108. </div>
  109. </div> <br>
  110. @endif
  111. <div class="row">
  112. <div class="col-md-12">
  113. <legend><i class="fa fa-credit-card"></i> Payment</legend>
  114. @if(isset($payments) && !empty($payments))
  115. <table class="table table-striped">
  116. <thead>
  117. <th class="col-md-4">Name</th>
  118. <th class="col-md-4">Description</th>
  119. <th class="col-md-4 text-right">Choose payment</th>
  120. </thead>
  121. <tbody>
  122. @foreach($payments as $payment)
  123. @include('layouts.front.payment-options', compact('payment', 'total', 'shipment_object_id'))
  124. @endforeach
  125. </tbody>
  126. </table>
  127. @else
  128. <p class="alert alert-danger">No payment method set</p>
  129. @endif
  130. </div>
  131. </div>
  132. @else
  133. <p class="alert alert-danger"><a href="{{ route('customer.address.create', [$customer->id]) }}">No address found. You need to create an address first here.</a></p>
  134. @endif
  135. </div>
  136. </div>
  137. @else
  138. <div class="row">
  139. <div class="col-md-12">
  140. <p class="alert alert-warning">No products in cart yet. <a href="{{ route('home') }}">Show now!</a></p>
  141. </div>
  142. </div>
  143. @endif
  144. </div>
  145. @endsection
  146. @section('js')
  147. <script type="text/javascript">
  148. function setTotal(total, shippingCost) {
  149. let computed = +shippingCost + parseFloat(total);
  150. $('#total').html(computed.toFixed(2));
  151. }
  152. function setShippingFee(cost) {
  153. el = '#shippingFee';
  154. $(el).html(cost);
  155. $('#shippingFeeC').val(cost);
  156. }
  157. function setCourierDetails(courierId) {
  158. $('.courier_id').val(courierId);
  159. }
  160. $(document).ready(function () {
  161. let clicked = false;
  162. $('#sameDeliveryAddress').on('change', function () {
  163. clicked = !clicked;
  164. if (clicked) {
  165. $('#sameDeliveryAddressRow').show();
  166. } else {
  167. $('#sameDeliveryAddressRow').hide();
  168. }
  169. });
  170. let billingAddress = 'input[name="billing_address"]';
  171. $(billingAddress).on('change', function () {
  172. let chosenAddressId = $(this).val();
  173. $('.address_id').val(chosenAddressId);
  174. $('.delivery_address_id').val(chosenAddressId);
  175. });
  176. let deliveryAddress = 'input[name="delivery_address"]';
  177. $(deliveryAddress).on('change', function () {
  178. let chosenDeliveryAddressId = $(this).val();
  179. $('.delivery_address_id').val(chosenDeliveryAddressId);
  180. });
  181. let courier = 'input[name="courier"]';
  182. $(courier).on('change', function () {
  183. let shippingCost = $(this).data('cost');
  184. let total = $('#total').data('total');
  185. setCourierDetails($(this).val());
  186. setShippingFee(shippingCost);
  187. setTotal(total, shippingCost);
  188. });
  189. if ($(courier).is(':checked')) {
  190. let shippingCost = $(courier + ':checked').data('cost');
  191. let courierId = $(courier + ':checked').val();
  192. let total = $('#total').data('total');
  193. setShippingFee(shippingCost);
  194. setCourierDetails(courierId);
  195. setTotal(total, shippingCost);
  196. }
  197. });
  198. </script>
  199. @endsection