Insert records cart codeigniter

0

I have the following PHP

if($this->input->post('stock_unity_push')=='0'){
    $stock_unity_push = 0;
} else {
    $stock_unity_push = str_replace(".", "", str_replace("R$ ", "", $this->input->post('stock_unity_push')));
    $stock_unity_push = number_format((float)$stock_unity_push, 2, '.', '');
}

$data = array(
    'id'      => $this->input->post('product_id'),
    'qty'     => $this->input->post('stock_purchase'),
    'price'   => ($stock_unity_push) ? $stock_unity_push : '0',
    'name'    => 'product_'.$this->input->post('product_id')
    //'options' => array('supplier' => $this->input->post('supplier'))
);

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

But to add to the cart, it adds only one record, and replaces the current cart. I'm using the codeigniter cart.

    
asked by anonymous 11.12.2018 / 20:22

1 answer

1

According to documentation the way to add more than one item is doing so.

$data = array(
        array(
                'id'      => 'sku_123ABC',
                'qty'     => 1,
                'price'   => 39.95,
                'name'    => 'T-Shirt',
                'options' => array('Size' => 'L', 'Color' => 'Red')
        ),
        array(
                'id'      => 'sku_567ZYX',
                'qty'     => 1,
                'price'   => 9.95,
                'name'    => 'Coffee Mug'
        ),
        array(
                'id'      => 'sku_965QRS',
                'qty'     => 1,
                'price'   => 29.95,
                'name'    => 'Shot Glass'
        )
);

However you can use the array_push function to mount your $ data and only at the end call the insert method.

    
11.12.2018 / 20:49