Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: display checkout/order prices according to the ICM pricing settings #179

Merged
merged 6 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
"option": "watch",
"problemMatcher": ["$tsc-watch"]
},
{
"label": "run continuous app-compile",
"type": "typescript",
"tsconfig": "tsconfig.app.json",
"option": "watch",
"problemMatcher": ["$tsc-watch"]
},
{
"label": "run tslint",
"type": "npm",
Expand Down
3 changes: 2 additions & 1 deletion src/app/core/facades/checkout.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ import {
isBasketInvoiceAndShippingAddressEqual,
} from 'ish-core/store/checkout/basket';
import { getCheckoutStep } from 'ish-core/store/checkout/viewconf';
import { getServerConfigParameter } from 'ish-core/store/configuration';
import { CreateOrder, getOrdersError, getSelectedOrder } from 'ish-core/store/orders';
import { getLoggedInUser } from 'ish-core/store/user';
import { whenTruthy } from 'ish-core/utils/operators';

// tslint:disable:member-ordering
@Injectable({ providedIn: 'root' })
export class CheckoutFacade {
Expand Down Expand Up @@ -105,6 +105,7 @@ export class CheckoutFacade {
switchMap(() => this.store.pipe(select(getBasketEligiblePaymentMethods)))
);
}
priceType$ = this.store.pipe(select(getServerConfigParameter<'gross' | 'net'>('pricing.priceType')));

setBasketPayment(paymentName: string) {
this.store.dispatch(new SetBasketPayment({ id: paymentName }));
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/models/basket-rebate/basket-rebate.interface.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { PriceItem } from 'ish-core/models/price-item/price-item.interface';
import { PriceItemData } from 'ish-core/models/price-item/price-item.interface';

export interface BasketRebateData {
id: string;
promotionType: string;
amount: PriceItem;
amount: PriceItemData;
description?: string;
code?: string;
promotion?: string;
Expand Down
29 changes: 17 additions & 12 deletions src/app/core/models/basket-rebate/basket-rebate.mapper.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { BasketRebateData } from './basket-rebate.interface';
import { BasketRebateMapper } from './basket-rebate.mapper';

describe('Basket Rebate Mapper', () => {
describe('fromData', () => {
it(`should return BasketRebate when getting BasketRebateData`, () => {
const basketRebateData = {
const basketRebate = BasketRebateMapper.fromData({
id: 'basketDiscountId',
promotionType: 'Discount',
amount: {
Expand All @@ -20,17 +19,23 @@ describe('Basket Rebate Mapper', () => {
description: 'Dicount description',
code: 'CODE5433',
promotion: 'FreeShippingOnLEDTVs',
} as BasketRebateData;
});

const basketRebate = BasketRebateMapper.fromData(basketRebateData);

expect(basketRebate).toBeTruthy();
expect(basketRebate.id).toBe(basketRebateData.id);
expect(basketRebate.rebateType).toBe(basketRebateData.promotionType);
expect(basketRebate.description).toBe(basketRebateData.description);
expect(basketRebate.code).toBe(basketRebateData.code);
expect(basketRebate.amount.value).toBePositive();
expect(basketRebate.promotionId).toBe(basketRebateData.promotion);
expect(basketRebate).toMatchInlineSnapshot(`
Object {
"amount": Object {
"currency": "USD",
"gross": 43.34,
"net": 40.34,
"type": "PriceItem",
},
"code": "CODE5433",
"description": "Dicount description",
"id": "basketDiscountId",
"promotionId": "FreeShippingOnLEDTVs",
"rebateType": "Discount",
}
`);
});
});
});
4 changes: 2 additions & 2 deletions src/app/core/models/basket-rebate/basket-rebate.mapper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BasketRebateData } from 'ish-core/models/basket-rebate/basket-rebate.interface';
import { PriceMapper } from 'ish-core/models/price/price.mapper';
import { PriceItemMapper } from 'ish-core/models/price-item/price-item.mapper';

import { BasketRebate } from './basket-rebate.model';

Expand All @@ -8,7 +8,7 @@ export class BasketRebateMapper {
if (data) {
return {
id: data.id,
amount: PriceMapper.fromPriceItem(data.amount),
amount: PriceItemMapper.fromPriceItem(data.amount),
description: data.description,
rebateType: data.promotionType,
code: data.code,
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/models/basket-rebate/basket-rebate.model.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Price } from 'ish-core/models/price/price.model';
import { PriceItem } from 'ish-core/models/price-item/price-item.model';

export interface BasketRebate {
id: string;
amount: Price;
amount: PriceItem;
description?: string;
rebateType: string;
code?: string;
Expand Down
35 changes: 15 additions & 20 deletions src/app/core/models/basket-total/basket-total.interface.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
import { PriceItem } from 'ish-core/models/price-item/price-item.interface';
import { Price } from 'ish-core/models/price/price.model';
import { PriceItemData } from 'ish-core/models/price-item/price-item.interface';

export interface BasketTotalData {
itemTotal: PriceItem;
undiscountedItemTotal?: PriceItem;
shippingTotal?: PriceItem;
undiscountedShippingTotal: PriceItem;
paymentCostsTotal?: PriceItem;
surchargeTotal?: PriceItem;
grandTotal: PriceItem;
itemTotal: PriceItemData;
undiscountedItemTotal?: PriceItemData;
shippingTotal?: PriceItemData;
undiscountedShippingTotal: PriceItemData;
paymentCostsTotal?: PriceItemData;
surchargeTotal?: PriceItemData;
grandTotal: PriceItemData;

itemValueDiscountsTotal?: PriceItem;
basketValueDiscountsTotal?: PriceItem;
itemValueDiscountsTotal?: PriceItemData;
basketValueDiscountsTotal?: PriceItemData;

itemShippingDiscountsTotal?: PriceItem;
basketShippingDiscountsTotal?: PriceItem;
itemShippingDiscountsTotal?: PriceItemData;
basketShippingDiscountsTotal?: PriceItemData;

shippingDiscountsTotal?: PriceItem;
valueDiscountsTotal: PriceItem;
discountTotal?: PriceItem;

taxTotalsByTaxRate?: {
calculatedTax: Price;
}[];
shippingDiscountsTotal?: PriceItemData;
valueDiscountsTotal: PriceItemData;
discountTotal?: PriceItemData;
}
27 changes: 14 additions & 13 deletions src/app/core/models/basket-total/basket-total.model.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
import { BasketRebate } from 'ish-core/models/basket-rebate/basket-rebate.model';
import { PriceItem } from 'ish-core/models/price-item/price-item.model';
import { Price } from 'ish-core/models/price/price.model';

export interface BasketTotal {
itemTotal: Price;
undiscountedItemTotal?: Price;
shippingTotal?: Price;
undiscountedShippingTotal?: Price;
paymentCostsTotal?: Price;
dutiesAndSurchargesTotal?: Price;
itemTotal: PriceItem;
undiscountedItemTotal?: PriceItem;
shippingTotal?: PriceItem;
undiscountedShippingTotal?: PriceItem;
paymentCostsTotal?: PriceItem;
dutiesAndSurchargesTotal?: PriceItem;
taxTotal?: Price;
total: Price;
total: PriceItem;

itemRebatesTotal?: Price;
valueRebatesTotal?: Price;
itemRebatesTotal?: PriceItem;
valueRebatesTotal?: PriceItem;
valueRebates?: BasketRebate[];

itemShippingRebatesTotal?: Price;
shippingRebatesTotal?: Price;
itemShippingRebatesTotal?: PriceItem;
shippingRebatesTotal?: PriceItem;
shippingRebates?: BasketRebate[];

itemSurchargeTotalsByType?: {
amount: Price;
amount: PriceItem;
description: string;
displayName: string;
}[];

bucketSurchargeTotalsByType?: {
amount: Price;
amount: PriceItem;
description: string;
displayName: string;
}[];
Expand Down
6 changes: 3 additions & 3 deletions src/app/core/models/basket/basket.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { LineItemData } from 'ish-core/models/line-item/line-item.interface';
import { PaymentInstrument } from 'ish-core/models/payment-instrument/payment-instrument.model';
import { PaymentMethodBaseData } from 'ish-core/models/payment-method/payment-method.interface';
import { PaymentData } from 'ish-core/models/payment/payment.interface';
import { PriceItem } from 'ish-core/models/price-item/price-item.interface';
import { PriceItemData } from 'ish-core/models/price-item/price-item.interface';
import { ShippingMethodData } from 'ish-core/models/shipping-method/shipping-method.interface';

export interface BasketBaseData {
Expand All @@ -29,12 +29,12 @@ export interface BasketBaseData {
totalProductQuantity?: number;
surcharges?: {
itemSurcharges?: {
amount: PriceItem;
amount: PriceItemData;
description: string;
name: string;
}[];
bucketSurcharges?: {
amount: PriceItem;
amount: PriceItemData;
description: string;
name: string;
}[];
Expand Down
16 changes: 8 additions & 8 deletions src/app/core/models/basket/basket.mapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ describe('Basket Mapper', () => {
basket = BasketMapper.fromData(basketData);
expect(basket).toBeTruthy();

expect(basket.totals.itemTotal.value).toBe(basketData.data.totals.itemTotal.gross.value);
expect(basket.totals.itemSurchargeTotalsByType[0].amount.value).toBe(
expect(basket.totals.itemTotal.gross).toBe(basketData.data.totals.itemTotal.gross.value);
expect(basket.totals.itemSurchargeTotalsByType[0].amount.gross).toBe(
basketData.data.surcharges.itemSurcharges[0].amount.gross.value
);
expect(basket.totals.bucketSurchargeTotalsByType[0].amount.value).toBe(
expect(basket.totals.bucketSurchargeTotalsByType[0].amount.gross).toBe(
basketData.data.surcharges.bucketSurcharges[0].amount.gross.value
);
expect(basket.totals.isEstimated).toBeTrue();
Expand Down Expand Up @@ -226,7 +226,7 @@ describe('Basket Mapper', () => {
it('should return discounts if included', () => {
basket = BasketMapper.fromData(basketData);

expect(basket.totals.valueRebates[0].amount.value).toBePositive();
expect(basket.totals.valueRebates[0].amount.gross).toBePositive();
});

it('should return estimated as false if invoive address, shipping address and shipping method is set', () => {
Expand All @@ -249,9 +249,9 @@ describe('Basket Mapper', () => {
totals = BasketMapper.getTotals(basketBaseData);
expect(totals).toBeTruthy();

expect(totals.total.value).toBe(basketData.data.totals.grandTotal.gross.value);
expect(totals.itemTotal.value).toBe(basketData.data.totals.itemTotal.gross.value);
expect(totals.itemSurchargeTotalsByType[0].amount.value).toBe(
expect(totals.total.gross).toBe(basketData.data.totals.grandTotal.gross.value);
expect(totals.itemTotal.gross).toBe(basketData.data.totals.itemTotal.gross.value);
expect(totals.itemSurchargeTotalsByType[0].amount.gross).toBe(
basketData.data.surcharges.itemSurcharges[0].amount.gross.value
);
expect(totals.isEstimated).toBeFalse();
Expand All @@ -261,7 +261,7 @@ describe('Basket Mapper', () => {
totals = BasketMapper.getTotals(basketBaseData, basketIncludedData.discounts);
expect(totals).toBeTruthy();

expect(totals.valueRebates[0].amount.value).toBePositive();
expect(totals.valueRebates[0].amount.gross).toBePositive();
expect(totals.valueRebates[0].id).toEqual('discount_1');
});
});
Expand Down
30 changes: 15 additions & 15 deletions src/app/core/models/basket/basket.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BasketTotal } from 'ish-core/models/basket-total/basket-total.model';
import { BasketBaseData, BasketData } from 'ish-core/models/basket/basket.interface';
import { LineItemMapper } from 'ish-core/models/line-item/line-item.mapper';
import { PaymentMapper } from 'ish-core/models/payment/payment.mapper';
import { PriceMapper } from 'ish-core/models/price/price.mapper';
import { PriceItemMapper } from 'ish-core/models/price-item/price-item.mapper';
import { ShippingMethodMapper } from 'ish-core/models/shipping-method/shipping-method.mapper';

import { Basket } from './basket.model';
Expand Down Expand Up @@ -73,24 +73,24 @@ export class BasketMapper {

return totalsData
? {
itemTotal: PriceMapper.fromPriceItem(totalsData.itemTotal),
undiscountedItemTotal: PriceMapper.fromPriceItem(totalsData.undiscountedItemTotal),
shippingTotal: PriceMapper.fromPriceItem(totalsData.shippingTotal),
undiscountedShippingTotal: PriceMapper.fromPriceItem(totalsData.undiscountedShippingTotal),
paymentCostsTotal: PriceMapper.fromPriceItem(totalsData.paymentCostsTotal),
dutiesAndSurchargesTotal: PriceMapper.fromPriceItem(totalsData.surchargeTotal),
taxTotal: { ...totalsData.grandTotal.tax, type: 'Money' },
total: PriceMapper.fromPriceItem(totalsData.grandTotal),
itemTotal: PriceItemMapper.fromPriceItem(totalsData.itemTotal),
undiscountedItemTotal: PriceItemMapper.fromPriceItem(totalsData.undiscountedItemTotal),
shippingTotal: PriceItemMapper.fromPriceItem(totalsData.shippingTotal),
undiscountedShippingTotal: PriceItemMapper.fromPriceItem(totalsData.undiscountedShippingTotal),
paymentCostsTotal: PriceItemMapper.fromPriceItem(totalsData.paymentCostsTotal),
dutiesAndSurchargesTotal: PriceItemMapper.fromPriceItem(totalsData.surchargeTotal),
taxTotal: PriceItemMapper.fromSpecificPriceItem(totalsData.grandTotal, 'tax'),
total: PriceItemMapper.fromPriceItem(totalsData.grandTotal),

itemRebatesTotal: PriceMapper.fromPriceItem(totalsData.itemValueDiscountsTotal),
valueRebatesTotal: PriceMapper.fromPriceItem(totalsData.basketValueDiscountsTotal),
itemRebatesTotal: PriceItemMapper.fromPriceItem(totalsData.itemValueDiscountsTotal),
valueRebatesTotal: PriceItemMapper.fromPriceItem(totalsData.basketValueDiscountsTotal),
valueRebates:
data.discounts && data.discounts.valueBasedDiscounts && discounts
? data.discounts.valueBasedDiscounts.map(discountId => BasketRebateMapper.fromData(discounts[discountId]))
: undefined,

itemShippingRebatesTotal: PriceMapper.fromPriceItem(totalsData.itemShippingDiscountsTotal),
shippingRebatesTotal: PriceMapper.fromPriceItem(totalsData.basketShippingDiscountsTotal),
itemShippingRebatesTotal: PriceItemMapper.fromPriceItem(totalsData.itemShippingDiscountsTotal),
shippingRebatesTotal: PriceItemMapper.fromPriceItem(totalsData.basketShippingDiscountsTotal),
shippingRebates:
data.discounts && data.discounts.shippingBasedDiscounts && discounts
? data.discounts.shippingBasedDiscounts.map(discountId =>
Expand All @@ -101,15 +101,15 @@ export class BasketMapper {
itemSurchargeTotalsByType:
data.surcharges && data.surcharges.itemSurcharges
? data.surcharges.itemSurcharges.map(surcharge => ({
amount: PriceMapper.fromPriceItem(surcharge.amount),
amount: PriceItemMapper.fromPriceItem(surcharge.amount),
displayName: surcharge.name,
description: surcharge.description,
}))
: undefined,
bucketSurchargeTotalsByType:
data.surcharges && data.surcharges.bucketSurcharges
? data.surcharges.bucketSurcharges.map(surcharge => ({
amount: PriceMapper.fromPriceItem(surcharge.amount),
amount: PriceItemMapper.fromPriceItem(surcharge.amount),
displayName: surcharge.name,
description: surcharge.description,
}))
Expand Down
22 changes: 11 additions & 11 deletions src/app/core/models/line-item/line-item.interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PriceItem } from 'ish-core/models/price-item/price-item.interface';
import { Price } from 'ish-core/models/price/price.model';
import { PriceItemData } from 'ish-core/models/price-item/price-item.interface';
import { PriceData } from 'ish-core/models/price/price.interface';

export interface LineItemData {
id: string;
Expand All @@ -13,21 +13,21 @@ export interface LineItemData {

surcharges?: [
{
amount: PriceItem;
amount: PriceItemData;
description?: string;
name?: string;
}
];
discounts?: string[];
pricing: {
salesTaxTotal?: Price;
shippingTaxTotal?: Price;
shippingTotal: PriceItem;
total: PriceItem;
valueRebatesTotal?: PriceItem;
price: PriceItem;
undiscountedPrice: PriceItem;
singleBasePrice: PriceItem;
salesTaxTotal?: PriceData;
shippingTaxTotal?: PriceData;
shippingTotal: PriceItemData;
total: PriceItemData;
valueRebatesTotal?: PriceItemData;
price: PriceItemData;
undiscountedPrice: PriceItemData;
singleBasePrice: PriceItemData;
};
hiddenGift: boolean;
freeGift: boolean;
Expand Down
Loading