Skip to content

Commit 7af76a6

Browse files
authored
fix: prevent console error messages on checkout shipping page (#1040)
1 parent 84c449e commit 7af76a6

File tree

7 files changed

+48
-28
lines changed

7 files changed

+48
-28
lines changed

src/app/core/facades/checkout.facade.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ export class CheckoutFacade {
146146
}
147147
eligibleShippingMethodsNoFetch$ = this.store.pipe(select(getBasketEligibleShippingMethods));
148148

149+
shippingMethod$(id: string) {
150+
return this.eligibleShippingMethodsNoFetch$.pipe(
151+
map(methods => (methods?.length ? methods.find(method => method.id === id) : undefined))
152+
);
153+
}
154+
149155
getValidShippingMethod$() {
150156
return combineLatest([
151157
this.basket$.pipe(whenTruthy()),

src/app/pages/checkout-shipping/checkout-shipping/checkout-shipping.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ export class CheckoutShippingComponent implements OnInit, OnDestroy {
4646
key: 'shippingMethod',
4747
wrappers: ['shipping-radio-wrapper'],
4848
templateOptions: {
49-
label: method.name,
50-
shippingMethod: method,
49+
description: method.description,
5150
id: `shipping_method${method.id}`,
5251
value: method.id,
5352
},
Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
<span>{{ shippingMethod?.name }}:</span>&nbsp;
2-
<strong *ngIf="shippingMethod?.shippingCosts">{{ shippingMethod?.shippingCosts | ishPrice }}&nbsp;</strong>
3-
<span *ngIf="shippingMethod?.shippingTimeMin && shippingMethod?.shippingTimeMax" class="form-text form-text-inline">
4-
{{ 'checkout.shipping.delivery_time.description' | translate }}
5-
<span *ngIf="shippingMethod?.shippingTimeMin === 0 && shippingMethod?.shippingTimeMax === 1">
6-
{{ 'checkout.shipping.delivery_time.within24' | translate }}
1+
<ng-container *ngIf="shippingMethod$ | async as shippingMethod">
2+
<span>{{ shippingMethod.name }}:</span>&nbsp;
3+
<strong *ngIf="shippingMethod.shippingCosts">{{ shippingMethod.shippingCosts | ishPrice }}&nbsp;</strong>
4+
<span *ngIf="shippingMethod.shippingTimeMin && shippingMethod.shippingTimeMax" class="form-text form-text-inline">
5+
{{ 'checkout.shipping.delivery_time.description' | translate }}
6+
<span *ngIf="shippingMethod.shippingTimeMin === 0 && shippingMethod.shippingTimeMax === 1">
7+
{{ 'checkout.shipping.delivery_time.within24' | translate }}
8+
</span>
9+
<span *ngIf="shippingMethod.shippingTimeMin === 0 && shippingMethod.shippingTimeMax > 1">
10+
{{ 'checkout.shipping.delivery_time.within' | translate: { '0': shippingMethod?.shippingTimeMax } }}
11+
</span>
12+
<span *ngIf="shippingMethod.shippingTimeMin > 0">
13+
{{
14+
'checkout.shipping.delivery_time'
15+
| translate: { '0': shippingMethod.shippingTimeMin, '1': shippingMethod.shippingTimeMax }
16+
}}
17+
</span>
718
</span>
8-
<span *ngIf="shippingMethod?.shippingTimeMin === 0 && shippingMethod?.shippingTimeMax > 1">
9-
{{ 'checkout.shipping.delivery_time.within' | translate: { '0': shippingMethod?.shippingTimeMax } }}
10-
</span>
11-
<span *ngIf="shippingMethod?.shippingTimeMin > 0">
12-
{{
13-
'checkout.shipping.delivery_time'
14-
| translate: { '0': shippingMethod?.shippingTimeMin, '1': shippingMethod?.shippingTimeMax }
15-
}}
16-
</span>
17-
</span>
19+
</ng-container>

src/app/pages/checkout-shipping/formly/shipping-info/shipping-info.component.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
22
import { TranslatePipe } from '@ngx-translate/core';
33
import { MockPipe } from 'ng-mocks';
4+
import { instance, mock } from 'ts-mockito';
45

6+
import { CheckoutFacade } from 'ish-core/facades/checkout.facade';
57
import { PricePipe } from 'ish-core/models/price/price.pipe';
68

79
import { ShippingInfoComponent } from './shipping-info.component';
@@ -10,10 +12,13 @@ describe('Shipping Info Component', () => {
1012
let component: ShippingInfoComponent;
1113
let fixture: ComponentFixture<ShippingInfoComponent>;
1214
let element: HTMLElement;
15+
let checkoutFacade: CheckoutFacade;
1316

1417
beforeEach(async () => {
18+
checkoutFacade = mock(CheckoutFacade);
1519
await TestBed.configureTestingModule({
1620
declarations: [MockPipe(PricePipe), MockPipe(TranslatePipe), ShippingInfoComponent],
21+
providers: [{ provide: CheckoutFacade, useFactory: () => instance(checkoutFacade) }],
1722
}).compileComponents();
1823
});
1924

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1-
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
2+
import { Observable } from 'rxjs';
23

4+
import { CheckoutFacade } from 'ish-core/facades/checkout.facade';
35
import { ShippingMethod } from 'ish-core/models/shipping-method/shipping-method.model';
46

57
@Component({
68
selector: 'ish-shipping-info',
79
templateUrl: './shipping-info.component.html',
810
changeDetection: ChangeDetectionStrategy.OnPush,
911
})
10-
export class ShippingInfoComponent {
11-
@Input() shippingMethod: ShippingMethod;
12+
export class ShippingInfoComponent implements OnInit {
13+
@Input() shippingMethodId: string;
14+
15+
shippingMethod$: Observable<ShippingMethod>;
16+
17+
constructor(private checkoutFacade: CheckoutFacade) {}
18+
19+
ngOnInit(): void {
20+
if (this.shippingMethodId) {
21+
this.shippingMethod$ = this.checkoutFacade.shippingMethod$(this.shippingMethodId);
22+
}
23+
}
1224
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="form-check" [class.has-error]="showError">
22
<ng-template #fieldComponent></ng-template>
33
<label class="form-check-label" [for]="to.id" [ngClass]="to.labelClass">
4-
<ish-shipping-info [shippingMethod]="shippingMethod"></ish-shipping-info>
4+
<ish-shipping-info [shippingMethodId]="to.value"></ish-shipping-info>
55
<a class="details-tooltip" [ngbPopover]="ShippingMethodDescription" placement="top">
66
{{ 'checkout.detail.text' | translate }}
77
<fa-icon [icon]="['fas', 'info-circle']"></fa-icon>
@@ -10,5 +10,5 @@
1010
</div>
1111

1212
<ng-template #ShippingMethodDescription>
13-
<span [innerHTML]="shippingMethod.description"></span>
13+
<span [innerHTML]="to.description"></span>
1414
</ng-template>

src/app/pages/checkout-shipping/formly/shipping-radio-wrapper/shipping-radio-wrapper.component.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,4 @@ import { FieldWrapper } from '@ngx-formly/core';
1414
templateUrl: './shipping-radio-wrapper.component.html',
1515
changeDetection: ChangeDetectionStrategy.OnPush,
1616
})
17-
export class ShippingRadioWrapperComponent extends FieldWrapper {
18-
get shippingMethod() {
19-
return this.to.shippingMethod;
20-
}
21-
}
17+
export class ShippingRadioWrapperComponent extends FieldWrapper {}

0 commit comments

Comments
 (0)