Merge pull request #4382 from devansh-webkul/locale-wise-channel-settings
Enhancement completed locale wise channel settings
This commit is contained in:
commit
b8ced5861d
|
|
@ -2,18 +2,56 @@
|
|||
|
||||
namespace Webkul\Admin\DataGrids;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Webkul\Ui\DataGrid\DataGrid;
|
||||
use Webkul\Core\Repositories\ChannelRepository;
|
||||
|
||||
class ChannelDataGrid extends DataGrid
|
||||
{
|
||||
/**
|
||||
* Assign primary key.
|
||||
*/
|
||||
protected $index = 'id';
|
||||
|
||||
/**
|
||||
* Sort order.
|
||||
*/
|
||||
protected $sortOrder = 'desc';
|
||||
|
||||
/**
|
||||
* Filter Locale.
|
||||
*/
|
||||
protected $locale;
|
||||
|
||||
/**
|
||||
* ChannelRepository $channelRepository
|
||||
*
|
||||
* @var \Webkul\Core\Repositories\ChannelRepository
|
||||
*/
|
||||
protected $channelRepository;
|
||||
|
||||
/**
|
||||
* Create a new datagrid instance.
|
||||
*
|
||||
* @param \Webkul\Core\Repositories\ChannelRepository $channelRepository
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
ChannelRepository $channelRepository
|
||||
)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->locale = request()->get('locale') ?? app()->getLocale();
|
||||
|
||||
$this->channelRepository = $channelRepository;
|
||||
}
|
||||
|
||||
public function prepareQueryBuilder()
|
||||
{
|
||||
$queryBuilder = DB::table('channels')->addSelect('id', 'code', 'name', 'hostname');
|
||||
$queryBuilder = $this->channelRepository->query()
|
||||
->leftJoin('channel_translations', 'channel_translations.channel_id', '=', 'channels.id')
|
||||
->addSelect('channels.id', 'channels.code', 'channel_translations.locale', 'channel_translations.name as translated_name', 'channels.hostname')
|
||||
->where('channel_translations.locale', '=', $this->locale);
|
||||
|
||||
$this->setQueryBuilder($queryBuilder);
|
||||
}
|
||||
|
|
@ -39,7 +77,7 @@ class ChannelDataGrid extends DataGrid
|
|||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'name',
|
||||
'index' => 'translated_name',
|
||||
'label' => trans('admin::app.datagrid.name'),
|
||||
'type' => 'string',
|
||||
'searchable' => true,
|
||||
|
|
|
|||
|
|
@ -6,8 +6,9 @@
|
|||
|
||||
@section('content')
|
||||
<div class="content">
|
||||
@php $locale = request()->get('locale') ?: app()->getLocale(); @endphp
|
||||
|
||||
<form method="POST" action="{{ route('admin.channels.update', $channel->id) }}" @submit.prevent="onSubmit" enctype="multipart/form-data">
|
||||
<form method="POST" action="{{ route('admin.channels.update', ['id' => $channel->id, 'locale' => $locale]) }}" @submit.prevent="onSubmit" enctype="multipart/form-data">
|
||||
<div class="page-header">
|
||||
<div class="page-title">
|
||||
<h1>
|
||||
|
|
@ -15,6 +16,18 @@
|
|||
|
||||
{{ __('admin::app.settings.channels.edit-title') }}
|
||||
</h1>
|
||||
|
||||
<div class="control-group">
|
||||
<select class="control" id="locale-switcher" onChange="window.location.href = this.value">
|
||||
@foreach (core()->getAllLocales() as $localeModel)
|
||||
|
||||
<option value="{{ route('admin.channels.edit', $channel->id) . '?locale=' . $localeModel->code }}" {{ ($localeModel->code) == $locale ? 'selected' : '' }}>
|
||||
{{ $localeModel->name }}
|
||||
</option>
|
||||
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="page-action">
|
||||
|
|
@ -25,6 +38,7 @@
|
|||
</div>
|
||||
|
||||
<div class="page-content">
|
||||
|
||||
<div class="form-container">
|
||||
@csrf()
|
||||
<input name="_method" type="hidden" value="PUT">
|
||||
|
|
@ -42,15 +56,21 @@
|
|||
<span class="control-error" v-if="errors.has('code')">@{{ errors.first('code') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('name') ? 'has-error' : '']">
|
||||
<label for="name" class="required">{{ __('admin::app.settings.channels.name') }}</label>
|
||||
<input v-validate="'required'" class="control" id="name" name="name" data-vv-as=""{{ __('admin::app.settings.channels.name') }}"" value="{{ old('name') ?: $channel->name }}"/>
|
||||
<span class="control-error" v-if="errors.has('name')">@{{ errors.first('name') }}</span>
|
||||
<div class="control-group" :class="[errors.has('{{$locale}}[name]') ? 'has-error' : '']">
|
||||
<label for="name" class="required">
|
||||
{{ __('admin::app.settings.channels.name') }}
|
||||
<span class="locale">[{{ $locale }}]</span>
|
||||
</label>
|
||||
<input v-validate="'required'" class="control" id="name" name="{{$locale}}[name]" data-vv-as=""{{ __('admin::app.settings.channels.name') }}"" value="{{ old($locale)['name'] ?? ($channel->translate($locale)['name'] ?? '') }}"/>
|
||||
<span class="control-error" v-if="errors.has('{{$locale}}[name]')">@{{ errors.first('{!!$locale!!}[page_title]') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label for="description">{{ __('admin::app.settings.channels.description') }}</label>
|
||||
<textarea class="control" id="description" name="description">{{ old('description') ?: $channel->description }}</textarea>
|
||||
<label for="description">
|
||||
{{ __('admin::app.settings.channels.description') }}
|
||||
<span class="locale">[{{ $locale }}]</span>
|
||||
</label>
|
||||
<textarea class="control" id="description" name="{{$locale}}[description]">{{ old($locale)['description'] ?? ($channel->translate($locale)['description'] ?? '') }}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('inventory_sources[]') ? 'has-error' : '']">
|
||||
|
|
@ -97,9 +117,9 @@
|
|||
<label for="locales" class="required">{{ __('admin::app.settings.channels.locales') }}</label>
|
||||
<?php $selectedOptionIds = old('locales') ?: $channel->locales->pluck('id')->toArray() ?>
|
||||
<select v-validate="'required'" class="control" id="locales" name="locales[]" data-vv-as=""{{ __('admin::app.settings.channels.locales') }}"" multiple>
|
||||
@foreach (core()->getAllLocales() as $locale)
|
||||
<option value="{{ $locale->id }}" {{ in_array($locale->id, $selectedOptionIds) ? 'selected' : '' }}>
|
||||
{{ $locale->name }}
|
||||
@foreach (core()->getAllLocales() as $localeModel)
|
||||
<option value="{{ $localeModel->id }}" {{ in_array($localeModel->id, $selectedOptionIds) ? 'selected' : '' }}>
|
||||
{{ $localeModel->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
|
|
@ -110,9 +130,9 @@
|
|||
<label for="default_locale_id" class="required">{{ __('admin::app.settings.channels.default-locale') }}</label>
|
||||
<?php $selectedOption = old('default_locale_id') ?: $channel->default_locale_id ?>
|
||||
<select v-validate="'required'" class="control" id="default_locale_id" name="default_locale_id" data-vv-as=""{{ __('admin::app.settings.channels.default-locale') }}"">
|
||||
@foreach (core()->getAllLocales() as $locale)
|
||||
<option value="{{ $locale->id }}" {{ $selectedOption == $locale->id ? 'selected' : '' }}>
|
||||
{{ $locale->name }}
|
||||
@foreach (core()->getAllLocales() as $localeModel)
|
||||
<option value="{{ $localeModel->id }}" {{ $selectedOption == $localeModel->id ? 'selected' : '' }}>
|
||||
{{ $localeModel->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
|
|
@ -166,13 +186,19 @@
|
|||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label for="home_page_content">{{ __('admin::app.settings.channels.home_page_content') }}</label>
|
||||
<textarea class="control" id="home_page_content" name="home_page_content">{{ old('home_page_content') ?: $channel->home_page_content }}</textarea>
|
||||
<label for="home_page_content">
|
||||
{{ __('admin::app.settings.channels.home_page_content') }}
|
||||
<span class="locale">[{{ $locale }}]</span>
|
||||
</label>
|
||||
<textarea class="control" id="home_page_content" name="{{$locale}}[home_page_content]">{{ old($locale)['home_page_content'] ?? ($channel->translate($locale)['home_page_content'] ?? '') }}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label for="footer_content">{{ __('admin::app.settings.channels.footer_content') }}</label>
|
||||
<textarea class="control" id="footer_content" name="footer_content">{{ old('footer_content') ?: $channel->footer_content }}</textarea>
|
||||
<label for="footer_content">
|
||||
{{ __('admin::app.settings.channels.footer_content') }}
|
||||
<span class="locale">[{{ $locale }}]</span>
|
||||
</label>
|
||||
<textarea class="control" id="footer_content" name="{{$locale}}[footer_content]">{{ old($locale)['footer_content'] ?? ($channel->translate($locale)['footer_content'] ?? '') }}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
|
|
@ -191,32 +217,44 @@
|
|||
</accordian>
|
||||
|
||||
@php
|
||||
$seo = json_decode($channel->home_seo);
|
||||
$home_seo = $channel->translate($locale)['home_seo'] ?? '{}';
|
||||
$seo = json_decode($home_seo);
|
||||
@endphp
|
||||
|
||||
{{-- home page seo --}}
|
||||
<accordian :title="'{{ __('admin::app.settings.channels.seo') }}'" :active="true">
|
||||
<div slot="body">
|
||||
<div class="control-group" :class="[errors.has('seo_title') ? 'has-error' : '']">
|
||||
<label for="seo_title" class="required">{{ __('admin::app.settings.channels.seo-title') }}</label>
|
||||
<input v-validate="'required'" class="control" id="seo_title" name="seo_title" data-vv-as=""{{ __('admin::app.settings.channels.seo-title') }}"" value="{{ $seo->meta_title ?? old('seo_title') }}"/>
|
||||
<span class="control-error" v-if="errors.has('seo_title')">@{{ errors.first('seo_title') }}</span>
|
||||
<div class="control-group" :class="[errors.has('{{$locale}}[seo_title]') ? 'has-error' : '']">
|
||||
<label for="seo_title" class="required">
|
||||
{{ __('admin::app.settings.channels.seo-title') }}
|
||||
<span class="locale">[{{ $locale }}]</span>
|
||||
</label>
|
||||
|
||||
<input v-validate="'required'" class="control" id="seo_title" name="{{$locale}}[seo_title]" data-vv-as=""{{ __('admin::app.settings.channels.seo-title') }}"" value="{{ $seo->meta_title ?? (old($locale)['seo_title'] ?? '') }}"/>
|
||||
|
||||
<span class="control-error" v-if="errors.has('{{$locale}}[seo_title]')">@{{ errors.first('{!!$locale!!}[page_title]') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('seo_description') ? 'has-error' : '']">
|
||||
<label for="seo_description" class="required">{{ __('admin::app.settings.channels.seo-description') }}</label>
|
||||
<div class="control-group" :class="[errors.has('{{$locale}}[seo_description]') ? 'has-error' : '']">
|
||||
<label for="seo_description" class="required">
|
||||
{{ __('admin::app.settings.channels.seo-description') }}
|
||||
<span class="locale">[{{ $locale }}]</span>
|
||||
</label>
|
||||
|
||||
<textarea v-validate="'required'" class="control" id="seo_description" name="seo_description" data-vv-as=""{{ __('admin::app.settings.channels.seo-description') }}"">{{ $seo->meta_description ?? old('seo_description') }}</textarea>
|
||||
<textarea v-validate="'required'" class="control" id="seo_description" name="{{$locale}}[seo_description]" data-vv-as=""{{ __('admin::app.settings.channels.seo-description') }}"">{{ $seo->meta_description ?? (old($locale)['seo_description'] ?? '') }}</textarea>
|
||||
|
||||
<span class="control-error" v-if="errors.has('seo_description')">@{{ errors.first('seo_description') }}</span>
|
||||
<span class="control-error" v-if="errors.has('{{$locale}}[seo_description]')">@{{ errors.first('{!!$locale!!}[page_title]') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('seo_keywords') ? 'has-error' : '']">
|
||||
<label for="seo_keywords" class="required">{{ __('admin::app.settings.channels.seo-keywords') }}</label>
|
||||
<div class="control-group" :class="[errors.has('{{$locale}}[seo_keywords]') ? 'has-error' : '']">
|
||||
<label for="seo_keywords" class="required">
|
||||
{{ __('admin::app.settings.channels.seo-keywords') }}
|
||||
<span class="locale">[{{ $locale }}]</span>
|
||||
</label>
|
||||
|
||||
<textarea v-validate="'required'" class="control" id="seo_keywords" name="seo_keywords" data-vv-as=""{{ __('admin::app.settings.channels.seo-keywords') }}"">{{ $seo->meta_keywords ?? old('seo_keywords') }}</textarea>
|
||||
<textarea v-validate="'required'" class="control" id="seo_keywords" name="{{$locale}}[seo_keywords]" data-vv-as=""{{ __('admin::app.settings.channels.seo-keywords') }}"">{{ $seo->meta_keywords ?? (old($locale)['seo_keywords'] ?? '') }}</textarea>
|
||||
|
||||
<span class="control-error" v-if="errors.has('seo_keywords')">@{{ errors.first('seo_keywords') }}</span>
|
||||
<span class="control-error" v-if="errors.has('{{$locale}}[seo_keywords]')">@{{ errors.first('{!!$locale!!}[page_title]') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</accordian>
|
||||
|
|
@ -234,8 +272,11 @@
|
|||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label for="maintenance-mode-text">{{ __('admin::app.settings.channels.maintenance-mode-text') }}</label>
|
||||
<input class="control" id="maintenance-mode-text" name="maintenance_mode_text" value="{{ old('maintenance_mode_text') ?: $channel->maintenance_mode_text }}"/>
|
||||
<label for="maintenance-mode-text">
|
||||
{{ __('admin::app.settings.channels.maintenance-mode-text') }}
|
||||
<span class="locale">[{{ $locale }}]</span>
|
||||
</label>
|
||||
<input class="control" id="maintenance-mode-text" name="{{$locale}}[maintenance_mode_text]" value="{{ old('maintenance_mode_text') ?? ($channel->translate($locale)['maintenance_mode_text'] ?? '') }}"/>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Core\Contracts;
|
||||
|
||||
interface ChannelTranslation
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateChannelTranslationsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('channel_translations', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->integer('channel_id')->unsigned();
|
||||
$table->string('locale')->index();
|
||||
$table->string('name');
|
||||
$table->text('description')->nullable();
|
||||
$table->text('home_page_content')->nullable();
|
||||
$table->text('footer_content')->nullable();
|
||||
$table->text('maintenance_mode_text')->nullable();
|
||||
$table->json('home_seo')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['channel_id', 'locale']);
|
||||
$table->foreign('channel_id')->references('id')->on('channels')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('channel_translations');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class RemoveColumnsFromChannelsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('channels', function (Blueprint $table) {
|
||||
$table->dropColumn('name');
|
||||
$table->dropColumn('description');
|
||||
$table->dropColumn('home_page_content');
|
||||
$table->dropColumn('footer_content');
|
||||
$table->dropColumn('maintenance_mode_text');
|
||||
$table->dropColumn('home_seo');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('channels', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace Webkul\Core\Database\Seeders;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ChannelTableSeeder extends Seeder
|
||||
{
|
||||
|
|
@ -14,20 +14,175 @@ class ChannelTableSeeder extends Seeder
|
|||
DB::table('channels')->insert([
|
||||
'id' => 1,
|
||||
'code' => 'default',
|
||||
'name' => 'Default',
|
||||
'theme' => 'velocity',
|
||||
'hostname' => config('app.url'),
|
||||
'root_category_id' => 1,
|
||||
'home_page_content' => '<p>@include("shop::home.slider") @include("shop::home.featured-products") @include("shop::home.new-products")</p>
|
||||
<div class="banner-container">
|
||||
<div class="left-banner"><img src='.asset("/themes/default/assets/images/1.webp").' data-src='.asset("/themes/default/assets/images/1.webp").' class="lazyload" alt="test" width="720" height="720" /></div>
|
||||
<div class="right-banner"><img src='. asset("/themes/default/assets/images/2.webp").' data-src='. asset("/themes/default/assets/images/2.webp").' class="lazyload" alt="test" width="460" height="330" /> <img src='.asset("/themes/default/assets/images/3.webp").' data-src='.asset("/themes/default/assets/images/3.webp").' class="lazyload" alt="test" width="460" height="330" /></div>
|
||||
</div>',
|
||||
'footer_content' => '<div class="list-container"><span class="list-heading">Quick Links</span><ul class="list-group"><li><a href="@php echo route(\'shop.cms.page\', \'about-us\') @endphp">About Us</a></li><li><a href="@php echo route(\'shop.cms.page\', \'return-policy\') @endphp">Return Policy</a></li><li><a href="@php echo route(\'shop.cms.page\', \'refund-policy\') @endphp">Refund Policy</a></li><li><a href="@php echo route(\'shop.cms.page\', \'terms-conditions\') @endphp">Terms and conditions</a></li><li><a href="@php echo route(\'shop.cms.page\', \'terms-of-use\') @endphp">Terms of Use</a></li><li><a href="@php echo route(\'shop.cms.page\', \'contact-us\') @endphp">Contact Us</a></li></ul></div><div class="list-container"><span class="list-heading">Connect With Us</span><ul class="list-group"><li><a href="#"><span class="icon icon-facebook"></span>Facebook </a></li><li><a href="#"><span class="icon icon-twitter"></span> Twitter </a></li><li><a href="#"><span class="icon icon-instagram"></span> Instagram </a></li><li><a href="#"> <span class="icon icon-google-plus"></span>Google+ </a></li><li><a href="#"> <span class="icon icon-linkedin"></span>LinkedIn </a></li></ul></div>',
|
||||
'name' => 'Default',
|
||||
'default_locale_id' => 1,
|
||||
'base_currency_id' => 1,
|
||||
'home_seo' => '{"meta_title": "Demo store", "meta_keywords": "Demo store meta keyword", "meta_description": "Demo store meta description"}',
|
||||
]);
|
||||
|
||||
DB::table('channel_translations')->insert([
|
||||
[
|
||||
'id' => 1,
|
||||
'channel_id' => 1,
|
||||
'locale' => 'en',
|
||||
'name' => 'Default',
|
||||
'home_page_content' => '
|
||||
<p>@include("shop::home.slider") @include("shop::home.featured-products") @include("shop::home.new-products")</p>
|
||||
<div class="banner-container">
|
||||
<div class="left-banner">
|
||||
<img src='.asset("/themes/default/assets/images/1.webp").' data-src='.asset("/themes/default/assets/images/1.webp").' class="lazyload" alt="test" width="720" height="720" />
|
||||
</div>
|
||||
<div class="right-banner">
|
||||
<img src='. asset("/themes/default/assets/images/2.webp").' data-src='. asset("/themes/default/assets/images/2.webp").' class="lazyload" alt="test" width="460" height="330" />
|
||||
<img src='.asset("/themes/default/assets/images/3.webp").' data-src='.asset("/themes/default/assets/images/3.webp").' class="lazyload" alt="test" width="460" height="330" />
|
||||
</div>
|
||||
</div>
|
||||
',
|
||||
'footer_content' => '
|
||||
<div class="list-container">
|
||||
<span class="list-heading">Quick Links</span>
|
||||
<ul class="list-group">
|
||||
<li><a href="@php echo route(\'shop.cms.page\', \'about-us\') @endphp">About Us</a></li>
|
||||
<li><a href="@php echo route(\'shop.cms.page\', \'return-policy\') @endphp">Return Policy</a></li>
|
||||
<li><a href="@php echo route(\'shop.cms.page\', \'refund-policy\') @endphp">Refund Policy</a></li>
|
||||
<li><a href="@php echo route(\'shop.cms.page\', \'terms-conditions\') @endphp">Terms and conditions</a></li>
|
||||
<li><a href="@php echo route(\'shop.cms.page\', \'terms-of-use\') @endphp">Terms of Use</a></li><li><a href="@php echo route(\'shop.cms.page\', \'contact-us\') @endphp">Contact Us</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="list-container">
|
||||
<span class="list-heading">Connect With Us</span>
|
||||
<ul class="list-group">
|
||||
<li><a href="#"><span class="icon icon-facebook"></span>Facebook </a></li>
|
||||
<li><a href="#"><span class="icon icon-twitter"></span> Twitter </a></li>
|
||||
<li><a href="#"><span class="icon icon-instagram"></span> Instagram </a></li>
|
||||
<li><a href="#"> <span class="icon icon-google-plus"></span>Google+ </a></li>
|
||||
<li><a href="#"> <span class="icon icon-linkedin"></span>LinkedIn </a></li>
|
||||
</ul>
|
||||
</div>
|
||||
',
|
||||
'home_seo' => '{"meta_title": "Demo store", "meta_keywords": "Demo store meta keyword", "meta_description": "Demo store meta description"}',
|
||||
], [
|
||||
'id' => 2,
|
||||
'channel_id' => 1,
|
||||
'locale' => 'fr',
|
||||
'name' => 'Default',
|
||||
'home_page_content' => '
|
||||
<p>@include("shop::home.slider") @include("shop::home.featured-products") @include("shop::home.new-products")</p>
|
||||
<div class="banner-container">
|
||||
<div class="left-banner">
|
||||
<img src='.asset("/themes/default/assets/images/1.webp").' data-src='.asset("/themes/default/assets/images/1.webp").' class="lazyload" alt="test" width="720" height="720" />
|
||||
</div>
|
||||
<div class="right-banner">
|
||||
<img src='. asset("/themes/default/assets/images/2.webp").' data-src='. asset("/themes/default/assets/images/2.webp").' class="lazyload" alt="test" width="460" height="330" />
|
||||
<img src='.asset("/themes/default/assets/images/3.webp").' data-src='.asset("/themes/default/assets/images/3.webp").' class="lazyload" alt="test" width="460" height="330" />
|
||||
</div>
|
||||
</div>
|
||||
',
|
||||
'footer_content' => '
|
||||
<div class="list-container">
|
||||
<span class="list-heading">Quick Links</span>
|
||||
<ul class="list-group">
|
||||
<li><a href="@php echo route(\'shop.cms.page\', \'about-us\') @endphp">About Us</a></li>
|
||||
<li><a href="@php echo route(\'shop.cms.page\', \'return-policy\') @endphp">Return Policy</a></li>
|
||||
<li><a href="@php echo route(\'shop.cms.page\', \'refund-policy\') @endphp">Refund Policy</a></li>
|
||||
<li><a href="@php echo route(\'shop.cms.page\', \'terms-conditions\') @endphp">Terms and conditions</a></li>
|
||||
<li><a href="@php echo route(\'shop.cms.page\', \'terms-of-use\') @endphp">Terms of Use</a></li><li><a href="@php echo route(\'shop.cms.page\', \'contact-us\') @endphp">Contact Us</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="list-container">
|
||||
<span class="list-heading">Connect With Us</span>
|
||||
<ul class="list-group">
|
||||
<li><a href="#"><span class="icon icon-facebook"></span>Facebook </a></li>
|
||||
<li><a href="#"><span class="icon icon-twitter"></span> Twitter </a></li>
|
||||
<li><a href="#"><span class="icon icon-instagram"></span> Instagram </a></li>
|
||||
<li><a href="#"> <span class="icon icon-google-plus"></span>Google+ </a></li>
|
||||
<li><a href="#"> <span class="icon icon-linkedin"></span>LinkedIn </a></li>
|
||||
</ul>
|
||||
</div>
|
||||
',
|
||||
'home_seo' => '{"meta_title": "Demo store", "meta_keywords": "Demo store meta keyword", "meta_description": "Demo store meta description"}',
|
||||
], [
|
||||
'id' => 3,
|
||||
'channel_id' => 1,
|
||||
'locale' => 'nl',
|
||||
'name' => 'Default',
|
||||
'home_page_content' => '
|
||||
<p>@include("shop::home.slider") @include("shop::home.featured-products") @include("shop::home.new-products")</p>
|
||||
<div class="banner-container">
|
||||
<div class="left-banner">
|
||||
<img src='.asset("/themes/default/assets/images/1.webp").' data-src='.asset("/themes/default/assets/images/1.webp").' class="lazyload" alt="test" width="720" height="720" />
|
||||
</div>
|
||||
<div class="right-banner">
|
||||
<img src='. asset("/themes/default/assets/images/2.webp").' data-src='. asset("/themes/default/assets/images/2.webp").' class="lazyload" alt="test" width="460" height="330" />
|
||||
<img src='.asset("/themes/default/assets/images/3.webp").' data-src='.asset("/themes/default/assets/images/3.webp").' class="lazyload" alt="test" width="460" height="330" />
|
||||
</div>
|
||||
</div>
|
||||
',
|
||||
'footer_content' => '
|
||||
<div class="list-container">
|
||||
<span class="list-heading">Quick Links</span>
|
||||
<ul class="list-group">
|
||||
<li><a href="@php echo route(\'shop.cms.page\', \'about-us\') @endphp">About Us</a></li>
|
||||
<li><a href="@php echo route(\'shop.cms.page\', \'return-policy\') @endphp">Return Policy</a></li>
|
||||
<li><a href="@php echo route(\'shop.cms.page\', \'refund-policy\') @endphp">Refund Policy</a></li>
|
||||
<li><a href="@php echo route(\'shop.cms.page\', \'terms-conditions\') @endphp">Terms and conditions</a></li>
|
||||
<li><a href="@php echo route(\'shop.cms.page\', \'terms-of-use\') @endphp">Terms of Use</a></li><li><a href="@php echo route(\'shop.cms.page\', \'contact-us\') @endphp">Contact Us</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="list-container">
|
||||
<span class="list-heading">Connect With Us</span>
|
||||
<ul class="list-group">
|
||||
<li><a href="#"><span class="icon icon-facebook"></span>Facebook </a></li>
|
||||
<li><a href="#"><span class="icon icon-twitter"></span> Twitter </a></li>
|
||||
<li><a href="#"><span class="icon icon-instagram"></span> Instagram </a></li>
|
||||
<li><a href="#"> <span class="icon icon-google-plus"></span>Google+ </a></li>
|
||||
<li><a href="#"> <span class="icon icon-linkedin"></span>LinkedIn </a></li>
|
||||
</ul>
|
||||
</div>
|
||||
',
|
||||
'home_seo' => '{"meta_title": "Demo store", "meta_keywords": "Demo store meta keyword", "meta_description": "Demo store meta description"}',
|
||||
], [
|
||||
'id' => 4,
|
||||
'channel_id' => 1,
|
||||
'locale' => 'tr',
|
||||
'name' => 'Default',
|
||||
'home_page_content' => '
|
||||
<p>@include("shop::home.slider") @include("shop::home.featured-products") @include("shop::home.new-products")</p>
|
||||
<div class="banner-container">
|
||||
<div class="left-banner">
|
||||
<img src='.asset("/themes/default/assets/images/1.webp").' data-src='.asset("/themes/default/assets/images/1.webp").' class="lazyload" alt="test" width="720" height="720" />
|
||||
</div>
|
||||
<div class="right-banner">
|
||||
<img src='. asset("/themes/default/assets/images/2.webp").' data-src='. asset("/themes/default/assets/images/2.webp").' class="lazyload" alt="test" width="460" height="330" />
|
||||
<img src='.asset("/themes/default/assets/images/3.webp").' data-src='.asset("/themes/default/assets/images/3.webp").' class="lazyload" alt="test" width="460" height="330" />
|
||||
</div>
|
||||
</div>
|
||||
',
|
||||
'footer_content' => '
|
||||
<div class="list-container">
|
||||
<span class="list-heading">Quick Links</span>
|
||||
<ul class="list-group">
|
||||
<li><a href="@php echo route(\'shop.cms.page\', \'about-us\') @endphp">About Us</a></li>
|
||||
<li><a href="@php echo route(\'shop.cms.page\', \'return-policy\') @endphp">Return Policy</a></li>
|
||||
<li><a href="@php echo route(\'shop.cms.page\', \'refund-policy\') @endphp">Refund Policy</a></li>
|
||||
<li><a href="@php echo route(\'shop.cms.page\', \'terms-conditions\') @endphp">Terms and conditions</a></li>
|
||||
<li><a href="@php echo route(\'shop.cms.page\', \'terms-of-use\') @endphp">Terms of Use</a></li><li><a href="@php echo route(\'shop.cms.page\', \'contact-us\') @endphp">Contact Us</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="list-container">
|
||||
<span class="list-heading">Connect With Us</span>
|
||||
<ul class="list-group">
|
||||
<li><a href="#"><span class="icon icon-facebook"></span>Facebook </a></li>
|
||||
<li><a href="#"><span class="icon icon-twitter"></span> Twitter </a></li>
|
||||
<li><a href="#"><span class="icon icon-instagram"></span> Instagram </a></li>
|
||||
<li><a href="#"> <span class="icon icon-google-plus"></span>Google+ </a></li>
|
||||
<li><a href="#"> <span class="icon icon-linkedin"></span>LinkedIn </a></li>
|
||||
</ul>
|
||||
</div>
|
||||
',
|
||||
'home_seo' => '{"meta_title": "Demo store", "meta_keywords": "Demo store meta keyword", "meta_description": "Demo store meta description"}',
|
||||
]
|
||||
]);
|
||||
|
||||
DB::table('channel_currencies')->insert([
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use Webkul\Core\Repositories\ChannelRepository;
|
|||
class ChannelController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains route related configuration
|
||||
* Contains route related configuration.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
|
@ -61,36 +61,40 @@ class ChannelController extends Controller
|
|||
*/
|
||||
public function store()
|
||||
{
|
||||
$this->validate(request(), [
|
||||
'code' => ['required', 'unique:channels,code', new \Webkul\Core\Contracts\Validations\Code],
|
||||
'name' => 'required',
|
||||
'locales' => 'required|array|min:1',
|
||||
'default_locale_id' => 'required|in_array:locales.*',
|
||||
'currencies' => 'required|array|min:1',
|
||||
'base_currency_id' => 'required|in_array:currencies.*',
|
||||
'root_category_id' => 'required',
|
||||
'logo.*' => 'nullable|mimes:bmp,jpeg,jpg,png,webp',
|
||||
'favicon.*' => 'nullable|mimes:bmp,jpeg,jpg,png,webp',
|
||||
'seo_title' => 'required|string',
|
||||
'seo_description' => 'required|string',
|
||||
'seo_keywords' => 'required|string',
|
||||
'hostname' => 'unique:channels,hostname',
|
||||
'is_maintenance_on' => 'boolean'
|
||||
$data = $this->validate(request(), [
|
||||
/* general */
|
||||
'code' => ['required', 'unique:channels,code', new \Webkul\Core\Contracts\Validations\Code],
|
||||
'name' => 'required',
|
||||
'description' => 'nullable',
|
||||
'inventory_sources' => 'required|array|min:1',
|
||||
'root_category_id' => 'required',
|
||||
'hostname' => 'unique:channels,hostname',
|
||||
|
||||
/* currencies and locales */
|
||||
'locales' => 'required|array|min:1',
|
||||
'default_locale_id' => 'required|in_array:locales.*',
|
||||
'currencies' => 'required|array|min:1',
|
||||
'base_currency_id' => 'required|in_array:currencies.*',
|
||||
|
||||
/* design */
|
||||
'theme' => 'nullable',
|
||||
'home_page_content' => 'nullable',
|
||||
'footer_content' => 'nullable',
|
||||
'logo.*' => 'nullable|mimes:bmp,jpeg,jpg,png,webp',
|
||||
'favicon.*' => 'nullable|mimes:bmp,jpeg,jpg,png,webp',
|
||||
|
||||
/* seo */
|
||||
'seo_title' => 'required|string',
|
||||
'seo_description' => 'required|string',
|
||||
'seo_keywords' => 'required|string',
|
||||
|
||||
/* maintenance mode */
|
||||
'is_maintenance_on' => 'boolean',
|
||||
'maintenance_mode_text' => 'nullable',
|
||||
'allowed_ips' => 'nullable'
|
||||
]);
|
||||
|
||||
$data = request()->all();
|
||||
|
||||
$data['seo']['meta_title'] = $data['seo_title'];
|
||||
$data['seo']['meta_description'] = $data['seo_description'];
|
||||
$data['seo']['meta_keywords'] = $data['seo_keywords'];
|
||||
|
||||
unset($data['seo_title']);
|
||||
unset($data['seo_description']);
|
||||
unset($data['seo_keywords']);
|
||||
|
||||
$data['home_seo'] = json_encode($data['seo']);
|
||||
|
||||
unset($data['seo']);
|
||||
$data = $this->setSEOContent($data);
|
||||
|
||||
Event::dispatch('core.channel.create.before');
|
||||
|
||||
|
|
@ -124,32 +128,42 @@ class ChannelController extends Controller
|
|||
*/
|
||||
public function update($id)
|
||||
{
|
||||
$this->validate(request(), [
|
||||
'code' => ['required', 'unique:channels,code,' . $id, new \Webkul\Core\Contracts\Validations\Code],
|
||||
'name' => 'required',
|
||||
'locales' => 'required|array|min:1',
|
||||
'inventory_sources' => 'required|array|min:1',
|
||||
'default_locale_id' => 'required|in_array:locales.*',
|
||||
'currencies' => 'required|array|min:1',
|
||||
'base_currency_id' => 'required|in_array:currencies.*',
|
||||
'root_category_id' => 'required',
|
||||
'logo.*' => 'nullable|mimes:bmp,jpeg,jpg,png,webp',
|
||||
'favicon.*' => 'nullable|mimes:bmp,jpeg,jpg,png,webp',
|
||||
'hostname' => 'unique:channels,hostname,' . $id,
|
||||
'is_maintenance_on' => 'boolean'
|
||||
$locale = request()->get('locale') ?: app()->getLocale();
|
||||
|
||||
$data = $this->validate(request(), [
|
||||
/* general */
|
||||
'code' => ['required', 'unique:channels,code,' . $id, new \Webkul\Core\Contracts\Validations\Code],
|
||||
$locale . '.name' => 'required',
|
||||
$locale . '.description' => 'nullable',
|
||||
'inventory_sources' => 'required|array|min:1',
|
||||
'root_category_id' => 'required',
|
||||
'hostname' => 'unique:channels,hostname,' . $id,
|
||||
|
||||
/* currencies and locales */
|
||||
'locales' => 'required|array|min:1',
|
||||
'default_locale_id' => 'required|in_array:locales.*',
|
||||
'currencies' => 'required|array|min:1',
|
||||
'base_currency_id' => 'required|in_array:currencies.*',
|
||||
|
||||
/* design */
|
||||
'theme' => 'nullable',
|
||||
$locale . '.home_page_content' => 'nullable',
|
||||
$locale . '.footer_content' => 'nullable',
|
||||
'logo.*' => 'nullable|mimes:bmp,jpeg,jpg,png,webp',
|
||||
'favicon.*' => 'nullable|mimes:bmp,jpeg,jpg,png,webp',
|
||||
|
||||
/* seo */
|
||||
$locale . '.seo_title' => 'nullable',
|
||||
$locale . '.seo_description' => 'nullable',
|
||||
$locale . '.seo_keywords' => 'nullable',
|
||||
|
||||
/* maintenance mode */
|
||||
'is_maintenance_on' => 'boolean',
|
||||
$locale . '.maintenance_mode_text' => 'nullable',
|
||||
'allowed_ips' => 'nullable'
|
||||
]);
|
||||
|
||||
$data = request()->all();
|
||||
|
||||
$data['seo']['meta_title'] = $data['seo_title'];
|
||||
$data['seo']['meta_description'] = $data['seo_description'];
|
||||
$data['seo']['meta_keywords'] = $data['seo_keywords'];
|
||||
|
||||
unset($data['seo_title']);
|
||||
unset($data['seo_description']);
|
||||
unset($data['seo_keywords']);
|
||||
|
||||
$data['home_seo'] = json_encode($data['seo']);
|
||||
$data = $this->setSEOContent($data, $locale);
|
||||
|
||||
Event::dispatch('core.channel.update.before', $id);
|
||||
|
||||
|
|
@ -190,11 +204,55 @@ class ChannelController extends Controller
|
|||
|
||||
return response()->json(['message' => true], 200);
|
||||
} catch(\Exception $e) {
|
||||
// session()->flash('warning', trans($e->getMessage()));
|
||||
session()->flash('error', trans('admin::app.response.delete-failed', ['name' => 'Channel']));
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json(['message' => false], 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the seo content and return back the updated array.
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $locale
|
||||
* @return array
|
||||
*/
|
||||
private function setSEOContent(array $data, $locale = null)
|
||||
{
|
||||
$editedData = $data;
|
||||
|
||||
if ($locale) {
|
||||
$editedData = $data[$locale];
|
||||
}
|
||||
|
||||
$editedData['home_seo']['meta_title'] = $editedData['seo_title'];
|
||||
$editedData['home_seo']['meta_description'] = $editedData['seo_description'];
|
||||
$editedData['home_seo']['meta_keywords'] = $editedData['seo_keywords'];
|
||||
$editedData['home_seo'] = json_encode($editedData['home_seo']);
|
||||
|
||||
$editedData = $this->unsetKeys($editedData, ['seo_title', 'seo_description', 'seo_keywords']);
|
||||
|
||||
if ($locale) {
|
||||
$data[$locale] = $editedData;
|
||||
$editedData = $data;
|
||||
}
|
||||
|
||||
return $editedData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset keys.
|
||||
*
|
||||
* @param array $keys
|
||||
* @return array
|
||||
*/
|
||||
private function unsetKeys($data, $keys)
|
||||
{
|
||||
foreach ($keys as $key) {
|
||||
unset($data[$key]);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
namespace Webkul\Core\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Webkul\Category\Models\CategoryProxy;
|
||||
use Webkul\Core\Eloquent\TranslatableModel;
|
||||
use Webkul\Inventory\Models\InventorySourceProxy;
|
||||
use Webkul\Core\Contracts\Channel as ChannelContract;
|
||||
|
||||
class Channel extends Model implements ChannelContract
|
||||
class Channel extends TranslatableModel implements ChannelContract
|
||||
{
|
||||
protected $fillable = [
|
||||
'code',
|
||||
|
|
@ -27,6 +27,15 @@ class Channel extends Model implements ChannelContract
|
|||
'allowed_ips'
|
||||
];
|
||||
|
||||
public $translatedAttributes = [
|
||||
'name',
|
||||
'description',
|
||||
'home_page_content',
|
||||
'footer_content',
|
||||
'maintenance_mode_text',
|
||||
'home_seo',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the channel locales.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Core\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webkul\Core\Contracts\ChannelTranslation as ChannelTranslationContract;
|
||||
|
||||
class ChannelTranslation extends Model implements ChannelTranslationContract
|
||||
{
|
||||
protected $guarded = [];
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Core\Models;
|
||||
|
||||
use Konekt\Concord\Proxies\ModelProxy;
|
||||
|
||||
class ChannelTranslationProxy extends ModelProxy
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -26,7 +26,17 @@ class ChannelRepository extends Repository
|
|||
*/
|
||||
public function create(array $data)
|
||||
{
|
||||
$channel = $this->model->create($data);
|
||||
$model = $this->getModel();
|
||||
|
||||
foreach (core()->getAllLocales() as $locale) {
|
||||
foreach ($model->translatedAttributes as $attribute) {
|
||||
if (isset($data[$attribute])) {
|
||||
$data[$locale->code][$attribute] = $data[$attribute];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$channel = parent::create($data);
|
||||
|
||||
$channel->locales()->sync($data['locales']);
|
||||
|
||||
|
|
@ -51,7 +61,7 @@ class ChannelRepository extends Repository
|
|||
{
|
||||
$channel = $this->find($id);
|
||||
|
||||
$channel->update($data);
|
||||
parent::update($data, $id, $attribute);
|
||||
|
||||
$channel->locales()->sync($data['locales']);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue