Skip to content

Commit

Permalink
add to cart bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
iskurbanov committed Oct 1, 2022
1 parent 445250a commit 2382a2b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions context/shopContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ export default function ShopProvider({ children }) {
}, [])


async function addToCart(newItem) {
async function addToCart(addedItem) {
const newItem = {...addedItem}
console.log(newItem)
setCartOpen(true)

if (cart.length === 0) {
setCart([newItem])

const checkout = await createCheckout(newItem.id, newItem.variantQuantity)
const checkout = await createCheckout(newItem.id, 1)

setCheckoutId(checkout.id)
setCheckoutUrl(checkout.webUrl)
Expand Down Expand Up @@ -97,7 +99,7 @@ export default function ShopProvider({ children }) {

async function decrementCartItem(item) {
setCartLoading(true)

if (item.variantQuantity === 1) {
removeCartItem(item.id)
} else {
Expand Down

0 comments on commit 2382a2b

Please sign in to comment.