@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.
@@ -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 existingPrice = mappedPriceId
2228
+ const mappedPrice = mappedPriceId
2222
2229
  ? existingPrices.find((entry) => entry.id === mappedPriceId) ?? null
2223
- : existingPrices.find((entry) => (
2224
- (typeof entry.variant === 'string' ? entry.variant : entry.variant?.id ?? null) === price.variantId
2225
- && entry.channelId === price.channelId
2226
- && entry.currencyCode === price.currencyCode
2227
- && entry.kind === price.priceKindCode
2228
- )) ?? null
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
  }