added search for teamstore

This commit is contained in:
franknstayn
2022-03-19 20:00:34 +08:00
parent 1addae0652
commit 1d6d79f2ae
4 changed files with 228 additions and 171 deletions

View File

@@ -32,7 +32,43 @@ class TeamStoreController extends Controller
$UserModel = new UserModel; $UserModel = new UserModel;
$store_array = $m->selectTeamStore('StoreUrl', $teamStoreURL); $store_array = $m->selectTeamStore('StoreUrl', $teamStoreURL);
$product_array = $m->selectTeamStoreProducts('TeamStoreId', $store_array[0]->Id); // $product_array = $m->selectTeamStoreProducts('TeamStoreId', $store_array[0]->Id);
$q = $request->input('q');
$sort = $request->input('s');
if (isset($q) && isset($sort)) {
if ($sort == "latest") {
$field = "Id";
$sort_value = "DESC";
} elseif ($sort == "al-desc") {
$field = "ProductName";
$sort_value = "DESC";
} elseif ($sort == "oldest") {
$field = "Id";
$sort_value = "ASC";
} else {
$field = "ProductName";
$sort_value = "ASC";
}
if ($q != "") {
// keyword and sort
$product_array = $m->searchTeamstoreProducts('TeamStoreId', $store_array[0]->Id, $field, $sort_value, $q);
} else {
// sort only
$product_array = $m->filterTeamstoreProducts('TeamStoreId', $store_array[0]->Id, $field, $sort_value);
}
} else {
$field = "ProductName";
$sort_value = "ASC";
$sort = "al-asc";
$product_array = $m->filterTeamstoreProducts('TeamStoreId', $store_array[0]->Id, $field, $sort_value);
}
$user_role = ''; $user_role = '';
if (Auth::check()) { if (Auth::check()) {
@@ -60,9 +96,13 @@ class TeamStoreController extends Controller
} }
$thumbnails = [];
foreach ($product_array as $p => $pr_arr) { foreach ($product_array as $p => $pr_arr) {
$thumbnails_array = $m->getProductThumbnails($pr_arr->Id); $thumbnails_array = $m->getProductThumbnails($pr_arr->Id);
$displayThumbnails = "product-image-placeholder.png";
if (!empty($thumbnails_array)) { if (!empty($thumbnails_array)) {
foreach ($thumbnails_array as $t => $thumb) { foreach ($thumbnails_array as $t => $thumb) {
@@ -104,11 +144,13 @@ class TeamStoreController extends Controller
'DateCreated' => "" 'DateCreated' => ""
); );
} }
// var_dump($thumbnails);
return view('teamstore-sublayouts.index') return view('teamstore-sublayouts.index')
->with('store_array', $store_array) ->with('store_array', $store_array)
->with('product_array', $product_array) ->with('product_array', $product_array)
->with('announcement', $data) ->with('announcement', $data)
->with('keyword', $q)
->with('filter', $sort)
->with('thumbnails', $thumbnails); ->with('thumbnails', $thumbnails);
} }

View File

@@ -286,11 +286,35 @@ class TeamStoreModel extends Model
return $i; return $i;
} }
function selectRoster($productId){ function selectRoster($productId)
{
$i = DB::table('roster') $i = DB::table('roster')
->where("ProductId", $productId) ->where("ProductId", $productId)
->get(); ->get();
return $i; return $i;
} }
function filterTeamstoreProducts($field1, $value1, $field2, $value2)
{
$i = DB::table('teamstore_products')
->where($field1, $value1)
->where('PrivacyStatus', 'public')
->orderBy($field2, $value2)->get();
// ->orderBy('Ordering', 'ASC')->get();
return $i;
}
function searchTeamstoreProducts($field1, $value1, $field2, $value2, $keyword)
{
$i = DB::table('teamstore_products')
->where($field1, $value1)
->where('PrivacyStatus', 'public')
->where("ProductName", "LIKE", "%$keyword%")
->orderBy($field2, $value2)->get();
// ->orderBy('Ordering', 'ASC')->get();
return $i;
}
} }

View File

@@ -796,6 +796,11 @@
var name = selected.val(); var name = selected.val();
$(this).closest("tr").find("input[name='order_number[]']").val(number) $(this).closest("tr").find("input[name='order_number[]']").val(number)
}); });
$('#filter_product').change(function() {
this.form.submit();
});
}); //end document ready }); //end document ready
</script> </script>
</body> </body>

View File

@@ -1,6 +1,5 @@
@extends('merchbay_main') @extends('merchbay_main')
@section('main-content') @section('main-content')
@if ($store_array[0]->IsHibernated) @if ($store_array[0]->IsHibernated)
<script> <script>
window.location = "../"; window.location = "../";
@@ -13,12 +12,8 @@
<div class="row"> <div class="row">
<div class="col-lg-12 text-center"> <div class="col-lg-12 text-center">
<div class="store-banner border-top"> <div class="store-banner border-top">
<img <img src="{{ config('site_config.uploads') .'teamstore/' .$store_array[0]->ImageFolder .'/' .$store_array[0]->StoreBanner }}"
src="{{ config('site_config.uploads') . 'teamstore/' . $store_array[0]->ImageFolder . '/' . $store_array[0]->StoreBanner }}" id="storeBanner" class="shadow-sm img-fluid w-100" alt="{{ $store_array[0]->StoreName }}" />
id="storeBanner"
class="shadow-sm img-fluid w-100"
alt="{{$store_array[0]->StoreName}}"
/>
</div> </div>
</div> </div>
</div> </div>
@@ -76,52 +71,47 @@
@endif @endif
</div> </div>
</div> </div>
<form id="frm_product_filter">
<div class="row py-4"> <div class="row py-4">
<div class="col-lg-7"> <div class="col-lg-7">
<form class="row g-2 g-lg-5"> <div method="get" class="row g-2 g-lg-5">
<div class="col-lg-9"> <div class="col-lg-9">
<div class="input-group"> <div class="input-group">
<input <input type="text" class="form-control border-end-0" placeholder="Search Item"
type="text" aria-label="Search Item" aria-describedby="basic-addon2" name="q"
class="form-control border-end-0" value="{{ $keyword }}" />
placeholder="Search Item" <span class="input-group-text bg-white border-start-0" id="basic-addon2"><i
aria-label="Search Item" class="fa fa-search"></i></span>
aria-describedby="basic-addon2" </div>
/>
<span
class="input-group-text bg-white border-start-0"
id="basic-addon2"
><i class="bi bi-search"></i
></span>
</div> </div>
</div> </div>
</form>
</div> </div>
<div class="col-lg-5"> <div class="col-lg-5">
<form <div class="row g-2 g-lg-5 justify-content-end align-items-center">
class="row g-2 g-lg-5 justify-content-end align-items-center"
>
<div class="col-lg-12"> <div class="col-lg-12">
<div class="row"> <div class="row">
<div class="col-md-5 sort-by"> <div class="col-md-5 sort-by">
<label for="selectSortBy" class="col-form-label" <label for="selectSortBy" class="col-form-label">Sort by:</label>
>Sort by:</label
>
</div> </div>
<div class="col-md-7"> <div class="col-md-7">
<select name="sort" class="form-control" id="sort"> <select name="s" class="form-control" id="filter_product">
<option value="">Store Name A → Z</option> <option value="latest" @if ($filter === 'latest') selected @endif
<option value="">Store Name Z → A</option> selected>Newest → Oldest</option>
<option value="">Newest → Oldest</option> <option value="oldest" @if ($filter === 'oldest') selected @endif>
<option value="">Oldest → Newest</option> Oldest → Newest</option>
<option value="al-asc" @if ($filter === 'al-asc') selected @endif>
Store Name A → Z</option>
<option value="al-desc" @if ($filter === 'al-desc') selected @endif>
Store Name Z → A</option>
</select> </select>
</div> </div>
</div> </div>
</div> </div>
</div>
</div>
</div>
</form> </form>
</div>
</div>
<div class="row"> <div class="row">
<div class="col-lg-12"> <div class="col-lg-12">
@@ -129,9 +119,9 @@
</div> </div>
</div> </div>
@if (count($thumbnails))
<div class="row"> <div class="row">
@foreach ($product_array as $i => $product) @foreach ($product_array as $i => $product)
@if($product->PrivacyStatus == "public")
@foreach ($thumbnails as $t => $thumb) @foreach ($thumbnails as $t => $thumb)
@if ($thumb['product_id'] == $product->Id) @if ($thumb['product_id'] == $product->Id)
@define $storeFolder = $thumb['folder'] @define $storeFolder = $thumb['folder']
@@ -141,45 +131,41 @@
<div class="col-lg-3 col-md-3 col-sm-4"> <div class="col-lg-3 col-md-3 col-sm-4">
<div class="p-3 product"> <div class="p-3 product">
<a href="{{ url('store') }}/{{ $store_array[0]->StoreUrl }}/product/{{ $product->ProductURL }}"> <a
href="{{ url('store') }}/{{ $store_array[0]->StoreUrl }}/product/{{ $product->ProductURL }}">
<div class="product-image"> <div class="product-image">
<img <img src="{{ config('site_config.images_url') }}/{{ $filename }}"
src="{{ config('site_config.images_url') }}/{{ $filename }}" class="d-block border shadow-sm" alt="{{ $product->ProductName }}" />
class="d-block border shadow-sm"
alt="{{ $product->ProductName }}"
/>
</div> </div>
</a> </a>
<div class="row"> <div class="row">
<div class="col-sm-8"> <div class="col-sm-8">
<div class="store-name">{{ $product->ProductName }}</div> <div class="store-name">{{ $product->ProductName }}</div>
<div class="product-price d-flex"> <div class="product-price d-flex">
<div class="price">{{ $store_array[0]->StoreCurrency }} {{ $product->ProductPrice }}</div> <div class="price">{{ $store_array[0]->StoreCurrency }}
{{ $product->ProductPrice }}</div>
</div> </div>
</div> </div>
<div class="col-sm-4 py-2"> <div class="col-sm-4 py-2">
<a <a href="{{ url('store') }}/{{ $store_array[0]->StoreUrl }}/product/{{ $product->ProductURL }}"
href="{{ url('store') }}/{{ $store_array[0]->StoreUrl }}/product/{{ $product->ProductURL }}" class="btn btn-sm btn-black w-100">View</a>
class="btn btn-sm btn-black w-100"
>View</a
>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
@endif
@endforeach @endforeach
<!-- END PRODUCTS --> <!-- END PRODUCTS -->
</div>
{{-- @else
<div class="row">
<div class="col-lg-12"> <div class="col-lg-12">
<div class="py-4 text-center"> <h4 class="text-center py-4 text-muted">No Product Found.</h4>
<button type="submit" class="btn btn-black mb-3 px-5">
View more
</button>
</div> </div>
</div> --}}
</div> </div>
@endif
</div> </div>
</div> </div>
</div> </div>