@open-mercato/sync-akeneo 0.11.1-develop.8378.1.e2099fcc8e → 0.11.1-develop.8385.1.e9d8a4b8f7

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.
@@ -813,6 +813,8 @@ export async function createAkeneoImporter(client: AkeneoClient, scope: ImportSc
813
813
  const preferredPriceKindCodeCache = new Map<string, Promise<string | null>>()
814
814
  const attributeOptionLabelCache = new Map<string, Promise<Map<string, string>>>()
815
815
  const defaultProductSettings = buildDefaultAkeneoMapping('products').settings?.products
816
+ const salesChannelsAvailable = em.getMetadata().has(SalesChannel)
817
+ let salesChannelsUnavailableReported = false
816
818
 
817
819
  function buildCommandContext(): CommandRuntimeContext {
818
820
  return {
@@ -976,7 +978,20 @@ export async function createAkeneoImporter(client: AkeneoClient, scope: ImportSc
976
978
  return categoryCache.get(code) ?? null
977
979
  }
978
980
 
981
+ async function reportSalesChannelsUnavailable(): Promise<void> {
982
+ if (salesChannelsUnavailableReported) return
983
+ salesChannelsUnavailableReported = true
984
+ const integrationLogService = container.resolve('integrationLogService') as IntegrationLogService
985
+ await integrationLogService.write({
986
+ integrationId: 'sync_akeneo',
987
+ level: 'warn',
988
+ code: 'sync_akeneo.sales_channels_unavailable',
989
+ message: 'The sales module is disabled, so Akeneo channel-bound offers and prices were skipped.',
990
+ }, scope)
991
+ }
992
+
979
993
  async function resolveChannel(code: string, options?: { createIfMissing?: boolean; label?: string | null }): Promise<{ id: string; code: string } | null> {
994
+ if (!salesChannelsAvailable) return null
980
995
  const normalizedCode = code.trim().toLowerCase()
981
996
  if (!normalizedCode) return null
982
997
  const cacheKey = `${normalizedCode}:${options?.createIfMissing ? 'create' : 'read'}:${options?.label ?? ''}`
@@ -1038,6 +1053,7 @@ export async function createAkeneoImporter(client: AkeneoClient, scope: ImportSc
1038
1053
  }
1039
1054
 
1040
1055
  async function resolvePreferredLocalChannelCode(): Promise<string | null> {
1056
+ if (!salesChannelsAvailable) return null
1041
1057
  const cacheKey = 'preferred'
1042
1058
  if (!preferredChannelCodeCache.has(cacheKey)) {
1043
1059
  preferredChannelCodeCache.set(cacheKey, (async () => {
@@ -1834,6 +1850,10 @@ export async function createAkeneoImporter(client: AkeneoClient, scope: ImportSc
1834
1850
  settings: AkeneoProductMappingSettings
1835
1851
  priceAttributeCodes: string[]
1836
1852
  }): Promise<AkeneoProductMappingSettings['priceMappings']> {
1853
+ if (!salesChannelsAvailable) {
1854
+ if (params.priceAttributeCodes.length > 0) await reportSalesChannelsUnavailable()
1855
+ return []
1856
+ }
1837
1857
  const fallbackChannelCode = await resolvePreferredLocalChannelCode()
1838
1858
 
1839
1859
  const mappings: AkeneoProductMappingSettings['priceMappings'] = []
@@ -2145,6 +2165,10 @@ export async function createAkeneoImporter(client: AkeneoClient, scope: ImportSc
2145
2165
  resolvedProductDescription: string | null
2146
2166
  variantExternalId: string
2147
2167
  }): Promise<void> {
2168
+ if (!salesChannelsAvailable) {
2169
+ if (params.settings.priceMappings.length > 0) await reportSalesChannelsUnavailable()
2170
+ return
2171
+ }
2148
2172
  const desiredOffers = new Map<string, DesiredOffer>()
2149
2173
  for (const priceMapping of params.settings.priceMappings) {
2150
2174
  const channel = await resolveChannel(priceMapping.localChannelCode, {
@@ -382,15 +382,17 @@ async function loadLocalDiscoveryContext(em: EntityManager, scope: IntegrationSc
382
382
  priceKinds: PriceKindOption[]
383
383
  }> {
384
384
  const [channels, priceKinds] = await Promise.all([
385
- findWithDecryption(em, SalesChannel, {
386
- organizationId: scope.organizationId,
387
- tenantId: scope.tenantId,
388
- deletedAt: null,
389
- isActive: true,
390
- }, {
391
- fields: ['code', 'name'],
392
- orderBy: { name: 'asc' },
393
- }, scope),
385
+ em.getMetadata().has(SalesChannel)
386
+ ? findWithDecryption(em, SalesChannel, {
387
+ organizationId: scope.organizationId,
388
+ tenantId: scope.tenantId,
389
+ deletedAt: null,
390
+ isActive: true,
391
+ }, {
392
+ fields: ['code', 'name'],
393
+ orderBy: { name: 'asc' },
394
+ }, scope)
395
+ : Promise.resolve<SalesChannel[]>([]),
394
396
  findWithDecryption(em, CatalogPriceKind, {
395
397
  tenantId: scope.tenantId,
396
398
  deletedAt: null,