2017-08-09 36 views
0

我想更新購物車的數量。我已經谷歌很多,但無法做到這一點。如何更新CodeIgniter中的購物車數量?

最大的頁面顯示我不想要的。確切的解決方案,我沒有得到。希望我能來到這裏。請幫助我做到這一點。這是我的查看頁面

**<table class="table table-hover table-bordered table-striped snipcart-details "> <thead> 
       <tr> 
        <th style="color:#FF0033; font-weight:bolder; text-align:center;" >Delete Cart</th> 
        <th style="color:#FF0033; font-weight:bolder; text-align:center;" >Product Name</th> 
        <th style="color:#FF0033; font-weight:bolder; text-align:center;" >Image</th> 
        <th style="color:#FF0033; font-weight:bolder; text-align:center;" >Price</th> 
        <th style="color:#FF0033; font-weight:bolder; text-align:center;" >Quantity</th>      
        <th colspan="2" style="color:#FF0033; font-weight:bolder; text-align:center;" >Total</th> 
       </tr> 
       </thead> 
       <tbody>     
       <?php foreach ($this->cart->contents() as $items) { ?> 
       <tr>      
        <td style="color:#000000; font-weight:bolder; text-align:center;" > 
        <a href="#" class="remove_cart" title="delete" row_id="<?php echo $items['rowid']; ?>" rel="1"> 
        <i class="fa fa-times fa-2x" style="color:red;" aria-hidden="true"></i> </a></td> 
        <td style="color:#000000; font-weight:bolder; text-align:center;" ><?php echo $items['name']; ?></td> 
        <td align="center"><img src="<?php echo base_url('resource/allproduct/'.$items['productImage']);?>" height="50px;" /></td></td> 
        <td style="color:#000000; font-weight:bolder; text-align:center;"><?php echo $items['price']; ?></td> 
        <td align="center"><input type="number" name="qty" id="qty" value="<?php echo $items['qty']; ?>"></td>    
      <td colspan="2" style="color:#000000; font-weight:bolder; text-align:center;">TK <?php echo $this->cart->format_number($items['subtotal']); ?></td> 
       </tr> 
       <?php } ?> 
      </tbody>     
      <tbody> 
       <tr>      
        <th scope="row"><a href=""> <input type="button" name="submit" value="Update" class="button" /> </a></th> 
        <td align="center"><a href="<?php echo site_url('home'); ?>"> <input type="button" name="submit" value="Continue Shopping" class="button" /></a></td> 
        <td colspan="3" class="button" align="center" >  
            <?php if(!empty($userid)){?> 
            <a href="<?php echo site_url("checkout"); ?>"><input class="button" type="submit" value="Place Order"></a> 
            <?php } else {?> 
            <a href="<?php echo site_url("login"); ?>"><input class="button" type="submit" value="Place Order"></a>          
            <?php }?>              
        </td> 
        <td align="center" style="color:#000000;" > <h4>Grand Total</h4> </td> 
        <td style="font-size:24px; font-weight:800; color:green;">TK <?php echo $this->cart->format_number($this->cart->total()); ?></td>   
       </tr> 
      </tbody> 
     </table>** 

這裏是CONTROLER

public function index() 
{ 
    $data['basicinfo']   = $this->M_cloud->basicall('basic_info'); 
    $where      = array('status' => 1); 
    $data['categoryinfo']  = $this->M_cloud->categoryinfo('item_manage', $where); 
    $data['rows']    = count($this->cart->contents());  
    $data['userid']    = $this->session->userdata('user_id');  
    $data['subcategoryinfo'] = $this->M_cloud->findAll2('sub_category', array('status' => 1));  
    $data['menuinformation'] = $this->M_cloud->findReport('our_service', array('serviceType'=> 2), 'menuname asc'); 
    $data['menuservice']  = $this->M_cloud->findReport('our_service', array('serviceType'=> 1), 'menuname asc');  
    $data['socialmedia']  = $this->M_cloud->findAll('social_tbl', 'name asc'); 
    $data['newsinfo']   = $this->M_cloud->findAll('news_table', 'newstitle DESC'); 
    $this->load->view('cartPage', $data);  
} 

    public function buy() 
{ 
    $proId = $this->input->post('proId'); 
    $Qty = $this->input->post('Qty'); 
    $prosize = $this->input->post('prosize');  
    $result = $this->M_cloud->find('product_manage', array('proid' => $proId));  
    $data2 = array(
       'id'     => $proId, 
       'qty'     => $Qty, 
       'name'     => $result->proName, 
       'price'     => $result->price, 
       'prosize'    => $prosize, 
       'productImage'   => $result->proimg1, 
       'product_code'   => $result->procode     
      ); 
    $this->cart->insert($data2);   
    redirect('cart'); 
} 

public function deleteCartItem() { 
    $row_id    = $this->input->post('row_id'); 
    $data = array(
     'rowid' => $row_id, 
     'qty'  => 0 
    ); 
    $this->cart->update($data); 
} 

請幫我怎麼更新購物車的數量。提前致謝。

回答

0

要更新車編號:

function updateCartItem(){ 
     $data=array(
      'rowid'=>$this->input->post('rowid',TRUE), 
      'qty'=> $this->input->post('quantity',TRUE) 
      ); 

       if ($this->cart->update($data)) { 
       echo "Success";   
       }else{ 
        echo "Faliure"; 
       } 

} 

從購物車中刪除項目:

function deleteCartItem(){ 
$row_id = $this->input->post('row_id',TRUE); 
    if ($rowid) { 
      return $this->cart->remove($rowid); 
     } 
} 
+0

哪裏視圖頁面動作? – Sumonto

+0

我可以幫助你的錯誤不與功能,你必須設計自己的購物車頁面 –

+0

我的意思是說如何調用行動控制? <?php echo site_url('controler_name/funcntion_name');?>這就是它唯一或別的方法我應該打電話給????請讓我知道 – Sumonto