Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MWPW-166076 Update a.com Business plans page CTAs to point to CME-1 M7 #3723

Open
wants to merge 9 commits into
base: stage
Choose a base branch
from
33 changes: 33 additions & 0 deletions libs/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ const PREVIEW = 'target-preview';
const PAGE_URL = new URL(window.location.href);
export const SLD = PAGE_URL.hostname.includes('.aem.') ? 'aem' : 'hlx';

const BUSINESS_PLANS_PATH = '/creativecloud/business-plans.html';
const PROMO_PARAM = 'promo';
let isMartechLoaded = false;

Expand Down Expand Up @@ -689,6 +690,31 @@ export function convertStageLinks({ anchors, config, hostname, href }) {
});
}

async function getImsCountry() {
if (window.adobeIMS?.isSignedInUser()) {
const profile = await window.adobeIMS.getProfile();
return profile.countryCode;
}

return null;
}

export async function generateM7Link() {
const { locale } = getConfig();
const { getMiloLocaleSettings } = await import('../blocks/merch/merch.js');
const pageCountry = getMiloLocaleSettings(locale).country;
const imsCountry = await getImsCountry();
const country = imsCountry || pageCountry;

const m7link = new URL('https://commerce.adobe.com/store/segmentation');
m7link.searchParams.append('cli', 'adobe_com');
m7link.searchParams.append('co', country);
m7link.searchParams.append('pa', 'ccsn_direct_individual');
m7link.searchParams.append('cs', 't');
m7link.searchParams.append('af', 'uc_segmentation_hide_tabs');
return m7link.toString();
}

export function decorateLinks(el) {
const config = getConfig();
decorateImageLinks(el);
Expand Down Expand Up @@ -737,6 +763,13 @@ export function decorateLinks(el) {
processQuickLink(a);
})();
}

if (a.href.includes(BUSINESS_PLANS_PATH)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you explored using an autoblock for such scenario? I think it would be better instead of adding all the logic in utils.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bozojovicic - you can see caas or faas autoblocks for reference

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created it libs/blocks/m7business/m7business.js
BTW, autoblock is awesome idea!

generateM7Link().then((m7Link) => {
a.href = m7Link;
});
}

// Append aria-label
const pipeRegex = /\s?\|([^|]*)$/;
if (pipeRegex.test(a.textContent) && !/\.[a-z]+/i.test(a.textContent)) {
Expand Down
3 changes: 3 additions & 0 deletions test/utils/mocks/body.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
Text | Aria label
</a>
</p>
<p>
<a class="business-plans" href="https://www.adobe.com/creativecloud/business-plans.html"></a>
</p>
</div>
<div class="quote borders contained hide-block">
<div>
Expand Down
16 changes: 16 additions & 0 deletions test/utils/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,22 @@ describe('Utils', () => {
expect(httpLink.dataset.httpLink).to.equal('true');
});

it('Converts business plans link to M7 link', () => {
const container = document.querySelector('main div');
utils.decorateLinks(container);
const m7Link = container.querySelector('.business-plans');
expect(m7Link.href).to.equal('https://commerce.adobe.com/store/segmentation?cli=adobe_com&co=US&pa=ccsn_direct_individual&cs=t&af=uc_segmentation_hide_tabs');
});

it('Converts business plans link to M7 link for IMS user', async () => {
const buIms = window.adobeIMS;
const profile = { countryCode: 'CH' };
window.adobeIMS = { getProfile: () => profile, isSignedInUser: () => true };
const m7Link = await utils.generateM7Link();
expect(m7Link).to.equal('https://commerce.adobe.com/store/segmentation?cli=adobe_com&co=CH&pa=ccsn_direct_individual&cs=t&af=uc_segmentation_hide_tabs');
window.adobeIMS = buIms;
});

it('Sets up milo.deferredPromise', async () => {
const { resolveDeferred } = utils.getConfig();
expect(window.milo.deferredPromise).to.exist;
Expand Down
Loading