Why codeigniter shopping cart class doesn't allow any special character in the name?

后端 未结 5 986
春和景丽
春和景丽 2020-12-29 09:32

I have a question just like in the title - Why codeigniter shopping cart class doesn\'t allow any special character in the name? When I\'m adding some item with normal name

相关标签:
5条回答
  • 2020-12-29 10:22

    I have changed $product_name_safe = FALSE; on system/libraries/Cart.php and fixed

    0 讨论(0)
  • 2020-12-29 10:24

    I just found this question from google while facing the same problem, but the answer ipalaus provided didn't fix my problem, because it still does not allow greek characters. After some more digging I found this :

    <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class MY_Cart extends CI_Cart {
    
        var $product_name_rules = '\d\D';
    
    }
    

    which basically allows everything. Enjoy!

    0 讨论(0)
  • 2020-12-29 10:24

    You can also optionally just modify the regular expression to allow quotes like so:

    $this->cart->product_name_rules = "\.\:\-_\"\' a-z0-9";
    
    0 讨论(0)
  • 2020-12-29 10:24

    This all does not help on UTF8 Characters (etc Serbian), but i have made something like, before putting in chart use like this

    $name=ucfirst(url_title(convert_accented_characters($name), ' ', TRUE));
    

    And modified ./application/config/foreign_chars.php

    $foreign_characters = array(
        '/ä|æ|ǽ/' => 'ae',
        '/ö|œ/' => 'oe',
        '/ü/' => 'ue',
        '/Ä/' => 'Ae',
        '/Ü/' => 'Ue',
        '/Ö/' => 'Oe',
        '/À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ/' => 'A',
        '/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª/' => 'a',
        '/Ç|Ć|Ĉ|Ċ|Č/' => 'C',
        '/ç|ć|ĉ|ċ|č/' => 'c',
        '/Ð|Ď|Đ/' => 'D',
        '/ð|ď|đ/' => 'd',
        '/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě/' => 'E',
        '/è|é|ê|ë|ē|ĕ|ė|ę|ě/' => 'e',
        '/Ĝ|Ğ|Ġ|Ģ/' => 'G',
        '/ĝ|ğ|ġ|ģ/' => 'g',
        '/Ĥ|Ħ/' => 'H',
        '/ĥ|ħ/' => 'h',
        '/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ/' => 'I',
        '/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı/' => 'i',
        '/Ĵ/' => 'J',
        '/ĵ/' => 'j',
        '/Ķ/' => 'K',
        '/ķ/' => 'k',
        '/Ĺ|Ļ|Ľ|Ŀ|Ł/' => 'L',
        '/ĺ|ļ|ľ|ŀ|ł/' => 'l',
        '/Ñ|Ń|Ņ|Ň/' => 'N',
        '/ñ|ń|ņ|ň|ʼn/' => 'n',
        '/Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ/' => 'O',
        '/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º/' => 'o',
        '/Ŕ|Ŗ|Ř/' => 'R',
        '/ŕ|ŗ|ř/' => 'r',
        '/Ś|Ŝ|Ş|Š/' => 'S',
        '/ś|ŝ|ş|š|ſ/' => 's',
        '/Ţ|Ť|Ŧ/' => 'T',
        '/ţ|ť|ŧ/' => 't',
        '/Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ/' => 'U',
        '/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ/' => 'u',
        '/Ý|Ÿ|Ŷ/' => 'Y',
        '/ý|ÿ|ŷ/' => 'y',
        '/Ŵ/' => 'W',
        '/ŵ/' => 'w',
        '/Ź|Ż|Ž/' => 'Z',
        '/ź|ż|ž/' => 'z',
        '/Æ|Ǽ/' => 'AE',
        '/ß/'=> 'ss',
        '/IJ/' => 'IJ',
        '/ij/' => 'ij',
        '/Œ/' => 'OE',
        '/š/' => 's',
        '/đ/' => 'd',
        '/č/' => 'c',
        '/ć/' => 'c',
        '/ž/' => 'z',
        '/Š/' => 'S',
        '/Đ/' => 'D',
        '/Č/' => 'C',
        '/Ć/' => 'C',
        '/Ž/' => 'Z',
        '/ƒ/' => 'f'
    ); 
    
    0 讨论(0)
  • 2020-12-29 10:31

    If you look on Cart.php you will see on line 31 var $product_name_rules = '\.\:\-_ a-z0-9';.

    A nice way to change this variable is putting a MY_Cart.php on your application\libraries\MY_Cart.php with this code:

    <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class MY_Cart extends CI_Cart {
    
        var $product_name_rules = '[:print:]';
    
    }
    

    Or you can also modify it when you add the product, using:

    $this->cart->product_name_rules = '[:print:]';
    $this->cart->insert(array());
    
    0 讨论(0)
提交回复
热议问题