diff --git a/packages/Sarga/API/Http/Controllers/Products.php b/packages/Sarga/API/Http/Controllers/Products.php index 5ee134fff..8313c17f2 100644 --- a/packages/Sarga/API/Http/Controllers/Products.php +++ b/packages/Sarga/API/Http/Controllers/Products.php @@ -11,6 +11,7 @@ use Sarga\Shop\Repositories\ProductRepository; use Webkul\API\Http\Controllers\Shop\ProductController; use Sarga\API\Http\Resources\Catalog\Product as ProductResource; use Sarga\Shop\Repositories\AttributeOptionRepository; +use Webkul\Product\Repositories\ProductFlatRepository; class Products extends ProductController @@ -131,6 +132,18 @@ class Products extends ProductController // ->get(); $products = $this->productRepository->searchProductByAttribute($key); + $queries = explode(' ', $key); + $channel = core()->getRequestedChannelCode(); + + $locale = core()->getRequestedLocaleCode(); + $results = app(ProductFlatRepository::class)->getModel()::search(implode(' OR ', $queries)) + ->select('product_id','sku','name','product_number','url_key',) + ->where('status', 1) + ->where('visible_individually', 1) + ->where('channel', $channel) + ->where('locale', $locale) + ->orderBy('product_id', 'desc') + ->limit(10); return $products; diff --git a/packages/Sarga/Brand/src/Models/Brand.php b/packages/Sarga/Brand/src/Models/Brand.php index d8581c229..4e92575b9 100644 --- a/packages/Sarga/Brand/src/Models/Brand.php +++ b/packages/Sarga/Brand/src/Models/Brand.php @@ -4,6 +4,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Support\Facades\Storage; +use Laravel\Scout\Searchable; use Sarga\Brand\Contracts\Brand as BrandContract; use Webkul\Category\Models\CategoryProxy; use Webkul\Marketplace\Models\SellerProxy; @@ -11,13 +12,30 @@ use Webkul\Product\Models\ProductProxy; class Brand extends Model implements BrandContract { + use Searchable; + + /** + * The table associated with the model. + * + * @var string + */ + protected $table = 'brands'; + protected $fillable = [ 'position', 'status', 'code', 'name' ]; - + /** + * Get the index name for the model. + * + * @return string + */ + public function searchableAs() + { + return 'brands_index'; + } /** * Get image url for the category image. */