Cart class weirdness |
[eluser]bendog[/eluser]
Hi, Just started looking at the latest release and played a bit with the cart class. I'm finding some design choice with the class a bit weird, thought I should report the findings if someone is running in the same problems.. Problem 1 The insert method seems to always wipe any existing matching entry with the same rowid.. line 235: unset($this->_cart_contents[$rowid]) This means that when you add an item to the cart a second time it basically replaces it.. most cart implementation have a "add to cart" button, not a "replace cart entry with this new item" button. Seems odd. Alternatively, if there was a way to know a) if an item is already in the cart b) what the quantity of that item is we could do a conditional if (item exist) update(old item with new quantity + old quantity) else insert(new item) but no function is provided to check if an item is already in the cart or what its quantity is (other than looping through the content, which seems a bit heavy handed) am I missing something? this version of the _insert function fixe the problem for me: Code: function _insert($items = array()) Problem 2 Finally, there is one more bug I think... the total_items method returns the number of unique rowids, not the number of products in the cart. line 392: $this->_cart_contents['total_items'] = count($this->_cart_contents); this should really be calculated at the same time as the total price is calculated. otherwise, all good Ben
[eluser]bendog[/eluser]
Forgot to post the fix for problem 2. Code: function _save_cart()
[eluser]jegbagus[/eluser]
hi bendog, really great post! here my opinion regarding your problem : Problem no 1. I think CI developer goes to the right way. there is a missing point in your post. user should also can reduce their quantity product. with your solution, they can't reduce their cart quantity, it will always increase. Problem no 2. yes i think you are right. they return number of unique item. not total of product in cart. but you can calculate easily with loop trough the array.
[eluser]InsiteFX[/eluser]
It's a CodeIgniter Library, if it doe's not do what you want just extend the Cart Library. Enjoy InsiteFX
[eluser]bendog[/eluser]
[quote author="jegbagus" date="1252938428"] there is a missing point in your post. user should also can reduce their quantity product. with your solution, they can't reduce their cart quantity, it will always increase. [/quote] The only practicle case where that would happen is when editing the cart, the update method should take care of that I think...
[eluser]bendog[/eluser]
[quote author="InsiteFX" date="1252985548"]It's a CodeIgniter Library, if it doe's not do what you want just extend the Cart Library. [/quote] I wasn't complaining about the library, I think it's great that CI provides the library. I'm just reporting on the problems I've come across and the solutions I've found in case someone was experiencing the same issues.
[eluser]jegbagus[/eluser]
bendog, you should put this post at featured request. or create extend for cart library and share it to us it will help this community much. regards.
[eluser]tashigiri[/eluser]
[quote author="jegbagus" date="1253003287"]bendog, you should put this post at featured request. or create extend for cart library and share it to us it will help this community much. regards.[/quote] im agree with that..^^
[eluser]Unknown[/eluser]
This is driving me crazy. I've spent days figuring this out. Yes, I have read other postings about this, but obviously I'm missing something (part of my brain perhaps). finding nemo Wisconsin Individual Health Insurance
[eluser]Unknown[/eluser]
Bendog thanks for posting your fixes! The new Cart class has saved me time in my current project, but that first problem was really bugging me. |
Welcome Guest, Not a member yet? Register Sign In |