CodeIgniter Cart library doesnt support cyrillic characters in the product name

Jan 22, 2011 Author: Dr_ViRuS

Web Developers is happy people no they don't.

Why?

When you start some new project u must become Lawyer, Doctor, priest etc.. to understand other cultures, their customs, alphabets religious prohibitions, whether written from left to right or vice versa, which encoding they use and similar trifles. And after that your starting with your technical "highly technological problems"

Developing one project for Cyrillic alphabet region i had problem with Codeignatier Cart library because by default CI Cart Library support only Latin charters . Bright side of the coin is that someone before me already had the same problem

CI Cart Library have a filter for titles with a regexp only allowing
alpha-numeric, dashes, underscores, colons or periods

var $product_name_rules    = '\.\:\-_ a-z0-9';

Solution 1 on Russian way

Just find and comment out the following part from system/libraries/Cart.php:

  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;
}

Solution 2 Recommended

After you loading Cart lib add this

   $this->cart->product_name_rules .="_-а-яА-Я ";
 

Example

 class Basket extends Controller
 {
        function Basket ()
        {
            parent::Controller();
            $this->load->library('cart');
            $this->cart->product_name_rules .="_-а-яА-Я ";
 }

I hope i helped you to fix this "bug" and you get your payment :)
Note : Don't forget to set ci_sessiosn table in UTF-8


views 577640
  1. Add New Comment

gravatar
Mr. Anonymus
May 22,2011 at 00:43:05
Thanks for this tip! It saved me. If you use autoload for loading "cart" library, you can add the "Solution 2" operator string into a class constructor.
gravatar
Anonymus
March 10,2012 at 00:31:01
Tnx you save my time with this tutorial for cyrillic characters support in CodeIgniter
gravatar
MIchail1982
September 10,2012 at 07:49:11
Right way is extends CI_Cart. Sample at on http://code-igniter.ru/forum/viewtopic.php?f=4&p=31693#p31693
gravatar
Mohit Singh
February 22,2016 at 17:16:02
Thanks for the great solution, sometimes small things takes too much to be solved. This line "Note : Don't forget to set ci_sessiosn table in UTF-8" saved me. Thanks a Lot