From f8d0b192e44280f0f4c386877b9e31cd74542bd6 Mon Sep 17 00:00:00 2001 From: BrianJiang2021 <80307788+BrianJiang2021@users.noreply.github.com> Date: Tue, 26 Dec 2023 16:44:18 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"fix=EF=BC=9Ashopping=20list=20product?= =?UTF-8?q?=20bun1714=20(#870)"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 9125e4602f4b5b27810ab2f1bf188622d31ac835. --- apps/storefront/src/pages/pdp/PDP.tsx | 6 +- .../components/QuickOrderFooter.tsx | 6 +- .../components/AddToShoppingList.tsx | 39 +++++-------- .../components/ShoppingDetailTable.tsx | 8 +-- .../src/utils/b3AddToShoppingList.ts | 1 - .../src/utils/b3Product/b3Product.ts | 57 ------------------- .../src/utils/b3Product/shared/config.ts | 4 +- 7 files changed, 20 insertions(+), 101 deletions(-) diff --git a/apps/storefront/src/pages/pdp/PDP.tsx b/apps/storefront/src/pages/pdp/PDP.tsx index e8d75536..ba13af29 100644 --- a/apps/storefront/src/pages/pdp/PDP.tsx +++ b/apps/storefront/src/pages/pdp/PDP.tsx @@ -24,7 +24,6 @@ import { globalStateSelector } from '@/store' import { B3SStorage, getDefaultCurrencyInfo, - getValidOptionsList, globalSnackbar, isAllRequiredOptionFilled, } from '@/utils' @@ -67,8 +66,6 @@ export const serialize = (form: any) => { case 'checkbox': if (file.checked) { arr[file.name] = file.value - } else { - arr[file.name] = '' } break case 'radio': @@ -186,12 +183,11 @@ export const addProductsToShoppingList = async ({ break } - const newOptionLists = getValidOptionsList(optionList, productsInfo[index]) products.push({ productId, variantId, quantity, - optionList: newOptionLists, + optionList, }) } diff --git a/apps/storefront/src/pages/quickorder/components/QuickOrderFooter.tsx b/apps/storefront/src/pages/quickorder/components/QuickOrderFooter.tsx index 40b8d432..58f35b4e 100644 --- a/apps/storefront/src/pages/quickorder/components/QuickOrderFooter.tsx +++ b/apps/storefront/src/pages/quickorder/components/QuickOrderFooter.tsx @@ -40,7 +40,6 @@ import { calculateProductListPrice, currencyFormat, getProductPriceIncTax, - getValidOptionsList, snackbar, validProductQty, } from '@/utils' @@ -521,17 +520,16 @@ function QuickOrderFooter(props: QuickOrderFooterProps) { checkedArr.forEach((product: ListItemProps) => { const { - node: { optionList, productId, quantity, variantId, productsSearch }, + node: { optionList, productId, quantity, variantId }, } = product const optionsList = getOptionsList(optionList) - const newOptionLists = getValidOptionsList(optionsList, productsSearch) items.push({ productId: +productId, variantId: +variantId, quantity: +quantity, - optionList: newOptionLists, + optionList: optionsList, }) }) diff --git a/apps/storefront/src/pages/shoppingListDetails/components/AddToShoppingList.tsx b/apps/storefront/src/pages/shoppingListDetails/components/AddToShoppingList.tsx index b32f2ff2..fea4c370 100644 --- a/apps/storefront/src/pages/shoppingListDetails/components/AddToShoppingList.tsx +++ b/apps/storefront/src/pages/shoppingListDetails/components/AddToShoppingList.tsx @@ -9,7 +9,7 @@ import { addProductToBcShoppingList, addProductToShoppingList, } from '@/shared/service/b2b' -import { B3SStorage, getValidOptionsList, snackbar } from '@/utils' +import { B3SStorage, snackbar } from '@/utils' import { getAllModifierDefaultValue } from '../../../utils/b3Product/shared/config' import { ShoppingListDetailsContext } from '../context/ShoppingListDetailsContext' @@ -40,18 +40,12 @@ export default function AddToShoppingList(props: AddToListProps) { : addProductToBcShoppingList const addToList = async (products: CustomFieldItems[]) => { - const items = products.map((product) => { - const newOptionLists = getValidOptionsList( - product.newSelectOptionList, - product - ) - return { - optionList: newOptionLists, - productId: product.id, - quantity: product.quantity, - variantId: product.variantId, - } - }) + const items = products.map((product) => ({ + optionList: product.newSelectOptionList, + productId: product.id, + quantity: product.quantity, + variantId: product.variantId, + })) const res: CustomFieldItems = await addItemsToShoppingList({ shoppingListId: id, @@ -66,18 +60,12 @@ export default function AddToShoppingList(props: AddToListProps) { } const quickAddToList = async (products: CustomFieldItems[]) => { - const items = products.map((product) => { - const newOptionLists = getValidOptionsList( - product.newSelectOptionList || product.optionList, - product?.products || product - ) - return { - optionList: newOptionLists || [], - productId: parseInt(product.productId, 10) || 0, - quantity: product.quantity, - variantId: parseInt(product.variantId, 10) || 0, - } - }) + const items = products.map((product) => ({ + optionList: product.newSelectOptionList || product.optionList, + productId: parseInt(product.productId, 10) || 0, + quantity: product.quantity, + variantId: parseInt(product.variantId, 10) || 0, + })) const res: CustomFieldItems = await addItemsToShoppingList({ shoppingListId: id, @@ -151,7 +139,6 @@ export default function AddToShoppingList(props: AddToListProps) { variantId: parseInt(variantId, 10) || 0, quantity: +qty, optionList: optionsList, - products: item.products, }) }) diff --git a/apps/storefront/src/pages/shoppingListDetails/components/ShoppingDetailTable.tsx b/apps/storefront/src/pages/shoppingListDetails/components/ShoppingDetailTable.tsx index 4cbdf0cc..c355ee29 100644 --- a/apps/storefront/src/pages/shoppingListDetails/components/ShoppingDetailTable.tsx +++ b/apps/storefront/src/pages/shoppingListDetails/components/ShoppingDetailTable.tsx @@ -23,7 +23,7 @@ import { updateBcShoppingListsItem, } from '@/shared/service/b2b' import { store } from '@/store' -import { currencyFormat, getValidOptionsList, snackbar } from '@/utils' +import { currencyFormat, snackbar } from '@/utils' import { getBCPrice } from '@/utils/b3Product/b3Product' import { getProductOptionsFields } from '@/utils/b3Product/shared/config' @@ -256,17 +256,13 @@ function ShoppingDetailTable( ? updateB2BShoppingListsItem : updateBcShoppingListsItem try { - const newOptionLists = getValidOptionsList( - products[0].newSelectOptionList, - products[0] - ) const data = { itemId: editProductItemId, shoppingListId, itemData: { variantId: products[0].variantId, quantity: products[0].quantity, - optionList: newOptionLists || [], + optionList: products[0].newSelectOptionList || [], }, } diff --git a/apps/storefront/src/utils/b3AddToShoppingList.ts b/apps/storefront/src/utils/b3AddToShoppingList.ts index cd7c65f0..b03261a2 100644 --- a/apps/storefront/src/utils/b3AddToShoppingList.ts +++ b/apps/storefront/src/utils/b3AddToShoppingList.ts @@ -284,7 +284,6 @@ export const serialize = (form: any) => { case 'checkbox': case 'radio': if (!file.checked) { - if (file.type === 'checkbox') arr[file.name] = '' break } else { if (arr[file.name]) { diff --git a/apps/storefront/src/utils/b3Product/b3Product.ts b/apps/storefront/src/utils/b3Product/b3Product.ts index bde94238..f25e0627 100644 --- a/apps/storefront/src/utils/b3Product/b3Product.ts +++ b/apps/storefront/src/utils/b3Product/b3Product.ts @@ -76,11 +76,6 @@ interface ProductInfo extends Variant { optionSelections?: ProductOptionString[] } -interface OptionsProps { - optionId: string | number - optionValue: string | number -} - export interface LineItems { quantity: number productId: number @@ -1201,57 +1196,6 @@ const getBCPrice = (basePrice: number, taxPrice: number) => { return price } -const getValidOptionsList = ( - options: OptionsProps[] | CustomFieldItems, - originProduct: CustomFieldItems -) => { - const targetType = ['text', 'numbers_only_text', 'multi_line_text'] - const originOptions = originProduct?.modifiers || originProduct?.allOptions - const newOptions: CustomFieldItems = [] - options.forEach( - (option: { optionId: number | string; optionValue: number | string }) => { - const currentOption = originOptions.find( - (item: { id: string | number }) => { - const optionId = option.optionId.toString() - const targetId = optionId?.includes('attribute') - ? optionId.split('[')[1].split(']')[0] - : optionId - - return +targetId === +item.id - } - ) - - if (!option.optionValue || +option.optionValue === 0) { - if (currentOption?.type === 'checkbox') { - const optionValues = currentOption?.option_values || [] - - const checkboxValue = optionValues.find( - (value: { - value_data: { checked_value: boolean } - label: string - }) => !value?.value_data?.checked_value || value?.label === 'No' - ) - newOptions.push({ - optionId: option.optionId, - optionValue: checkboxValue.id.toString(), - }) - } - if ( - (targetType.includes(currentOption.type) || - currentOption.type.includes('text')) && - option.optionValue - ) { - newOptions.push(option) - } - } else { - newOptions.push(option) - } - } - ) - - return newOptions -} - export { addQuoteDraftProduce, addQuoteDraftProducts, @@ -1266,7 +1210,6 @@ export { getNewProductsList, getProductExtraPrice, getQuickAddProductExtraPrice, - getValidOptionsList, setModifierQtyPrice, validProductQty, } diff --git a/apps/storefront/src/utils/b3Product/shared/config.ts b/apps/storefront/src/utils/b3Product/shared/config.ts index 9376d623..46b1c48a 100644 --- a/apps/storefront/src/utils/b3Product/shared/config.ts +++ b/apps/storefront/src/utils/b3Product/shared/config.ts @@ -460,9 +460,9 @@ export const getAllModifierDefaultValue = (modifiers: CustomFieldItems) => { const day = date.getDate() modifierInfo.defaultValue = { + year, month, day, - year, } } @@ -558,9 +558,9 @@ export const getOptionRequestData = ( const month = date.getMonth() + 1 const day = date.getDate() + requestData[`${decodeName}[year]`] = year requestData[`${decodeName}[month]`] = month requestData[`${decodeName}[day]`] = day - requestData[`${decodeName}[year]`] = year return }