bumbummen99 / LaravelShoppingcart

A simple shopping cart implementation for Laravel
MIT License
505 stars 234 forks source link

Restoring from database breaks associative model connection on last CartItem #120

Closed bureauvk closed 3 years ago

bureauvk commented 3 years ago

For some reason when restoring the cart from the database, the last item's associative model is set to NULL. For all other items the associative model is fine, only the last item in the cart array loses its connection to the associative model.

Anyone else experiencing this issue?

-

It seems, when a cart is stored, the last CartItem does not keep the CartItemassociatedModel value.

Example I have 6 products in the cart. (cart is stored in DB) The last CartItem's associated model value is NULL. (it should be '\App\Models\Product' like the rest)

When I add another Item to the cart. I erase the currently stored cart, ( Cart::erase($identifier) ) And store the new cart with 7 items ( Cart::store($identifier) )

The 6th item, that just had NULL on its associated model, now does have the expected value. But the item just added (7th) has NULL for its associated model.

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days