@open-mercato/sync-akeneo 0.8.1-develop.7296.1.2111d779db → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/sync_akeneo/lib/catalog-importer.js +22 -1
- package/dist/modules/sync_akeneo/lib/catalog-importer.js.map +2 -2
- package/package.json +6 -7
- package/src/modules/sync_akeneo/__tests__/catalog-importer.prices.test.ts +712 -0
- package/src/modules/sync_akeneo/lib/catalog-importer.ts +32 -7
|
@@ -469,6 +469,12 @@ function familyRequiresAttribute(family: AkeneoFamily, attributeCode: string): b
|
|
|
469
469
|
return Object.values(requirements).some((codes) => Array.isArray(codes) && codes.includes(attributeCode))
|
|
470
470
|
}
|
|
471
471
|
|
|
472
|
+
function resolvePriceVariantId(price: Pick<CatalogProductPrice, 'variant'>): string | null {
|
|
473
|
+
const variant: unknown = price.variant
|
|
474
|
+
if (typeof variant === 'string') return variant
|
|
475
|
+
return price.variant?.id ?? null
|
|
476
|
+
}
|
|
477
|
+
|
|
472
478
|
function parsePriceCollection(value: unknown): Array<{ currencyCode: string; amount: number }> {
|
|
473
479
|
if (!Array.isArray(value)) return []
|
|
474
480
|
return value
|
|
@@ -2209,6 +2215,7 @@ export async function createAkeneoImporter(client: AkeneoClient, scope: ImportSc
|
|
|
2209
2215
|
CatalogProductPrice,
|
|
2210
2216
|
{
|
|
2211
2217
|
offer: offerId,
|
|
2218
|
+
variant: params.localVariantId,
|
|
2212
2219
|
organizationId: scope.organizationId,
|
|
2213
2220
|
tenantId: scope.tenantId,
|
|
2214
2221
|
},
|
|
@@ -2218,14 +2225,18 @@ export async function createAkeneoImporter(client: AkeneoClient, scope: ImportSc
|
|
|
2218
2225
|
const desiredPriceExternalIds = new Set(offer.prices.map((price) => price.externalId))
|
|
2219
2226
|
for (const price of offer.prices) {
|
|
2220
2227
|
const mappedPriceId = await externalIdMappingService.lookupLocalId('sync_akeneo', 'catalog_product_price', price.externalId, scope)
|
|
2221
|
-
const
|
|
2228
|
+
const mappedPrice = mappedPriceId
|
|
2222
2229
|
? existingPrices.find((entry) => entry.id === mappedPriceId) ?? null
|
|
2223
|
-
:
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2230
|
+
: null
|
|
2231
|
+
const existingPrice = mappedPrice
|
|
2232
|
+
?? existingPrices.find((entry) => (
|
|
2233
|
+
resolvePriceVariantId(entry) === price.variantId
|
|
2234
|
+
&& entry.channelId === price.channelId
|
|
2235
|
+
&& entry.currencyCode === price.currencyCode
|
|
2236
|
+
&& entry.kind === price.priceKindCode
|
|
2237
|
+
&& entry.minQuantity === 1
|
|
2238
|
+
))
|
|
2239
|
+
?? null
|
|
2229
2240
|
const input = {
|
|
2230
2241
|
organizationId: scope.organizationId,
|
|
2231
2242
|
tenantId: scope.tenantId,
|
|
@@ -2271,6 +2282,20 @@ export async function createAkeneoImporter(client: AkeneoClient, scope: ImportSc
|
|
|
2271
2282
|
undefined,
|
|
2272
2283
|
scope,
|
|
2273
2284
|
)
|
|
2285
|
+
const sharedWithOtherVariants = offerPrices.some((price) => {
|
|
2286
|
+
const priceVariantId = resolvePriceVariantId(price)
|
|
2287
|
+
return priceVariantId !== null && priceVariantId !== params.localVariantId
|
|
2288
|
+
})
|
|
2289
|
+
if (sharedWithOtherVariants) {
|
|
2290
|
+
for (const price of offerPrices) {
|
|
2291
|
+
if (resolvePriceVariantId(price) !== params.localVariantId) continue
|
|
2292
|
+
const priceExternalId = await externalIdMappingService.lookupExternalId('sync_akeneo', 'catalog_product_price', price.id, scope)
|
|
2293
|
+
if (priceExternalId) {
|
|
2294
|
+
await executeCommand('catalog.prices.delete', { id: price.id })
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
2297
|
+
continue
|
|
2298
|
+
}
|
|
2274
2299
|
for (const price of offerPrices) {
|
|
2275
2300
|
await executeCommand('catalog.prices.delete', { id: price.id })
|
|
2276
2301
|
}
|