Order History View and Track Orders

This commit is contained in:
UronShrestha 2024-07-09 11:44:05 +05:45
parent a1835247d6
commit f4aab0bed3
6 changed files with 214 additions and 23 deletions

View File

@ -185,6 +185,37 @@ class MainController extends Controller
}
}
public function myOrders()
{
$customerId = auth()->id(); // Assuming you are using authentication
$orders = Order::where('customerId', session()->get('id'))->get();
$items = DB::table('products')
->join('order_items', 'order_items.productId', '=', 'products.id')
->select('products.name', 'products.picture', 'products.price', 'order_items.quantity', 'order_items.orderId as order_id')
->whereIn('order_items.orderId', $orders->pluck('id'))
->get();
return view('orders', compact('orders', 'items'));
}
// public function myOrders()
// {
// $customerId = auth()->id(); // Assuming you are using authentication
// $orders = Order::where('customerId', session()->get('id'))->get();
// $items = DB::table('products')
// ->join('order_items', 'order_items.productId', '=', 'products.id')
// ->select('products.name', 'products.picture', 'products.price', 'order_items.quantity', 'order_items.orderId as order_id')
// ->whereIn('order_items.orderId', $orders->pluck('id'))
// ->get();
// return view('orders', compact('orders', 'items'));
// }
public function profile()
{
if (session()->has('id')) {

View File

@ -3856,4 +3856,8 @@ ol {
.categories__text:before {
height: 250px;
}
.custom-upward {
margin-top: -20px; /* Adjust the value as needed */
}
}

View File

@ -88,7 +88,20 @@
<script src={{ URL::asset('js/mixitup.min.js') }}></script>
<script src={{ URL::asset('js/owl.carousel.min.js') }}></script>
<script src={{ URL::asset('js/main.js') }}></script>
</body>
<script src="https://code.jquery.com/jquery-3.6.3.min.js"
integrity="sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU=" crossorigin="anonymous"></script>
{{-- Datatables script --}}
<script src="//cdn.datatables.net/2.0.8/js/dataTables.min.js"></script>
<script>
$(document).ready(function() {
$('#myTable').DataTable();
});
</script>
<script>
document.addEventListener("DOMContentLoaded", function() {
@ -107,6 +120,8 @@
}, 2000); // 2000 milliseconds = 3 seconds
});
</script>
</body>
</html>

View File

@ -22,8 +22,24 @@
<link rel="stylesheet" href="{{ URL::asset('css/owl.carousel.min.css') }}"type="text/css">
<link rel="stylesheet" href="{{ URL::asset('css/slicknav.min.css') }}" type="text/css">
<link rel="stylesheet" href="{{ URL::asset('css/style.css') }}" type="text/css">
{{-- bootstrap --}}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/5.1.3/css/bootstrap.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<!-- Include the Stripe.js library -->
<script src="https://js.stripe.com/v3/"></script>
<!-- datatables-->
<link rel="stylesheet" href="//cdn.datatables.net/2.0.8/css/dataTables.dataTables.min.css">
{{-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.3.0/css/bootstrap.min.css"> --}}
<link rel="stylesheet" href="https://cdn.datatables.net/2.0.8/css/dataTables.bootstrap5.css">
</head>
<body>
@ -78,10 +94,10 @@
<div class="header__top__links">
@if (session()->has('id'))
<a href="{{ URL::to('/logout') }}">Logout</a>
<a href="{{ route('logout') }}">Logout</a>
@else
<a href="{{ URL::to('/login') }}">Login</a>
<a href="{{ URL::to('/register') }}">Register</a>
<a href="{{ route('login') }}">Login</a>
<a href="{{ route('register') }}">Register</a>
@endif
{{-- <a href="{{ URL::to('/register') }}">Sign in</a>
<a href="{{ URL::to('/login') }}">Login</a> --}}
@ -103,21 +119,22 @@
<div class="row">
<div class="col-lg-3 col-md-3">
<div class="header__logo">
<a href="{{ URL::to('/') }}"><img src="{{ URL::asset('img/logo.png') }}" alt=""></a>
<a href="{{ route('/') }}"><img src="{{ URL::asset('img/logo.png') }}" alt=""></a>
</div>
</div>
<div class="col-lg-6 col-md-6">
<nav class="header__menu mobile-menu">
<ul>
<li class="active"><a href="{{ URL::to('/') }}">Home</a></li>
<li><a href="{{ URL::to('shop') }}">Shop</a></li>
<li><a href="{{ route('/') }}">Home</a></li>
<li><a href="{{ route('shop') }}">Shop</a></li>
<li><a href="#">Pages</a>
<ul class="dropdown">
<li><a href="{{ URL::to('about') }}">About Us</a></li>
<li><a href="{{ route('about') }}">About Us</a></li>
{{-- <li><a href="{{ URL::to('singleProduct') }}">Single Product</a></li> --}}
<li><a href="{{ URL::to('cart') }}">Shopping Cart</a></li>
<li><a href="{{ URL::to('checkout') }}">Check Out</a></li>
<li><a href="{{ URL::to('profile') }}">Profile</a></li>
<li><a href="{{ route('cart') }}">Shopping Cart</a></li>
<li><a href="{{ route('checkout') }}">Check Out</a></li>
<li><a href="{{ route('myOrders') }}">My Orders</a></li>
<li><a href="{{ route('profile') }}">Profile</a></li>
</ul>
</li>
@ -130,7 +147,7 @@
<a href="#" class="search-switch"><img src="{{ URL::asset('img/icon/search.png') }}"
alt=""></a>
<a href="#"><img src="{{ URL::asset('img/icon/heart.png') }}" alt=""></a>
<a href="{{ URL::to('cart') }}"><img src="{{ URL::asset('img/icon/cart.png') }}"
<a href="{{ route('cart') }}"><img src="{{ URL::asset('img/icon/cart.png') }}"
alt="">
<span>0</span></a>
<div class="price">Rs 0.00</div>

View File

@ -0,0 +1,123 @@
<x-header />
<!-- Contact Section Begin -->
<section class="contact spad">
<div class="container">
<div class="row">
<div class="col-lg-10 col-md-6 mx-auto">
<div class="section-title">
<h2>My Orders</h2>
</div>
<div class="contact__form">
@if (session('success'))
<div class="alert alert-success">
{{ session('success') }}
</div>
@endif
@if (session('error'))
<div class="alert alert-danger">
{{ session('error') }}
</div>
@endif
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<table id="myTable" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th>S.No.</th>
<th>Name</th>
<th>Address</th>
<th>Phone</th>
<th>Status</th>
<th>Order Date</th>
<th>Total Bill</th>
<th>View Products</th>
</tr>
</thead>
<tbody>
@foreach ($orders as $order)
<tr>
<td>{{ $loop->iteration }}</td>
<td>{{ $order->name }}</td>
<td>{{ $order->address }}</td>
<td>{{ $order->phone }}</td>
<td>{{ $order->status }}</td>
<td>{{ $order->created_at }}</td>
<td>{{ $order->bill }}</td>
<td>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal"
data-bs-target="#viewProductsModal{{ $order->id }}">
View
</button>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</section>
<!-- Contact Section End -->
<!-- Modal Begin -->
@foreach ($orders as $order)
<div class="modal fade" id="viewProductsModal{{ $order->id }}" tabindex="-1"
aria-labelledby="exampleModalLabel{{ $order->id }}" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel{{ $order->id }}">All Products</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<table class="table table-bordered">
<thead>
<tr>
<th>Product</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
@foreach ($items as $product)
@if ($product->order_id == $order->id)
<tr>
<td><img src="{{ url::to('uploads/products/' . $product->picture) }}"
width="100px" alt="">{{ $product->name }}</td>
<td>{{ $product->quantity }}</td>
<td>{{ $product->price }}</td>
<td>{{ $product->price * $product->quantity }}</td>
</tr>
@endif
@endforeach
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-bs-dismiss="modal">Close</button>
{{-- <button type="button" class="btn btn-primary">Save changes</button> --}}
</div>
</div>
</div>
</div>
@endforeach
<!-- Modal End -->
<!-- Footer Section Begin -->
<x-footer />
<!-- Footer Section End -->

View File

@ -5,32 +5,33 @@ use App\Http\Controllers\StripePaymentController;
use Illuminate\Support\Facades\Route;
Route::get('/', [MainController::class, 'index']);
Route::get('/about', [MainController::class, 'about']);
Route::get('/', [MainController::class, 'index'])->name('/');
Route::get('/about', [MainController::class, 'about'])->name('about');
Route::get('/blog', [MainController::class, 'blog']);
Route::get('/profile', [MainController::class, 'profile']);
Route::get('/profile', [MainController::class, 'profile'])->name('profile');
Route::post('/updateUser', [MainController::class, 'updateUser']);
Route::get('/cart', [MainController::class, 'cart']);
Route::get('/cart', [MainController::class, 'cart'])->name('cart');
Route::post('/addToCart', [MainController::class, 'addToCart']);
Route::get('/deleteCartItem/{id}', [MainController::class, 'deleteCartItem']);
Route::post('/updateCartItem/{id}', [MainController::class, 'updateCartItem'])->name("cart.update");
Route::get('/checkout', [MainController::class, 'checkout']);
Route::get('/main', [MainController::class, 'main']);
Route::get('/checkout', [MainController::class, 'checkout'])->name('checkout');
Route::get('/myOrders', [MainController::class, 'myOrders'])->name('myOrders');
Route::get('/shop', [MainController::class, 'shop']);
Route::get('/shop', [MainController::class, 'shop'])->name('shop');
Route::get('/single/{id}', [MainController::class, 'singleProduct']);
Route::get('/register', [MainController::class, 'register'])->name('register');
Route::post('/registerUser', [MainController::class, 'registerUser'])->name('registerUser');
Route::get('/login', [MainController::class, 'login']);
Route::get('/login', [MainController::class, 'login'])->name('login');
Route::post('/loginUser', [MainController::class, 'loginUser']);
Route::get('/logout', [MainController::class, 'logout']);
Route::get('/logout', [MainController::class, 'logout'])->name('logout');
Route::controller(StripePaymentController::class)->group(function () {