![]() |
Cart: updating the "options" array - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Cart: updating the "options" array (/showthread.php?tid=27345) |
Cart: updating the "options" array - El Forum - 02-08-2010 [eluser]stef25[/eluser] The options array in the Cart class exists to store additional data that does not include the 4 default values of id, quantity, price and name. I have a few extra fields, one of which is "duration" (im using the cart to build a reservation system for items that can be rented) When I run the code below, the cart->update() always fails. Is it possible to update the options array? Code: $product['duration'] = $this->input->post('new_duration'); The cart_data array is below, which should be all ok? I know I'm storing duplicate values in the options array but I don't think this matters ... Code: Array Why is this failing? Cart: updating the "options" array - El Forum - 02-08-2010 [eluser]stef25[/eluser] OK, I think it's because I'm not passing the rowid value ... Cart: updating the "options" array - El Forum - 03-01-2010 [eluser]packetfox[/eluser] Hello, have you solved this issue? I also would like to update values stored in the options array, but i think it will not work without a custom piece of code that extends the cart class. From what i can see, the cart->update() function only takes care updating the Value for the Quantity Field, but leaves what is in the options array untouched. Cart: updating the "options" array - El Forum - 03-01-2010 [eluser]stef25[/eluser] It's not possible to update the options array; I made some modifications in the cart class, but modifying the core is not really recommended ... Cart: updating the "options" array - El Forum - 03-01-2010 [eluser]packetfox[/eluser] I know its not recommended, but maybe a quick fix before i get down extending the class. Is it convenient / possible to share your code modification? Thanks either way and have a great day. Cart: updating the "options" array - El Forum - 03-01-2010 [eluser]stef25[/eluser] Actually I just modified it so I can update just one option specific to my application, that is the "duration" field. I'm using the cart to "reserve" items for rental that are then picked up at the stores. Code: if ($this->_cart_contents[$items['rowid']]['qty'] == $items['qty']) changed to Code: if ($this->_cart_contents[$items['rowid']]['qty'] == $items['qty'] AND $this->_cart_contents[$items['rowid']]['duration'] == $items['duration']) Where it says Code: $this->_cart_contents[$items['rowid']]['qty'] = $items['qty']; I added Code: $this->_cart_contents[$items['rowid']]['duration'] = $items['duration']; I think that's it. Cart: updating the "options" array - El Forum - 03-01-2010 [eluser]packetfox[/eluser] Excellent, thanks a lot. Ill need to revisit this, but for now it allowed me to process an extra field. Once i found a nice and solid way to process the options array i will share it here. best regards, DS Cart: updating the "options" array - El Forum - 05-19-2010 [eluser]The Questioner[/eluser] I've been working on my own ecommerce site based upon the cart class. Along the way, I've extended the cart class for some much-needed functionality. Here are the most useful functions (all to be placed in the cart class):- To check if a cart item exists (by row ID): Code: function does_cart_item_exist($strRowID) To retrieve a specific cart product item (by row ID): Code: function get_cart_item($strRowID) To replace the contents of a cart product item with updated values (by row ID): Code: function update_existing_cart_item($strRowID, $arrData) $arrData has to contain the full array that is used when inserting a new cart item, as well as the rowid. For example: Code: //prepare all details for updated cart item I hope this helps my fellow CodeIgnities. |