Skip to content

Commit

Permalink
fix: sl to cart quantity issues & cantPurchase products tips
Browse files Browse the repository at this point in the history
  • Loading branch information
b3aton authored and kris-liu-smile committed Mar 10, 2023
1 parent 3f36e10 commit c9f1681
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,14 @@ export const ReAddToCart = (props: ShoppingProductsProps) => {
const quantityNumber = parseInt(`${quantity}`, 10) || 0
if (minQuantity !== 0 && quantityNumber < minQuantity) {
product.node.quantity = minQuantity
product.isValid = true
} else if (maxQuantity !== 0 && quantityNumber > maxQuantity) {
product.node.quantity = maxQuantity
product.isValid = true
}
if (isStock !== '0' && stock && quantity > stock) {
product.node.quantity = stock
product.isValid = true
}
})

Expand Down Expand Up @@ -326,7 +329,7 @@ export const ReAddToCart = (props: ShoppingProductsProps) => {
variant="filled"
severity="error"
>
{allowJuniorPlaceOrder ? `${successProducts} product(s) can\n't checkout, please change the quantity` : `${products.length} product(s) were not added to cart, please change the quantity`}
{allowJuniorPlaceOrder ? `${products.length} product(s) can\n't checkout, please change the quantity` : `${products.length} product(s) were not added to cart, please change the quantity`}
</Alert>
</Box>
<B3Sping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,25 @@ const ShoppingDetailFooter = (props: ShoppingDetailFooterProps) => {
try {
const skus: string[] = []

let cantPurchase: string = ''

checkedArr.forEach((item: ProductsProps) => {
const {
node,
} = item

if (node.productsSearch.availability === 'disabled') {
cantPurchase += `${node.variantSku},`
}

skus.push(node.variantSku)
})

if (cantPurchase) {
snackbar.error(`Sku(s): ${cantPurchase.slice(0, -1)} unavailable for purchasing, please uncheck.`)
return
}

if (skus.length === 0) {
snackbar.error(allowJuniorPlaceOrder ? 'Please select at least one item to checkout' : 'Please select at least one item to add to cart')
return
Expand Down
11 changes: 10 additions & 1 deletion apps/storefront/src/shared/service/request/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,18 @@ import {

const originFetch = window.fetch

const responseResult = (path: string, res: any, resolve: any, init: any) => {
if (path.includes('current.jwt')) return res.text()
console.log(init)
if (init.method === 'DELETE') {
resolve()
}
return res.json()
}

function b3Fetch(path: string, init: any, type?: string, customMessage = false) {
return new Promise((resolve, reject) => {
originFetch(path, init).then((res: Response) => (path.includes('current.jwt') ? res.text() : res.json())).then(async (res) => {
originFetch(path, init).then((res: Response) => responseResult(path, res, resolve, init)).then(async (res) => {
if (res?.code === 500) {
const data = res?.data || {}
const message = data.errMsg || res.message || ''
Expand Down

0 comments on commit c9f1681

Please sign in to comment.