Problems with the cart class |
[eluser]Brayan[/eluser]
I have 2 problems: 1 . I can’t add products that names have slashes to the cart.. they are not added other products that dont have slashes are usually added 2. On the cart->update(), I want to update the price of the product too, but it doesn't work I only can update the quantity ? on the user guide its just quantity that they show on example :-( There is a way to solve this problems ? thank's a lot and sorry for the bad english =\
[eluser]scud[/eluser]
I've got similar problem with cart. If I could not solve it I try to you my own library. Probably it's the best one for me.
[eluser]nelson.wells[/eluser]
Look at the cart class around line 141 and find this function definition Code: function _insert($items = array()) That function contains rules for adding items to the cart, and the comments describe how to change the rules. I can't really help you with the second problem right now as I have never ran into it and don't have time. I'll try to look at it when I get home tonight. Good luck.
[eluser]scud[/eluser]
Great thanks for your help. I've looked around find some advices. Now I try to add a helper to cart
[eluser]Brayan[/eluser]
Thanks ! but the 1st problem I already solved.. I just commented these lines: Code: if ( ! preg_match("/^[".$this->product_name_rules."]+$/i", $items['name'])) now will add any product anyway.. the second problem still alive =\
[eluser]nelson.wells[/eluser]
After looking at the cart->update function, it will only update the quantity. Does anyone know if they plan on making that function more flexible in CI 2? I don't like that the update function is only useful for updating the price. If they don't plan on making it more flexible, maybe I will lend my hand at it... Here is a quick and dirty solution. You should take more validation and error checking steps, but this will get the job done in a hurry. Code: class MY_Cart extends CI_Cart Put that in the file MY_Cart.php in the libraries folder. You call it like this Code: $data = array( Please note that the function does not accept an array of items. You'll have to do some additional programming to do that
[eluser]nelson.wells[/eluser]
I've written a better solution that someone may be interested in. This will let you update any index in the cart class (that is not an array, it doesn't do that yet). You can follow progress at the BitBucket project or read more about it on my blog. Code: class MY_Cart extends CI_Cart
[eluser]Dule[/eluser]
Actually, this is the code of MY_Cart.php library, posted by nelson.wells, I just debugged it ($item instead of $items), and now it works fine: lets you update not only quantity, but also any other index in your cart, such as name or price. Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Code: $this->cart->update($data); Code: $this->cart->update_all($data); |
Welcome Guest, Not a member yet? Register Sign In |