feat(prestashop): delegate product ingestion to orders (1.1.13)
This commit is contained in:
+4
-27
@@ -4,7 +4,6 @@ const { normalizeStatusId } = require('./status-mapper');
|
||||
const { paymentTransactionId, parsePrestashopDate, upsertMapping } = require('./automation-jobs');
|
||||
const {
|
||||
buildProductSourceId,
|
||||
parseProductSourceId,
|
||||
resolveProductMetadata,
|
||||
} = require('./product-metadata');
|
||||
|
||||
@@ -101,6 +100,9 @@ async function importFromPSOrder(orderId, api, config) {
|
||||
tax: taxRate ? Math.round(taxRate * 100) / 100 : 0,
|
||||
qty: parseFloat(product.product_quantity)
|
||||
};
|
||||
// Jednorazowa migracja starej tożsamości produktu odbywa się już po
|
||||
// stronie core/products przez synchroniczny kontrakt core/orders.
|
||||
p.previousSourceId = productId;
|
||||
|
||||
const psProduct = await api.getProduct(productId);
|
||||
Log.debug( "Fetched product details: " + getPSMultiLangField(psProduct.name));
|
||||
@@ -149,6 +151,7 @@ async function importFromPSOrder(orderId, api, config) {
|
||||
ean: psItem.ean13,
|
||||
qty: parseFloat(packItem.quantity)
|
||||
};
|
||||
pData.previousSourceId = packProductId;
|
||||
|
||||
let packCombination = null;
|
||||
if (packCombinationId !== '0') {
|
||||
@@ -187,32 +190,6 @@ async function importFromPSOrder(orderId, api, config) {
|
||||
products.push(p);
|
||||
}
|
||||
|
||||
const productsForUpsert = products.flatMap(product => [product, ...(Array.isArray(product.pack) ? product.pack : [])]);
|
||||
for (const product of productsForUpsert.filter(item => item.sourceId && item.name)) {
|
||||
const sourceIdentity = parseProductSourceId(product.sourceId);
|
||||
const upsert = {
|
||||
// własny kod modułu bierzemy z core (po rejestracji), nie z hardcode'u
|
||||
sourceModule: Core.getModuleInfo().code,
|
||||
sourceId: String(product.sourceId),
|
||||
previousSourceId: sourceIdentity?.productId || undefined,
|
||||
sku: product.sku || '',
|
||||
name: product.name,
|
||||
};
|
||||
if (Object.hasOwn(product, 'baseUnitPrice') && product.baseUnitPrice !== undefined) {
|
||||
upsert.unitPrice = product.baseUnitPrice;
|
||||
}
|
||||
for (const field of ['tax', 'weight', 'ean', 'coverImageUrl', 'brand', 'warehouseLocation']) {
|
||||
if (Object.hasOwn(product, field) && product[field] !== undefined) upsert[field] = product[field];
|
||||
}
|
||||
await Core.callModule('core/products', 'upsert', upsert).catch(error => {
|
||||
Log.warn('PrestaShop product catalog upsert failed', {
|
||||
sourceId: product.sourceId,
|
||||
sku: product.sku || '',
|
||||
error: error?.message,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const fallbackStatusId = await resolveImportStatusId(config);
|
||||
if (!fallbackStatusId) {
|
||||
throw new Error(`Cannot import order ${orderId} — no valid order status configured`);
|
||||
|
||||
Reference in New Issue
Block a user