Services refactor
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
PrintfulService,
|
||||
SyncService,
|
||||
WebflowService,
|
||||
PrintfulClient,
|
||||
ProductSyncer,
|
||||
WebflowClient,
|
||||
} from "@blade-and-brawn/commerce";
|
||||
|
||||
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
@@ -25,23 +25,35 @@ const validateEquality = (wValue: any, pValue: any): Validation => {
|
||||
return validation;
|
||||
};
|
||||
|
||||
const wProducts = await WebflowService.Products.getAll();
|
||||
const printful = new PrintfulClient({
|
||||
token: Bun.env.PRINTFUL_AUTH!,
|
||||
storeId: Bun.env.PRINTFUL_STORE_ID!,
|
||||
});
|
||||
|
||||
const webflow = new WebflowClient({
|
||||
siteId: Bun.env.WEBFLOW_SITE_ID!,
|
||||
collectionsId: Bun.env.WEBFLOW_COLLECTION_ID!,
|
||||
token: Bun.env.WEBFLOW_AUTH!,
|
||||
webhookSecret: Bun.env.WEBFLOW_WEBHOOK_SECRET!,
|
||||
});
|
||||
|
||||
const syncer = new ProductSyncer(printful, webflow);
|
||||
|
||||
const wProducts = await webflow.Products.getAll();
|
||||
|
||||
let invalidCount = 0;
|
||||
for (const wProduct of wProducts) {
|
||||
for (const sku of wProduct.skus ?? []) {
|
||||
console.log("Webflow: " + sku.id, sku.fieldData.name);
|
||||
|
||||
const pVariant = await PrintfulService.Products.Variants.get(
|
||||
`@${sku.id}`,
|
||||
);
|
||||
const pVariant = await printful.Products.Variants.get(`@${sku.id}`);
|
||||
if (pVariant) {
|
||||
console.log("Printful: " + pVariant.id, pVariant.name);
|
||||
const validations = [
|
||||
// validateEquality(sku.fieldData.name, pVariant.name),
|
||||
validateEquality(
|
||||
sku.fieldData["sku-values"]?.["color"],
|
||||
SyncService.findColorInProductName(pVariant.name),
|
||||
syncer.findColorInProductName(pVariant.name),
|
||||
),
|
||||
validateEquality(
|
||||
sku.fieldData["sku-values"]?.["size"],
|
||||
@@ -55,7 +67,7 @@ for (const wProduct of wProducts) {
|
||||
|
||||
// if (!validateEquality(sku.fieldData.name, pVariant.name).isValid) {
|
||||
// sku.fieldData.name = pVariant.name;
|
||||
// await WebflowService.Products.Skus.update(wProduct.product.id, sku.id, sku);
|
||||
// await webflow.Products.Skus.update(wProduct.product.id, sku.id, sku);
|
||||
// }
|
||||
|
||||
const errors = validations.filter((v) => !v.isValid);
|
||||
|
||||
Reference in New Issue
Block a user