Skip to content

Commit 5e459e9

Browse files
payment2
1 parent 4db7075 commit 5e459e9

File tree

9 files changed

+77
-79
lines changed

9 files changed

+77
-79
lines changed

app/Http/Controllers/Auth/AdminAuthController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function login(Request $request): RedirectResponse
4646
}
4747

4848
$request->session()->regenerate();
49-
return redirect()->intended('/admin/dashboard');
49+
return redirect()->intended('/admin/products');
5050
}
5151

5252
return back()->withErrors([

app/Http/Controllers/Auth/AuthenticatedSessionController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function store(LoginRequest $request): RedirectResponse
3535

3636
$user = $request->user();
3737

38-
if ($user->role !== 'user') {
38+
if ($user->role == 'user') {
3939
Auth::logout();
4040
$request->session()->invalidate();
4141
$request->session()->regenerateToken();

app/Services/CartService.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function removeItemFromCart(int $productId, array $optionIds = [])
5454
protected function updateItemQuantityToDatabase(int $productId, int $quantity, array $optionIds = []): void
5555
{
5656
$userId = Auth::id();
57-
krsort($optionIds);
57+
sort($optionIds);
5858

5959
$cartItem = Cart::where('product_id', $productId)->where('user_id', $userId)
6060
->where('variation_type_option_ids', $optionIds)
@@ -69,7 +69,7 @@ protected function updateItemQuantityToDatabase(int $productId, int $quantity, a
6969
protected function updateItemQuantityToCookies(int $productId, int $quantity, array $optionIds = []): void
7070
{
7171
$cartItems = $this->getCartItemsFromCookies();
72-
krsort($optionIds);
72+
sort($optionIds);
7373
$cartItemKey = $productId . '_' . json_encode($optionIds);
7474
if (isset($cartItems[$cartItemKey])) {
7575
$cartItems[$cartItemKey]['quantity'] = $quantity;
@@ -80,7 +80,7 @@ protected function updateItemQuantityToCookies(int $productId, int $quantity, ar
8080
protected function removeItemFromDatabase(int $productId, array $optionIds = []): void
8181
{
8282
$userId = Auth::id();
83-
krsort($optionIds);
83+
sort($optionIds);
8484
Cart::where('product_id', $productId)
8585
->where('user_id', $userId)
8686
->where('variation_type_option_ids', $optionIds)
@@ -90,7 +90,7 @@ protected function removeItemFromDatabase(int $productId, array $optionIds = [])
9090
protected function removeItemFromCookies(int $productId, array $optionIds = []): void
9191
{
9292
$cartItems = $this->getCartItemsFromCookies();
93-
krsort($optionIds);
93+
sort($optionIds);
9494
$cartItemKey = $productId . '_' . json_encode($optionIds);
9595
if (isset($cartItems[$cartItemKey])) {
9696
unset($cartItems[$cartItemKey]);
@@ -166,7 +166,7 @@ public function getCartItems(): array
166166
protected function saveItemToDatabase(int $productId, int $quantity, int $price, array $optionIds): void
167167
{
168168
$userId = Auth::id();
169-
krsort($optionIds);
169+
sort($optionIds);
170170

171171
$cartItem = Cart::where('product_id', $productId)
172172
->where('user_id', $userId)
@@ -190,7 +190,7 @@ protected function saveItemToDatabase(int $productId, int $quantity, int $price,
190190
protected function saveItemToCookies(int $productId, int $quantity, int $price, array $optionIds): void
191191
{
192192
$cartItems = $this->getCartItemsFromCookies();
193-
krsort($optionIds);
193+
sort($optionIds);
194194
$cartItemKey = $productId . '_' . json_encode($optionIds);
195195
if (!isset($cartItems[$cartItemKey])) {
196196
$cartItems[$cartItemKey] = [

resources/js/components/ecommerce/CategoryMenuItem.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useState } from 'react';
44
interface Category {
55
id: number;
66
name: string;
7+
image: string;
78
slug: string;
89
icon?: string;
910
children: Category[];
@@ -22,12 +23,16 @@ export default function CategoryMenuItem({ category }: CategoryMenuItemProps) {
2223
<>
2324
<a
2425
href="#"
25-
className="flex items-center justify-between px-4 py-3 hover:bg-gray-100"
26+
className="text-black flex items-center justify-between px-4 py-3 hover:bg-gray-100"
2627
onMouseEnter={() => setIsSubMenuOpen(true)}
2728
onMouseLeave={() => setIsSubMenuOpen(false)}
2829
>
29-
<div className="flex items-center">
30-
<i className={`fas fa-${category.icon || 'folder'} mr-3 text-indigo-500`}></i>
30+
<div className="text-black flex items-center">
31+
<i className={`fas fa-${category.icon || 'folder'} mr-3 =text-indigo-500`}></i>
32+
<img
33+
src={category.image || '/default-category.png'}
34+
className=" w-5 h-5 mr-2 inline-block object-cover rounded"
35+
/>
3136
<span>{category.name}</span>
3237
</div>
3338
<i className="fas fa-chevron-right text-xs"></i>

resources/js/components/ecommerce/Header.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Link, usePage } from '@inertiajs/react';
2-
import { ChevronDown, Facebook, Instagram, Menu, Search, ShoppingCart, Twitter, User } from 'lucide-react';
2+
import { FaFacebookF, FaTwitter, FaInstagram, FaShoppingCart, FaChevronDown, FaBars, FaChevronRight } from 'react-icons/fa';
3+
import {Search,User } from 'lucide-react';
34
import { useState } from 'react';
45
import CategoryMenuItem from './CategoryMenuItem';
56

@@ -9,7 +10,6 @@ export default function EcommerceHeader() {
910
const [isCurrencyOpen, setIsCurrencyOpen] = useState(false);
1011
const [isLanguageOpen, setIsLanguageOpen] = useState(false);
1112
const [isCategoriesOpen, setIsCategoriesOpen] = useState(false);
12-
const [isSubCategoriesOpen, setIsSubCategoriesOpen] = useState(false);
1313

1414
return (
1515
<>
@@ -18,21 +18,21 @@ export default function EcommerceHeader() {
1818
<div className="container mx-auto flex items-center justify-between px-4">
1919
<div className="flex space-x-4">
2020
<Link href="#" className="hover:text-gray-300">
21-
<Facebook className="h-5 w-5" />
21+
<FaFacebookF className="h-5 w-5" />
2222
</Link>
2323
<Link href="#" className="hover:text-gray-300">
24-
<Twitter className="h-5 w-5" />
24+
<FaTwitter className="h-5 w-5" />
2525
</Link>
2626
<Link href="#" className="hover:text-gray-300">
27-
<Instagram className="h-5 w-5" />
27+
<FaInstagram className="h-5 w-5" />
2828
</Link>
2929
</div>
30-
<div className="flex items-center space-x-6">
30+
<div className=" flex items-center space-x-6">
3131
{/* Currency Dropdown */}
3232
<div className="relative">
3333
<button onClick={() => setIsCurrencyOpen(!isCurrencyOpen)} className="flex items-center space-x-1 hover:text-gray-300">
3434
<span>USD</span>
35-
<ChevronDown className="h-3 w-3" />
35+
<FaChevronDown className="h-3 w-3" />
3636
</button>
3737
{isCurrencyOpen && (
3838
<div className="absolute right-0 z-50 mt-2 w-40 overflow-hidden rounded-md bg-white text-gray-800 shadow-lg">
@@ -53,7 +53,7 @@ export default function EcommerceHeader() {
5353
<div className="relative">
5454
<button onClick={() => setIsLanguageOpen(!isLanguageOpen)} className="flex items-center space-x-1 hover:text-gray-300">
5555
<span>English</span>
56-
<ChevronDown className="h-3 w-3" />
56+
<FaChevronDown className="h-3 w-3" />
5757
</button>
5858
{isLanguageOpen && (
5959
<div className="absolute right-0 z-50 mt-2 w-40 overflow-hidden rounded-md bg-white text-gray-800 shadow-lg">
@@ -97,7 +97,7 @@ export default function EcommerceHeader() {
9797
{/* Cart Dropdown */}
9898
<div className="relative">
9999
<Link href={route('cart.index')} className="relative hover:text-indigo-600">
100-
<ShoppingCart className="h-6 w-6" />
100+
<FaShoppingCart className="h-6 w-6" />
101101
{cartCount > 0 && (
102102
<span className="absolute -top-2 -right-2 flex h-5 w-5 items-center justify-center rounded-full bg-red-500 text-xs text-white">
103103
{cartCount}
@@ -140,15 +140,17 @@ export default function EcommerceHeader() {
140140
<button
141141
onClick={() => setIsCategoriesOpen(!isCategoriesOpen)}
142142
className="flex items-center px-4 py-3 text-gray-700 hover:text-indigo-600 focus:outline-none"
143+
143144
>
144-
<Menu className="mr-2 h-5 w-5" />
145+
<FaBars className="mr-2" />
145146
<span>All Categories</span>
146-
<ChevronDown className="ml-1 h-3 w-3" />
147+
<FaChevronDown className="ml-1 h-3 w-3" />
147148
</button>
148-
<div x-show="open" className="dropdown-menu absolute left-0 z-50 w-64 rounded-b-md bg-white shadow-lg">
149-
{/* <!-- Category with subcategories --> */}
149+
<div x-show="open" className="text-black dropdown-menu absolute left-0 z-50 w-64 rounded-b-md bg-white shadow-lg">
150+
150151
{parentCategories.length > 0 &&
151152
parentCategories.map((category: any) => <CategoryMenuItem key={category.id} category={category} />)}
153+
152154
</div>
153155
</div>
154156

resources/js/components/ecommerce/HomePage/ProductCard.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { ProductListItem } from '@/types';
22
import { router, useForm } from '@inertiajs/react';
33
import { Heart, ShoppingBag } from 'lucide-react';
4+
import { toast } from 'react-toastify';
5+
46

57
type Props = {
68
product: ProductListItem;
@@ -23,7 +25,11 @@ const ProductCard = ({ product }: Props) => {
2325
form.post(route('cart.store', product.id), {
2426
preserveScroll: true,
2527
preserveState: true,
28+
onSuccess: () => {
29+
toast.success('The product has been added to the shopping cart.');
30+
},
2631
onError: (err: any) => {
32+
toast.error('The product has not been added.');
2733
console.log(err);
2834
},
2935
});
@@ -73,7 +79,7 @@ const ProductCard = ({ product }: Props) => {
7379
</p>
7480
<div className="flex items-center justify-between">
7581
<div>
76-
<span className="font-bold text-indigo-600">{product.price}</span>
82+
<span className="font-bold text-indigo-600">${product.price}</span>
7783
{product.isDiscount && (
7884
<span className="ml-2 text-gray-400 line-through">
7985
${product.originalPrice ?? '119.99'}

resources/js/pages/Ecommerce/Cart.tsx

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Link, router } from '@inertiajs/react'
22
import { ArrowLeft, Minus, Plus, Trash2 } from 'lucide-react'
33
import { useState } from 'react'
44
import { EcomLayout } from '@/layouts/ecom-layout';
5+
import { toast } from 'react-toastify';
56

67
interface CartItem {
78
id: string | number
@@ -33,7 +34,7 @@ const Cart = ({ cartItems, cartCount }: CartProps) => {
3334
const updateQuantity = (item: CartItem, newQuantity: number) => {
3435
if (newQuantity < 1) return
3536

36-
const itemKey = `${item.product_id}_${JSON.stringify(item.option_ids)}`
37+
const itemKey = `${item.id}`
3738
setUpdatingItems((prev) => new Set(prev).add(itemKey))
3839

3940
router.put(
@@ -59,11 +60,14 @@ const Cart = ({ cartItems, cartCount }: CartProps) => {
5960
data: {
6061
option_ids: item.option_ids,
6162
},
63+
onSuccess: () => {
64+
toast.success('The product has been deleted.');
65+
},
6266
})
6367
}
6468

6569
const subtotal = cartItems.reduce((sum, item) => sum + item.price * item.quantity, 0)
66-
const shipping = 0 // Free shipping
70+
const shipping = 0
6771
const total = subtotal + shipping
6872

6973
const handleCheckout = () => {
@@ -76,28 +80,14 @@ const Cart = ({ cartItems, cartCount }: CartProps) => {
7680
<div className="container mx-auto px-4 py-8">
7781
<div className="text-center">
7882
<div className="mb-6">
79-
<svg
80-
className="mx-auto h-24 w-24 text-gray-300"
81-
fill="none"
82-
viewBox="0 0 24 24"
83-
stroke="currentColor"
84-
>
85-
<path
86-
strokeLinecap="round"
87-
strokeLinejoin="round"
88-
strokeWidth={2}
89-
d="M3 3h2l.4 2M7 13h10l4-8H5.4m0 0L7 13m0 0l-2.5 5M7 13l2.5 5m6-5v6a2 2 0 01-2 2H9a2 2 0 01-2-2v-6m6 0V9a2 2 0 00-2-2H9a2 2 0 00-2 2v4.01"
90-
/>
83+
<svg className="mx-auto h-24 w-24 text-gray-300" fill="none" viewBox="0 0 24 24" stroke="currentColor">
84+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
85+
d="M3 3h2l.4 2M7 13h10l4-8H5.4m0 0L7 13m0 0l-2.5 5M7 13l2.5 5m6-5v6a2 2 0 01-2 2H9a2 2 0 01-2-2v-6m6 0V9a2 2 0 00-2-2H9a2 2 0 00-2 2v4.01" />
9186
</svg>
9287
</div>
9388
<h2 className="mb-4 text-2xl font-bold text-gray-800">Your cart is empty</h2>
94-
<p className="mb-8 text-gray-600">
95-
Looks like you haven't added any items to your cart yet.
96-
</p>
97-
<Link
98-
href="/"
99-
className="inline-flex items-center rounded-md bg-indigo-600 px-6 py-3 text-white hover:bg-indigo-700"
100-
>
89+
<p className="mb-8 text-gray-600">Looks like you haven't added any items to your cart yet.</p>
90+
<Link href="/" className="inline-flex items-center rounded-md bg-indigo-600 px-6 py-3 text-white hover:bg-indigo-700">
10191
<ArrowLeft className="mr-2 h-5 w-5" />
10292
Continue Shopping
10393
</Link>
@@ -110,23 +100,18 @@ const Cart = ({ cartItems, cartCount }: CartProps) => {
110100
return (
111101
<EcomLayout>
112102
<div className="container mx-auto px-4 py-8">
113-
{/* Breadcrumb */}
114103
<div className="mb-6">
115104
<nav className="flex" aria-label="Breadcrumb">
116105
<ol className="flex items-center space-x-4">
117106
<li>
118-
<Link href="/" className="text-gray-500 hover:text-gray-700">
119-
Home
120-
</Link>
107+
<Link href="/" className="text-gray-500 hover:text-gray-700">Home</Link>
121108
</li>
122109
<li>
123110
<div className="flex items-center">
124111
<svg className="h-5 w-5 text-gray-400" fill="currentColor" viewBox="0 0 20 20">
125-
<path
126-
fillRule="evenodd"
127-
d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"
128-
clipRule="evenodd"
129-
/>
112+
<path fillRule="evenodd"
113+
d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"
114+
clipRule="evenodd" />
130115
</svg>
131116
<span className="ml-4 text-gray-500">Shopping Cart</span>
132117
</div>
@@ -136,7 +121,6 @@ const Cart = ({ cartItems, cartCount }: CartProps) => {
136121
</div>
137122

138123
<div className="grid grid-cols-1 gap-8 lg:grid-cols-3">
139-
{/* Cart Items */}
140124
<div className="lg:col-span-2">
141125
<div className="rounded-lg bg-white shadow-sm">
142126
<div className="border-b px-6 py-4">
@@ -146,7 +130,7 @@ const Cart = ({ cartItems, cartCount }: CartProps) => {
146130
</div>
147131
<div className="divide-y">
148132
{cartItems.map((item) => {
149-
const itemKey = `${item.product_id}_${JSON.stringify(item.option_ids)}`
133+
const itemKey = `${item.id}`
150134
const isUpdating = updatingItems.has(itemKey)
151135

152136
return (
@@ -159,19 +143,16 @@ const Cart = ({ cartItems, cartCount }: CartProps) => {
159143
/>
160144
<div className="ml-4 flex-1">
161145
<h3 className="text-lg font-medium text-gray-800">
162-
<Link
163-
href={route('product.detail', { slug: item.slug })}
164-
className="hover:text-indigo-600"
165-
>
146+
<Link href={route('product.detail', { slug: item.slug })} className="hover:text-indigo-600">
166147
{item.name}
167148
</Link>
168149
</h3>
169150
{item.options.length > 0 && (
170151
<div className="mt-1 text-sm text-gray-600">
171152
{item.options.map((option) => (
172153
<span key={option.id} className="mr-2">
173-
{option.type.name}: {option.name}
174-
</span>
154+
{option.type.name}: {option.name}
155+
</span>
175156
))}
176157
</div>
177158
)}
@@ -215,12 +196,11 @@ const Cart = ({ cartItems, cartCount }: CartProps) => {
215196
</div>
216197
</div>
217198

218-
{/* Order Summary */}
219199
<div className="lg:col-span-1">
220200
<div className="rounded-lg bg-white p-6 shadow-sm">
221201
<h2 className="mb-4 text-lg font-semibold text-gray-800">Order Summary</h2>
222202
<div className="space-y-3">
223-
<div className="flex justify-between">
203+
<div className="text-black flex justify-between">
224204
<span className="text-gray-600">Subtotal</span>
225205
<span className="font-medium">${subtotal.toFixed(2)}</span>
226206
</div>

0 commit comments

Comments
 (0)