Merge pull request #422 from jitendra-webkul/jitendra

Channel root category feature added
This commit is contained in:
JItendra Singh 2018-12-31 16:35:50 +05:30 committed by GitHub
commit 4e89ce082e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 81 additions and 4 deletions

View File

@ -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');
}
}

View File

@ -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',

View File

@ -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="&quot;{{ __('admin::app.settings.channels.root-category') }}&quot;">
@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"/>

View File

@ -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="&quot;{{ __('admin::app.settings.channels.root-category') }}&quot;">
@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"/>

View File

@ -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
*

View File

@ -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()
{
//
}
}

View File

@ -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'
]);

View File

@ -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.
*/

View File

@ -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);
}