diseñadorneon

// === FPD - Pricing personalizado para letreros de neón ===
// Ajusta PX_PER_CM si tu canvas usa otra escala (px por cm)
var PX_PER_CM = 10; // <-- AJUSTAR si es necesario

function FPD_PR_custom(product) {
  var total = 0;

  // Helper: convierte px a cm según tu setup
  function pxToCm(px) {
    return px / PX_PER_CM;
  }

  // 1) LED y Acrílico por cm (usamos ancho como aproximación de longitud de tubo)
  var width_cm = pxToCm(product.stage.width || 0);
  // Si prefieres usar perímetro u otra medida, aquí se puede ajustar
  var led_price = width_cm * 150;      // $150 x cm
  var acri_price = width_cm * 15;      // $15 x cm
  total += Math.round(led_price) + Math.round(acri_price);

  // 2) Corte por letras (minúscula 3000, mayúscula 6000)
  try {
    var texts = (product.getElements) ? product.getElements('text') : [];
    var corteLetters = 0;
    for (var i = 0; i < texts.length; i++) {
      var t = texts[i].text || '';
      for (var j = 0; j < t.length; j++) {
        var ch = t[j];
        if (/[a-záéíóúñü]/.test(ch)) corteLetters += 3000;
        else if (/[A-ZÁÉÍÓÚÑÜ]/.test(ch)) corteLetters += 6000;
      }
    }
    total += corteLetters;
  } catch(e) {
    // Si product.getElements no está disponible, no sumamos este ítem
  }

  // 3) Corte acrílico por rango (según ancho y alto en cm)
  var height_cm = pxToCm(product.stage.height || 0);
  if (width_cm <= 120 && height_cm <= 90) {
    total += 10000;
  } else if (width_cm >= 121 && height_cm >= 90) {
    total += 18000;
  }

  // 4) Fuente de energía por longitud (usar ancho_cm como proxy -> metros)
  var metros = width_cm / 100; // cm -> m
  if (metros > 0 && metros <= 3) total += 12000;
  else if (metros > 3 && metros <= 5) total += 28000;
  else if (metros > 5 && metros <= 8) total += 40000;
  else if (metros > 8 && metros <= 12) total += 60000;

  // Si tu producto tiene un campo input (ej. "Cable length") y quieres usarlo:
  // var userCable = product.customFields && product.customFields.cable_length;
  // if (userCable) { // interpretar userCable en metros y aplicar reglas similares }

  return total;
}
Carrito de compra