@labdigital/commercetools-mock 2.59.1 → 2.61.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.
Files changed (222) hide show
  1. package/dist/{index.d.ts → index.d.mts} +154 -275
  2. package/dist/{index.js → index.mjs} +413 -401
  3. package/dist/index.mjs.map +1 -0
  4. package/package.json +30 -18
  5. package/src/config.ts +1 -1
  6. package/src/ctMock.test.ts +1 -1
  7. package/src/ctMock.ts +22 -21
  8. package/src/index.test.ts +1 -1
  9. package/src/index.ts +3 -3
  10. package/src/lib/haversine.test.ts +2 -2
  11. package/src/lib/masking.ts +1 -1
  12. package/src/lib/parser.ts +2 -2
  13. package/src/lib/password.ts +1 -1
  14. package/src/lib/predicateParser.test.ts +1 -1
  15. package/src/lib/predicateParser.ts +4 -4
  16. package/src/lib/product-review-statistics.test.ts +4 -8
  17. package/src/lib/productSearchFilter.test.ts +3 -3
  18. package/src/lib/productSearchFilter.ts +6 -6
  19. package/src/lib/projectionSearchFilter.test.ts +3 -3
  20. package/src/lib/projectionSearchFilter.ts +4 -4
  21. package/src/lib/review-statistics.ts +1 -1
  22. package/src/lib/searchQueryTypeChecker.test.ts +3 -3
  23. package/src/lib/searchQueryTypeChecker.ts +8 -4
  24. package/src/lib/tax.test.ts +119 -0
  25. package/src/lib/tax.ts +186 -0
  26. package/src/oauth/server.test.ts +7 -7
  27. package/src/oauth/server.ts +7 -7
  28. package/src/priceSelector.test.ts +1 -1
  29. package/src/priceSelector.ts +2 -2
  30. package/src/product-projection-search.ts +10 -12
  31. package/src/product-search-availability.test.ts +1 -1
  32. package/src/product-search.ts +6 -7
  33. package/src/projectAPI.test.ts +1 -1
  34. package/src/projectAPI.ts +7 -7
  35. package/src/repositories/abstract.ts +8 -10
  36. package/src/repositories/as-associate.test.ts +4 -4
  37. package/src/repositories/as-associate.ts +3 -3
  38. package/src/repositories/associate-role.ts +7 -9
  39. package/src/repositories/attribute-group.test.ts +3 -3
  40. package/src/repositories/attribute-group.ts +5 -5
  41. package/src/repositories/business-unit.test.ts +6 -6
  42. package/src/repositories/business-unit.ts +21 -23
  43. package/src/repositories/cart/actions.ts +79 -15
  44. package/src/repositories/cart/helpers.ts +5 -84
  45. package/src/repositories/cart/index.test.ts +53 -10
  46. package/src/repositories/cart/index.ts +17 -21
  47. package/src/repositories/cart-discount/actions.ts +5 -6
  48. package/src/repositories/cart-discount/index.ts +5 -5
  49. package/src/repositories/category/actions.ts +4 -4
  50. package/src/repositories/category/index.test.ts +3 -3
  51. package/src/repositories/category/index.ts +8 -8
  52. package/src/repositories/channel.test.ts +4 -4
  53. package/src/repositories/channel.ts +6 -6
  54. package/src/repositories/custom-object.ts +11 -8
  55. package/src/repositories/customer/actions.ts +9 -9
  56. package/src/repositories/customer/index.test.ts +3 -3
  57. package/src/repositories/customer/index.ts +12 -9
  58. package/src/repositories/customer-group.test.ts +4 -4
  59. package/src/repositories/customer-group.ts +6 -6
  60. package/src/repositories/discount-code/actions.ts +4 -4
  61. package/src/repositories/discount-code/index.ts +5 -5
  62. package/src/repositories/discount-group/actions.ts +3 -4
  63. package/src/repositories/discount-group/index.ts +4 -4
  64. package/src/repositories/errors.ts +1 -1
  65. package/src/repositories/extension.test.ts +3 -3
  66. package/src/repositories/extension.ts +6 -6
  67. package/src/repositories/helpers.ts +9 -12
  68. package/src/repositories/index.test.ts +3 -3
  69. package/src/repositories/index.ts +43 -43
  70. package/src/repositories/inventory-entry/actions.ts +15 -3
  71. package/src/repositories/inventory-entry/index.ts +5 -5
  72. package/src/repositories/my-customer.ts +5 -5
  73. package/src/repositories/my-order.ts +2 -2
  74. package/src/repositories/my-quote-request.ts +1 -1
  75. package/src/repositories/order/actions.ts +8 -9
  76. package/src/repositories/order/index.test.ts +191 -9
  77. package/src/repositories/order/index.ts +63 -21
  78. package/src/repositories/order-edit.ts +4 -4
  79. package/src/repositories/payment/actions.ts +6 -6
  80. package/src/repositories/payment/helpers.ts +3 -3
  81. package/src/repositories/payment/index.ts +7 -7
  82. package/src/repositories/product/actions.ts +7 -7
  83. package/src/repositories/product/helpers.ts +4 -4
  84. package/src/repositories/product/index.ts +13 -13
  85. package/src/repositories/product-discount.ts +9 -6
  86. package/src/repositories/product-projection.ts +7 -7
  87. package/src/repositories/product-selection.ts +9 -6
  88. package/src/repositories/product-tailoring.ts +6 -3
  89. package/src/repositories/product-type.ts +8 -5
  90. package/src/repositories/project.ts +5 -5
  91. package/src/repositories/quote/actions.ts +6 -6
  92. package/src/repositories/quote/index.ts +5 -5
  93. package/src/repositories/quote-request/actions.ts +6 -6
  94. package/src/repositories/quote-request/index.test.ts +3 -3
  95. package/src/repositories/quote-request/index.ts +5 -5
  96. package/src/repositories/quote-staged/actions.ts +6 -6
  97. package/src/repositories/quote-staged/index.ts +5 -5
  98. package/src/repositories/recurrence-policy/actions.ts +3 -3
  99. package/src/repositories/recurrence-policy/index.ts +4 -8
  100. package/src/repositories/recurring-order/actions.ts +3 -3
  101. package/src/repositories/recurring-order/index.ts +5 -5
  102. package/src/repositories/review.test.ts +5 -5
  103. package/src/repositories/review.ts +10 -9
  104. package/src/repositories/shipping-method/actions.ts +7 -9
  105. package/src/repositories/shipping-method/helpers.ts +1 -1
  106. package/src/repositories/shipping-method/index.ts +8 -8
  107. package/src/repositories/shopping-list/actions.ts +5 -5
  108. package/src/repositories/shopping-list/index.ts +7 -7
  109. package/src/repositories/standalone-price.ts +9 -6
  110. package/src/repositories/state.ts +9 -6
  111. package/src/repositories/store.ts +10 -7
  112. package/src/repositories/subscription.test.ts +3 -3
  113. package/src/repositories/subscription.ts +9 -6
  114. package/src/repositories/tax-category/actions.ts +4 -4
  115. package/src/repositories/tax-category/index.ts +6 -6
  116. package/src/repositories/type/actions.ts +4 -4
  117. package/src/repositories/type/index.ts +5 -5
  118. package/src/repositories/zone.test.ts +3 -3
  119. package/src/repositories/zone.ts +8 -5
  120. package/src/server.ts +4 -3
  121. package/src/services/abstract.ts +5 -5
  122. package/src/services/as-associate-cart.test.ts +1 -1
  123. package/src/services/as-associate-cart.ts +2 -2
  124. package/src/services/as-associate-order.test.ts +1 -1
  125. package/src/services/as-associate-order.ts +2 -2
  126. package/src/services/as-associate-quote-request.ts +2 -3
  127. package/src/services/as-associate.test.ts +1 -1
  128. package/src/services/as-associate.ts +4 -4
  129. package/src/services/associate-roles.test.ts +1 -1
  130. package/src/services/associate-roles.ts +2 -2
  131. package/src/services/attribute-group.test.ts +1 -1
  132. package/src/services/attribute-group.ts +2 -2
  133. package/src/services/business-units.test.ts +5 -5
  134. package/src/services/business-units.ts +2 -2
  135. package/src/services/cart-discount.ts +2 -2
  136. package/src/services/cart.test.ts +213 -2
  137. package/src/services/cart.ts +4 -5
  138. package/src/services/category.test.ts +1 -1
  139. package/src/services/category.ts +2 -2
  140. package/src/services/channel.test.ts +1 -1
  141. package/src/services/channel.ts +2 -2
  142. package/src/services/custom-object.test.ts +2 -2
  143. package/src/services/custom-object.ts +3 -3
  144. package/src/services/customer-group.test.ts +1 -1
  145. package/src/services/customer-group.ts +2 -2
  146. package/src/services/customer.test.ts +3 -3
  147. package/src/services/customer.ts +4 -5
  148. package/src/services/discount-code.test.ts +1 -1
  149. package/src/services/discount-code.ts +2 -2
  150. package/src/services/discount-group.test.ts +1 -1
  151. package/src/services/discount-group.ts +2 -2
  152. package/src/services/extension.test.ts +1 -1
  153. package/src/services/extension.ts +2 -2
  154. package/src/services/index.ts +44 -44
  155. package/src/services/inventory-entry.test.ts +16 -1
  156. package/src/services/inventory-entry.ts +2 -2
  157. package/src/services/my-business-unit.test.ts +1 -1
  158. package/src/services/my-business-unit.ts +2 -2
  159. package/src/services/my-cart.test.ts +1 -1
  160. package/src/services/my-cart.ts +2 -2
  161. package/src/services/my-customer.test.ts +2 -2
  162. package/src/services/my-customer.ts +6 -6
  163. package/src/services/my-order.ts +2 -2
  164. package/src/services/my-payment.test.ts +1 -1
  165. package/src/services/my-payment.ts +2 -2
  166. package/src/services/my-shopping-list.ts +2 -2
  167. package/src/services/order.test.ts +4 -11
  168. package/src/services/order.ts +4 -4
  169. package/src/services/payment.test.ts +1 -1
  170. package/src/services/payment.ts +2 -2
  171. package/src/services/product-discount.test.ts +1 -1
  172. package/src/services/product-discount.ts +2 -2
  173. package/src/services/product-projection.test.ts +2 -2
  174. package/src/services/product-projection.ts +4 -4
  175. package/src/services/product-selection.test.ts +1 -1
  176. package/src/services/product-selection.ts +2 -2
  177. package/src/services/product-type.test.ts +1 -1
  178. package/src/services/product-type.ts +2 -2
  179. package/src/services/product.test.ts +1 -1
  180. package/src/services/product.ts +3 -3
  181. package/src/services/project.test.ts +1 -1
  182. package/src/services/project.ts +4 -4
  183. package/src/services/quote-request.test.ts +2 -2
  184. package/src/services/quote-request.ts +2 -2
  185. package/src/services/quote-staged.ts +2 -2
  186. package/src/services/quote.ts +2 -2
  187. package/src/services/recurrence-policy.test.ts +1 -1
  188. package/src/services/recurrence-policy.ts +2 -2
  189. package/src/services/recurring-order.test.ts +1 -1
  190. package/src/services/recurring-order.ts +2 -2
  191. package/src/services/reviews.test.ts +1 -1
  192. package/src/services/reviews.ts +2 -2
  193. package/src/services/shipping-method.test.ts +2 -2
  194. package/src/services/shipping-method.ts +4 -4
  195. package/src/services/shopping-list.test.ts +1 -1
  196. package/src/services/shopping-list.ts +2 -2
  197. package/src/services/standalone-price.test.ts +1 -1
  198. package/src/services/standalone-price.ts +2 -2
  199. package/src/services/state.test.ts +1 -1
  200. package/src/services/state.ts +2 -2
  201. package/src/services/store.test.ts +1 -1
  202. package/src/services/store.ts +2 -2
  203. package/src/services/subscription.test.ts +1 -1
  204. package/src/services/subscription.ts +2 -2
  205. package/src/services/tax-category.test.ts +1 -1
  206. package/src/services/tax-category.ts +2 -2
  207. package/src/services/type.test.ts +1 -1
  208. package/src/services/type.ts +2 -2
  209. package/src/services/zone.test.ts +1 -1
  210. package/src/services/zone.ts +2 -2
  211. package/src/shipping.test.ts +1 -1
  212. package/src/shipping.ts +8 -8
  213. package/src/storage/abstract.ts +1 -1
  214. package/src/storage/in-memory.ts +15 -17
  215. package/src/storage/index.ts +2 -2
  216. package/src/testing/business-unit.ts +1 -2
  217. package/src/testing/customer.ts +1 -1
  218. package/src/testing/type.ts +1 -1
  219. package/src/types.ts +1 -1
  220. package/src/validate.ts +1 -1
  221. package/dist/index.d.ts.map +0 -1
  222. package/dist/index.js.map +0 -1
@@ -6,10 +6,10 @@ import type {
6
6
  OrderImportDraft,
7
7
  } from "@commercetools/platform-sdk";
8
8
  import { describe, expect, test } from "vitest";
9
- import type { Config } from "~src/config";
10
- import { getBaseResourceProperties } from "~src/helpers";
11
- import { InMemoryStorage } from "~src/storage";
12
- import { OrderRepository } from "./index";
9
+ import type { Config } from "#src/config.ts";
10
+ import { getBaseResourceProperties } from "#src/helpers.ts";
11
+ import { InMemoryStorage } from "#src/storage/index.ts";
12
+ import { OrderRepository } from "./index.ts";
13
13
 
14
14
  describe("Order repository", () => {
15
15
  const storage = new InMemoryStorage();
@@ -192,6 +192,106 @@ describe("Order repository", () => {
192
192
  expect(result.shippingInfo).toEqual(cart.shippingInfo);
193
193
  });
194
194
 
195
+ test("should calculate taxed price when creating order from cart", () => {
196
+ const cart: Cart = {
197
+ ...getBaseResourceProperties(),
198
+ id: "cart-with-taxed-items",
199
+ version: 1,
200
+ cartState: "Active",
201
+ lineItems: [
202
+ {
203
+ id: "li-1",
204
+ productId: "product-1",
205
+ variantId: 1,
206
+ quantity: 1,
207
+ name: { en: "Test" },
208
+ variant: {
209
+ id: 1,
210
+ sku: "TEST",
211
+ },
212
+ price: {
213
+ value: {
214
+ type: "centPrecision",
215
+ currencyCode: "EUR",
216
+ centAmount: 1000,
217
+ fractionDigits: 2,
218
+ },
219
+ },
220
+ totalPrice: {
221
+ type: "centPrecision",
222
+ currencyCode: "EUR",
223
+ centAmount: 1000,
224
+ fractionDigits: 2,
225
+ },
226
+ taxedPrice: {
227
+ totalNet: {
228
+ type: "centPrecision",
229
+ currencyCode: "EUR",
230
+ centAmount: 1000,
231
+ fractionDigits: 2,
232
+ },
233
+ totalGross: {
234
+ type: "centPrecision",
235
+ currencyCode: "EUR",
236
+ centAmount: 1210,
237
+ fractionDigits: 2,
238
+ },
239
+ taxPortions: [
240
+ {
241
+ rate: 0.21,
242
+ amount: {
243
+ type: "centPrecision",
244
+ currencyCode: "EUR",
245
+ centAmount: 210,
246
+ fractionDigits: 2,
247
+ },
248
+ },
249
+ ],
250
+ totalTax: {
251
+ type: "centPrecision",
252
+ currencyCode: "EUR",
253
+ centAmount: 210,
254
+ fractionDigits: 2,
255
+ },
256
+ },
257
+ } as unknown as LineItem,
258
+ ],
259
+ customLineItems: [],
260
+ totalPrice: {
261
+ type: "centPrecision",
262
+ currencyCode: "EUR",
263
+ centAmount: 1000,
264
+ fractionDigits: 2,
265
+ },
266
+ priceRoundingMode: "HalfEven",
267
+ refusedGifts: [],
268
+ shippingMode: "Single",
269
+ shipping: [],
270
+ shippingAddress: { country: "NL" },
271
+ taxMode: "Platform",
272
+ taxRoundingMode: "HalfEven",
273
+ taxCalculationMode: "LineItemLevel",
274
+ origin: "Customer",
275
+ itemShippingAddresses: [],
276
+ directDiscounts: [],
277
+ discountCodes: [],
278
+ discountOnTotalPrice: undefined,
279
+ inventoryMode: "None",
280
+ };
281
+
282
+ storage.add("dummy", "cart", cart);
283
+ const ctx = { projectKey: "dummy" };
284
+ const result = repository.create(ctx, {
285
+ cart: { id: cart.id, typeId: "cart" },
286
+ version: cart.version,
287
+ });
288
+
289
+ expect(result.taxedPrice).toBeDefined();
290
+ expect(result.taxedPrice?.totalNet.centAmount).toBe(1000);
291
+ expect(result.taxedPrice?.totalGross.centAmount).toBe(1210);
292
+ expect(result.taxedPrice?.totalTax?.centAmount).toBe(210);
293
+ });
294
+
195
295
  test("create order in store", async () => {
196
296
  storage.add("dummy", "store", {
197
297
  ...getBaseResourceProperties(),
@@ -274,12 +374,94 @@ describe("Order repository", () => {
274
374
  expect(result.paymentState).toBe("Paid");
275
375
  });
276
376
 
377
+ test("should calculate taxed price when importing order", () => {
378
+ storage.add("dummy", "product", {
379
+ ...getBaseResourceProperties(),
380
+ id: "product-import",
381
+ productType: {
382
+ typeId: "product-type",
383
+ id: "product-type-id",
384
+ },
385
+ masterData: {
386
+ current: {
387
+ name: { en: "Imported" },
388
+ slug: { en: "imported" },
389
+ categories: [],
390
+ masterVariant: {
391
+ id: 1,
392
+ sku: "IMPORT-SKU",
393
+ prices: [],
394
+ attributes: [],
395
+ },
396
+ variants: [],
397
+ searchKeywords: {},
398
+ attributes: [],
399
+ },
400
+ staged: {
401
+ name: { en: "Imported" },
402
+ slug: { en: "imported" },
403
+ categories: [],
404
+ masterVariant: {
405
+ id: 1,
406
+ sku: "IMPORT-SKU",
407
+ prices: [],
408
+ attributes: [],
409
+ },
410
+ variants: [],
411
+ searchKeywords: {},
412
+ attributes: [],
413
+ },
414
+ published: false,
415
+ hasStagedChanges: false,
416
+ },
417
+ });
418
+
419
+ const draft: OrderImportDraft = {
420
+ orderNumber: "IMPORT-ORDER-1",
421
+ totalPrice: {
422
+ centAmount: 1000,
423
+ currencyCode: "EUR",
424
+ },
425
+ lineItems: [
426
+ {
427
+ name: { en: "Imported" },
428
+ variant: {
429
+ sku: "IMPORT-SKU",
430
+ },
431
+ price: {
432
+ value: {
433
+ type: "centPrecision",
434
+ currencyCode: "EUR",
435
+ centAmount: 1000,
436
+ fractionDigits: 2,
437
+ },
438
+ },
439
+ quantity: 1,
440
+ taxRate: {
441
+ name: "Standard VAT",
442
+ amount: 0.21,
443
+ includedInPrice: false,
444
+ country: "NL",
445
+ id: "import-tax-rate",
446
+ subRates: [],
447
+ },
448
+ },
449
+ ],
450
+ customLineItems: [],
451
+ };
452
+
453
+ const result = repository.import({ projectKey: "dummy" }, draft);
454
+ expect(result.taxedPrice).toBeDefined();
455
+ expect(result.taxedPrice?.totalNet.centAmount).toBe(1000);
456
+ expect(result.taxedPrice?.totalGross.centAmount).toBe(1210);
457
+ expect(result.taxedPrice?.totalTax?.centAmount).toBe(210);
458
+ });
459
+
277
460
  test("import exiting product", async () => {
278
461
  storage.add("dummy", "product", {
279
462
  id: "15fc56ba-a74e-4cf8-b4b0-bada5c101541",
280
- // @ts-ignore
281
463
  masterData: {
282
- // @ts-ignore
464
+ // @ts-expect-error
283
465
  current: {
284
466
  name: { "nl-NL": "Dummy" },
285
467
  slug: { "nl-NL": "Dummy" },
@@ -402,7 +584,7 @@ describe("Order repository", () => {
402
584
  productType: {
403
585
  typeId: 'product-type',
404
586
  id: '109caecb-abe6-4900-ab03-7af5af985ff3',
405
- // @ts-ignore
587
+ // @ts-expect-error
406
588
  version: 1,
407
589
  },
408
590
  variant: {
@@ -412,7 +594,7 @@ describe("Order repository", () => {
412
594
  prices: [
413
595
  {
414
596
  value: {
415
- // @ts-ignore
597
+ // @ts-expect-error
416
598
  type: 'centPrecision',
417
599
  currencyCode: 'EUR',
418
600
  centAmount: 14900,
@@ -439,7 +621,7 @@ describe("Order repository", () => {
439
621
  },
440
622
  price: {
441
623
  value: {
442
- // @ts-ignore
624
+ // @ts-expect-error
443
625
  type: 'centPrecision',
444
626
  currencyCode: 'EUR',
445
627
  centAmount: 14900,
@@ -2,14 +2,11 @@ import assert from "node:assert";
2
2
  import type {
3
3
  Cart,
4
4
  CartReference,
5
- CentPrecisionMoney,
6
5
  CustomLineItem,
7
6
  CustomLineItemImportDraft,
8
7
  GeneralError,
9
- InvalidOperationError,
10
8
  LineItem,
11
9
  LineItemImportDraft,
12
- MissingTaxRateForCountryError,
13
10
  Order,
14
11
  OrderFromCartDraft,
15
12
  OrderImportDraft,
@@ -19,20 +16,24 @@ import type {
19
16
  ShippingInfo,
20
17
  ShippingMethodDoesNotMatchCartError,
21
18
  ShippingMethodReference,
22
- TaxPortion,
23
- TaxedItemPrice,
24
19
  } from "@commercetools/platform-sdk";
25
- import { Decimal } from "decimal.js/decimal";
26
- import type { Config } from "~src/config";
27
- import { CommercetoolsError } from "~src/exceptions";
28
- import { generateRandomString, getBaseResourceProperties } from "~src/helpers";
20
+ import type { Config } from "#src/config.ts";
21
+ import { CommercetoolsError } from "#src/exceptions.ts";
22
+ import {
23
+ generateRandomString,
24
+ getBaseResourceProperties,
25
+ } from "#src/helpers.ts";
26
+ import {
27
+ calculateTaxedPriceFromRate,
28
+ calculateTaxTotals,
29
+ } from "#src/lib/tax.ts";
29
30
  import {
30
31
  createShippingInfoFromMethod,
31
32
  getShippingMethodsMatchingCart,
32
- } from "~src/shipping";
33
- import type { Writable } from "~src/types";
34
- import type { RepositoryContext } from "../abstract";
35
- import { AbstractResourceRepository, type QueryParams } from "../abstract";
33
+ } from "#src/shipping.ts";
34
+ import type { Writable } from "#src/types.ts";
35
+ import type { RepositoryContext } from "../abstract.ts";
36
+ import { AbstractResourceRepository, type QueryParams } from "../abstract.ts";
36
37
  import {
37
38
  createAddress,
38
39
  createCentPrecisionMoney,
@@ -40,9 +41,8 @@ import {
40
41
  createPrice,
41
42
  createTypedMoney,
42
43
  resolveStoreReference,
43
- roundDecimal,
44
- } from "../helpers";
45
- import { OrderUpdateHandler } from "./actions";
44
+ } from "../helpers.ts";
45
+ import { OrderUpdateHandler } from "./actions.ts";
46
46
 
47
47
  export class OrderRepository extends AbstractResourceRepository<"order"> {
48
48
  constructor(config: Config) {
@@ -75,7 +75,7 @@ export class OrderRepository extends AbstractResourceRepository<"order"> {
75
75
  throw new Error("Cannot find cart");
76
76
  }
77
77
 
78
- const resource: Order = {
78
+ const resource: Writable<Order> = {
79
79
  ...getBaseResourceProperties(),
80
80
  anonymousId: cart.anonymousId,
81
81
  billingAddress: cart.billingAddress,
@@ -110,6 +110,16 @@ export class OrderRepository extends AbstractResourceRepository<"order"> {
110
110
  totalPrice: cart.totalPrice,
111
111
  store: cart.store,
112
112
  };
113
+
114
+ const { taxedPrice, taxedShippingPrice } = calculateTaxTotals({
115
+ lineItems: cart.lineItems,
116
+ customLineItems: cart.customLineItems,
117
+ shippingInfo: cart.shippingInfo,
118
+ totalPrice: cart.totalPrice,
119
+ });
120
+ resource.taxedPrice = resource.taxedPrice ?? taxedPrice;
121
+ resource.taxedShippingPrice =
122
+ resource.taxedShippingPrice ?? taxedShippingPrice;
113
123
  return this.saveNew(context, resource);
114
124
  }
115
125
 
@@ -194,6 +204,16 @@ export class OrderRepository extends AbstractResourceRepository<"order"> {
194
204
  });
195
205
  }
196
206
 
207
+ const { taxedPrice, taxedShippingPrice } = calculateTaxTotals({
208
+ lineItems: resource.lineItems,
209
+ customLineItems: resource.customLineItems,
210
+ shippingInfo: resource.shippingInfo,
211
+ totalPrice: resource.totalPrice,
212
+ });
213
+ resource.taxedPrice = resource.taxedPrice ?? taxedPrice;
214
+ resource.taxedShippingPrice =
215
+ resource.taxedShippingPrice ?? taxedShippingPrice;
216
+
197
217
  return this.saveNew(context, resource);
198
218
  }
199
219
 
@@ -238,6 +258,12 @@ export class OrderRepository extends AbstractResourceRepository<"order"> {
238
258
  throw new Error("No product found");
239
259
  }
240
260
 
261
+ const quantity = draft.quantity ?? 1;
262
+ const totalPrice = createCentPrecisionMoney({
263
+ ...draft.price.value,
264
+ centAmount: (draft.price.value.centAmount ?? 0) * quantity,
265
+ });
266
+
241
267
  const lineItem: LineItem = {
242
268
  ...getBaseResourceProperties(),
243
269
  custom: createCustomFields(
@@ -252,12 +278,17 @@ export class OrderRepository extends AbstractResourceRepository<"order"> {
252
278
  priceMode: "Platform",
253
279
  productId: product.id,
254
280
  productType: product.productType,
255
- quantity: draft.quantity,
281
+ quantity,
256
282
  state: draft.state || [],
257
283
  taxRate: draft.taxRate,
284
+ taxedPrice: calculateTaxedPriceFromRate(
285
+ totalPrice.centAmount,
286
+ totalPrice.currencyCode,
287
+ draft.taxRate,
288
+ ),
258
289
  taxedPricePortions: [],
259
290
  perMethodTaxRate: [],
260
- totalPrice: createCentPrecisionMoney(draft.price.value),
291
+ totalPrice,
261
292
  variant: {
262
293
  id: variant.id,
263
294
  sku: variant.sku,
@@ -273,6 +304,12 @@ export class OrderRepository extends AbstractResourceRepository<"order"> {
273
304
  context: RepositoryContext,
274
305
  draft: CustomLineItemImportDraft,
275
306
  ): CustomLineItem {
307
+ const quantity = draft.quantity ?? 1;
308
+ const totalPrice = createCentPrecisionMoney({
309
+ ...draft.money,
310
+ centAmount: (draft.money.centAmount ?? 0) * quantity,
311
+ });
312
+
276
313
  const lineItem: CustomLineItem = {
277
314
  ...getBaseResourceProperties(),
278
315
  custom: createCustomFields(
@@ -283,12 +320,17 @@ export class OrderRepository extends AbstractResourceRepository<"order"> {
283
320
  discountedPricePerQuantity: [],
284
321
  money: createTypedMoney(draft.money),
285
322
  name: draft.name,
286
- quantity: draft.quantity ?? 0,
323
+ quantity,
287
324
  perMethodTaxRate: [],
288
325
  priceMode: draft.priceMode ?? "Standard",
289
326
  slug: draft.slug,
290
327
  state: [],
291
- totalPrice: createCentPrecisionMoney(draft.money),
328
+ totalPrice,
329
+ taxedPrice: calculateTaxedPriceFromRate(
330
+ totalPrice.centAmount,
331
+ totalPrice.currencyCode,
332
+ draft.taxRate,
333
+ ),
292
334
  taxedPricePortions: [],
293
335
  };
294
336
 
@@ -3,10 +3,10 @@ import type {
3
3
  OrderEditDraft,
4
4
  OrderEditResult,
5
5
  } from "@commercetools/platform-sdk";
6
- import type { Config } from "~src/config";
7
- import { getBaseResourceProperties } from "../helpers";
8
- import type { RepositoryContext } from "./abstract";
9
- import { AbstractResourceRepository } from "./abstract";
6
+ import type { Config } from "#src/config.ts";
7
+ import { getBaseResourceProperties } from "../helpers.ts";
8
+ import type { RepositoryContext } from "./abstract.ts";
9
+ import { AbstractResourceRepository } from "./abstract.ts";
10
10
 
11
11
  export class OrderEditRepository extends AbstractResourceRepository<"order-edit"> {
12
12
  constructor(config: Config) {
@@ -8,9 +8,9 @@ import type {
8
8
  PaymentChangeTransactionStateAction,
9
9
  PaymentChangeTransactionTimestampAction,
10
10
  PaymentSetAnonymousIdAction,
11
+ PaymentSetCustomerAction,
11
12
  PaymentSetCustomFieldAction,
12
13
  PaymentSetCustomTypeAction,
13
- PaymentSetCustomerAction,
14
14
  PaymentSetInterfaceIdAction,
15
15
  PaymentSetKeyAction,
16
16
  PaymentSetMethodInfoAction,
@@ -30,15 +30,15 @@ import type {
30
30
  State,
31
31
  Transaction,
32
32
  } from "@commercetools/platform-sdk";
33
- import type { Writable } from "~src/types";
34
- import type { RepositoryContext, UpdateHandlerInterface } from "../abstract";
35
- import { AbstractUpdateHandler } from "../abstract";
33
+ import type { Writable } from "#src/types.ts";
34
+ import type { RepositoryContext, UpdateHandlerInterface } from "../abstract.ts";
35
+ import { AbstractUpdateHandler } from "../abstract.ts";
36
36
  import {
37
37
  createCentPrecisionMoney,
38
38
  createCustomFields,
39
39
  getReferenceFromResourceIdentifier,
40
- } from "../helpers";
41
- import { transactionFromTransactionDraft } from "./helpers";
40
+ } from "../helpers.ts";
41
+ import { transactionFromTransactionDraft } from "./helpers.ts";
42
42
 
43
43
  export class PaymentUpdateHandler
44
44
  extends AbstractUpdateHandler
@@ -3,9 +3,9 @@ import type {
3
3
  TransactionDraft,
4
4
  } from "@commercetools/platform-sdk";
5
5
  import { v4 as uuidv4 } from "uuid";
6
- import type { AbstractStorage } from "~src/storage";
7
- import type { RepositoryContext } from "../abstract";
8
- import { createCentPrecisionMoney, createCustomFields } from "../helpers";
6
+ import type { AbstractStorage } from "#src/storage/index.ts";
7
+ import type { RepositoryContext } from "../abstract.ts";
8
+ import { createCentPrecisionMoney, createCustomFields } from "../helpers.ts";
9
9
 
10
10
  export const transactionFromTransactionDraft = (
11
11
  context: RepositoryContext,
@@ -3,17 +3,17 @@ import type {
3
3
  PaymentDraft,
4
4
  StateReference,
5
5
  } from "@commercetools/platform-sdk";
6
- import type { Config } from "~src/config";
7
- import { getBaseResourceProperties } from "~src/helpers";
8
- import type { RepositoryContext } from "../abstract";
9
- import { AbstractResourceRepository } from "../abstract";
6
+ import type { Config } from "#src/config.ts";
7
+ import { getBaseResourceProperties } from "#src/helpers.ts";
8
+ import type { RepositoryContext } from "../abstract.ts";
9
+ import { AbstractResourceRepository } from "../abstract.ts";
10
10
  import {
11
11
  createCentPrecisionMoney,
12
12
  createCustomFields,
13
13
  getReferenceFromResourceIdentifier,
14
- } from "../helpers";
15
- import { PaymentUpdateHandler } from "./actions";
16
- import { transactionFromTransactionDraft } from "./helpers";
14
+ } from "../helpers.ts";
15
+ import { PaymentUpdateHandler } from "./actions.ts";
16
+ import { transactionFromTransactionDraft } from "./helpers.ts";
17
17
 
18
18
  export class PaymentRepository extends AbstractResourceRepository<"payment"> {
19
19
  constructor(config: Config) {
@@ -35,19 +35,19 @@ import type {
35
35
  StateReference,
36
36
  TaxCategoryReference,
37
37
  } from "@commercetools/platform-sdk";
38
- import { CommercetoolsError } from "~src/exceptions";
39
- import type { Writable } from "~src/types";
40
- import { AbstractUpdateHandler, type RepositoryContext } from "../abstract";
38
+ import { CommercetoolsError } from "#src/exceptions.ts";
39
+ import type { Writable } from "#src/types.ts";
40
+ import { AbstractUpdateHandler, type RepositoryContext } from "../abstract.ts";
41
41
  import {
42
42
  createCustomFields,
43
43
  getReferenceFromResourceIdentifier,
44
- } from "../helpers";
44
+ } from "../helpers.ts";
45
45
  import {
46
46
  checkForStagedChanges,
47
47
  getVariant,
48
48
  priceFromDraft,
49
49
  variantFromDraft,
50
- } from "./helpers";
50
+ } from "./helpers.ts";
51
51
 
52
52
  type ProductUpdateHandlerMethod<T> = (
53
53
  context: RepositoryContext,
@@ -944,7 +944,7 @@ export class ProductUpdateHandler
944
944
  resource: Writable<Product>,
945
945
  { taxCategory }: ProductSetTaxCategoryAction,
946
946
  ) {
947
- let taxCategoryReference: TaxCategoryReference | undefined = undefined;
947
+ let taxCategoryReference: TaxCategoryReference | undefined;
948
948
  if (taxCategory) {
949
949
  taxCategoryReference =
950
950
  getReferenceFromResourceIdentifier<TaxCategoryReference>(
@@ -972,7 +972,7 @@ export class ProductUpdateHandler
972
972
  resource: Writable<Product>,
973
973
  { state, force }: ProductTransitionStateAction,
974
974
  ) {
975
- let productStateReference: StateReference | undefined = undefined;
975
+ let productStateReference: StateReference | undefined;
976
976
  if (state) {
977
977
  productStateReference =
978
978
  getReferenceFromResourceIdentifier<StateReference>(
@@ -11,14 +11,14 @@ import type {
11
11
  ProductVariantDraft,
12
12
  } from "@commercetools/platform-sdk";
13
13
  import { v4 as uuidv4 } from "uuid";
14
- import type { AbstractStorage } from "~src/storage";
15
- import type { Writable } from "~src/types";
16
- import type { RepositoryContext } from "../abstract";
14
+ import type { AbstractStorage } from "#src/storage/index.ts";
15
+ import type { Writable } from "#src/types.ts";
16
+ import type { RepositoryContext } from "../abstract.ts";
17
17
  import {
18
18
  createCustomFields,
19
19
  createTypedMoney,
20
20
  getReferenceFromResourceIdentifier,
21
- } from "../helpers";
21
+ } from "../helpers.ts";
22
22
 
23
23
  interface VariantResult {
24
24
  variant: Writable<ProductVariant> | undefined;
@@ -10,16 +10,16 @@ import type {
10
10
  StateReference,
11
11
  TaxCategoryReference,
12
12
  } from "@commercetools/platform-sdk";
13
- import type { Config } from "~src/config";
14
- import { CommercetoolsError } from "~src/exceptions";
15
- import { getBaseResourceProperties } from "~src/helpers";
16
- import { ReviewStatisticsService } from "~src/lib/review-statistics";
17
- import { ProductSearch } from "~src/product-search";
18
- import type { GetParams, RepositoryContext } from "../abstract";
19
- import { AbstractResourceRepository } from "../abstract";
20
- import { getReferenceFromResourceIdentifier } from "../helpers";
21
- import { ProductUpdateHandler } from "./actions";
22
- import { variantFromDraft } from "./helpers";
13
+ import type { Config } from "#src/config.ts";
14
+ import { CommercetoolsError } from "#src/exceptions.ts";
15
+ import { getBaseResourceProperties } from "#src/helpers.ts";
16
+ import { ReviewStatisticsService } from "#src/lib/review-statistics.ts";
17
+ import { ProductSearch } from "#src/product-search.ts";
18
+ import type { GetParams, RepositoryContext } from "../abstract.ts";
19
+ import { AbstractResourceRepository } from "../abstract.ts";
20
+ import { getReferenceFromResourceIdentifier } from "../helpers.ts";
21
+ import { ProductUpdateHandler } from "./actions.ts";
22
+ import { variantFromDraft } from "./helpers.ts";
23
23
 
24
24
  export class ProductRepository extends AbstractResourceRepository<"product"> {
25
25
  protected _searchService: ProductSearch;
@@ -37,7 +37,7 @@ export class ProductRepository extends AbstractResourceRepository<"product"> {
37
37
  throw new Error("Missing master variant");
38
38
  }
39
39
 
40
- let productType: ProductTypeReference | undefined = undefined;
40
+ let productType: ProductTypeReference | undefined;
41
41
  try {
42
42
  productType = getReferenceFromResourceIdentifier<ProductTypeReference>(
43
43
  draft.productType,
@@ -83,7 +83,7 @@ export class ProductRepository extends AbstractResourceRepository<"product"> {
83
83
  });
84
84
 
85
85
  // Resolve Tax category
86
- let taxCategoryReference: TaxCategoryReference | undefined = undefined;
86
+ let taxCategoryReference: TaxCategoryReference | undefined;
87
87
  if (draft.taxCategory) {
88
88
  taxCategoryReference =
89
89
  getReferenceFromResourceIdentifier<TaxCategoryReference>(
@@ -94,7 +94,7 @@ export class ProductRepository extends AbstractResourceRepository<"product"> {
94
94
  }
95
95
 
96
96
  // Resolve Product State
97
- let productStateReference: StateReference | undefined = undefined;
97
+ let productStateReference: StateReference | undefined;
98
98
  if (draft.state) {
99
99
  productStateReference =
100
100
  getReferenceFromResourceIdentifier<StateReference>(
@@ -18,12 +18,15 @@ import type {
18
18
  ProductDiscountValueExternal,
19
19
  ProductDiscountValueRelative,
20
20
  } from "@commercetools/platform-sdk";
21
- import type { Config } from "~src/config";
22
- import { getBaseResourceProperties } from "../helpers";
23
- import type { Writable } from "../types";
24
- import type { RepositoryContext, UpdateHandlerInterface } from "./abstract";
25
- import { AbstractResourceRepository, AbstractUpdateHandler } from "./abstract";
26
- import { createTypedMoney } from "./helpers";
21
+ import type { Config } from "#src/config.ts";
22
+ import { getBaseResourceProperties } from "../helpers.ts";
23
+ import type { Writable } from "../types.ts";
24
+ import type { RepositoryContext, UpdateHandlerInterface } from "./abstract.ts";
25
+ import {
26
+ AbstractResourceRepository,
27
+ AbstractUpdateHandler,
28
+ } from "./abstract.ts";
29
+ import { createTypedMoney } from "./helpers.ts";
27
30
 
28
31
  export class ProductDiscountRepository extends AbstractResourceRepository<"product-discount"> {
29
32
  constructor(config: Config) {
@@ -4,13 +4,13 @@ import type {
4
4
  ProductProjection,
5
5
  QueryParam,
6
6
  } from "@commercetools/platform-sdk";
7
- import type { Config } from "~src/config";
8
- import { CommercetoolsError } from "~src/exceptions";
9
- import { parseQueryExpression } from "../lib/predicateParser";
10
- import { applyPriceSelector } from "../priceSelector";
11
- import { ProductProjectionSearch } from "../product-projection-search";
12
- import type { GetParams, RepositoryContext } from "./abstract";
13
- import { AbstractResourceRepository } from "./abstract";
7
+ import type { Config } from "#src/config.ts";
8
+ import { CommercetoolsError } from "#src/exceptions.ts";
9
+ import { parseQueryExpression } from "../lib/predicateParser.ts";
10
+ import { applyPriceSelector } from "../priceSelector.ts";
11
+ import { ProductProjectionSearch } from "../product-projection-search.ts";
12
+ import type { GetParams, RepositoryContext } from "./abstract.ts";
13
+ import { AbstractResourceRepository } from "./abstract.ts";
14
14
 
15
15
  export type ProductProjectionQueryParams = {
16
16
  staged?: boolean;