如果购物车中没有东西,我可以支付

作为标题,我需要执行一个代码,如果购物车中没有东西,我必须看到一个警报(在结帐前在购物车中添加一些东西),并且如果用户添加了东西,那一切都很好...希望能对我有所帮助。提前致谢!如有任何疑问,请随时与我联系!

<?php

//fetch_cart.php

session_start();

$total_price = 0;
$total_item = 0;

$output = '
<div class="table-responsive" id="order_table">
 <table class="table table-bordered table-striped">
  <tr>  
            <th width="40%">Product Name</th>  
            <th width="10%">Quantity</th>  
            <th width="20%">Price</th>  
            <th width="15%">Total</th>  
            <th width="5%">---</th>  
        </tr>
';

if(!empty($_SESSION["shopping_cart"]))
{
 foreach($_SESSION["shopping_cart"] as $keys => $values)
 {
  $output .= '
  <tr>
   <td>'.$values["product_name"].'</td>
   <td>'.$values["product_quantity"].'</td>
   <td align="right">$ '.$values["product_price"].'</td>
   <td align="right">$ '.number_format($values["product_quantity"] * $values["product_price"], 2).'</td>
   <td><button name="delete" class="btn btn-danger btn-xs delete" id="'. $values["product_id"].'">Delete from Cart</button></td>
  </tr>
  ';
  $total_price = $total_price + ($values["product_quantity"] * $values["product_price"]);

  $total_item = $total_item + 1;
 }
 $output .= '
 <tr>  
        <td colspan="3" align="right">Totale</td>  
        <td align="right">€ '.number_format($total_price, 2).'</td>  
        <td></td>  
    </tr>
 ';
}
else
{
 $output .= '
    <tr>
     <td colspan="5" align="center">
      Your Cart is Actually Clear. Add something to buy!
     </td>
    </tr>
    ';
}

$output .= '</table></div>';

$data = array(
 'cart_details'  => $output,
 'total_price'  => '€' . number_format($total_price, 2),
 'total_item'  => $total_item
);

echo json_encode($data);

?>

评论