8000 MWPW-169236 [Merch Cards] Support for Volume Discount Flex Promos by bozojovicic · Pull Request #4517 · adobecom/milo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

MWPW-169236 [Merch Cards] Support for Volume Discount Flex Promos #4517

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

Draft
wants to merge 3 commits into
base: stage
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions libs/deps/mas/commerce.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion libs/deps/mas/merch-card.js

Large diffs are not rendered by default.

142 changes: 71 additions & 71 deletions libs/features/mas/dist/mas.js

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions libs/features/mas/src/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CheckoutWorkflowStep } from './constants.js';

import { buildCheckoutUrl } from './buildCheckoutUrl.js';
import { Defaults } from './defaults.js';
import { toOfferSelectorIds, toQuantity } from './utilities.js';
import { toOfferSelectorIds, toQuantity, isPromotionSupported } from './utilities.js';
import { MODAL_TYPE_3_IN_1 } from './constants.js';

/**
Expand Down Expand Up @@ -88,7 +88,8 @@ export function Checkout({ settings }) {
const [{
productArrangementCode,
marketSegments: [offerMarketSegment],
customerSegment: offerCustomerSegment,
customerSegment: offerCustomerSegment,
promotion,
offerType }] = offers;
// cleanup checkoutMarketSegment - not needed
let marketSegment = ms ?? offerMarketSegment ?? checkoutMarketSegment;
Expand All @@ -101,7 +102,7 @@ export function Checkout({ settings }) {
}
const data = {
is3in1,
checkoutPromoCode,
checkoutPromoCode: isPromotionSupported(offers?.[0], options) ? checkoutPromoCode : null,
clientId,
context,
country,
Expand Down
1 change: 1 addition & 0 deletions libs/features/mas/src/inline-price.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export class InlinePrice extends HTMLSpanElement {
'data-display-annual',
'data-perpetual',
'data-promotion-code',
'data-quantity',
'data-force-tax-exclusive',
'data-template',
'data-wcs-osi',
Expand Down
1 change: 1 addition & 0 deletions libs/features/mas/src/merch-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ export class MerchCard extends LitElement {
handleQuantitySelection(event) {
const allLinks = [
...this.checkoutLinks,
...this.prices,
...(this.activeDescriptionLinks ?? []),
];
if (allLinks.length === 0) return;
Expand Down
5 changes: 5 additions & 0 deletions libs/features/mas/src/price/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
formatAnnualPrice,
makeSpacesAroundNonBreaking,
} from './utilities.js';
import { isPromotionSupported } from '../utilities.js';

export const defaultLiterals = {
recurrenceLabel:
Expand Down Expand Up @@ -377,11 +378,13 @@ const createPriceTemplate =
* or outdated promotion), or concatenation of new & old prices, old being stroke through.
*/
const createPromoPriceTemplate = () => (context, value, attributes) => {
const promotionSupported = isPromotionSupported(value, context);
const displayOldPrice =
context.displayOldPrice === undefined ||
toBoolean(context.displayOldPrice);
const shouldDisplayOldPrice =
displayOldPrice &&
promotionSupported &&
value.priceWithoutDiscount &&
value.priceWithoutDiscount != value.price;
return `${shouldDisplayOldPrice
Expand All @@ -394,6 +397,7 @@ const createPromoPriceTemplate = () => (context, value, attributes) => {

const createPromoPriceWithAnnualTemplate =
() => (context, value, attributes) => {
const promotionSupported = isPromotionSupported(value, context);
let { instant } = context;
try {
if (!instant) {
Expand All @@ -418,6 +422,7 @@ const createPromoPriceWithAnnualTemplate =
toBoolean(context.displayOldPrice);
const shouldDisplayOldPrice =
displayOldPrice &&
promotionSupported &&
value.priceWithoutDiscount &&
value.priceWithoutDiscount != value.price;
return `${
Expand Down
14 changes: 14 additions & 0 deletions libs/features/mas/src/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,17 @@ export function getLogHeaders(response) {
}
return logHeaders;
}

/*
* Checks if the promotion is supported based on the offer's minProductQuantity and the selected quantity.
* @param {Offer} offer
* @param {Commerce.Options} options
* @returns {boolean} true if the selected quantity is greater than or equal to the minProductQuantity, false otherwise
*/
export function isPromotionSupported(offer = {}, options = {}) {
F438 const quantity = options.quantity?.[0];
if (!quantity) return true;

const minProductQuantity = offer.promotion?.displaySummary?.minProductQuantity || 1;
return quantity >= minProductQuantity;
}
24 changes: 23 additions & 1 deletion libs/features/mas/test/merch-card.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -832,8 +832,30 @@ <h4 slot="body-xxs">Desktop + Mobile</h4>
</div>
</merch-card>
</div>
</div>

<div class="one-merch-card inline-heading quantity-based-promotion">
<merch-card variant="plans" badge-color="#EDCC2D" badge-background-color="#000000" badge-text=" Best value" secure-label="Secure Transaction" checkbox-label="Add a 30-day free trial of Adobe Stock.*" stock-offer-osis="stock-puf,stock-abm,stock-m2m">
<merch-icon slot="icons" size="l" src="/test/mocks/img/creative-cloud.svg" alt="Creative Cloud All Apps"></merch-icon>
<h4 slot="heading-xs">Creative Cloud All Apps</h4>
<h3 slot="heading-m">
<span is="inline-price" data-promotion-code="TEST_PROMO" data-display-per-unit="false" data-display-recurrence="true" data-display-tax="false" data-wcs-osi="m2m"></span>
</h3>
<p slot="body-xxs" id="individuals2">Desktop</p>
<div slot="body-xs">
<p>Get 20+ Creative Cloud apps including Photoshop, Illustrator, Adobe Express, Premiere Pro, and Acrobat Pro. (Substance 3D apps are not included.)</p>
<p><a href="https://adobe.com">See plans & pricing details</a></p>
</div>
<div slot="quantity-select">
<merch-quantity-select title="Number of licenses" min="1" max="10" step="1" default-value="2" max-input="180"></merch-quantity-select>
</div>
<div slot="footer">
<a is="checkout-link" href="#" class="con-button blue active no-promo" data-wcs-osi="m2m">Save now</a>
<a is="checkout-link" href="#" data-promotion-code="OTHER_TEST_PROMO" class="con-button blue active other-promo" data-wcs-osi="puf">Save now</a>
<a is="checkout-link" href="#" data-promotion-code="TEST_PROMO" class="con-button blue active has-promo" data-wcs-osi="m2m">Save now</a>
</div>
</merch-card>
</div>
</div>
</main>
</body>
</html>
49 changes: 48 additions & 1 deletion libs/features/mas/test/merch-card.test.html.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import { runTests } from '@web/test-runner-mocha';
import { expect } from '@esm-bundle/chai';


import { mockLana } from './mocks/lana.js';
import { mockFetch } from './mocks/fetch.js';

import { delay } from './utils.js';
import { mockIms } from './mocks/ims.js';
import { withWcs } from './mocks/wcs.js';

import { EVENT_MERCH_QUANTITY_SELECTOR_CHANGE } from '../src/constants';

const skipTests = sessionStorage.getItem('skipTests');

runTests(async () => {
Expand Down Expand Up @@ -84,6 +85,52 @@ runTests(async () => {
});
});

it('should support quantity based promotions', async () => {
const card = document.querySelector('.quantity-based-promotion merch-card');
const button = card.querySelector('.con-button.has-promo');
const buttonNoPromo = card.querySelector('.con-button.no-promo');
const buttonOtherPromo = card.querySelector('.con-button.other-promo');
const quantitySelect = card.querySelector('merch-quantity-select');
expect(quantitySelect).to.exist;
await quantitySelect.updateComplete;

expect(card.price.dataset.promotionCode).to.equal('TEST_PROMO');
expect(card.price.querySelector('.price-strikethrough')).not.to.exist;
expect(button.getAttribute('href').includes('&apc=TEST_PROMO')).to.be.false;
expect(buttonNoPromo.getAttribute('href').includes('&apc=')).to.be.false;
expect(buttonOtherPromo.getAttribute('href').includes('&apc=OTHER_TEST_PROMO')).to.be.true;

quantitySelect.dispatchEvent(new CustomEvent(
EVENT_MERCH_QUANTITY_SELECTOR_CHANGE,
{
detail: { option: 4 },
bubbles: true,
},
));

await delay(100);
expect(button.getAttribute('href').includes('&apc=TEST_PROMO')).to.be.true;
expect(buttonNoPromo.getAttribute('href').includes('&apc=')).to.be.false;
expect(buttonOtherPromo.getAttribute('href').includes('&apc=OTHER_TEST_PROMO')).to.be.true;
expect(card.price.dataset.promotionCode).to.equal('TEST_PROMO');
expect(card.price.querySelector('.price-strikethrough')).to.exist;

quantitySelect.dispatchEvent(new CustomEvent(
EVENT_MERCH_QUANTITY_SELECTOR_CHANGE,
{
detail: { option: 2 },
bubbles: true,
},
));

await delay(100);
expect(button.getAttribute('href').includes('&apc=TEST_PROMO')).to.be.false;
expect(buttonNoPromo.getAttribute('href').includes('&apc=')).to.be.false;
expect(buttonOtherPromo.getAttribute('href').includes('&apc=OTHER_TEST_PROMO')).to.be.true;
expect(card.price.dataset.promotionCode).to.equal('TEST_PROMO');
expect(card.price.querySelector('.price-strikethrough')).not.to.exist;
});

it('should return title for segment card', async () => {
const title = document.querySelector(
'merch-card[variant="segment"]',
Expand Down
17 changes: 16 additions & 1 deletion libs/features/mas/test/mocks/offers.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@
"offerId": "257E1D82082387D152029F93C1030624",
"priceDetails": {
"price": 82.49,
"priceWithoutDiscount": 90.88,
"priceWithoutTax": 82.49,
"priceWithoutDiscountAndTax": 90.88,
"usePrecision": true,
"formatString": "'US$'#,##0.00",
"taxDisplay": "TAX_EXCLUSIVE",
Expand All @@ -139,7 +142,19 @@
"offerType": "BASE",
"pricePoint": "REGULAR",
"language": "MULT",
"merchant": "ADOBE"
"merchant": "ADOBE",
"promotion": {
"id": "7d221764-f6c4-461a-9f3b-9674d1a33699",
"promotionCode": "TEST_PROMO",
"start": "2024-04-30T07:00:00.000Z",
"end": "2186-05-01T06:59:00.000Z",
"displaySummary": {
"outcomeType": "PERCENTAGE_DISCOUNT",
"duration": "P1Y",
"amount": 13.0,
"minProductQuantity": 3
}
}
}
],
"20gb-mult": [
Expand Down
Loading
0