diff --git a/app/Http/Controllers/WishController.php b/app/Http/Controllers/WishController.php
new file mode 100644
index 0000000..8295ddf
--- /dev/null
+++ b/app/Http/Controllers/WishController.php
@@ -0,0 +1,84 @@
+wishlistRepository = $wishlistRepository;
+ }
+
+ /**
+ * Display the wishlist page
+ */
+ public function index(Request $request)
+ {
+ try {
+ $wishlists = $this->wishlistRepository->getList($request);
+
+ return view('account.wishlist', [
+ 'wishlists' => $wishlists,
+ 'user' => Auth::user()
+ ]);
+ } catch (\Exception $e) {
+ return redirect()->back()->with('error', 'Failed to load wishlist: ' . $e->getMessage());
+ }
+ }
+
+ /**
+ * Add item to wishlist
+ */
+ public function store(Request $request): JsonResponse
+ {
+ $request->validate([
+ 'item_id' => 'required|exists:items,id'
+ ]);
+
+ try {
+ $wishlist = $this->wishlistRepository->create([
+ 'item_id' => $request->item_id
+ ]);
+
+ return response()->json([
+ 'success' => true,
+ 'message' => 'Item added to wishlist successfully',
+ 'wishlist' => $wishlist
+ ]);
+ } catch (\Exception $e) {
+ return response()->json([
+ 'success' => false,
+ 'message' => 'Failed to add item to wishlist: ' . $e->getMessage()
+ ], 500);
+ }
+ }
+
+ /**
+ * Remove item from wishlist
+ */
+ public function destroy(Request $request, $id): JsonResponse
+ {
+ try {
+
+
+ $this->wishlistRepository->delete($id);
+
+ return response()->json([
+ 'success' => true,
+ 'message' => 'Item removed from wishlist successfully'
+ ]);
+ } catch (\Exception $e) {
+ return response()->json([
+ 'success' => false,
+ 'message' => 'Failed to remove item from wishlist: ' . $e->getMessage()
+ ], 500);
+ }
+ }
+}
diff --git a/app/Models/ItemReference.php b/app/Models/ItemReference.php
index 4853b09..5c2a1b6 100644
--- a/app/Models/ItemReference.php
+++ b/app/Models/ItemReference.php
@@ -199,4 +199,6 @@ class ItemReference extends Model
return $result;
}
+
+
}
diff --git a/app/Models/Items.php b/app/Models/Items.php
index 06e3e2c..18b1be4 100644
--- a/app/Models/Items.php
+++ b/app/Models/Items.php
@@ -355,4 +355,10 @@ class Items extends Model
return 0;
}
}
+
+
+ public function isWishlist() : bool
+ {
+ return $this->hasOne(Wishlist::class, 'item_id', 'id')->where('customer_id', auth()->user()->customer->id)->exists();
+ }
}
diff --git a/app/Models/Wishlist.php b/app/Models/Wishlist.php
new file mode 100644
index 0000000..56a69c2
--- /dev/null
+++ b/app/Models/Wishlist.php
@@ -0,0 +1,27 @@
+belongsTo(Customer::class);
+ }
+
+ public function item(): BelongsTo
+ {
+ return $this->belongsTo(Items::class);
+ }
+}
diff --git a/app/Repositories/Member/WishlistRepository.php b/app/Repositories/Member/WishlistRepository.php
new file mode 100644
index 0000000..83e48a2
--- /dev/null
+++ b/app/Repositories/Member/WishlistRepository.php
@@ -0,0 +1,75 @@
+user()->id)->first();
+
+ if (!$customer) {
+ throw new \Exception('Customer not found');
+ }
+ $limit = 20;
+
+ $wishlist = Wishlist::where('customer_id', $customer->id)
+ ->with([
+ 'item.variants',
+
+ ])
+ ->orderBy('created_at', 'desc')
+ ->paginate($limit);
+
+ return $wishlist;
+ }
+
+ public function create($data)
+ {
+ $model = DB::transaction(function () use ($data) {
+ $customer = Customer::where('user_id', auth()->user()->id)->first();
+
+ // Check if item already exists in wishlist
+ $existing = Wishlist::where('customer_id', $customer->id)
+ ->where('item_id', $data['item_id'])
+ ->first();
+
+ if ($existing) {
+ return $existing; // Return existing item if already in wishlist
+ }
+
+ $model = Wishlist::create([
+ 'customer_id' => $customer->id,
+ 'item_id' => $data['item_id'],
+ ]);
+
+ return $model;
+ });
+
+
+ return $model;
+ }
+
+ public function delete($item_id)
+ {
+ $wishlist = DB::transaction(function () use ($item_id) {
+ $wishlist = Wishlist::where('customer_id', auth()->user()->customer->id)
+ ->where('item_id', $item_id)
+ ->first();
+
+ if (!$wishlist) {
+ throw new \Exception('Wishlist not found');
+ }
+
+ $wishlist->delete();
+ return $wishlist;
+ });
+
+
+ return $wishlist;
+ }
+}
diff --git a/resources/views/account/wishlist.blade.php b/resources/views/account/wishlist.blade.php
index 0531122..8761d6f 100644
--- a/resources/views/account/wishlist.blade.php
+++ b/resources/views/account/wishlist.blade.php
@@ -7,15 +7,15 @@
-
+ {{--
Interesting offers
@@ -69,9 +69,9 @@
-
+
--}}
- --}}
-
-
-
-
-
-
-
-
-
$340.99 $430.00
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+ @foreach ($wishlists as $key => $value)
+ @include('components.home.product-card', ['product' => $value->item])
+ @endforeach
+
diff --git a/resources/views/components/home/product-card.blade.php b/resources/views/components/home/product-card.blade.php
index dee9213..c765aa5 100644
--- a/resources/views/components/home/product-card.blade.php
+++ b/resources/views/components/home/product-card.blade.php
@@ -33,8 +33,8 @@
@endif
- @if ($product->variants->count() > 1)
-
+{{ $product->variants->count() - 1 }} Varian
+ @if (($product->variants?->count() ?? 0) > 1)
+
+{{ ($product->variants->count() ?? 0) - 1 }} Varian
@endif
{{--
+1 color
--}}
{{--
diff --git a/resources/views/layouts/partials/account-sidebar.blade.php b/resources/views/layouts/partials/account-sidebar.blade.php
index ad3e980..3de21cb 100644
--- a/resources/views/layouts/partials/account-sidebar.blade.php
+++ b/resources/views/layouts/partials/account-sidebar.blade.php
@@ -51,7 +51,7 @@
{{--
1 --}}
+ href="{{ route('wishlist.index') }}">
{{ __('account_sidebar.wishlist') }}
diff --git a/resources/views/shop/product-fashion.blade.php b/resources/views/shop/product-fashion.blade.php
index a373ea9..7d15262 100644
--- a/resources/views/shop/product-fashion.blade.php
+++ b/resources/views/shop/product-fashion.blade.php
@@ -1,9 +1,6 @@
@extends('layouts.landing', ['title' => $product->name ?? 'Detail'])
@section('content')
-
-
-
@@ -73,9 +70,9 @@
@@ -98,17 +95,35 @@
--}}
- {{ $product->name }}
+
+
+
{{ $product->name }}
+
+
+ {{-- wishlist/love button --}}
+
+
{{-- add category --}}
+ {{ $product->category->name }}
+
+ {{ $product->brand->name }}
+
+
+
{!! nl2br(Str::limit($product->description, 500)) !!}
@@ -144,8 +159,8 @@
@foreach ($product->variants as $key => $variant)
+ value="{{ $variant->reference->id }}" id="variant-id-{{ $variant->id }}"
+ {{ $key == 0 ? 'checked' : '' }}>