Minicart.js显示所有购物车项目

时间:2017-08-05 16:55:53

标签: javascript paypal

我想在控制台中显示购物车中的所有商品,但它无效。我试过这个:

<script src="js/minicart.min.js"></script>
<script>
var items = paypal.minicart.cart.items();
  console.log(items);
</script>

并收到错误消息。然后我尝试了这个:

<script src="js/minicart.min.js"></script>
<script>
  console.log(paypal.minicart.cart.items());
</script>

并在我的控制台中获得了Array[Object],而不是购物车中的实际商品。我的代码可能有什么问题?

2 个答案:

答案 0 :(得分:0)

如果您想要显示它,请转到

paypal.minicart.cart.items().forEach(
  console.log.bind(console)
);

答案 1 :(得分:0)

        <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>

我已经通过表格传递了PID和单元名。

检查页面:

{{1}}