When adding item to cart API makes request to https://undefined.swell.store/api/cart/items #254
-
I am currently running into an issue with the swell js frontend API. I am able to retrieve products with no issue. However, when adding to the cart. The API is trying to make this request...
This is my init file for swell: import swell from 'swell-js'
import { env } from "@/env.mjs";
const options = {
useCamelCase: false
}
swell.init(
env.NEXT_PUBLIC_SWELL_STORE_ID,
env.NEXT_PUBLIC_SWELL_PUBLIC_KEY,
options
)
export default swell This is my library file for adding to cart and getting cart object: import swell from '../../../swell';
export const addToCart = async (productId: string, quantity: number) => {
return await swell.cart.addItem({
productId: productId,
quantity: quantity
});
}
export const getCart = async () => {
console.log(await swell.cart.get());
return await swell.cart.get();
} And this is the function within the React Component: const buyNow = async (slug: string) => {
// add to swell cart
const addItem = await addToCart(slug, 1);
const cart = await getCart();
console.log(cart);
} I am guessing there is some issue with the store id, which is where undefined should be. Any help with how I can solve this or get around this? Thank you in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @KermitTheFr0g, could you check if |
Beta Was this translation helpful? Give feedback.
-
Hey @KermitTheFr0g, I ran into the same issue initially and setting it up like this is what worked for me:
|
Beta Was this translation helpful? Give feedback.
Hi @KermitTheFr0g, could you check if
env.NEXT_PUBLIC_SWELL_STORE_ID
has a defined value when callingswell.init
? That could be one of the reasons you're getting undefined there.