fix(prestashop): import combinations as distinct products in 1.1.10
This commit is contained in:
@@ -43,6 +43,12 @@ test('order import upserts verified metadata for the ordered product and pack it
|
||||
order_rows: [{
|
||||
product_id: '10', product_attribute_id: '100', product_name: 'Pack', product_reference: 'PACK-V',
|
||||
product_ean13: '', unit_price_tax_excl: '10', unit_price_tax_incl: '12.3', product_quantity: '1',
|
||||
}, {
|
||||
product_id: '30', product_attribute_id: '300', product_name: 'Variant Blue', product_reference: 'OLD-BLUE',
|
||||
product_ean13: '', unit_price_tax_excl: '20', unit_price_tax_incl: '24.6', product_quantity: '1',
|
||||
}, {
|
||||
product_id: '30', product_attribute_id: '301', product_name: 'Variant Red', product_reference: 'OLD-RED',
|
||||
product_ean13: '', unit_price_tax_excl: '21', unit_price_tax_incl: '25.83', product_quantity: '1',
|
||||
}],
|
||||
},
|
||||
};
|
||||
@@ -55,10 +61,16 @@ test('order import upserts verified metadata for the ordered product and pack it
|
||||
id: '20', name: 'Item', reference: 'ITEM-BASE', manufacturer_name: 'Item Brand', location: 'ITEM-BASE-BIN',
|
||||
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: {},
|
||||
},
|
||||
};
|
||||
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' },
|
||||
};
|
||||
const api = {
|
||||
isBLSupported: async () => false,
|
||||
@@ -79,13 +91,33 @@ test('order import upserts verified metadata for the ordered product and pack it
|
||||
};
|
||||
await importFromPSOrder('1', api, { _id: 'default', orderStatus: '000000000000000000000001', statusMapping: [] });
|
||||
|
||||
assert.equal(upserts.length, 2);
|
||||
assert.deepEqual(upserts.find(product => product.sourceId === '10'), {
|
||||
sourceModule: 'core/prestashop', sourceId: '10', sku: 'PACK-V', name: 'Pack', unitPrice: 10,
|
||||
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,
|
||||
ean: '', brand: 'Pack Brand', warehouseLocation: 'PACK-V-BIN',
|
||||
});
|
||||
assert.deepEqual(upserts.find(product => product.sourceId === '20'), {
|
||||
sourceModule: 'core/prestashop', sourceId: '20', sku: 'ITEM-V', name: 'Item',
|
||||
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,
|
||||
brand: 'Item Brand', warehouseLocation: 'ITEM-V-BIN',
|
||||
});
|
||||
assert.deepEqual(
|
||||
upserts.filter(product => product.sourceId.startsWith('product:30:')).map(product => product.sourceId),
|
||||
['product:30:combination:300', 'product:30:combination:301']
|
||||
);
|
||||
assert.deepEqual(
|
||||
upserts.filter(product => product.sourceId.startsWith('product:30:')).map(product => product.sku),
|
||||
['VARIANT-BLUE', 'VARIANT-RED']
|
||||
);
|
||||
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,
|
||||
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,
|
||||
ean: '5901234123464', brand: 'Variant Brand', warehouseLocation: 'RED-BIN',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -108,6 +108,18 @@ test('does not turn an unsafe reference filter into an empty combination match',
|
||||
assert.equal(await api.findProductCombinationsByReference('1', 'SKU[1]'), null);
|
||||
});
|
||||
|
||||
test('uses a combination image before the base product cover', async () => {
|
||||
const api = new PrestashopApi('https://shop.example', 'secret', true, { maxGetAttempts: 1 });
|
||||
api.getProduct = async () => assert.fail('base product must not be fetched when variant has an image');
|
||||
|
||||
const url = await api.getProductCoverImageUrl('1', {
|
||||
associations: { images: [{ id: '55' }] },
|
||||
});
|
||||
|
||||
assert.match(url, /images\/products\/1\/55\/home_default/);
|
||||
assert.match(url, /ws_key=secret/);
|
||||
});
|
||||
|
||||
test('collects public customer notes from order, cart and customer thread without cross-order leakage', async t => {
|
||||
const originalFetch = Core.fetch;
|
||||
t.after(() => { Core.fetch = originalFetch; });
|
||||
|
||||
@@ -3,13 +3,14 @@ const assert = require('node:assert/strict');
|
||||
const Module = require('node:module');
|
||||
const path = require('node:path');
|
||||
|
||||
function loadMethod({ onGetProduct, onFindCombinations, onManufacturer, onStocks }) {
|
||||
function loadMethod({ onGetProduct, onGetCombination, onFindCombinations, onManufacturer, onStocks }) {
|
||||
const methodPath = path.resolve(__dirname, '../methods/product/get_metadata.js');
|
||||
const originalLoad = Module._load;
|
||||
Module._load = function(request, parent, isMain) {
|
||||
if (request === '../../src/PrestaApi') {
|
||||
return class PrestashopApi {
|
||||
async getProduct(id) { return onGetProduct(id); }
|
||||
async getProductCombination(id) { return onGetCombination ? onGetCombination(id) : null; }
|
||||
async findProductCombinationsByReference(id, sku) { return onFindCombinations(id, sku); }
|
||||
async getManufacturer(id) { return onManufacturer(id); }
|
||||
async getStockAvailabilities(id, attributeId) { return onStocks(id, attributeId); }
|
||||
@@ -80,6 +81,50 @@ test('metadata lookup returns a variant only for exactly one verified reference
|
||||
});
|
||||
});
|
||||
|
||||
test('metadata lookup resolves a composite variant identity by exact combination ID', async () => {
|
||||
const combinationCalls = [];
|
||||
const method = loadMethod({
|
||||
onGetProduct: async id => ({ id, reference: 'base', manufacturer_name: 'Brand', location: 'BASE' }),
|
||||
onGetCombination: async id => {
|
||||
combinationCalls.push(id);
|
||||
return { id, id_product: '1', reference: 'variant', location: 'BIN-1' };
|
||||
},
|
||||
onFindCombinations: async () => assert.fail('composite identity must not search by reference'),
|
||||
onManufacturer: async () => null,
|
||||
onStocks: async () => [],
|
||||
});
|
||||
|
||||
const result = await method({
|
||||
products: [{ sourceId: 'product:1:combination:10', sku: ' VaRiAnT ' }],
|
||||
}, {});
|
||||
|
||||
assert.deepEqual(combinationCalls, ['10']);
|
||||
assert.deepEqual(result, {
|
||||
results: [{
|
||||
sourceId: 'product:1:combination:10',
|
||||
sku: 'VaRiAnT',
|
||||
brand: 'Brand',
|
||||
warehouseLocation: 'BIN-1',
|
||||
}],
|
||||
});
|
||||
});
|
||||
|
||||
test('product source identities distinguish base products and combinations', () => {
|
||||
const { buildProductSourceId, parseProductSourceId } = require('../src/product-metadata');
|
||||
|
||||
assert.equal(buildProductSourceId('10', 0), 'product:10:combination:0');
|
||||
assert.equal(buildProductSourceId('10', '101'), 'product:10:combination:101');
|
||||
assert.deepEqual(parseProductSourceId('product:10:combination:101'), {
|
||||
sourceId: 'product:10:combination:101',
|
||||
productId: '10',
|
||||
combinationId: '101',
|
||||
legacy: false,
|
||||
});
|
||||
assert.deepEqual(parseProductSourceId('10'), {
|
||||
sourceId: '10', productId: '10', combinationId: null, legacy: true,
|
||||
});
|
||||
});
|
||||
|
||||
test('metadata lookup omits synthetic SKUs and ambiguous variant matches', async () => {
|
||||
let requestedCombinations = 0;
|
||||
const method = loadMethod({
|
||||
|
||||
Reference in New Issue
Block a user