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;
$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);
}

View File

@@ -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;
}
}