Welcome Guest, Not a member yet? Register   Sign In
i have error cart
#1

[eluser]johanriyan[/eluser]
Hello guys,

please help me,

when i am submit buy, my cart not work,

here my Controller :

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Cart extends CI_Controller {

public function __construct(){
parent::__construct();
$this->load->model('m_admin');

}


public function index(){
$data['title']="Cart";  
$this->load->view('include/header',$data);
$this->load->view('include/menu');
$data['produk']=$this->m_admin->getProduk();
$this->load->view('v_cart',$data);
$this->load->view('include/footer');

}

public function add()
{
  $product = $this->m_admin->get($this->input->post('id'));
  $data = array(
   'id' => $this->input->post('id'),
   'qty' => 1,
   'price' => $product->price,
   'name' => $product->name
    );
  $this->cart->insert($data);
  redirect('cart');
}
}


and this is my view :

Code:
<ul class="thumbnails">
&lt;?php foreach($produk as $item){?&gt;
&lt;?php echo form_open('cart/add'); ?&gt;
<li class="span4">
  <div class="thumbnail">
    <img src="http://placehold.it/320x200" alt="ALT NAME">
    <div class="caption">
      <h3>&lt;?php echo $item->name;?&gt;</h3>
      <p>Rp. &lt;?php echo number_format($item->price,2,',','.');?&gt;</p>
      &lt;input type="hidden" name="id" value="&lt;?php echo $item-&gt;id ?&gt;"&gt;
      &lt;input type="submit" class="btn btn-primary btn-block" value="Buy"&gt;
    </div>
  </div>
</li>
&lt;?php }?&gt;
</ul>
<table class="table">

        <tbody>
        &lt;?php foreach($this->cart->contents() as $result): ?&gt;
          <tr>
            <td>&lt;?php echo $result['name'] ?&gt;</td>
            <td>Small</td>
            <td>
              &lt;input type="number"  45px; padding: 1px" value="0"&gt;
            </td>
            <td>&lt;?php echo $this->cart->total(); ?&gt;</td>
            <td>
              &lt;input type="number"  45px; padding: 1px" value="0"&gt;
            </td>
            <td>Large</td>
            <td>
              &lt;input type="number"  45px; padding: 1px" value="0"&gt;
            </td>
            <td>Ultra</td>
            <td>
              &lt;input type="number"  45px; padding: 1px" value="0"&gt;
            </td>
          </tr>
          &lt;?php endforeach; ?&gt;
          </tbody>
      </table>

This is my config :
Code:
$config['sess_cookie_name']  = 'ci_session';
$config['sess_expiration']  = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name']  = 'ci_sessions';
$config['sess_match_ip']  = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;

and autoload :

Code:
$autoload['libraries'] = array('database','pagination','session','form_validation','cart');


/*
| -------------------------------------------------------------------
|  Auto-load Helper Files
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['helper'] = array('url', 'file');
*/

$autoload['helper'] = array('url','form');


how to fix it.
i am using codeigniter version 2.1.3.
#2

[eluser]greedyman[/eluser]
$product->name, you need override regular expression of codeigniter for insert name includes utf-8.
#3

[eluser]johanriyan[/eluser]
Thk u greedyman for your respon.


I still do not understand. sorry to be clarified.

#4

[eluser]greedyman[/eluser]
[quote author="johanriyan" date="1373591899"]Thk u greedyman for your respon.


I still do not understand. sorry to be clarified.

[/quote]

Ok. You should create a file in /system/libraries/ folder, and put a content as below:
Code:
&lt;?php if ( !defined('BASEPATH')) exit('No direct script access allowed');

class MY_Cart extends CI_Cart {
    
    function __construct() {
        
        parent::__construct();
        
        // override product_name_rules to insert
        $this->product_name_rules = '\d\D'; // or '.*';
    }
    
}

/* End of file My_Cart.php */
/* Location: ./application/libraries/My_Cart.php */

Finally, autoload cart library. Let's try!




Theme © iAndrew 2016 - Forum software by © MyBB