Step 1: tạo route about
- Hiệu chỉnh file
routes/web.php
php
1Route::get('/gio-hang', 'Frontend\FrontendController@cart')->name('frontend.cart');Step 2: viết code action
Viết code cho action cart():
php
1/**2 * Action hiển thị giỏ hàng3 */4public function cart(Request $request)5{6 return view('frontend.pages.shopping-cart');7}Tạo view resources/views/frontend/pages/shopping-cart.blade.php
php
1{{-- View này sẽ kế thừa giao diện từ `frontend.layouts.master` --}}2@extends('frontend.layouts.master')3 4{{-- Thay thế nội dung vào Placeholder `title` của view `frontend.layouts.master` --}}5@section('title')6Giỏ hàng Shop Hoa tươi - Sunshine7@endsection8 9{{-- Thay thế nội dung vào Placeholder `custom-css` của view `frontend.layouts.master` --}}10@section('custom-css')11@endsection12 13{{-- Thay thế nội dung vào Placeholder `main-content` của view `frontend.layouts.master` --}}14@section('main-content')15 16<!-- Hiển thị giỏ hàng -->17<ngcart-cart template-url="{{ asset('vendor/ngCart/template/ngCart/cart.html') }}"></ngcart-cart>18 19@endsection20 21{{-- Thay thế nội dung vào Placeholder `custom-scripts` của view `frontend.layouts.master` --}}22@section('custom-scripts')23@endsectionStep 3: hiệu chỉnh template cart
Hiệu chỉnh file public/vendor/ngCart/template/ngCart/cart.html:
php
1<!-- Shoping Cart -->2<form class="bg0 p-t-75 p-b-85 ngCart cart">3 <div class="container">4 <div class="row" ng-show="ngCart.getTotalItems() === 0">5 <div class="col-lg-12 col-md-12">6 <div class="alert alert-warning" role="alert">7 Giỏ hàng trống8 </div>9 </div>10 </div>11 12 <div class="row" ng-show="ngCart.getTotalItems() > 0">13 <div class="col-lg-10 col-xl-7 m-lr-auto m-b-50">14 <div class="m-l-25 m-r--38 m-lr-0-xl">15 <div class="wrap-table-shopping-cart">16 <table class="table-shopping-cart">17 <tr class="table_head">18 <th class="column-1">Sản phẩm</th>19 <th class="column-2"></th>20 <th class="column-3">Đơn giá</th>21 <th class="column-4">Số lượng</th>22 <th class="column-5">Thành tiền</th>23 <th class="column-6">Hành động</th>24 </tr>25 26 <tr class="table_row" ng-repeat="item in ngCart.getCart().items track by $index">27 <td class="column-1">28 <div class="how-itemcart1">29 <img src="<% item.getData().sp_hinh_url %>" alt="IMG">30 </div>31 </td>32 <td class="column-2"><% item.getName() %></td>33 <td class="column-3"><% item.getPrice() | currency %></td>34 <td class="column-4"><% item.getQuantity() | number %></td>35 <td class="column-5"><% item.getTotal() | currency %> </td>36 <td><span ng-click="ngCart.removeItemById(item.getId())"37 class="glyphicon glyphicon-remove remove">Xóa</span></td>38 </tr>39 </table>40 </div>41 </div>42 </div>43 44 <div class="col-sm-10 col-lg-7 col-xl-5 m-lr-auto m-b-50">45 <div class="bor10 p-lr-40 p-t-30 p-b-40 m-l-63 m-r-40 m-lr-0-xl p-lr-15-sm">46 <h4 class="mtext-109 cl2 p-b-30">47 Tính tiền giỏ hàng48 </h4>49 50 <div class="flex-w flex-t p-t-27 p-b-33">51 <!-- Thuế -->52 <div class="size-208" ng-show="ngCart.getTax()">53 <span class="mtext-101 cl2">54 Thuế (<% ngCart.getTaxRate() %>%):55 </span>56 </div>57 58 <div class="size-209 p-t-1" ng-show="ngCart.getTax()">59 <span class="mtext-110 cl2">60 <% ngCart.getTax() | currency %>61 </span>62 </div>63 64 <!-- Vận chuyển -->65 <div class="size-208" ng-show="ngCart.getShipping()">66 <span class="mtext-101 cl2">67 Vận chuyển68 </span>69 </div>70 71 <div class="size-209 p-t-1" ng-show="ngCart.getShipping()">72 <span class="mtext-110 cl2">73 <% ngCart.getShipping() | currency %>74 </span>75 </div>76 77 <!-- Tổng thành tiền -->78 <div class="size-208">79 <span class="mtext-101 cl2">80 Tổng thành tiền:81 </span>82 </div>83 84 <div class="size-209 p-t-1">85 <span class="mtext-110 cl2">86 <% ngCart.totalCost() | currency %>87 </span>88 </div>89 </div>90 91 <button class="flex-c-m stext-101 cl0 size-116 bg3 bor14 hov-btn3 p-lr-15 trans-04 pointer">92 Thanh toán93 </button>94 </div>95 </div>96 </div>97 </div>98</form>99 100<style>101 .ngCart.cart span[ng-click] {102 cursor: pointer;103 }104 105 .ngCart.cart .glyphicon.disabled {106 color: #aaa;107 }108 109 .ngCart.cart .title {110 color: blue;111 font-weight: bold;112 }113 114 .ngCart.cart .remove {115 color: red;116 }117</style>
