fix(prestashop): resolve bundle item VAT with fallback (1.1.14)

This commit is contained in:
fatequod
2026-09-22 12:21:13 +02:00
parent be4284bdd6
commit 93ebfe728d
7 changed files with 131 additions and 7 deletions
+14
View File
@@ -83,6 +83,7 @@ test('order import passes verified metadata and pack facts only through core/ord
'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 taxLookups = [];
const api = {
isBLSupported: async () => false,
makeRequest: async endpoint => {
@@ -93,6 +94,10 @@ test('order import passes verified metadata and pack facts only through core/ord
},
getProduct: async id => products[id],
getProductCombination: async id => combinations[id],
getProductTaxRate: async (productId, combinationId, context) => {
taxLookups.push({ productId, combinationId, context });
return productId === '20' ? 0.08 : null;
},
getProductCoverImageUrl: async () => null,
getCurrency: async () => ({ iso_code: 'PLN' }),
getCountry: async () => ({ iso_code: 'PL' }),
@@ -111,9 +116,18 @@ test('order import passes verified metadata and pack facts only through core/ord
assert.equal(createdOrder.products[0].pack[0].sourceId, 'product:20:combination:200');
assert.equal(createdOrder.products[0].pack[0].previousSourceId, '20');
assert.equal(createdOrder.products[0].pack[0].baseUnitPrice, 3.25);
assert.equal(createdOrder.products[0].pack[0].tax, 0.08);
assert.equal(createdOrder.products[0].pack[1].sourceId, 'product:21:combination:0');
assert.equal(createdOrder.products[0].pack[1].sku, 'REGULAR-ITEM');
assert.equal(createdOrder.products[0].pack[1].baseUnitPrice, 4.5);
assert.equal(createdOrder.products[0].pack[1].tax, 0.23, 'missing tax data uses the configured fallback');
assert.deepEqual(taxLookups, [{
productId: '20', combinationId: '200',
context: { countryId: '1', stateId: undefined, postcode: '00-001', currencyId: '1' },
}, {
productId: '21', combinationId: '0',
context: { countryId: '1', stateId: undefined, postcode: '00-001', currencyId: '1' },
}]);
assert.deepEqual(createdOrder.products.slice(1).map(product => product.sku), [
'VARIANT-BLUE', 'VARIANT-RED',
]);
+33
View File
@@ -160,6 +160,39 @@ test('uses a combination image before the base product cover', async () => {
assert.match(url, /ws_key=secret/);
});
test('derives a combination VAT rate from the base product tax calculation and caches it', async t => {
const originalFetch = Core.fetch;
t.after(() => { Core.fetch = originalFetch; });
const urls = [];
Core.fetch = async url => {
urls.push(url);
return response(200, { product: { orbito_price_net: '100.00', orbito_price_gross: '123.00' } });
};
const api = new PrestashopApi('https://shop.example', 'secret', true, { maxGetAttempts: 1 });
const context = { countryId: '1', stateId: '0', postcode: '00-001', currencyId: '2' };
assert.equal(await api.getProductTaxRate('20', '200', context), 0.23);
assert.equal(await api.getProductTaxRate('20', '200', context), 0.23);
assert.equal(urls.length, 1);
assert.match(urls[0], /products\/20\?/);
assert.match(urls[0], /price%5Borbito_price_net%5D%5Buse_tax%5D=0/);
assert.match(urls[0], /price%5Borbito_price_gross%5D%5Buse_tax%5D=1/);
assert.match(urls[0], /price%5Borbito_price_gross%5D%5Bproduct_attribute%5D=200/);
assert.match(urls[0], /price%5Borbito_price_gross%5D%5Bcountry%5D=1/);
assert.match(urls[0], /price%5Borbito_price_gross%5D%5Bpostcode%5D=00-001/);
});
test('returns no VAT rate when PrestaShop cannot provide comparable net and gross prices', async t => {
const originalFetch = Core.fetch;
t.after(() => { Core.fetch = originalFetch; });
Core.fetch = async () => response(200, {
product: { orbito_price_net: 'invalid', orbito_price_gross: '123.00' },
});
const api = new PrestashopApi('https://shop.example', 'secret', true, { maxGetAttempts: 1 });
assert.equal(await api.getProductTaxRate('20', '0', { countryId: '1' }), null);
});
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; });