From d9ab9a293da3d9ac0a60770e563be672787797e8 Mon Sep 17 00:00:00 2001 From: Axel Cureno Basurto Date: Mon, 30 Sep 2024 14:57:12 -0700 Subject: [PATCH] Reverts MWPW-157555: Causing prices and CTAs to fail in Safari (#2987) --- libs/blocks/merch/merch.js | 10 +++++++++- test/blocks/merch/merch.test.js | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/libs/blocks/merch/merch.js b/libs/blocks/merch/merch.js index 7b5b4e3d05..6fb4b58ea7 100644 --- a/libs/blocks/merch/merch.js +++ b/libs/blocks/merch/merch.js @@ -2,7 +2,6 @@ import { createTag, getConfig, loadArea, loadScript, loadStyle, localizeLink, } from '../../utils/utils.js'; import { replaceKey } from '../../features/placeholders.js'; -import * as commerceLib from '../../deps/mas/commerce.js'; export const CHECKOUT_LINK_CONFIG_PATH = '/commerce/checkout-link.json'; // relative to libs. @@ -423,6 +422,15 @@ export async function initService(force = false) { } const { env, commerce = {}, locale } = getConfig(); initService.promise = initService.promise ?? polyfills().then(async () => { + const { hostname, searchParams } = new URL(window.location.href); + let commerceLibPath = '../../deps/mas/commerce.js'; + if (/hlx\.(page|live)$|localhost$|www\.stage\.adobe\.com$/.test(hostname)) { + const maslibs = searchParams.get('maslibs'); + if (maslibs) { + commerceLibPath = `${getMasBase(hostname, maslibs)}/libs/commerce.js`; + } + } + const commerceLib = await import(commerceLibPath); const service = await commerceLib.init(() => ({ env, commerce, diff --git a/test/blocks/merch/merch.test.js b/test/blocks/merch/merch.test.js index 10d84111a5..cee0f412cc 100644 --- a/test/blocks/merch/merch.test.js +++ b/test/blocks/merch/merch.test.js @@ -798,6 +798,16 @@ describe('Merch Block', () => { updateSearch({}); }); + it('should load commerce.js via maslibs', async () => { + initService.promise = undefined; + getMasBase.baseUrl = 'http://localhost:2000/test/blocks/merch/mas'; + updateSearch({ maslibs: 'test' }); + setConfig(config); + await mockIms(); + const commerce = await initService(true); + expect(commerce.mock).to.be.true; + }); + it('should return the default Adobe URL if no maslibs parameter is present', () => { expect(getMasBase()).to.equal('https://www.adobe.com/mas'); });