Skip to content

Commit d8e9677

Browse files
bozojovicicBozo Jovicic
andauthored
MWPW-187145 [ROW M@S] 3-in-1 fallback feature to maintain CRM on Plans page (#5384)
* MWPW-187145 [ROW M@S] 3-in-1 fallback feature to maintain CRM on Plans page * MWPW-187145 - unit tests * MWPW-187145 - unit tests * MWPW-187145 - lint * MWPW-187145 [ROW M@S] 3-in-1 fallback feature to maintain CRM on Plans page * Trigger Build * Trigger Build * MWPW-187145 [ROW M@S] 3-in-1 fallback feature to maintain CRM on Plans page * MWPW-187145 [ROW M@S] 3-in-1 fallback feature to maintain CRM on Plans page * MWPW-187145 - Pass stock and quantity to fallback modal * MWPW-187145 - formatting * MWPW-187145 - Fix for Nala * MWPW-187145 - Fix for Nala --------- Co-authored-by: Bozo Jovicic <bozo@hitthecode.com>
1 parent a0a8725 commit d8e9677

File tree

3 files changed

+84
-10
lines changed

3 files changed

+84
-10
lines changed

libs/blocks/merch/merch.js

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,10 @@ export const CC_ALL_APPS = [
325325
const NAME_LOCALE = 'LOCALE';
326326
const NAME_PRODUCT_FAMILY = 'PRODUCT_FAMILY';
327327
const FREE_TRIAL_PATH = 'FREE_TRIAL_PATH';
328+
const CRM_PATH = 'CRM_PATH';
328329
const BUY_NOW_PATH = 'BUY_NOW_PATH';
329330
const FREE_TRIAL_HASH = 'FREE_TRIAL_HASH';
331+
const CRM_HASH = 'CRM_HASH';
330332
const BUY_NOW_HASH = 'BUY_NOW_HASH';
331333
const OFFER_TYPE_TRIAL = 'TRIAL';
332334
const LOADING_ENTITLEMENTS = 'loading-entitlements';
@@ -919,7 +921,7 @@ export async function updateModalState({ cta, closedByUser } = {}) {
919921
return modalState.isOpen;
920922
}
921923

922-
export async function openModal(e, url, offerType, hash, extraOptions, el) {
924+
export async function openModal(e, urlParam, offerType, hash, extraOptions, el) {
923925
e.preventDefault();
924926
e.stopImmediatePropagation();
925927
if (modalState.isOpen) return;
@@ -939,6 +941,17 @@ export async function openModal(e, url, offerType, hash, extraOptions, el) {
939941
}
940942
return;
941943
}
944+
945+
let url = urlParam;
946+
if (el?.dataset.modal === 'crm') {
947+
const card = el.closest('merch-card');
948+
const stock = card?.querySelector('merch-addon')?.shadowRoot?.querySelector('input[type="checkbox"]')?.checked;
949+
const quantity = card?.querySelector('merch-quantity-select')?.shadowRoot?.querySelector('input[name="quantity"]')?.value;
950+
const urlObj = new URL(url);
951+
if (stock) urlObj.searchParams.set('stock', 'on');
952+
if (quantity) urlObj.searchParams.set('qs', quantity);
953+
if (stock || quantity) url = urlObj.toString();
954+
}
942955
if (isInternalModal(url)) {
943956
const fragmentPath = url.split(/(hlx|aem).(page|live)/).pop();
944957
modal = await openFragmentModal(fragmentPath, getModal);
@@ -950,9 +963,13 @@ export async function openModal(e, url, offerType, hash, extraOptions, el) {
950963

951964
export function setCtaHash(el, checkoutLinkConfig, offerType) {
952965
if (!(el && checkoutLinkConfig && offerType)) return undefined;
953-
const hash = checkoutLinkConfig[
954-
`${offerType === OFFER_TYPE_TRIAL ? FREE_TRIAL_HASH : BUY_NOW_HASH}`
955-
];
966+
let columnName;
967+
if (el.dataset.modal === 'crm') {
968+
columnName = CRM_HASH;
969+
} else {
970+
columnName = offerType === OFFER_TYPE_TRIAL ? FREE_TRIAL_HASH : BUY_NOW_HASH;
971+
}
972+
const hash = checkoutLinkConfig[columnName];
956973
if (hash) {
957974
el.setAttribute('data-modal-id', hash);
958975
}
@@ -997,14 +1014,33 @@ export async function getModalAction(offers, options, el, isMiloPreview = isPrev
9971014
options,
9981015
);
9991016
if (!checkoutLinkConfig) return undefined;
1000-
const columnName = offerType === OFFER_TYPE_TRIAL ? FREE_TRIAL_PATH : BUY_NOW_PATH;
1017+
let columnName;
1018+
if (el?.dataset.modal === 'crm') {
1019+
columnName = CRM_PATH;
1020+
} else {
1021+
columnName = offerType === OFFER_TYPE_TRIAL ? FREE_TRIAL_PATH : BUY_NOW_PATH;
1022+
}
10011023
const hash = setCtaHash(el, checkoutLinkConfig, offerType);
10021024
let url = checkoutLinkConfig[columnName];
1025+
1026+
if (url?.includes('|')) {
1027+
const urls = url.split('|');
1028+
const tabpanel = el.closest('.tabpanel');
1029+
if (tabpanel) {
1030+
const index = [...tabpanel.parentElement.children].indexOf(tabpanel);
1031+
if (urls[index]) {
1032+
url = urls[index].trim();
1033+
}
1034+
} else {
1035+
url = urls[0].trim();
1036+
}
1037+
}
1038+
10031039
if (!url && !el?.isOpen3in1Modal) return undefined;
10041040
const prodModalUrl = isProdModal(url);
10051041
url = isInternalModal(url) || prodModalUrl
1006-
? await localizeLinkAsync(checkoutLinkConfig[columnName])
1007-
: checkoutLinkConfig[columnName];
1042+
? await localizeLinkAsync(url)
1043+
: url;
10081044
url = isMiloPreview && prodModalUrl ? url.replace('https://www.adobe.com', 'https://www.stage.adobe.com') : url;
10091045
return {
10101046
url,

nala/blocks/merch/three-in-one.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module.exports = {
5252
{
5353
sectionId: 'deeplink-students-override',
5454
attributes: {
55-
'data-modal': 'crm',
55+
'data-modal': 'd2p',
5656
href: 'https://commerce.adobe.com/store/segmentation?cli=adobe_com&ctx=fp&co=US&lang=en&ms=e&ot=BASE&cs=INDIVIDUAL&pa=phsp_direct_individual',
5757
'aria-label': 'Buy now - Photoshop - Students and teachers',
5858
'data-extra-options': '{"ms":"e"}',
@@ -62,7 +62,7 @@ module.exports = {
6262
{
6363
sectionId: 'deeplink-business-override',
6464
attributes: {
65-
'data-modal': 'crm',
65+
'data-modal': 'd2p',
6666
href: 'https://commerce.adobe.com/store/segmentation?cli=adobe_com&ctx=fp&co=US&lang=en&ms=COM&ot=BASE&cs=t&pa=phsp_direct_individual',
6767
'aria-label': 'Buy now - Photoshop - Business',
6868
'data-extra-options': '{"cs":"t"}',
@@ -72,7 +72,7 @@ module.exports = {
7272
{
7373
sectionId: 'deeplink-promoid',
7474
attributes: {
75-
'data-modal': 'crm',
75+
'data-modal': 'd2p',
7676
href: 'https://commerce.adobe.com/store/segmentation?cli=adobe_com&ctx=fp&co=US&promoid=K42KVSWP&mv=other&lang=en&ms=COM&ot=BASE&cs=INDIVIDUAL&pa=phsp_direct_individual',
7777
'aria-label': 'Buy now - Photoshop - Individuals',
7878
'data-extra-options': '{"promoid":"K42KVSWP","mv":"other"}',

test/blocks/merch/merch.test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ const CHECKOUT_LINK_CONFIGS = {
5757
FREE_TRIAL_PATH: 'https://www.adobe.com/mini-plans/illustrator.html?mid=ft&web=1',
5858
BUY_NOW_PATH: 'https://www.adobe.com/plans-fragments/modals/individual/modals-content-rich/illustrator/master.modal.html',
5959
LOCALE: '',
60+
CRM_HASH: 'crm-buy-illustrator',
61+
CRM_PATH: 'https://www.adobe.com/plans-fragments/modals/individual/crm/illustrator/master.modal.html',
6062
},
6163
{
6264
PRODUCT_FAMILY: 'PHOTOSHOP',
@@ -91,6 +93,8 @@ const CHECKOUT_LINK_CONFIGS = {
9193
FREE_TRIAL_PATH: 'https://www.adobe.com/mini-plans/audition.html?mid=ft&web=1',
9294
BUY_NOW_PATH: 'www.adobe.com/will/not/be/localized.html',
9395
LOCALE: '',
96+
CRM_HASH: 'crm-buy-audition',
97+
CRM_PATH: 'https://www.adobe.com/plans-fragments/modals/individual/crm/audition/master.modal.html',
9498
},
9599
{
96100
PRODUCT_FAMILY: 'ILLUSTRATOR+abc',
@@ -99,6 +103,8 @@ const CHECKOUT_LINK_CONFIGS = {
99103
FREE_TRIAL_PATH: 'https://www.adobe.com/mini-plans/illustrator_abc.html?mid=ft&web=1',
100104
BUY_NOW_PATH: 'https://www.adobe.com/buy/mini-plans/illustrator_abc.html?mid=ft&web=1',
101105
LOCALE: '',
106+
CRM_HASH: 'crm-buy-illustrator-abc',
107+
CRM_PATH: 'https://www.adobe.com/plans-fragments/modals/individual/crm_abc/illustrator/master.modal.html',
102108
},
103109
],
104110
};
@@ -978,13 +984,15 @@ describe('Merch Block', () => {
978984
const checkoutLinkConfig = await getCheckoutLinkConfig(undefined, undefined, 'ILLUSTRATOR', options);
979985
expect(checkoutLinkConfig.FREE_TRIAL_PATH).to.equal('https://www.adobe.com/mini-plans/illustrator_abc.html?mid=ft&web=1');
980986
expect(checkoutLinkConfig.BUY_NOW_PATH).to.equal('https://www.adobe.com/buy/mini-plans/illustrator_abc.html?mid=ft&web=1');
987+
expect(checkoutLinkConfig.CRM_PATH).to.equal('https://www.adobe.com/plans-fragments/modals/individual/crm_abc/illustrator/master.modal.html');
981988
});
982989

983990
it('getCheckoutLinkConfig: finds using paCode and no svar', async () => {
984991
const options = { extraOptions: '{"other": "xyz"}' };
985992
const checkoutLinkConfig = await getCheckoutLinkConfig(undefined, undefined, 'ILLUSTRATOR', options);
986993
expect(checkoutLinkConfig.FREE_TRIAL_PATH).to.equal('https://www.adobe.com/mini-plans/illustrator.html?mid=ft&web=1');
987994
expect(checkoutLinkConfig.BUY_NOW_PATH).to.equal('https://www.adobe.com/plans-fragments/modals/individual/modals-content-rich/illustrator/master.modal.html');
995+
expect(checkoutLinkConfig.CRM_PATH).to.equal('https://www.adobe.com/plans-fragments/modals/individual/crm/illustrator/master.modal.html');
988996
});
989997

990998
it('getCheckoutLinkConfig: finds using productCode', async () => {
@@ -1034,6 +1042,36 @@ describe('Merch Block', () => {
10341042
expect(action.url).to.equal('https://www.stage.adobe.com/plans-fragments/modals/individual/modals-content-rich/illustrator/master.modal.html');
10351043
});
10361044

1045+
it('getModalAction: localize crm path if it comes from us/en production', async () => {
1046+
setConfig({
1047+
...config,
1048+
pathname: '/fr/test.html',
1049+
locales: { fr: { ietf: 'fr-FR' } },
1050+
prodDomains: PROD_DOMAINS,
1051+
placeholders: { download: 'Télécharger' },
1052+
});
1053+
fetchCheckoutLinkConfigs.promise = undefined;
1054+
setCheckoutLinkConfigs(CHECKOUT_LINK_CONFIGS);
1055+
const el = document.createElement('a');
1056+
el.setAttribute('data-modal', 'crm');
1057+
const action = await getModalAction([{ productArrangement: { productFamily: 'ILLUSTRATOR' } }], { modal: true }, el);
1058+
expect(action.url).to.equal('https://www.adobe.com/fr/plans-fragments/modals/individual/crm/illustrator/master.modal.html');
1059+
});
1060+
1061+
it('getModalAction: rewrites host on crm path to www.stage.adobe.com if on Stage or aem.page', async () => {
1062+
setConfig({
1063+
...config,
1064+
prodDomains: PROD_DOMAINS,
1065+
placeholders: { download: 'Télécharger' },
1066+
});
1067+
fetchCheckoutLinkConfigs.promise = undefined;
1068+
setCheckoutLinkConfigs(CHECKOUT_LINK_CONFIGS);
1069+
const el = document.createElement('a');
1070+
el.setAttribute('data-modal', 'crm');
1071+
const action = await getModalAction([{ productArrangement: { productFamily: 'ILLUSTRATOR' } }], { modal: true }, el, true);
1072+
expect(action.url).to.equal('https://www.stage.adobe.com/plans-fragments/modals/individual/crm/illustrator/master.modal.html');
1073+
});
1074+
10371075
it('getModalAction: skip modal url localization if url is invalid', async () => {
10381076
setConfig({
10391077
...config,

0 commit comments

Comments
 (0)