CodeIgniter Forums
Cart doesn't insert - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Cart doesn't insert (/showthread.php?tid=34239)



Cart doesn't insert - El Forum - 09-23-2010

[eluser]dalunatic[/eluser]
Working on my first CI project. Now adding the library cart; using the User Guide and googled tuts. However, I cannot seem to add/insert any product to the cart session where there is an empty array directly after the insert(). I am quite sure to have it setup correctly (db, config).

Please who can shine a light in the dark?

Code:
class Cart extends Controller {

    function Cart()
    {
        parent::Controller();
        $this->load->model('cart_model');
    }
    function index()
    {
        $this->load->view('cart/mandje_index');
    }
    function add($aid)
    {
        $this->load->model('products_model');
        $data['product'] = $this->products_model->A_Product_Details($aid);
        $data['pr_pics'] = $this->products_model->A_Product_With_Pics($aid);
        
        $add_this = array(
            'id'        => $data['product'][0]->a_id,
            'qty'         => 1,
            'price'        => $data['product'][0]->a_price,
            'name'        => $data['product'][0]->a_name,
            'options'    => array('Size' => $data['product'][0]->a_dimension    )
            );
            /*,'Color' => $data['product'][0]->a_color
                ,'Weight' => $data['product'][0]->a_weight
                ,'Extra' => $data['product'][0]->a_extra
                ,'Deliverytime' => $data['product'][0]->a_deliverytime
                */
        //print_r($add_this); // no empty values    

        $this->cart->insert($add_this);

        print_r($this->cart->contents()); // output: Array()

        //$this->load->view('cart/mandje_index');
    }
}



Cart doesn't insert - El Forum - 09-23-2010

[eluser]WanWizard[/eluser]
What is the return value of
Code:
$this->cart->insert($add_this);
it will return FALSE if the insert failed, TRUE if it succeeded.

If it returns FALSE, the log will tell you why (if you set the log_threshold to 'error' or higher).


Cart doesn't insert - El Forum - 09-23-2010

[eluser]dalunatic[/eluser]
In if/else statement it returned FALSE. No explanation unfortunately although
Code:
$config['log_threshold'] = 4;
is set.


Cart doesn't insert - El Forum - 09-24-2010

[eluser]WanWizard[/eluser]
Looking at the code, it only returns FALSE without logging an error when:
- the 'id' field is missing from the array (doesn't seem to be the case here)
- the 'qty' field is zero or not numeric (doesn't seem to be the case here)

In all other cases there's a log_message() before returning FALSE.


Cart doesn't insert - El Forum - 09-24-2010

[eluser]dalunatic[/eluser]
Thanks for your swift advice WanWizard!

This is what i found in the log file (thought you meant it would produce an error while executing the script). Guess there's a mistake here and thus no ID...

DEBUG - 2010-09-24 10:00:43 --> Config Class Initialized
DEBUG - 2010-09-24 10:00:43 --> Hooks Class Initialized
DEBUG - 2010-09-24 10:00:44 --> URI Class Initialized
DEBUG - 2010-09-24 10:00:44 --> Router Class Initialized
DEBUG - 2010-09-24 10:00:44 --> Output Class Initialized
DEBUG - 2010-09-24 10:00:44 --> Input Class Initialized
DEBUG - 2010-09-24 10:00:44 --> XSS Filtering completed
DEBUG - 2010-09-24 10:00:44 --> XSS Filtering completed
DEBUG - 2010-09-24 10:00:44 --> XSS Filtering completed
DEBUG - 2010-09-24 10:00:44 --> Global POST and COOKIE data sanitized
DEBUG - 2010-09-24 10:00:44 --> Language Class Initialized
DEBUG - 2010-09-24 10:00:45 --> Loader Class Initialized
DEBUG - 2010-09-24 10:00:45 --> Helper loaded: form_helper
DEBUG - 2010-09-24 10:00:45 --> Helper loaded: url_helper
DEBUG - 2010-09-24 10:00:45 --> Database Driver Class Initialized
DEBUG - 2010-09-24 10:00:45 --> Session Class Initialized
DEBUG - 2010-09-24 10:00:45 --> Helper loaded: string_helper
DEBUG - 2010-09-24 10:00:45 --> Encrypt Class Initialized
DEBUG - 2010-09-24 10:00:45 --> Session routines successfully run
DEBUG - 2010-09-24 10:00:46 --> Cart Class Initialized
DEBUG - 2010-09-24 10:00:46 --> Session class already loaded. Second attempt ignored.
DEBUG - 2010-09-24 10:00:46 --> Form Validation Class Initialized
DEBUG - 2010-09-24 10:00:46 --> Model Class Initialized
DEBUG - 2010-09-24 10:00:46 --> Controller Class Initialized
DEBUG - 2010-09-24 10:00:46 --> Model Class Initialized
ERROR - 2010-09-24 10:00:46 --> An invalid price was submitted for product ID: 7
DEBUG - 2010-09-24 10:00:46 --> Language file loaded: language/english/profiler_lang.php
DEBUG - 2010-09-24 10:00:46 --> Helper loaded: text_helper
DEBUG - 2010-09-24 10:00:47 --> Final output sent to browser
DEBUG - 2010-09-24 10:00:47 --> Total execution time: 2.9402