From 86317ee9a8687bdb1bbaefa176cbcb5ba55a502b Mon Sep 17 00:00:00 2001 From: Danilo Hoffmann Date: Mon, 4 Dec 2023 10:29:04 +0100 Subject: [PATCH] feat: introduce optional ICM Compatibility Interceptor (#1542) * can be used for `messageToMerchant` feature toggle compatibility with ICM 7.10 * see https://github.com/intershop/intershop-pwa/blob/develop/docs/guides/migrations.md#from-50-to-51 Co-authored-by: Stefan Hauke --- docs/guides/migrations.md | 4 +++ src/app/core/core.module.ts | 2 ++ .../icm-compatibility.interceptor.ts | 31 +++++++++++++++++++ src/environments/environment.model.ts | 2 ++ 4 files changed, 39 insertions(+) create mode 100644 src/app/core/interceptors/icm-compatibility.interceptor.ts diff --git a/docs/guides/migrations.md b/docs/guides/migrations.md index c69647b569..11890a471b 100644 --- a/docs/guides/migrations.md +++ b/docs/guides/migrations.md @@ -12,6 +12,10 @@ kb_sync_latest_only The OrderListComponent is strictly presentational, components using it have to supply the data. The getOrders method of the OrderService doesn't fetch all related order data by default, you can provide an additional parameter to include the data you need. +In ICM 11 the `messageToMerchant` flag can be configured in the back office and its setting is supplied by the `/configurations` REST call. +For this reason the `messageToMerchant` feature toggle is removed as a configurable feature toggle. +To still be able to configure the message to merchant feature via feature toggle in ICM 7.10 environments an [`ICMCompatibilityInterceptor`](../../src/app/core/interceptors/icm-compatibility.interceptor.ts) was introduced that can be enabled in ICM 7.10 based projects in the [`core.module.ts`](../../src/app/core/core.module.ts). + ## From 4.2 to 5.0 Starting with the Intershop PWA 5.0 we develop and test against an Intershop Commerce Management 11 server. diff --git a/src/app/core/core.module.ts b/src/app/core/core.module.ts index 62416b3801..33f70302c4 100644 --- a/src/app/core/core.module.ts +++ b/src/app/core/core.module.ts @@ -30,6 +30,8 @@ import { DefaultErrorHandler } from './utils/default-error-handler'; StateManagementModule, ], providers: [ + // include the ICMCompatibilityInterceptor to add support for REST API changes (e.g. messageToMerchant) + // { provide: HTTP_INTERCEPTORS, useClass: ICMCompatibilityInterceptor, multi: true }, { provide: HTTP_INTERCEPTORS, useClass: PGIDChangeInterceptor, multi: true }, { provide: HTTP_INTERCEPTORS, useClass: ICMErrorMapperInterceptor, multi: true }, { diff --git a/src/app/core/interceptors/icm-compatibility.interceptor.ts b/src/app/core/interceptors/icm-compatibility.interceptor.ts new file mode 100644 index 0000000000..787894fe3f --- /dev/null +++ b/src/app/core/interceptors/icm-compatibility.interceptor.ts @@ -0,0 +1,31 @@ +import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { Observable, map, withLatestFrom } from 'rxjs'; + +import { FeatureToggleService } from 'ish-core/feature-toggle.module'; + +// not-dead-code +/** + * provides a compatibility layer for REST API changes in newer ICM versions + * please enable the interceptor in the `core.module.ts` if needed + * e.g. `messageToMerchant` is no longer an environment feature toggle in ICM 11 but controlled by the configurations call + */ +@Injectable() +export class ICMCompatibilityInterceptor implements HttpInterceptor { + constructor(private featureToggleService: FeatureToggleService) {} + + intercept(req: HttpRequest, next: HttpHandler): Observable> { + if (req.url.endsWith('/configurations') && req instanceof HttpRequest) { + return next.handle(req).pipe( + withLatestFrom(this.featureToggleService.enabled$('messageToMerchant')), + map(([event, messageToMerchant]) => { + if (event instanceof HttpResponse && messageToMerchant && event.body?.data?.shipping) { + event.body.data.shipping.messageToMerchant = true; + } + return event; + }) + ); + } + return next.handle(req); + } +} diff --git a/src/environments/environment.model.ts b/src/environments/environment.model.ts index 4c89e9df09..b42139945e 100644 --- a/src/environments/environment.model.ts +++ b/src/environments/environment.model.ts @@ -48,6 +48,8 @@ export interface Environment { | 'tracking' | 'tacton' | 'maps' + /* ICM compatibility - see ICMCompatibilityInterceptor */ + | 'messageToMerchant' )[]; /* ADDITIONAL FEATURE CONFIGURATIONS */