[英]Minicart.js display all cart items
I would like to display all items in my cart in console but its not working.我想在控制台中显示我购物车中的所有项目,但它不起作用。 I tried this:我试过这个:
<script src="js/minicart.min.js"></script>
<script>
var items = paypal.minicart.cart.items();
console.log(items);
</script>
and got an error.并出现错误。 Then I tried this:然后我尝试了这个:
<script src="js/minicart.min.js"></script>
<script>
console.log(paypal.minicart.cart.items());
</script>
and got Array[Object]
in my console instead of the actual items in my cart.并在我的控制台中获得了Array[Object]
而不是购物车中的实际项目。 What could be the problem with my code?我的代码可能有什么问题?
If you want to display it just go for如果你想显示它只是去
paypal.minicart.cart.items().forEach(
console.log.bind(console)
);
<div class="snipcart-details">
<form action="#" method="post">
<fieldset>
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="business" value=" " />
<input type="hidden" name="item_name" value="<?php echo $row1['P_Name']; ?>" />
<input type="hidden" name="amount" id="amt_<?php echo $i ?>" value="<?php echo $pp;?>" />
<input type="hidden" name="discount_amount" id="discount_<?php echo $i ?>" value="<?php echo $offer; ?>">
<input type="hidden" name="currency_code" value="INR">
<input type="hidden" name="return" value=" ">
<input type="hidden" name="cancel_return" value=" " />
<input type="hidden" name="shipping" value="<?php echo $PID; ?>" />
<input type="hidden" name="shipping2" value="<?php echo $unitnamepo; ?>" />
<input type="submit" name="submit" value="Add to cart" class="button" />
</fieldset>
</form>
</div>
I have passed PID & Unitname through the form.我已经通过表单传递了 PID 和 Unitname。
CHECKOUT PAGE:结帐页面:
<div class="privacy about">
<h3>Chec<span>kout</span></h3>
<?php
foreach ($_POST as $key => $value) {
$PodInCart=(sizeof($_POST)-7)/6;
}
?>
<div class="checkout-right">
<h4>Your shopping cart contains: <span><?php echo $PodInCart; ?> Products</span></h4>
<table class="timetable_sub">
<thead>
<tr>
<th>SL No.</th>
<th>Product</th>
<th>Quantity</th>
<th>Unit</th>
<th>Name</th>
<th>Price</th>
<th>Remove</th>
</tr>
</thead>
<tbody>
<?php
for ($i=1; $i<=$PodInCart; $i++)
{ ?>
<?php
$Id=$_POST["shipping_".$i];
$sqlimg = "SELECT P_Img FROM products WHERE P_Id='$Id'";
$resultimg = $conn->query($sqlimg);
$rowimg=mysqli_fetch_assoc($resultimg);
$img="product_img/".$rowimg['P_Img'];
?>
<tr class="rem<?php echo $i ?>">
<td class="invert"><?php echo $i ?></td>
<td class="invert-image"><a href="#"><img src="<?php echo $img; ?>" width="40" height="40" alt=" " class="img-responsive"></a></td>
<td class="invert">
<div class="quantity">
<div class="quantity-select">
<?php echo $_POST["quantity_".$i]; ?>
</div>
</div>
</td>
<td class="invert"><?php echo $_POST["shipping2_".$i]; ?></td>
<td class="invert"><?php echo $_POST["item_name_".$i]; ?></td>
<td class="invert">₹
<?php
$P1=$_POST["amount_".$i];
$QTY=$_POST["quantity_".$i];
$P2=($_POST["discount_amount_".$i])/($_POST["quantity_".$i]);
$P3=$P1-$P2;
$QTY=$_POST["quantity_".$i];
$Fprice=$P3*$QTY;
echo $Fprice;
?>
</td>
<td class="invert">
<div class="rem">
<form id="updateCart<?php echo $i; ?>" action="#" method="post" class="last">
<fieldset>
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="display" value="1">
<button type="submit" class="minicart-remove">x</button>
</fieldset>
</form>
</div>
</td>
</tr>
<?php } ?>
</tbody></table>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.