Skip to content

Commit 35da11e

Browse files
authored
fix: make customline item tax dependent on (shipping address) country (#331)
1 parent 9a70063 commit 35da11e

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

.changeset/rotten-ravens-knock.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@labdigital/commercetools-mock": patch
3+
---
4+
5+
fix: make tax rate for custom line item dependent on the cart.shippingAddress.country ?? cart.country

src/repositories/cart/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ export class CartUpdateHandler
346346
context.projectKey,
347347
{ money, name, slug, quantity, taxCategory, custom, priceMode, key },
348348
this._storage,
349-
resource.country,
349+
resource.shippingAddress?.country ?? resource.country,
350350
);
351351

352352
resource.customLineItems.push(customLineItem);

src/repositories/cart/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export const createCustomLineItemFromDraft = (
178178
const taxRate = taxCategory
179179
? taxCategory.rates.find(
180180
(rate) => !rate.country || rate.country === country,
181-
) || taxCategory.rates[0]
181+
)
182182
: undefined;
183183

184184
return {

src/repositories/cart/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class CartRepository extends AbstractResourceRepository<"cart"> {
8181
context.projectKey,
8282
draftCustomLineItem,
8383
this._storage,
84-
draft.country,
84+
draft.shippingAddress?.country ?? draft.country,
8585
),
8686
) ?? [];
8787

src/services/cart.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ describe("Cart Update Actions", () => {
116116
const createCart = async (currency: string) => {
117117
const response = await supertest(ctMock.app).post("/dummy/carts").send({
118118
currency,
119+
country: "NL",
119120
});
120121
expect(response.status).toBe(201);
121122
cart = response.body;
@@ -653,11 +654,11 @@ describe("Cart Update Actions", () => {
653654
.post(`/dummy/carts/${cart.id}`)
654655
.send({
655656
version: 1,
656-
actions: [{ action: "setCountry", country: "NL" }],
657+
actions: [{ action: "setCountry", country: "BE" }],
657658
});
658659
expect(response.status).toBe(200);
659660
expect(response.body.version).toBe(2);
660-
expect(response.body.country).toBe("NL");
661+
expect(response.body.country).toBe("BE");
661662
});
662663

663664
test("setDirectDiscounts", async () => {

0 commit comments

Comments
 (0)