longclawshop/longclaw

Request:Remove all or single product item from basket

mohdizzy opened this issue · 2 comments

Description

Great wagtail integration! Was trying to figure out on how to remove all items from the basket or a single product item. The current API allows subtracting the quantity of the product but not remove the product by itself.

For now, I just used the destroy_basket function from utils to get this done with an ajax call. I think may be making this as a separate API would be better.

Is the destroy function (https://github.com/JamesRamm/longclaw/blob/master/longclaw/basket/api.py) not enough to meet your needs? This would let you delete a single item:
DELETE /basket/<variant_id>

I think you can delete the whole basket by sending a PUT request with an empty array in the body to the basket endpoint:
something like

fetch(
`${host}/basket`,
{ method: 'PUT', body: JSON.stringify([]) }
)

Although I agree an explicit 'DELETE' endpoint would be more intuitive