简体   繁体   中英

Codeigniter cart

I am new and I don't know much. I tried several ways but still nothing. It's not working this way.

public function addToCart(){
    $product_url=md5($this->input->post('produktUrl'));
    $cart['id']=$product_url;
    $cart['qty']=$this->input->post('kol');
    $cart['price']=$this->model->cena($this->input->post('produktUrl'));
    $cart['name']=$this->input->post('produktUrl');
    $cart['ime']=$this->input->post('ime');

    $cart['options']['size']=$this->input->post('golemina');
    $cart['options']['color']=$this->input->post('boja');


    foreach ($this->cart->contents() as $key) {
            if($cart['id']==$key['id']){
                $cart['rowid']=$key['rowid'];
                $cart['qty']=$this->input->post('kol');
                $this->cart->update($cart);
            } else {
                $this->cart->insert($cart);
            }
        }
    print_r($this->cart->contents());
}

I don't actually know what your problem is, but you can try this one:

public function addToCart() {
    $product_url = md5($this->input->post('produktUrl'));

    $data = array(
        'id'      =>    $product_url,
        'qty'     =>    $this->input->post('kol'),
        'price'   =>    $this->model->cena($this->input->post('produktUrl')),
        'name'    =>    $this->input->post('produktUrl'),
        'options' => array(
                'ime'   =>  $this->input->post('ime'), 
                'size'  =>  $this->input->post('golemina'),
                'color' =>  $this->input->post('boja')
        )
    );
    $this->cart->insert($data);
    print_r($this->cart->contents());
}

also, make sure that you've loaded this in application/config/autoload.php

$autoload['libraries'] = array('database' , 'session', 'cart');

I hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM