📣 The forum has moved to GitHub
We’ve switched to GitHub Discussions as the hub for our community. This will improve the experience of collaborating for everyone, sharing what you’re working on, and discussing ideas for how Swell can be improved. Existing threads will remain open, but new posts are disabled.
Go to GitHub →Cannot create a cart anymore?
Since recently I am not able to add items to a cart anymore (it used to work 1-2 days ago).
Calling (1) swell.cart.setItems([])
works but when I try, e.g. (2) swell.cart.setItems([{id: '<some_id>', quantity: 1}])
I get a 404.
(1) cURL of the first request:
curl 'https://<storeid>.swell.store/api/cart/items' \ -X 'PUT' \ -H 'authority: storeid.swell.store' \ -H 'accept: application/json' \ -H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' \ -H 'authorization: Basic xxxyyyzzz' \ -H 'content-type: application/json' \ -H 'dnt: 1' \ -H 'origin: xyz' \ -H 'referer: xyz' \ -H 'sec-fetch-dest: empty' \ -H 'sec-fetch-mode: cors' \ -H 'sec-fetch-site: cross-site' \ -H 'sec-gpc: 1' \ -H 'x-session: xxx:yyy' \ --data-raw '[]' \ --compressed
Response = 200
----
(2) cURL of the second request:
curl 'https://storeid.swell.store/api/cart/items' \ -X 'PUT' \ -H 'authority: storeid.swell.store' \ -H 'accept: application/json' \ -H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' \ -H 'authorization: Basic xxxyyyzzz' \ -H 'content-type: application/json' \ -H 'dnt: 1' \ -H 'origin: xyz' \ -H 'referer: xyz' \ -H 'sec-fetch-dest: empty' \ -H 'sec-fetch-mode: cors' \ -H 'sec-fetch-site: cross-site' \ -H 'sec-gpc: 1' \ -H 'x-session: yyy' \ --data-raw '[{"id":"some_id_that_exists","quantity":1}]' \ --compressed
Response = 404
And on the client side I would see this error:
Access to fetch at 'https://storeid.swell.store/api/cart/items' from origin 'https://<xxx>.dev' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
What is going on?
Best Answer
-
Hello @Oleg @Hamed Bahram @Israel Pasos The reported issue was reviewed, and our team indicated that there could be some confusion around when to use the cart.items.id or the product.id, depending on the operation wanted.
For example:
In `swell.cart.setItems`, the argument should use product_id, instead of id, unless you already have an item with a given id.
- Set new items to a cart:
swell.cart.setItems([{product_id: '<some product.id>', quantity: 1}])
- Update existing items in a cart:
swell.cart.setItems([{id: '<an existing cart.items.id value>', product_id: '<some product.id>', quantity: 2}])
- Add an item to a cart:
swell.cart.addItem('<some product.id>')
- Remove an item from a cart:
swell.cart.removeItem(' <an existing cart.items.id value>')
This is also referenced in our docs, here: https://developers.swell.is/frontend-api/carts
Our team is working on improving our current documentation to make this clearer.
When you have a chance, can you please confirm if this corrects the issue you are running into?
1
Answers
-
Same applies to `await swell.cart.removeItem('<item_id>')`...
# i.e. curl 'https://<store_id>.swell.store/api/cart/items/<item_id>' \ -X 'DELETE' \ [...]
... which yields a 404 as well (with the same error as the one described in the original post).
Some other methods, e.g. `await swell.cart.addItem({...})` do work as expected, though. Something's definitely not right.
Developing with Swell is becoming a huge pain. I am wondering whether it is production-ready at all, since some things just do not work.
0 -
Hi @Oleg Very sorry for the inconvenience.
I could also reproduce this issue and I see a CORS error on
setItems
method with item details present in it.I raised a bug ticket internally for faster resolution.
1 -
Any update on this?
I have the same problem with `await swell.cart.removeItem('<item_id>')`
1 -
Any ETA for this? @Logesh Dinakaran
0 -
Our team is still working on it and I will update you once it is resolved. Thanks for your patience!
0 -
Started getting this today.
0 -
This issue is unfortunate given the fact that my project is brand new.
@Oleg I'm evaluating Swell. It seems you have a bit more experience with it. Would you recommend it?
0 -
@Oleg a 404 on the Cart endpoints generally mean you don't have access or it couldn't find the resource your were trying to change.
For the case you mentioned, it is possible that the item ID didn't match any cart items (the cart item ID is unique, and is not the product ID) - or your session token changed and you were trying to remove an item for a different cart.
@Israel Pasos could you share some of the issues you were getting as well?
0 -
If I understand it correctly:
- You add an item to the cart with
swell.cart.addItem("product_id")
- If you want to increase the quantity by 1, you can just call
swell.cart.addItem("product_id")
again - If you want to increase its quantity by
n
, you shouldawait swell.cart.addItem("product_id")
on step 1 (or `await swell.cart.get()` at some later point in time), then get into the response'scart.items
, iterate through that array to find theproduct_id
you just added and get theid
for it. Once you finally have found theid
you call `swell.cart.updateItem("id", { quantity: n })`. - Similar procedure to remove an item from the cart as described in the last point.
This seems to gain even more complexity if you want to work with
swell.cart.setItems
instead.Is it just me, or this is a bit screwed up?
I would expect to be working with just one identifier and not 2 (
product_id
andid
) - shouldn't we be able to uniquely identify a product with one identifier? - or at least when awaitingaddItem
to get theid
as a response, straight away, without having to iterate throughcart.items
.Also, the documentation does not really reflect this information (unless you already know about this nuance beforehand, of course).
Another observation I made and posted into another thread (for which there has been no response so far):
It seems that taxes do work when items are added to the cart using "swell.cart.addItem", but not when "swell.cart.setItem" is used instead.
Am I missing something here?
I think that Swell is a project with potential and I love what it's trying to achieve. But it is by no means production-ready. From what I see, the company is allocating much effort into creating integrations/partnerships with other tools/companies, but not improving/fixing the fundamental stuff.
I am pretty sure that you can build and ship a store on top of it, if you're very familiar with some nuances such as the aforementioned ones and are ready to build some workarounds here and there... but I mean... would you want to go that extra mile and take the risk associated with it? As of today, I have my doubts.
0 - You add an item to the cart with