darryldecode / laravelshoppingcart

Shopping Cart Implementation for Laravel Framework
1.34k stars 438 forks source link

New package with improved cart performance #344

Open izyy123 opened 2 years ago

izyy123 commented 2 years ago

Hello everybody,

when using an otherwise excellent library, I noticed that all changes to the shopping cart are immediately saved in the storage (session, database etc). The storage is also called e.g. when calling the getSubTotal() method, etc. - although in my opinion this is basically not necessary at all. As a result, the database can be completely unnecessarily overloaded (in my case, more than 30 myql queries were executed!). I changed the library a bit and created a new one. I would be happy if you could install and test it. I am definitely ready to implement all the changes in the basic library, but since the syntax has changed a bit and the new library is not 100% compatible with the basic one, I decided to create a new one.

Package - https://github.com/izyy123/laravelshoppingcart, https://packagist.org/packages/izyy123/cart

Only 3 commits are important - https://github.com/darryldecode/laravelshoppingcart/commit/ebc873b92c492c6f4fb3743e656e3866cf7c8945 https://github.com/darryldecode/laravelshoppingcart/commit/ebc873b92c492c6f4fb3743e656e3866cf7c8945 https://github.com/darryldecode/laravelshoppingcart/commit/8b69405ccc94b6b36ca5cba2aebafae8676685b3

Basically there are only two changes. Using session() method to set user key is mandatory and I implemented new save() method witch should be called whenever you want to save the cart into storage.

Comments are welcome. General about the performance of the core library and my updates.

Greetings