2017-08-17 31 views
0

カートに追加するために同じアイテムが複数選択されている場合、以下で作業するコードは、同じ数量を更新するのではなく、ショッピングカートの表示テーブルに別の行を追加します項目。PHPショッピングカートに商品を追加

私はカードに追加しているときに、製品IDとチェックを実行してくださいだけでアイテムの数量を更新し、カート

<?php $total = 0; ?> 
<?php if(isset($_SESSION['cart'])){ ?> 
<?php foreach($_SESSION['cart'] as $row): ?> 
<?php if($row['qty'] != 0): ?> 
<tr> 
    <td class="text-center"><strong><?php echo 
    $row['product'];?></strong></td> 
    <td class="text-center"> 
    <?php echo $row['price'];?> 
    </td> 
    <td class="text-center"> 
    <form action="cart/data.php?q=updatecart&id=<?php echo 
    $row['proID'];?>" method="POST"> 
     <input type="number" name="qty" value="<?php echo 
    $row['qty'];?>" min="0" style="width:50px;" /> 
     <button type="submit" class="btn btn-info">Update</button> 
    </form> 
    </td> 
    <?php $itotal = $row['price'] * $row['qty']; ?> 
    <td class="text-center"> 
    <font class="itotal"> 
     <?php 
    echo $itotal; ?> 
    </font> 
    </td> 
    <td class="text-center"><a href="cart/data.php? 
    q=removefromcart&id=<?php echo $row['proID'];?>"><i class="fa fa-times- 
    circle fa-lg text-danger removeproduct"></i></a></td> 
</tr> 
<?php $total = $total + $itotal;?> 
<?php endif;?> 
<?php endforeach; ?> 
<?php $_SESSION['totalprice'] = isset($_SESSION['totalprice']) ? 
    $_SESSION['totalprice'] : $total; ?> 
+0

data.phpとは何ですか?あなたの問題は、このコードではなく、そこにあります。 – Viktor

+0

これは、関数function addtocart($ product、$ price、$ qty){ $ cart = array( 'proID' => $ _SESSION ['proID']、 'product' => $ product、 'の価格です'=> $ price、 ' qty '=> $ qty ); $ _SESSION ['proID'] = $ _SESSION ['proID'] +1; array_push($ _ SESSION ['cart']、$ cart); trueを返します。 } – Leej

答えて

0

上で再度表示しないように願って、

のproductIDがすでにある場合数量エルス

に1を追加します カートにジャスト

またCLEを試してみてくださいカートに追加あなたのコードを理解するのが難しい。

関連する問題