开发者

Shopping Cart not working properly in codeigniter

I’m trying to add items to the shopping cart but it will only add the first 6 items to the cart. The rest don’t seem to get added.

I’ve checked the arrays and they have the required id, qty, price, and name. What am I doing wrong?

Here is the code:

function add_cart_item() {

    $id = $this->input->post('product_id'); // Assign posted product_id to $id
    $cty = $this->input->post('quantity'); // Assign posted quantity to $cty
    $colors = $this->input->post('color_id'); // Assign posted color to $colors
    $sizes = $this->input->post('size_id'); // Assign posted size to $sizes

    $warna = "warna";
    $ukuran = "ukuran";

    //Ini untuk warna
    $sqlNameColor = 'SELECT NAME FROM ref_colors WHERE ID = "'.$colors.'"';
    $queryNameColor = $this->db->query($sqlNameColor);
    $color_id = $queryNameColor->row()->NAME;

    //Ini untuk ukuran
    $sqlNameSize = 'SELECT NAME FROM ref_sizes WHERE ID = "'.$sizes.'"';
    $queryNameSize = $this->db->query($sqlNameSize);
    $size_id = $queryNameSize->row()->NAME;

    //Ini untuk weight
    $sqlWeight = 'SELECT WEIGHT FROM v_weight WHERE PRODUCT_ID = "'.$id.'"';
    $queryWeight = $this->db->query($sqlWeight);
    $weight = $queryWeight->row()->WEIGHT;

    $product = $this->model_product->get($id);


    $data = array(
                'id'      => $id,
                'qty'     => $cty,
                'price'   => $product->PRICE,
                'name'    => $product->NAME,
        'colors'  => $color_id, 
        'sizes'   => $size_id,
        'colors_id' => $colors,
        'weight' => $weight,
        'size_id' => $this->input->post('size_id'),
        'image'   => $product->IMAGE,
        'options'=>array('Size' => $this->input->post('size_id'), 'Color' => $this->input->post('color_id'))


            );

            $this->cart->insert($data);
    $data['cart_list'] = $this->cart->contents(); 
    show_shoppingcart('shoppingcart_view', $data);

}

The problem is when i add option value in my cart.

Here is the arrays result:

Array (
[698d51a19d8a121ce581499d7b701668] => Array
    (
        [rowid] => 698d51a19d8a121ce581499d7b701668
        [id] => 1
        [qty] => 1
        [price] => 10000
        [name] => Nike superfly Merah
        [colors] => MERAH
        [sizes] => 34
        [colors_id] => 1
        [weight] => 
        [size_id] => 1
        [image] => assets/images/product/SB 02 - 03 Nike superfly3 merah.jpg
        [options] => Array
            (
                [Size] => 1
                [Color] => 1
            )

        [subtotal] => 10000
    )

[caf1a3dfb505ffed0d024130f58c5cfa] => Array
    (
        [rowid] => caf1a3dfb505ffed0d024130f58c5cfa
        [id] => 3
        [qty] => 1
        [price] => 30000
        [name] => Nike Superfly ungu
        [colors] => MERAH
        [sizes] => 35
        [colors_id] => 1
        [weight] => 
        [size_id] => 2
        [image] => assets/images/product/thumbs/T SB 02 - 02 nike superfly3 ijo Stabilo 3.jpg
        [options] => Array
            (
                [Size] => 2
                [Color] => 1
            )

        [subtotal] => 30000
    )

[f85454e8279be180185cac7d243c5eb3] => Array
    (
        [rowid] => f85454e8279be180185cac7d243c5eb3
        [id] => 4
        [qty] => 1
        [price] => 20000
        [name] => Nike Superfly Ijo stabilo
        [colors] => PUTIH
        [sizes] => 35
        [colors_id] => 2
        [weight] => 
        [size_id] => 2
        [image] => assets/images/product/thumbs/t SBI 001 03 - Nike CTR putih lis Merah 2.jpg
        [options] => Array
            (
                [Size] => 2
                [Color] => 2
            )

        [subtotal] => 20000
    )

[c8ed21db4f678f3b13b9d5ee16489088] => Array
    (
        [rowid] => c8ed21db4f678f3b13b9d5ee16489088
        [id] => 7
        [qty] => 1
        [price] => 12000
        [name] => NIKE CTR Fabregas Kw Super PUTIH KOM 
        [colors] => PUTIH
        [sizes] => 35
        [colors_id] => 2
        [weight] => 
        [size_id] => 2
        [image] => assets/images/product/thumbs/T SB 02 04 - Nike superfly3 ungu3 - Copy.jpg
        [开发者_如何学Pythonoptions] => Array
            (
                [Size] => 2
                [Color] => 2
            )

        [subtotal] => 12000
    )

[ccc0aa1b81bf81e16c676ddb977c5881] => Array
    (
        [rowid] => ccc0aa1b81bf81e16c676ddb977c5881
        [id] => 9
        [qty] => 1
        [price] => 12000
        [name] => ADIDAS CTR Fabregas Kw Super PUTIH KOM BIRU
        [colors] => PUTIH
        [sizes] => 35
        [colors_id] => 2
        [weight] => 
        [size_id] => 2
        [image] => assets/images/product/thumbs/T SBI 001 01 - Nike CTR putih lis Biru 2.jpg
        [options] => Array
            (
                [Size] => 2
                [Color] => 2
            )

        [subtotal] => 12000
    )

)


Ryan is correct. Here is the SQL that worked for me.

CREATE TABLE `ci_sessions` (
  `session_id` varchar(40) NOT NULL DEFAULT '0',
  `ip_address` varchar(16) NOT NULL DEFAULT '0',
  `user_agent` varchar(50) NOT NULL,
  `last_activity` int(10) unsigned NOT NULL DEFAULT '0',
  `user_data` text NOT NULL,
  PRIMARY KEY (`session_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;


Enable session database would solve the problem, your session can't hold your cart data, that's why you only can add 6 items.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜