Skip to content

Commit

Permalink
🎨 Enable coupon code on all checkout pages (#2000)
Browse files Browse the repository at this point in the history
* 🎨 Enable coupon code on all checkout pages

* ♻️ Refactor Christmas coupon logic into mixin

* 🔥 Remove unused code
  • Loading branch information
AuroraHuang22 authored Dec 23, 2024
1 parent 379423d commit 3fc7944
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 19 deletions.
7 changes: 5 additions & 2 deletions src/components/NFTBook/CrossSellDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ import { getNFTBookPurchaseLink } from '~/util/api';
import { logTrackerEvent, logPurchaseFlowEvent } from '~/util/EventLogger';
import nftOrCollectionMixin from '~/mixins/nft-or-collection';
import couponMixin from '~/mixins/coupon';
export default {
name: 'NFTBookCrossSellDialog',
mixins: [nftOrCollectionMixin],
mixins: [nftOrCollectionMixin, couponMixin],
props: {
open: {
type: Boolean,
Expand Down Expand Up @@ -150,7 +151,9 @@ export default {
{
gaClientId: this.getGaClientId,
gaSessionId: this.getGaSessionId,
coupon: this.$route.query.coupon,
coupon: this.getApplicableCoupon({
checkoutPrice: customPriceInDecimal,
}),
customPriceInDecimal,
utmCampaign: this.utmCampaign,
utmSource: `${this.utmSource}_cross-sell`,
Expand Down
3 changes: 3 additions & 0 deletions src/constant/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,6 @@ export const SEARCH_SUGGESTIONS = [
'信仰',
'邵家臻',
];

export const CHRISTMAS_CAMPAIGN_MIN_SPEND = 9;
export const CHRISTMAS_CAMPAIGN_COUPON = 'XMASREAD';
22 changes: 22 additions & 0 deletions src/mixins/coupon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {
CHRISTMAS_CAMPAIGN_MIN_SPEND,
CHRISTMAS_CAMPAIGN_COUPON,
} from '@/constant/index';

export default {
computed: {
mixinCoupon() {
return this.$route.query.coupon || '';
},
},
methods: {
getApplicableCoupon({ cartCoupon, checkoutPrice }) {
if (this.mixinCoupon || cartCoupon) {
return this.mixinCoupon || cartCoupon;
}
return checkoutPrice > CHRISTMAS_CAMPAIGN_MIN_SPEND
? CHRISTMAS_CAMPAIGN_COUPON
: '';
},
},
};
14 changes: 9 additions & 5 deletions src/pages/nft/class/_classId/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -426,24 +426,25 @@

<script>
import { mapActions, mapGetters } from 'vuex';
import { nftClassCollectionType, parseNFTMetadataURL } from '~/util/nft';
import { getNFTBookPurchaseLink, postNewStripeFiatPayment } from '~/util/api';
import { logTrackerEvent, logPurchaseFlowEvent } from '~/util/EventLogger';
import {
IS_TESTNET,
USD_TO_HKD_RATIO,
EXTERNAL_HOST,
NFT_BOOK_PLATFORM_LIKER_LAND,
LIKECOIN_API_BASE,
LIKECOIN_BUTTON_BASE,
} from '~/constant';
} from '@/constant/index';
import { nftClassCollectionType, parseNFTMetadataURL } from '~/util/nft';
import { getNFTBookPurchaseLink, postNewStripeFiatPayment } from '~/util/api';
import { logTrackerEvent, logPurchaseFlowEvent } from '~/util/EventLogger';
import nftMixin from '~/mixins/nft';
import clipboardMixin from '~/mixins/clipboard';
import crossSellMixin from '~/mixins/cross-sell';
import navigationListenerMixin from '~/mixins/navigation-listener';
import utmMixin from '~/mixins/utm';
import alertMixin from '~/mixins/alert';
import couponMixin from '~/mixins/coupon';
export default {
name: 'NFTClassDetailsPage',
Expand All @@ -454,6 +455,7 @@ export default {
navigationListenerMixin,
utmMixin,
alertMixin,
couponMixin,
],
layout: 'default',
asyncData({ query }) {
Expand Down Expand Up @@ -1424,7 +1426,9 @@ export default {
gaClientId,
gaSessionId,
giftInfo,
coupon: this.$route.query.coupon,
coupon: this.getApplicableCoupon({
checkoutPrice: edition.price,
}),
customPriceInDecimal,
utmCampaign: this.utmCampaign,
utmSource: this.utmSource,
Expand Down
6 changes: 5 additions & 1 deletion src/pages/nft/collection/_collectionId/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ import clipboardMixin from '~/mixins/clipboard';
import navigationListenerMixin from '~/mixins/navigation-listener';
import utmMixin from '~/mixins/utm';
import alertMixin from '~/mixins/alert';
import couponMixin from '~/mixins/coupon';
export default {
name: 'NFTCollectionDetailsPage',
Expand All @@ -120,6 +121,7 @@ export default {
navigationListenerMixin,
utmMixin,
alertMixin,
couponMixin,
],
layout: 'default',
data() {
Expand Down Expand Up @@ -533,7 +535,9 @@ export default {
gaClientId,
giftInfo,
gaSessionId,
coupon: this.$route.query.coupon,
coupon: this.getApplicableCoupon({
checkoutPrice: customPriceInDecimal,
}),
customPriceInDecimal,
utmCampaign: this.utmCampaign,
utmSource: this.utmSource,
Expand Down
17 changes: 6 additions & 11 deletions src/pages/shopping-cart/book.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,14 @@ import { getNFTBookCartPurchaseLink } from '~/util/api';
import nftMixin from '~/mixins/nft';
import alertMixin from '~/mixins/alert';
const CHRISTMAS_CAMPAIGN_MIN_SPEND = 9;
const CHRISTMAS_CAMPAIGN_COUPON = 'XMASREAD';
import couponMixin from '~/mixins/coupon';
export default {
name: 'ShoppingCartPage',
filters: {
formatNumberWithUSD,
},
mixins: [nftMixin, alertMixin],
mixins: [nftMixin, alertMixin, couponMixin],
data() {
return {
isGiftDialogOpen: false,
Expand Down Expand Up @@ -251,12 +249,6 @@ export default {
formattedFiatPrice() {
return formatNumberWithUSD(this.totalNFTPriceInUSD);
},
getApplicableCoupon() {
if (this.coupon) return this.coupon;
return this.totalItemPriceInUSD > CHRISTMAS_CAMPAIGN_MIN_SPEND
? CHRISTMAS_CAMPAIGN_COUPON
: '';
},
},
mounted() {
logPurchaseFlowEvent(this, 'view_cart', this.purchaseEventParams);
Expand Down Expand Up @@ -387,7 +379,10 @@ export default {
fbClickId: this.fbClickId,
items: this.shoppingCartBookItems,
email: this.walletEmail,
coupon: this.getApplicableCoupon,
coupon: this.getApplicableCoupon({
cartCoupon: this.coupon,
checkoutPrice: this.totalNFTPriceInUSD,
}),
giftInfo,
},
{
Expand Down

0 comments on commit 3fc7944

Please sign in to comment.