Adding to the basket in the Codeigniter basket class

Thanks for taking the time to read this. Ive used the shopping cart class from the code igniter for the base cart, but I had one small problem. After adding the item to the cart, I redirect the user to the verification page, but when I click on the browser, the item is deleted. I know this because I have <?php echo anchor('cart','<strong>'.$this->cart->total_items(). '</strong> item(s)') ?> In the title , and it decreases upon return. This is really annoying, and I would like to fix it.

it is a form processing controller

 public function process () { if($this->input->post('submit')) { $product = $this->products_model->getProductRow($this->input->post('productid')); $data = array( 'id' => $product['id'], 'qty' => 1, 'price' => $this->product_helper->calcPrice($product['id']), 'name' => $product['name'] ); $this->cart->insert($data); redirect('cart'); //have tried using redirect('cart', 303); but doest do anything //have also tried flusing the buffer } else redirect('seatcovers');} 

Is there something trivial that I'm missing here, or is it something that needs to be changed in the CI bucket class?

Thank you very much

+4
source share
2 answers

I know a little old, but I had the same problem, the problem is that the library has a regex to limit the name of the element

 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 

change this or create your own custom cart.

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

I found a solution here http://darrenonthe.net/2011/05/03/cant-add-products-to-codeigniter-shop-cart-class/ ?

+1
source

Important: The Cart class uses the CodeIgniter session class to store basket information in the database, so before using the Cart class, you must configure the database table as described in the session documentation and set the session settings in your application / config / config.php file for use of the database.

I assume you did this too? The only suggestion I have for you is to remove the redirect, try to go to another page, and then go back to see if it supports the correct number.

In addition, you say that you use the return button to the browser. Have you tried refreshing the page to see if it uses a cached copy of the browser?

0
source

Source: https://habr.com/ru/post/1344981/


All Articles