CakePhp-如何从购物车列表中删除购物车行

时间:2020-09-01 12:29:39

标签: php cakephp e-commerce cakephp-2.0 cakephp-2.3

我的购物车列表显示以下列列表。

产品价格数量总计

产品1 200 5 1000

Product2 300 3 900

我的Carts控制器中具有Index.php的此Cart列表。如何从列表中删除添加的项目?

下面的index.php代码实际上显示了添加的项目列表。

<?php
        $total=0;
    ?>
    <!-- slider Area Start-->
    <div class="slider-area ">
        <!-- Mobile Menu -->
        <div class="single-slider slider-height2 d-flex align-items-center" data-background=<?= @$this->Url->build('/img/hero/category.jpg')?>>
            <div class="container">
                <div class="row">
                    <div class="col-xl-12">
                        <div class="hero-cap text-center">
                            <h2>Card List</h2>
                        </div>
                    </div>
                </div>
            </div>
        </div>
      </div>
      <!-- slider Area End-->
    
      <!--================Cart Area =================-->
      <section class="cart_area section_padding">
        <div class="container">
          <div class="cart_inner">
            <div class="table-responsive">
              <table class="table">
                <thead>
                  <tr>
                    <th scope="col">Product</th>
                    <th scope="col">Price</th>
                    <th scope="col">Quantity</th>
                    <th scope="col">Total</th>
                  </tr>
                </thead>
                <tbody>
                <?php foreach($carts as $cart): ?>
                  <tr>
                    <td>
                      <div class="media">
                        <div class="d-flex">
                          <img src=<?= @$this->Url->build("/img/categori/{$cart->product->thumb}")?> alt="" width="100" height="100"/>
                        </div>
                        <div class="media-body">
                          <p><?= $cart->product->name ?></p>
                        </div>
                      </div>
                    </td>
                    <td>
                      <h5><?= $this->Number->format($cart->price) ?></h5>
                    </td>
                    <td>
                      <div class="product_count">
                        <input disabled value=<?= $this->Number->format($cart->quantity) ?> id=<?= $this->Number->format($cart->id) ?>>
                      </div>
                    </td>
                    <td>
                      <h5><?php 
                                $subtotal=0;
                                $subtotal = $this->Number->format($cart->quantity)*$this->Number->format($cart->price); 
                                $total += $subtotal;
                                echo $subtotal;
                      ?></h5>
                    </td>
                  </tr>
                <?php endforeach; ?>
                  
                  <tr class="bottom_button">
                    <td>
                      <a class="btn_1" href="<?= @$this->Url->build("/products") ?>">Update Cart</a>
                    </td>
                    <td></td>
                    <td></td>
                    <td>
                      <div class="cupon_text float-right">
                        <a class="btn_1" href="#">Close Coupon</a>
                      </div>
                    </td>
                  </tr>
                  <tr>
                    <td></td>
                    <td></td>
                    <td>
                      <h5>Subtotal</h5>
                    </td>
                    <td>
                      <h5><?= $total?></h5>
                    </td>
                  </tr>
                  <tr class="shipping_area">
                    <td></td>
                    <td></td>
                    <td>
                      <h5>Shipping</h5>
                    </td>
                    <td>
                      <div class="shipping_box">
                        <ul class="list">
                          <li>
                            Flat Rate: $5.00
                            <input type="radio" aria-label="Radio button for following text input">
                          </li>
                          <li>
                            Free Shipping
                            <input type="radio" aria-label="Radio button for following text input">
                          </li>
                        </ul>
                      </div>
                    </td>
                  </tr>
                </tbody>
              </table>
              <div class="checkout_btn_inner float-right">
                <a class="btn_1" href="<?= @$this->Url->build("/products") ?>">Continue Shopping</a>
                <a class="btn_1 checkout_btn_1" href="#">Proceed to checkout</a>
                
    
              </div>
            </div>
          </div>
      </section>
      
      <!--================End Cart Area =================-->

在我的Cart控制器中删除函数,如下所示:

 public function delete($id = null)
    {
        $this->request->allowMethod(['post', 'delete']);
        $cart = $this->Carts->get($id);
        if ($this->Carts->delete($cart)) {
            $this->Flash->success(__('The cart has been deleted.'));
        } else {
            $this->Flash->error(__('The cart could not be deleted. Please, try again.'));
        }

        return $this->redirect(['action' => 'index']);
    }

0 个答案:

没有答案