Skip to content

Commit

Permalink
fix: show price with tax
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianJiang2021 committed Apr 17, 2023
1 parent 6c23194 commit dfa2b5f
Show file tree
Hide file tree
Showing 18 changed files with 452 additions and 258 deletions.
244 changes: 132 additions & 112 deletions apps/storefront/src/components/B3ProductList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,130 +295,150 @@ export const B3ProductList: <T>(props: ProductProps<T>) => ReactElement = (props
}

{
products.map((product) => (
<Flex
isMobile={isMobile}
key={product.id}
>
{
showCheckbox && (
<Checkbox
checked={isChecked(product)}
onChange={() => handleSelectChange(product)}
/>
)
}
<FlexItem padding={isMobile ? '0' : '0 6% 0 0'}>
<ProductImage src={product.imageUrl || PRODUCT_DEFAULT_IMAGE} />
<Box
sx={{
marginLeft: '16px',
}}
>
<Typography
variant="body1"
color="#212121"
onClick={() => {
if (canToProduct) {
const {
location: {
origin,
},
} = window

if (product?.productUrl) window.location.href = `${origin}${product?.productUrl}`
}
}}
sx={{
cursor: 'pointer',
}}
>
{product.name}
</Typography>
<Typography
variant="body1"
color="#616161"
>
{product.sku}
</Typography>
{(product.product_options || []).map((option) => (
<ProductOptionText key={`${option.option_id}`}>{`${option.display_name}: ${option.display_value}`}</ProductOptionText>
))}
</Box>
</FlexItem>
products.map((product) => {
const {
variants = [],
} = product
const currentVariant = variants[0]
let productPrice = +product.base_price
if (currentVariant) {
const bcCalculatedPrice = currentVariant.bc_calculated_price

productPrice = +bcCalculatedPrice.tax_inclusive
}

<FlexItem
textAlignLocation={textAlign}
padding={quantityEditable ? '10px 0 0' : ''}
{...itemStyle.default}
>
{isMobile && <span>Price:</span>}
{`${currency} ${getProductPrice(product.base_price)}`}
</FlexItem>
if (!currentVariant) {
const priceIncTax = product?.price_inc_tax || product.base_price
const priceExTax = product?.price_ex_tax || product.base_price

<FlexItem
textAlignLocation={textAlign}
{...itemStyle.qty}
productPrice = +priceIncTax || +priceExTax
}

return (
<Flex
isMobile={isMobile}
key={product.id}
>
{
quantityEditable ? (
<>
<TextField
type="number"
variant="filled"
hiddenLabel={!isMobile}
label={isMobile ? 'Qty' : ''}
value={getQuantity(product)}
onChange={handleProductQuantityChange(product.id)}
onKeyDown={handleNumberInputKeyDown}
onBlur={handleNumberInputBlur(product)}
size="small"
sx={{
width: `${isMobile ? '110px' : '72px'}`,
'& .MuiFormHelperText-root': {
marginLeft: '0',
marginRight: '0',
},
}}
error={!!product.helperText}
helperText={product.helperText}
/>
</>
) : (
<>
{isMobile && <span>Qty:</span>}
{getQuantity(product)}
</>
showCheckbox && (
<Checkbox
checked={isChecked(product)}
onChange={() => handleSelectChange(product)}
/>
)
}
</FlexItem>
<FlexItem padding={isMobile ? '0' : '0 6% 0 0'}>
<ProductImage src={product.imageUrl || PRODUCT_DEFAULT_IMAGE} />
<Box
sx={{
marginLeft: '16px',
}}
>
<Typography
variant="body1"
color="#212121"
onClick={() => {
if (canToProduct) {
const {
location: {
origin,
},
} = window

if (product?.productUrl) window.location.href = `${origin}${product?.productUrl}`
}
}}
sx={{
cursor: 'pointer',
}}
>
{product.name}
</Typography>
<Typography
variant="body1"
color="#616161"
>
{product.sku}
</Typography>
{(product.product_options || []).map((option) => (
<ProductOptionText key={`${option.option_id}`}>{`${option.display_name}: ${option.display_value}`}</ProductOptionText>
))}
</Box>
</FlexItem>

<FlexItem
textAlignLocation={textAlign}
padding={quantityEditable ? '10px 0 0' : ''}
{...itemStyle.default}
>
{isMobile && (
<span>
{totalText}
:
</span>
)}
{`${currency} ${getProductTotals(getQuantity(product) || 0, product.base_price)}`}
</FlexItem>
<FlexItem
textAlignLocation={textAlign}
padding={quantityEditable ? '10px 0 0' : ''}
{...itemStyle.default}
>
{isMobile && <span>Price:</span>}
{`${currency} ${getProductPrice(productPrice)}`}
</FlexItem>

{ renderAction && (
<FlexItem
textAlignLocation={textAlign}
{...itemStyle.qty}
>
{
quantityEditable ? (
<>
<TextField
type="number"
variant="filled"
hiddenLabel={!isMobile}
label={isMobile ? 'Qty' : ''}
value={getQuantity(product)}
onChange={handleProductQuantityChange(product.id)}
onKeyDown={handleNumberInputKeyDown}
onBlur={handleNumberInputBlur(product)}
size="small"
sx={{
width: `${isMobile ? '110px' : '72px'}`,
'& .MuiFormHelperText-root': {
marginLeft: '0',
marginRight: '0',
},
}}
error={!!product.helperText}
helperText={product.helperText}
/>
</>
) : (
<>
{isMobile && <span>Qty:</span>}
{getQuantity(product)}
</>
)
}
</FlexItem>

<FlexItem
textAlignLocation={textAlign}
padding={quantityEditable ? '10px 0 0' : ''}
{...itemStyle.default}
width={isMobile ? '100%' : actionWidth}
>
<>
{ renderAction(product) }
</>
{isMobile && (
<span>
{totalText}
:
</span>
)}
{`${currency} ${getProductTotals(getQuantity(product) || 0, productPrice)}`}
</FlexItem>
)}
</Flex>
))

{ renderAction && (
<FlexItem
{...itemStyle.default}
width={isMobile ? '100%' : actionWidth}
>
<>
{ renderAction(product) }
</>
</FlexItem>
)}
</Flex>
)
})
}
</Box>
) : <></>
Expand Down
8 changes: 4 additions & 4 deletions apps/storefront/src/pages/orderDetail/shared/B2BOrderData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ const getOrderSummary = (data: B2BOrderData) => {
createAt: dateCreated,
name: `${firstName} ${lastName}`,
priceData: {
'Sub total': formatPrice(subtotalExTax || subtotalIncTax || ''),
Shipping: formatPrice(shippingCostExTax || shippingCostIncTax || ''),
'Handing fee': formatPrice(handlingCostExTax || handlingCostIncTax || ''),
'Sub total': formatPrice(subtotalIncTax || subtotalExTax || ''),
Shipping: formatPrice(shippingCostIncTax || shippingCostExTax || ''),
'Handing fee': formatPrice(handlingCostIncTax || handlingCostExTax || ''),
Tax: formatPrice(totalTax || ''),
'Grand total': formatPrice(totalExTax || totalIncTax || ''),
'Grand total': formatPrice(totalIncTax || totalExTax || ''),
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
snackbar,
getDefaultCurrencyInfo,
addQuoteDraftProduce,
getProductPriceIncTax,
} from '@/utils'

import {
Expand Down Expand Up @@ -527,10 +528,22 @@ const QuickOrderFooter = (props: QuickOrderFooterProps) => {

checkedArr.forEach((item: ListItemProps) => {
const {
node,
node: {
variantId,
productsSearch: {
variants,
},
quantity,
basePrice,
},
} = item

total += +node.basePrice * +node.quantity
if (variants) {
const priceIncTax = getProductPriceIncTax(variants, +variantId) || +basePrice
total += priceIncTax * +quantity
} else {
total += +basePrice * +quantity
}
})

setSelectedSubTotal((1000 * total) / 1000)
Expand Down
Loading

0 comments on commit dfa2b5f

Please sign in to comment.