diff --git a/integration-libs/opf/cta/components/opf-cta-scripts/opf-cta-scripts.service.spec.ts b/integration-libs/opf/cta/components/opf-cta-scripts/opf-cta-scripts.service.spec.ts index dc26229ca58..00fd42d5aba 100644 --- a/integration-libs/opf/cta/components/opf-cta-scripts/opf-cta-scripts.service.spec.ts +++ b/integration-libs/opf/cta/components/opf-cta-scripts/opf-cta-scripts.service.spec.ts @@ -67,6 +67,7 @@ describe('OpfCtaScriptsService', () => { 'stopEvents', 'fillCtaRequestforCartPage', 'fillCtaRequestforProductPage', + 'registerScriptReadyEvent', ]); opfStaticCtaServiceMock = jasmine.createSpyObj('OpfStaticCtaService', [ 'fillCtaRequestforPagesWithOrder', @@ -98,6 +99,7 @@ describe('OpfCtaScriptsService', () => { ); opfDynamicCtaServiceMock.initiateEvents.and.returnValue(); opfDynamicCtaServiceMock.stopEvents.and.returnValue(); + opfDynamicCtaServiceMock.registerScriptReadyEvent.and.returnValue(); orderFacadeMock.getOrderDetails.and.returnValue(of(mockOrder)); orderHistoryFacadeMock.getOrderDetails.and.returnValue(of(mockOrder)); diff --git a/integration-libs/opf/cta/components/opf-cta-scripts/opf-cta-scripts.service.ts b/integration-libs/opf/cta/components/opf-cta-scripts/opf-cta-scripts.service.ts index ff735366408..690ad125b6b 100644 --- a/integration-libs/opf/cta/components/opf-cta-scripts/opf-cta-scripts.service.ts +++ b/integration-libs/opf/cta/components/opf-cta-scripts/opf-cta-scripts.service.ts @@ -72,12 +72,14 @@ export class OpfCtaScriptsService { !!ctaScriptsRequest?.scriptLocations.map((location) => DynamicCtaLocations.includes(location) ); - + isDynamicCtaLocation && + this.opfDynamicCtaService.registerScriptReadyEvent(); return this.fetchCtaScripts(ctaScriptsRequest); }), tap((scriptsResponse) => { - isDynamicCtaLocation = !!scriptsResponse.length && isDynamicCtaLocation; - isDynamicCtaLocation && this.opfDynamicCtaService.initiateEvents(); + isDynamicCtaLocation && + !!scriptsResponse.length && + this.opfDynamicCtaService.initiateEvents(); }), finalize(() => { this.opfResourceLoaderService.clearAllProviderResources(); diff --git a/integration-libs/opf/cta/core/services/opf-dynamic-cta.service.ts b/integration-libs/opf/cta/core/services/opf-dynamic-cta.service.ts index 79e070bfda7..6a3b5e70ee6 100644 --- a/integration-libs/opf/cta/core/services/opf-dynamic-cta.service.ts +++ b/integration-libs/opf/cta/core/services/opf-dynamic-cta.service.ts @@ -132,7 +132,6 @@ export class OpfDynamicCtaService { initiateEvents() { if (!this.isOnsiteMessagingInit) { - this.registerScriptReadyEvent(); this.listenScriptReadyEvent(); this.isCartPage && this.cartChangedListener(); @@ -160,7 +159,7 @@ export class OpfDynamicCtaService { ).padStart(4, '0'); } - protected registerScriptReadyEvent() { + registerScriptReadyEvent() { this.globalFunctionsFacade.registerGlobalFunctions({ paymentSessionId: '', domain: GlobalFunctionsDomain.GLOBAL,