File
Metadata
| changeDetection |
ChangeDetectionStrategy.OnPush |
| selector |
cx-payment-type |
| templateUrl |
./payment-type.component.html |
Methods
|
changeType
|
changeType(code: string)
|
|
|
Parameters :
| Name |
Type |
Optional |
| code |
string
|
No
|
|
|
Private
_poNumberInput
|
Type : ElementRef
|
Decorators :
@ViewChild('poNumber', {static: false})
|
|
|
|
cartPoNumber$
|
Type : Observable<string>
|
Default value : this.paymentTypeService
.getPoNumber()
.pipe(
filter(isNotUndefined),
tap((po) => {
return (this.cartPoNumber = po);
})
)
|
|
|
|
typeSelected$
|
Type : Observable<string>
|
Default value : this.paymentTypeService
.getSelectedPaymentType()
.pipe(
filter(isNotUndefined),
distinctUntilChanged(),
tap((selected) => {
this.typeSelected = selected;
this.checkoutStepService.resetSteps();
this.checkoutStepService.disableEnableStep(
CheckoutStepType.PAYMENT_DETAILS,
selected === B2BPaymentTypeEnum.ACCOUNT_PAYMENT
);
})
)
|
|
|
import {
ChangeDetectionStrategy,
Component,
ElementRef,
ViewChild,
} from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { CheckoutStepType, PaymentTypeFacade } from '@spartacus/checkout/root';
import {
B2BPaymentTypeEnum,
isNotUndefined,
PaymentType,
} from '@spartacus/core';
import { Observable } from 'rxjs';
import { distinctUntilChanged, filter, tap } from 'rxjs/operators';
import { CheckoutStepService } from '../../services/checkout-step.service';
@Component({
selector: 'cx-payment-type',
templateUrl: './payment-type.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class PaymentTypeComponent {
@ViewChild('poNumber', { static: false })
private _poNumberInput: ElementRef;
typeSelected: string;
cartPoNumber: string;
paymentTypes$: Observable<PaymentType[]> =
this.paymentTypeService.getPaymentTypes();
typeSelected$: Observable<string> = this.paymentTypeService
.getSelectedPaymentType()
.pipe(
filter(isNotUndefined),
distinctUntilChanged(),
tap((selected) => {
this.typeSelected = selected;
this.checkoutStepService.resetSteps();
this.checkoutStepService.disableEnableStep(
CheckoutStepType.PAYMENT_DETAILS,
selected === B2BPaymentTypeEnum.ACCOUNT_PAYMENT
);
})
);
cartPoNumber$: Observable<string> = this.paymentTypeService
.getPoNumber()
.pipe(
filter(isNotUndefined),
tap((po) => {
return (this.cartPoNumber = po);
})
);
constructor(
protected paymentTypeService: PaymentTypeFacade,
protected checkoutStepService: CheckoutStepService,
protected activatedRoute: ActivatedRoute
) {}
changeType(code: string): void {
this.paymentTypeService.setPaymentType(code);
this.typeSelected = code;
}
next(): void {
// set po number to cart
const poNumInput = this._poNumberInput.nativeElement.value;
if (this.typeSelected && poNumInput !== this.cartPoNumber) {
this.paymentTypeService.setPaymentType(this.typeSelected, poNumInput);
}
this.checkoutStepService.next(this.activatedRoute);
}
back(): void {
this.checkoutStepService.back(this.activatedRoute);
}
}
<div class="row">
<div class="col-md-12 col-lg-6">
<label>
<span class="label-content">{{
'checkoutPO.poNumber' | cxTranslate
}}</span>
<input
#poNumber
class="form-control"
formControlName="poNumber"
type="text"
placeholder="{{ 'checkoutPO.placeholder' | cxTranslate }}"
value="{{ cartPoNumber$ | async }}"
/>
</label>
</div>
</div>
<div class="row">
<div class="col-md-12 col-lg-6">
<ng-container
*ngIf="
(paymentTypes$ | async)?.length && typeSelected$ | async;
else loading
"
>
<label class="cx-payment-type-container">
<span class="label-content">{{
'paymentTypes.title' | cxTranslate
}}</span>
<div class="form-check" *ngFor="let type of paymentTypes$ | async">
<input
id="paymentType-{{ type.code }}"
class="form-check-input"
role="radio"
type="radio"
aria-checked="true"
(change)="changeType(type.code)"
[value]="type.code"
[checked]="type.code == typeSelected"
formControlName="paymentType"
/>
<label
class="cx-payment-type-label form-check-label form-radio-label"
for="paymentType-{{ type.code }}"
>
<div class="cx-payment-type">
{{ 'paymentTypes.paymentType_' + type?.code | cxTranslate }}
</div>
</label>
</div>
</label>
</ng-container>
</div>
</div>
<div class="cx-checkout-btns row">
<div class="col-md-12 col-lg-6">
<button class="btn btn-block btn-action" (click)="back()">
{{ 'checkout.backToCart' | cxTranslate }}
</button>
</div>
<div class="col-md-12 col-lg-6">
<button class="btn btn-block btn-primary" (click)="next()">
{{ 'common.continue' | cxTranslate }}
</button>
</div>
</div>
<ng-template #loading>
<div class="cx-spinner">
<cx-spinner></cx-spinner>
</div>
</ng-template>
Legend
Html element with directive