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

[FIX] CXSPA-9334 Terms and condition URL not changed accordingly when… #19966

Merged
merged 12 commits into from
Feb 11, 2025
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
/>
<span class="form-check-label">
{{ 'checkoutReview.confirmThatRead' | cxTranslate }}
<a
[routerLink]="{ cxRoute: 'termsAndConditions' } | cxUrl"
<a
[attr.href]="termsAndConditionUrl$ | async"
andreighervan7 marked this conversation as resolved.
Show resolved Hide resolved
class="cx-tc-link"
target="_blank"
rel="noopener noreferrer"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,36 @@ import {
Component,
ComponentRef,
OnDestroy,
OnInit,
ViewContainerRef,
} from '@angular/core';
import {
UntypedFormBuilder,
UntypedFormGroup,
Validators,
} from '@angular/forms';
import { RoutingService } from '@spartacus/core';
import { Router } from '@angular/router';
import {
CurrencyService,
LanguageService,
RoutingService,
} from '@spartacus/core';
import { OrderFacade } from '@spartacus/order/root';
import { LaunchDialogService, LAUNCH_CALLER } from '@spartacus/storefront';
import { Observable } from 'rxjs';
import { BehaviorSubject, combineLatest, Observable } from 'rxjs';

@Component({
selector: 'cx-place-order',
templateUrl: './checkout-place-order.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: false,
})
export class CheckoutPlaceOrderComponent implements OnDestroy {
export class CheckoutPlaceOrderComponent implements OnDestroy, OnInit {
placedOrder: void | Observable<ComponentRef<any> | undefined>;
currency: string;
andreighervan7 marked this conversation as resolved.
Show resolved Hide resolved
termsAndConditionUrl$ = new BehaviorSubject<string>('');
private currency$ = this.currencyService.getActive();
andreighervan7 marked this conversation as resolved.
Show resolved Hide resolved
private language$ = this.languageService.getActive();
andreighervan7 marked this conversation as resolved.
Show resolved Hide resolved

checkoutSubmitForm: UntypedFormGroup = this.fb.group({
termsAndConditions: [false, Validators.requiredTrue],
Expand All @@ -43,9 +53,16 @@ export class CheckoutPlaceOrderComponent implements OnDestroy {
protected routingService: RoutingService,
protected fb: UntypedFormBuilder,
protected launchDialogService: LaunchDialogService,
protected vcr: ViewContainerRef
protected vcr: ViewContainerRef,
protected route: Router,
andreighervan7 marked this conversation as resolved.
Show resolved Hide resolved
protected currencyService: CurrencyService,
protected languageService: LanguageService
) {}

ngOnInit() {
this.setTermsOfConditionUrl();
}

submitForm(): void {
if (this.checkoutSubmitForm.valid) {
this.placedOrder = this.launchDialogService.launch(
Expand Down Expand Up @@ -78,6 +95,16 @@ export class CheckoutPlaceOrderComponent implements OnDestroy {
this.routingService.go({ cxRoute: 'orderConfirmation' });
}

setTermsOfConditionUrl(): void {
combineLatest([this.currency$, this.language$]).subscribe(
andreighervan7 marked this conversation as resolved.
Show resolved Hide resolved
([currency, language]) => {
const segments = this.route.url.split('/').filter((s) => !!s);
const url = `/${segments[0]}/${language}/${currency}/terms-and-conditions`;
this.termsAndConditionUrl$.next(url);
andreighervan7 marked this conversation as resolved.
Show resolved Hide resolved
}
);
}

ngOnDestroy(): void {
this.launchDialogService.clear(LAUNCH_CALLER.PLACE_ORDER_SPINNER);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
[class.active]="isActive(i)"
[class.disabled]="isDisabled(i)"
>
<a

andreighervan7 marked this conversation as resolved.
Show resolved Hide resolved
<!--<a
[routerLink]="{ cxRoute: step.routeName } | cxUrl"
class="cx-link"
[attr.aria-current]="isActive(i) ? 'step' : null"
Expand All @@ -31,6 +32,28 @@
}
"
>
</a>-->
<a
[attr.href]="setNavUrl(step.routeName)"
class="cx-link"
[attr.aria-current]="isActive(i) ? 'step' : null"
[attr.aria-disabled]="isDisabled(i) ? 'true' : null"
[class.active]="isActive(i)"
[class.disabled]="isDisabled(i)"
[tabindex]="getTabIndex(i)"
[innerHTML]="
step.nameMultiLine !== false
? (step.name | cxTranslate | cxMultiLine)
: (step.name | cxTranslate)
"
[attr.aria-label]="
'checkoutProgress.state.' + getStepState(i)
| cxTranslate
: {
step: step.name | cxTranslate,
}
"
>
</a>
</li>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,32 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { ChangeDetectionStrategy, Component } from '@angular/core';
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { CheckoutStep, CheckoutStepState } from '@spartacus/checkout/base/root';
import { BehaviorSubject, Observable } from 'rxjs';
import { BehaviorSubject, combineLatest, Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
import { CheckoutStepService } from '../services/checkout-step.service';
import { Router } from '@angular/router';
import { CurrencyService, LanguageService } from '@spartacus/core';

@Component({
selector: 'cx-checkout-progress',
templateUrl: './checkout-progress.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: false,
})
export class CheckoutProgressComponent {
export class CheckoutProgressComponent implements OnInit {
private _steps$: BehaviorSubject<CheckoutStep[]> =
this.checkoutStepService.steps$;
currency: string | undefined;
language: string | undefined;

constructor(protected checkoutStepService: CheckoutStepService) {}
constructor(
protected checkoutStepService: CheckoutStepService,
protected route: Router,
protected currencyService: CurrencyService,
protected languageService: LanguageService
) {}

activeStepIndex: number;
activeStepIndex$: Observable<number> =
Expand All @@ -32,6 +41,10 @@ export class CheckoutProgressComponent {
return this._steps$.asObservable();
}

ngOnInit(): void {
this.setLanguageAndCurrency();
}

getTabIndex(stepIndex: number): number {
return !this.isActive(stepIndex) && !this.isDisabled(stepIndex) ? 0 : -1;
}
Expand All @@ -53,4 +66,37 @@ export class CheckoutProgressComponent {
}
return CheckoutStepState.COMPLETED;
}

setNavUrl(routeName: string): string {
const segments = this.route.url.split('/').filter((s) => !!s);

if (!this.currency || !this.language) {
return '';
}

const baseUrl = `/${segments[0]}/${this.language}/${this.currency}/checkout`;

switch (routeName) {
case 'checkoutDeliveryAddress':
return `${baseUrl}/delivery-address`;
case 'checkoutPaymentDetails':
return `${baseUrl}/payment-details`;
case 'checkoutReviewOrder':
return `${baseUrl}/review-order`;
case 'checkoutDeliveryMode':
return `${baseUrl}/delivery-mode`;
default:
return baseUrl;
}
}

setLanguageAndCurrency(): void {
combineLatest([
this.currencyService.getActive(),
this.languageService.getActive(),
]).subscribe(([currency, language]) => {
this.currency = currency;
this.language = language;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
} from '@angular/core';
import { UntypedFormBuilder } from '@angular/forms';
import { CheckoutPlaceOrderComponent } from '@spartacus/checkout/base/components';
import { RoutingService } from '@spartacus/core';
import { CurrencyService, LanguageService, RoutingService } from '@spartacus/core';
import { Router } from '@angular/router';
import {
OrderFacade,
ORDER_TYPE,
Expand Down Expand Up @@ -49,9 +50,21 @@ export class CheckoutScheduledReplenishmentPlaceOrderComponent
protected launchDialogService: LaunchDialogService,
protected vcr: ViewContainerRef,
protected checkoutReplenishmentFormService: CheckoutReplenishmentFormService,
protected scheduledReplenishmentOrderFacade: ScheduledReplenishmentOrderFacade
protected scheduledReplenishmentOrderFacade: ScheduledReplenishmentOrderFacade,
protected route: Router,
protected currencyService: CurrencyService,
protected languageService: LanguageService
) {
super(orderFacade, routingService, fb, launchDialogService, vcr);
super(
orderFacade,
routingService,
fb,
launchDialogService,
vcr,
route,
currencyService,
languageService
);
}

submitForm(): void {
Expand Down
Loading