search settings

This commit is contained in:
Kerim 2023-04-24 10:50:22 +05:00
parent c602ab1123
commit c54d727245
3 changed files with 91 additions and 11 deletions

View File

@ -55,15 +55,24 @@ class Products extends ProductController
]);
if ($validation->fails()) {
return response()->json(['errors'=>$validation->getMessageBag()->all()],422);
return response()->json(['errors' => $validation->getMessageBag()->all()], 422);
}
$content = $cmsRepository->findByUrlKeyOrFail($pageUrl);
// dump($content);
if ($content!=null) {
// return response()->json(['error'=>'Not Found page'],404);
return response([
'data' => $content,
'message' => 'Successfully get page'
]);
} else {
return response([
'status' => 404,
'data' => 'error',
'message' => 'Not found page'
]);
}
}
public function home(SliderRepository $sliderRepository,)
@ -105,17 +114,20 @@ class Products extends ProductController
[
'title' => 'New Products',
'type' => 'product',
'items' => $newProducts
'items' => $newProducts,
'filter' => 'new=1'
],
[
'title' => 'Adv Banner',
'type' => 'banner',
'items' => $banner
'items' => $banner,
'filter' => 'brands=14'
],
[
'title' => 'Featured Products',
'type' => 'product',
'items' => $featuredProducts
'items' => $featuredProducts,
'filter' => 'featured=true'
],
],
]
@ -204,7 +216,7 @@ class Products extends ProductController
public function searchProducts()
{
// return $this->productRepository->searchProductByAttribute(request('key'));
return ProductResource::collection($this->productRepository->searchProductByAttribute(request('key')));
return ProductResource::collection($this->productRepository->searchProductByAttributeNurgul(request('key'), request('perPage')));
}
public function discountedProducts()

View File

@ -91,7 +91,7 @@ class OrderResource extends JsonResource
$data = array();
foreach($items as $item){
$seller = $this->sellerProductRepository->getSellerByProductId($item->product_id);
$data[$seller->shop_title ?? 'outlet']['products'][] = OrderItemResource::make($item);
$data[$seller->shop_title ?? 'nurgulShop']['products'][] = OrderItemResource::make($item);
// $data[$seller->shop_title ?? 'outlet']['logo'] = $seller->logo ? Storage::url($seller->logo) : null;
// $data[$seller->shop_title ?? 'outlet']['slogan'] = $seller->slogan;
// $data[$seller->shop_title ?? 'outlet']['review_average'] = $seller->review_average;

View File

@ -59,6 +59,74 @@ class ProductRepository extends WProductRepository
*
* @return \Illuminate\Support\Collection
*/
public function searchProductByAttributeNurgul($term, $perPage)
{
$channel = core()->getRequestedChannelCode();
$locale = core()->getRequestedLocaleCode();
if (config('scout.driver') == 'algolia') {
$results = app(ProductFlatRepository::class)->getModel()::search('query', function ($searchDriver, string $query, array $options) use ($term, $channel, $locale) {
$queries = explode('_', $term);
$options['similarQuery'] = array_map('trim', $queries);
$searchDriver->setSettings([
'attributesForFaceting' => [
'searchable(locale)',
'searchable(channel)',
],
]);
$options['facetFilters'] = ['locale:' . $locale, 'channel:' . $channel];
return $searchDriver->search($query, $options);
})
->where('status', 1)
->where('visible_individually', 1)
->orderBy('product_id', 'desc')
->paginate($perPage);
} else if (config('scout.driver') == 'elastic') {
$queries = explode('_', $term);
$results = app(ProductFlatRepository::class)->getModel()::search(implode(' OR ', $queries))
->where('status', 1)
->where('visible_individually', 1)
->where('channel', $channel)
->where('locale', $locale)
->orderBy('product_id', 'desc')
->paginate($perPage);
} else {
$results = app(ProductFlatRepository::class)->scopeQuery(function ($query) use ($term, $channel, $locale) {
$query = $query->distinct()
->addSelect('product_flat.*')
->where('product_flat.channel', $channel)
->where('product_flat.locale', $locale)
->whereNotNull('product_flat.url_key');
if (! core()->getConfigData('catalog.products.homepage.out_of_stock_items')) {
$query = $this->checkOutOfStockItem($query);
}
return $query->where('product_flat.status', 1)
->where('product_flat.visible_individually', 1)
->where(function ($subQuery) use ($term) {
$queries = explode('_', $term);
foreach (array_map('trim', $queries) as $value) {
$subQuery->orWhere('product_flat.name', 'like', '%' . urldecode($value) . '%')
->orWhere('product_flat.short_description', 'like', '%' . urldecode($value) . '%');
}
})
->orderBy('product_id', 'desc');
})->paginate($perPage);
}
return $results;
}
public function getAll($categoryId = null)
{
$params = request()->input();