Product/sku deletion fixes
This commit is contained in:
@@ -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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user