zandoan / turing-frontend

41 stars 33 forks source link

Adding item to a cart/ creating a cart returns 500 due to incorrect cart_id #36

Closed kevinrblake closed 5 years ago

kevinrblake commented 5 years ago

I used the api to generate a unique cart Id then tried to add a product to a cart using that id and I got "Error: Invalid value { cart_id: '1xh7q2ze08jxcklvqr' }", however, that same cart_id works in Swagger.

Should I simply generate my own unique identifier or is there something I'm doing wrong? Also, it generates a cart when I send '' as a cart_id.

Product object; { cart_id: this.bagId, product_id: product.product_id, attributes: attributeString }

bagId is the generated id and attributeString is a combination of size and color seperated by a comma 'L, White'

Service method: static async addProductToCart(product) { try { const response = await axios.post('https:backendapi.turing.com/shoppingcart/add', product) return response.data } catch(error){ console.log(error) } }

edertaveiraturing commented 5 years ago

Hi Kevin. So, could you send me the complete JSON of that request?

kevinrblake commented 5 years ago

Looking at the Json ({"cart_id":"1xh7q2ze08jxdorebr"},"product_id":2,"attributes":"XL, Orange"}), I discovered that the cart_id returned from the api come back, not as a simple string but as an object and I wasn't pulling it out of the object. It's working now.

Thanks for the prompt answer though =)