Product/sku deletion fixes

This commit is contained in:
Dominic Ferrando
2026-07-17 13:01:19 -04:00
parent 1ffc2fe79d
commit 082d7f7cb3
9 changed files with 109 additions and 9 deletions
+21
View File
@@ -145,6 +145,27 @@ export class ProductSyncer {
);
}
}
// Remove webflow SKUs whose color+size no longer corresponds to any current printful variant.
const currentPKeys = new Set<string>(
pMetaProduct.entries.flatMap(({ colorGroup, product: pProduct }) =>
pProduct.sync_variants.map((pVariant) => `${colorGroup ?? pVariant.color}::${pVariant.size}`)
)
);
const orphanedWSkus = wProduct.skus.filter((existingWSku) =>
!currentPKeys.has(`${existingWSku.fieldData["sku-values"]?.["color"]}::${existingWSku.fieldData["sku-values"]?.["size"]}`)
);
for (const orphanedWSku of orphanedWSkus) {
this.log.info(
{
wSkuId: orphanedWSku.id,
color: orphanedWSku.fieldData["sku-values"]?.["color"],
size: orphanedWSku.fieldData["sku-values"]?.["size"],
},
"removing webflow SKU no longer present in printful",
);
await this.Webflow.Products.Skus.remove(orphanedWSku.id);
}
} else {
this.log.info("existing webflow product not found, creating it");