From e5b75a92efc8bb4193fcab44eade0de6eef47e38 Mon Sep 17 00:00:00 2001 From: merdan Date: Thu, 28 Oct 2021 20:30:35 +0500 Subject: [PATCH] brendler --- .../Sarga/API/Http/Controllers/Categories.php | 4 --- .../Sarga/API/Http/Controllers/Resources.php | 19 ++++++++++++++ .../API/Http/Resources/Catalog/Attribute.php | 25 +++++++++++++++++++ .../Resources/Catalog/AttributeOption.php | 25 +++++++++++++++++++ .../API/Http/Resources/Catalog/Category.php | 2 +- packages/Sarga/API/Http/routes.php | 9 +++++++ 6 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 packages/Sarga/API/Http/Controllers/Resources.php create mode 100644 packages/Sarga/API/Http/Resources/Catalog/Attribute.php create mode 100644 packages/Sarga/API/Http/Resources/Catalog/AttributeOption.php diff --git a/packages/Sarga/API/Http/Controllers/Categories.php b/packages/Sarga/API/Http/Controllers/Categories.php index 3d57041de..8b1109bcd 100644 --- a/packages/Sarga/API/Http/Controllers/Categories.php +++ b/packages/Sarga/API/Http/Controllers/Categories.php @@ -14,8 +14,4 @@ class Categories extends CategoryController ); } - public function brands($id) - { - - } } \ No newline at end of file diff --git a/packages/Sarga/API/Http/Controllers/Resources.php b/packages/Sarga/API/Http/Controllers/Resources.php new file mode 100644 index 000000000..a86480d87 --- /dev/null +++ b/packages/Sarga/API/Http/Controllers/Resources.php @@ -0,0 +1,19 @@ +_config['authorization_required']) && $this->_config['authorization_required'] ? + $this->repository->where(['customer_id'=>auth()->user()->id,'code'=>$code])->first() : + $this->repository->where('code',$code)->first(); + + if($query) + return new $this->_config['resource']($query); + else + return response()->json(['status'=>false,'message'=>'Not found'],404); + } +} \ No newline at end of file diff --git a/packages/Sarga/API/Http/Resources/Catalog/Attribute.php b/packages/Sarga/API/Http/Resources/Catalog/Attribute.php new file mode 100644 index 000000000..4a4949240 --- /dev/null +++ b/packages/Sarga/API/Http/Resources/Catalog/Attribute.php @@ -0,0 +1,25 @@ + $this->id, + 'code' => $this->code, + 'name' => $this->name, + 'options' => AttributeOption::collection($this->options), + ]; + } + +} \ No newline at end of file diff --git a/packages/Sarga/API/Http/Resources/Catalog/AttributeOption.php b/packages/Sarga/API/Http/Resources/Catalog/AttributeOption.php new file mode 100644 index 000000000..0d26e822e --- /dev/null +++ b/packages/Sarga/API/Http/Resources/Catalog/AttributeOption.php @@ -0,0 +1,25 @@ + $this->id, +// 'admin_name' => $this->admin_name, + 'label' => $this->label, +// 'swatch_value' => $this->swatch_value, + 'image' => $this->swatch_value_url + ]; + } +} \ No newline at end of file diff --git a/packages/Sarga/API/Http/Resources/Catalog/Category.php b/packages/Sarga/API/Http/Resources/Catalog/Category.php index 1c3fa7768..d8dd69993 100644 --- a/packages/Sarga/API/Http/Resources/Catalog/Category.php +++ b/packages/Sarga/API/Http/Resources/Catalog/Category.php @@ -19,7 +19,7 @@ class Category extends JsonResource 'id' => $this->id, // 'code' => $this->code, 'name' => $this->name, -// 'slug' => $this->slug, + 'slug' => $this->slug, // 'display_mode' => $this->display_mode, 'description' => $this->description, // 'status' => $this->status, diff --git a/packages/Sarga/API/Http/routes.php b/packages/Sarga/API/Http/routes.php index 8357ec301..e91effada 100644 --- a/packages/Sarga/API/Http/routes.php +++ b/packages/Sarga/API/Http/routes.php @@ -2,6 +2,9 @@ use Sarga\API\Http\Controllers\Categories; use Sarga\API\Http\Controllers\Channels; +use Sarga\API\Http\Controllers\Resources; +use Webkul\Attribute\Repositories\AttributeRepository; +use Sarga\API\Http\Resources\Catalog\Attribute; Route::group(['prefix' => 'api'], function ($router) { Route::group(['middleware' => ['locale', 'currency']], function ($router) { @@ -12,5 +15,11 @@ Route::group(['prefix' => 'api'], function ($router) { Route::get('descendant-categories', [Categories::class, 'index']); Route::get('category-brands/{id}', [Categories::class, 'brands']); + //attributes by code + Route::get('attribute-by-code/{code}', [Resources::class, 'get'])->defaults('_config', [ + 'repository' => AttributeRepository::class, + 'resource' => Attribute::class, + ]); + }); });