2011-09-11 34 views
0

我試圖將商品添加到購物車,但它只會將前6個商品添加到購物車。其餘的似乎沒有被添加。購物車在codeigniter中無法正常工作

我檢查了數組,他們有所需的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 
    ) 

+0

基本上,您可能會得到與默認情況下生成的相同rowid,CI_Cart中的哈希由product_id和選項生成。如果tehse相同,那麼它將創建相同的rowid,因此不會讓您將產品添加到購物車中。 –

回答

0

啓用會話數據庫可以解決這個問題,你的會話不能握住你的車的數據,這就是爲什麼你只可以添加6個項目。

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;