Welcome Guest, Not a member yet? Register   Sign In
Odd Cart Behavior
#1

[eluser]RMinor[/eluser]
I am offering free products if certain criteria are met and I am getting the following error when I try to add the free product to the cart "ERROR - 2012-06-26 16:14:13 --> An invalid price was submitted for product ID: 38". I am trying to send the price as 0.00, and i have also tried (float)0.00, and '0.00'. Nothing works. Does anyone have any ideas?
#2

[eluser]InsiteFX[/eluser]
Try .00 if not then you would need to extend the cart class and fix it the current function removes all 0 before the decimal point.
#3

[eluser]RMinor[/eluser]
That did not work. Are there any updates to the cart class that would fix this. I am using version 2.1.0 right now.
#4

[eluser]RMinor[/eluser]
Nothing I have tried thus far has worked. What would I need to do as far as extending the cart class that would enable it to accept 0.00 as a price?
#5

[eluser]Matalina[/eluser]
does 0 not work?

this is what I do:

Code:
$data = array(
       'id'      => $model_id,
       'qty'     => 1,
       'price'   => '0.00',
       'name'    => $model_id
    );
#6

[eluser]RMinor[/eluser]
I had that at first. Here is my add method from my cart controller. Note that in this particular instance the 'free_nail' or 'free_tanktop' attribute will be TRUE, so the price gets reset as 0.00 (I have included comments where it happens). The error logs are telling me that the price is invalid.

Code:
public function add($options_to_check = array('color', 'size', 'free_nail', 'free_tanktop'))
{
    $this->load->model('Cart_model');
    if ($this->input->post('free_nail')) {
        $price = 0.00; // price is set here
        $this->session->set_userdata('free_nail', TRUE);
    } elseif ($this->input->post('free_tanktop')) {
        $price = 0.00; // price is set here
        $this->session->set_userdata('free_tanktop', TRUE);
    } else {
        $price = $this->Cart_model->getProductPrice($this->input->post('id'));
    }
    $data = array(
        'id'    => $this->input->post('id'),
        'name'  => str_replace('/', '-',$this->input->post('name')),
        'qty'   => (int)$this->input->post('quantity'),
        'price' => (float)$price
    );
    $options = array();
    foreach($options_to_check as $option) {
        if($this->input->post($option)) {
            $options[$option] = str_replace('/', '-', $this->input->post($option));
        }
    }
    if(count($options)) {
        $data['options'] = $options;
    }
    if ($this->cart->insert($data)) {
        if (!$this->input->is_ajax_request()) {
            redirect('cart');
        } else {
            $this->output
                ->set_content_type('application/json')
                ->set_output(json_encode(array('message' => 'TRUE', 'data' => $data)));
        }
    } else {
        if ($this->input->is_ajax_request()) {
            $this->output
                ->set_content_type('application/json')
                ->set_output(json_encode(array('message' => 'FALSE', 'data' => $data)));
        }
    }
}
#7

[eluser]Matalina[/eluser]
The difference between my code and your code is:

Code:
$price = '0.00' // a string
$price = 0.00 // a float



#8

[eluser]RMinor[/eluser]
The weird thing is that I had it as '0.00' too and it still would not work.
#9

[eluser]Matalina[/eluser]
You also have:

Code:
'price' => (float)$price
#10

[eluser]RMinor[/eluser]
Well, I put the price variable as a float
Code:
$price = 0.00;
and it still doesn't work. Is there some sort of bug in the cart class? This is really driving me crazy.




Theme © iAndrew 2016 - Forum software by © MyBB