Skip to content

Commit

Permalink
feat: add taxes in ProductCard and set default usePriceWithTaxes to f…
Browse files Browse the repository at this point in the history
…alse
  • Loading branch information
ArthurTriis1 committed May 10, 2024
1 parent 266a76f commit 3d5b633
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/core/@generated/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as types from './graphql'
* Therefore it is highly recommended to use the babel or swc plugin for production.
*/
const documents = {
'\n fragment ProductSummary_product on StoreProduct {\n id: productID\n slug\n sku\n brand {\n brandName: name\n }\n name\n gtin\n\n isVariantOf {\n productGroupID\n name\n }\n\n image {\n url\n alternateName\n }\n\n brand {\n name\n }\n\n offers {\n lowPrice\n offers {\n availability\n price\n listPrice\n quantity\n seller {\n identifier\n }\n }\n }\n\n additionalProperty {\n propertyID\n name\n value\n valueReference\n }\n }\n':
'\n fragment ProductSummary_product on StoreProduct {\n id: productID\n slug\n sku\n brand {\n brandName: name\n }\n name\n gtin\n\n isVariantOf {\n productGroupID\n name\n }\n\n image {\n url\n alternateName\n }\n\n brand {\n name\n }\n\n offers {\n lowPrice\n lowPriceWithTaxes\n offers {\n availability\n price\n listPrice\n listPriceWithTaxes\n quantity\n seller {\n identifier\n }\n }\n }\n\n additionalProperty {\n propertyID\n name\n value\n valueReference\n }\n }\n':
types.ProductSummary_ProductFragmentDoc,
'\n fragment Filter_facets on StoreFacet {\n ... on StoreFacetRange {\n key\n label\n\n min {\n selected\n absolute\n }\n\n max {\n selected\n absolute\n }\n\n __typename\n }\n ... on StoreFacetBoolean {\n key\n label\n values {\n label\n value\n selected\n quantity\n }\n\n __typename\n }\n }\n':
types.Filter_FacetsFragmentDoc,
Expand Down Expand Up @@ -64,7 +64,7 @@ const documents = {
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function gql(
source: '\n fragment ProductSummary_product on StoreProduct {\n id: productID\n slug\n sku\n brand {\n brandName: name\n }\n name\n gtin\n\n isVariantOf {\n productGroupID\n name\n }\n\n image {\n url\n alternateName\n }\n\n brand {\n name\n }\n\n offers {\n lowPrice\n offers {\n availability\n price\n listPrice\n quantity\n seller {\n identifier\n }\n }\n }\n\n additionalProperty {\n propertyID\n name\n value\n valueReference\n }\n }\n'
source: '\n fragment ProductSummary_product on StoreProduct {\n id: productID\n slug\n sku\n brand {\n brandName: name\n }\n name\n gtin\n\n isVariantOf {\n productGroupID\n name\n }\n\n image {\n url\n alternateName\n }\n\n brand {\n name\n }\n\n offers {\n lowPrice\n lowPriceWithTaxes\n offers {\n availability\n price\n listPrice\n listPriceWithTaxes\n quantity\n seller {\n identifier\n }\n }\n }\n\n additionalProperty {\n propertyID\n name\n value\n valueReference\n }\n }\n'
): typeof import('./graphql').ProductSummary_ProductFragmentDoc
/**
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
Expand Down
12 changes: 10 additions & 2 deletions packages/core/@generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1109,10 +1109,12 @@ export type ProductSummary_ProductFragment = {
image: Array<{ url: string; alternateName: string }>
offers: {
lowPrice: number
lowPriceWithTaxes: number
offers: Array<{
availability: string
price: number
listPrice: number
listPriceWithTaxes: number
quantity: number
seller: { identifier: string }
}>
Expand Down Expand Up @@ -1417,10 +1419,12 @@ export type ClientManyProductsQueryQuery = {
image: Array<{ url: string; alternateName: string }>
offers: {
lowPrice: number
lowPriceWithTaxes: number
offers: Array<{
availability: string
price: number
listPrice: number
listPriceWithTaxes: number
quantity: number
seller: { identifier: string }
}>
Expand Down Expand Up @@ -1546,10 +1550,12 @@ export type ClientSearchSuggestionsQueryQuery = {
image: Array<{ url: string; alternateName: string }>
offers: {
lowPrice: number
lowPriceWithTaxes: number
offers: Array<{
availability: string
price: number
listPrice: number
listPriceWithTaxes: number
quantity: number
seller: { identifier: string }
}>
Expand Down Expand Up @@ -1676,10 +1682,12 @@ export const ProductSummary_ProductFragmentDoc = new TypedDocumentString(
}
offers {
lowPrice
lowPriceWithTaxes
offers {
availability
price
listPrice
listPriceWithTaxes
quantity
seller {
identifier
Expand Down Expand Up @@ -2054,7 +2062,7 @@ export const SubscribeToNewsletterDocument = {
export const ClientManyProductsQueryDocument = {
__meta__: {
operationName: 'ClientManyProductsQuery',
operationHash: 'c0d7d2ae1d5aaae5d50eea683b389377c36fb57d',
operationHash: '99012563e9885c3b27a716ca212a2c317e7ec12f',
},
} as unknown as TypedDocumentString<
ClientManyProductsQueryQuery,
Expand All @@ -2081,7 +2089,7 @@ export const ClientProductQueryDocument = {
export const ClientSearchSuggestionsQueryDocument = {
__meta__: {
operationName: 'ClientSearchSuggestionsQuery',
operationHash: 'a8a27661f6a032e086c047339e0d0f180f0e0161',
operationHash: '47af7b9c9e0fb18b01050767daf3e765f67819ac',
},
} as unknown as TypedDocumentString<
ClientSearchSuggestionsQueryQuery,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/components/cart/CartItem/CartItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ function useCartItemEvent() {

interface Props {
item: ICartItem
useUnitMultiplier: boolean
usePriceWithTaxes: boolean
useUnitMultiplier?: boolean
usePriceWithTaxes?: boolean
}

function CartItem({
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/components/cart/CartSidebar/CartSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function CartSidebar({
icon: { icon: checkoutButtonIcon, alt: checkoutButtonIconAlt },
},
quantitySelector,
usePriceWithTaxes = true,
usePriceWithTaxes = false,
}: CartSidebarProps) {
const btnProps = useCheckoutButton()
const {
Expand Down Expand Up @@ -136,8 +136,8 @@ function CartSidebar({
{items.map((item) => (
<li key={item.id}>
<CartItem
usePriceWithTaxes={usePriceWithTaxes}
item={item}
usePriceWithTaxes={usePriceWithTaxes}
useUnitMultiplier={
quantitySelector?.useUnitMultiplier ?? false
}
Expand Down
15 changes: 13 additions & 2 deletions packages/core/src/components/product/ProductCard/ProductCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export interface ProductCardProps {
* Enables a DiscountBadge to the component.
*/
showDiscountBadge?: boolean
/**
* Difine if Product uses taxes in price
*/
usePriceWithTaxes?: boolean
}

function ProductCard({
Expand All @@ -63,15 +67,17 @@ function ProductCard({
buttonLabel = 'Add',
onButtonClick,
showDiscountBadge = true,
usePriceWithTaxes = false,
...otherProps
}: ProductCardProps) {
const {
sku,
isVariantOf: { name },
image: [img],
offers: {
lowPrice: spotPrice,
offers: [{ listPrice, availability }],
lowPrice,
lowPriceWithTaxes,
offers: [{ listPrice: listPriceBase, availability, listPriceWithTaxes }],
},
} = product

Expand All @@ -88,6 +94,9 @@ function ProductCard({
[availability]
)

const spotPrice = usePriceWithTaxes ? lowPriceWithTaxes : lowPrice
const listPrice = usePriceWithTaxes ? listPriceWithTaxes : listPriceBase

const hasDiscount = spotPrice <= listPrice

return (
Expand Down Expand Up @@ -152,10 +161,12 @@ export const fragment = gql(`
offers {
lowPrice
lowPriceWithTaxes
offers {
availability
price
listPrice
listPriceWithTaxes
quantity
seller {
identifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function ProductDetails({
},
notAvailableButton: { title: notAvailableButtonTitle },
quantitySelector,
usePriceWithTaxes = true,
usePriceWithTaxes = false,
}: ProductDetailsProps) {
const {
DiscountBadge,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ interface ProductDetailsSettingsProps {
quantity: number
setQuantity: Dispatch<SetStateAction<number>>
notAvailableButtonTitle: string
useUnitMultiplier: boolean
usePriceWithTaxes: boolean
useUnitMultiplier?: boolean
usePriceWithTaxes?: boolean
}

function ProductDetailsSettings({
Expand All @@ -35,8 +35,8 @@ function ProductDetailsSettings({
setQuantity,
buyButtonIcon: { icon: buyButtonIconName, alt: buyButtonIconAlt },
notAvailableButtonTitle,
useUnitMultiplier,
usePriceWithTaxes,
useUnitMultiplier = false,
usePriceWithTaxes = false,
}: ProductDetailsSettingsProps) {
const {
BuyButton,
Expand Down

0 comments on commit 3d5b633

Please sign in to comment.