Cannot add Products to CodeIgniter Shopping cart class


Recently i came across with a problem with codeigniter shopping class implementation. That is some products cannot be added to shopping cart. Here is the reason for that.


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

So what you need to do is change the regex rule as follows.

Create a new class in application/libraries/My_Cart.php as follows and add the new regex rule.

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Cart extends CI_Cart
 function __construct()
 $this->product_name_rules = '\.\:\-_ a-z0-9|(\W)';

The new rule take care about any pattern in the product name . Problem solved 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s