Step 1: hiệu chỉnh action
Hiệu chỉnh code action index():
- Bổ sung query lấy danh sách loại, hình ảnh liên quan
Hiệu chỉnh file app/Http/Controllers/Frontend/FrontendController.php
php
1<?php2 3namespace App\Http\Controllers\Frontend;4 5use Illuminate\Http\Request;6use App\Http\Controllers\Controller;7use App\Loai;8use App\Mau;9use App\Sanpham;10use DB;11use Mail;12use App\Mail\ContactMailer;13 14class FrontendController extends Controller15{16 /**17 * Action hiển thị view Trang chủ18 * GET /19 */20 public function index(Request $request)21 {22 // Query top 3 loại sản phẩm (có sản phẩm) mới nhất23 $ds_top3_newest_loaisanpham = DB::table('cusc_loai')24 ->join('cusc_sanpham', 'cusc_loai.l_ma', '=', 'cusc_sanpham.l_ma')25 ->orderBy('l_capNhat')->take(3)->get();26 27 // Query tìm danh sách sản phẩm28 $danhsachsanpham = $this->searchSanPham($request);29 30 // Query Lấy các hình ảnh liên quan của các Sản phẩm đã được lọc31 $danhsachhinhanhlienquan = DB::table('cusc_hinhanh')32 ->whereIn('sp_ma', $danhsachsanpham->pluck('sp_ma')->toArray())33 ->get();34 35 // Query danh sách Loại36 $danhsachloai = Loai::all();37 38 // Query danh sách màu39 $danhsachmau = Mau::all();40 41 // Hiển thị view `frontend.index` với dữ liệu truyền vào42 return view('frontend.index')43 ->with('ds_top3_newest_loaisanpham', $ds_top3_newest_loaisanpham)44 ->with('danhsachsanpham', $danhsachsanpham)45 ->with('danhsachhinhanhlienquan', $danhsachhinhanhlienquan)46 ->with('danhsachmau', $danhsachmau)47 ->with('danhsachloai', $danhsachloai);48 }49 50 ...51}Step 2: tạo widget product
Hiệu chỉnh widget resources/views/frontend/widgets/product-list.blade.php
php
1<div class="bg0 m-t-23 p-b-140">2 <div class="container">3 <div class="flex-w flex-sb-m p-b-52">4 <div class="flex-w flex-l-m filter-tope-group m-tb-10">5 <button class="stext-106 cl6 hov1 bor3 trans-04 m-r-32 m-tb-5 how-active1" data-filter="*">6 Tất cả7 </button>8 9 @foreach($danhsachloai as $loai)10 <button class="stext-106 cl6 hov1 bor3 trans-04 m-r-32 m-tb-5" data-filter=".loai-{{ $loai->l_ma }}">11 {{ $loai->l_ten }}12 </button>13 @endforeach14 </div>15 16 <div class="flex-w flex-c-m m-tb-10">17 <div class="flex-c-m stext-106 cl6 size-104 bor4 pointer hov-btn3 trans-04 m-r-8 m-tb-4 js-show-filter">18 <i class="icon-filter cl2 m-r-6 fs-15 trans-04 zmdi zmdi-filter-list"></i>19 <i class="icon-close-filter cl2 m-r-6 fs-15 trans-04 zmdi zmdi-close dis-none"></i>20 Filter21 </div>22 23 <div class="flex-c-m stext-106 cl6 size-105 bor4 pointer hov-btn3 trans-04 m-tb-4 js-show-search">24 <i class="icon-search cl2 m-r-6 fs-15 trans-04 zmdi zmdi-search"></i>25 <i class="icon-close-search cl2 m-r-6 fs-15 trans-04 zmdi zmdi-close dis-none"></i>26 Search27 </div>28 </div>29 30 <!-- Search product -->31 <div class="dis-none panel-search w-full p-t-10 p-b-15">32 <div class="bor8 dis-flex p-l-15">33 <button class="size-113 flex-c-m fs-16 cl2 hov-cl1 trans-04">34 <i class="zmdi zmdi-search"></i>35 </button>36 37 <input class="mtext-107 cl2 size-114 plh2 p-r-15" type="text" name="search-product" placeholder="Search">38 </div>39 </div>40 41 <!-- Filter -->42 <div class="dis-none panel-filter w-full p-t-10">43 <div class="wrap-filter flex-w bg6 w-full p-lr-40 p-t-27 p-lr-15-sm">44 <div class="filter-col1 p-r-15 p-b-27">45 <div class="mtext-102 cl2 p-b-15">46 Sort By47 </div>48 49 <ul>50 <li class="p-b-6">51 <a href="#" class="filter-link stext-106 trans-04">52 Default53 </a>54 </li>55 56 <li class="p-b-6">57 <a href="#" class="filter-link stext-106 trans-04">58 Popularity59 </a>60 </li>61 62 <li class="p-b-6">63 <a href="#" class="filter-link stext-106 trans-04">64 Average rating65 </a>66 </li>67 68 <li class="p-b-6">69 <a href="#" class="filter-link stext-106 trans-04 filter-link-active">70 Newness71 </a>72 </li>73 74 <li class="p-b-6">75 <a href="#" class="filter-link stext-106 trans-04">76 Price: Low to High77 </a>78 </li>79 80 <li class="p-b-6">81 <a href="#" class="filter-link stext-106 trans-04">82 Price: High to Low83 </a>84 </li>85 </ul>86 </div>87 88 <div class="filter-col2 p-r-15 p-b-27">89 <div class="mtext-102 cl2 p-b-15">90 Price91 </div>92 93 <ul>94 <li class="p-b-6">95 <a href="#" class="filter-link stext-106 trans-04 filter-link-active">96 All97 </a>98 </li>99 100 <li class="p-b-6">101 <a href="#" class="filter-link stext-106 trans-04">102 $0.00 - $50.00103 </a>104 </li>105 106 <li class="p-b-6">107 <a href="#" class="filter-link stext-106 trans-04">108 $50.00 - $100.00109 </a>110 </li>111 112 <li class="p-b-6">113 <a href="#" class="filter-link stext-106 trans-04">114 $100.00 - $150.00115 </a>116 </li>117 118 <li class="p-b-6">119 <a href="#" class="filter-link stext-106 trans-04">120 $150.00 - $200.00121 </a>122 </li>123 124 <li class="p-b-6">125 <a href="#" class="filter-link stext-106 trans-04">126 $200.00+127 </a>128 </li>129 </ul>130 </div>131 132 <div class="filter-col3 p-r-15 p-b-27">133 <div class="mtext-102 cl2 p-b-15">134 Color135 </div>136 137 <ul>138 <li class="p-b-6">139 <span class="fs-15 lh-12 m-r-6" style="color: #222;">140 <i class="zmdi zmdi-circle"></i>141 </span>142 143 <a href="#" class="filter-link stext-106 trans-04">144 Black145 </a>146 </li>147 148 <li class="p-b-6">149 <span class="fs-15 lh-12 m-r-6" style="color: #4272d7;">150 <i class="zmdi zmdi-circle"></i>151 </span>152 153 <a href="#" class="filter-link stext-106 trans-04 filter-link-active">154 Blue155 </a>156 </li>157 158 <li class="p-b-6">159 <span class="fs-15 lh-12 m-r-6" style="color: #b3b3b3;">160 <i class="zmdi zmdi-circle"></i>161 </span>162 163 <a href="#" class="filter-link stext-106 trans-04">164 Grey165 </a>166 </li>167 168 <li class="p-b-6">169 <span class="fs-15 lh-12 m-r-6" style="color: #00ad5f;">170 <i class="zmdi zmdi-circle"></i>171 </span>172 173 <a href="#" class="filter-link stext-106 trans-04">174 Green175 </a>176 </li>177 178 <li class="p-b-6">179 <span class="fs-15 lh-12 m-r-6" style="color: #fa4251;">180 <i class="zmdi zmdi-circle"></i>181 </span>182 183 <a href="#" class="filter-link stext-106 trans-04">184 Red185 </a>186 </li>187 188 <li class="p-b-6">189 <span class="fs-15 lh-12 m-r-6" style="color: #aaa;">190 <i class="zmdi zmdi-circle-o"></i>191 </span>192 193 <a href="#" class="filter-link stext-106 trans-04">194 White195 </a>196 </li>197 </ul>198 </div>199 200 <div class="filter-col4 p-b-27">201 <div class="mtext-102 cl2 p-b-15">202 Tags203 </div>204 205 <div class="flex-w p-t-4 m-r--5">206 <a href="#" class="flex-c-m stext-107 cl6 size-301 bor7 p-lr-15 hov-tag1 trans-04 m-r-5 m-b-5">207 Fashion208 </a>209 210 <a href="#" class="flex-c-m stext-107 cl6 size-301 bor7 p-lr-15 hov-tag1 trans-04 m-r-5 m-b-5">211 Lifestyle212 </a>213 214 <a href="#" class="flex-c-m stext-107 cl6 size-301 bor7 p-lr-15 hov-tag1 trans-04 m-r-5 m-b-5">215 Denim216 </a>217 218 <a href="#" class="flex-c-m stext-107 cl6 size-301 bor7 p-lr-15 hov-tag1 trans-04 m-r-5 m-b-5">219 Streetstyle220 </a>221 222 <a href="#" class="flex-c-m stext-107 cl6 size-301 bor7 p-lr-15 hov-tag1 trans-04 m-r-5 m-b-5">223 Crafts224 </a>225 </div>226 </div>227 </div>228 </div>229 </div>230 231 <div class="row isotope-grid">232 @foreach($data as $index=>$sp)233 <div class="col-sm-6 col-md-4 col-lg-3 p-b-35 isotope-item loai-{{ $sp->l_ma }}">234 <!-- Block2 -->235 <div class="block2">236 <div class="block2-pic hov-img0">237 <img src="{{ asset('storage/photos/' . $sp->sp_hinh) }}" alt="IMG-PRODUCT">238 239 <a href="#" class="block2-btn flex-c-m stext-103 cl2 size-102 bg0 bor2 hov-btn1 p-lr-15 trans-04 js-show-modal" data-sp-ma="{{ $sp->sp_ma }}">240 Xem nhanh241 </a>242 </div>243 244 <div class="block2-txt flex-w flex-t p-t-14">245 <div class="block2-txt-child1 flex-col-l ">246 <a href="product-detail.html" class="stext-104 cl4 hov-cl1 trans-04 js-name-b2 p-b-6">247 {{ $sp->sp_ten }}248 </a>249 250 <span class="stext-105 cl3">251 {{ $sp->sp_giaBan }}252 </span>253 </div>254 </div>255 </div>256 257 <!-- Modal quick view -->258 @include('frontend.widgets.product-quick-view', ['sp' => $sp, 'hinhanhlienquan' => $danhsachhinhanhlienquan])259 </div>260 @endforeach261 </div>262 263 <!-- Load more -->264 <div class="flex-c-m flex-w w-full p-t-45">265 <a href="#" class="flex-c-m stext-101 cl5 size-103 bg2 bor1 hov-btn1 p-lr-15 trans-04">266 Load More267 </a>268 </div>269 </div>270</div>Thêm mới widget resources/views/frontend/widgets/product-info.blade.php
php
1<div class="container">2 <div class="bg0 p-t-60 p-b-30 p-lr-15-lg how-pos3-parent">3 <button class="how-pos3 hov3 trans-04 js-hide-modal" data-sp-ma="{{ $sp->sp_ma }}">4 <img src="{{ asset('themes/cozastore/images/icons/icon-close.png') }}" alt="CLOSE">5 </button>6 7 <div class="row">8 <div class="col-md-6 col-lg-7 p-b-30">9 <div class="p-l-25 p-r-30 p-lr-0-lg">10 <div class="wrap-slick3 flex-sb flex-w">11 <div class="wrap-slick3-dots"></div>12 <div class="wrap-slick3-arrows flex-sb-m flex-w"></div>13 14 <div class="slick3 gallery-lb">15 <div class="item-slick3" data-thumb="{{ asset('storage/photos/' . $sp->sp_hinh) }}">16 <div class="wrap-pic-w pos-relative">17 <img src="{{ asset('storage/photos/' . $sp->sp_hinh) }}" alt="IMG-PRODUCT">18 19 <a class="flex-c-m size-108 how-pos1 bor0 fs-16 cl10 bg0 hov-btn3 trans-04" href="{{ asset('storage/photos/' . $sp->sp_hinh) }}">20 <i class="fa fa-expand"></i>21 </a>22 </div>23 </div>24 25 <?php26 // Lọc các hình ảnh liên quan đến sản phẩm27 $id = $sp->sp_ma;28 $hinhanhlienquan = $hinhanhlienquan->toArray();29 $filteredItems = array_filter($hinhanhlienquan, function ($item) use ($id) {30 return $item->sp_ma == $id;31 });32 ?>33 @foreach($filteredItems as $hinhanh)34 <div class="item-slick3" data-thumb="{{ asset('storage/photos/' . $hinhanh->ha_ten) }}">35 <div class="wrap-pic-w pos-relative">36 <img src="{{ asset('storage/photos/' . $hinhanh->ha_ten) }}" alt="IMG-PRODUCT">37 38 <a class="flex-c-m size-108 how-pos1 bor0 fs-16 cl10 bg0 hov-btn3 trans-04" href="{{ asset('storage/photos/' . $hinhanh->ha_ten) }}">39 <i class="fa fa-expand"></i>40 </a>41 </div>42 </div>43 @endforeach44 </div>45 </div>46 </div>47 </div>48 49 <div class="col-md-6 col-lg-5 p-b-30">50 <div class="p-r-50 p-t-5 p-lr-0-lg">51 <h4 class="mtext-105 cl2 js-name-detail p-b-14">52 <a href="{{ route('frontend.productDetail', ['id' => $sp->sp_ma]) }}">{{ $sp->sp_ten }}</a>53 </h4>54 55 <span class="mtext-106 cl2">56 {{ $sp->sp_giaBan }}57 </span>58 59 <p class="stext-102 cl3 p-t-23">60 {{ $sp->sp_thongTin }}61 </p>62 63 <!-- -->64 <div class="p-t-33">65 <div class="flex-w flex-r-m p-b-10">66 <div class="size-203 flex-c-m respon6">67 Màu sắc68 </div>69 70 <div class="size-204 respon6-next">71 <div class="rs1-select2 bor8 bg0">72 <select class="js-select2" name="time">73 <option>Chọn màu</option>74 @foreach($danhsachmau as $mau)75 <option value="{{ $mau->m_ma }}">{{ $mau->m_ten }}</option>76 @endforeach77 </select>78 <div class="dropDownSelect2"></div>79 </div>80 </div>81 </div>82 83 <div class="flex-w flex-r-m p-b-10">84 <div class="size-204 flex-w flex-m respon6-next">85 <ngcart-addtocart template-url="{{ asset('vendor/ngCart/template/ngCart/addtocart.html') }}" id="{{ $sp->sp_ma }}" name="{{ $sp->sp_ten }}" price="{{ $sp->sp_giaBan }}" quantity="1" quantity-max="30" data="{ sp_hinh_url: '{{ asset('storage/photos/' . $sp->sp_hinh) }}' }">Thêm vào giỏ hàng</ngcart-addtocart>86 </div>87 </div>88 </div>89 90 <!-- -->91 <div class="flex-w flex-m p-l-100 p-t-40 respon7">92 <div class="flex-m bor9 p-r-10 m-r-11">93 <a href="#" class="fs-14 cl3 hov-cl1 trans-04 lh-10 p-lr-5 p-tb-2 js-addwish-detail tooltip100" data-tooltip="Add to Wishlist">94 <i class="zmdi zmdi-favorite"></i>95 </a>96 </div>97 98 <a href="#" class="fs-14 cl3 hov-cl1 trans-04 lh-10 p-lr-5 p-tb-2 m-r-8 tooltip100" data-tooltip="Facebook">99 <i class="fa fa-facebook"></i>100 </a>101 102 <a href="#" class="fs-14 cl3 hov-cl1 trans-04 lh-10 p-lr-5 p-tb-2 m-r-8 tooltip100" data-tooltip="Twitter">103 <i class="fa fa-twitter"></i>104 </a>105 106 <a href="#" class="fs-14 cl3 hov-cl1 trans-04 lh-10 p-lr-5 p-tb-2 m-r-8 tooltip100" data-tooltip="Google Plus">107 <i class="fa fa-google-plus"></i>108 </a>109 </div>110 </div>111 </div>112 </div>113 </div>114</div>Thêm mới widget resources/views/frontend/widgets/product-quick-view.blade.php
php
1<div class="wrap-modal1 js-modal-{{ $sp->sp_ma }} p-t-60 p-b-20">2 <div class="overlay-modal1 js-hide-modal" data-sp-ma="{{ $sp->sp_ma }}"></div>3 4 <!-- Product info -->5 @include('frontend.widgets.product-info', ['sp' => $sp, 'hinhanhlienquan' => $danhsachhinhanhlienquan])6</div>Step 3: hiệu chỉnh js hiển thị popup Quick view
Hiệu chỉnh file public/theme/cozastore/js/main.js`
javascript
1/*==================================================================2[ Show modal ]*/3$('.js-show-modal').on('click',function(e){4 e.preventDefault();5 var sp_ma = $(this).data('sp-ma');6 $(`.js-modal-${sp_ma}`).addClass('show-modal1');7});8 9$('.js-hide-modal').on('click',function(){10 var sp_ma = $(this).data('sp-ma');11 $(`.js-modal-${sp_ma}`).removeClass('show-modal1');12});Step 4: hiệu chỉnh template nút Add to cart
Hiệu chỉnh file public/vendor/ngCart/template/ngCart/addtocart.html
html
1<div ng-hide="attrs.id">2 <button class="flex-c-m stext-101 cl0 size-101 bg1 bor1 hov-btn1 p-lr-15 trans-04 js-addcart-detail" 3 ng-disabled="true" ng-transclude>4 </button>5</div>6 7<div ng-show="attrs.id"></div>8 <span ng-show="quantityMax">9 <select class="form-control" name="quantity" id="quantity" ng-model="q" ng-options=" v for v in qtyOpt"></select>10 </span>11 12 <button class="flex-c-m stext-101 cl0 size-101 bg1 bor1 hov-btn1 p-lr-15 trans-04 js-addcart-detail mt-2" 13 ng-click="ngCart.addItem(id, name, price, q, data)"14 ng-transclude>15 </button>16 <mark ng-show="inCart()">17 Sản phẩm đã có trong giỏ hàng. <a ng-click="ngCart.removeItemById(id)" style="cursor: pointer;">Xóa</a>18 </mark>19</div>
