2011-09-11 18 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); 

} 

私は私のカート内のオプション値を追加するときに問題があります。ここで

が配列の結果である:あなたが唯一の6つの項目を追加することができる理由

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

基本的に、CI_Cartのハッシュはproduct_idとオプションによってデフォルトで生成されたものと同じROWIDが生成されている可能性があります。同じものであれば、同じROWIDが作成され、製品をカートに追加することはできません。 –

答えて

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; 
関連する問題