Channels list with sliders
This commit is contained in:
parent
a1125752df
commit
64525fcb0b
|
|
@ -105,7 +105,8 @@
|
|||
"Webkul\\SocialLogin\\": "packages/Webkul/SocialLogin/src",
|
||||
"Webkul\\DebugBar\\": "packages/Webkul/DebugBar/src",
|
||||
"Webkul\\Marketing\\": "packages/Webkul/Marketing/src",
|
||||
"Sarga\\Shop\\": "packages/Sarga/Shop/src"
|
||||
"Sarga\\Shop\\": "packages/Sarga/Shop/src",
|
||||
"Sarga\\API\\": "packages/Sarga/API"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
|
|
|
|||
|
|
@ -282,6 +282,8 @@ return [
|
|||
Webkul\SocialLogin\Providers\SocialLoginServiceProvider::class,
|
||||
Webkul\DebugBar\Providers\DebugBarServiceProvider::class,
|
||||
Webkul\Marketing\Providers\MarketingServiceProvider::class,
|
||||
Sarga\Shop\Providers\ShopServiceProvider::class,
|
||||
Sarga\API\Providers\APIServiceProvider::class
|
||||
],
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
<?php namespace Sarga\API\Http\Controllers;
|
||||
|
||||
use Webkul\API\Http\Controllers\Shop\Controller;
|
||||
use Sarga\API\Http\Resources\Core\Channel;
|
||||
use Sarga\Shop\Repositories\ChannelRepository;
|
||||
|
||||
class Channels extends Controller
|
||||
{
|
||||
protected $channelRepository;
|
||||
|
||||
public function __construct(ChannelRepository $channelRepository)
|
||||
{
|
||||
$this->channelRepository = $channelRepository;
|
||||
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
$channels = $this->channelRepository->with('sliders')->get();
|
||||
|
||||
if($channels)
|
||||
{
|
||||
return Channel::collection($channels);
|
||||
}
|
||||
else
|
||||
{
|
||||
return response()->json(['not found'],404);
|
||||
}
|
||||
}
|
||||
|
||||
public function get($channel_id){
|
||||
$this->categoryRepository->getVisibleCategoryTree(request()->input('parent_id'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Sarga\API\Http\Resources\Catalog;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Category extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'slug' => $this->slug,
|
||||
'display_mode' => $this->display_mode,
|
||||
'description' => $this->description,
|
||||
'status' => $this->status,
|
||||
'image_url' => $this->image_url,
|
||||
'category_icon_path' => $this->category_icon_path
|
||||
? Storage::url($this->category_icon_path)
|
||||
: null,
|
||||
'additional' => is_array($this->resource->additional)
|
||||
? $this->resource->additional
|
||||
: json_decode($this->resource->additional, true),
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Sarga\API\Http\Resources\Core;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Sarga\API\Http\Resources\Catalog\Category;
|
||||
|
||||
|
||||
class Channel extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'hostname' => $this->hostname,
|
||||
'root_category_id' => $this->root_category_id,
|
||||
'is_maintenance_on' => $this->is_maintenance_on,
|
||||
'sliders' => Slider::collection($this->sliders)
|
||||
// 'root_category' => $this->when($this->root_category_id, new CategoryResource($this->root_category)),
|
||||
// 'main_categories' => $this->when(request()->has('channel_id'),Category::collection($this->categories))
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Sarga\API\Http\Resources\Core;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Slider extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'image_url' => $this->image_url,
|
||||
'content' => $this->content,
|
||||
'expired_at'=> $this->expired_at,
|
||||
'sort_order'=> $this->sort_order,
|
||||
'slider_path'=>$this->slider_path
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
use Sarga\API\Http\Controllers\Channels;
|
||||
|
||||
Route::group(['prefix' => 'api'], function ($router) {
|
||||
Route::group(['middleware' => ['locale', 'currency']], function ($router) {
|
||||
//Channel routes
|
||||
Route::get('channels',[Channels::class, 'index']);
|
||||
Route::get('channels/{channel_id}',[Channels::class, 'get']);
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
namespace Sarga\API\Providers;
|
||||
use Illuminate\Routing\Router;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class APIServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot(Router $router)
|
||||
{
|
||||
$this->loadRoutesFrom(__DIR__.'/../Http/routes.php');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"name": "sarga/api",
|
||||
"description": "API for Sarga.",
|
||||
"license": "MIT",
|
||||
|
||||
"authors": [
|
||||
{
|
||||
"name": "merdan muhammedow",
|
||||
"email": "merdan.m@gmail.com"
|
||||
}
|
||||
],
|
||||
|
||||
"require": {},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Sarga\\Shop\\": "src/"
|
||||
}
|
||||
},
|
||||
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Sarga\\API\\Providers\\APIerviceProvider"
|
||||
],
|
||||
"aliases": {}
|
||||
}
|
||||
},
|
||||
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<?php namespace Sarga\Shop\Models;
|
||||
use Webkul\Core\Models\Channel as BagistoChannel;
|
||||
use Webkul\Core\Models\SliderProxy;
|
||||
|
||||
class Channel extends BagistoChannel
|
||||
{
|
||||
public function sliders()
|
||||
{
|
||||
return $this->hasMany(SliderProxy::modelClass());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Sarga\Shop\Models;
|
||||
|
||||
use Webkul\Core\Models\ChannelTranslation as BagistoChannelTranslation;
|
||||
class ChannelTranslation extends BagistoChannelTranslation
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Sarga\Shop\Repositories;
|
||||
|
||||
use Sarga\Shop\Models\Channel;
|
||||
use Webkul\Core\Repositories\ChannelRepository as BagistoChannelRepo;
|
||||
|
||||
class ChannelRepository extends BagistoChannelRepo
|
||||
{
|
||||
function model()
|
||||
{
|
||||
return Channel::class;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
namespace Webkul\API\Http\Resources\Checkout;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Webkul\API\Http\Resources\Core\Channel as ChannelResource;
|
||||
use Webkul\API\Http\Resources\Core\ChannelResource as ChannelResource;
|
||||
use Webkul\API\Http\Resources\Customer\Customer as CustomerResource;
|
||||
use Webkul\Tax\Helpers\Tax;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
namespace Webkul\API\Http\Resources\Sales;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Webkul\API\Http\Resources\Core\Channel as ChannelResource;
|
||||
use Webkul\API\Http\Resources\Core\ChannelResource as ChannelResource;
|
||||
use Webkul\API\Http\Resources\Customer\Customer as CustomerResource;
|
||||
|
||||
class Order extends JsonResource
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ use Webkul\API\Http\Resources\Catalog\Attribute;
|
|||
use Webkul\API\Http\Resources\Catalog\AttributeFamily;
|
||||
use Webkul\API\Http\Resources\Catalog\Category;
|
||||
use Webkul\API\Http\Resources\Catalog\ProductReview;
|
||||
use Webkul\API\Http\Resources\Core\Channel;
|
||||
use Webkul\API\Http\Resources\Core\ChannelResource;
|
||||
use Webkul\API\Http\Resources\Core\Country;
|
||||
use Webkul\API\Http\Resources\Core\Currency;
|
||||
use Webkul\API\Http\Resources\Core\Locale;
|
||||
|
|
@ -133,12 +133,12 @@ Route::group(['prefix' => 'api'], function ($router) {
|
|||
//Channel routes
|
||||
Route::get('channels', [ResourceController::class, 'index'])->defaults('_config', [
|
||||
'repository' => ChannelRepository::class,
|
||||
'resource' => Channel::class,
|
||||
'resource' => ChannelResource::class,
|
||||
]);
|
||||
|
||||
Route::get('channels/{id}', [ResourceController::class, 'get'])->defaults('_config', [
|
||||
'repository' => ChannelRepository::class,
|
||||
'resource' => Channel::class,
|
||||
'resource' => ChannelResource::class,
|
||||
]);
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue