Skip to content

Commit

Permalink
feat: save orderReferenceId as native basket attribute (#1499)
Browse files Browse the repository at this point in the history
  • Loading branch information
SGrueber authored Sep 8, 2023
1 parent d8634d3 commit 7c160ce
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 28 deletions.
2 changes: 2 additions & 0 deletions docs/guides/migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ kb_sync_latest_only

## 4.1 to 4.2

The basket attribute 'orderReferenceId' is now saved as native attribute 'externalOrderReference' at the basket, but it still exists at the basket and can be displayed further on, if needed.

A better handling for cookie `SameSite` and `secure` settings was implemented with new defaults to `SameSite=Strict` and `secure`.
This can still be overridden when calling `cookies.services` `put` method with explicitly set values.
Now the `secure` setting is always set to `true` if in `https` mode, you can prevent this by explicitly setting it to `false`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ describe('Requisition Mapper', () => {
user: 'bboldner@test.intershop.de',
costCenter: 'CostCenter123',
creationDate: 12345678,
externalOrderReference: 'EXT12345',
lineItemCount: 2,
messageToMerchant: 'test message',
approval: {
costCenterApproval: {
approvers: [{ email: 'jlink@test.intershop.de' }],
Expand Down Expand Up @@ -98,12 +100,13 @@ describe('Requisition Mapper', () => {
"customerNo": "OilCorp",
"dynamicMessages": undefined,
"email": "bboldner@test.intershop.de",
"externalOrderReference": "EXT12345",
"id": "testUUDI",
"infos": undefined,
"invoiceToAddress": undefined,
"lineItemCount": 2,
"lineItems": [],
"messageToMerchant": undefined,
"messageToMerchant": "test message",
"orderNo": "10001",
"payment": undefined,
"promotionCodes": undefined,
Expand Down
5 changes: 5 additions & 0 deletions src/app/core/facades/checkout.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
setBasketPayment,
startCheckout,
submitOrder,
updateBasket,
updateBasketAddress,
updateBasketCostCenter,
updateBasketItem,
Expand Down Expand Up @@ -132,6 +133,10 @@ export class CheckoutFacade {
this.store.dispatch(updateBasketCostCenter({ costCenter }));
}

updateBasketExternalOrderReference(externalOrderReference: string) {
this.store.dispatch(updateBasket({ update: { externalOrderReference } }));
}

setBasketCustomAttribute(attribute: Attribute): void {
this.store.dispatch(setBasketAttribute({ attribute }));
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/core/models/basket/basket.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { ShippingMethodData } from 'ish-core/models/shipping-method/shipping-met

export interface BasketBaseData {
id: string;
purchaseCurrency?: string;
calculated: boolean;
purchaseCurrency?: string;
invoiceToAddress?: string;
commonShipToAddress?: string;
commonShippingMethod?: string;
Expand All @@ -27,6 +27,7 @@ export interface BasketBaseData {
valueBasedDiscounts?: string[];
};
buckets?: string[];
externalOrderReference?: string;
lineItems?: string[];
messageToMerchant?: string;
payments?: string[];
Expand Down
6 changes: 6 additions & 0 deletions src/app/core/models/basket/basket.mapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ describe('Basket Mapper', () => {
},
],
},
messageToMerchant: 'test message',
externalOrderReference: 'EXT12345',
};

const basketIncludedData = {
Expand Down Expand Up @@ -179,6 +181,10 @@ describe('Basket Mapper', () => {
expect(basket.totals.bucketSurchargeTotalsByType[0].amount.gross).toBe(
basketData.data.surcharges.bucketSurcharges[0].amount.gross.value
);

expect(basket.messageToMerchant).toBe(basketData.data.messageToMerchant);
expect(basket.externalOrderReference).toBe(basketData.data.externalOrderReference);

expect(basket.totals.isEstimated).toBeTrue();
});

Expand Down
1 change: 1 addition & 0 deletions src/app/core/models/basket/basket.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class BasketMapper {
attributes: data.attributes,
taxationId: data.attributes?.find(attr => attr.name === 'taxationID')?.value as string,
user: data.buyer,
externalOrderReference: data.externalOrderReference,
messageToMerchant: data.messageToMerchant,
};
}
Expand Down
1 change: 1 addition & 0 deletions src/app/core/models/basket/basket.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface AbstractBasket<T> {
firstName: string;
lastName: string;
};
externalOrderReference?: string;
messageToMerchant?: string;
}

Expand Down
5 changes: 5 additions & 0 deletions src/app/core/models/order/order.mapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ describe('Order Mapper', () => {
},
],
},
messageToMerchant: 'test message',
externalOrderReference: 'EXT12345',
attributes: [
{ name: 'BusinessObjectAttributes#OrderApproval_ApprovalDate', value: '2020-10-12T13:40:00+02:00', type: 'Date' },
{ name: 'BusinessObjectAttributes#OrderApproval_ApproverFirstName', value: 'Patricia', type: 'String' },
Expand Down Expand Up @@ -160,6 +162,9 @@ describe('Order Mapper', () => {

expect(order.approval.approverFirstName).toBe('Patricia');
expect(order.requisitionNo).toBe(orderBaseData.requisitionDocumentNo);

expect(order.messageToMerchant).toBe(orderBaseData.messageToMerchant);
expect(order.externalOrderReference).toBe(orderBaseData.externalOrderReference);
});
});
});
2 changes: 2 additions & 0 deletions src/app/core/models/order/order.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ export class OrderMapper {
attributes: data.attributes,
taxationId: data.taxIdentificationNumber,
user: data.buyer,
messageToMerchant: data.messageToMerchant,
externalOrderReference: data.externalOrderReference,
};
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/app/core/services/basket/basket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ import { getBasketIdOrCurrent, getCurrentBasket } from 'ish-core/store/customer/
import { encodeResourceID } from 'ish-core/utils/url-resource-ids';

export type BasketUpdateType =
| { invoiceToAddress: string }
| { commonShipToAddress: string }
| { commonShippingMethod: string }
| { costCenter: string }
| { commonShipToAddress: string }
| { calculated: boolean }
| { costCenter: string }
| { externalOrderReference: string }
| { invoiceToAddress: string }
| { messageToMerchant: string };

export type BasketItemUpdateType =
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/store/customer/basket/basket.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const addMessageToMerchant = createAction(
'[Basket] Message to Merchant',
payload<{ messageToMerchant: string }>()
);
export const updateBasket = createAction('[Basket Internal] Update Basket', payload<{ update: BasketUpdateType }>());
export const updateBasket = createAction('[Basket API] Update Basket', payload<{ update: BasketUpdateType }>());

export const updateBasketFail = createAction('[Basket API] Update Basket Fail', httpError());

Expand Down
6 changes: 3 additions & 3 deletions src/app/core/store/customer/basket/basket.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ describe('Basket Effects', () => {

effects.recalculateBasketAfterCurrencyChange$.subscribe(action => {
expect(action).toMatchInlineSnapshot(`
[Basket Internal] Update Basket:
update: {"calculated":true}
`);
[Basket API] Update Basket:
update: {"calculated":true}
`);
done();
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/utils/dev/basket-mock-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class BasketMockData {
commonShippingMethod: BasketMockData.getShippingMethod(),
payment: BasketMockData.getPayment(),
totals: BasketMockData.getTotals(),
attributes: [{ name: 'orderReferenceID', value: '111-222-333' }],
externalOrderReference: '111-222-333',
} as BasketView;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<p>{{ object.costCenter }} {{ costCenterName }}</p>
</div>

<div *ngIf="orderReferenceID" data-testing-id="orderReferenceID">
<div *ngIf="object.externalOrderReference" data-testing-id="orderReferenceID">
<a
*ngIf="editRouterLink"
class="float-right btn-tool"
Expand All @@ -23,6 +23,6 @@
<fa-icon [icon]="['fas', 'pencil-alt']"></fa-icon>
</a>
<strong>{{ 'checkout.widget.buyer.orderReferenceId' | translate }}</strong>
<p>{{ orderReferenceID }}</p>
<p>{{ object.externalOrderReference }}</p>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export class BasketBuyerComponent implements OnInit, OnDestroy {
customer$: Observable<Customer>;

taxationID: string;
orderReferenceID: string;
costCenterName: string;
userName: string;
companyName1: string;
Expand All @@ -35,7 +34,6 @@ export class BasketBuyerComponent implements OnInit, OnDestroy {

ngOnInit() {
this.taxationID = this.object.taxationId;
this.orderReferenceID = this.getAttributeValue('orderReferenceID');
this.costCenterName = this.getAttributeValue('BusinessObjectAttributes#Order_CostCenter_Name');

this.userName = this.object.user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('Basket Order Reference Component', () => {

it('should read the order reference id from the basket', () => {
component.basket = {
attributes: [{ name: 'orderReferenceID', value: '4711' }],
externalOrderReference: '4711',
} as Basket;

fixture.detectChanges();
Expand All @@ -66,7 +66,7 @@ describe('Basket Order Reference Component', () => {
});
component.submitForm();

verify(checkoutFacade.setBasketCustomAttribute(anything())).once();
verify(checkoutFacade.updateBasketExternalOrderReference(anything())).once();
});

it('should not emit form when an invalid form is submitted', () => {
Expand All @@ -77,6 +77,6 @@ describe('Basket Order Reference Component', () => {
});
component.submitForm();

verify(checkoutFacade.setBasketCustomAttribute(anything())).never();
verify(checkoutFacade.updateBasketExternalOrderReference(anything())).never();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,14 @@ export class BasketOrderReferenceComponent implements OnInit, OnChanges {
ngOnChanges(changes: SimpleChanges) {
if (this.basket) {
this.successMessage(changes.basket);
this.model = { ...this.model, orderReferenceId: this.getOrderReferenceId(this.basket) };
this.model = { ...this.model, orderReferenceId: this.basket.externalOrderReference };
}
}

private getOrderReferenceId(basket: Basket): string {
return basket?.attributes?.find(attr => attr.name === 'orderReferenceID')?.value as string;
}

private successMessage(basketChange: SimpleChange) {
if (
this.getOrderReferenceId(basketChange?.previousValue) !== this.getOrderReferenceId(basketChange?.currentValue) &&
(basketChange?.previousValue as Basket)?.externalOrderReference !==
(basketChange?.currentValue as Basket)?.externalOrderReference &&
!basketChange?.firstChange
) {
this.showSuccessMessage = true;
Expand All @@ -83,16 +80,13 @@ export class BasketOrderReferenceComponent implements OnInit, OnChanges {
}

get disabled() {
return this.form.invalid || (!this.getOrderReferenceId(this.basket) && !this.form.get('orderReferenceId').value);
return this.form.invalid || (!this.basket?.externalOrderReference && !this.form.get('orderReferenceId').value);
}

submitForm() {
if (this.disabled) {
return;
}
this.checkoutFacade.setBasketCustomAttribute({
name: 'orderReferenceID',
value: this.form.get('orderReferenceId').value,
});
this.checkoutFacade.updateBasketExternalOrderReference(this.form.get('orderReferenceId').value);
}
}

0 comments on commit 7c160ce

Please sign in to comment.