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 2 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.

112 changes: 56 additions & 56 deletions libs/features/mas/dist/mas.js

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions libs/features/mas/src/checkout-mixin.js
10000
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ export function createCheckoutElement(Class, options = {}, innerHTML = '') {
return element;
}

export function removePromoIfQuantityNotMet(offers, options = {}) {
const quantity = options.quantity?.[0];
if (!quantity) return;

const minProductQuantity = offers?.[0]?.promotion?.displaySummary?.minProductQuantity || 1;
if (quantity < minProductQuantity) {
delete options.promotionCode;
}
}

export function CheckoutMixin(Base) {
return class CheckoutBase extends Base {
/* c8 ignore next 1 */
Expand Down Expand Up @@ -152,6 +162,8 @@ export function CheckoutMixin(Base) {
let offers = await Promise.all(promises);
// offer is expected to contain one or two offers at max (en, mult)
offers = offers.map((offer) => selectOffers(offer, options));

removePromoIfQuantityNotMet(offers.flat(), options);
options.country = this.dataset.imsCountry || options.country;
const checkoutAction = await service.buildCheckoutAction?.(
offers.flat(),
Expand Down
3 changes: 3 additions & 0 deletions libs/features/mas/src/inline-price.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { selectOffers, getService } from './utilities.js';
import { Defaults } from './defaults.js';
import { FF_DEFAULTS } from './constants.js';
import { getParameter } from '@dexter/tacocat-core';
import { removePromoIfQuantityNotMet } from './checkout-mixin';

const INDIVIDUAL = 'INDIVIDUAL_COM';
const BUSINESS = 'TEAM_COM';
Expand Down Expand Up @@ -177,6 +178,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 Expand Up @@ -348,6 +350,7 @@ export class InlinePrice extends HTMLSpanElement {
},
this,
);
removePromoIfQuantityNotMet(offers.flat(), options);
version ??= this.masElement.togglePending(options);
if (offers.length) {
if (this.masElement.toggleResolved(version, offers, options)) {
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
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