sarga filters
This commit is contained in:
parent
eeb843cdd6
commit
bde7603f7b
|
|
@ -4,9 +4,11 @@ namespace Sarga\API\Http\Controllers;
|
|||
|
||||
use Sarga\API\Http\Resources\Core\Slider;
|
||||
use Webkul\Core\Repositories\SliderRepository;
|
||||
use Webkul\RestApi\Http\Controllers\V1\Shop\ResourceController;
|
||||
|
||||
class Banners extends \Webkul\RestApi\Http\Controllers\V1\Shop\Core\CoreController
|
||||
class Banners extends ResourceController
|
||||
{
|
||||
protected $requestException = ['page', 'limit', 'pagination', 'sort', 'order', 'token','locale'];
|
||||
/**
|
||||
* Resource class name.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@ namespace Sarga\API\Http\Controllers;
|
|||
|
||||
use Sarga\API\Http\Resources\Core\CMSResource;
|
||||
use Webkul\CMS\Repositories\CmsRepository;
|
||||
use Webkul\RestApi\Http\Controllers\V1\Shop\Core\CoreController;
|
||||
use Webkul\RestApi\Http\Controllers\V1\Shop\ResourceController;
|
||||
|
||||
class CMSController extends CoreController
|
||||
class CMSController extends ResourceController
|
||||
{
|
||||
protected $requestException = ['page', 'limit', 'pagination', 'sort', 'order', 'token','locale'];
|
||||
/**
|
||||
* Resource class name.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -2,42 +2,43 @@
|
|||
|
||||
namespace Sarga\API\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Sarga\API\Http\Resources\Catalog\Attribute;
|
||||
use Sarga\API\Http\Resources\Catalog\Brand;
|
||||
use Sarga\API\Http\Resources\Catalog\Category;
|
||||
use Sarga\API\Http\Resources\Catalog\Category as CategoryResource;
|
||||
use Sarga\Shop\Repositories\CategoryRepository;
|
||||
use Webkul\RestApi\Http\Controllers\V1\Shop\Catalog\CategoryController;
|
||||
|
||||
|
||||
class Categories extends Controller
|
||||
class Categories extends CategoryController
|
||||
{
|
||||
|
||||
public function __construct(protected CategoryRepository $categoryRepository)
|
||||
// protected $requestException = ['page', 'limit', 'pagination', 'sort', 'order', 'token','locale'];
|
||||
/**
|
||||
* Repository class name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function repository()
|
||||
{
|
||||
return CategoryRepository::class;
|
||||
}
|
||||
public function index()
|
||||
/**
|
||||
* Resource class name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function resource()
|
||||
{
|
||||
return Category::collection(
|
||||
$this->categoryRepository->getVisibleCategoryTree(request()->input('parent_id'))
|
||||
);
|
||||
}
|
||||
|
||||
public function details($id){
|
||||
$children = $this->categoryRepository->findWhere(['parent_id' => $id, 'status'=>1])
|
||||
->orderBy('position', 'ASC');
|
||||
|
||||
return CategoryResource::class;
|
||||
}
|
||||
|
||||
public function filters($id){
|
||||
$category = $this->categoryRepository->with(['filterableAttributes','children',
|
||||
'brands' => function ($q){
|
||||
$q->where('status',1);
|
||||
$category = $this->categoryRepository->with(['filterableAttributes','brands' => function ($q){
|
||||
$q->take(20);
|
||||
} ])
|
||||
->find($id);
|
||||
|
||||
if($category)
|
||||
return response([
|
||||
'subcategories' => Category::collection($category->children),
|
||||
'attributes' => Attribute::collection($category->filterableAttributes),
|
||||
'brands' => Brand::collection($category->brands),
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Sarga\API\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Sarga\API\Http\Resources\Catalog\Attribute;
|
||||
use Sarga\API\Http\Resources\Catalog\Brand;
|
||||
use Sarga\Brand\Repositories\BrandRepository;
|
||||
use Sarga\Shop\Repositories\CategoryRepository;
|
||||
use Webkul\Attribute\Repositories\AttributeRepository;
|
||||
use Webkul\RestApi\Http\Controllers\V1\V1Controller;
|
||||
|
||||
class Filters extends V1Controller
|
||||
{
|
||||
public function __construct(protected CategoryRepository $categoryRepository,
|
||||
protected BrandRepository $brandRepository,
|
||||
protected AttributeRepository $attributeRepository
|
||||
){}
|
||||
|
||||
public function index(Request $request){
|
||||
|
||||
if($request->has('category')){
|
||||
|
||||
$categories = $this->categoryRepository->with(['filterableAttributes','brands' => function ($q){
|
||||
$q->take(20);
|
||||
} ]);
|
||||
|
||||
$categories->find($request->get('category'));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function filters($id){
|
||||
$category = $this->categoryRepository->with(['filterableAttributes','children',
|
||||
'brands' => function ($q){
|
||||
$q->where('status',1);
|
||||
} ])
|
||||
->find($id);
|
||||
|
||||
if($category)
|
||||
return response([
|
||||
'subcategories' => Category::collection($category->children),
|
||||
'attributes' => Attribute::collection($category->filterableAttributes),
|
||||
'brands' => Brand::collection($category->brands),
|
||||
]);
|
||||
else{
|
||||
return response(['error'=>'not found'],404);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
namespace Sarga\API\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Sarga\API\Http\Resources\Catalog\Suggestion;
|
||||
use Sarga\Brand\Repositories\BrandRepository;
|
||||
use Sarga\Shop\Repositories\CategoryRepository;
|
||||
use Webkul\Category\Models\CategoryTranslationProxy;
|
||||
use Webkul\Product\Repositories\ProductFlatRepository;
|
||||
use Webkul\RestApi\Http\Controllers\V1\V1Controller;
|
||||
|
||||
class SearchController extends Controller
|
||||
class SearchController extends V1Controller
|
||||
{
|
||||
public function __construct(protected BrandRepository $brandRepository,
|
||||
protected ProductFlatRepository $productFlatRepository,
|
||||
|
|
|
|||
|
|
@ -10,11 +10,9 @@ use Sarga\Shop\Repositories\ProductRepository;
|
|||
use Sarga\Brand\Repositories\BrandRepository;
|
||||
use Sarga\Shop\Repositories\CategoryRepository;
|
||||
use Sarga\Shop\Repositories\VendorRepository;
|
||||
use Webkul\API\Http\Controllers\Shop\Controller;
|
||||
use Webkul\Marketplace\Repositories\SellerRepository;
|
||||
use Webkul\Product\Repositories\ProductFlatRepository;
|
||||
use Webkul\RestApi\Http\Controllers\V1\V1Controller;
|
||||
|
||||
class Vendors extends Controller
|
||||
class Vendors extends V1Controller
|
||||
{
|
||||
|
||||
public function __construct(protected VendorRepository $vendorRepository,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class Attribute extends JsonResource
|
|||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name ?? $this->admin_name,
|
||||
'options' => AttributeOption::collection($this->options),
|
||||
'options' => AttributeOption::collection($this->options()->take(20)->get()),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,8 +36,7 @@ Route::group(['prefix' => 'api'], function () {
|
|||
Route::get('vendor/brands/{vendor_id}',[Vendors::class,'brands'])->name('api.vendor.brands');
|
||||
|
||||
//category routes
|
||||
Route::get('descendant-categories', [Categories::class, 'index'])->name('api.descendant-categories');
|
||||
Route::get('category-details/{id}', [Categories::class, 'details']);
|
||||
Route::get('descendant-categories', [Categories::class, 'descendantCategories'])->name('api.descendant-categories');
|
||||
Route::get('categories', [ResourceController::class, 'index'])->defaults('_config', [
|
||||
'repository' => CategoryRepository::class,
|
||||
'resource' => Category::class,
|
||||
|
|
|
|||
Loading…
Reference in New Issue