前台产品搜索支持通过sku model筛选
This commit is contained in:
parent
354d43028d
commit
4ce6a39d38
|
|
@ -98,7 +98,6 @@ class ProductRepo
|
||||||
if (isset($data['model'])) {
|
if (isset($data['model'])) {
|
||||||
$query->where('model', 'like', "%{$data['model']}%");
|
$query->where('model', 'like', "%{$data['model']}%");
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,6 +107,18 @@ class ProductRepo
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$keyword = $data['keyword'] ?? '';
|
||||||
|
if ($keyword) {
|
||||||
|
$builder->where(function (Builder $query) use ($keyword) {
|
||||||
|
$query->whereHas('skus', function (Builder $query) use ($keyword) {
|
||||||
|
$query->where('sku', 'like', "%{$keyword}%")
|
||||||
|
->orWhere('model', 'like', "%{$keyword}%");
|
||||||
|
})->orWhereHas('description', function ($query) use ($keyword) {
|
||||||
|
$query->where('name', 'like', "%{$keyword}%");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($data['active'])) {
|
if (isset($data['active'])) {
|
||||||
$builder->where('active', (int)$data['active']);
|
$builder->where('active', (int)$data['active']);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ class ProductController extends Controller
|
||||||
public function search(Request $request)
|
public function search(Request $request)
|
||||||
{
|
{
|
||||||
$keyword = $request->get('keyword');
|
$keyword = $request->get('keyword');
|
||||||
$products = ProductRepo::getBuilder(['name' => $keyword])->where('active', true)->paginate();
|
$products = ProductRepo::getBuilder(['keyword' => $keyword])->where('active', true)->paginate();
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'products' => $products,
|
'products' => $products,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue