Skip to content

Commit

Permalink
feat: introduce optional ICM Compatibility Interceptor (#1542)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
dhhyi and shauke committed Jan 31, 2024
1 parent a77fd0f commit 88de2a2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/guides/migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ 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).
In addition the `'messageToMerchant'` environment feature toggle option needs to be enabled in the [`environment.model.ts`](../../src/environments/environment.model.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.
Expand Down
2 changes: 2 additions & 0 deletions src/app/core/core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
{
Expand Down
31 changes: 31 additions & 0 deletions src/app/core/interceptors/icm-compatibility.interceptor.ts
Original file line number Diff line number Diff line change
@@ -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, FeatureToggleType } from 'ish-core/utils/feature-toggle/feature-toggle.service';

// 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<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
if (req.url.endsWith('/configurations') && req instanceof HttpRequest) {
return next.handle(req).pipe(
withLatestFrom(this.featureToggleService.enabled$('messageToMerchant' as FeatureToggleType)),
map(([event, messageToMerchant]) => {
if (event instanceof HttpResponse && messageToMerchant && event.body?.data?.shipping) {
event.body.data.shipping.messageToMerchant = true;
}
return event;
})
);
}
return next.handle(req);
}
}
2 changes: 2 additions & 0 deletions src/environments/environment.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export interface Environment {
/* B2C features */
| 'guestCheckout'
| 'wishlists'
/* ICM compatibility - to be used with the ICMCompatibilityInterceptor */
// | 'messageToMerchant'
/* Third-party Integrations */
| 'addressDoctor'
| 'sentry'
Expand Down

0 comments on commit 88de2a2

Please sign in to comment.