Codeigniter(3.X)というPHPフレームワークでECサイトを構築しようとしています。
商品の詳細画面で商品概要仕様を選択して「カートに入れる」を押して画面遷移をすると
選択した商品の一覧が表示されますが、
この画面で更新ボタンを押すと商品が追加されてしまいます。
それで、下記のような処理に変更したのですが。1回目だけが追加されて2回目が追加されなくなりました。
どのようにすれば更新ボタンを押しても数量が増えなくなるでしょうか?
宜しくお願いいたします。
//POSTデータ $post_array = array(); $post_array = $this->input->post(); //SESSIONデータ $session_array = array(); $session_array = $this->session->all_userdata(); if(!array_key_exists("pr_id",$session_array)){ $data["title"] = "商品カートに商品が登録されていません。"; $this->load->view('/header/header_012',$data); $this->load->view('/common/parts_login',$data); // $this->load->view('/common/parts_category_list',$data); $this->load->view('/cart/cart_login_not_added'); $this->load->view('/common/parts_footer',$data); return FALSE; } //セッションに数量を格納 $this->session->set_userdata('qty', $post_array["qty"]); //すでにカートに登録されている内容を取得する $contents = $this->cart->contents(); //更新ボタンを押しての重複登録防止 $error = 0; //商品コンテンツ配列を確認して更新時のカウントアップを防ぐ if(!empty($contents)){ foreach($contents as $key => $value){ //コンテンツの中に商品IDがあり、現状の商品IDと一致する場合、コンテンツの数値が違う場合カウントアップ if($value["id"] == $session_array["pr_id"]){ if($value["qty"] != $post_array["qty"]){ $error++; } } } } //更新ボタンを押していない場合 if($error == 0){ $option_array = array(); $option_price = 0; //リバーシブル if(array_key_exists("reversible",$post_array)){ $this->session->set_userdata('reversible', $post_array["reversible"]); $option_array["reversible"] = $post_array["reversible"]; $price = $this->reversible->Get_Reversible_Option($post_array["reversible"]); $option_price += $price; } //オプション金額を入れる $option_array["option_price"] = $option_price; $product_array = $this->product->Get_Product_Main_Data_Detail($session_array["pr_id"]); $contents = array( 'id' => $session_array["pr_id"], 'qty' => $post_array["qty"], 'price' => $product_array["sale_price_ec"], 'name' => $product_array["product_name"], 'options' => $option_array, ); //カートに登録 $this->cart->insert($contents); } //カート操作後の情報取得 $contents = $this->cart->contents(); //総額 $total = $this->cart->total(); //金額表示フォーマット $data["total"] = number_format($total);
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/11/13 06:41
退会済みユーザー
2016/11/13 13:07