-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed.php
More file actions
220 lines (181 loc) · 11.8 KB
/
Copy pathseed.php
File metadata and controls
220 lines (181 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php
/**
* Database Seeder - Demo Data
* Run once: http://task1.test/seed.php
*/
require_once 'config/database.php';
$db = getDB();
echo "<h2>ShopAlpha Database Seeder</h2><pre>";
// ============================
// Categories
// ============================
$categories = [
['Electronics', 'electronics'],
['Clothing', 'clothing'],
['Home & Kitchen', 'home-kitchen'],
['Accessories', 'accessories'],
];
foreach ($categories as $cat) {
$stmt = $db->prepare("INSERT IGNORE INTO categories (name, slug) VALUES (?, ?)");
$stmt->execute($cat);
}
echo "✅ Categories seeded\n";
// Get category IDs
$catIds = [];
$stmt = $db->query("SELECT id, slug FROM categories");
foreach ($stmt->fetchAll() as $row) {
$catIds[$row['slug']] = $row['id'];
}
// ============================
// Products
// ============================
$products = [
// Electronics
[$catIds['electronics'], 'Wireless Bluetooth Headphones', 'wireless-bluetooth-headphones',
'Premium noise-cancelling wireless headphones with 30-hour battery life, deep bass, and crystal-clear audio. Perfect for music lovers and professionals.',
79.99, 'https://images.unsplash.com/photo-1505740420928-5e560c06d30e?w=500&h=500&fit=crop', 25, 1],
[$catIds['electronics'], 'Smart Watch Pro', 'smart-watch-pro',
'Feature-packed smartwatch with heart rate monitoring, GPS tracking, sleep analysis, and 7-day battery. Water-resistant up to 50 meters.',
199.99, 'https://images.unsplash.com/photo-1523275335684-37898b6baf30?w=500&h=500&fit=crop', 15, 1],
[$catIds['electronics'], 'Portable Bluetooth Speaker', 'portable-bluetooth-speaker',
'Waterproof portable speaker with 360° surround sound, 12-hour playtime, and built-in microphone for hands-free calls.',
49.99, 'https://images.unsplash.com/photo-1608043152269-423dbba4e7e1?w=500&h=500&fit=crop', 30, 0],
// Clothing
[$catIds['clothing'], 'Classic Denim Jacket', 'classic-denim-jacket',
'Timeless denim jacket crafted from premium cotton. Versatile style that pairs with everything from tees to dresses.',
89.99, 'https://images.unsplash.com/photo-1576995853123-5a10305d93c0?w=500&h=500&fit=crop', 20, 1],
[$catIds['clothing'], 'Premium Cotton T-Shirt', 'premium-cotton-tshirt',
'100% organic cotton crew-neck t-shirt. Pre-shrunk, soft, and breathable. Available in multiple colors.',
29.99, 'https://images.unsplash.com/photo-1521572163474-6864f9cf17ab?w=500&h=500&fit=crop', 50, 0],
[$catIds['clothing'], 'Running Sneakers', 'running-sneakers',
'Lightweight running sneakers with responsive cushioning and breathable mesh upper. Engineered for comfort on every run.',
129.99, 'https://images.unsplash.com/photo-1542291026-7eec264c27ff?w=500&h=500&fit=crop', 18, 1],
// Home & Kitchen
[$catIds['home-kitchen'], 'Ceramic Coffee Mug Set', 'ceramic-coffee-mug-set',
'Set of 4 handcrafted ceramic mugs in earth tones. Microwave and dishwasher safe. 12oz capacity each.',
34.99, 'https://images.unsplash.com/photo-1514228742587-6b1558fcca3d?w=500&h=500&fit=crop', 40, 0],
[$catIds['home-kitchen'], 'Stainless Steel Water Bottle', 'stainless-steel-water-bottle',
'Double-walled vacuum insulated bottle. Keeps drinks cold for 24 hours or hot for 12 hours. BPA-free, 750ml.',
24.99, 'https://images.unsplash.com/photo-1602143407151-7111542de6e8?w=500&h=500&fit=crop', 60, 0],
[$catIds['home-kitchen'], 'LED Desk Lamp', 'led-desk-lamp',
'Modern LED desk lamp with adjustable brightness, color temperature control, and USB charging port. Energy efficient.',
59.99, 'https://images.unsplash.com/photo-1507473885765-e6ed057ab3fe?w=500&h=500&fit=crop', 22, 1],
// Accessories
[$catIds['accessories'], 'Leather Wallet', 'leather-wallet',
'Genuine leather bifold wallet with RFID blocking technology. Features 8 card slots, 2 bill compartments, and ID window.',
44.99, 'https://images.unsplash.com/photo-1627123424574-724758594e93?w=500&h=500&fit=crop', 35, 0],
[$catIds['accessories'], 'Aviator Sunglasses', 'aviator-sunglasses',
'Classic aviator sunglasses with UV400 protection and polarized lenses. Gold metal frame with gradient tint.',
59.99, 'https://images.unsplash.com/photo-1572635196237-14b3f281503f?w=500&h=500&fit=crop', 28, 1],
[$catIds['accessories'], 'Canvas Backpack', 'canvas-backpack',
'Durable canvas backpack with padded laptop compartment (fits up to 15"), multiple pockets, and water-resistant coating.',
69.99, 'https://images.unsplash.com/photo-1553062407-98eeb64c6a62?w=500&h=500&fit=crop', 16, 1],
];
$stmt = $db->prepare(
"INSERT IGNORE INTO products (category_id, name, slug, description, price, image, stock, featured)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
);
foreach ($products as $p) {
$stmt->execute($p);
}
echo "✅ " . count($products) . " products seeded\n";
// ============================
// Test User
// ============================
$testPassword = password_hash('password123', PASSWORD_BCRYPT);
$stmt = $db->prepare(
"INSERT IGNORE INTO users (full_name, email, password, phone, address, is_admin) VALUES (?, ?, ?, ?, ?, 0)"
);
$stmt->execute(['Test User', 'test@example.com', $testPassword, '+233200000000', '123 Main Street, Accra, Ghana']);
echo "✅ Test user seeded (test@example.com / password123)\n";
// ============================
// Admin User
// ============================
$adminPassword = password_hash('admin123', PASSWORD_BCRYPT);
$stmt = $db->prepare(
"INSERT IGNORE INTO users (full_name, email, password, phone, address, is_admin) VALUES (?, ?, ?, ?, ?, 1)"
);
$stmt->execute(['Admin User', 'admin@shopalpha.com', $adminPassword, '+123456789', 'Admin Head Office']);
echo "✅ Admin user seeded (admin@shopalpha.com / admin123)\n";
// ============================
// Additional Sample Users
// ============================
$extraUsers = [
['Sarah Mensah', 'sarah@example.com', password_hash('password123', PASSWORD_BCRYPT), '+233201111111', '45 Oxford Street, Accra'],
['Kwame Asante', 'kwame@example.com', password_hash('password123', PASSWORD_BCRYPT), '+233202222222', '12 Liberation Road, Kumasi'],
['Ama Osei', 'ama@example.com', password_hash('password123', PASSWORD_BCRYPT), '+233203333333', '78 Beach Avenue, Takoradi'],
];
$stmtUser = $db->prepare(
"INSERT IGNORE INTO users (full_name, email, password, phone, address, is_admin) VALUES (?, ?, ?, ?, ?, 0)"
);
foreach ($extraUsers as $u) {
$stmtUser->execute($u);
}
echo "✅ Extra sample users seeded\n";
// ============================
// Seed Reviews
// ============================
$userIds = [];
$stmt = $db->query("SELECT id, email FROM users");
foreach ($stmt->fetchAll() as $row) {
$userIds[$row['email']] = $row['id'];
}
// Get product IDs
$productsList = [];
$stmt = $db->query("SELECT id, slug FROM products");
foreach ($stmt->fetchAll() as $row) {
$productsList[$row['slug']] = $row['id'];
}
$reviews = [
// Wireless Bluetooth Headphones
[$productsList['wireless-bluetooth-headphones'], $userIds['test@example.com'], 5, 'Absolutely love these! The sound is clear and noise cancelling works wonders.'],
[$productsList['wireless-bluetooth-headphones'], $userIds['admin@shopalpha.com'], 4, 'Very solid performance. Comfortable to wear for hours.'],
[$productsList['wireless-bluetooth-headphones'], $userIds['sarah@example.com'], 5, 'Best headphones I have ever owned. The battery lasts all week.'],
// Smart Watch Pro
[$productsList['smart-watch-pro'], $userIds['test@example.com'], 4, 'Great battery life and clear screen. Accurate heart rate monitor.'],
[$productsList['smart-watch-pro'], $userIds['kwame@example.com'], 5, 'Worth every penny. The sleep tracking has improved my rest schedule.'],
[$productsList['smart-watch-pro'], $userIds['ama@example.com'], 3, 'Decent smartwatch but the app could use some improvements.'],
// Portable Bluetooth Speaker
[$productsList['portable-bluetooth-speaker'], $userIds['test@example.com'], 5, 'Incredible sound for such a small speaker! Totally waterproof.'],
[$productsList['portable-bluetooth-speaker'], $userIds['admin@shopalpha.com'], 4, 'Great for poolside parties. Connects easily and stays paired.'],
[$productsList['portable-bluetooth-speaker'], $userIds['sarah@example.com'], 5, 'Bought this for beach trips and it is amazing.'],
// Classic Denim Jacket
[$productsList['classic-denim-jacket'], $userIds['sarah@example.com'], 5, 'Perfect fit and the material is high quality. Gets compliments everywhere.'],
[$productsList['classic-denim-jacket'], $userIds['kwame@example.com'], 4, 'Classic look that never goes out of style. Runs slightly large.'],
// Premium Cotton T-Shirt
[$productsList['premium-cotton-tshirt'], $userIds['test@example.com'], 3, 'Good quality but the color faded a bit after a few washes.'],
[$productsList['premium-cotton-tshirt'], $userIds['ama@example.com'], 4, 'Soft and breathable. Perfect for hot weather.'],
// Running Sneakers
[$productsList['running-sneakers'], $userIds['kwame@example.com'], 5, 'Very comfortable for long runs. Great cushioning and support.'],
[$productsList['running-sneakers'], $userIds['admin@shopalpha.com'], 4, 'Solid sneakers for daily training. True to size.'],
[$productsList['running-sneakers'], $userIds['test@example.com'], 4, 'Lightweight and responsive. My knees feel better after switching.'],
// Ceramic Coffee Mug Set
[$productsList['ceramic-coffee-mug-set'], $userIds['ama@example.com'], 5, 'Beautiful mugs! The earth tones match my kitchen perfectly.'],
[$productsList['ceramic-coffee-mug-set'], $userIds['sarah@example.com'], 4, 'Nice weight and the perfect size for morning coffee.'],
// Stainless Steel Water Bottle
[$productsList['stainless-steel-water-bottle'], $userIds['test@example.com'], 5, 'Keeps ice water cold all day. No condensation on the outside.'],
[$productsList['stainless-steel-water-bottle'], $userIds['kwame@example.com'], 4, 'Sturdy build and leak-proof lid. Great for hiking.'],
[$productsList['stainless-steel-water-bottle'], $userIds['admin@shopalpha.com'], 5, 'Best water bottle I have owned. Worth the price.'],
// LED Desk Lamp
[$productsList['led-desk-lamp'], $userIds['ama@example.com'], 4, 'Love the adjustable color temperatures. The USB port is handy.'],
[$productsList['led-desk-lamp'], $userIds['sarah@example.com'], 3, 'Good lamp but the base could be more stable.'],
// Leather Wallet
[$productsList['leather-wallet'], $userIds['kwame@example.com'], 5, 'Slim and elegant. RFID blocking gives peace of mind.'],
[$productsList['leather-wallet'], $userIds['test@example.com'], 4, 'Great quality leather that smells amazing. Ages nicely.'],
[$productsList['leather-wallet'], $userIds['ama@example.com'], 4, 'Bought as a gift and the recipient loved it.'],
// Aviator Sunglasses
[$productsList['aviator-sunglasses'], $userIds['sarah@example.com'], 5, 'Classic style and the polarization makes driving much safer.'],
[$productsList['aviator-sunglasses'], $userIds['admin@shopalpha.com'], 4, 'Good build quality. Lightweight frame.'],
// Canvas Backpack
[$productsList['canvas-backpack'], $userIds['kwame@example.com'], 5, 'Perfect for campus. Fits my laptop and books with room to spare.'],
[$productsList['canvas-backpack'], $userIds['test@example.com'], 4, 'Stylish and durable. The water-resistant coating really works.'],
[$productsList['canvas-backpack'], $userIds['ama@example.com'], 5, 'Love the multiple compartments. Great for travel.'],
];
foreach ($reviews as $rev) {
$stmt = $db->prepare("INSERT IGNORE INTO reviews (product_id, user_id, rating, comment) VALUES (?, ?, ?, ?)");
$stmt->execute($rev);
}
echo "✅ " . count($reviews) . " product reviews seeded\n";
echo "\n🎉 Seeding complete!\n";
echo "</pre>";
echo '<p><a href="index.php" style="color:#3b82f6;font-weight:bold">→ Go to ShopAlpha</a></p>';