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 <s.hauke@intershop.de>
  • Loading branch information
dhhyi and shauke committed Jan 30, 2024
1 parent d18cde7 commit dbb0ca4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/guides/migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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 } 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<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
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);
}
}
2 changes: 2 additions & 0 deletions src/environments/environment.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export interface Environment {
| 'tracking'
| 'tacton'
| 'maps'
/* ICM compatibility - see ICMCompatibilityInterceptor */
| 'messageToMerchant'
)[];

/* ADDITIONAL FEATURE CONFIGURATIONS */
Expand Down

0 comments on commit dbb0ca4

Please sign in to comment.