Welcome Guest, Not a member yet? Register   Sign In
[solved] cart class. How to add an item with a name incluiding latin characters?
#1

[eluser]chefnelone[/eluser]
Hello
I'm using the cart class.

I have no problem adding an item like:

Code:
$data = array(                
                        'id' => '1',
                        'qty' => '5',
                        'price' => '1000',
                        'name' => 'classic'
                        
                );
    
$this->cart->insert($data);

but, if 'name' has latin characters it doesn't work:
Code:
$data = array(                
                        'id' => '1',
                        'qty' => '5',
                        'price' => '1000',
                        'name' => 'clásico' //the problem is the 'clásico' word
                        
                );
    
$this->cart->insert($data); //it doesn't add this item

How can I fix this?
#2

[eluser]JHackamack[/eluser]
Is your database set up to accept utf-8 characters?
#3

[eluser]chefnelone[/eluser]
Yes, but I'm not saving the cart's data in the database anyway...
#4

[eluser]JHackamack[/eluser]
From the documentation:

The Cart class utilizes CodeIgniter's Session Class to save the cart information to a database
#5

[eluser]chefnelone[/eluser]
I'm lost...

but I think that saving the data in a database is optional?
It saves the data in a Cookie.

I didn't create any table in the database to save the data; and except this isssue the cart class is working fine.
#6

[eluser]chefnelone[/eluser]
You'r right.

I missed that from de documentation.

I have created the table for saving sessions.
#7

[eluser]JHackamack[/eluser]
There is also the possibility of this:

It could also be with the configurations files in the cart class:
Code:
var $product_id_rules    = '\.a-z0-9_-'; // alpha-numeric, dashes, underscores, or periods
    var $product_name_rules    = '\.\:\-_ a-z0-9'; // alpha-numeric, dashes, underscores, colons or periods

in conjunction with this
        if ( ! preg_match("/^[".$this->product_name_rules."]+$/i", $items['name']))
        {
            log_message('error', 'An invalid name was submitted as the product name: '.$items['name'].' The name can only contain alpha-numeric characters, dashes, underscores, colons, and spaces');
            return FALSE;
        }

It doesn't look like in your code you're checking for false returns, so it might be hitting against the preg_match and failing.
#8

[eluser]chefnelone[/eluser]
ok, it's clear that the line

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

states that character like á, é, à, etc. are not allowed.

What if I change the rule to force to accept them ? If so, how can I do this?
#9

[eluser]JHackamack[/eluser]
You can change the rule to accept them. Rules are meant to be broken. Changing this is above my head, so somebody else will have to give you guidance on this.
#10

[eluser]chefnelone[/eluser]
Maybe not the best solution, but it worked for me

Code:
var $product_name_rules    = '\.\:\-_ a-z0-9áéíóúàèìòùñç\'';




Theme © iAndrew 2016 - Forum software by © MyBB