cart.blade.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. @php
  2. if (auth()->user() != null) {
  3. $user_id = Auth::user()->id;
  4. $cart = \App\Models\Cart::where('user_id', $user_id)->get();
  5. } else {
  6. $temp_user_id = Session()->get('temp_user_id');
  7. if ($temp_user_id) {
  8. $cart = \App\Models\Cart::where('temp_user_id', $temp_user_id)->get();
  9. }
  10. }
  11. @endphp
  12. <a href="javascript:void(0)" class="d-flex align-items-center text-reset h-100" data-toggle="dropdown"
  13. data-display="static">
  14. <i class="la la-shopping-cart la-2x opacity-80"></i>
  15. <span class="flex-grow-1 ml-1">
  16. @if (isset($cart) && count($cart) > 0)
  17. <span class="badge badge-primary badge-inline badge-pill cart-count">
  18. {{ count($cart) }}
  19. </span>
  20. @else
  21. <span class="badge badge-primary badge-inline badge-pill cart-count">0</span>
  22. @endif
  23. <span class="nav-box-text d-none d-xl-block opacity-70">{{ translate('Cart') }}</span>
  24. </span>
  25. </a>
  26. <div class="dropdown-menu dropdown-menu-right dropdown-menu-lg p-0 stop-propagation">
  27. @if (isset($cart) && count($cart) > 0)
  28. <div class="p-3 fs-15 fw-600 p-3 border-bottom">
  29. {{ translate('Cart Items') }}
  30. </div>
  31. <ul class="h-250px overflow-auto c-scrollbar-light list-group list-group-flush">
  32. @php
  33. $total = 0;
  34. @endphp
  35. @foreach ($cart as $key => $cartItem)
  36. @php
  37. $product = \App\Models\Product::find($cartItem['product_id']);
  38. // $total = $total + ($cartItem['price'] + $cartItem['tax']) * $cartItem['quantity'];
  39. $total = $total + cart_product_price($cartItem, $product, false) * $cartItem['quantity'];
  40. @endphp
  41. @if ($product != null)
  42. <li class="list-group-item">
  43. <span class="d-flex align-items-center">
  44. <a href="{{ route('product', $product->slug) }}"
  45. class="text-reset d-flex align-items-center flex-grow-1">
  46. <img src="{{ static_asset('assets/img/placeholder.jpg') }}"
  47. data-src="{{ uploaded_asset($product->thumbnail_img) }}"
  48. class="img-fit lazyload size-60px rounded"
  49. alt="{{ $product->getTranslation('name') }}">
  50. <span class="minw-0 pl-2 flex-grow-1">
  51. <span class="fw-600 mb-1 text-truncate-2">
  52. {{ $product->getTranslation('name') }}
  53. </span>
  54. <span class="">{{ $cartItem['quantity'] }}x</span>
  55. {{-- <span
  56. class="">{{ single_price($cartItem['price'] + $cartItem['tax']) }}</span> --}}
  57. <span class="">{{ cart_product_price($cartItem, $product) }}</span>
  58. </span>
  59. </a>
  60. <span class="">
  61. <button onclick="removeFromCart({{ $cartItem['id'] }})"
  62. class="btn btn-sm btn-icon stop-propagation">
  63. <i class="la la-close"></i>
  64. </button>
  65. </span>
  66. </span>
  67. </li>
  68. @endif
  69. @endforeach
  70. </ul>
  71. <div class="px-3 py-2 fs-15 border-top d-flex justify-content-between">
  72. <span class="opacity-60">{{ translate('Subtotal') }}</span>
  73. <span class="fw-600">{{ single_price($total) }}</span>
  74. </div>
  75. <div class="px-3 py-2 text-center border-top">
  76. <ul class="list-inline mb-0">
  77. <li class="list-inline-item">
  78. <a href="{{ route('cart') }}" class="btn btn-soft-primary btn-sm">
  79. {{ translate('View cart') }}
  80. </a>
  81. </li>
  82. @if (Auth::check())
  83. <li class="list-inline-item">
  84. <a href="{{ route('checkout.shipping_info') }}" class="btn btn-primary btn-sm">
  85. {{ translate('Checkout') }}
  86. </a>
  87. </li>
  88. @endif
  89. </ul>
  90. </div>
  91. @else
  92. <div class="text-center p-3">
  93. <i class="las la-frown la-3x opacity-60 mb-3"></i>
  94. <h3 class="h6 fw-700">{{ translate('Your Cart is empty') }}</h3>
  95. </div>
  96. @endif
  97. </div>