corregidos bugs de: ret, vs delivery, efectivo vs link, charsets, price query
This commit is contained in:
@@ -72,6 +72,51 @@ function parsePrice(p) {
|
||||
return Number.isFinite(n) ? n : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodifica HTML entities comunes (WooCommerce las usa en nombres de productos)
|
||||
*/
|
||||
function decodeHtmlEntities(str) {
|
||||
if (!str || typeof str !== "string") return str;
|
||||
// Solo procesar si hay entidades
|
||||
if (!str.includes("&")) return str;
|
||||
|
||||
const entities = {
|
||||
"&": "&", "<": "<", ">": ">", """: '"', "'": "'", "'": "'",
|
||||
" ": " ", "¡": "¡", "¢": "¢", "£": "£", "¤": "¤",
|
||||
"¥": "¥", "¦": "¦", "§": "§", "¨": "¨", "©": "©",
|
||||
"ª": "ª", "«": "«", "¬": "¬", "­": "\u00AD", "®": "®",
|
||||
"¯": "¯", "°": "°", "±": "±", "²": "²", "³": "³",
|
||||
"´": "´", "µ": "µ", "¶": "¶", "·": "·", "¸": "¸",
|
||||
"¹": "¹", "º": "º", "»": "»", "¼": "¼", "½": "½",
|
||||
"¾": "¾", "¿": "¿", "À": "À", "Á": "Á", "Â": "Â",
|
||||
"Ã": "Ã", "Ä": "Ä", "Å": "Å", "Æ": "Æ", "Ç": "Ç",
|
||||
"È": "È", "É": "É", "Ê": "Ê", "Ë": "Ë", "Ì": "Ì",
|
||||
"Í": "Í", "Î": "Î", "Ï": "Ï", "Ð": "Ð", "Ñ": "Ñ",
|
||||
"Ò": "Ò", "Ó": "Ó", "Ô": "Ô", "Õ": "Õ", "Ö": "Ö",
|
||||
"×": "×", "Ø": "Ø", "Ù": "Ù", "Ú": "Ú", "Û": "Û",
|
||||
"Ü": "Ü", "Ý": "Ý", "Þ": "Þ", "ß": "ß", "à": "à",
|
||||
"á": "á", "â": "â", "ã": "ã", "ä": "ä", "å": "å",
|
||||
"æ": "æ", "ç": "ç", "è": "è", "é": "é", "ê": "ê",
|
||||
"ë": "ë", "ì": "ì", "í": "í", "î": "î", "ï": "ï",
|
||||
"ð": "ð", "ñ": "ñ", "ò": "ò", "ó": "ó", "ô": "ô",
|
||||
"õ": "õ", "ö": "ö", "÷": "÷", "ø": "ø", "ù": "ù",
|
||||
"ú": "ú", "û": "û", "ü": "ü", "ý": "ý", "þ": "þ",
|
||||
"ÿ": "ÿ",
|
||||
};
|
||||
|
||||
let result = str;
|
||||
// Reemplazar entities nombradas usando iteración (más robusto que regex)
|
||||
for (const [entity, char] of Object.entries(entities)) {
|
||||
if (result.includes(entity)) {
|
||||
result = result.split(entity).join(char);
|
||||
}
|
||||
}
|
||||
// Reemplazar entities numéricas ({ o {)
|
||||
result = result.replace(/&#(\d+);/g, (_, num) => String.fromCharCode(parseInt(num, 10)));
|
||||
result = result.replace(/&#x([0-9a-fA-F]+);/gi, (_, hex) => String.fromCharCode(parseInt(hex, 16)));
|
||||
return result;
|
||||
}
|
||||
|
||||
function normalizeAttributes(attrs) {
|
||||
const out = {};
|
||||
if (!Array.isArray(attrs)) return out;
|
||||
@@ -90,7 +135,7 @@ function normalizeWooProduct(p) {
|
||||
woo_id: p?.id,
|
||||
type: p?.type || "simple",
|
||||
parent_id: p?.parent_id || null,
|
||||
name: p?.name || "",
|
||||
name: decodeHtmlEntities(p?.name || ""),
|
||||
slug: p?.slug || null,
|
||||
status: p?.status || null,
|
||||
catalog_visibility: p?.catalog_visibility || null,
|
||||
@@ -114,7 +159,7 @@ function snapshotRowToItem(row) {
|
||||
const raw = row?.raw || {};
|
||||
return {
|
||||
woo_product_id: row?.woo_id,
|
||||
name: row?.name || "",
|
||||
name: decodeHtmlEntities(row?.name || ""),
|
||||
sku: raw?.SKU || raw?.sku || row?.slug || null,
|
||||
slug: row?.slug || null,
|
||||
price: row?.price_current != null ? Number(row.price_current) : null,
|
||||
|
||||
Reference in New Issue
Block a user