Codeigniter 代码点火器更新数量不工作
数量不更新仅当我向购物车多次添加具有完全相同选项的项目时,它会替换而不是增加现有项目的数量 这是购物车视图代码Codeigniter 代码点火器更新数量不工作,codeigniter,Codeigniter,数量不更新仅当我向购物车多次添加具有完全相同选项的项目时,它会替换而不是增加现有项目的数量 这是购物车视图代码 `<table class="table table-bordered table-hover"> <thead ><!-- Table head --> <tr> <th class="active">Sl</th> <th class="active col-sm-4">Produc
`<table class="table table-bordered table-hover">
<thead ><!-- Table head -->
<tr>
<th class="active">Sl</th>
<th class="active col-sm-4">Product</th>
<th class="active col-sm-2">Real Price</th>
<th class="active ">Qty</th>
<th class="active ">Disc Price</th>
<th class="active">Total</th>
<th class="active">Action</th>
</tr>
</thead><!-- / Table head -->
<tbody><!-- / Table body -->
<?php $cart = $this->cart->contents() ;
?>
<?php $counter =1 ; ?>
<?php if (!empty($cart)): foreach ($cart as $item) : ?>
<tr class="custom-tr">
<td class="vertical-td">
<?php echo $counter ?>
</td>
<td class="vertical-td"><?php echo $item['name'] ?></td>
<td class="vertical-td"><?php echo $item['pkprice'] ?></td>
<td class="vertical-td">
<input type="text" name="qty" style="width: 50px" value="<?php echo $item['qty'] ?>" onblur ="order(this);" id="<?php echo 'qty'.$item['rowid'] ?>" class="form-control">
</td>
<td>
<div class="input-group">
<span class="input-group-addon">
<input type="checkbox" id="<?php echo 'opt'.$item['rowid'] ?>" onclick="return price_checkbox(this)" name="custom_price"
<?php echo $item['price_option'] == 'custom_price' ? 'checked':'' ?>
data-placement="top" data-toggle="tooltip" data-original-title="Custom Price">
</span>
<input type="text" name="price" value="<?php echo $item['price'] ?>" onblur ="order(this);" id="<?php echo 'pri'.$item['rowid'] ?>" class="form-control"
<?php echo $item['price_option'] == 'custom_price' ? '':'disabled' ?> >
</div>
<input type="hidden" name="product_code" value="<?php echo $item['id'] ?>" id="<?php echo 'code'.$item['rowid'] ?>">
</td>
<td class="vertical-td"><?php echo number_format($item['subtotal'], 2, '.', ',') ?></td>
<td class="vertical-td">
<?php echo btn_delete('admin/order/delete_cart_item/' . $item['rowid']); ?>
</td>
</tr>
<?php
$counter++;
endforeach;
?><!--get all sub category if not this empty-->
<?php else : ?> <!--get error message if this empty-->
<td colspan="6">
<strong>There is no record for display</strong>
</td><!--/ get error message if this empty-->
<?php endif; ?>
</tbody><!-- / Table body -->
`
Sl
产品
实际价格
数量
光盘价格
全部的
行动
data placement=“top”data toggle=“tooltip”data original title=“自定义价格”>
>
你试过这个吗
<?php foreach ($this->cart->contents() as $items): ?>
<?php echo form_hidden($counter.'[rowid]', $items['rowid']); ?> // write this
//写这个
然后这个
<td><?php echo form_input(array('name' => $counter.'[qty]', 'value' => $items['qty'], 'maxlength' => '3', 'size' => '5')); ?></td>
而不是-
<?php echo form_input(array('name' =>'rowid1[]', 'type'=>'text', 'value' => $items['rowid'], 'maxlength' => '3', 'size' => '5')); ?>
我希望这能起作用检查当更新查询为fire时生成的查询,我认为任何信号引用都会添加到您的查询中。
要检查最后一次数据库查询,请使用此函数:-
打印($this->db->last_query()) 经过很多努力,我正确地获得了我的代码这里是正确的插入和更新代码
function add_cart_item_by_barcode(){
$product_code = $this->input->post('barcode', true);
$result = $this->order_model->validate_add_cart_item($product_code);
$rowid = $this->input->post('rowid');
$cart = $this->cart->contents();
foreach ($cart as $cart) {
if($product_code == $cart['id']){
$rowid=$cart['rowid'];
$qty=$cart['qty'];
$data=array(
'rowid'=>$rowid,
'qty'=>$qty+1
);
$data=$this->cart->update($data);
$this->session->set_flashdata('cart_msg', 'add');
redirect('admin/order/new_order/'.$flag ='add');
}
}
if ($result) {
// update rate
$price = $this->check_product_rate($result->product_id, $qty=1);
//product tax check
$tax = $this->product_tax_calculate($result->tax_id, $qty=1, $price);
$data = array(
'id' => $result->product_code,
'qty' => $qty,
'price' => $price,
'buying_price' => $result->buying_price,
'name' => $result->product_name,
'pkprice' => $result->p_price,
'tax' => $tax,
'price_option' => 'general'
);
$this->cart->insert($data);
$this->session->set_flashdata('cart_msg', 'add');
}
redirect('admin/order/new_order/'.$flag ='add');
}
您是否有一些错误?没有错误,只需再次添加产品,数量仍然为1您是否只需插入数据<代码>$this->cart->insert($data)代码>是所有代码正常工作$this->cart->insert($data);但是当按条形码再次添加产品时,数量没有增加您应该使用更新
,但您使用的是插入
!当我将产品添加到购物车时,产品添加成功,其数量为1,但当我再次添加相同的产品时,数量没有增加,其仍然为1,我认为问题在于表单输入(),你能用普通的html编写吗?或者把普通的html输入改成表单输入吗?我现在更新了代码。请解决我在一周内尝试过的问题,但没有成功。你试过再次运行它吗?代码更改后?foreach($this->cart->contents()$item){if($item['id']='your_product_id'){$item['qty']=3;$this->cart->update($item);}选择tbl_产品。*,tbl_存货。产品数量,tbl_存货。通知数量来源(tbl_产品
)左键连接tbl\u库存tbl\u库存product\u id
=tbl\u产品product\u id
其中tbl\u产品
状态
=1订单由tbl\u产品
product\u id
DESC这是生成的Hello shoaib,我只是想看看当你启动更新查询时生成了什么查询。在我的公共函数“按条形码添加购物车”中没有更新查询,我永远不知道如果购物车中已有物品,我该如何使用它。如何在公共函数中更新其数量“按条形码添加购物车”中所有代码都工作正常,但不知道如何进行更新在公共功能中查询按条形码添加购物车项目。
function add_cart_item_by_barcode(){
$product_code = $this->input->post('barcode', true);
$result = $this->order_model->validate_add_cart_item($product_code);
$rowid = $this->input->post('rowid');
$cart = $this->cart->contents();
foreach ($cart as $cart) {
if($product_code == $cart['id']){
$rowid=$cart['rowid'];
$qty=$cart['qty'];
$data=array(
'rowid'=>$rowid,
'qty'=>$qty+1
);
$data=$this->cart->update($data);
$this->session->set_flashdata('cart_msg', 'add');
redirect('admin/order/new_order/'.$flag ='add');
}
}
if ($result) {
// update rate
$price = $this->check_product_rate($result->product_id, $qty=1);
//product tax check
$tax = $this->product_tax_calculate($result->tax_id, $qty=1, $price);
$data = array(
'id' => $result->product_code,
'qty' => $qty,
'price' => $price,
'buying_price' => $result->buying_price,
'name' => $result->product_name,
'pkprice' => $result->p_price,
'tax' => $tax,
'price_option' => 'general'
);
$this->cart->insert($data);
$this->session->set_flashdata('cart_msg', 'add');
}
redirect('admin/order/new_order/'.$flag ='add');
}