Channel root category feature added
This commit is contained in:
parent
abd3bba617
commit
cb3da5fc08
|
|
@ -27,7 +27,5 @@ class EventServiceProvider extends ServiceProvider
|
|||
Event::listen('catalog.product.create.after', 'Webkul\Admin\Listeners\Product@afterProductCreated');
|
||||
|
||||
Event::listen('catalog.product.update.after', 'Webkul\Admin\Listeners\Product@afterProductUpdate');
|
||||
|
||||
Event::listen('catalog.product.delete.after', 'Webkul\Admin\Listeners\Product@afterProductDelete');
|
||||
}
|
||||
}
|
||||
|
|
@ -467,6 +467,7 @@ return [
|
|||
'default-locale' => 'Default Locale',
|
||||
'currencies' => 'Currencies',
|
||||
'base-currency' => 'Base Currency',
|
||||
'root-category' => 'Root Category',
|
||||
'inventory_sources' => 'Inventory Sources',
|
||||
'design' => 'Design',
|
||||
'theme' => 'Theme',
|
||||
|
|
|
|||
|
|
@ -56,6 +56,18 @@
|
|||
<span class="control-error" v-if="errors.has('inventory_sources[]')">@{{ errors.first('inventory_sources[]') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('root_category_id') ? 'has-error' : '']">
|
||||
<label for="root_category_id" class="required">{{ __('admin::app.settings.channels.root-category') }}</label>
|
||||
<select v-validate="'required'" class="control" id="root_category_id" name="root_category_id" data-vv-as=""{{ __('admin::app.settings.channels.root-category') }}"">
|
||||
@foreach(app('Webkul\Category\Repositories\CategoryRepository')->getRootCategories() as $category)
|
||||
<option value="{{ $category->id }}" {{ old('root_category_id') == $category->id ? 'selected' : '' }}>
|
||||
{{ $category->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<span class="control-error" v-if="errors.has('root_category_id')">@{{ errors.first('root_category_id') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label for="hostname">{{ __('admin::app.settings.channels.hostname') }}</label>
|
||||
<input class="control" id="hostname" name="hostname" value="{{ old('hostname') }}" placeholder="https://www.example.com"/>
|
||||
|
|
|
|||
|
|
@ -59,6 +59,19 @@
|
|||
<span class="control-error" v-if="errors.has('inventory_sources[]')">@{{ errors.first('inventory_sources[]') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('root_category_id') ? 'has-error' : '']">
|
||||
<label for="root_category_id" class="required">{{ __('admin::app.settings.channels.root-category') }}</label>
|
||||
<?php $selectedOption = old('root_category_id') ?: $channel->root_category_id ?>
|
||||
<select v-validate="'required'" class="control" id="root_category_id" name="root_category_id" data-vv-as=""{{ __('admin::app.settings.channels.root-category') }}"">
|
||||
@foreach(app('Webkul\Category\Repositories\CategoryRepository')->getRootCategories() as $category)
|
||||
<option value="{{ $category->id }}" {{ $selectedOption == $category->id ? 'selected' : '' }}>
|
||||
{{ $category->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<span class="control-error" v-if="errors.has('root_category_id')">@{{ errors.first('root_category_id') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label for="hostname">{{ __('admin::app.settings.channels.hostname') }}</label>
|
||||
<input type="text" class="control" id="hostname" name="hostname" value="{{ $channel->hostname }}" placeholder="https://www.example.com"/>
|
||||
|
|
|
|||
|
|
@ -80,6 +80,17 @@ class CategoryRepository extends Repository
|
|||
: Category::orderBy('position', 'ASC')->get()->toTree();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get root categories
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRootCategories()
|
||||
{
|
||||
return Category::withDepth()->having('depth', '=', 0)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* get visible category tree
|
||||
*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AlterChannelsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('channels', function (Blueprint $table) {
|
||||
$table->integer('root_category_id')->nullable()->unsigned();
|
||||
$table->foreign('root_category_id')->references('id')->on('categories')->onDelete('set null');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
|
@ -77,6 +77,7 @@ class ChannelController extends Controller
|
|||
'default_locale_id' => 'required',
|
||||
'currencies' => 'required|array|min:1',
|
||||
'base_currency_id' => 'required',
|
||||
'root_category_id' => 'required',
|
||||
'logo.*' => 'mimes:jpeg,jpg,bmp,png',
|
||||
'favicon.*' => 'mimes:jpeg,jpg,bmp,png'
|
||||
]);
|
||||
|
|
@ -122,6 +123,7 @@ class ChannelController extends Controller
|
|||
'default_locale_id' => 'required',
|
||||
'currencies' => 'required|array|min:1',
|
||||
'base_currency_id' => 'required',
|
||||
'root_category_id' => 'required',
|
||||
'logo.*' => 'mimes:jpeg,jpg,bmp,png',
|
||||
'favicon.*' => 'mimes:jpeg,jpg,bmp,png'
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -6,11 +6,12 @@ use Illuminate\Database\Eloquent\Model;
|
|||
use Illuminate\Support\Facades\Storage;
|
||||
use Webkul\Core\Models\Locale;
|
||||
use Webkul\Core\Models\Currency;
|
||||
use Webkul\Category\Models\Category;
|
||||
use Webkul\Inventory\Models\InventorySource;
|
||||
|
||||
class Channel extends Model
|
||||
{
|
||||
protected $fillable = ['code', 'name', 'description', 'theme', 'home_page_content', 'footer_content', 'hostname', 'default_locale_id', 'base_currency_id'];
|
||||
protected $fillable = ['code', 'name', 'description', 'theme', 'home_page_content', 'footer_content', 'hostname', 'default_locale_id', 'base_currency_id', 'root_category_id'];
|
||||
|
||||
/**
|
||||
* Get the channel locales.
|
||||
|
|
@ -55,6 +56,14 @@ class Channel extends Model
|
|||
return $this->belongsTo(Currency::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base currency
|
||||
*/
|
||||
public function root_category()
|
||||
{
|
||||
return $this->belongsTo(Category::class, 'root_category_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get logo image url.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class CategoryComposer
|
|||
{
|
||||
$categories = [];
|
||||
|
||||
foreach ($this->category->getVisibleCategoryTree() as $category) {
|
||||
foreach ($this->category->getVisibleCategoryTree(core()->getCurrentChannel()->root_category_id) as $category) {
|
||||
if($category->slug)
|
||||
array_push($categories, $category);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue