From 21a63b65db73622fee0eda84f06c8940b9733bfd Mon Sep 17 00:00:00 2001 From: Guilherme Popolin Date: Wed, 5 Jul 2023 10:08:57 +0200 Subject: [PATCH 1/5] refact(OfferPresenter): hide changes under DISCOUNTS feature flag --- apps/store/.env.local.example | 1 + .../PurchaseForm/OfferPresenter.tsx | 31 ++++++++++--------- apps/store/src/utils/Features.ts | 1 + 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/apps/store/.env.local.example b/apps/store/.env.local.example index 33f3fc6a0b..cdb6eea64b 100644 --- a/apps/store/.env.local.example +++ b/apps/store/.env.local.example @@ -41,6 +41,7 @@ NEXT_PUBLIC_FEATURE_ENGLISH_LANGUAGE=true NEXT_PUBLIC_FEATURE_COUNTRY_SELECTOR=true NEXT_PUBLIC_FEATURE_SAS_PARTNERSHIP=true NEXT_PUBLIC_FEATURE_HOMECOMING=true +NEXT_PUBLIC_FEATURE_DISCOUNTS=true # Vercel Edge Config Connection String (https://github.com/vercel/edge-config) EDGE_CONFIG= diff --git a/apps/store/src/components/ProductPage/PurchaseForm/OfferPresenter.tsx b/apps/store/src/components/ProductPage/PurchaseForm/OfferPresenter.tsx index 22a442d4d9..795c5ef87e 100644 --- a/apps/store/src/components/ProductPage/PurchaseForm/OfferPresenter.tsx +++ b/apps/store/src/components/ProductPage/PurchaseForm/OfferPresenter.tsx @@ -19,6 +19,7 @@ import { PriceIntent } from '@/services/priceIntent/priceIntent.types' import { ShopSession } from '@/services/shopSession/ShopSession.types' import { useTracking } from '@/services/Tracking/useTracking' import { convertToDate } from '@/utils/date' +import { Features } from '@/utils/Features' import { PageLink } from '@/utils/PageLink' import { useGetDiscountExplanation } from '@/utils/useDiscountExplanation' import { useFormatter } from '@/utils/useFormatter' @@ -296,7 +297,7 @@ const useDiscountTooltipProps = ( if (selectedOffer.priceMatch) { const company = selectedOffer.priceMatch.externalInsurer.displayName - if (selectedOffer.priceMatch.priceReduction.amount < 1) { + if (selectedOffer.priceMatch.priceReduction.amount <= 0) { // No price reduction due to incomparable offers const amount = formatter.monthlyPrice(selectedOffer.priceMatch.externalPrice) return { @@ -315,19 +316,21 @@ const useDiscountTooltipProps = ( } as const } - const redeemedCampaign = redeemedCampaigns?.[0] - if (redeemedCampaign && selectedOffer.cost.discount.amount > 0) { - return { - children: getDiscountExplanation({ - ...redeemedCampaign.discount, - amount: selectedOffer.cost.discount, - }), - subtitle: t('DISCOUNT_PRICE_AFTER_EXPIRATION', { - amount: formatter.monthlyPrice(selectedOffer.cost.gross), - ns: 'cart', - }), - color: 'green', - } as const + if (Features.enabled('DISCOUNTS')) { + const redeemedCampaign = redeemedCampaigns?.[0] + if (redeemedCampaign && selectedOffer.cost.discount.amount > 0) { + return { + children: getDiscountExplanation({ + ...redeemedCampaign.discount, + amount: selectedOffer.cost.discount, + }), + subtitle: t('DISCOUNT_PRICE_AFTER_EXPIRATION', { + amount: formatter.monthlyPrice(selectedOffer.cost.gross), + ns: 'cart', + }), + color: 'green', + } as const + } } }, [t, formatter, getDiscountExplanation, selectedOffer, redeemedCampaigns]) diff --git a/apps/store/src/utils/Features.ts b/apps/store/src/utils/Features.ts index 456d810bc7..625e85c501 100644 --- a/apps/store/src/utils/Features.ts +++ b/apps/store/src/utils/Features.ts @@ -14,6 +14,7 @@ const config = { SAS_PARTNERSHIP: process.env.NEXT_PUBLIC_FEATURE_SAS_PARTNERSHIP === 'true', INSURELY_CAR: process.env.NEXT_PUBLIC_FEATURE_INSURELY_CAR === 'true', HOMECOMING: process.env.NEXT_PUBLIC_FEATURE_HOMECOMING === 'true', + DISCOUNTS: process.env.NEXT_PUBLIC_FEATURE_DISCOUNTS === 'true', } as const export type FeatureFlag = keyof typeof config From e9598b635eb40c6194645a46c4d56d138d140d24 Mon Sep 17 00:00:00 2001 From: Guilherme Popolin Date: Wed, 5 Jul 2023 16:25:36 +0200 Subject: [PATCH 2/5] Revert "refact(OfferPresenter): hide changes under DISCOUNTS feature flag" This reverts commit b109c6304f9d35cbbf4a40d2eefeb3fbc71d7ce5. --- apps/store/.env.local.example | 1 - .../PurchaseForm/OfferPresenter.tsx | 31 +++++++++---------- apps/store/src/utils/Features.ts | 1 - 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/apps/store/.env.local.example b/apps/store/.env.local.example index cdb6eea64b..33f3fc6a0b 100644 --- a/apps/store/.env.local.example +++ b/apps/store/.env.local.example @@ -41,7 +41,6 @@ NEXT_PUBLIC_FEATURE_ENGLISH_LANGUAGE=true NEXT_PUBLIC_FEATURE_COUNTRY_SELECTOR=true NEXT_PUBLIC_FEATURE_SAS_PARTNERSHIP=true NEXT_PUBLIC_FEATURE_HOMECOMING=true -NEXT_PUBLIC_FEATURE_DISCOUNTS=true # Vercel Edge Config Connection String (https://github.com/vercel/edge-config) EDGE_CONFIG= diff --git a/apps/store/src/components/ProductPage/PurchaseForm/OfferPresenter.tsx b/apps/store/src/components/ProductPage/PurchaseForm/OfferPresenter.tsx index 795c5ef87e..22a442d4d9 100644 --- a/apps/store/src/components/ProductPage/PurchaseForm/OfferPresenter.tsx +++ b/apps/store/src/components/ProductPage/PurchaseForm/OfferPresenter.tsx @@ -19,7 +19,6 @@ import { PriceIntent } from '@/services/priceIntent/priceIntent.types' import { ShopSession } from '@/services/shopSession/ShopSession.types' import { useTracking } from '@/services/Tracking/useTracking' import { convertToDate } from '@/utils/date' -import { Features } from '@/utils/Features' import { PageLink } from '@/utils/PageLink' import { useGetDiscountExplanation } from '@/utils/useDiscountExplanation' import { useFormatter } from '@/utils/useFormatter' @@ -297,7 +296,7 @@ const useDiscountTooltipProps = ( if (selectedOffer.priceMatch) { const company = selectedOffer.priceMatch.externalInsurer.displayName - if (selectedOffer.priceMatch.priceReduction.amount <= 0) { + if (selectedOffer.priceMatch.priceReduction.amount < 1) { // No price reduction due to incomparable offers const amount = formatter.monthlyPrice(selectedOffer.priceMatch.externalPrice) return { @@ -316,21 +315,19 @@ const useDiscountTooltipProps = ( } as const } - if (Features.enabled('DISCOUNTS')) { - const redeemedCampaign = redeemedCampaigns?.[0] - if (redeemedCampaign && selectedOffer.cost.discount.amount > 0) { - return { - children: getDiscountExplanation({ - ...redeemedCampaign.discount, - amount: selectedOffer.cost.discount, - }), - subtitle: t('DISCOUNT_PRICE_AFTER_EXPIRATION', { - amount: formatter.monthlyPrice(selectedOffer.cost.gross), - ns: 'cart', - }), - color: 'green', - } as const - } + const redeemedCampaign = redeemedCampaigns?.[0] + if (redeemedCampaign && selectedOffer.cost.discount.amount > 0) { + return { + children: getDiscountExplanation({ + ...redeemedCampaign.discount, + amount: selectedOffer.cost.discount, + }), + subtitle: t('DISCOUNT_PRICE_AFTER_EXPIRATION', { + amount: formatter.monthlyPrice(selectedOffer.cost.gross), + ns: 'cart', + }), + color: 'green', + } as const } }, [t, formatter, getDiscountExplanation, selectedOffer, redeemedCampaigns]) diff --git a/apps/store/src/utils/Features.ts b/apps/store/src/utils/Features.ts index 625e85c501..456d810bc7 100644 --- a/apps/store/src/utils/Features.ts +++ b/apps/store/src/utils/Features.ts @@ -14,7 +14,6 @@ const config = { SAS_PARTNERSHIP: process.env.NEXT_PUBLIC_FEATURE_SAS_PARTNERSHIP === 'true', INSURELY_CAR: process.env.NEXT_PUBLIC_FEATURE_INSURELY_CAR === 'true', HOMECOMING: process.env.NEXT_PUBLIC_FEATURE_HOMECOMING === 'true', - DISCOUNTS: process.env.NEXT_PUBLIC_FEATURE_DISCOUNTS === 'true', } as const export type FeatureFlag = keyof typeof config From 9bfae66c6f86ed4da98d035f6ef21d4ba75db5b4 Mon Sep 17 00:00:00 2001 From: Guilherme Popolin Date: Wed, 5 Jul 2023 11:07:11 +0200 Subject: [PATCH 3/5] refact: remove references for offer.price field over offer.cost --- .../CartEntryItem/CartEntryCollapsible.tsx | 17 ++++++++++++++--- .../CartEntryItem/CartEntryItem.tsx | 4 +--- .../CartInventory/CartEntryOfferItem.tsx | 12 +++++++++++- .../CartInventory/CartInventory.helpers.tsx | 2 +- .../components/CartInventory/CartInventory.tsx | 2 +- .../CartInventory/CartInventory.types.ts | 4 ++-- .../PurchaseForm/DeductibleSelector.tsx | 2 +- .../PurchaseForm/ProductTierSelector.tsx | 2 +- .../ProductPage/PurchaseForm/PurchaseForm.tsx | 2 +- .../PurchaseForm/getOffersByPrice.ts | 4 ++-- .../graphql/OfferRecommendationFragment.graphql | 16 +++++++++++++--- .../src/graphql/ProductOfferFragment.graphql | 4 ---- apps/store/src/services/Tracking/Tracking.ts | 14 +++++++------- 13 files changed, 55 insertions(+), 30 deletions(-) diff --git a/apps/store/src/components/CartInventory/CartEntryItem/CartEntryCollapsible.tsx b/apps/store/src/components/CartInventory/CartEntryItem/CartEntryCollapsible.tsx index b486e7c17b..1ab3cac5ce 100644 --- a/apps/store/src/components/CartInventory/CartEntryItem/CartEntryCollapsible.tsx +++ b/apps/store/src/components/CartInventory/CartEntryItem/CartEntryCollapsible.tsx @@ -4,12 +4,17 @@ import { motion } from 'framer-motion' import { useTranslation } from 'next-i18next' import React, { ReactNode, useState } from 'react' import { ChevronIcon, Text, theme } from 'ui' +import { ProductOfferFragment } from '@/services/apollo/generated' +import { useFormatter } from '@/utils/useFormatter' -type Props = { defaultOpen: boolean; price: string; children: ReactNode } +type Props = { defaultOpen: boolean; cost: ProductOfferFragment['cost']; children: ReactNode } -export const CartEntryCollapsible = ({ defaultOpen, price, children }: Props) => { +export const CartEntryCollapsible = ({ defaultOpen, cost, children }: Props) => { const [open, setOpen] = useState(defaultOpen) const { t } = useTranslation('cart') + const formatter = useFormatter() + + const hasDiscountApplied = cost.discount.amount > 0 return ( @@ -19,7 +24,12 @@ export const CartEntryCollapsible = ({ defaultOpen, price, children }: Props) => - {price} + {hasDiscountApplied && ( + + {formatter.monthlyPrice(cost.gross)} + + )} + {formatter.monthlyPrice(cost.net)} @@ -56,6 +66,7 @@ const PriceFlex = styled.div({ display: 'flex', alignItems: 'center', height: '100%', + gap: theme.space.xs, }) const Trigger = styled(Collapsible.Trigger)({ diff --git a/apps/store/src/components/CartInventory/CartEntryItem/CartEntryItem.tsx b/apps/store/src/components/CartInventory/CartEntryItem/CartEntryItem.tsx index 0fd58b595d..71163fa4d6 100644 --- a/apps/store/src/components/CartInventory/CartEntryItem/CartEntryItem.tsx +++ b/apps/store/src/components/CartInventory/CartEntryItem/CartEntryItem.tsx @@ -5,7 +5,6 @@ import { useEditProductOffer } from '@/components/CartPage/useEditProductOffer' import { Pillow } from '@/components/Pillow/Pillow' import { SpaceFlex } from '@/components/SpaceFlex/SpaceFlex' import { CartFragmentFragment } from '@/services/apollo/generated' -import { useFormatter } from '@/utils/useFormatter' import { CartEntry } from '../CartInventory.types' import { RemoveEntryDialog } from '../RemoveEntryDialog' import { CartEntryCollapsible } from './CartEntryCollapsible' @@ -24,7 +23,6 @@ export const CartEntryItem = ({ defaultOpen = false, ...props }: Props) => { const { shopSessionId, readOnly, onRemove, ...cartEntry } = props const { title: titleLabel, cost, pillow } = cartEntry const { t } = useTranslation('cart') - const formatter = useFormatter() const [editProductOffer, editState] = useEditProductOffer() const handleConfirmEdit = () => { @@ -51,7 +49,7 @@ export const CartEntryItem = ({ defaultOpen = false, ...props }: Props) => { - + diff --git a/apps/store/src/components/CartInventory/CartEntryOfferItem.tsx b/apps/store/src/components/CartInventory/CartEntryOfferItem.tsx index 4498cda57a..77f4018b60 100644 --- a/apps/store/src/components/CartInventory/CartEntryOfferItem.tsx +++ b/apps/store/src/components/CartInventory/CartEntryOfferItem.tsx @@ -53,6 +53,8 @@ export const CartEntryOfferItem = ({ shopSessionId, product, offer }: CartOfferI if (!show) return null + const hasDiscountApplied = offer.cost.discount.amount > 0 + return ( @@ -95,7 +97,14 @@ export const CartEntryOfferItem = ({ shopSessionId, product, offer }: CartOfferI - {formatter.monthlyPrice(offer.price)} + + {hasDiscountApplied && ( + + {formatter.monthlyPrice(offer.cost.gross)} + + )} + {formatter.monthlyPrice(offer.cost.net)} + ) } @@ -142,6 +151,7 @@ const Layout = { gridArea: GRID_AREAS.Price, display: 'flex', alignItems: 'center', + gap: theme.space.xs, }), Content: styled.div({ gridArea: GRID_AREAS.Content }), Actions: styled.div({ gridArea: GRID_AREAS.Actions }), diff --git a/apps/store/src/components/CartInventory/CartInventory.helpers.tsx b/apps/store/src/components/CartInventory/CartInventory.helpers.tsx index e853d34279..e4fd5e8e50 100644 --- a/apps/store/src/components/CartInventory/CartInventory.helpers.tsx +++ b/apps/store/src/components/CartInventory/CartInventory.helpers.tsx @@ -60,7 +60,7 @@ export const getCartEntry = (item: ShopSession['cart']['entries'][number]): Cart return { offerId: item.id, title: item.variant.product.displayNameFull, - cost: item.price, + cost: item.cost, startDate: hasCancellation ? undefined : convertToDate(item.startDate), pillow: { src: item.variant.product.pillowImage.src, diff --git a/apps/store/src/components/CartInventory/CartInventory.tsx b/apps/store/src/components/CartInventory/CartInventory.tsx index 0b072e3774..8492baf3a1 100644 --- a/apps/store/src/components/CartInventory/CartInventory.tsx +++ b/apps/store/src/components/CartInventory/CartInventory.tsx @@ -43,7 +43,7 @@ export const CartInventory = ({ shopSessionId, cart, readOnly = false }: Props) key={item.id} offerId={item.id} title={item.variant.product.displayNameFull} - cost={item.price} + cost={item.cost} pillow={{ src: item.variant.product.pillowImage.src, alt: item.variant.product.pillowImage.alt ?? '', diff --git a/apps/store/src/components/CartInventory/CartInventory.types.ts b/apps/store/src/components/CartInventory/CartInventory.types.ts index 4b9f7521da..9e522d1e6e 100644 --- a/apps/store/src/components/CartInventory/CartInventory.types.ts +++ b/apps/store/src/components/CartInventory/CartInventory.types.ts @@ -1,10 +1,10 @@ -import { CartFragmentFragment } from '@/services/apollo/generated' +import { CartFragmentFragment, ProductOfferFragment } from '@/services/apollo/generated' import { Money } from '@/utils/formatter' export type CartEntry = { offerId: string title: string - cost: Money + cost: ProductOfferFragment['cost'] startDate?: Date | null pillow: { src: string; alt?: string } documents: CartFragmentFragment['entries'][number]['variant']['documents'] diff --git a/apps/store/src/components/ProductPage/PurchaseForm/DeductibleSelector.tsx b/apps/store/src/components/ProductPage/PurchaseForm/DeductibleSelector.tsx index 34b6376a40..a0cbc28acf 100644 --- a/apps/store/src/components/ProductPage/PurchaseForm/DeductibleSelector.tsx +++ b/apps/store/src/components/ProductPage/PurchaseForm/DeductibleSelector.tsx @@ -37,7 +37,7 @@ export const DeductibleSelector = ({ offers, selectedOffer, onValueChange }: Pro if (offer.deductible) { levels.push({ id: offer.id, - price: offer.price, + price: offer.cost.net, title: offer.deductible.displayName, description: offer.deductible.tagline, }) diff --git a/apps/store/src/components/ProductPage/PurchaseForm/ProductTierSelector.tsx b/apps/store/src/components/ProductPage/PurchaseForm/ProductTierSelector.tsx index ea2ad714dd..720181d9e7 100644 --- a/apps/store/src/components/ProductPage/PurchaseForm/ProductTierSelector.tsx +++ b/apps/store/src/components/ProductPage/PurchaseForm/ProductTierSelector.tsx @@ -31,7 +31,7 @@ export const ProductTierSelector = ({ offers, selectedOffer, onValueChange }: Pr key={offer.id} value={offer.id} title={offer.variant.displayName} - price={formatter.monthlyPrice(offer.price)} + price={formatter.monthlyPrice(offer.cost.net)} description={getVariantDescription(offer.variant.typeOfContract)} /> ))} diff --git a/apps/store/src/components/ProductPage/PurchaseForm/PurchaseForm.tsx b/apps/store/src/components/ProductPage/PurchaseForm/PurchaseForm.tsx index 6fd2bb71ba..6b61afae03 100644 --- a/apps/store/src/components/ProductPage/PurchaseForm/PurchaseForm.tsx +++ b/apps/store/src/components/ProductPage/PurchaseForm/PurchaseForm.tsx @@ -199,7 +199,7 @@ export const PurchaseForm = () => { notifyProductAdded({ name: productData.displayNameFull, - price: formatter.monthlyPrice(item.price), + price: formatter.monthlyPrice(item.cost.net), pillowSrc: productData.pillowImage.src, description: !item.cancellation.requested || diff --git a/apps/store/src/components/ProductPage/PurchaseForm/getOffersByPrice.ts b/apps/store/src/components/ProductPage/PurchaseForm/getOffersByPrice.ts index 49f8e59ca6..5f4686d32c 100644 --- a/apps/store/src/components/ProductPage/PurchaseForm/getOffersByPrice.ts +++ b/apps/store/src/components/ProductPage/PurchaseForm/getOffersByPrice.ts @@ -2,8 +2,8 @@ import { ProductOfferFragment } from '@/services/apollo/generated' export const getOffersByPrice = (offers: Array) => { return [...offers].sort((a, b) => { - if (a.price.amount < b.price.amount) return -1 - if (a.price.amount > b.price.amount) return 1 + if (a.cost.net.amount < b.cost.net.amount) return -1 + if (a.cost.net.amount > b.cost.net.amount) return 1 return 0 }) } diff --git a/apps/store/src/graphql/OfferRecommendationFragment.graphql b/apps/store/src/graphql/OfferRecommendationFragment.graphql index cdd321e4d7..271f6cb976 100644 --- a/apps/store/src/graphql/OfferRecommendationFragment.graphql +++ b/apps/store/src/graphql/OfferRecommendationFragment.graphql @@ -9,8 +9,18 @@ fragment OfferRecommendation on ProductOffer { displayNameFull } } - price { - amount - currencyCode + cost { + gross { + amount + currencyCode + } + net { + amount + currencyCode + } + discount { + amount + currencyCode + } } } diff --git a/apps/store/src/graphql/ProductOfferFragment.graphql b/apps/store/src/graphql/ProductOfferFragment.graphql index 26c08f7d89..a49a688292 100644 --- a/apps/store/src/graphql/ProductOfferFragment.graphql +++ b/apps/store/src/graphql/ProductOfferFragment.graphql @@ -22,10 +22,6 @@ fragment ProductOffer on ProductOffer { url } } - price { - amount - currencyCode - } cost { gross { amount diff --git a/apps/store/src/services/Tracking/Tracking.ts b/apps/store/src/services/Tracking/Tracking.ts index 9153aa7da9..7935a9503a 100644 --- a/apps/store/src/services/Tracking/Tracking.ts +++ b/apps/store/src/services/Tracking/Tracking.ts @@ -20,7 +20,7 @@ type TrackingProductData = { } type TrackingOffer = { - price: ProductOfferFragment['price'] + cost: ProductOfferFragment['cost'] variant: { typeOfContract: ProductOfferFragment['variant']['typeOfContract'] product: { @@ -140,8 +140,8 @@ export class Tracking { const userData = await getLegacyUserData(this.context) const eventData = { offerData: { - insurance_price: offer.price.amount, - currency: offer.price.currencyCode as string, + insurance_price: offer.cost.gross.amount, + currency: offer.cost.gross.currencyCode as string, insurance_type: offer.variant.typeOfContract, flow_type: offer.variant.product.name, @@ -304,13 +304,13 @@ const offerToEcommerceEvent = ({ return { event, ecommerce: { - value: offer.price.amount, - currency: offer.price.currencyCode, + value: offer.cost.gross.amount, + currency: offer.cost.gross.currencyCode, items: [ { item_id: offer.variant.product.id, item_name: offer.variant.product.displayNameFull, - price: offer.price.amount, + price: offer.cost.gross.amount, item_variant: offer.variant.typeOfContract, ...(source && { item_list_id: source }), }, @@ -341,7 +341,7 @@ const cartToEcommerceEvent = ( items: cart.entries.map((entry) => ({ item_id: entry.variant.product.id, item_name: entry.variant.product.displayNameFull, - price: entry.price.amount, + price: entry.cost.gross.amount, variant: entry.variant.typeOfContract, })), }, From 33b65545d0505c9ca29dce0acdf1047a65dc2049 Mon Sep 17 00:00:00 2001 From: Guilherme Popolin Date: Wed, 5 Jul 2023 16:00:25 +0200 Subject: [PATCH 4/5] refact: hide discount related changed under DISCOUNTS feature flag --- .../CartEntryItem/CartEntryCollapsible.tsx | 22 +++++++++----- .../CartEntryItem/CartEntryItem.tsx | 4 +-- .../CartInventory/CartEntryOfferItem.tsx | 9 +++--- .../CartInventory/CartInventory.helpers.tsx | 1 + .../CartInventory/CartInventory.tsx | 1 + .../CartInventory/CartInventory.types.ts | 1 + .../PurchaseForm/DeductibleSelector.tsx | 4 ++- .../PurchaseForm/ProductTierSelector.tsx | 22 ++++++++------ .../ProductPage/PurchaseForm/PurchaseForm.tsx | 4 ++- .../PurchaseForm/getOffersByPrice.ts | 19 ++++++++---- .../OfferRecommendationFragment.graphql | 4 +++ .../src/graphql/ProductOfferFragment.graphql | 4 +++ apps/store/src/services/Tracking/Tracking.ts | 30 ++++++++++++------- 13 files changed, 85 insertions(+), 40 deletions(-) diff --git a/apps/store/src/components/CartInventory/CartEntryItem/CartEntryCollapsible.tsx b/apps/store/src/components/CartInventory/CartEntryItem/CartEntryCollapsible.tsx index 1ab3cac5ce..a3af3f464b 100644 --- a/apps/store/src/components/CartInventory/CartEntryItem/CartEntryCollapsible.tsx +++ b/apps/store/src/components/CartInventory/CartEntryItem/CartEntryCollapsible.tsx @@ -4,18 +4,22 @@ import { motion } from 'framer-motion' import { useTranslation } from 'next-i18next' import React, { ReactNode, useState } from 'react' import { ChevronIcon, Text, theme } from 'ui' -import { ProductOfferFragment } from '@/services/apollo/generated' +import type { Money, ProductOfferFragment } from '@/services/apollo/generated' +import { Features } from '@/utils/Features' import { useFormatter } from '@/utils/useFormatter' -type Props = { defaultOpen: boolean; cost: ProductOfferFragment['cost']; children: ReactNode } +type Props = { + defaultOpen: boolean + price: Money + cost: ProductOfferFragment['cost'] + children: ReactNode +} -export const CartEntryCollapsible = ({ defaultOpen, cost, children }: Props) => { +export const CartEntryCollapsible = ({ defaultOpen, price, cost, children }: Props) => { const [open, setOpen] = useState(defaultOpen) const { t } = useTranslation('cart') const formatter = useFormatter() - const hasDiscountApplied = cost.discount.amount > 0 - return ( @@ -24,12 +28,16 @@ export const CartEntryCollapsible = ({ defaultOpen, cost, children }: Props) => - {hasDiscountApplied && ( + {Features.enabled('DISCOUNTS') && cost.discount.amount > 0 && ( {formatter.monthlyPrice(cost.gross)} )} - {formatter.monthlyPrice(cost.net)} + + {Features.enabled('DISCOUNTS') + ? formatter.monthlyPrice(cost.net) + : formatter.monthlyPrice(price)} + diff --git a/apps/store/src/components/CartInventory/CartEntryItem/CartEntryItem.tsx b/apps/store/src/components/CartInventory/CartEntryItem/CartEntryItem.tsx index 71163fa4d6..8ffceb4ef7 100644 --- a/apps/store/src/components/CartInventory/CartEntryItem/CartEntryItem.tsx +++ b/apps/store/src/components/CartInventory/CartEntryItem/CartEntryItem.tsx @@ -21,7 +21,7 @@ type Props = CartEntry & { export const CartEntryItem = ({ defaultOpen = false, ...props }: Props) => { const { shopSessionId, readOnly, onRemove, ...cartEntry } = props - const { title: titleLabel, cost, pillow } = cartEntry + const { title: titleLabel, price, cost, pillow } = cartEntry const { t } = useTranslation('cart') const [editProductOffer, editState] = useEditProductOffer() @@ -49,7 +49,7 @@ export const CartEntryItem = ({ defaultOpen = false, ...props }: Props) => { - + diff --git a/apps/store/src/components/CartInventory/CartEntryOfferItem.tsx b/apps/store/src/components/CartInventory/CartEntryOfferItem.tsx index 77f4018b60..950410f97c 100644 --- a/apps/store/src/components/CartInventory/CartEntryOfferItem.tsx +++ b/apps/store/src/components/CartInventory/CartEntryOfferItem.tsx @@ -15,6 +15,7 @@ import { ProductRecommendationFragment, } from '@/services/apollo/generated' import { useTracking } from '@/services/Tracking/useTracking' +import { Features } from '@/utils/Features' import { useFormatter } from '@/utils/useFormatter' type CartOfferItemProps = { @@ -53,8 +54,6 @@ export const CartEntryOfferItem = ({ shopSessionId, product, offer }: CartOfferI if (!show) return null - const hasDiscountApplied = offer.cost.discount.amount > 0 - return ( @@ -98,12 +97,14 @@ export const CartEntryOfferItem = ({ shopSessionId, product, offer }: CartOfferI - {hasDiscountApplied && ( + {Features.enabled('DISCOUNTS') && offer.cost.discount.amount > 0 && ( {formatter.monthlyPrice(offer.cost.gross)} )} - {formatter.monthlyPrice(offer.cost.net)} + {Features.enabled('DISCOUNTS') + ? formatter.monthlyPrice(offer.cost.net) + : formatter.monthlyPrice(offer.price)} ) diff --git a/apps/store/src/components/CartInventory/CartInventory.helpers.tsx b/apps/store/src/components/CartInventory/CartInventory.helpers.tsx index e4fd5e8e50..afb55ea46c 100644 --- a/apps/store/src/components/CartInventory/CartInventory.helpers.tsx +++ b/apps/store/src/components/CartInventory/CartInventory.helpers.tsx @@ -60,6 +60,7 @@ export const getCartEntry = (item: ShopSession['cart']['entries'][number]): Cart return { offerId: item.id, title: item.variant.product.displayNameFull, + price: item.price, cost: item.cost, startDate: hasCancellation ? undefined : convertToDate(item.startDate), pillow: { diff --git a/apps/store/src/components/CartInventory/CartInventory.tsx b/apps/store/src/components/CartInventory/CartInventory.tsx index 8492baf3a1..1c51b21857 100644 --- a/apps/store/src/components/CartInventory/CartInventory.tsx +++ b/apps/store/src/components/CartInventory/CartInventory.tsx @@ -43,6 +43,7 @@ export const CartInventory = ({ shopSessionId, cart, readOnly = false }: Props) key={item.id} offerId={item.id} title={item.variant.product.displayNameFull} + price={item.price} cost={item.cost} pillow={{ src: item.variant.product.pillowImage.src, diff --git a/apps/store/src/components/CartInventory/CartInventory.types.ts b/apps/store/src/components/CartInventory/CartInventory.types.ts index 9e522d1e6e..080d241bcb 100644 --- a/apps/store/src/components/CartInventory/CartInventory.types.ts +++ b/apps/store/src/components/CartInventory/CartInventory.types.ts @@ -4,6 +4,7 @@ import { Money } from '@/utils/formatter' export type CartEntry = { offerId: string title: string + price: Money cost: ProductOfferFragment['cost'] startDate?: Date | null pillow: { src: string; alt?: string } diff --git a/apps/store/src/components/ProductPage/PurchaseForm/DeductibleSelector.tsx b/apps/store/src/components/ProductPage/PurchaseForm/DeductibleSelector.tsx index a0cbc28acf..ca62e53a84 100644 --- a/apps/store/src/components/ProductPage/PurchaseForm/DeductibleSelector.tsx +++ b/apps/store/src/components/ProductPage/PurchaseForm/DeductibleSelector.tsx @@ -8,6 +8,7 @@ import { FormElement } from '@/components/ProductPage/PurchaseForm/PurchaseForm. import * as TierLevelRadioGroup from '@/components/TierSelector/TierLevelRadioGroup' import * as TierSelector from '@/components/TierSelector/TierSelector' import { Money, ProductOfferFragment } from '@/services/apollo/generated' +import { Features } from '@/utils/Features' import { useCurrentLocale } from '@/utils/l10n/useCurrentLocale' import { PageLink } from '@/utils/PageLink' import { useFormatter } from '@/utils/useFormatter' @@ -35,9 +36,10 @@ export const DeductibleSelector = ({ offers, selectedOffer, onValueChange }: Pro offers.forEach((offer) => { if (offer.deductible) { + const price = Features.enabled('DISCOUNTS') ? offer.cost.net : offer.price levels.push({ id: offer.id, - price: offer.cost.net, + price, title: offer.deductible.displayName, description: offer.deductible.tagline, }) diff --git a/apps/store/src/components/ProductPage/PurchaseForm/ProductTierSelector.tsx b/apps/store/src/components/ProductPage/PurchaseForm/ProductTierSelector.tsx index 720181d9e7..d2194d373b 100644 --- a/apps/store/src/components/ProductPage/PurchaseForm/ProductTierSelector.tsx +++ b/apps/store/src/components/ProductPage/PurchaseForm/ProductTierSelector.tsx @@ -4,6 +4,7 @@ import { Text } from 'ui' import * as TierLevelRadioGroup from '@/components/TierSelector/TierLevelRadioGroup' import * as TierSelector from '@/components/TierSelector/TierSelector' import { ProductOfferFragment } from '@/services/apollo/generated' +import { Features } from '@/utils/Features' import { useFormatter } from '@/utils/useFormatter' type Props = { @@ -26,15 +27,18 @@ export const ProductTierSelector = ({ offers, selectedOffer, onValueChange }: Pr - {offers.map((offer) => ( - - ))} + {offers.map((offer) => { + const price = Features.enabled('DISCOUNTS') ? offer.cost.net : offer.price + return ( + + ) + })} diff --git a/apps/store/src/components/ProductPage/PurchaseForm/PurchaseForm.tsx b/apps/store/src/components/ProductPage/PurchaseForm/PurchaseForm.tsx index 6b61afae03..90c8fa6281 100644 --- a/apps/store/src/components/ProductPage/PurchaseForm/PurchaseForm.tsx +++ b/apps/store/src/components/ProductPage/PurchaseForm/PurchaseForm.tsx @@ -30,6 +30,7 @@ import { useShopSession } from '@/services/shopSession/ShopSessionContext' import { TrackingContextKey } from '@/services/Tracking/Tracking' import { useTracking } from '@/services/Tracking/useTracking' import { sendDialogEvent } from '@/utils/dialogEvent' +import { Features } from '@/utils/Features' import { useBreakpoint } from '@/utils/useBreakpoint/useBreakpoint' import { useFormatter } from '@/utils/useFormatter' import { ScrollPast } from '../ScrollPast/ScrollPast' @@ -197,9 +198,10 @@ export const PurchaseForm = () => { return await router.push(nextUrl) } + const price = Features.enabled('DISCOUNTS') ? item.cost.net : item.price notifyProductAdded({ name: productData.displayNameFull, - price: formatter.monthlyPrice(item.cost.net), + price: formatter.monthlyPrice(price), pillowSrc: productData.pillowImage.src, description: !item.cancellation.requested || diff --git a/apps/store/src/components/ProductPage/PurchaseForm/getOffersByPrice.ts b/apps/store/src/components/ProductPage/PurchaseForm/getOffersByPrice.ts index 5f4686d32c..e5c9668bf1 100644 --- a/apps/store/src/components/ProductPage/PurchaseForm/getOffersByPrice.ts +++ b/apps/store/src/components/ProductPage/PurchaseForm/getOffersByPrice.ts @@ -1,9 +1,18 @@ import { ProductOfferFragment } from '@/services/apollo/generated' +import { Features } from '@/utils/Features' export const getOffersByPrice = (offers: Array) => { - return [...offers].sort((a, b) => { - if (a.cost.net.amount < b.cost.net.amount) return -1 - if (a.cost.net.amount > b.cost.net.amount) return 1 - return 0 - }) + return [...offers].sort(Features.enabled('DISCOUNTS') ? sortByCost : sortByPrice) +} + +const sortByCost = (a: ProductOfferFragment, b: ProductOfferFragment) => { + if (a.cost.net.amount < b.cost.net.amount) return -1 + if (a.cost.net.amount > b.cost.net.amount) return 1 + return 0 +} + +const sortByPrice = (a: ProductOfferFragment, b: ProductOfferFragment) => { + if (a.price.amount < b.price.amount) return -1 + if (a.price.amount > b.price.amount) return 1 + return 0 } diff --git a/apps/store/src/graphql/OfferRecommendationFragment.graphql b/apps/store/src/graphql/OfferRecommendationFragment.graphql index 271f6cb976..2f4f10e9f9 100644 --- a/apps/store/src/graphql/OfferRecommendationFragment.graphql +++ b/apps/store/src/graphql/OfferRecommendationFragment.graphql @@ -9,6 +9,10 @@ fragment OfferRecommendation on ProductOffer { displayNameFull } } + price { + amount + currencyCode + } cost { gross { amount diff --git a/apps/store/src/graphql/ProductOfferFragment.graphql b/apps/store/src/graphql/ProductOfferFragment.graphql index a49a688292..26c08f7d89 100644 --- a/apps/store/src/graphql/ProductOfferFragment.graphql +++ b/apps/store/src/graphql/ProductOfferFragment.graphql @@ -22,6 +22,10 @@ fragment ProductOffer on ProductOffer { url } } + price { + amount + currencyCode + } cost { gross { amount diff --git a/apps/store/src/services/Tracking/Tracking.ts b/apps/store/src/services/Tracking/Tracking.ts index 7935a9503a..e0c823edbd 100644 --- a/apps/store/src/services/Tracking/Tracking.ts +++ b/apps/store/src/services/Tracking/Tracking.ts @@ -10,6 +10,7 @@ import { } from '@/services/gtm' import { PriceIntent } from '@/services/priceIntent/priceIntent.types' import { ShopSession } from '@/services/shopSession/ShopSession.types' +import { Features } from '@/utils/Features' import { getAdtractionProductCategories } from './adtraction' type TrackingContext = Partial> @@ -20,6 +21,7 @@ type TrackingProductData = { } type TrackingOffer = { + price: ProductOfferFragment['price'] cost: ProductOfferFragment['cost'] variant: { typeOfContract: ProductOfferFragment['variant']['typeOfContract'] @@ -138,10 +140,11 @@ export class Tracking { public async reportOfferCreated(offer: ProductOfferFragment) { const event = TrackingEvent.OfferCreated const userData = await getLegacyUserData(this.context) + const price = Features.enabled('DISCOUNTS') ? offer.cost.gross : offer.price const eventData = { offerData: { - insurance_price: offer.cost.gross.amount, - currency: offer.cost.gross.currencyCode as string, + insurance_price: price.amount, + currency: price.currencyCode as string, insurance_type: offer.variant.typeOfContract, flow_type: offer.variant.product.name, @@ -301,16 +304,17 @@ const offerToEcommerceEvent = ({ context, source, }: OfferToEcommerseEventParams): EcommerceEvent => { + const price = Features.enabled('DISCOUNTS') ? offer.cost.gross : offer.price return { event, ecommerce: { - value: offer.cost.gross.amount, - currency: offer.cost.gross.currencyCode, + value: price.amount, + currency: price.currencyCode, items: [ { item_id: offer.variant.product.id, item_name: offer.variant.product.displayNameFull, - price: offer.cost.gross.amount, + price: price.amount, item_variant: offer.variant.typeOfContract, ...(source && { item_list_id: source }), }, @@ -338,12 +342,16 @@ const cartToEcommerceEvent = ( ecommerce: { value: cart.cost.net.amount, currency: cart.cost.net.currencyCode, - items: cart.entries.map((entry) => ({ - item_id: entry.variant.product.id, - item_name: entry.variant.product.displayNameFull, - price: entry.cost.gross.amount, - variant: entry.variant.typeOfContract, - })), + items: cart.entries.map((entry) => { + const price = Features.enabled('DISCOUNTS') ? entry.cost.gross : entry.price + + return { + item_id: entry.variant.product.id, + item_name: entry.variant.product.displayNameFull, + price: price.amount, + variant: entry.variant.typeOfContract, + } + }), }, shopSession: { id: context[TrackingContextKey.ShopSessionId] as string, From 87fad7a339eba3b7d2e726005a72ffad7528baef Mon Sep 17 00:00:00 2001 From: Guilherme Popolin Date: Wed, 5 Jul 2023 16:29:12 +0200 Subject: [PATCH 5/5] Revert "refact: hide discount related changed under DISCOUNTS feature flag" This reverts commit e2c978cac9f93d3bf18fb08c6c7d6bdfb26ba960. --- .../CartEntryItem/CartEntryCollapsible.tsx | 22 +++++--------- .../CartEntryItem/CartEntryItem.tsx | 4 +-- .../CartInventory/CartEntryOfferItem.tsx | 9 +++--- .../CartInventory/CartInventory.helpers.tsx | 1 - .../CartInventory/CartInventory.tsx | 1 - .../CartInventory/CartInventory.types.ts | 1 - .../PurchaseForm/DeductibleSelector.tsx | 4 +-- .../PurchaseForm/ProductTierSelector.tsx | 22 ++++++-------- .../ProductPage/PurchaseForm/PurchaseForm.tsx | 4 +-- .../PurchaseForm/getOffersByPrice.ts | 19 ++++-------- .../OfferRecommendationFragment.graphql | 4 --- .../src/graphql/ProductOfferFragment.graphql | 4 --- apps/store/src/services/Tracking/Tracking.ts | 30 +++++++------------ 13 files changed, 40 insertions(+), 85 deletions(-) diff --git a/apps/store/src/components/CartInventory/CartEntryItem/CartEntryCollapsible.tsx b/apps/store/src/components/CartInventory/CartEntryItem/CartEntryCollapsible.tsx index a3af3f464b..1ab3cac5ce 100644 --- a/apps/store/src/components/CartInventory/CartEntryItem/CartEntryCollapsible.tsx +++ b/apps/store/src/components/CartInventory/CartEntryItem/CartEntryCollapsible.tsx @@ -4,22 +4,18 @@ import { motion } from 'framer-motion' import { useTranslation } from 'next-i18next' import React, { ReactNode, useState } from 'react' import { ChevronIcon, Text, theme } from 'ui' -import type { Money, ProductOfferFragment } from '@/services/apollo/generated' -import { Features } from '@/utils/Features' +import { ProductOfferFragment } from '@/services/apollo/generated' import { useFormatter } from '@/utils/useFormatter' -type Props = { - defaultOpen: boolean - price: Money - cost: ProductOfferFragment['cost'] - children: ReactNode -} +type Props = { defaultOpen: boolean; cost: ProductOfferFragment['cost']; children: ReactNode } -export const CartEntryCollapsible = ({ defaultOpen, price, cost, children }: Props) => { +export const CartEntryCollapsible = ({ defaultOpen, cost, children }: Props) => { const [open, setOpen] = useState(defaultOpen) const { t } = useTranslation('cart') const formatter = useFormatter() + const hasDiscountApplied = cost.discount.amount > 0 + return ( @@ -28,16 +24,12 @@ export const CartEntryCollapsible = ({ defaultOpen, price, cost, children }: Pro - {Features.enabled('DISCOUNTS') && cost.discount.amount > 0 && ( + {hasDiscountApplied && ( {formatter.monthlyPrice(cost.gross)} )} - - {Features.enabled('DISCOUNTS') - ? formatter.monthlyPrice(cost.net) - : formatter.monthlyPrice(price)} - + {formatter.monthlyPrice(cost.net)} diff --git a/apps/store/src/components/CartInventory/CartEntryItem/CartEntryItem.tsx b/apps/store/src/components/CartInventory/CartEntryItem/CartEntryItem.tsx index 8ffceb4ef7..71163fa4d6 100644 --- a/apps/store/src/components/CartInventory/CartEntryItem/CartEntryItem.tsx +++ b/apps/store/src/components/CartInventory/CartEntryItem/CartEntryItem.tsx @@ -21,7 +21,7 @@ type Props = CartEntry & { export const CartEntryItem = ({ defaultOpen = false, ...props }: Props) => { const { shopSessionId, readOnly, onRemove, ...cartEntry } = props - const { title: titleLabel, price, cost, pillow } = cartEntry + const { title: titleLabel, cost, pillow } = cartEntry const { t } = useTranslation('cart') const [editProductOffer, editState] = useEditProductOffer() @@ -49,7 +49,7 @@ export const CartEntryItem = ({ defaultOpen = false, ...props }: Props) => { - + diff --git a/apps/store/src/components/CartInventory/CartEntryOfferItem.tsx b/apps/store/src/components/CartInventory/CartEntryOfferItem.tsx index 950410f97c..77f4018b60 100644 --- a/apps/store/src/components/CartInventory/CartEntryOfferItem.tsx +++ b/apps/store/src/components/CartInventory/CartEntryOfferItem.tsx @@ -15,7 +15,6 @@ import { ProductRecommendationFragment, } from '@/services/apollo/generated' import { useTracking } from '@/services/Tracking/useTracking' -import { Features } from '@/utils/Features' import { useFormatter } from '@/utils/useFormatter' type CartOfferItemProps = { @@ -54,6 +53,8 @@ export const CartEntryOfferItem = ({ shopSessionId, product, offer }: CartOfferI if (!show) return null + const hasDiscountApplied = offer.cost.discount.amount > 0 + return ( @@ -97,14 +98,12 @@ export const CartEntryOfferItem = ({ shopSessionId, product, offer }: CartOfferI - {Features.enabled('DISCOUNTS') && offer.cost.discount.amount > 0 && ( + {hasDiscountApplied && ( {formatter.monthlyPrice(offer.cost.gross)} )} - {Features.enabled('DISCOUNTS') - ? formatter.monthlyPrice(offer.cost.net) - : formatter.monthlyPrice(offer.price)} + {formatter.monthlyPrice(offer.cost.net)} ) diff --git a/apps/store/src/components/CartInventory/CartInventory.helpers.tsx b/apps/store/src/components/CartInventory/CartInventory.helpers.tsx index afb55ea46c..e4fd5e8e50 100644 --- a/apps/store/src/components/CartInventory/CartInventory.helpers.tsx +++ b/apps/store/src/components/CartInventory/CartInventory.helpers.tsx @@ -60,7 +60,6 @@ export const getCartEntry = (item: ShopSession['cart']['entries'][number]): Cart return { offerId: item.id, title: item.variant.product.displayNameFull, - price: item.price, cost: item.cost, startDate: hasCancellation ? undefined : convertToDate(item.startDate), pillow: { diff --git a/apps/store/src/components/CartInventory/CartInventory.tsx b/apps/store/src/components/CartInventory/CartInventory.tsx index 1c51b21857..8492baf3a1 100644 --- a/apps/store/src/components/CartInventory/CartInventory.tsx +++ b/apps/store/src/components/CartInventory/CartInventory.tsx @@ -43,7 +43,6 @@ export const CartInventory = ({ shopSessionId, cart, readOnly = false }: Props) key={item.id} offerId={item.id} title={item.variant.product.displayNameFull} - price={item.price} cost={item.cost} pillow={{ src: item.variant.product.pillowImage.src, diff --git a/apps/store/src/components/CartInventory/CartInventory.types.ts b/apps/store/src/components/CartInventory/CartInventory.types.ts index 080d241bcb..9e522d1e6e 100644 --- a/apps/store/src/components/CartInventory/CartInventory.types.ts +++ b/apps/store/src/components/CartInventory/CartInventory.types.ts @@ -4,7 +4,6 @@ import { Money } from '@/utils/formatter' export type CartEntry = { offerId: string title: string - price: Money cost: ProductOfferFragment['cost'] startDate?: Date | null pillow: { src: string; alt?: string } diff --git a/apps/store/src/components/ProductPage/PurchaseForm/DeductibleSelector.tsx b/apps/store/src/components/ProductPage/PurchaseForm/DeductibleSelector.tsx index ca62e53a84..a0cbc28acf 100644 --- a/apps/store/src/components/ProductPage/PurchaseForm/DeductibleSelector.tsx +++ b/apps/store/src/components/ProductPage/PurchaseForm/DeductibleSelector.tsx @@ -8,7 +8,6 @@ import { FormElement } from '@/components/ProductPage/PurchaseForm/PurchaseForm. import * as TierLevelRadioGroup from '@/components/TierSelector/TierLevelRadioGroup' import * as TierSelector from '@/components/TierSelector/TierSelector' import { Money, ProductOfferFragment } from '@/services/apollo/generated' -import { Features } from '@/utils/Features' import { useCurrentLocale } from '@/utils/l10n/useCurrentLocale' import { PageLink } from '@/utils/PageLink' import { useFormatter } from '@/utils/useFormatter' @@ -36,10 +35,9 @@ export const DeductibleSelector = ({ offers, selectedOffer, onValueChange }: Pro offers.forEach((offer) => { if (offer.deductible) { - const price = Features.enabled('DISCOUNTS') ? offer.cost.net : offer.price levels.push({ id: offer.id, - price, + price: offer.cost.net, title: offer.deductible.displayName, description: offer.deductible.tagline, }) diff --git a/apps/store/src/components/ProductPage/PurchaseForm/ProductTierSelector.tsx b/apps/store/src/components/ProductPage/PurchaseForm/ProductTierSelector.tsx index d2194d373b..720181d9e7 100644 --- a/apps/store/src/components/ProductPage/PurchaseForm/ProductTierSelector.tsx +++ b/apps/store/src/components/ProductPage/PurchaseForm/ProductTierSelector.tsx @@ -4,7 +4,6 @@ import { Text } from 'ui' import * as TierLevelRadioGroup from '@/components/TierSelector/TierLevelRadioGroup' import * as TierSelector from '@/components/TierSelector/TierSelector' import { ProductOfferFragment } from '@/services/apollo/generated' -import { Features } from '@/utils/Features' import { useFormatter } from '@/utils/useFormatter' type Props = { @@ -27,18 +26,15 @@ export const ProductTierSelector = ({ offers, selectedOffer, onValueChange }: Pr - {offers.map((offer) => { - const price = Features.enabled('DISCOUNTS') ? offer.cost.net : offer.price - return ( - - ) - })} + {offers.map((offer) => ( + + ))} diff --git a/apps/store/src/components/ProductPage/PurchaseForm/PurchaseForm.tsx b/apps/store/src/components/ProductPage/PurchaseForm/PurchaseForm.tsx index 90c8fa6281..6b61afae03 100644 --- a/apps/store/src/components/ProductPage/PurchaseForm/PurchaseForm.tsx +++ b/apps/store/src/components/ProductPage/PurchaseForm/PurchaseForm.tsx @@ -30,7 +30,6 @@ import { useShopSession } from '@/services/shopSession/ShopSessionContext' import { TrackingContextKey } from '@/services/Tracking/Tracking' import { useTracking } from '@/services/Tracking/useTracking' import { sendDialogEvent } from '@/utils/dialogEvent' -import { Features } from '@/utils/Features' import { useBreakpoint } from '@/utils/useBreakpoint/useBreakpoint' import { useFormatter } from '@/utils/useFormatter' import { ScrollPast } from '../ScrollPast/ScrollPast' @@ -198,10 +197,9 @@ export const PurchaseForm = () => { return await router.push(nextUrl) } - const price = Features.enabled('DISCOUNTS') ? item.cost.net : item.price notifyProductAdded({ name: productData.displayNameFull, - price: formatter.monthlyPrice(price), + price: formatter.monthlyPrice(item.cost.net), pillowSrc: productData.pillowImage.src, description: !item.cancellation.requested || diff --git a/apps/store/src/components/ProductPage/PurchaseForm/getOffersByPrice.ts b/apps/store/src/components/ProductPage/PurchaseForm/getOffersByPrice.ts index e5c9668bf1..5f4686d32c 100644 --- a/apps/store/src/components/ProductPage/PurchaseForm/getOffersByPrice.ts +++ b/apps/store/src/components/ProductPage/PurchaseForm/getOffersByPrice.ts @@ -1,18 +1,9 @@ import { ProductOfferFragment } from '@/services/apollo/generated' -import { Features } from '@/utils/Features' export const getOffersByPrice = (offers: Array) => { - return [...offers].sort(Features.enabled('DISCOUNTS') ? sortByCost : sortByPrice) -} - -const sortByCost = (a: ProductOfferFragment, b: ProductOfferFragment) => { - if (a.cost.net.amount < b.cost.net.amount) return -1 - if (a.cost.net.amount > b.cost.net.amount) return 1 - return 0 -} - -const sortByPrice = (a: ProductOfferFragment, b: ProductOfferFragment) => { - if (a.price.amount < b.price.amount) return -1 - if (a.price.amount > b.price.amount) return 1 - return 0 + return [...offers].sort((a, b) => { + if (a.cost.net.amount < b.cost.net.amount) return -1 + if (a.cost.net.amount > b.cost.net.amount) return 1 + return 0 + }) } diff --git a/apps/store/src/graphql/OfferRecommendationFragment.graphql b/apps/store/src/graphql/OfferRecommendationFragment.graphql index 2f4f10e9f9..271f6cb976 100644 --- a/apps/store/src/graphql/OfferRecommendationFragment.graphql +++ b/apps/store/src/graphql/OfferRecommendationFragment.graphql @@ -9,10 +9,6 @@ fragment OfferRecommendation on ProductOffer { displayNameFull } } - price { - amount - currencyCode - } cost { gross { amount diff --git a/apps/store/src/graphql/ProductOfferFragment.graphql b/apps/store/src/graphql/ProductOfferFragment.graphql index 26c08f7d89..a49a688292 100644 --- a/apps/store/src/graphql/ProductOfferFragment.graphql +++ b/apps/store/src/graphql/ProductOfferFragment.graphql @@ -22,10 +22,6 @@ fragment ProductOffer on ProductOffer { url } } - price { - amount - currencyCode - } cost { gross { amount diff --git a/apps/store/src/services/Tracking/Tracking.ts b/apps/store/src/services/Tracking/Tracking.ts index e0c823edbd..7935a9503a 100644 --- a/apps/store/src/services/Tracking/Tracking.ts +++ b/apps/store/src/services/Tracking/Tracking.ts @@ -10,7 +10,6 @@ import { } from '@/services/gtm' import { PriceIntent } from '@/services/priceIntent/priceIntent.types' import { ShopSession } from '@/services/shopSession/ShopSession.types' -import { Features } from '@/utils/Features' import { getAdtractionProductCategories } from './adtraction' type TrackingContext = Partial> @@ -21,7 +20,6 @@ type TrackingProductData = { } type TrackingOffer = { - price: ProductOfferFragment['price'] cost: ProductOfferFragment['cost'] variant: { typeOfContract: ProductOfferFragment['variant']['typeOfContract'] @@ -140,11 +138,10 @@ export class Tracking { public async reportOfferCreated(offer: ProductOfferFragment) { const event = TrackingEvent.OfferCreated const userData = await getLegacyUserData(this.context) - const price = Features.enabled('DISCOUNTS') ? offer.cost.gross : offer.price const eventData = { offerData: { - insurance_price: price.amount, - currency: price.currencyCode as string, + insurance_price: offer.cost.gross.amount, + currency: offer.cost.gross.currencyCode as string, insurance_type: offer.variant.typeOfContract, flow_type: offer.variant.product.name, @@ -304,17 +301,16 @@ const offerToEcommerceEvent = ({ context, source, }: OfferToEcommerseEventParams): EcommerceEvent => { - const price = Features.enabled('DISCOUNTS') ? offer.cost.gross : offer.price return { event, ecommerce: { - value: price.amount, - currency: price.currencyCode, + value: offer.cost.gross.amount, + currency: offer.cost.gross.currencyCode, items: [ { item_id: offer.variant.product.id, item_name: offer.variant.product.displayNameFull, - price: price.amount, + price: offer.cost.gross.amount, item_variant: offer.variant.typeOfContract, ...(source && { item_list_id: source }), }, @@ -342,16 +338,12 @@ const cartToEcommerceEvent = ( ecommerce: { value: cart.cost.net.amount, currency: cart.cost.net.currencyCode, - items: cart.entries.map((entry) => { - const price = Features.enabled('DISCOUNTS') ? entry.cost.gross : entry.price - - return { - item_id: entry.variant.product.id, - item_name: entry.variant.product.displayNameFull, - price: price.amount, - variant: entry.variant.typeOfContract, - } - }), + items: cart.entries.map((entry) => ({ + item_id: entry.variant.product.id, + item_name: entry.variant.product.displayNameFull, + price: entry.cost.gross.amount, + variant: entry.variant.typeOfContract, + })), }, shopSession: { id: context[TrackingContextKey.ShopSessionId] as string,