Skip to content

Commit

Permalink
fix: dynamic cta not visible on first visit (#19333)
Browse files Browse the repository at this point in the history
CXSPA-6730
  • Loading branch information
FollowTheFlo authored Oct 4, 2024
1 parent 7279d4f commit 12c6c13
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ describe('OpfCtaScriptsService', () => {
'stopEvents',
'fillCtaRequestforCartPage',
'fillCtaRequestforProductPage',
'registerScriptReadyEvent',
]);
opfStaticCtaServiceMock = jasmine.createSpyObj('OpfStaticCtaService', [
'fillCtaRequestforPagesWithOrder',
Expand Down Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ export class OpfDynamicCtaService {

initiateEvents() {
if (!this.isOnsiteMessagingInit) {
this.registerScriptReadyEvent();
this.listenScriptReadyEvent();

this.isCartPage && this.cartChangedListener();
Expand Down Expand Up @@ -160,7 +159,7 @@ export class OpfDynamicCtaService {
).padStart(4, '0');
}

protected registerScriptReadyEvent() {
registerScriptReadyEvent() {
this.globalFunctionsFacade.registerGlobalFunctions({
paymentSessionId: '',
domain: GlobalFunctionsDomain.GLOBAL,
Expand Down

0 comments on commit 12c6c13

Please sign in to comment.