Skip to content

Commit

Permalink
include customizedProduct data in linked products
Browse files Browse the repository at this point in the history
  • Loading branch information
itswadesh committed Mar 1, 2024
1 parent 121b47e commit a0677d8
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 188 deletions.
73 changes: 0 additions & 73 deletions src/lib/themes/misiki/ProductDetails.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -265,79 +265,6 @@ function handleSelectedLinkiedProducts(e) {
// This is used only for customized product else cart?/add
async function addToBag(p, customizedImg, customizedJson) {
try {
loading = true
cartButtonText = 'Adding...'
let cart = await CartService.addToCartService({
pid: p.id,
vid: p.id,
qty: 1,
options: selectedOptions,
customizedImg: customizedImg,
storeId: $page.data.storeId,
customizedData: customizedJson,
origin: $page.data.origin,
server: isServer,
cookies
})
if (selectedLinkiedProducts?.length) {
for (const i of selectedLinkiedProducts) {
cart = await CartService.addToCartService({
pid: i,
vid: i,
qty: 1,
storeId: $page.data.storeId,
origin: $page.data.origin,
server: isServer,
cookies
})
}
}
const response = await fetch('/server/cart')
cart = await response.json()
if (cart) {
const cookieCart = {
cartId: cart?.cart_id,
// items: cart?.items,
qty: cart?.qty,
tax: cart?.tax,
subtotal: cart?.subtotal,
total: cart?.total,
currencySymbol: cart?.currencySymbol,
discount: cart?.discount,
savings: cart?.savings,
selfTakeout: cart?.selfTakeout,
shipping: cart?.shipping,
unavailableItems: cart?.unavailableItems,
formattedAmount: cart?.formattedAmount
}
cookies.set('cartId', cookieCart.cartId, { path: '/', maxAge: 31536000 })
// cartButtonText = 'Added To Cart'
bounceItemFromTop = true
}
cartButtonText = 'Go to Cart'
p.qty < 0 ? fireGTagEvent('remove_from_cart', cart) : fireGTagEvent('add_to_cart', cart)
await invalidateAll()
// const res = await getAPI('carts/my')
} catch (e) {
// toast(e, 'error')
cartButtonText = 'Error Add To Cart'
} finally {
loading = false
// await delay(1000)
cartButtonText = 'Add to Bag'
bounceItemFromTop = false
}
}
// let windowHeight
// let cartButtonPosition = 0
// onMount(() => {
Expand Down
73 changes: 0 additions & 73 deletions src/lib/themes/varni-ace/ProductDetails.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -283,79 +283,6 @@ function handleSelectedLinkiedProducts(e) {
// This is used only for customized product else cart?/add
async function addToBag(p, customizedImg, customizedJson) {
try {
loading = true
cartButtonText = 'Adding...'
let cart = await CartService.addToCartService({
pid: p.id,
vid: p.id,
qty: 1,
options: selectedOptions,
customizedImg: customizedImg,
storeId: $page.data.storeId,
customizedData: customizedJson,
origin: $page.data.origin,
server: isServer,
cookies
})
if (selectedLinkiedProducts?.length) {
for (const i of selectedLinkiedProducts) {
cart = await CartService.addToCartService({
pid: i,
vid: i,
qty: 1,
storeId: $page.data.storeId,
origin: $page.data.origin,
server: isServer,
cookies
})
}
}
const response = await fetch('/server/cart')
cart = await response.json()
if (cart) {
const cookieCart = {
cartId: cart?.cart_id,
// items: cart?.items,
qty: cart?.qty,
tax: cart?.tax,
subtotal: cart?.subtotal,
total: cart?.total,
currencySymbol: cart?.currencySymbol,
discount: cart?.discount,
savings: cart?.savings,
selfTakeout: cart?.selfTakeout,
shipping: cart?.shipping,
unavailableItems: cart?.unavailableItems,
formattedAmount: cart?.formattedAmount
}
cookies.set('cartId', cookieCart.cartId, { path: '/', maxAge: 31536000 })
// cartButtonText = 'Added To Cart'
bounceItemFromTop = true
}
cartButtonText = 'Go to Cart'
p.qty < 0 ? fireGTagEvent('remove_from_cart', cart) : fireGTagEvent('add_to_cart', cart)
await invalidateAll()
// const res = await getAPI('carts/my')
} catch (e) {
// toast(e, 'error')
cartButtonText = 'Error Add To Cart'
} finally {
loading = false
// await delay(1000)
cartButtonText = 'Add to Bag'
bounceItemFromTop = false
}
}
// let windowHeight
// let cartButtonPosition = 0
// onMount(() => {
Expand Down
20 changes: 5 additions & 15 deletions src/routes/(app)/cart/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,6 @@ const add: Action = async ({ request, cookies, locals }) => {
return fail(400, { invalid: true })
}
try {
// let cart = await CartService.addToCartService({
// pid,
// vid: currentVariantId || vid,
// qty,
// options,
// customizedImg,
// customizedData,
// storeId: locals.storeId,
// cartId,
// origin: locals.origin,
// sid // This is a special case to pass complete cookie
// })
let cart = await CartService.addToCartService({
pid,
vid: currentVariantId || vid,
Expand All @@ -96,7 +84,7 @@ const add: Action = async ({ request, cookies, locals }) => {
storeId: locals.storeId,
cartId,
origin: locals.origin,
sid // This is a special case to pass complete cookie
sid
})
// if (!cartId) { // Commented out because when can't find cart_id in database, it will still won't set the new cart_id in cookies
cartId = cart.cart_id // This is required because when cart_id is null, it will add 3 items with null cart id hence last one prevails
Expand All @@ -117,7 +105,10 @@ const add: Action = async ({ request, cookies, locals }) => {
storeId: locals.storeId,
cartId,
origin: locals.origin,
sid // This is a special case to pass complete cookie
sid,
options,
customizedImg,
customizedData
})
}
}
Expand Down Expand Up @@ -153,7 +144,6 @@ const add: Action = async ({ request, cookies, locals }) => {
return {}
}
} catch (e) {
console.log('e', e)
return {}
}
}
Expand Down
27 changes: 0 additions & 27 deletions src/routes/(catalog)/reel/ReelSlider.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,6 @@ function toggleMute(product) {
product.muted = !product.muted
}
const addToCart = async ({ pid, qty, customizedImg, ix, loadingType }: any) => {
if (loadingType) {
selectedLoadingType = loadingType
}
loading[ix] = true
cartButtonText = 'Checkout Cart'
isAddedtoBag = true
try {
await CartService.addToCartService({
pid: pid,
vid: pid,
qty: qty,
customizedImg: customizedImg || null,
storeId: $page.data.storeId,
origin: $page.data.origin
})
await invalidateAll()
} catch (e) {
console.log(e)
} finally {
loading[ix] = false
selectedLoadingType = null
}
}
$: innerWidth = 0
let responsiveWidth = 0
$: if (innerWidth >= 640) {
Expand Down

0 comments on commit a0677d8

Please sign in to comment.