Home > CodeIgniter > Cannot add Products to CodeIgniter Shopping cart class

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.

</pre>
<?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
<pre>?>

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()
 {
 parent::__construct();
 $this->product_name_rules = '\.\:\-_ a-z0-9|(\W)';
 }
}

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

Advertisements
Categories: CodeIgniter
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: