updating loyality
This commit is contained in:
parent
0c98d8d160
commit
a1d6822c0a
@ -75,6 +75,7 @@ try {
|
|||||||
$loyaltySettings = $settingsStmt->fetch(PDO::FETCH_ASSOC);
|
$loyaltySettings = $settingsStmt->fetch(PDO::FETCH_ASSOC);
|
||||||
$loyalty_enabled = $loyaltySettings ? (bool)$loyaltySettings['is_enabled'] : true;
|
$loyalty_enabled = $loyaltySettings ? (bool)$loyaltySettings['is_enabled'] : true;
|
||||||
$points_threshold = $loyaltySettings ? intval($loyaltySettings['points_for_free_meal']) : 70;
|
$points_threshold = $loyaltySettings ? intval($loyaltySettings['points_for_free_meal']) : 70;
|
||||||
|
$points_per_product = $loyaltySettings ? intval($loyaltySettings['points_per_order']) : 10;
|
||||||
|
|
||||||
$current_points = 0;
|
$current_points = 0;
|
||||||
$points_deducted = 0;
|
$points_deducted = 0;
|
||||||
@ -206,9 +207,9 @@ try {
|
|||||||
// Recalculate Subtotal and Earned Points
|
// Recalculate Subtotal and Earned Points
|
||||||
foreach ($processed_items as $pi) {
|
foreach ($processed_items as $pi) {
|
||||||
$calculated_total += $pi['unit_price'] * $pi['quantity'];
|
$calculated_total += $pi['unit_price'] * $pi['quantity'];
|
||||||
// Award points for PAID loyalty items (10 points each)
|
// Award points for PAID loyalty items
|
||||||
if ($pi['is_loyalty'] && $pi['unit_price'] > 0) {
|
if ($pi['is_loyalty'] && $pi['unit_price'] > 0) {
|
||||||
$points_awarded += $pi['quantity'] * 10;
|
$points_awarded += $pi['quantity'] * $points_per_product;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,4 +374,4 @@ You've earned *{points_earned} points* with this order.
|
|||||||
if ($pdo->inTransaction()) $pdo->rollBack();
|
if ($pdo->inTransaction()) $pdo->rollBack();
|
||||||
error_log("Order Error: " . $e->getMessage());
|
error_log("Order Error: " . $e->getMessage());
|
||||||
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user