Crinsane / LaravelShoppingcart

A simple shopping cart implementation for Laravel
MIT License
3.67k stars 1.73k forks source link

Can you just create a getRowID function? #625

Open kev1ncal opened 4 years ago

kev1ncal commented 4 years ago

Is this some kind of magical way of getting an item in the cart? Why do you have to make the rowId as the most important thing to search for items inside the cart? e.g get() function requires rowId instead of the given ID?

bumbummen99 commented 4 years ago

Take a look at https://github.com/Crinsane/LaravelShoppingcart/blob/f460ab7312cce32cb428cf39a500a2d16600b1d6/src/CartItem.php#L330 RowID is based on the ID and Options so you can add the same Product but with different options resulting in different Positions/Items on the Cart. For example if you add a Product instance it has multiple variances like color or size etc which should be treated as seperate positions in the calculation but not necessarily as seperate models in your data structure, therefore the identifier for the CartItem has to be a combination of the ID and the options (hash).