Skip to content

Commit

Permalink
fix: decimal shift scayle price denominations
Browse files Browse the repository at this point in the history
  • Loading branch information
Benj0s committed Jan 20, 2025
1 parent 506bca4 commit 7643c8d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
56 changes: 28 additions & 28 deletions src/codec/codecs/commerce/scayle/__snapshots__/scayle.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ exports[`scayle integration getCategory by slug 1`] = `
"url": "https://dc-integration-middleware-test-demo-absolute-url.cdn.aboutyou.cloud/images/68bf124a0517bffaa5fe1dc7ac8707db.jpg",
},
],
"listPrice": "2,990.00",
"salePrice": "2,990.00",
"listPrice": "29.90",
"salePrice": "29.90",
"sku": "LEV0074002000005_S",
},
],
Expand Down Expand Up @@ -158,8 +158,8 @@ exports[`scayle integration getProduct by ID 1`] = `
"url": "https://dc-integration-middleware-test-demo-absolute-url.cdn.aboutyou.cloud/images/68bf124a0517bffaa5fe1dc7ac8707db.jpg",
},
],
"listPrice": "2,990.00",
"salePrice": "2,990.00",
"listPrice": "29.90",
"salePrice": "29.90",
"sku": "LEV0074002000005_S",
},
],
Expand Down Expand Up @@ -194,8 +194,8 @@ exports[`scayle integration getProducts by IDs 1`] = `
"url": "https://dc-integration-middleware-test-demo.cdn.aboutyou.cloud/images/68bf124a0517bffaa5fe1dc7ac8707db.jpg",
},
],
"listPrice": "3,990.00",
"salePrice": "3,990.00",
"listPrice": "39.90",
"salePrice": "39.90",
"sku": "THS0906008000001_S",
},
],
Expand Down Expand Up @@ -226,8 +226,8 @@ exports[`scayle integration getProducts by IDs 1`] = `
"url": "https://dc-integration-middleware-test-demo.cdn.aboutyou.cloud/images/68bf124a0517bffaa5fe1dc7ac8707db.jpg",
},
],
"listPrice": "3,990.00",
"salePrice": "3,990.00",
"listPrice": "39.90",
"salePrice": "39.90",
"sku": "THS0906006000001_S",
},
],
Expand Down Expand Up @@ -263,8 +263,8 @@ exports[`scayle integration getProducts by categories - paginated 1`] = `
"url": "https://dc-integration-middleware-test-demo.cdn.aboutyou.cloud/images/68bf124a0517bffaa5fe1dc7ac8707db.jpg",
},
],
"listPrice": "32,990.00",
"salePrice": "32,990.00",
"listPrice": "329.90",
"salePrice": "329.90",
"sku": "LIJ0480001000004_38",
},
],
Expand Down Expand Up @@ -295,8 +295,8 @@ exports[`scayle integration getProducts by categories - paginated 1`] = `
"url": "https://dc-integration-middleware-test-demo.cdn.aboutyou.cloud/images/68bf124a0517bffaa5fe1dc7ac8707db.jpg",
},
],
"listPrice": "2,990.00",
"salePrice": "2,990.00",
"listPrice": "29.90",
"salePrice": "29.90",
"sku": "LEV0031009000002_S",
},
],
Expand Down Expand Up @@ -327,8 +327,8 @@ exports[`scayle integration getProducts by categories - paginated 1`] = `
"url": "https://dc-integration-middleware-test-demo.cdn.aboutyou.cloud/images/68bf124a0517bffaa5fe1dc7ac8707db.jpg",
},
],
"listPrice": "2,990.00",
"salePrice": "2,990.00",
"listPrice": "29.90",
"salePrice": "29.90",
"sku": "LEV0031001002000_S",
},
],
Expand Down Expand Up @@ -359,8 +359,8 @@ exports[`scayle integration getProducts by categories - paginated 1`] = `
"url": "https://dc-integration-middleware-test-demo.cdn.aboutyou.cloud/images/68bf124a0517bffaa5fe1dc7ac8707db.jpg",
},
],
"listPrice": "2,990.00",
"salePrice": "2,990.00",
"listPrice": "29.90",
"salePrice": "29.90",
"sku": "LEV0074002000005_S",
},
],
Expand Down Expand Up @@ -399,8 +399,8 @@ exports[`scayle integration getProducts by category id 1`] = `
"url": "https://dc-integration-middleware-test-demo-absolute-url.cdn.aboutyou.cloud/images/68bf124a0517bffaa5fe1dc7ac8707db.jpg",
},
],
"listPrice": "2,990.00",
"salePrice": "2,990.00",
"listPrice": "29.90",
"salePrice": "29.90",
"sku": "LEV0074002000005_S",
},
],
Expand Down Expand Up @@ -436,8 +436,8 @@ exports[`scayle integration getProducts by keyword - paginated 1`] = `
"url": "https://dc-integration-middleware-test-demo.cdn.aboutyou.cloud/images/68bf124a0517bffaa5fe1dc7ac8707db.jpg",
},
],
"listPrice": "32,990.00",
"salePrice": "32,990.00",
"listPrice": "329.90",
"salePrice": "329.90",
"sku": "LIJ0480001000004_38",
},
],
Expand Down Expand Up @@ -468,8 +468,8 @@ exports[`scayle integration getProducts by keyword - paginated 1`] = `
"url": "https://dc-integration-middleware-test-demo.cdn.aboutyou.cloud/images/68bf124a0517bffaa5fe1dc7ac8707db.jpg",
},
],
"listPrice": "2,990.00",
"salePrice": "2,990.00",
"listPrice": "29.90",
"salePrice": "29.90",
"sku": "LEV0031009000002_S",
},
],
Expand Down Expand Up @@ -500,8 +500,8 @@ exports[`scayle integration getProducts by keyword - paginated 1`] = `
"url": "https://dc-integration-middleware-test-demo.cdn.aboutyou.cloud/images/68bf124a0517bffaa5fe1dc7ac8707db.jpg",
},
],
"listPrice": "2,990.00",
"salePrice": "2,990.00",
"listPrice": "29.90",
"salePrice": "29.90",
"sku": "LEV0031001002000_S",
},
],
Expand Down Expand Up @@ -532,8 +532,8 @@ exports[`scayle integration getProducts by keyword - paginated 1`] = `
"url": "https://dc-integration-middleware-test-demo.cdn.aboutyou.cloud/images/68bf124a0517bffaa5fe1dc7ac8707db.jpg",
},
],
"listPrice": "2,990.00",
"salePrice": "2,990.00",
"listPrice": "29.90",
"salePrice": "29.90",
"sku": "LEV0074002000005_S",
},
],
Expand Down Expand Up @@ -572,8 +572,8 @@ exports[`scayle integration getProducts by keyword 1`] = `
"url": "https://dc-integration-middleware-test-demo-absolute-url.cdn.aboutyou.cloud/images/68bf124a0517bffaa5fe1dc7ac8707db.jpg",
},
],
"listPrice": "2,990.00",
"salePrice": "2,990.00",
"listPrice": "29.90",
"salePrice": "29.90",
"sku": "LEV0074002000005_S",
},
],
Expand Down
8 changes: 6 additions & 2 deletions src/codec/codecs/commerce/scayle/mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { formatMoneyString } from '../../../../common/util'
import { CodecPropertyConfig } from '../../core'
import { CodecConfig } from '.'

const decimalShiftDenomination = (price: string) => {
return Number(price) > 0 ? Number(price) / 100 : undefined
}

export const mapProduct = (product: ScayleProduct, config: CodecPropertyConfig<CodecConfig>): Product | null => {
if (!product) {
return null
Expand Down Expand Up @@ -47,10 +51,10 @@ export const mapProductVariants = (variant: ScaylaProductVariant): Variant => {
return {
id: String(variant.id),
sku: variant.referenceKey,
listPrice: formatMoneyString(variant.price?.withTax, {
listPrice: formatMoneyString(decimalShiftDenomination(variant.price?.withTax), {
currency: variant.price?.currencyCode
}),
salePrice: formatMoneyString(variant.price?.withTax, {
salePrice: formatMoneyString(decimalShiftDenomination(variant.price?.withTax), {
currency: variant.price?.currencyCode
}),
attributes: {},
Expand Down

0 comments on commit 7643c8d

Please sign in to comment.