update 3
This commit is contained in:
parent
600e86d0fa
commit
7673b8e4dc
@ -163,7 +163,18 @@ try {
|
|||||||
throw new Exception("No loyalty-eligible products in the order to redeem.");
|
throw new Exception("No loyalty-eligible products in the order to redeem.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$total_loyalty_qty = 0;
|
||||||
|
foreach ($processed_items as $item) {
|
||||||
|
if ($item['is_loyalty']) {
|
||||||
|
$total_loyalty_qty += $item['quantity'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$possible_redemptions = floor($current_points / $points_threshold);
|
$possible_redemptions = floor($current_points / $points_threshold);
|
||||||
|
if ($total_loyalty_qty > $possible_redemptions) {
|
||||||
|
throw new Exception("You are only eligible for $possible_redemptions free product(s). Please reduce quantity in cart.");
|
||||||
|
}
|
||||||
|
|
||||||
$redemptions_done = 0;
|
$redemptions_done = 0;
|
||||||
|
|
||||||
while ($redemptions_done < $possible_redemptions) {
|
while ($redemptions_done < $possible_redemptions) {
|
||||||
|
|||||||
@ -259,20 +259,25 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
if (loyaltyPointsDisplay) loyaltyPointsDisplay.textContent = currentCustomer.points + ' pts';
|
if (loyaltyPointsDisplay) loyaltyPointsDisplay.textContent = currentCustomer.points + ' pts';
|
||||||
|
|
||||||
if (redeemLoyaltyBtn) {
|
if (redeemLoyaltyBtn) {
|
||||||
const hasLoyaltyItem = cart.some(item => item.is_loyalty);
|
const totalLoyaltyQuantity = cart.reduce((sum, item) => item.is_loyalty ? sum + item.quantity : sum, 0);
|
||||||
|
const hasLoyaltyItem = totalLoyaltyQuantity > 0;
|
||||||
const hasNonLoyaltyItem = cart.some(item => !item.is_loyalty);
|
const hasNonLoyaltyItem = cart.some(item => !item.is_loyalty);
|
||||||
|
const eligibleCount = currentCustomer.eligible_count || 1;
|
||||||
|
|
||||||
redeemLoyaltyBtn.disabled = !currentCustomer.eligible_for_free_meal || !hasLoyaltyItem || hasNonLoyaltyItem;
|
const isOverLimit = totalLoyaltyQuantity > eligibleCount;
|
||||||
|
|
||||||
|
redeemLoyaltyBtn.disabled = !currentCustomer.eligible_for_free_meal || !hasLoyaltyItem || hasNonLoyaltyItem || isOverLimit;
|
||||||
|
|
||||||
if (loyaltyMessage) {
|
if (loyaltyMessage) {
|
||||||
if (currentCustomer.eligible_for_free_meal) {
|
if (currentCustomer.eligible_for_free_meal) {
|
||||||
const count = currentCustomer.eligible_count || 1;
|
loyaltyMessage.innerHTML = `<span class="text-success fw-bold">Eligible for ${eligibleCount} Free Product${eligibleCount > 1 ? 's' : ''}!</span>`;
|
||||||
loyaltyMessage.innerHTML = `<span class="text-success fw-bold">Eligible for ${count} Free Product${count > 1 ? 's' : ''}!</span>`;
|
|
||||||
|
|
||||||
if (hasNonLoyaltyItem) {
|
if (hasNonLoyaltyItem) {
|
||||||
loyaltyMessage.innerHTML += '<div class="text-danger small" style="font-size: 0.7rem;">(Remove non-loyalty products to redeem)</div>';
|
loyaltyMessage.innerHTML += '<div class="text-danger small" style="font-size: 0.7rem;">(Remove non-loyalty products to redeem)</div>';
|
||||||
} else if (!hasLoyaltyItem) {
|
} else if (!hasLoyaltyItem) {
|
||||||
loyaltyMessage.innerHTML += '<div class="text-warning small" style="font-size: 0.7rem;">(Add a loyalty product to redeem)</div>';
|
loyaltyMessage.innerHTML += '<div class="text-warning small" style="font-size: 0.7rem;">(Add a loyalty product to redeem)</div>';
|
||||||
|
} else if (isOverLimit) {
|
||||||
|
loyaltyMessage.innerHTML += `<div class="text-danger small" style="font-size: 0.7rem;">(Maximum ${eligibleCount} free products allowed)</div>`;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
loyaltyMessage.textContent = `${currentCustomer.points_needed || 0} pts away from a free product.`;
|
loyaltyMessage.textContent = `${currentCustomer.points_needed || 0} pts away from a free product.`;
|
||||||
|
|||||||
@ -1,33 +0,0 @@
|
|||||||
|
|
||||||
function updateLoyaltyUI() {
|
|
||||||
if (!loyaltySection || typeof LOYALTY_SETTINGS === 'undefined' || !LOYALTY_SETTINGS.is_enabled) return;
|
|
||||||
|
|
||||||
if (currentCustomer) {
|
|
||||||
loyaltySection.classList.remove('d-none');
|
|
||||||
if (loyaltyPointsDisplay) loyaltyPointsDisplay.textContent = currentCustomer.points + ' pts';
|
|
||||||
|
|
||||||
if (redeemLoyaltyBtn) {
|
|
||||||
const hasLoyaltyItem = cart.some(item => item.is_loyalty);
|
|
||||||
const hasNonLoyaltyItem = cart.some(item => !item.is_loyalty);
|
|
||||||
|
|
||||||
redeemLoyaltyBtn.disabled = !currentCustomer.eligible_for_free_meal || !hasLoyaltyItem || hasNonLoyaltyItem;
|
|
||||||
|
|
||||||
if (loyaltyMessage) {
|
|
||||||
if (currentCustomer.eligible_for_free_meal) {
|
|
||||||
const count = currentCustomer.eligible_count || 1;
|
|
||||||
loyaltyMessage.innerHTML = `<span class="text-success fw-bold">Eligible for ${count} Free Product${count > 1 ? 's' : ''}!</span>`;
|
|
||||||
|
|
||||||
if (hasNonLoyaltyItem) {
|
|
||||||
loyaltyMessage.innerHTML += '<div class="text-danger small" style="font-size: 0.7rem;">(Remove non-loyalty products to redeem)</div>';
|
|
||||||
} else if (!hasLoyaltyItem) {
|
|
||||||
loyaltyMessage.innerHTML += '<div class="text-warning small" style="font-size: 0.7rem;">(Add a loyalty product to redeem)</div>';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
loyaltyMessage.textContent = `${currentCustomer.points_needed || 0} pts away from a free product.`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
loyaltySection.classList.add('d-none');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user