update pos 4
This commit is contained in:
parent
4ca9818d92
commit
52c9aed760
31
pos.php
31
pos.php
@ -448,13 +448,13 @@ require __DIR__ . '/includes/header.php';
|
|||||||
|
|
||||||
<!-- Grid -->
|
<!-- Grid -->
|
||||||
<div class="products-grid" id="productsGrid">
|
<div class="products-grid" id="productsGrid">
|
||||||
<?php foreach ($catalog as $sku => $item):
|
<?php $productIndex = 0; foreach ($catalog as $sku => $item):
|
||||||
$itemSkuRaw = (string) $sku;
|
$itemSkuRaw = (string) $sku;
|
||||||
$primaryNameRaw = trim((string) (current_lang() === 'ar' ? ($item['name_ar'] ?? '') : ($item['name_en'] ?? '')));
|
$primaryNameRaw = trim((string) (current_lang() === 'ar' ? ($item['name_ar'] ?? '') : ($item['name_en'] ?? '')));
|
||||||
$fallbackNameRaw = trim((string) (current_lang() === 'ar' ? ($item['name_en'] ?? '') : ($item['name_ar'] ?? '')));
|
$fallbackNameRaw = trim((string) (current_lang() === 'ar' ? ($item['name_en'] ?? '') : ($item['name_ar'] ?? '')));
|
||||||
$itemNameRaw = $primaryNameRaw !== ''
|
$itemNameRaw = $primaryNameRaw !== ''
|
||||||
? $primaryNameRaw
|
? $primaryNameRaw
|
||||||
: ($fallbackNameRaw !== '' ? $fallbackNameRaw : ('SKU ' . $itemSkuRaw));
|
: ($fallbackNameRaw !== '' ? $fallbackNameRaw : (tr('صنف ' . $itemSkuRaw, 'Item ' . $itemSkuRaw)));
|
||||||
$searchBits = [
|
$searchBits = [
|
||||||
(string) ($item['name_ar'] ?? ''),
|
(string) ($item['name_ar'] ?? ''),
|
||||||
(string) ($item['name_en'] ?? ''),
|
(string) ($item['name_en'] ?? ''),
|
||||||
@ -474,7 +474,7 @@ require __DIR__ . '/includes/header.php';
|
|||||||
$isRecentlyAdded = $createdAtStamp && $createdAtStamp >= strtotime('-7 days');
|
$isRecentlyAdded = $createdAtStamp && $createdAtStamp >= strtotime('-7 days');
|
||||||
$createdLabel = $createdAtStamp ? date('Y-m-d', $createdAtStamp) : '';
|
$createdLabel = $createdAtStamp ? date('Y-m-d', $createdAtStamp) : '';
|
||||||
?>
|
?>
|
||||||
<div class="product-card" data-sku="<?= $itemSku ?>" data-name="<?= $itemName ?>" data-price="<?= $itemPrice ?>" data-cat="<?= $itemCat ?>" data-search="<?= h($searchText) ?>" data-created="<?= h($createdAtRaw) ?>" onclick="addToCart('<?= $itemSku ?>')">
|
<div class="product-card" data-sku="<?= $itemSku ?>" data-name="<?= $itemName ?>" data-price="<?= $itemPrice ?>" data-cat="<?= $itemCat ?>" data-search="<?= h($searchText) ?>" data-created="<?= h($createdAtRaw) ?>" data-index="<?= $productIndex++ ?>" onclick="addToCart('<?= $itemSku ?>')">
|
||||||
<div class="product-img-wrapper">
|
<div class="product-img-wrapper">
|
||||||
<?php if (!empty($imageUrl)):
|
<?php if (!empty($imageUrl)):
|
||||||
$imgAlt = $itemName;
|
$imgAlt = $itemName;
|
||||||
@ -497,12 +497,6 @@ require __DIR__ . '/includes/header.php';
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="product-title" title="<?= $itemName ?>"><?= $itemName ?></div>
|
<div class="product-title" title="<?= $itemName ?>"><?= $itemName ?></div>
|
||||||
<div class="product-meta">
|
|
||||||
<div class="product-sku" title="<?= $itemSku ?>">SKU: <?= $itemSku ?></div>
|
|
||||||
<?php if ($createdLabel !== ''): ?>
|
|
||||||
<div class="product-created"><?= h(tr('أضيف', 'Added')) ?>: <?= h($createdLabel) ?></div>
|
|
||||||
<?php endif; ?>
|
|
||||||
</div>
|
|
||||||
<div class="product-price"><?= h(currency((float)$item['price'])) ?></div>
|
<div class="product-price"><?= h(currency((float)$item['price'])) ?></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -769,21 +763,32 @@ document.getElementById('posBarcode').addEventListener('keypress', function(e) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const INITIAL_PRODUCT_LIMIT = 100;
|
||||||
|
|
||||||
function applyFilters() {
|
function applyFilters() {
|
||||||
const q = document.getElementById('posSearch').value.toLowerCase().trim();
|
const q = document.getElementById('posSearch').value.toLowerCase().trim();
|
||||||
const activeCat = document.querySelector('.cat-btn.active').dataset.cat;
|
const activeCat = document.querySelector('.cat-btn.active').dataset.cat;
|
||||||
|
let visibleCount = 0;
|
||||||
|
|
||||||
document.querySelectorAll('.product-card').forEach(card => {
|
document.querySelectorAll('.product-card').forEach(card => {
|
||||||
const searchable = (card.dataset.search || card.dataset.name || '').toLowerCase();
|
const searchable = (card.dataset.search || card.dataset.name || '').toLowerCase();
|
||||||
const cat = card.dataset.cat;
|
const cat = card.dataset.cat;
|
||||||
|
|
||||||
const matchesSearch = q === '' || searchable.includes(q);
|
const matchesSearch = q === '' || searchable.includes(q);
|
||||||
const matchesCat = (activeCat === 'all' || cat === activeCat);
|
const matchesCat = (activeCat === 'all' || cat === activeCat);
|
||||||
|
const matches = matchesSearch && matchesCat;
|
||||||
card.hidden = !(matchesSearch && matchesCat);
|
const withinInitialLimit = q !== '' || visibleCount < INITIAL_PRODUCT_LIMIT;
|
||||||
|
|
||||||
|
card.hidden = !(matches && withinInitialLimit);
|
||||||
|
|
||||||
|
if (matches) {
|
||||||
|
visibleCount += 1;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
applyFilters();
|
||||||
|
|
||||||
// Cart Logic
|
// Cart Logic
|
||||||
function addToCart(sku) {
|
function addToCart(sku) {
|
||||||
if (!catalogData[sku]) return;
|
if (!catalogData[sku]) return;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user