Skip to content

Commit 2fe2ae9

Browse files
committedFeb 5, 2025
creating cart crud
1 parent 84327cc commit 2fe2ae9

17 files changed

+827
-54
lines changed
 

‎controllers/CartController.php

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
namespace app\controllers;
4+
use app\core\Application;
5+
use app\core\Controller;
6+
use app\core\Request;
7+
use app\core\Response;
8+
use app\models\cart;
9+
10+
class CartController extends Controller {
11+
12+
// add product to the cart
13+
public function addToCartController (Request $request, Response $response) {
14+
$user_id = Application::$app->session->get('customer');
15+
16+
if (!$user_id) {
17+
Application::$app->response->redirect('/customer-login');
18+
}
19+
20+
$product_id = $request->getBody()['product_id'];
21+
$quantity = $request->getBody()['quantity'] ?? 1;
22+
23+
if (!$product_id) {
24+
Application::$app->session->setFlash('error','no id getting ');
25+
}
26+
27+
$cart = new Cart();
28+
if ($cart->addToCart($user_id, $product_id, $quantity)) {
29+
Application::$app->session->setFlash('success','Product add to cart');
30+
// http_response_code(200); // Set HTTP status code
31+
// header('Content-Type: application/json'); // Set response header
32+
// echo json_encode(['message' => 'Product added to cart']);
33+
Application::$app->response->redirect('/market-place-home');
34+
35+
} else {
36+
Application::$app->session->setFlash('error','Prodcut add to cart fail');
37+
// http_response_code(400); // Set HTTP status code
38+
// header('Content-Type: application/json'); // Set response header
39+
// echo json_encode(['message' => 'Failed to add product to cart']);
40+
Application::$app->response->redirect('/market-place-home');
41+
}
42+
}
43+
44+
//function to retrive products
45+
public function viewCart() {
46+
if (!Application::$app->session->get('customer')) {
47+
Application::$app->response->redirect('/customer-login');
48+
}
49+
50+
$user_id = Application::$app->session->get('customer');
51+
$cart = new Cart();
52+
$cartItems = $cart->getCartItems($user_id);
53+
54+
if(empty($cartItems)){
55+
Application::$app->session->setFlash('error','Cart is empty');
56+
Application::$app->response->redirect('/market-place-home');
57+
}
58+
59+
$this->setLayout('auth');
60+
return $this->render('service-centre/view-cart', ['cartItems'=> $cartItems]);
61+
62+
}
63+
64+
//function to remove cart items
65+
public function removeItemsFromCart(Request $request, Response $response) {
66+
if (!Application::$app->session->get('customer')) {
67+
Application::$app->session->setFlash('error','Please login first');
68+
Application::$app->response->redirect('/customer-login');
69+
}
70+
$user_id = Application::$app->session->get('customer');
71+
$product_id = $request->getBody()['product_id'];
72+
73+
if (!$product_id) {
74+
Application::$app->session->setFlash('error','Select item to remove');
75+
}
76+
$cart = new Cart();
77+
if ($cart->removeCartItem($user_id, $product_id)) {
78+
Application::$app->response->redirect('/view-cart');
79+
Application::$app->session->setFlash('success','Product remove successfully');
80+
} else {
81+
Application::$app->session->setFlash('error','Product remove failed, try again');
82+
}
83+
}
84+
85+
}

‎controllers/ProductController.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,27 @@ public function delete(Request $request){
135135
}
136136

137137

138-
}
138+
public function filterProductByCategory(Request $request, Response $response) {
139+
//get category by the params
140+
141+
$category = $_GET['category'] ?? 'all';
142+
143+
if ($category === 'all') {
144+
$products = (new Product())->getAllProducts();
145+
} else {
146+
$products = (new Product())->getProductsByCategory($category);
147+
}
139148

149+
140150

151+
if ($products) {
152+
$this->setLayout('auth');
153+
return $this->render('service-centre/market-place-home', [
154+
'products'=> $products,
155+
]);
156+
}
157+
}
158+
159+
}
141160

142161
?>

‎controllers/ServiceCentreController.php

+6
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ public function serviceCenterMessages()
124124
return $this->render('/service-centre/service-center-messages');
125125
}
126126

127+
public function cart()
128+
{
129+
$this->setLayout('auth');
130+
return $this->render('/service-centre/view-cart');
131+
}
132+
127133
public function viewServiceCenterProfile($id)
128134
{
129135

‎core/DbModel.php

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ abstract public function attributes(): array;
1111
abstract public function primaryKey(): string;
1212

1313

14+
// protected Database $db;
15+
16+
// public function __construct(){
17+
// $this->db = Application::$app->db;
18+
// }
19+
20+
1421
public function save()
1522
{
1623

‎models/Product.php

+25-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Product extends DbModel
1111
public string $description = '';
1212
public float $price;
1313
public string $media = '';
14+
public string $category;
1415
public ?string $created_at = null;
1516
public ?string $updated_at = null;
1617

@@ -21,7 +22,7 @@ public function tableName(): string
2122

2223
public function attributes(): array
2324
{
24-
return ['ser_cen_id', 'description', 'price', 'media'];
25+
return ['ser_cen_id', 'description', 'price', 'media', 'category'];
2526
}
2627
public function primaryKey(): string
2728
{
@@ -101,7 +102,7 @@ public function editProduct(): bool
101102
{
102103
$sql = "
103104
UPDATE product
104-
SET description = :description, price = :price, media = CASE WHEN :media = '' THEN media ELSE :media END, updated_at = NOW()
105+
SET description = :description, price = :price, category = :category, media = CASE WHEN :media = '' THEN media ELSE :media END, updated_at = NOW()
105106
WHERE product_id = :product_id AND ser_cen_id = :ser_cen_id
106107
";
107108

@@ -111,6 +112,7 @@ public function editProduct(): bool
111112
$stmt->bindValue(':media', $this->media);
112113
$stmt->bindValue(':product_id', $this->product_id);
113114
$stmt->bindValue(':ser_cen_id', $this->ser_cen_id);
115+
$stmt->bindValue(':category', $this->category);
114116

115117
// Debugging: Check SQL and parameters
116118
// var_dump([
@@ -163,6 +165,27 @@ public function updateRules(): array
163165

164166
];
165167
}
168+
169+
public function getProductsByCategory(string $category) {
170+
try {
171+
172+
$sql = 'SELECT p.*, s.name AS seller_name
173+
FROM product p
174+
JOIN service_center s ON p.ser_cen_id = s.ser_cen_id
175+
WHERE p.category = :category
176+
ORDER BY p.created_at DESC';
177+
178+
$stmt = self::prepare($sql);
179+
$stmt->bindValue(':category', $category);
180+
$stmt->execute();
181+
182+
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
183+
184+
} catch (\Exception $e) {
185+
error_log($e->getMessage());
186+
return [];
187+
}
188+
}
166189
}
167190

168191
?>

‎models/cart.php

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?php
2+
3+
namespace app\models;
4+
use app\core\DbModel;
5+
use app\core\Application;
6+
7+
class Cart extends DbModel
8+
{
9+
public int $id;
10+
public int $cart_id;
11+
public int $user_id;
12+
public int $product_id;
13+
public int $quantity;
14+
public ?string $created_at = null;
15+
public ?string $updated_at = null;
16+
17+
public function tableName(): string {
18+
return 'cart_items';
19+
}
20+
21+
public function attributes(): array {
22+
return ['cart_id','product_id','quantity'];
23+
}
24+
25+
public function primaryKey(): string {
26+
return 'id';
27+
}
28+
29+
// add a product to cart
30+
public function addToCart(int $user_id, int $product_id, int $quantity) {
31+
//get the cart_id for the user
32+
$sql = 'SELECT cart_id FROM customer WHERE cus_id = :cus_id';
33+
$stmt = self::prepare($sql);
34+
$stmt->bindValue(':cus_id', $user_id);
35+
$stmt->execute();
36+
$cart = $stmt->fetchColumn();
37+
38+
//if user does not have an cart, then create a one
39+
if (!$cart) {
40+
// $this->db->query("INSERT INTO cart (user_id) VALUES (?)", [$user_id]);
41+
// $cart = $this->db->lastInsertId();
42+
// $this->db->query("UPDATE customer SET cart_id = ? WHERE cus_id = ?", [$cart, $user_id]);
43+
$stmt = Application::$app->db->pdo->prepare("INSERT INTO cart (user_id) VALUES (?)");
44+
$stmt->execute([$user_id]);
45+
46+
// Get last inserted cart_id
47+
$cart = Application::$app->db->pdo->lastInsertId();
48+
49+
// Update customer table with the cart_id
50+
$stmt = Application::$app->db->pdo->prepare("UPDATE customer SET cart_id = ? WHERE cus_id = ?");
51+
$stmt->execute([$cart, $user_id]);
52+
}
53+
// $existing = $this->db->query("SELECT id FROM cart_items WHERE cart_id = ? AND product_id = ?", [$cart, $product_id])->fetchColumn();
54+
// Check if the product is already in the cart
55+
$stmt = Application::$app->db->pdo->prepare("SELECT id FROM cart_items WHERE cart_id = ? AND product_id = ?");
56+
$stmt->execute([$cart, $product_id]);
57+
$existing = $stmt->fetchColumn();
58+
59+
if ($existing) {
60+
// $this->db->query("UPDATE cart_items SET quantity = quantity + ? WHERE id = ?", [$quantity, $existing]);
61+
// Update quantity if product exists in cart
62+
$stmt = Application::$app->db->pdo->prepare("UPDATE cart_items SET quantity = quantity + ? WHERE id = ?");
63+
$stmt->execute([$quantity, $existing]);
64+
} else {
65+
// $this->db->query("INSERT INTO cart_items (cart_id, product_id, quantity) VALUES (?, ?, ?)", [$cart, $product_id, $quantity]);
66+
// Insert new product into cart_items
67+
$stmt = Application::$app->db->pdo->prepare("INSERT INTO cart_items (cart_id, product_id, quantity) VALUES (?, ?, ?)");
68+
$stmt->execute([$cart, $product_id, $quantity]);
69+
}
70+
71+
return true;
72+
73+
}
74+
75+
//get all items for a specific user
76+
public function getCartItems(int $user_id) {
77+
$db = Application::$app->db->pdo;
78+
$stmt = $db->prepare("
79+
SELECT ci.id, ci.product_id, ci.quantity, p.description, p.price, p.media
80+
FROM cart_items ci
81+
JOIN cart c ON ci.cart_id = c.id
82+
JOIN product p ON ci.product_id = p.product_id
83+
WHERE c.user_id = ?
84+
");
85+
$stmt->execute([$user_id]);
86+
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
87+
}
88+
89+
//model to remove items from the cart
90+
public function removeCartItem(int $user_id, int $product_id) {
91+
$db = Application::$app->db->pdo;
92+
93+
$stmt = $db->prepare("SELECT id FROM cart WHERE user_id = ?");
94+
$stmt->execute([$user_id]);
95+
$cart = $stmt->fetch(\PDO::FETCH_ASSOC);
96+
97+
if (!$cart) {
98+
return false;
99+
}
100+
101+
$cart_id = $cart['id'];
102+
103+
$stmt = $db->prepare("DELETE FROM cart_items WHERE cart_id = ? AND product_id = ?");
104+
return $stmt->execute([$cart_id, $product_id]);
105+
}
106+
107+
public function rules(): array
108+
{
109+
return [
110+
111+
];
112+
}
113+
114+
public function updateRules(): array
115+
{
116+
return [
117+
118+
];
119+
}
120+
121+
}

‎public/css/service-center/add-products.css

+27
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,33 @@ table tr:hover {
162162
background-color: #e9ecef;
163163
}
164164

165+
.category-select {
166+
width: 100%;
167+
max-width: 300px;
168+
padding: 10px;
169+
font-size: 14px;
170+
border: 2px solid #ccc;
171+
border-radius: 5px;
172+
background-color: #fff;
173+
color: #333;
174+
cursor: pointer;
175+
outline: none;
176+
transition: border-color 0.3s ease-in-out;
177+
}
178+
179+
.category-select:focus {
180+
border-color: #007bff;
181+
}
182+
183+
option {
184+
font-size: 14px;
185+
padding: 10px;
186+
}
187+
188+
.category-select:hover {
189+
border-color: #0056b3;
190+
}
191+
165192
/* Responsive Table */
166193
@media (max-width: 768px) {
167194
table {

‎public/css/service-center/marketplace.css

+44
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,47 @@
7171
.category-list li a:hover {
7272
text-decoration: underline;
7373
}
74+
75+
.marketplace-container {
76+
display: flex;
77+
gap: 20px;
78+
padding: 20px;
79+
}
80+
81+
.categories-sidebar {
82+
width: 250px;
83+
background-color: #f8f9fa;
84+
padding: 15px;
85+
border-radius: 8px;
86+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
87+
}
88+
89+
.categories-title {
90+
font-size: 1.2rem;
91+
margin-bottom: 15px;
92+
}
93+
94+
.categories-list {
95+
list-style: none;
96+
padding: 0;
97+
margin-top: 10px;
98+
}
99+
100+
.categories-list:hover {
101+
color: #007bff;
102+
}
103+
104+
.category-link {
105+
text-decoration: none;
106+
color: #333;
107+
display: block;
108+
padding: 8px 0;
109+
margin-top: 20px;
110+
margin-bottom: 20px;
111+
transition: color 0.3s ease;
112+
113+
}
114+
115+
.category-link:hover {
116+
color: #007bff;
117+
}

‎public/css/service-center/update-product.css

+27
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,30 @@ form button[type="submit"]:hover {
7979
padding: 5px; /* Add padding inside the border */
8080
background-color: #fff; /* Add a white background for contrast */
8181
}
82+
83+
.category-select {
84+
width: 100%;
85+
max-width: 300px;
86+
padding: 10px;
87+
font-size: 14px;
88+
border: 2px solid #ccc;
89+
border-radius: 5px;
90+
background-color: #fff;
91+
color: #333;
92+
cursor: pointer;
93+
outline: none;
94+
transition: border-color 0.3s ease-in-out;
95+
}
96+
97+
.category-select:focus {
98+
border-color: #007bff;
99+
}
100+
101+
option {
102+
font-size: 14px;
103+
padding: 10px;
104+
}
105+
106+
.category-select:hover {
107+
border-color: #0056b3;
108+
}

‎public/index.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require_once __DIR__ . '/../vendor/autoload.php';
44

55
use app\controllers\AuthController;
6+
use app\controllers\CartController;
67
use app\core\Application;
78
use app\controllers\SiteController;
89
use app\controllers\CustomerController;
@@ -92,6 +93,9 @@
9293
$app->router->get('/card-details', [ServiceCentreController::class, 'cardDetails']);
9394
$app->router->get('/service-centre-map', [ServiceCentreController::class, 'serviceCentreMap']);
9495
$app->router->get('/service-center-payment-details', [ServiceCentreController::class, 'serviceCenterPaymentDetails']);
96+
$app->router->get('/service-center-profile/{id}', [ServiceCentreController::class, 'viewServiceCenterProfile']);
97+
$app->router->get('/view-cart', [CartController::class, 'viewCart']);
98+
$app->router->post('/remove-from-cart', [CartController::class, 'removeItemsFromCart']);
9599

96100

97101
/* Routes related to the product (service center) */
@@ -103,6 +107,8 @@
103107
$app->router->get('/service-center-update-product', [ServiceCentreController::class, 'update']);
104108
$app->router->post('/service-center-update-product', [ProductController::class, 'update']);
105109
$app->router->post('/service-center-delete-product', [ProductController::class, 'delete']);
110+
$app->router->get('/get-product-by-category', [ProductController::class, 'filterProductByCategory']);
111+
$app->router->post('/add-to-cart', [CartController::class, 'addToCartController']);
106112

107113
/* Customer Routes */
108114
$app->router->get('/customer-dashboard', [CustomerController::class, 'customerDashboard']);
@@ -117,7 +123,6 @@
117123
$app->router->get('/geolocation-service-centres', [CustomerController::class, 'getServiceCentresGeocoding']);
118124
$app->router->get('/customer-location', [CustomerController::class, 'customerLocation']);
119125
$app->router->get('/technician-profile/{id}', [TechnicianController::class, 'viewTechnicianProfile']);
120-
$app->router->get('/service-center-profile/{id}', [ServiceCentreController::class, 'viewServiceCenterProfile']);
121126
$app->router->post('/cus-tech-req', [CustomerController::class, 'cusTechReq']);
122127
$app->router->post('/delete-cus-tech-req', [CustomerController::class, 'deleteCusTechReq']);
123128
$app->router->get('/customer-messages', [CustomerController::class, 'customerMessages']);

‎public/js/service-center/cart.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
document.querySelectorAll('.add-to-cart-btn').forEach(button => {
2+
button.addEventListener('click', ()=>{
3+
const product_id = button.getAttribute('data-product-id');
4+
console.log(product_id)
5+
6+
fetch('/add-to-cart', {
7+
method: 'POST',
8+
headers: {
9+
'Content-Type': 'application/json',
10+
},
11+
body: JSON.stringify({product_id: product_id, quantity: 1})
12+
})
13+
.then(response => response.json())
14+
.then(data => {
15+
alert(data.message);
16+
})
17+
.catch(error => console.error('Error:', error))
18+
})
19+
})
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
document.querySelectorAll('.category-link').forEach(link => {
2+
link.addEventListener('click', (e) => {
3+
e.preventDefault(); // Prevent default link behavior
4+
5+
const selectedCategory = link.getAttribute('data-category');
6+
const productsGrid = document.getElementById('products-grid');
7+
8+
// Fetch products from the server
9+
fetch(`/get-products-by-category?category=${selectedCategory}`)
10+
.then(response => response.json())
11+
.then(products => {
12+
// Clear existing products
13+
productsGrid.innerHTML = '';
14+
15+
// Render new products
16+
if (products.length > 0) {
17+
products.forEach(product => {
18+
productsGrid.innerHTML += `
19+
<div class="product-card">
20+
<img class="product-image"
21+
src="/assets/uploads/${product.media}"
22+
alt="Product Image">
23+
<div class="product-details">
24+
<h2 class="product-title">${product.description}</h2>
25+
<p class="product-price">Rs. ${product.price}</p>
26+
<p class="product-seller">Sold by: ${product.seller_name}</p>
27+
</div>
28+
<a href="/check-out-page" class="product-btn">View Details</a>
29+
</div>
30+
`;
31+
});
32+
} else {
33+
productsGrid.innerHTML = '<p class="no-products">No products are available in this category.</p>';
34+
}
35+
})
36+
.catch(error => console.error('Error fetching products:', error));
37+
});
38+
});

‎views/customer/components/sidebar.php

+10
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@
7070
</li>
7171
7272
73+
<li>
74+
<a href="/market-place-home">
75+
<span class="icon">
76+
<ion-icon name="chatbubble-outline"></ion-icon>
77+
</span>
78+
<span class="title">Market</span>
79+
</a>
80+
</li>
81+
82+
7383
<li>
7484
<a href="/customer-settings">
7585
<span class="icon">

‎views/service-centre/create-product.php

+15
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@
4747
<label for="media">Upload Media:</label>
4848
<input type="file" id="media" name="media" accept="image/*,video/*" required>
4949

50+
<label for="category">Category:</label>
51+
<select class="category-select" name="category" id="category" required>
52+
<option value="">Select a category</option>
53+
<option value="Tools">Tools</option>
54+
<option value="Engine & Transmission">Engine & Transmission</option>
55+
<option value="Brakes & Suspension">Brakes & Suspension</option>
56+
<option value="Electrical & Electronics">Electrical & Electronics</option>
57+
<option value="Body Parts & Exterior">Body Parts & Exterior</option>
58+
<option value="Tires & Wheels">Tires & Wheels</option>
59+
<option value="Interior Accessories">Interior Accessories</option>
60+
<option value="Fluids & Maintenance">Fluids & Maintenance</option>
61+
<option value="Performance & Upgrades">Performance & Upgrades</option>
62+
<option value="Safety & Security">Safety & Security</option>
63+
</select>
64+
5065
<button type="submit">Add Product</button>
5166
</form>
5267

‎views/service-centre/market-place-home.php

+95-50
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,39 @@
2626

2727
<body>
2828
<nav class="container">
29-
3029
<header class="d-flex flex-wrap align-items-center justify-content-center justify-content-md-between py-3">
3130
<div class="col-md-3 mb-2 mb-md-0">
3231
<a href="/" class="d-inline-flex link-body-emphasis text-decoration-none">
3332
<img class="logo-img" src="/assets/shopping-cart_market-place.png">
3433
</a>
3534
</div>
3635

37-
3836
<ul class="nav col-12 col-md-auto mb-2 justify-content-center mb-md-0">
3937
<li><a href="/" class="nav-link px-2 link-secondary">Home</a></li>
4038
<li><a href="/service-centre-landing" class="nav-link px-2">Service Centre</a></li>
41-
<!-- <li><a href="#" class="nav-link px-2">FAQs</a></li>-->
4239
<li><a href="/about-us" class="nav-link px-2">About</a></li>
43-
<li><a href="#" class="nav-link px-2">
40+
<li><a href="/view-cart" class="nav-link px-2">
4441
<ion-icon name="cart-outline"></ion-icon>
4542
</a></li>
4643
</ul>
4744

48-
<!-- --><?php //if (Application::isGuestTechnician()): ?>
49-
<!-- <div class="col-md-3 text-center">-->
50-
<!-- <button type="button" class="btn btn-outline-primary me-2"><a class="text-decoration-none"-->
51-
<!-- href="/select-user-login">Login</a>-->
52-
<!-- </button>-->
53-
<!-- <button type="button" class="btn btn-primary"><a class="text-decoration-none"-->
54-
<!-- href="/select-user-sign-up">Sign Up</a></button>-->
55-
<!-- </div>-->
56-
<!-- --><?php //else: ?>
57-
<!-- <div class="col-md-3 text-center">-->
58-
<!---->
59-
<!-- </div>-->
60-
<!-- --><?php //endif; ?>
6145
<form class="search-bar">
6246
<input class="search-bar-enter" type="search" placeholder="Search" aria-label="Search">
6347
<button class="btn" type="submit">Search</button>
6448
</form>
49+
<h6>
50+
<?php
51+
52+
$username = strtoupper(Application::$app->customer->{'name'});
53+
54+
if ($username) {
55+
echo $username;
56+
} else {
57+
echo '<button class="btn" onclick="window.location.href=\'/customer-login\'" style="margin-right:20px;">Login</button>';
58+
}
59+
60+
?>
61+
</h6>
6562
</header>
6663
</nav>
6764

@@ -75,31 +72,58 @@
7572
</div>
7673
</section>
7774

78-
79-
<section class="marketplace">
80-
<h1 class="marketplace-title">Available Products</h1>
81-
<div class="products-grid">
82-
<?php if (!empty($products)): ?>
83-
<?php foreach ($products as $product): ?>
84-
<div class="product-card">
85-
<img class="product-image"
86-
src="/assets/uploads/<?php echo htmlspecialchars($product['media']); ?>"
87-
alt="Product Image">
88-
<div class="product-details">
89-
<h2 class="product-title"><?php echo htmlspecialchars($product['description']); ?></h2>
90-
<p class="product-price">Rs. <?php echo htmlspecialchars($product['price']); ?></p>
91-
<p class="product-seller">Sold by: <?php echo htmlspecialchars($product['seller_name']); ?></p>
92-
</div>
93-
<a href="/check-out-page" class="product-btn">View Details</a>
75+
<!-- Main Content with Sidebar -->
76+
<section class="marketplace-container">
77+
<!-- Categories Sidebar -->
78+
<aside class="categories-sidebar">
79+
<h3 class="categories-title">Product Categories</h3>
80+
<ul class="categories-list">
81+
<li><a href="/get-product-by-category?category=all" class="category-link" data-category="all" >All</a></li>
82+
<li><a href="/get-product-by-category?category=tools" class="category-link" data-category="tools" >Tools</a></li>
83+
<li><a href="/get-product-by-category?category=engine-transmission" class="category-link" data-category="engine-transmission" >Engine & Transmission</a></li>
84+
<li><a href="/get-product-by-category?category=brakes-suspension" class="category-link" data-category="brakes-suspension" >Brakes & Suspension</a></li>
85+
<li><a href="/get-product-by-category?category=electrical-electronics" class="category-link" data-category="electrical-electronics" >Electrical & Electronics</a></li>
86+
<li><a href="/get-product-by-category?category=body-parts-exterior" class="category-link" data-category="body-parts-exterior" >Body Parts & Exterior</a></li>
87+
<li><a href="/get-product-by-category?category=tires-wheels" class="category-link" data-category="tires-wheels" >Tires & Wheels</a></li>
88+
<li><a href="/get-product-by-category?category=interior-accessories" class="category-link" data-category="interior-accessories" >Interior Accessories</a></li>
89+
<li><a href="/get-product-by-category?category=fluids-maintenance" class="category-link" data-category="fluids-maintenance" >Fluids & Maintenance</a></li>
90+
<li><a href="/get-product-by-category?category=performance-upgrades" class="category-link" data-category="performance-upgrades" >Performance & Upgrades</a></li>
91+
<li><a href="/get-product-by-category?category=safety-security" class="category-link" data-category="safety-security" >Safety & Security</a></li>
92+
</ul>
93+
</aside>
94+
95+
<!-- Marketplace Products Section -->
96+
<div class="marketplace">
97+
<h1 class="marketplace-title">Available Products</h1>
98+
<div class="products-grid">
99+
<?php if (!empty($products)): ?>
100+
<?php foreach ($products as $product): ?>
101+
<div class="product-card">
102+
<img class="product-image"
103+
src="/assets/uploads/<?php echo htmlspecialchars($product['media']); ?>"
104+
alt="Product Image">
105+
<div class="product-details">
106+
<h2 class="product-title"><?php echo htmlspecialchars($product['description']); ?></h2>
107+
<p class="product-price">Rs. <?php echo htmlspecialchars($product['price']); ?></p>
108+
<p class="product-seller">Sold by: <?php echo htmlspecialchars($product['seller_name']); ?></p>
109+
<p>Product id: <?php echo htmlspecialchars($product['product_id']) ?></p>
110+
</div>
111+
<!-- <a href="/check-out-page" class="product-btn">View Details</a> -->
112+
<!-- <button class="add-to-cart-btn" data-product-id="<?php echo $product['product_id']; ?>">Add to Cart</button> -->
113+
<form action="/add-to-cart" method="post">
114+
<input type="hidden" name="product_id" value="<?php echo $product['product_id']; ?>">
115+
<button class="btn" style="color:black;" type="submit">Add to cart</button>
116+
</form>
94117
</div>
95118
<?php endforeach; ?>
96119
<?php else: ?>
97-
<p class="no-products">No products are available at the moment.</p>
120+
<p class="no-products">No products are available in this category.</p>
98121
<?php endif; ?>
99122
</div>
123+
</div>
100124
</section>
101125

102-
126+
<!-- Footer -->
103127
<div class="container-f">
104128
<footer class="py-5">
105129
<div class="row">
@@ -110,57 +134,78 @@
110134
<h5>Company</h5>
111135
<ul class="nav-f flex-column">
112136
<li class="nav-item-f mb-2"><a href="#" class="nav-link-f p-0 text-body-secondary">About Us</a></li>
113-
<li class="nav-item-f mb-2"><a href="#" class="nav-link-f p-0 text-body-secondary">Our Offerings</a>
114-
</li>
137+
<li class="nav-item-f mb-2"><a href="#" class="nav-link-f p-0 text-body-secondary">Our Offerings</a></li>
115138
</ul>
116139
</div>
117140

118141
<div class="col-6 col-md-2 mb-3">
119142
<h5>Products</h5>
120143
<ul class="nav flex-column">
121-
<li class="nav-item-f mb-2"><a href="#" class="nav-link-f p-0 text-body-secondary">Nearby
122-
Technicians</a></li>
123-
<li class="nav-item-f mb-2"><a href="#" class="nav-link-f p-0 text-body-secondary">Service
124-
Centers</a></li>
125-
<li class="nav-item-f mb-2"><a href="#" class="nav-link-f p-0 text-body-secondary">Service Center
126-
Marketplace</a></li>
144+
<li class="nav-item-f mb-2"><a href="#" class="nav-link-f p-0 text-body-secondary">Nearby Technicians</a></li>
145+
<li class="nav-item-f mb-2"><a href="#" class="nav-link-f p-0 text-body-secondary">Service Centers</a></li>
146+
<li class="nav-item-f mb-2"><a href="#" class="nav-link-f p-0 text-body-secondary">Service Center Marketplace</a></li>
127147
</ul>
128148
</div>
129149

130150
<div class="col-6 col-md-2 mb-3">
131151
<h5>Safety Measures</h5>
132152
<ul class="nav flex-column">
133153
<li class="nav-item-f mb-2"><a href="#" class="nav-link-f p-0 text-body-secondary">Safety</a></li>
134-
<li class="nav-item-f mb-2"><a href="#" class="nav-link-f p-0 text-body-secondary">Diversity and
135-
Inclusion</a></li>
154+
<li class="nav-item-f mb-2"><a href="#" class="nav-link-f p-0 text-body-secondary">Diversity and Inclusion</a></li>
136155
</ul>
137156
</div>
138-
139157
</div>
140158

141159
<div class="d-flex flex-column flex-sm-row justify-content-between py-4 my-4 mx-4 border-top">
142160
<p>© 2024 Fixme Technologies Inc.</p>
143161
<ul class="list-unstyled d-flex">
144162
<li class="ms-3"><a class="link-body-emphasis" href="#">
145163
<svg class="bi" width="24" height="24">
146-
<path d="M5.026 15c6.038 0 9.341-5.003 9.341-9.334 0-.14 0-.284-.009-.425A6.683 6.683 0 0 0 16 3.542a6.658 6.658 0 0 1-1.889.518A3.301 3.301 0 0 0 15.555 2a6.533 6.533 0 0 1-2.084.797 3.301 3.301 0 0 0-5.617 3.005A9.355 9.355 0 0 1 1.114 2.1a3.3 3.3 0 0 0 1.019 4.396A3.267 3.267 0 0 1 .64 6.575v.034a3.301 3.301 0 0 0 2.644 3.234 3.203 3.203 0 0 1-.865.115 3.23 3.23 0 0 1-.621-.059 3.305 3.305 0 0 0 3.067 2.281A6.588 6.588 0 0 1 0 13.027 9.286 9.286 0 0 0 5.031 15z"/>
147164
<use xlink:href="#twitter"></use>
148165
</svg>
149166
</a></li>
150167
<li class="ms-3"><a class="link-body-emphasis" href="#">
151168
<svg class="bi" width="24" height="24">
152-
<path d="M8 0C5.79 0 5.555.01 4.69.047a6.153 6.153 0 0 0-2.292.431 4.383 4.383 0 0 0-1.633 1.064A4.394 4.394 0 0 0 .048 4.69 6.154 6.154 0 0 0 0 6.977C0 7.445.002 7.805.005 8.128L.02 9.81v1.154c.003.352.006.729.006 1.104 0 .375-.003.752-.006 1.104v1.154c-.003.326-.005.687-.005 1.155 0 .642.027 1.192.125 1.684.099.492.264.939.518 1.33.22.333.514.616.87.857.33.226.706.41 1.12.556.466.166 1.065.239 1.747.263C5.805 16 6.287 16 8 16c1.713 0 2.195-.002 2.74-.014.682-.024 1.28-.097 1.746-.263a4.432 4.432 0 0 0 1.12-.556c.357-.241.65-.524.87-.857.253-.391.419-.838.518-1.33.098-.492.125-1.042.125-1.684 0-.469-.002-.83-.005-1.155v-1.154c-.003-.352-.006-.729-.006-1.104 0-.375.003-.752.006-1.104V9.81l.015-1.683c.003-.326.005-.687.005-1.155 0-.642-.027-1.192-.125-1.684a4.406 4.406 0 0 0-.518-1.33c-.22-.333-.514-.616-.87-.857a4.438 4.438 0 0 0-1.12-.556 6.163 6.163 0 0 0-1.746-.263C10.195.003 9.713.001 8 .001zm0 1.557c1.65 0 1.914.007 2.586.036.589.026 1.021.102 1.344.231.408.17.706.375.956.624.249.249.453.548.624.956.129.323.205.755.231 1.344.03.672.037.936.037 2.586 0 1.65-.007 1.914-.036 2.586-.026.589-.102 1.021-.231 1.344a2.764 2.764 0 0 1-.624.956 2.784 2.784 0 0 1-.956.624c-.323.129-.755.205-1.344.231-.672.03-.936.037-2.586.037-1.65 0-1.914-.007-2.586-.036-.589-.026-1.021-.102-1.344-.231a2.77 2.77 0 0 1-.956-.624 2.786 2.786 0 0 1-.624-.956c-.129-.323-.205-.755-.231-1.344-.03-.672-.037-.936-.037-2.586 0-1.65.007-1.914.036-2.586.026-.589.102-1.021.231-1.344.17-.408.375-.706.624-.956.249-.249.548-.453.956-.624.323-.129.755-.205 1.344-.231.672-.03.936-.037 2.586-.037zM8 3.292a4.706 4.706 0 1 0 0 9.411 4.706 4.706 0 0 0 0-9.411zm0 1.55a3.156 3.156 0 1 1 0 6.311 3.156 3.156 0 0 1 0-6.311zm4.566-.855a1.088 1.088 0 1 0 0 2.176 1.088 1.088 0 0 0 0-2.176z"/>
153169
<use xlink:href="#instagram"></use>
154170
</svg>
155171
</a></li>
156172
<li class="ms-3"><a class="link-body-emphasis" href="#">
157173
<svg class="bi" width="24" height="24">
158-
<path d="M8 0C3.582 0 0 3.582 0 8c0 4.07 3.065 7.428 7.032 7.931V10.14H5.037V8h1.995V6.392c0-1.973 1.21-3.05 2.963-3.05.84 0 1.562.063 1.77.09v2.053h-1.215c-.952 0-1.137.451-1.137 1.113V8h2.273l-.296 2.14H9.413v5.79C13.35 15.428 16 12.07 16 8c0-4.418-3.582-8-8-8z"/>
159174
<use xlink:href="#facebook"></use>
160175
</svg>
161176
</a></li>
162177
</ul>
163178
</div>
164179
</footer>
165180
</div>
166-
</body>
181+
182+
<!-- <script src="/js/service-center/filterProducts.js"></script> -->
183+
<!-- <script>
184+
document.addEventListener("DOMContentLoaded", function () {
185+
document.querySelectorAll(".category-link").forEach(link => {
186+
link.addEventListener("click", function (event) {
187+
event.preventDefault(); // Prevent default anchor behavior
188+
189+
let category = this.getAttribute("data-category");
190+
191+
// Send an AJAX request to fetch filtered products
192+
fetch(`/get-product-by-category?category=${category}`, {
193+
method: "GET",
194+
headers: {
195+
"X-Requested-With": "XMLHttpRequest"
196+
}
197+
})
198+
.then(response => response.text())
199+
.then(data => {
200+
document.getElementById("product-list").innerHTML = data; // Update the product list
201+
})
202+
.catch(error => console.error("Error:", error));
203+
});
204+
});
205+
});
206+
</script> -->
207+
208+
<script src="/js/service-center/cart.js"></script>
209+
210+
</body>
211+
</html>

‎views/service-centre/update-product.php

+17
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,23 @@
7777
<input type="number" step="0.01" name="price" value="<?php echo htmlspecialchars($product['price']); ?>">
7878
</div>
7979

80+
<div>
81+
<label for="">Category:</label>
82+
<select class="category-select" name="category" id="category" required>
83+
<option value=""><?php echo htmlspecialchars($product['category']) ?></option>
84+
<option value="Tools">Tools</option>
85+
<option value="Engine & Transmission">Engine & Transmission</option>
86+
<option value="Brakes & Suspension">Brakes & Suspension</option>
87+
<option value="Electrical & Electronics">Electrical & Electronics</option>
88+
<option value="Body Parts & Exterior">Body Parts & Exterior</option>
89+
<option value="Tires & Wheels">Tires & Wheels</option>
90+
<option value="Interior Accessories">Interior Accessories</option>
91+
<option value="Fluids & Maintenance">Fluids & Maintenance</option>
92+
<option value="Performance & Upgrades">Performance & Upgrades</option>
93+
<option value="Safety & Security">Safety & Security</option>
94+
</select>
95+
</div>
96+
8097
<div>
8198
<label>Media:</label>
8299
<input type="file" name="media">

‎views/service-centre/view-cart.php

+265
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
<?php
2+
3+
use app\core\Application;
4+
5+
?>
6+
<!DOCTYPE html>
7+
<html lang="en">
8+
9+
<head>
10+
<meta charset="UTF-8">
11+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
12+
<link rel="stylesheet" href="/css/base/_reset.css">
13+
<link rel="stylesheet" href="/css/base/_global.css">
14+
<link rel="stylesheet" href="/css/service-center/market-place-navbar.css">
15+
<link rel="stylesheet" href="/css/home/footer.css">
16+
<link rel="stylesheet" href="/css/home/home.css">
17+
<link rel="stylesheet" href="/css/service-center/marketplace.css">
18+
<link rel="stylesheet" href="/css/service-center/market-place-product-view.css">
19+
<script src="/js/home/main.js"></script>
20+
<script src="/js/technician/main.js"></script>
21+
<script src="/js/service-center/marketplace-home.js"></script>
22+
<script type="module" src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.esm.js"></script>
23+
<script nomodule src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.js"></script>
24+
<title>Cart</title>
25+
<style>
26+
.cart-container {
27+
max-width: 1200px;
28+
margin: 0 auto;
29+
padding: 20px;
30+
}
31+
32+
.cart-header {
33+
font-size: 2rem;
34+
font-weight: bold;
35+
margin-bottom: 20px;
36+
}
37+
38+
.cart-items {
39+
display: flex;
40+
flex-direction: column;
41+
gap: 20px;
42+
}
43+
44+
.cart-item {
45+
display: flex;
46+
align-items: center;
47+
background: #fff;
48+
padding: 20px;
49+
border-radius: 10px;
50+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
51+
}
52+
53+
.cart-item img {
54+
width: 100px;
55+
height: 100px;
56+
object-fit: cover;
57+
border-radius: 10px;
58+
margin-right: 20px;
59+
}
60+
61+
.item-details {
62+
flex: 1;
63+
}
64+
65+
.item-details h2 {
66+
font-size: 1.2rem;
67+
margin-bottom: 10px;
68+
}
69+
70+
.item-details p {
71+
margin: 5px 0;
72+
}
73+
74+
.remove-from-cart-btn {
75+
background: #ff4d4d;
76+
color: white;
77+
border: none;
78+
padding: 10px 20px;
79+
border-radius: 5px;
80+
cursor: pointer;
81+
}
82+
83+
.remove-from-cart-btn:hover {
84+
background: #ff1a1a;
85+
}
86+
87+
.cart-summary {
88+
margin-top: 30px;
89+
padding: 20px;
90+
background: #fff;
91+
border-radius: 10px;
92+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
93+
}
94+
95+
.cart-summary h2 {
96+
font-size: 1.5rem;
97+
margin-bottom: 20px;
98+
}
99+
100+
.cart-summary p {
101+
font-size: 1.2rem;
102+
margin: 10px 0;
103+
}
104+
105+
.checkout-btn {
106+
background: #4CAF50;
107+
color: white;
108+
border: none;
109+
padding: 15px 30px;
110+
border-radius: 5px;
111+
cursor: pointer;
112+
width: 100%;
113+
font-size: 1.2rem;
114+
}
115+
116+
.checkout-btn:hover {
117+
background: #45a049;
118+
}
119+
</style>
120+
</head>
121+
122+
<body>
123+
124+
<nav class="container">
125+
<header class="d-flex flex-wrap align-items-center justify-content-center justify-content-md-between py-3">
126+
<div class="col-md-3 mb-2 mb-md-0">
127+
<a href="/" class="d-inline-flex link-body-emphasis text-decoration-none">
128+
<img class="logo-img" src="/assets/shopping-cart_market-place.png">
129+
</a>
130+
</div>
131+
132+
<ul class="nav col-12 col-md-auto mb-2 justify-content-center mb-md-0">
133+
<li><a href="/" class="nav-link px-2 link-secondary">Home</a></li>
134+
<li><a href="/service-centre-landing" class="nav-link px-2">Service Centre</a></li>
135+
<li><a href="/about-us" class="nav-link px-2">About</a></li>
136+
</ul>
137+
138+
<form class="search-bar">
139+
<input class="search-bar-enter" type="search" placeholder="Search" aria-label="Search">
140+
<button class="btn" type="submit">Search</button>
141+
</form>
142+
<h6>
143+
<?php
144+
$username = strtoupper(Application::$app->customer->{'name'});
145+
146+
if ($username) {
147+
echo $username;
148+
} else {
149+
echo '<button class="btn" onclick="window.location.href=\'/customer-login\'" style="margin-right:20px;">Login</button>';
150+
}
151+
?>
152+
</h6>
153+
</header>
154+
</nav>
155+
156+
<section>
157+
<div class="flash-message">
158+
<?php if (Application::$app->session->getFlash('success')): ?>
159+
<div class="alert alert-success">
160+
<?php echo Application::$app->session->getFlash('success') ?>
161+
</div>
162+
<?php endif; ?>
163+
</div>
164+
</section>
165+
166+
<div class="cart-container">
167+
<h1 class="cart-header">Your Cart</h1>
168+
<div class="cart-items">
169+
<?php if (!empty($cartItems)): ?>
170+
<?php
171+
$totalItems = 0;
172+
$totalCost = 0;
173+
?>
174+
<?php foreach ($cartItems as $item): ?>
175+
<?php
176+
$totalItems += $item['quantity'];
177+
$totalCost += $item['price'] * $item['quantity'];
178+
?>
179+
<div class="cart-item">
180+
<img src="/assets/uploads/<?php echo htmlspecialchars($item['media']); ?>" alt="Product Image">
181+
<div class="item-details">
182+
<h2><?php echo htmlspecialchars($item['description']); ?></h2>
183+
<p>Price: Rs. <?php echo htmlspecialchars($item['price']); ?></p>
184+
<p>Quantity: <?php echo htmlspecialchars($item['quantity']); ?></p>
185+
<p>product_id: <?php echo htmlspecialchars($item['product_id']); ?></p>
186+
<form action="/remove-from-cart" method="post">
187+
<input type="hidden" name="product_id" value="<?php echo $item['product_id'] ?>">
188+
<button class="remove-from-cart-btn" type="submit">Remove</button>
189+
</form>
190+
</div>
191+
</div>
192+
<?php endforeach; ?>
193+
<?php else: ?>
194+
<p>Your cart is empty.</p>
195+
<?php endif; ?>
196+
</div>
197+
198+
<?php if (!empty($cartItems)): ?>
199+
<div class="cart-summary">
200+
<h2>Cart Summary</h2>
201+
<p>Total Items: <?php echo $totalItems; ?></p>
202+
<p>Total Cost: Rs. <?php echo $totalCost; ?></p>
203+
<button class="checkout-btn" onclick="window.location.href='/checkout'">Proceed to Checkout</button>
204+
</div>
205+
<?php endif; ?>
206+
</div>
207+
208+
<!-- footer -->
209+
<div class="container-f">
210+
<footer class="py-5">
211+
<div class="row">
212+
<div class="col-6 col-md-2 mb-3">
213+
<h3 class="ml-3">FIXME</h3>
214+
</div>
215+
<div class="col-6 col-md-2 mb-3">
216+
<h5>Company</h5>
217+
<ul class="nav-f flex-column">
218+
<li class="nav-item-f mb-2"><a href="#" class="nav-link-f p-0 text-body-secondary">About Us</a></li>
219+
<li class="nav-item-f mb-2"><a href="#" class="nav-link-f p-0 text-body-secondary">Our Offerings</a></li>
220+
</ul>
221+
</div>
222+
223+
<div class="col-6 col-md-2 mb-3">
224+
<h5>Products</h5>
225+
<ul class="nav flex-column">
226+
<li class="nav-item-f mb-2"><a href="#" class="nav-link-f p-0 text-body-secondary">Nearby Technicians</a></li>
227+
<li class="nav-item-f mb-2"><a href="#" class="nav-link-f p-0 text-body-secondary">Service Centers</a></li>
228+
<li class="nav-item-f mb-2"><a href="#" class="nav-link-f p-0 text-body-secondary">Service Center Marketplace</a></li>
229+
</ul>
230+
</div>
231+
232+
<div class="col-6 col-md-2 mb-3">
233+
<h5>Safety Measures</h5>
234+
<ul class="nav flex-column">
235+
<li class="nav-item-f mb-2"><a href="#" class="nav-link-f p-0 text-body-secondary">Safety</a></li>
236+
<li class="nav-item-f mb-2"><a href="#" class="nav-link-f p-0 text-body-secondary">Diversity and Inclusion</a></li>
237+
</ul>
238+
</div>
239+
</div>
240+
241+
<div class="d-flex flex-column flex-sm-row justify-content-between py-4 my-4 mx-4 border-top">
242+
<p>© 2024 Fixme Technologies Inc.</p>
243+
<ul class="list-unstyled d-flex">
244+
<li class="ms-3"><a class="link-body-emphasis" href="#">
245+
<svg class="bi" width="24" height="24">
246+
<use xlink:href="#twitter"></use>
247+
</svg>
248+
</a></li>
249+
<li class="ms-3"><a class="link-body-emphasis" href="#">
250+
<svg class="bi" width="24" height="24">
251+
<use xlink:href="#instagram"></use>
252+
</svg>
253+
</a></li>
254+
<li class="ms-3"><a class="link-body-emphasis" href="#">
255+
<svg class="bi" width="24" height="24">
256+
<use xlink:href="#facebook"></use>
257+
</svg>
258+
</a></li>
259+
</ul>
260+
</div>
261+
</footer>
262+
</div>
263+
264+
</body>
265+
</html>

0 commit comments

Comments
 (0)
Please sign in to comment.