Skip to content

Commit

Permalink
fix: quick order add product to cart without sku
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianJiang2021 committed Jun 28, 2023
1 parent 3faca98 commit a5fc150
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
9 changes: 9 additions & 0 deletions apps/storefront/src/hooks/dom/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,20 @@ const addProductsFromCartToQuote = (setOpenPage: DispatchProps) => {

const cartProductsList = getCartProducts(lineItems)

const noSkuProducts = cartProductsList.filter(({ sku }) => !sku)

if (noSkuProducts.length > 0) {
globalSnackbar.error('Can not add products without SKU.', {
isClose: true,
})
}

if (cartProductsList.length === 0) {
globalSnackbar.error('No products being added.', {
isClose: true,
})
}
if (noSkuProducts.length === cartProductsList.length) return

const isSuccess = await addProductsToDraftQuote(cartProductsList)
if (isSuccess) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ function QuickOrderFooter(props: QuickOrderFooterProps) {
const { node } = item

inventoryInfos.forEach((inventory: CustomFieldItems) => {
if (node.variantSku === inventory.variantSku) {
if (
node.variantSku === inventory.variantSku &&
+node.variantId === +inventory.variantId
) {
const { optionList, quantity } = node

const options = optionList.map((option: CustomFieldItems) => ({
Expand Down Expand Up @@ -274,6 +277,20 @@ function QuickOrderFooter(props: QuickOrderFooterProps) {
}
)

const noSkuProducts = checkedArr.filter((checkedItem: ListItemProps) => {
const {
node: { variantSku },
} = checkedItem

return !variantSku
})
if (noSkuProducts.length > 0) {
snackbar.error('Can not add products without SKU.', {
isClose: true,
})
}
if (noSkuProducts.length === checkedArr.length) return

const productIds: number[] = []
productsWithSku.forEach((product: ListItemProps) => {
const { node } = product
Expand Down
9 changes: 9 additions & 0 deletions apps/storefront/src/pages/quote/components/AddToQuote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ export default function AddToQuote(props: AddToListProps) {
const addToList = async (products: CustomFieldItems[]) => {
const newProducts = getNewQuoteProduct(products)

const noSkuProducts = products.filter(({ sku }) => !sku)
if (noSkuProducts.length > 0) {
snackbar.error('Can not add products without SKU.', {
isClose: true,
})
}

if (noSkuProducts.length === products.length) return []

addToQuote(newProducts)

snackbar.success('Product were added to your quote.', {
Expand Down
8 changes: 6 additions & 2 deletions apps/storefront/src/utils/graphqlDataConvert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ export const convertObjectToGraphql = (data: CustomFieldItems) => {

export const convertArrayToGraphql = (data: CustomFieldItems) => {
let str = '['
data.forEach((list: any) => {
str += convertObjectToGraphql(list)
data.forEach((list: CustomFieldItems, index: number) => {
if (index === data.length - 1) {
str += convertObjectToGraphql(list)
} else {
str += `${convertObjectToGraphql(list)},`
}
})
str += ']'

Expand Down

0 comments on commit a5fc150

Please sign in to comment.