Skip to content
This repository has been archived by the owner on Sep 1, 2021. It is now read-only.

400 Bad Request deleting Cart lines #48

Open
mrogers-5s opened this issue Feb 15, 2019 · 5 comments
Open

400 Bad Request deleting Cart lines #48

mrogers-5s opened this issue Feb 15, 2019 · 5 comments

Comments

@mrogers-5s
Copy link

I've got a Rails integration for tracking abandoned cart activity in Spree, but lately, it seems carts are failing to update -- specifically when an item is removed from the user's cart.

We've noticed that every DELETE request sent to /ecommerce/stores/{store_id}/carts/{cart_id}/lines/{line_id} returns a 400 error with In order to delete this line item, delete the parent resource.

The implication here is that if a customer deletes an item from their cart, in order to track that in MailChimp, we need to delete their entire cart and start over, which seems problematic.

Is there a different process we should be using to sync line item deletes?

@MatthewKennedy
Copy link

MatthewKennedy commented Jul 9, 2019

Did you manage to get this fixed?

@mrogers-5s
Copy link
Author

More or less.

Ultimately, due to the above error, updating a cart with line item changes requires us to delete any previously saved MailChimp record and resubmit it in order to post the updates. Though that functionally gives us what we need, it seems less efficient at it requires additional API calls:

ON UPDATE:

  • First, check to see if a cart already exists
  • If it exists, delete it
  • Post the complete cart record

The only other alternative I can see from the documentation would be to send patch/post/delete requests as needed for each line item individually, which I believe leads to more API calls than the above scenario.

Given how frequently a cart object changes during its lifetime, it seems like the Carts endpoint would benefit from create or update functionality

@MatthewKennedy
Copy link

Hi @mrogers-5s

Thanks for that, it will save me battling on trying to get that delete line item to work.

@MatthewKennedy
Copy link

MatthewKennedy commented Jul 12, 2019

Hi @mrogers-5s

I managed to get the delete line item to work in this fork, if you're interested.

https://github.com/MatthewKennedy/spree_mailchimp_ecommerce/blob/master/app/models/spree/line_item_decorator.rb

line 8 in the above file gets the info of the deleted line item then passes them to the delete_line_item method that organises and formats the data, and then passes the order number and line id to the job file below to execute the line item delete on the Mailchimp api:

https://github.com/MatthewKennedy/spree_mailchimp_ecommerce/blob/master/app/jobs/spree_mailchimp_ecommerce/delete_line_item_job.rb

This extension uses background jobs in Sidekiq, to create, update and destroy a Mailchimp cart, because of this to destroy and then re-create a cart for updating proved troublesome depending on how Sidekiq executed the jobs and if a retry was initiated.

@thor-juhasz
Copy link

@MatthewKennedy @mrogers-5s sorry to resurrect. But in case you still run into this, have you tried deleting a line item when it is not the last item in the cart? I just had this happen to me. If I have multiple line items, the request is successful. If it is the last one, it gives me this same error response.
In a way it makes sense, there is no point tracking a cart in Mailchimp that has no items.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants