@open-mercato/sync-akeneo 0.8.1-develop.7297.1.67605e74f9 → 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.
@@ -259,6 +259,11 @@ function familyRequiresAttribute(family, attributeCode) {
259
259
  if (!requirements || typeof requirements !== "object") return false;
260
260
  return Object.values(requirements).some((codes) => Array.isArray(codes) && codes.includes(attributeCode));
261
261
  }
262
+ function resolvePriceVariantId(price) {
263
+ const variant = price.variant;
264
+ if (typeof variant === "string") return variant;
265
+ return price.variant?.id ?? null;
266
+ }
262
267
  function parsePriceCollection(value) {
263
268
  if (!Array.isArray(value)) return [];
264
269
  return value.map((entry) => {
@@ -1668,6 +1673,7 @@ async function createAkeneoImporter(client, scope) {
1668
1673
  CatalogProductPrice,
1669
1674
  {
1670
1675
  offer: offerId,
1676
+ variant: params.localVariantId,
1671
1677
  organizationId: scope.organizationId,
1672
1678
  tenantId: scope.tenantId
1673
1679
  },
@@ -1677,7 +1683,8 @@ async function createAkeneoImporter(client, scope) {
1677
1683
  const desiredPriceExternalIds = new Set(offer.prices.map((price) => price.externalId));
1678
1684
  for (const price of offer.prices) {
1679
1685
  const mappedPriceId = await externalIdMappingService.lookupLocalId("sync_akeneo", "catalog_product_price", price.externalId, scope);
1680
- const existingPrice = mappedPriceId ? existingPrices.find((entry) => entry.id === mappedPriceId) ?? null : existingPrices.find((entry) => (typeof entry.variant === "string" ? entry.variant : entry.variant?.id ?? null) === price.variantId && entry.channelId === price.channelId && entry.currencyCode === price.currencyCode && entry.kind === price.priceKindCode) ?? null;
1686
+ const mappedPrice = mappedPriceId ? existingPrices.find((entry) => entry.id === mappedPriceId) ?? null : null;
1687
+ const existingPrice = mappedPrice ?? existingPrices.find((entry) => resolvePriceVariantId(entry) === price.variantId && entry.channelId === price.channelId && entry.currencyCode === price.currencyCode && entry.kind === price.priceKindCode && entry.minQuantity === 1) ?? null;
1681
1688
  const input2 = {
1682
1689
  organizationId: scope.organizationId,
1683
1690
  tenantId: scope.tenantId,
@@ -1719,6 +1726,20 @@ async function createAkeneoImporter(client, scope) {
1719
1726
  void 0,
1720
1727
  scope
1721
1728
  );
1729
+ const sharedWithOtherVariants = offerPrices.some((price) => {
1730
+ const priceVariantId = resolvePriceVariantId(price);
1731
+ return priceVariantId !== null && priceVariantId !== params.localVariantId;
1732
+ });
1733
+ if (sharedWithOtherVariants) {
1734
+ for (const price of offerPrices) {
1735
+ if (resolvePriceVariantId(price) !== params.localVariantId) continue;
1736
+ const priceExternalId = await externalIdMappingService.lookupExternalId("sync_akeneo", "catalog_product_price", price.id, scope);
1737
+ if (priceExternalId) {
1738
+ await executeCommand("catalog.prices.delete", { id: price.id });
1739
+ }
1740
+ }
1741
+ continue;
1742
+ }
1722
1743
  for (const price of offerPrices) {
1723
1744
  await executeCommand("catalog.prices.delete", { id: price.id });
1724
1745
  }