Skip to content

Commit

Permalink
Revert "fix:shopping list product bun1714 (#870)"
Browse files Browse the repository at this point in the history
This reverts commit 9125e46.
  • Loading branch information
BrianJiang2021 authored and libruce committed Dec 26, 2023
1 parent a62a52e commit f8d0b19
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 101 deletions.
6 changes: 1 addition & 5 deletions apps/storefront/src/pages/pdp/PDP.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { globalStateSelector } from '@/store'
import {
B3SStorage,
getDefaultCurrencyInfo,
getValidOptionsList,
globalSnackbar,
isAllRequiredOptionFilled,
} from '@/utils'
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -186,12 +183,11 @@ export const addProductsToShoppingList = async ({
break
}

const newOptionLists = getValidOptionsList(optionList, productsInfo[index])
products.push({
productId,
variantId,
quantity,
optionList: newOptionLists,
optionList,
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import {
calculateProductListPrice,
currencyFormat,
getProductPriceIncTax,
getValidOptionsList,
snackbar,
validProductQty,
} from '@/utils'
Expand Down Expand Up @@ -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,
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -151,7 +139,6 @@ export default function AddToShoppingList(props: AddToListProps) {
variantId: parseInt(variantId, 10) || 0,
quantity: +qty,
optionList: optionsList,
products: item.products,
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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 || [],
},
}

Expand Down
1 change: 0 additions & 1 deletion apps/storefront/src/utils/b3AddToShoppingList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
57 changes: 0 additions & 57 deletions apps/storefront/src/utils/b3Product/b3Product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -1266,7 +1210,6 @@ export {
getNewProductsList,
getProductExtraPrice,
getQuickAddProductExtraPrice,
getValidOptionsList,
setModifierQtyPrice,
validProductQty,
}
4 changes: 2 additions & 2 deletions apps/storefront/src/utils/b3Product/shared/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,9 @@ export const getAllModifierDefaultValue = (modifiers: CustomFieldItems) => {
const day = date.getDate()

modifierInfo.defaultValue = {
year,
month,
day,
year,
}
}

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit f8d0b19

Please sign in to comment.