diff --git a/packages/Sarga/API/Http/Controllers/Categories.php b/packages/Sarga/API/Http/Controllers/Categories.php index e02a2cee5..c8aa73849 100644 --- a/packages/Sarga/API/Http/Controllers/Categories.php +++ b/packages/Sarga/API/Http/Controllers/Categories.php @@ -3,6 +3,7 @@ namespace Sarga\API\Http\Controllers; use App\Http\Controllers\Controller; +use Sarga\API\Http\Resources\Catalog\Attribute; use Sarga\API\Http\Resources\Catalog\Category; use Sarga\Shop\Repositories\CategoryRepository; @@ -33,4 +34,14 @@ class Categories extends Controller } + public function filters($id){ + $category = $this->categoryRepository->with('filterableAttributes')->find($id); + + if($category) + return Attribute::collection($category->filterableAttributes); + else{ + return response()->json(['error'=>'not found'],404); + } + } + } \ No newline at end of file diff --git a/packages/Sarga/API/Http/routes.php b/packages/Sarga/API/Http/routes.php index c1b21331f..667b26bbb 100644 --- a/packages/Sarga/API/Http/routes.php +++ b/packages/Sarga/API/Http/routes.php @@ -33,6 +33,7 @@ Route::group(['prefix' => 'api'], function ($router) { 'repository' => CategoryRepository::class, 'resource' => Category::class, ])->name('api.categories'); + Route::get('categories/{id}/filters',[Categories::class,'filters']); //attributes by code Route::get('attribute-options', [ResourceController::class, 'index'])->defaults('_config', [ 'repository' => AttributeOptionRepository::class,