CodeIgniter Forums

Full Version: Problem with CodeIgniter Cart class
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]cysquan[/eluser]
Hello everyone, I'm having a little problem with the provided Cart class from CI

when I try to add a product that has name contains special character, the cart doesn't seem to work.

Code:
$data = array(  
                              'id'      => $id,  
                              'qty'     => '1',  
                              'price'   => $row->product_price_decimal,  
                              'name'    => "intel duo core"  
                      );
                 $this->cart->insert($data);

The code above is working with the name not contain any special character, however if I change the name to something similar to this (e.g 'name' => 'intel duo core 1/2') then the product is not added to cart.

How can I fix this?

Thanks in advance!

El Forum

[eluser]WanWizard[/eluser]
You will have to modify the product name rules: $this->cart->product_name_rules (a regex that is used to validate the name).

The default value is
Code:
$product_name_rules    = '\.\:\-_ a-z0-9'; // alpha-numeric, dashes, underscores, colons or periods

El Forum

[eluser]cysquan[/eluser]
Thanks a ton Big Grin

El Forum

[eluser]MikeeJay[/eluser]
And if you also would like to allow:

åäö ÅÄÖ é É

How should the regex look like?

El Forum

[eluser]WanWizard[/eluser]
Without having tried it: maybe this might be of some help: http://www.regular-expressions.info/unicode.html#prop. PHP uses the PRCE engine, which should support this.

El Forum

[eluser]Fabiano Shark[/eluser]
This worked for me:
Code:
$this->product_name_rules = '\d\D';


Isto resolve problemas de acentuação no carrinho de compras (cart) do codeigniter. Wink

Crédito: http://ellislab.com/forums/viewreply/811712/