Skip to content

Commit

Permalink
Reverts MWPW-157555: Causing prices and CTAs to fail in Safari (adobe…
Browse files Browse the repository at this point in the history
  • Loading branch information
Axelcureno authored Sep 30, 2024
1 parent 864d1f1 commit d9ab9a2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion libs/blocks/merch/merch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions test/blocks/merch/merch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down

0 comments on commit d9ab9a2

Please sign in to comment.