From 1d6d79f2ae29fc84a8ff9c1007bdfbda2f2398f2 Mon Sep 17 00:00:00 2001 From: franknstayn Date: Sat, 19 Mar 2022 20:00:34 +0800 Subject: [PATCH] added search for teamstore --- .../teamstore/TeamStoreController.php | 48 ++- app/Models/teamstore/TeamStoreModel.php | 30 +- resources/views/merchbay_main.blade.php | 5 + .../teamstore-sublayouts/index.blade.php | 316 +++++++++--------- 4 files changed, 228 insertions(+), 171 deletions(-) diff --git a/app/Http/Controllers/teamstore/TeamStoreController.php b/app/Http/Controllers/teamstore/TeamStoreController.php index 189d20c..7e47931 100755 --- a/app/Http/Controllers/teamstore/TeamStoreController.php +++ b/app/Http/Controllers/teamstore/TeamStoreController.php @@ -32,7 +32,43 @@ class TeamStoreController extends Controller $UserModel = new UserModel; $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 = ''; if (Auth::check()) { @@ -59,10 +95,14 @@ class TeamStoreController extends Controller } } - + + $thumbnails = []; foreach ($product_array as $p => $pr_arr) { $thumbnails_array = $m->getProductThumbnails($pr_arr->Id); + $displayThumbnails = "product-image-placeholder.png"; + + if (!empty($thumbnails_array)) { foreach ($thumbnails_array as $t => $thumb) { @@ -104,11 +144,13 @@ class TeamStoreController extends Controller 'DateCreated' => "" ); } - + // var_dump($thumbnails); return view('teamstore-sublayouts.index') ->with('store_array', $store_array) ->with('product_array', $product_array) ->with('announcement', $data) + ->with('keyword', $q) + ->with('filter', $sort) ->with('thumbnails', $thumbnails); } diff --git a/app/Models/teamstore/TeamStoreModel.php b/app/Models/teamstore/TeamStoreModel.php index 3e2a137..f564ab1 100755 --- a/app/Models/teamstore/TeamStoreModel.php +++ b/app/Models/teamstore/TeamStoreModel.php @@ -286,11 +286,35 @@ class TeamStoreModel extends Model return $i; } - function selectRoster($productId){ + function selectRoster($productId) + { $i = DB::table('roster') - ->where("ProductId", $productId) - ->get(); + ->where("ProductId", $productId) + ->get(); + 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; } } diff --git a/resources/views/merchbay_main.blade.php b/resources/views/merchbay_main.blade.php index 82aeb24..cffb758 100755 --- a/resources/views/merchbay_main.blade.php +++ b/resources/views/merchbay_main.blade.php @@ -796,6 +796,11 @@ var name = selected.val(); $(this).closest("tr").find("input[name='order_number[]']").val(number) }); + + + $('#filter_product').change(function() { + this.form.submit(); + }); }); //end document ready diff --git a/resources/views/teamstore-sublayouts/index.blade.php b/resources/views/teamstore-sublayouts/index.blade.php index ea51b04..bb9205a 100755 --- a/resources/views/teamstore-sublayouts/index.blade.php +++ b/resources/views/teamstore-sublayouts/index.blade.php @@ -1,186 +1,172 @@ @extends('merchbay_main') @section('main-content') - -@if ($store_array[0]->IsHibernated) - -@endif + @if ($store_array[0]->IsHibernated) + + @endif -
-
-
-
-
- {{$store_array[0]->StoreName}} -
+
+
+
+
+
+ {{ $store_array[0]->StoreName }} +
+
-
-
-
-
-
-
-

Please read:

-
    -
  1. - Items purchased are made on demand. Orders will be shipped - based on dates set by your store administrator. -
  2. -
  3. - Store payments are processed through PayPal. A PayPal - account is not required to make a purchase. -
  4. -
  5. - Orders will be batch processed on a weekly basis, please allow 4-8 weeks for delivery -
  6. -
  7. - We are currently only shipping to US locations. For - international orders, please contact orders@merchbay.com - if you'd like to place an order. -
  8. -
  9. Expect shipping delays due to COVID-19.
  10. -
  11. - All sales are final. No returns or exchanges will be - accepted. -
  12. -
  13. - Be advised payments made on merchbay will show up as crewsportswear on your receipt -
  14. -
-
- -
-

Disclaimer

-
- Masks and gaiters sold by Merchbay are not intended for - medical use. Merchbay does not make any medical or health - claims. -
-
- - @if ($announcement->IsActive) -
-

Announcements:

-
- {!! nl2br(e($announcement->Announcement)) !!} -
-
- @endif -
-
- -
-
-
-
-
- - -
-
-
-
-
-
+
+
+
-
-
- +
+

Please read:

+
    +
  1. + Items purchased are made on demand. Orders will be shipped + based on dates set by your store administrator. +
  2. +
  3. + Store payments are processed through PayPal. A PayPal + account is not required to make a purchase. +
  4. +
  5. + Orders will be batch processed on a weekly basis, please allow 4-8 weeks for delivery +
  6. +
  7. + We are currently only shipping to US locations. For + international orders, please contact orders@merchbay.com + if you'd like to place an order. +
  8. +
  9. Expect shipping delays due to COVID-19.
  10. +
  11. + All sales are final. No returns or exchanges will be + accepted. +
  12. +
  13. + Be advised payments made on merchbay will show up as crewsportswear on your receipt +
  14. +
-
- + +
+

Disclaimer

+
+ Masks and gaiters sold by Merchbay are not intended for + medical use. Merchbay does not make any medical or health + claims. +
+ + @if ($announcement->IsActive) +
+

Announcements:

+
+ {!! nl2br(e($announcement->Announcement)) !!} +
+
+ @endif +
+
+ +
+ +
+
+
+
+ + +
+
+
+
+
+
+
+
+
+ +
+
+ +
+
+
+
- -
-
+ -
-
-

Catalog

+
+
+

Catalog

+
-
+ + @if (count($thumbnails)) +
+ @foreach ($product_array as $i => $product) + @foreach ($thumbnails as $t => $thumb) + @if ($thumb['product_id'] == $product->Id) + @define $storeFolder = $thumb['folder'] + @define $filename = $thumb['thumb'] + @endif + @endforeach -
- @foreach($product_array as $i => $product) - @if($product->PrivacyStatus == "public") - @foreach($thumbnails as $t => $thumb) - @if($thumb['product_id'] == $product->Id) - @define $storeFolder = $thumb['folder'] - @define $filename = $thumb['thumb'] - @endif +
+
+ +
+ {{ $product->ProductName }} +
+
+
+
+
{{ $product->ProductName }}
+
+
{{ $store_array[0]->StoreCurrency }} + {{ $product->ProductPrice }}
+
+
+
+ View +
+
+
+
@endforeach + +
-
-
- -
- {{ $product->ProductName }} -
-
-
-
-
{{ $product->ProductName }}
-
-
{{ $store_array[0]->StoreCurrency }} {{ $product->ProductPrice }}
-
-
-
- View -
-
-
-
- @endif - @endforeach - - - {{-- -
-
- + @else +
+
+

No Product Found.

+
-
--}} + + @endif +
-
@endsection