购物车在codeigniter中无法正常工作

时间:2011-09-11 19:59:15

标签: codeigniter

我正在尝试将商品添加到购物车,但它只会将前6个商品添加到购物车。其余的似乎没有被添加。

我检查了数组,他们有所需的ID,数量,价格和名称。我做错了什么?

以下是代码:

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);

}

问题是当我在购物车中添加选项值时。

这是数组结果:

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
        [options] => 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
    )

2 个答案:

答案 0 :(得分:1)

瑞安是对的。 这是适用于我的SQL。

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;

答案 1 :(得分:0)

启用会话数据库可以解决问题,您的会话无法保存您的购物车数据,这就是您只能添加6个项目的原因。

相关问题