diff --git a/apps/storefront/src/components/B3ProductList.tsx b/apps/storefront/src/components/B3ProductList.tsx index 537d6b4e..c8123570 100644 --- a/apps/storefront/src/components/B3ProductList.tsx +++ b/apps/storefront/src/components/B3ProductList.tsx @@ -295,130 +295,150 @@ export const B3ProductList: (props: ProductProps) => ReactElement = (props } { - products.map((product) => ( - - { - showCheckbox && ( - handleSelectChange(product)} - /> - ) - } - - - - { - if (canToProduct) { - const { - location: { - origin, - }, - } = window - - if (product?.productUrl) window.location.href = `${origin}${product?.productUrl}` - } - }} - sx={{ - cursor: 'pointer', - }} - > - {product.name} - - - {product.sku} - - {(product.product_options || []).map((option) => ( - {`${option.display_name}: ${option.display_value}`} - ))} - - + 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 + } - - {isMobile && Price:} - {`${currency} ${getProductPrice(product.base_price)}`} - + if (!currentVariant) { + const priceIncTax = product?.price_inc_tax || product.base_price + const priceExTax = product?.price_ex_tax || product.base_price - { - quantityEditable ? ( - <> - - - ) : ( - <> - {isMobile && Qty:} - {getQuantity(product)} - + showCheckbox && ( + handleSelectChange(product)} + /> ) } - + + + + { + if (canToProduct) { + const { + location: { + origin, + }, + } = window + + if (product?.productUrl) window.location.href = `${origin}${product?.productUrl}` + } + }} + sx={{ + cursor: 'pointer', + }} + > + {product.name} + + + {product.sku} + + {(product.product_options || []).map((option) => ( + {`${option.display_name}: ${option.display_value}`} + ))} + + - - {isMobile && ( - - {totalText} - : - - )} - {`${currency} ${getProductTotals(getQuantity(product) || 0, product.base_price)}`} - + + {isMobile && Price:} + {`${currency} ${getProductPrice(productPrice)}`} + - { renderAction && ( + { + quantityEditable ? ( + <> + + + ) : ( + <> + {isMobile && Qty:} + {getQuantity(product)} + + ) + } + + + - <> - { renderAction(product) } - + {isMobile && ( + + {totalText} + : + + )} + {`${currency} ${getProductTotals(getQuantity(product) || 0, productPrice)}`} - )} - - )) + + { renderAction && ( + + <> + { renderAction(product) } + + + )} + + ) + }) } ) : <> diff --git a/apps/storefront/src/pages/orderDetail/shared/B2BOrderData.ts b/apps/storefront/src/pages/orderDetail/shared/B2BOrderData.ts index b611bb70..dee01ce0 100644 --- a/apps/storefront/src/pages/orderDetail/shared/B2BOrderData.ts +++ b/apps/storefront/src/pages/orderDetail/shared/B2BOrderData.ts @@ -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 || ''), }, } diff --git a/apps/storefront/src/pages/quickorder/components/QuickOrderFooter.tsx b/apps/storefront/src/pages/quickorder/components/QuickOrderFooter.tsx index 14612a86..825eb08a 100644 --- a/apps/storefront/src/pages/quickorder/components/QuickOrderFooter.tsx +++ b/apps/storefront/src/pages/quickorder/components/QuickOrderFooter.tsx @@ -48,6 +48,7 @@ import { snackbar, getDefaultCurrencyInfo, addQuoteDraftProduce, + getProductPriceIncTax, } from '@/utils' import { @@ -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) diff --git a/apps/storefront/src/pages/quickorder/components/QuickorderTable.tsx b/apps/storefront/src/pages/quickorder/components/QuickorderTable.tsx index a4138351..005eb028 100644 --- a/apps/storefront/src/pages/quickorder/components/QuickorderTable.tsx +++ b/apps/storefront/src/pages/quickorder/components/QuickorderTable.tsx @@ -20,11 +20,15 @@ import { import { getOrderedProducts, getBcOrderedProducts, + searchB2BProducts, + searchBcProducts, } from '@/shared/service/b2b' import { getDefaultCurrencyInfo, distanceDay, + snackbar, + getProductPriceIncTax, } from '@/utils' import { @@ -55,6 +59,10 @@ import B3FilterMore from '../../../components/filter/B3FilterMore' import QuickOrderCard from './QuickOrderCard' +import { + conversionProductsList, +} from '../../shoppingListDetails/shared/config' + import { B3Sping, } from '@/components' @@ -131,6 +139,9 @@ const QuickorderTable = ({ const { state: { isB2BUser, + companyInfo: { + id: companyInfoId, + }, }, } = useContext(GlobaledContext) @@ -145,6 +156,7 @@ const QuickorderTable = ({ const [isMobile] = useMobile() const { + currency_code: currencyCode, token: currencyToken, } = getDefaultCurrencyInfo() @@ -160,7 +172,40 @@ const QuickorderTable = ({ productIds.push(node.productId) } }) - return listProducts + + const getProducts = isB2BUser ? searchB2BProducts : searchBcProducts + + try { + const { + productsSearch, + } = await getProducts({ + productIds, + currencyCode, + companyId: companyInfoId, + }) + + const newProductsSearch = conversionProductsList(productsSearch) + + listProducts.forEach((item) => { + const { + node, + } = item + + const productInfo = newProductsSearch.find((search: CustomFieldItems) => { + const { + id: productId, + } = search + + return +node.productId === +productId + }) + + node.productsSearch = productInfo || {} + }) + + return listProducts + } catch (err: any) { + snackbar.error(err) + } } } @@ -316,8 +361,22 @@ const QuickorderTable = ({ { key: 'Price', title: 'Price', - render: (row) => { - const price = +row.basePrice * (+row.quantity) + render: (row: CustomFieldItems) => { + const { + productsSearch: { + variants, + }, + variantId, + basePrice, + quantity, + } = row + let priceIncTax = +basePrice + if (variants) { + priceIncTax = getProductPriceIncTax(variants, +variantId) + } + + const withTaxPrice = priceIncTax || +basePrice + const price = withTaxPrice * +quantity return ( ) => }, variantId, } = row - const currentVariantInfo = variants.find((item: CustomFieldItems) => +item.variant_id === +variantId) || {} - const bcCalculatedPrice: { - tax_inclusive: number | string, - } = currentVariantInfo.bc_calculated_price + let priceIncTax = +basePrice + if (variants) { + priceIncTax = getProductPriceIncTax(variants, +variantId) + } const price = +basePrice - const withTaxPrice = +bcCalculatedPrice.tax_inclusive + const withTaxPrice = priceIncTax || +basePrice const discountPrice = +offeredPrice const isDiscount = price - discountPrice > 0 @@ -292,17 +295,19 @@ const QuoteDetailTable = (props: ShoppingDetailTableProps, ref: Ref) => }, variantId, } = row - const currentVariantInfo = variants.find((item: CustomFieldItems) => +item.variant_id === +variantId) || {} - const bcCalculatedPrice: { - tax_inclusive: number | string, - } = currentVariantInfo.bc_calculated_price + + let priceIncTax = +basePrice + if (variants) { + priceIncTax = getProductPriceIncTax(variants, +variantId) + } + const price = +basePrice - const withTaxPrice = +bcCalculatedPrice.tax_inclusive + const withTaxPrice = priceIncTax || +basePrice const discountPrice = +offeredPrice const isDiscount = price - discountPrice > 0 const total = withTaxPrice * +quantity - const totalWithDiscount = (+withTaxPrice - +isDiscount) * +quantity + const totalWithDiscount = (withTaxPrice - +isDiscount) * +quantity return ( diff --git a/apps/storefront/src/pages/quote/components/QuoteDetailTableCard.tsx b/apps/storefront/src/pages/quote/components/QuoteDetailTableCard.tsx index 304ba4fa..99376514 100644 --- a/apps/storefront/src/pages/quote/components/QuoteDetailTableCard.tsx +++ b/apps/storefront/src/pages/quote/components/QuoteDetailTableCard.tsx @@ -9,6 +9,10 @@ import { PRODUCT_DEFAULT_IMAGE, } from '@/constants' +import { + getProductPriceIncTax, +} from '@/utils' + interface QuoteTableCardProps { item: any, currencyToken?: string, @@ -44,17 +48,18 @@ const QuoteDetailTableCard = (props: QuoteTableCardProps) => { }, variantId, } = quoteTableItem - const currentVariantInfo = variants.find((item: CustomFieldItems) => +item.variant_id === +variantId) || {} - const bcCalculatedPrice: { - tax_inclusive: number | string, - } = currentVariantInfo.bc_calculated_price + + let priceIncTax = +basePrice + if (variants) { + priceIncTax = getProductPriceIncTax(variants, +variantId) + } const price = +basePrice - const withTaxPrice = +bcCalculatedPrice.tax_inclusive + const withTaxPrice = priceIncTax || +basePrice const discountPrice = +offeredPrice const isDiscount = price - discountPrice > 0 - const total = withTaxPrice * +quantity + const total = +withTaxPrice * +quantity const totalWithDiscount = (+withTaxPrice - +isDiscount) * +quantity return ( diff --git a/apps/storefront/src/pages/quote/components/QuoteTable.tsx b/apps/storefront/src/pages/quote/components/QuoteTable.tsx index 4197e005..7fd5c81c 100644 --- a/apps/storefront/src/pages/quote/components/QuoteTable.tsx +++ b/apps/storefront/src/pages/quote/components/QuoteTable.tsx @@ -23,6 +23,7 @@ import { getModifiersPrice, getQuickAddProductExtraPrice, snackbar, + getProductPriceIncTax, } from '@/utils' import { @@ -379,14 +380,15 @@ const QuoteTable = (props: ShoppingDetailTableProps, ref: Ref) => { }, variantId, variantSku, + basePrice, } = row - const currentVariantInfo = variants.find((item: CustomFieldItems) => +item.variant_id === +variantId || variantSku === item.sku) || {} - const bcCalculatedPrice: { - tax_inclusive: number | string, - } = currentVariantInfo.bc_calculated_price - // const price = +row.basePrice - const withTaxPrice = +bcCalculatedPrice.tax_inclusive + let priceIncTax = +basePrice + if (variants) { + priceIncTax = getProductPriceIncTax(variants, +variantId, variantSku) + } + + const withTaxPrice = priceIncTax || +basePrice return ( ) => { title: 'Total', render: (row: CustomFieldItems) => { const { - // basePrice, + basePrice, quantity, productsSearch: { variants, @@ -439,13 +441,13 @@ const QuoteTable = (props: ShoppingDetailTableProps, ref: Ref) => { variantId, variantSku, } = row - const currentVariantInfo = variants.find((item: CustomFieldItems) => +item.variant_id === +variantId || variantSku === item.sku) || {} - const bcCalculatedPrice: { - tax_inclusive: number | string, - } = currentVariantInfo.bc_calculated_price + let priceIncTax = +basePrice + if (variants) { + priceIncTax = getProductPriceIncTax(variants, +variantId, variantSku) + } - const withTaxPrice = +bcCalculatedPrice.tax_inclusive - const total = +withTaxPrice * +quantity + const withTaxPrice = priceIncTax || +basePrice + const total = withTaxPrice * +quantity const optionList = JSON.parse(row.optionList) return ( diff --git a/apps/storefront/src/pages/quote/components/QuoteTableCard.tsx b/apps/storefront/src/pages/quote/components/QuoteTableCard.tsx index bd3e8b8a..75725a11 100644 --- a/apps/storefront/src/pages/quote/components/QuoteTableCard.tsx +++ b/apps/storefront/src/pages/quote/components/QuoteTableCard.tsx @@ -14,6 +14,10 @@ import { PRODUCT_DEFAULT_IMAGE, } from '@/constants' +import { + getProductPriceIncTax, +} from '@/utils' + import { getProductOptionsFields, } from '../../shoppingListDetails/shared/config' @@ -48,7 +52,7 @@ const QuoteTableCard = (props: QuoteTableCardProps) => { } = props const { - // basePrice, + basePrice, quantity, id, primaryImage, @@ -61,13 +65,14 @@ const QuoteTableCard = (props: QuoteTableCardProps) => { variantId, } = quoteTableItem - const currentVariantInfo = variants.find((item: CustomFieldItems) => +item.variant_id === +variantId || variantSku === item.sku) || {} - const bcCalculatedPrice: { - tax_inclusive: number | string, - } = currentVariantInfo.bc_calculated_price - const withTaxPrice = +bcCalculatedPrice.tax_inclusive - const total = +withTaxPrice * +quantity - const price = +withTaxPrice + let priceIncTax = +basePrice + if (variants) { + priceIncTax = getProductPriceIncTax(variants, +variantId, variantSku) + } + + const withTaxPrice = priceIncTax || +basePrice + const total = withTaxPrice * +quantity + const price = withTaxPrice const product: any = { ...quoteTableItem.productsSearch, diff --git a/apps/storefront/src/pages/shoppingListDetails/ShoppingListDetails.tsx b/apps/storefront/src/pages/shoppingListDetails/ShoppingListDetails.tsx index 5e0e6f83..85a63c01 100644 --- a/apps/storefront/src/pages/shoppingListDetails/ShoppingListDetails.tsx +++ b/apps/storefront/src/pages/shoppingListDetails/ShoppingListDetails.tsx @@ -321,10 +321,36 @@ const ShoppingListDetails = ({ checkedArr.forEach((item: ListItemProps) => { const { - node, + node: { + variantId, + productsSearch, + quantity, + basePrice, + }, } = item - total += +node.basePrice * +node.quantity + if (productsSearch) { + const { + variants, + } = productsSearch + + if (variants) { + const currentVariants = variants.find((variant: CustomFieldItems) => +variant.variant_id + === +variantId) + + if (currentVariants) { + const { + bc_calculated_price: bcCalculatedPrice, + } = currentVariants + + const price = +bcCalculatedPrice.tax_inclusive || +basePrice + + total += price * +quantity + } + } else { + total += +basePrice * +quantity + } + } }) setSelectedSubTotal((1000 * total) / 1000) diff --git a/apps/storefront/src/pages/shoppingListDetails/components/AddToShoppingList.tsx b/apps/storefront/src/pages/shoppingListDetails/components/AddToShoppingList.tsx index 1535d5a3..547635c1 100644 --- a/apps/storefront/src/pages/shoppingListDetails/components/AddToShoppingList.tsx +++ b/apps/storefront/src/pages/shoppingListDetails/components/AddToShoppingList.tsx @@ -83,7 +83,7 @@ export const AddToShoppingList = (props: AddToListProps) => { const quickAddToList = async (products: CustomFieldItems[]) => { const items = products.map((product) => ({ - optionList: product.newSelectOptionList, + optionList: product.newSelectOptionList || product.optionList, productId: parseInt(product.productId, 10) || 0, quantity: product.quantity, variantId: parseInt(product.variantId, 10) || 0, @@ -124,8 +124,8 @@ export const AddToShoppingList = (props: AddToListProps) => { } const optionsList = option.map((item: CustomFieldItems) => ({ - optionId: item.option_id, - optionValue: item.id, + optionId: `attribute[${item.option_id}]`, + optionValue: item.id.toString(), })) productItems.push({ diff --git a/apps/storefront/src/pages/shoppingListDetails/components/ChooseOptionsDialog.tsx b/apps/storefront/src/pages/shoppingListDetails/components/ChooseOptionsDialog.tsx index e853886a..37be5157 100644 --- a/apps/storefront/src/pages/shoppingListDetails/components/ChooseOptionsDialog.tsx +++ b/apps/storefront/src/pages/shoppingListDetails/components/ChooseOptionsDialog.tsx @@ -189,11 +189,11 @@ export const ChooseOptionsDialog = (props: ChooseOptionsDialogProps) => { } = product if (variantSku) { - const priceNumber = variants.find((variant) => variant.sku === variantSku)?.calculated_price || 0 + const priceNumber = variants.find((variant) => variant.sku === variantSku)?.bc_calculated_price?.tax_inclusive || 0 return `${currency} ${priceNumber.toFixed(2)}` } - const priceNumber = parseFloat(product.base_price) || 0 + const priceNumber = parseFloat(variants[0]?.bc_calculated_price?.tax_inclusive?.toString()) || 0 return `${currency} ${priceNumber.toFixed(2)}` } @@ -342,75 +342,82 @@ export const ChooseOptionsDialog = (props: ChooseOptionsDialogProps) => { isSpinning={isLoading} > {product && ( - - - - - - - - {product.name} - - - {variantSku || product.sku} - - {(product.product_options || []).map((option) => ( - {`${option.display_name}: ${option.display_value}`} - ))} - - - - - Price: - {getProductPrice(product)} - - - - - - - - - - + + + + + + + + + {product.name} + + + {variantSku || product.sku} + + {(product.product_options || []).map((option) => ( + {`${option.display_name}: ${option.display_value}`} + ))} + + + + + Price: + {getProductPrice(product)} + + + + + + + + + + + + - )} diff --git a/apps/storefront/src/pages/shoppingListDetails/components/ReAddToCart.tsx b/apps/storefront/src/pages/shoppingListDetails/components/ReAddToCart.tsx index 81bef5f4..730271f5 100644 --- a/apps/storefront/src/pages/shoppingListDetails/components/ReAddToCart.tsx +++ b/apps/storefront/src/pages/shoppingListDetails/components/ReAddToCart.tsx @@ -403,13 +403,15 @@ export const ReAddToCart = (props: ShoppingProductsProps) => { variantSku, optionList, productsSearch, + tax, + discount, // productsSearch: { // variants, // }, // variantId, } = product.node - const total = +basePrice * +quantity - const price = +basePrice + const price = +basePrice + +tax + +discount + const total = +price * +quantity // const newOptionList = JSON.parse(optionList) // let optionsValue = [] diff --git a/apps/storefront/src/pages/shoppingListDetails/components/ShoppingDetailCard.tsx b/apps/storefront/src/pages/shoppingListDetails/components/ShoppingDetailCard.tsx index fc8151ec..d831e653 100644 --- a/apps/storefront/src/pages/shoppingListDetails/components/ShoppingDetailCard.tsx +++ b/apps/storefront/src/pages/shoppingListDetails/components/ShoppingDetailCard.tsx @@ -18,6 +18,10 @@ import { PRODUCT_DEFAULT_IMAGE, } from '@/constants' +import { + getProductPriceIncTax, +} from '@/utils' + import { getProductOptionsFields, } from '../shared/config' @@ -58,7 +62,7 @@ const ShoppingDetailCard = (props: ShoppingDetailCardProps) => { } = props const { - // basePrice, + basePrice, quantity, itemId, variantId, @@ -71,14 +75,16 @@ const ShoppingDetailCard = (props: ShoppingDetailCardProps) => { variants, }, } = shoppingDetail - const currentVariantInfo = variants.find((item: CustomFieldItems) => +item.variant_id === +variantId) || {} - const bcCalculatedPrice: { - tax_inclusive: number | string, - } = currentVariantInfo.bc_calculated_price - const withTaxPrice = +bcCalculatedPrice.tax_inclusive - const total = +withTaxPrice * +quantity - const price = +withTaxPrice + let priceIncTax = +basePrice + if (variants) { + priceIncTax = getProductPriceIncTax(variants, +variantId, variantSku) + } + + const withTaxPrice = priceIncTax || +basePrice + + const total = withTaxPrice * +quantity + const price = withTaxPrice const product: any = { ...shoppingDetail.productsSearch, diff --git a/apps/storefront/src/pages/shoppingListDetails/components/ShoppingDetailTable.tsx b/apps/storefront/src/pages/shoppingListDetails/components/ShoppingDetailTable.tsx index 29d90071..72e36033 100644 --- a/apps/storefront/src/pages/shoppingListDetails/components/ShoppingDetailTable.tsx +++ b/apps/storefront/src/pages/shoppingListDetails/components/ShoppingDetailTable.tsx @@ -34,6 +34,7 @@ import { import { snackbar, + getProductPriceIncTax, } from '@/utils' import { @@ -447,12 +448,12 @@ const ShoppingDetailTable = (props: ShoppingDetailTableProps, ref: Ref) }, variantId, } = row - const currentVariantInfo = variants.find((item: CustomFieldItems) => +item.variant_id === +variantId) || {} - const bcCalculatedPrice: { - tax_inclusive: number | string, - } = currentVariantInfo.bc_calculated_price - // const price = +row.basePrice - const withTaxPrice = +bcCalculatedPrice.tax_inclusive + let priceIncTax + if (variants) { + priceIncTax = getProductPriceIncTax(variants, +variantId) + } + const price = +row.basePrice + const withTaxPrice = priceIncTax || price return ( ) title: 'Total', render: (row: CustomFieldItems) => { const { - // basePrice, + basePrice, quantity, itemId, productsSearch: { variants, + options, }, variantId, } = row - const currentVariantInfo = variants.find((item: CustomFieldItems) => +item.variant_id === +variantId) || {} - const bcCalculatedPrice: { - tax_inclusive: number | string, - } = currentVariantInfo.bc_calculated_price - const withTaxPrice = +bcCalculatedPrice.tax_inclusive + + let priceIncTax + if (variants) { + priceIncTax = getProductPriceIncTax(variants, +variantId) + } + + const withTaxPrice = priceIncTax || basePrice const total = +withTaxPrice * +quantity - const optionList = JSON.parse(row.optionList) + const optionList = options || JSON.parse(row.optionList) return ( @@ -620,7 +624,7 @@ const ShoppingDetailTable = (props: ShoppingDetailTableProps, ref: Ref) fontSize: '24px', }} > - {`${currencyToken}${shoppingListTotalPrice || 0.00}`} + {`${currencyToken}${shoppingListTotalPrice.toFixed(2) || 0.00}`} { + const currentVariantInfo = variants.find((item: CustomFieldItems) => +item.variant_id === variantId || variantSku === item.sku) || {} + const bcCalculatedPrice: { + tax_inclusive: number | string, + } = currentVariantInfo.bc_calculated_price + + const priceIncTax = +bcCalculatedPrice.tax_inclusive + + return priceIncTax +} diff --git a/apps/storefront/src/utils/index.ts b/apps/storefront/src/utils/index.ts index 4252b770..501cc11b 100644 --- a/apps/storefront/src/utils/index.ts +++ b/apps/storefront/src/utils/index.ts @@ -69,6 +69,10 @@ import { b2bPrintInvoice, } from './b3PrintInvoice' +import { + getProductPriceIncTax, +} from './b3Price' + export { addQuoteDraftProduce, getModifiersPrice, @@ -112,4 +116,5 @@ export { getDefaultCurrencyInfo, showPageMask, b2bPrintInvoice, + getProductPriceIncTax, }