Reputation: 641
I am using the cart library in Codeigniter. I am using this :
$product = array(
'id' => $product_id,
'qty' => $product_qty,
'price' => $product_price,
'name' => $product_name,
'attr_id' => $product_attr_id,
'short_desc'=> $product_short_desc,
'options' => array('size_id' => $product_size_id)
);
$this->cart->insert($product);
Some products are not being added because it has disallowed characters in name. I want to remove that restriction. I commented this code in my_project/system/libraries
:
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;
}
But its still not adding to cart. Can someone help me in this ?
Upvotes: 2
Views: 3018
Reputation: 21
Try the following code:
$this->cart->product_name_rules = '[:print:]';
$this->cart->insert(array());
Upvotes: 1
Reputation: 641
I was using this function before adding anything to the cart.. product name or id or anything..
function quote_smart($string)
{
$string = html_entity_decode($string);
$string = strip_tags($string);
$string = trim($string);
$string = htmlentities($string);
$string = preg_replace('/\s+/', ' ',$string); // Removing more than one space/Tab.
// Quote if not integer
if (!is_numeric($string))
{
$string = mysql_real_escape_string($string);
}
return $string;
}
I just removed it and it worked!! Thanks evryone for your answers.
Upvotes: 1
Reputation: 5689
Just Try:
In system/libraries/Cart.php You can find :
<?php
class CI_Cart {
// These are the regular expression rules that we use to validate the product ID and product name
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
?>
Don't make changes in above file but Create a new file called My_Cart.php in application/libraries, and enter the following code:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Cart extends CI_Cart
{
function __construct()
{
parent::__construct();
$this->product_name_rules = '\d\D'; //This will override `$product_name_rules` rule from system/libraries/Cart.php
}
}
?>
This solution involves overriding the Cart class and clearing the name restrictions.
Upvotes: 4