darryldecode / laravelshoppingcart

Shopping Cart Implementation for Laravel Framework
1.32k stars 413 forks source link

issue in getcartcontent - Object's Key/Value #349

Open cheema14 opened 1 year ago

cheema14 commented 1 year ago

When I call cart's getcontent method it returns a json response to me. which is okay. But the problem is below: { "data": { "1667847103": { "id": 1667847103, "name": "Second Service", "price": 50, "quantity": 1, "attributes": { "id": 2, "booking_id": "2", "service_from": "01:00", "service_to": "01:10", "booking_day": "Monday", "item_type": "services", "variant": null, "extras": [], "restorant_id": 30, "image": "/uploads/service_items/e479b758-e38d-4fa3-b0c4-35571caa439a_thumbnail.jpg", "friendly_price": "€50.00" }, "conditions": [] }, "cart_items": { "id": 1667851688, "name": "new dimensions", "price": 100, "quantity": 1, "attributes": { "id": 7, "booking_id": "34", "service_from": "09:00", "service_to": "09:30", "booking_day": "Invalid Date", "item_type": "services", "variant": null, "extras": [], "restorant_id": 30, "image": "/uploads/service_items/cbe92aff-586f-447a-a2cc-baa5f95c22c5_thumbnail.jpg", "friendly_price": "€100.00" }, "conditions": [] } }, "total": 450, "quantity": 6, "status": true, "errMsg": "" }

There is a key which is actually id:1667847103 and then there is a key which I made "cart_items". As you know that in JS you cannot do anyObj.1667847103, so I added a key "cart_items" so that I would be able to do anyObj.cart_items.blah .blah

Whenever I add cart_items in the Cart's addRow method, it only adds the last item being added to the cart. but when I Revert the code it works fine.

Can somebody help me with that real quick? I am stuck!