modularizado de prompts
This commit is contained in:
@@ -125,7 +125,7 @@ async function buildLineItems({ tenantId, basket }) {
|
||||
const lineItems = [];
|
||||
for (const it of items) {
|
||||
const productId = Number(it.product_id);
|
||||
const unit = String(it.unit);
|
||||
const unit = String(it.unit).toLowerCase();
|
||||
const qty = Number(it.quantity);
|
||||
if (!productId || !Number.isFinite(qty) || qty <= 0) continue;
|
||||
const pricePerKg = await getWooProductPrice({ tenantId, productId });
|
||||
@@ -144,8 +144,10 @@ async function buildLineItems({ tenantId, basket }) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Carne por gramos (enteros): quantity=1 y total calculado en base a ARS/kg
|
||||
const grams = Math.round(qty);
|
||||
// Carne por peso: convertir a gramos
|
||||
// Si qty < 100, asumir que viene en kg (ej: 1.5 kg)
|
||||
// Si qty >= 100, asumir que ya viene en gramos (ej: 1500 g)
|
||||
const grams = qty < 100 ? Math.round(qty * 1000) : Math.round(qty);
|
||||
const kilos = grams / 1000;
|
||||
const total = pricePerKg != null ? toMoney(pricePerKg * kilos) : null;
|
||||
lineItems.push({
|
||||
@@ -165,6 +167,13 @@ async function buildLineItems({ tenantId, basket }) {
|
||||
|
||||
function mapAddress(address) {
|
||||
if (!address || typeof address !== "object") return null;
|
||||
// Generar email fallback si no hay uno válido (usa formato wa_chat_id)
|
||||
let email = address.email || "";
|
||||
if (!email || !email.includes("@")) {
|
||||
const phone = address.phone || "";
|
||||
// Formato: {phone}@s.whatsapp.net (igual que wa_chat_id)
|
||||
email = phone ? `${phone.replace(/[^0-9]/g, "")}@s.whatsapp.net` : `anon-${Date.now()}@s.whatsapp.net`;
|
||||
}
|
||||
return {
|
||||
first_name: address.first_name || "",
|
||||
last_name: address.last_name || "",
|
||||
@@ -175,7 +184,7 @@ function mapAddress(address) {
|
||||
postcode: address.postcode || "",
|
||||
country: address.country || "AR",
|
||||
phone: address.phone || "",
|
||||
email: address.email || "",
|
||||
email,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user