update products

This commit is contained in:
Flatlogic Bot 2026-03-28 18:27:57 +00:00
parent ff9ab72c0b
commit 2ae728c351
3 changed files with 20 additions and 5 deletions

View File

@ -50,16 +50,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
if (!has_permission('products_edit')) {
$message = '<div class="alert alert-danger">Access Denied: You do not have permission to edit products.</div>';
} else {
$stmt = $pdo->prepare("UPDATE products SET name = ?, name_ar = ?, category_id = ?, price = ?, vat_percent = ?, cost_price = ?, stock_quantity = ?, description = ?, image_url = ?, promo_discount_percent = ?, promo_date_from = ?, promo_date_to = ?, is_loyalty = ?, show_in_qorder = ? WHERE id = ?");
$stmt->execute([$name, $name_ar, $category_id, $price, $vat_percent, $cost_price, $stock_quantity, $description, $image_url, $promo_discount_percent, $promo_date_from, $promo_date_to, $is_loyalty, $show_in_qorder, $id]);
$stmt = $pdo->prepare("UPDATE products SET name = ?, name_ar = ?, category_id = ?, price = ?, vat_percent = ?, cost_price = ?, stock_quantity = ?, description = ?, image_url = ?, promo_discount_percent = ?, promo_date_from = ?, promo_date_to = ?, is_loyalty = ?, show_in_qorder = ?, show_in_online_order = ? WHERE id = ?");
$stmt->execute([$name, $name_ar, $category_id, $price, $vat_percent, $cost_price, $stock_quantity, $description, $image_url, $promo_discount_percent, $promo_date_from, $promo_date_to, $is_loyalty, $show_in_qorder, $show_in_online_order, $id]);
$message = '<div class="alert alert-success">Product updated successfully!</div>';
}
} elseif ($action === 'add_product') {
if (!has_permission('products_add')) {
$message = '<div class="alert alert-danger">Access Denied: You do not have permission to add products.</div>';
} else {
$stmt = $pdo->prepare("INSERT INTO products (name, name_ar, category_id, price, vat_percent, cost_price, stock_quantity, description, image_url, promo_discount_percent, promo_date_from, promo_date_to, is_loyalty, show_in_qorder) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([$name, $name_ar, $category_id, $price, $vat_percent, $cost_price, $stock_quantity, $description, $image_url, $promo_discount_percent, $promo_date_from, $promo_date_to, $is_loyalty, $show_in_qorder]);
$stmt = $pdo->prepare("INSERT INTO products (name, name_ar, category_id, price, vat_percent, cost_price, stock_quantity, description, image_url, promo_discount_percent, promo_date_from, promo_date_to, is_loyalty, show_in_qorder, show_in_online_order) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([$name, $name_ar, $category_id, $price, $vat_percent, $cost_price, $stock_quantity, $description, $image_url, $promo_discount_percent, $promo_date_from, $promo_date_to, $is_loyalty, $show_in_qorder, $show_in_online_order]);
$message = '<div class="alert alert-success">Product created successfully!</div>';
}
}
@ -217,6 +217,11 @@ include 'includes/header.php';
<i class="bi bi-qr-code"></i> QR Menu
</span>
<?php endif; ?>
<?php if ($product["show_in_online_order"] ?? false): ?>
<span class="badge bg-success bg-opacity-10 text-success border border-success rounded-pill ms-1" style="font-size: 0.7rem;">
<i class="bi bi-globe"></i> Online
</span>
<?php endif; ?>
</div>
<small class="text-muted"><?= htmlspecialchars($product['name_ar'] ?? '') ?></small>
</div>
@ -382,6 +387,13 @@ include 'includes/header.php';
</div>
<input class="form-check-input ms-0" type="checkbox" name="show_in_qorder" id="productShowInQorder" style="width: 2.5rem; height: 1.25rem;" checked>
</div>
<div class="form-check form-switch p-3 bg-light rounded-3 border d-flex justify-content-between align-items-center mb-3">
<div class="ms-1">
<label class="form-check-label fw-bold text-dark mb-0" for="productShowInOnlineOrder">Show in Online Order</label>
<div class="small text-muted">Make this product visible in the Online Ordering page</div>
</div>
<input class="form-check-input ms-0" type="checkbox" name="show_in_online_order" id="productShowInOnlineOrder" style="width: 2.5rem; height: 1.25rem;" checked>
</div>
<h6 class="fw-bold border-bottom pb-2 mb-3"><i class="bi bi-percent me-1"></i> Promotion Settings</h6>
@ -419,6 +431,7 @@ function prepareAddForm() {
document.getElementById('productId').value = '';
document.getElementById('productImagePreview').style.display = 'none';
document.getElementById('productShowInQorder').checked = true;
document.getElementById('productShowInOnlineOrder').checked = true;
}
function prepareEditForm(p) {
@ -439,6 +452,7 @@ function prepareEditForm(p) {
document.getElementById('productPromoTo').value = p.promo_date_to || '';
document.getElementById('productIsLoyalty').checked = p.is_loyalty == 1;
document.getElementById('productShowInQorder').checked = p.show_in_qorder == 1;
document.getElementById('productShowInOnlineOrder').checked = (p.show_in_online_order === undefined ? true : p.show_in_online_order == 1);
if (p.image_url) {
const preview = document.getElementById('productImagePreview');

View File

@ -0,0 +1 @@
ALTER TABLE `products` ADD COLUMN IF NOT EXISTS `show_in_online_order` TINYINT(1) DEFAULT 1;

View File

@ -114,7 +114,7 @@ if ($table_id > 0) {
$outlet_id = (int)($table_info['outlet_id'] ?? 0);
$categories = $pdo->query("SELECT * FROM categories WHERE is_deleted = 0 ORDER BY sort_order")->fetchAll();
$all_products = $pdo->query("SELECT p.*, c.name as category_name, c.name_ar as category_name_ar FROM products p JOIN categories c ON p.category_id = c.id WHERE p.is_deleted = 0 AND p.show_in_qorder = 1 AND c.is_deleted = 0")->fetchAll();
$all_products = $pdo->query("SELECT p.*, c.name as category_name, c.name_ar as category_name_ar FROM products p JOIN categories c ON p.category_id = c.id WHERE p.is_deleted = 0 AND p.show_in_online_order = 1 AND c.is_deleted = 0")->fetchAll();
// Fetch variants
$variants_raw = $pdo->query("SELECT * FROM product_variants WHERE is_deleted = 0 ORDER BY price_adjustment ASC")->fetchAll();