[IMP] website_sale_aplicoop: Validar disponibilidad de productos al cargar órdenes históricas
- Backend: Agregar método _validate_items_for_group_order() para validar que los productos históricos sigan siendo disponibles en la orden de grupo actual - Backend: Modificar load_order_from_history() para filtrar solo items disponibles antes de pasar al template - Backend: Generar mensaje de aviso traducido cuando hay productos no disponibles - Template: Pasar información de productos no disponibles y warnings al JavaScript - Frontend: Mostrar notificación de advertencia si hubo productos excluidos durante la carga histórica - Notas: Esto evita cargar productos que ya no existen en la orden actual debido a cambios en categorías, proveedores o listas negras
This commit is contained in:
parent
4a928e92dd
commit
3ca90578ae
7 changed files with 271 additions and 8 deletions
|
|
@ -222,12 +222,14 @@
|
|||
var pickupDayKey = "load_from_history_pickup_day_" + this.orderId;
|
||||
var pickupDateKey = "load_from_history_pickup_date_" + this.orderId;
|
||||
var homeDeliveryKey = "load_from_history_home_delivery_" + this.orderId;
|
||||
var warningKey = "load_from_history_warning_" + this.orderId;
|
||||
|
||||
var itemsJson = sessionStorage.getItem(storageKey);
|
||||
var orderName = sessionStorage.getItem(orderNameKey);
|
||||
var pickupDay = sessionStorage.getItem(pickupDayKey);
|
||||
var pickupDate = sessionStorage.getItem(pickupDateKey);
|
||||
var homeDelivery = sessionStorage.getItem(homeDeliveryKey) === "true";
|
||||
var warningMessage = sessionStorage.getItem(warningKey);
|
||||
|
||||
console.log("DEBUG: _loadFromHistory called for orderId:", this.orderId);
|
||||
console.log("DEBUG: sessionStorageKey:", storageKey);
|
||||
|
|
@ -240,6 +242,7 @@
|
|||
homeDelivery,
|
||||
"(empty means different group order)"
|
||||
);
|
||||
console.log("DEBUG: warningMessage:", warningMessage);
|
||||
|
||||
if (!itemsJson || itemsJson === "[object Object]") {
|
||||
console.log("No valid items from history found in sessionStorage");
|
||||
|
|
@ -248,6 +251,7 @@
|
|||
sessionStorage.removeItem(pickupDayKey);
|
||||
sessionStorage.removeItem(pickupDateKey);
|
||||
sessionStorage.removeItem(homeDeliveryKey);
|
||||
sessionStorage.removeItem(warningKey);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -269,6 +273,7 @@
|
|||
sessionStorage.removeItem(pickupDayKey);
|
||||
sessionStorage.removeItem(pickupDateKey);
|
||||
sessionStorage.removeItem(homeDeliveryKey);
|
||||
sessionStorage.removeItem(warningKey);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -349,12 +354,19 @@
|
|||
}
|
||||
this._showNotification(message, "success", 3000);
|
||||
|
||||
// Show warning if some products were unavailable
|
||||
if (warningMessage) {
|
||||
console.log("Showing warning about unavailable products:", warningMessage);
|
||||
this._showNotification(warningMessage, "warning", 5000);
|
||||
}
|
||||
|
||||
// Clear sessionStorage
|
||||
sessionStorage.removeItem(storageKey);
|
||||
sessionStorage.removeItem(orderNameKey);
|
||||
sessionStorage.removeItem(pickupDayKey);
|
||||
sessionStorage.removeItem(pickupDateKey);
|
||||
sessionStorage.removeItem(homeDeliveryKey);
|
||||
sessionStorage.removeItem(warningKey);
|
||||
} catch (e) {
|
||||
console.error("Error loading from history:", e);
|
||||
console.error("itemsJson was:", itemsJson);
|
||||
|
|
@ -435,8 +447,32 @@
|
|||
}
|
||||
try {
|
||||
var data = JSON.parse(xhr.responseText || "{}");
|
||||
if (data && data.is_open === false) {
|
||||
// Clear cart if order is closed, action requests clearance, or cutoff already passed
|
||||
var shouldClear = false;
|
||||
if (data) {
|
||||
if (data.is_open === false) {
|
||||
shouldClear = true;
|
||||
}
|
||||
if (data.action && data.action === "clear_cart") {
|
||||
shouldClear = true;
|
||||
}
|
||||
if (data.cutoff_passed === true) {
|
||||
shouldClear = true;
|
||||
}
|
||||
}
|
||||
if (shouldClear) {
|
||||
console.log(
|
||||
"[groupOrderShop] check-status: clearing cart (reason:",
|
||||
data,
|
||||
")"
|
||||
);
|
||||
self._clearCurrentOrderCartSilently();
|
||||
// Update on-screen cart if visible
|
||||
try {
|
||||
self._updateCartDisplay();
|
||||
} catch (err) {
|
||||
console.warn("_updateCartDisplay failed after clearing cart:", err);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("[groupOrderShop] check-status parse error", e);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue