feat(prestashop): sync catalog base prices in 1.1.12
This commit is contained in:
@@ -21,6 +21,7 @@ function loadImporter(Core, PsOrder) {
|
||||
|
||||
test('order import upserts verified metadata for the ordered product and pack items', async () => {
|
||||
const upserts = [];
|
||||
let createdOrder = null;
|
||||
const Core = {
|
||||
getModuleInfo: () => ({ code: 'core/prestashop' }),
|
||||
callModule: async (module, method, params) => {
|
||||
@@ -29,7 +30,10 @@ test('order import upserts verified metadata for the ordered product and pack it
|
||||
upserts.push(params);
|
||||
return {};
|
||||
}
|
||||
if (module === 'core/orders' && method === 'create') return { _id: 'order-1' };
|
||||
if (module === 'core/orders' && method === 'create') {
|
||||
createdOrder = params;
|
||||
return { _id: 'order-1' };
|
||||
}
|
||||
throw new Error(`Unexpected core call: ${module}.${method}`);
|
||||
},
|
||||
};
|
||||
@@ -55,22 +59,22 @@ test('order import upserts verified metadata for the ordered product and pack it
|
||||
const products = {
|
||||
'10': {
|
||||
id: '10', name: 'Pack', reference: 'PACK-BASE', manufacturer_name: 'Pack Brand', location: 'BASE-BIN',
|
||||
weight: '1', type: 'pack', associations: { product_bundle: [{ id: '20', id_product_attribute: '200', quantity: '2' }] },
|
||||
price: '8', weight: '1', type: 'pack', associations: { product_bundle: [{ id: '20', id_product_attribute: '200', quantity: '2' }] },
|
||||
},
|
||||
'20': {
|
||||
id: '20', name: 'Item', reference: 'ITEM-BASE', manufacturer_name: 'Item Brand', location: 'ITEM-BASE-BIN',
|
||||
weight: '2', type: 'standard', associations: {},
|
||||
price: '3', weight: '2', type: 'standard', associations: {},
|
||||
},
|
||||
'30': {
|
||||
id: '30', name: 'Variant product', reference: 'VARIANT-BASE', manufacturer_name: 'Variant Brand',
|
||||
location: 'VARIANT-BASE-BIN', weight: '1', type: 'standard', associations: {},
|
||||
location: 'VARIANT-BASE-BIN', price: '15', weight: '1', type: 'standard', associations: {},
|
||||
},
|
||||
};
|
||||
const combinations = {
|
||||
'100': { id: '100', id_product: '10', reference: 'PACK-V', weight: '1.5', location: 'PACK-V-BIN' },
|
||||
'200': { id: '200', id_product: '20', reference: 'ITEM-V', weight: '2.5', location: 'ITEM-V-BIN' },
|
||||
'300': { id: '300', id_product: '30', reference: 'VARIANT-BLUE', ean13: '5901234123457', weight: '0.1', location: 'BLUE-BIN' },
|
||||
'301': { id: '301', id_product: '30', reference: 'VARIANT-RED', ean13: '5901234123464', weight: '0.2', location: 'RED-BIN' },
|
||||
'100': { id: '100', id_product: '10', reference: 'PACK-V', price: '1.5', weight: '1.5', location: 'PACK-V-BIN' },
|
||||
'200': { id: '200', id_product: '20', reference: 'ITEM-V', price: '0.25', weight: '2.5', location: 'ITEM-V-BIN' },
|
||||
'300': { id: '300', id_product: '30', reference: 'VARIANT-BLUE', price: '2', ean13: '5901234123457', weight: '0.1', location: 'BLUE-BIN' },
|
||||
'301': { id: '301', id_product: '30', reference: 'VARIANT-RED', price: '3', ean13: '5901234123464', weight: '0.2', location: 'RED-BIN' },
|
||||
};
|
||||
const api = {
|
||||
isBLSupported: async () => false,
|
||||
@@ -94,12 +98,12 @@ test('order import upserts verified metadata for the ordered product and pack it
|
||||
assert.equal(upserts.length, 4);
|
||||
assert.deepEqual(upserts.find(product => product.sourceId === 'product:10:combination:100'), {
|
||||
sourceModule: 'core/prestashop', sourceId: 'product:10:combination:100', previousSourceId: '10',
|
||||
sku: 'PACK-V', name: 'Pack', unitPrice: 10, tax: 0.23, weight: 2.5,
|
||||
sku: 'PACK-V', name: 'Pack', unitPrice: 9.5, tax: 0.23, weight: 2.5,
|
||||
ean: '', brand: 'Pack Brand', warehouseLocation: 'PACK-V-BIN',
|
||||
});
|
||||
assert.deepEqual(upserts.find(product => product.sourceId === 'product:20:combination:200'), {
|
||||
sourceModule: 'core/prestashop', sourceId: 'product:20:combination:200', previousSourceId: '20',
|
||||
sku: 'ITEM-V', name: 'Item', weight: 4.5,
|
||||
sku: 'ITEM-V', name: 'Item', unitPrice: 3.25, weight: 4.5,
|
||||
brand: 'Item Brand', warehouseLocation: 'ITEM-V-BIN',
|
||||
});
|
||||
assert.deepEqual(
|
||||
@@ -112,12 +116,14 @@ test('order import upserts verified metadata for the ordered product and pack it
|
||||
);
|
||||
assert.deepEqual(upserts.find(product => product.sourceId === 'product:30:combination:300'), {
|
||||
sourceModule: 'core/prestashop', sourceId: 'product:30:combination:300', previousSourceId: '30',
|
||||
sku: 'VARIANT-BLUE', name: 'Variant Blue', unitPrice: 20, tax: 0.23, weight: 1.1,
|
||||
sku: 'VARIANT-BLUE', name: 'Variant Blue', unitPrice: 17, tax: 0.23, weight: 1.1,
|
||||
ean: '5901234123457', brand: 'Variant Brand', warehouseLocation: 'BLUE-BIN',
|
||||
});
|
||||
assert.deepEqual(upserts.find(product => product.sourceId === 'product:30:combination:301'), {
|
||||
sourceModule: 'core/prestashop', sourceId: 'product:30:combination:301', previousSourceId: '30',
|
||||
sku: 'VARIANT-RED', name: 'Variant Red', unitPrice: 21, tax: 0.23, weight: 1.2,
|
||||
sku: 'VARIANT-RED', name: 'Variant Red', unitPrice: 18, tax: 0.23, weight: 1.2,
|
||||
ean: '5901234123464', brand: 'Variant Brand', warehouseLocation: 'RED-BIN',
|
||||
});
|
||||
assert.equal(createdOrder.products[0].unitPrice, 10, 'order keeps its transactional net price');
|
||||
assert.equal(createdOrder.products[0].baseUnitPrice, 9.5, 'order also carries the catalog base price');
|
||||
});
|
||||
|
||||
@@ -125,6 +125,30 @@ test('product source identities distinguish base products and combinations', ()
|
||||
});
|
||||
});
|
||||
|
||||
test('metadata resolves the net base price including a combination price impact', async () => {
|
||||
const { resolveProductMetadata, resolveBaseUnitPrice } = require('../src/product-metadata');
|
||||
const api = {
|
||||
getManufacturer: async () => null,
|
||||
getStockAvailabilities: async () => [],
|
||||
};
|
||||
const product = {
|
||||
id: '1', reference: 'BASE', price: '19.90', manufacturer_name: '', location: '',
|
||||
};
|
||||
const combination = {
|
||||
id: '10', id_product: '1', reference: 'VARIANT', price: '2.60', location: '',
|
||||
};
|
||||
|
||||
assert.equal(resolveBaseUnitPrice(product), 19.9);
|
||||
assert.equal(resolveBaseUnitPrice(product, combination), 22.5);
|
||||
assert.deepEqual(await resolveProductMetadata(api, product, {
|
||||
sku: 'VARIANT', combination,
|
||||
}), {
|
||||
unitPrice: 22.5,
|
||||
brand: '',
|
||||
warehouseLocation: '',
|
||||
});
|
||||
});
|
||||
|
||||
test('metadata lookup omits synthetic SKUs and ambiguous variant matches', async () => {
|
||||
let requestedCombinations = 0;
|
||||
const method = loadMethod({
|
||||
|
||||
Reference in New Issue
Block a user