sarga filters
This commit is contained in:
parent
a30a4bbb3c
commit
150758db51
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace Sarga\API\Http\Controllers;
|
||||
|
||||
use Sarga\API\Http\Resources\Catalog\AttributeOption;
|
||||
use Sarga\Shop\Repositories\AttributeOptionRepository;
|
||||
|
||||
class AttributeOptions extends \Webkul\RestApi\Http\Controllers\V1\Shop\ResourceController
|
||||
{
|
||||
protected $requestException = ['page', 'limit', 'pagination', 'sort', 'order', 'token','locale'];
|
||||
/**
|
||||
* Repository class name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function repository()
|
||||
{
|
||||
return AttributeOptionRepository::class;
|
||||
}
|
||||
/**
|
||||
* Resource class name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function resource()
|
||||
{
|
||||
return AttributeOption::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is resource authorized.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isAuthorized()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@ use Webkul\RestApi\Http\Controllers\V1\Shop\Catalog\CategoryController;
|
|||
|
||||
class Categories extends CategoryController
|
||||
{
|
||||
// protected $requestException = ['page', 'limit', 'pagination', 'sort', 'order', 'token','locale'];
|
||||
protected $requestException = ['page', 'limit', 'pagination', 'sort', 'order', 'token','locale'];
|
||||
/**
|
||||
* Repository class name.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,50 +0,0 @@
|
|||
<?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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ class Vendors extends V1Controller
|
|||
}
|
||||
|
||||
public function sources(){
|
||||
$vendors = $this->vendorRepository->select('marketplace_sellers.id','url','logo','banner','shop_title','brand_attribute_id')
|
||||
$vendors = $this->vendorRepository->select('marketplace_sellers.id','url','shop_title')
|
||||
->where('is_approved',true)
|
||||
->with(['categories:seller_id,type,categories'])
|
||||
// ->leftJoin('seller_categories','marketplace_sellers.id','=','seller_categories.seller_id')
|
||||
|
|
|
|||
|
|
@ -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()->take(40)->get()),
|
||||
'options' => AttributeOption::collection($this->options()->take(20)->get()),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,11 +18,9 @@ class Source extends \Illuminate\Http\Resources\Json\JsonResource
|
|||
'id' => $this->id,
|
||||
'shop_title' => $this->shop_title,
|
||||
'logo' => $this->logo_url,
|
||||
'banner' => $this->banner_url,
|
||||
$this->mergeWhen(!empty($this->main_categories) && $this->main_categories->count(),[
|
||||
'categories' => VendorCategory::collection($this->main_categories)
|
||||
])
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Sarga\API\Http\Controllers\Addresses;
|
||||
use Sarga\API\Http\Controllers\AttributeOptions;
|
||||
use Sarga\API\Http\Controllers\Carts;
|
||||
use Sarga\API\Http\Controllers\Checkout;
|
||||
use Sarga\API\Http\Controllers\Customers;
|
||||
|
|
@ -37,11 +38,9 @@ Route::group(['prefix' => 'api'], function () {
|
|||
|
||||
//category routes
|
||||
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,
|
||||
])->name('api.categories');
|
||||
Route::get('categories', [Categories::class, 'allResources'])->name('api.categories');
|
||||
Route::get('categories/{id}/filters',[Categories::class,'filters']);
|
||||
Route::get('attribute-options', [AttributeOptions::class, 'allResources']);
|
||||
|
||||
//attributes by code
|
||||
Route::get('attribute-options', [ResourceController::class, 'index'])->defaults('_config', [
|
||||
|
|
|
|||
Loading…
Reference in New Issue