Skip to content

Commit

Permalink
support annual merch link
Browse files Browse the repository at this point in the history
  • Loading branch information
3ch023 committed Jun 6, 2024
1 parent 08b193f commit 67e152f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
42 changes: 25 additions & 17 deletions libs/blocks/merch/merch.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ export const PRICE_TEMPLATE_DISCOUNT = 'discount';
export const PRICE_TEMPLATE_OPTICAL = 'optical';
export const PRICE_TEMPLATE_REGULAR = 'price';
export const PRICE_TEMPLATE_STRIKETHROUGH = 'strikethrough';
export const PRICE_TEMPLATE_ANNUAL = 'annual';
const PRICE_TEMPLATE_MAPPING = new Map([
['priceDiscount', PRICE_TEMPLATE_DISCOUNT],
['priceOptical', PRICE_TEMPLATE_OPTICAL],
['priceStrikethrough', PRICE_TEMPLATE_STRIKETHROUGH],
['priceAnnual', PRICE_TEMPLATE_ANNUAL],
]);

export const PLACEHOLDER_KEY_DOWNLOAD = 'download';

Expand Down Expand Up @@ -415,24 +422,25 @@ export async function getPriceContext(el, params) {
const displayRecurrence = params.get('term');
const displayTax = params.get('tax');
const forceTaxExclusive = params.get('exclusive');
let template = PRICE_TEMPLATE_REGULAR;
// This mapping also supports legacy OST links
switch (params.get('type')) {
case PRICE_TEMPLATE_DISCOUNT:
case 'priceDiscount':
template = PRICE_TEMPLATE_DISCOUNT;
break;
case PRICE_TEMPLATE_OPTICAL:
case 'priceOptical':
template = PRICE_TEMPLATE_OPTICAL;
break;
case PRICE_TEMPLATE_STRIKETHROUGH:
case 'priceStrikethrough':
template = PRICE_TEMPLATE_STRIKETHROUGH;
break;
default:
break;
}
const template = PRICE_TEMPLATE_MAPPING.get(params.get('type')) ?? params.get('type');

// switch (params.get('type')) {
// case PRICE_TEMPLATE_DISCOUNT:
// case 'priceDiscount':
// template = PRICE_TEMPLATE_DISCOUNT;
// break;
// case PRICE_TEMPLATE_OPTICAL:
// case 'priceOptical':
// template = PRICE_TEMPLATE_OPTICAL;
// break;
// case PRICE_TEMPLATE_STRIKETHROUGH:
// case 'priceStrikethrough':
// template = PRICE_TEMPLATE_STRIKETHROUGH;
// break;
// default:
// break;
// }
return {
...context,
displayOldPrice,
Expand Down
5 changes: 5 additions & 0 deletions test/blocks/merch/merch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import merch, {
PRICE_TEMPLATE_DISCOUNT,
PRICE_TEMPLATE_OPTICAL,
PRICE_TEMPLATE_STRIKETHROUGH,
PRICE_TEMPLATE_ANNUAL,
CHECKOUT_ALLOWED_KEYS,
buildCta,
getCheckoutContext,
Expand Down Expand Up @@ -187,6 +188,10 @@ describe('Merch Block', () => {
await validatePriceSpan('.merch.price.discount', { template: PRICE_TEMPLATE_DISCOUNT });
});

it('renders merch link to annual price', async () => {
await validatePriceSpan('.merch.price.annual', { template: PRICE_TEMPLATE_ANNUAL });
});

it('renders merch link to tax exclusive price with tax exclusive attribute', async () => {
await validatePriceSpan('.merch.price.tax-exclusive', { forceTaxExclusive: 'true' });
});
Expand Down

0 comments on commit 67e152f

Please sign in to comment.