Merge Bagisto master into Haendlerbund/Bagisto master (#14)

* added bagisto:install command

* updates for uploading attachments

* Issue #1808

* Issue #1779 fixed

* Issue #2045

* Issue #1971

* Issue #1779 fixed

* fire event on creating/updating slider

* Issue #1863 fixed

* Issue #1863 fixed

* Removed ')' in page edit blade

* Issue #2054 fixed

* Issue #2054 fixed

* Added mail from name field in .env.example file, Issue #2051

Co-authored-by: Sarthak Shrivastava <sarthak@bitfumes.com>
Co-authored-by: Shubham Mehrotra <shubhammehrotra.symfony@webkul.com>
Co-authored-by: Jitendra Singh <39991107+jitendra-webkul@users.noreply.github.com>
Co-authored-by: rahulshukla-webkul <42834394+rahulshukla-webkul@users.noreply.github.com>
This commit is contained in:
Annika Wolff 2020-01-16 13:54:18 +01:00 committed by GitHub
parent 4d578b0b4c
commit 976d19cd74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 721 additions and 528 deletions

View File

@ -35,6 +35,7 @@ MAIL_ENCRYPTION=tls
SHOP_MAIL_FROM=
ADMIN_MAIL_TO=
MAIL_FROM_NAME=
fixer_api_key=

View File

@ -0,0 +1,119 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Artisan;
class install extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'bagisto:install';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Run migrate and seed command, publish assets and config, link storage';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Install and configure bagisto
*/
public function handle()
{
$this->checkForEnvFile();
// running `php artisan migrate`
$this->warn('Step: Migrating all tables into database...');
$migrate = shell_exec('php artisan migrate:fresh');
$this->info($migrate);
// running `php artisan db:seed`
$this->warn('Step: seeding basic data for bagisto kickstart...');
$result = shell_exec('php artisan db:seed');
$this->info($result);
// running `php artisan vendor:publish --all`
$this->warn('Step: Publishing Assets and Configurations...');
$result = shell_exec('php artisan vendor:publish --all');
$this->info($result);
// running `php artisan storage:link`
$this->warn('Step: Linking Storage directory...');
$result = shell_exec('php artisan storage:link');
$this->info($result);
// running `composer dump-autoload`
$this->warn('Step: Composer Autoload...');
$result = shell_exec('composer dump-autoload');
$this->info($result);
$this->info('-----------------------------');
$this->info('Now, run `php artisan serve` to start using Bagisto');
$this->info('Cheers!');
}
/**
* Checking .env file and if not found then create .env file.
* Then ask for database name, password & username to set
* On .env file so that we can easily migrate to our db
*/
public function checkForEnvFile()
{
$envExists = File::exists(base_path() . '/.env');
if (!$envExists) {
$this->info('Creating .env file');
$this->createEnvFile();
} else {
$this->info('Great! .env file aready exists');
}
}
public function createEnvFile()
{
try {
File::copy('.env.example', '.env');
Artisan::call('key:generate');
$this->envUpdate('APP_URL=http://localhost', ':8000');
$this->addDatabaseDetails();
} catch (\Exception $e) {
$this->error('Error in creating .env file, please create manually and then run `php artisan migrate` again');
}
}
public function addDatabaseDetails()
{
$dbName = $this->ask('What is your database name to be used by bagisto');
$dbUser = $this->anticipate('What is your database username', ['root']);
$dbPass = $this->secret('What is your database password');
$this->envUpdate('DB_DATABASE=', $dbName);
$this->envUpdate('DB_USERNAME=', $dbUser);
$this->envUpdate('DB_PASSWORD=', $dbPass);
}
public static function envUpdate($key, $value)
{
$path = base_path() . '/.env';
file_put_contents($path, str_replace(
$key,
$key . $value,
file_get_contents($path)
));
}
}

View File

@ -15,7 +15,10 @@
"jquery": "^3.4.1",
"laravel-mix": "^5.0.0",
"laravel-mix-merge-manifest": "^0.1.2",
"vue": "^2.6.10"
"sass": "^1.24.4",
"sass-loader": "^8.0.2",
"vue": "^2.6.10",
"vue-template-compiler": "^2.6.11"
},
"dependencies": {
"vee-validate": "^2.2.15"

View File

@ -76,6 +76,7 @@ return [
'title' => 'admin::app.admin.system.logo-image',
'type' => 'image',
'channel_based' => true,
'validation' => 'mimes:jpeg,bmp,png,jpg'
]
]
], [
@ -156,5 +157,5 @@ return [
'type' => 'boolean'
]
],
],
],
];

View File

@ -13,23 +13,26 @@ use DB;
*/
class CMSPageDataGrid extends DataGrid
{
protected $index = 'id'; //the column that needs to be treated as index column
protected $index = 'id';
protected $sortOrder = 'desc'; //asc or desc
protected $sortOrder = 'desc';
public function prepareQueryBuilder()
{
$queryBuilder = DB::table('cms_pages')->select('id', 'url_key', 'page_title', 'channel_id', 'locale_id');
$queryBuilder = DB::table('cms_pages')
->select('cms_pages.id', 'cms_page_translations.page_title', 'cms_page_translations.url_key')
->leftJoin('cms_page_translations', function($leftJoin) {
$leftJoin->on('cms_pages.id', '=', 'cms_page_translations.cms_page_id')
->where('cms_page_translations.locale', app()->getLocale());
});
$this->addFilter('id', 'cms_pages.id');
$this->setQueryBuilder($queryBuilder);
}
public function addColumns()
{
$channels = app('Webkul\Core\Repositories\ChannelRepository');
$locales = app('Webkul\Core\Repositories\LocaleRepository');
$this->addColumn([
'index' => 'id',
'label' => trans('admin::app.datagrid.id'),
@ -39,15 +42,6 @@ class CMSPageDataGrid extends DataGrid
'filterable' => true
]);
$this->addColumn([
'index' => 'url_key',
'label' => trans('admin::app.datagrid.url-key'),
'type' => 'string',
'searchable' => true,
'sortable' => true,
'filterable' => true
]);
$this->addColumn([
'index' => 'page_title',
'label' => trans('admin::app.cms.pages.page-title'),
@ -58,45 +52,26 @@ class CMSPageDataGrid extends DataGrid
]);
$this->addColumn([
'index' => 'locale_id',
'label' => trans('admin::app.cms.pages.locale'),
'type' => 'number',
'searchable' => false,
'index' => 'url_key',
'label' => trans('admin::app.datagrid.url-key'),
'type' => 'string',
'searchable' => true,
'sortable' => true,
'filterable' => true,
'wrapper' => function($row) use($locales) {
$localeCode = $locales->find($row->locale_id)->code;
return $row->locale_id.' ('. $localeCode. ')';
}
]);
$this->addColumn([
'index' => 'channel_id',
'label' => trans('admin::app.cms.pages.channel'),
'type' => 'number',
'searchable' => false,
'sortable' => true,
'filterable' => true,
'wrapper' => function($row) use($channels) {
$channelCode = $channels->find($row->channel_id)->name;
return $row->channel_id.' ('. $channelCode. ')';
}
'filterable' => true
]);
}
public function prepareActions() {
$this->addAction([
'title' => 'Edit CMSPage',
'method' => 'GET', // use GET request only for redirect purposes
'method' => 'GET',
'route' => 'admin.cms.edit',
'icon' => 'icon pencil-lg-icon'
]);
$this->addAction([
'title' => 'Delete CMSPage',
'method' => 'POST', // use GET request only for redirect purposes
'method' => 'POST',
'route' => 'admin.cms.delete',
'icon' => 'icon trash-icon'
]);

View File

@ -21,7 +21,7 @@ class CartRuleCouponDataGrid extends DataGrid
{
$queryBuilder = DB::table('cart_rule_coupons')
->addSelect('id', 'code', 'created_at', 'expired_at', 'times_used')
->where('cart_rule_coupons.cart_rule_id', request('id'));
->where('cart_rule_coupons.cart_rule_id', collect(request()->segments())->last());
$this->setQueryBuilder($queryBuilder);
}

View File

@ -120,7 +120,7 @@ class ConfigurationController extends Controller
{
Event::fire('core.configuration.save.before');
if (request()->hasFile('general.design.admin_logo.logo_image')) {
if (request()->has('general.design.admin_logo.logo_image') && ! request()->input('general.design.admin_logo.logo_image.delete')) {
$this->validate(request(), [
'general.design.admin_logo.logo_image' => 'required|mimes:jpeg,bmp,png,jpg'
]);

View File

@ -726,7 +726,6 @@ Route::group(['middleware' => ['web']], function () {
'view' => 'admin::cms.index'
])->name('admin.cms.index');
Route::get('preview/{url_key}', 'Webkul\CMS\Http\Controllers\Admin\PageController@preview')->name('admin.cms.preview');
Route::get('create', 'Webkul\CMS\Http\Controllers\Admin\PageController@create')->defaults('_config', [
'view' => 'admin::cms.create'
@ -736,11 +735,11 @@ Route::group(['middleware' => ['web']], function () {
'redirect' => 'admin.cms.index'
])->name('admin.cms.store');
Route::get('update/{id}', 'Webkul\CMS\Http\Controllers\Admin\PageController@edit')->defaults('_config', [
Route::get('edit/{id}', 'Webkul\CMS\Http\Controllers\Admin\PageController@edit')->defaults('_config', [
'view' => 'admin::cms.edit'
])->name('admin.cms.edit');
Route::post('update/{id}', 'Webkul\CMS\Http\Controllers\Admin\PageController@update')->defaults('_config', [
Route::post('edit/{id}', 'Webkul\CMS\Http\Controllers\Admin\PageController@update')->defaults('_config', [
'redirect' => 'admin.cms.index'
])->name('admin.cms.update');

View File

@ -6,7 +6,9 @@ import './bootstrap';
window.Vue = Vue;
window.VeeValidate = VeeValidate;
Vue.use(VeeValidate);
Vue.use(VeeValidate, {
events: 'input|change|blur',
});
Vue.prototype.$http = axios
window.eventBus = new Vue();

View File

@ -1142,13 +1142,13 @@ return [
'pages' => [
'general' => 'General',
'seo' => 'SEO',
'pages' => 'Page',
'title' => 'pages',
'pages' => 'Pages',
'title' => 'Pages',
'add-title' => 'Add Page',
'content' => 'Content',
'url-key' => 'URL Key',
'channel' => 'Channel',
'locale' => 'Locale',
'channel' => 'Channels',
'locale' => 'Locales',
'create-btn-title' => 'Save Page',
'edit-title' => 'Edit Page',
'edit-btn-title' => 'Save Page',

View File

@ -11,9 +11,9 @@
<div class="page-header">
<div class="page-title">
<h1>
<i class="icon angle-left-icon back-link" onclick="history.length > 1 ? history.go(-1) : window.location = '{{ url('/admin/dashboard') }}';"></i>
<i class="icon angle-left-icon back-link" @click="redirectBack('{{ url('/admin/dashboard') }}')"></i>
{{ __('admin::app.cms.pages.pages') }}
{{ __('admin::app.cms.pages.add-title') }}
</h1>
</div>
@ -28,6 +28,9 @@
<div class="form-container">
@csrf()
{!! view_render_event('bagisto.admin.cms.pages.create_form_accordian.general.before') !!}
<accordian :title="'{{ __('admin::app.cms.pages.general') }}'" :active="true">
<div slot="body">
<div class="control-group" :class="[errors.has('page_title') ? 'has-error' : '']">
@ -38,16 +41,7 @@
<span class="control-error" v-if="errors.has('page_title')">@{{ errors.first('page_title') }}</span>
</div>
<div class="control-group" :class="[errors.has('url_key') ? 'has-error' : '']">
<label for="url-key" class="required">{{ __('admin::app.cms.pages.url-key') }}</label>
<input type="text" class="control" name="url_key" v-validate="'required'" value="{{ old('url-key') }}" data-vv-as="&quot;{{ __('admin::app.cms.pages.url-key') }}&quot;" v-slugify>
<span class="control-error" v-if="errors.has('url_key')">@{{ errors.first('url_key') }}</span>
</div>
@inject('channels', 'Webkul\Core\Repositories\ChannelRepository')
@inject('locales', 'Webkul\Core\Repositories\LocaleRepository')
<div class="control-group" :class="[errors.has('channels[]') ? 'has-error' : '']">
<label for="url-key" class="required">{{ __('admin::app.cms.pages.channel') }}</label>
@ -61,77 +55,56 @@
<span class="control-error" v-if="errors.has('channels[]')">@{{ errors.first('channels[]') }}</span>
</div>
<div class="control-group" :class="[errors.has('locales[]') ? 'has-error' : '']">
<label for="url-key" class="required">{{ __('admin::app.cms.pages.locale') }}</label>
<select type="text" class="control" name="locales[]" v-validate="'required'" value="{{ old('locale[]') }}" data-vv-as="&quot;{{ __('admin::app.cms.pages.locale') }}&quot;" multiple="multiple">
@foreach($locales->all() as $locale)
<option value="{{ $locale->id }}">{{ $locale->name }}</option>
@endforeach
</select>
<span class="control-error" v-if="errors.has('locales[]')">@{{ errors.first('locales[]') }}</span>
</div>
<div class="control-group" :class="[errors.has('html_content') ? 'has-error' : '']">
<label for="html_content" class="required">{{ __('admin::app.cms.pages.content') }}</label>
<textarea type="text" class="control" id="content" name="html_content" v-validate="'required'" value="{{ old('html_content') }}" data-vv-as="&quot;{{ __('admin::app.cms.pages.content') }}&quot;"></textarea>
{!! __('admin::app.cms.pages.one-col') !!}
{!! __('admin::app.cms.pages.two-col') !!}
{!! __('admin::app.cms.pages.three-col') !!}
<div class="mt-10 mb-10">
<a target="_blank" href="{{ route('ui.helper.classes') }}" class="btn btn-sm btn-primary">
{{ __('admin::app.cms.pages.helper-classes') }}
</a>
</div>
<span class="control-error" v-if="errors.has('html_content')">@{{ errors.first('html_content') }}</span>
</div>
</div>
</accordian>
{!! view_render_event('bagisto.admin.cms.pages.create_form_accordian.general.after') !!}
{!! view_render_event('bagisto.admin.cms.pages.create_form_accordian.seo.before') !!}
<accordian :title="'{{ __('admin::app.cms.pages.seo') }}'" :active="true">
<div slot="body">
<div class="control-group" :class="[errors.has('meta_title') ? 'has-error' : '']">
<label for="meta_title" class="required">{{ __('admin::app.cms.pages.meta_title') }}</label>
<div class="control-group">
<label for="meta_title">{{ __('admin::app.cms.pages.meta_title') }}</label>
<input type="text" class="control" name="meta_title" v-validate="'required'" value="{{ old('meta_title') }}" data-vv-as="&quot;{{ __('admin::app.cms.pages.meta_title') }}&quot;">
<span class="control-error" v-if="errors.has('meta_title')">@{{ errors.first('meta_title') }}</span>
<input type="text" class="control" name="meta_title" value="{{ old('meta_title') }}">
</div>
<div class="control-group" :class="[errors.has('meta_keywords') ? 'has-error' : '']">
<label for="meta_keywords" class="required">{{ __('admin::app.cms.pages.meta_keywords') }}</label>
<div class="control-group" :class="[errors.has('url_key') ? 'has-error' : '']">
<label for="url-key" class="required">{{ __('admin::app.cms.pages.url-key') }}</label>
<textarea type="text" class="control" name="meta_keywords" v-validate="'required'" value="{{ old('meta_keywords') }}" data-vv-as="&quot;{{ __('admin::app.cms.pages.meta_keywords') }}&quot;"></textarea>
<input type="text" class="control" name="url_key" v-validate="'required'" value="{{ old('url_key') }}" data-vv-as="&quot;{{ __('admin::app.cms.pages.url-key') }}&quot;" v-slugify>
<span class="control-error" v-if="errors.has('meta_keywords')">@{{ errors.first('meta_keywords') }}</span>
<span class="control-error" v-if="errors.has('url_key')">@{{ errors.first('url_key') }}</span>
</div>
<div class="control-group" :class="[errors.has('meta_description') ? 'has-error' : '']">
<div class="control-group">
<label for="meta_keywords">{{ __('admin::app.cms.pages.meta_keywords') }}</label>
<textarea type="text" class="control" name="meta_keywords" value="{{ old('meta_keywords') }}"></textarea>
</div>
<div class="control-group">
<label for="meta_description">{{ __('admin::app.cms.pages.meta_description') }}</label>
<textarea type="text" class="control" name="meta_description" value="{{ old('meta_description') }}" data-vv-as="&quot;{{ __('admin::app.cms.pages.meta_description') }}&quot;"></textarea>
<span class="control-error" v-if="errors.has('meta_description')">@{{ errors.first('meta_description') }}</span>
<textarea type="text" class="control" name="meta_description" value="{{ old('meta_description') }}"></textarea>
</div>
</div>
</accordian>
{!! view_render_event('bagisto.admin.cms.pages.create_form_accordian.seo.after') !!}
</div>
</div>
</form>
</div>
{{-- <modal id="showHelpers" :is-open="modalIds.showHelpers">
<h3 slot="header">{{ __('admin::app.cms.pages.helper-classes') }}</h3>
<div slot="body">
@include('ui::partials.helper-classes')
</div>
</modal> --}}
@stop
@push('scripts')
@ -142,7 +115,7 @@
tinymce.init({
selector: 'textarea#content',
height: 200,
width: "70%",
width: "100%",
plugins: 'image imagetools media wordcount save fullscreen code',
toolbar1: 'formatselect | bold italic strikethrough forecolor backcolor | link | alignleft aligncenter alignright alignjustify | numlist bullist outdent indent | removeformat | code',
image_advtab: true,

View File

@ -6,21 +6,37 @@
@section('content')
<div class="content">
<form method="POST" id="page-form" action="{{ route('admin.cms.edit', $page->id) }}" @submit.prevent="onSubmit">
<?php $locale = request()->get('locale') ?: app()->getLocale(); ?>
<form method="POST" id="page-form" action="" @submit.prevent="onSubmit">
<div class="page-header">
<div class="page-title">
<h1>
<i class="icon angle-left-icon back-link" onclick="history.length > 1 ? history.go(-1) : window.location = '{{ url('/admin/dashboard') }}';"></i>
<i class="icon angle-left-icon back-link" @click="redirectBack('{{ url('/admin/dashboard') }}')"></i>
{{ __('admin::app.cms.pages.pages') }}
{{ __('admin::app.cms.pages.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.cms.edit', $page->id) . '?locale=' . $localeModel->code }}" {{ ($localeModel->code) == $locale ? 'selected' : '' }}>
{{ $localeModel->name }}
</option>
@endforeach
</select>
</div>
</div>
<div class="page-action">
<button id="preview" class="btn btn-lg btn-primary">
{{ __('admin::app.cms.pages.preview') }}
</button>
@if ($page->translate($locale))
<a href="{{ route('shop.cms.page', $page->translate($locale)['url_key']) }}" class="btn btn-lg btn-primary" target="_blank">
{{ __('admin::app.cms.pages.preview') }}
</a>
@endif
<button type="submit" class="btn btn-lg btn-primary">
{{ __('admin::app.cms.pages.edit-btn-title') }}
@ -34,66 +50,72 @@
@csrf()
<accordian :title="'{{ __('admin::app.cms.pages.general') }}'" :active="true">
<div slot="body">
<div class="control-group" :class="[errors.has('page_title') ? 'has-error' : '']">
<div class="control-group" :class="[errors.has('{{$locale}}[page_title]') ? 'has-error' : '']">
<label for="page_title" class="required">{{ __('admin::app.cms.pages.page-title') }}</label>
<input type="text" class="control" name="page_title" v-validate="'required'" value="{{ $page->page_title ?? old('page_title') }}" data-vv-as="&quot;{{ __('admin::app.cms.pages.page-title') }}&quot;">
<input type="text" class="control" name="{{$locale}}[page_title]" v-validate="'required'" value="{{ old($locale)['page_title'] ?? ($page->translate($locale)['page_title'] ?? '') }}" data-vv-as="&quot;{{ __('admin::app.cms.pages.page-title') }}&quot;">
<span class="control-error" v-if="errors.has('page_title')">@{{ errors.first('page_title') }}</span>
<span class="control-error" v-if="errors.has('{{$locale}}[page_title]')">@{{ errors.first('{!!$locale!!}[page_title]') }}</span>
</div>
<div class="control-group" :class="[errors.has('url_key') ? 'has-error' : '']">
<label for="url-key" class="required">{{ __('admin::app.cms.pages.url-key') }}</label>
<div class="control-group" :class="[errors.has('channels[]') ? 'has-error' : '']">
<label for="url-key" class="required">{{ __('admin::app.cms.pages.channel') }}</label>
<input type="text" class="control" name="url_key" v-validate="'required'" value="{{ $page->url_key ?? old('url_key') }}" data-vv-as="&quot;{{ __('admin::app.cms.pages.url-key') }}&quot;" disabled>
<?php $selectedOptionIds = old('inventory_sources') ?: $page->channels->pluck('id')->toArray() ?>
<span class="control-error" v-if="errors.has('url_key')">@{{ errors.first('url_key') }}</span>
<select type="text" class="control" name="channels[]" v-validate="'required'" value="{{ old('channel[]') }}" data-vv-as="&quot;{{ __('admin::app.cms.pages.channel') }}&quot;" multiple="multiple">
@foreach(app('Webkul\Core\Repositories\ChannelRepository')->all() as $channel)
<option value="{{ $channel->id }}" {{ in_array($channel->id, $selectedOptionIds) ? 'selected' : '' }}>
{{ $channel->name }}
</option>
@endforeach
</select>
<span class="control-error" v-if="errors.has('channels[]')">@{{ errors.first('channels[]') }}</span>
</div>
<div class="control-group" :class="[errors.has('html_content') ? 'has-error' : '']">
<div class="control-group" :class="[errors.has('{{$locale}}[html_content]') ? 'has-error' : '']">
<label for="html_content" class="required">{{ __('admin::app.cms.pages.content') }}</label>
<textarea type="text" class="control" id="content" name="html_content" v-validate="'required'" data-vv-as="&quot;{{ __('admin::app.cms.pages.content') }}&quot;">{{ $page->html_content ?? old('html_content') }}</textarea>
<textarea type="text" class="control" id="content" name="{{$locale}}[html_content]" v-validate="'required'" data-vv-as="&quot;{{ __('admin::app.cms.pages.content') }}&quot;">
{{ old($locale)['html_content'] ?? ($page->translate($locale)['html_content'] ?? '') }}
</textarea>
{!! __('admin::app.cms.pages.one-col') !!}
{!! __('admin::app.cms.pages.two-col') !!}
{!! __('admin::app.cms.pages.three-col') !!}
<div class="mt-10 mb-10">
<a target="_blank" href="{{ route('ui.helper.classes') }}" class="btn btn-sm btn-primary">
{{ __('admin::app.cms.pages.helper-classes') }}
</a>
</div>
<span class="control-error" v-if="errors.has('html_content')">@{{ errors.first('html_content') }}</span>
<span class="control-error" v-if="errors.has('{{$locale}}[html_content]')">@{{ errors.first('{!!$locale!!}[html_content]') }}</span>
</div>
</div>
</accordian>
<accordian :title="'{{ __('admin::app.cms.pages.seo') }}'" :active="true">
<div slot="body">
<div class="control-group" :class="[errors.has('meta_title') ? 'has-error' : '']">
<label for="meta_title" class="required">{{ __('admin::app.cms.pages.meta_title') }}</label>
<div class="control-group">
<label for="meta_title">{{ __('admin::app.cms.pages.meta_title') }}</label>
<input type="text" class="control" name="meta_title" v-validate="'required'" value="{{ $page->meta_title ?? old('meta_title') }}" data-vv-as="&quot;{{ __('admin::app.cms.pages.meta_title') }}&quot;">
<span class="control-error" v-if="errors.has('meta_title')">@{{ errors.first('meta_title') }}</span>
<input type="text" class="control" name="{{$locale}}[meta_title]" value="{{ old($locale)['meta_title'] ?? ($page->translate($locale)['meta_title'] ?? '') }}">
</div>
<div class="control-group" :class="[errors.has('meta_keywords') ? 'has-error' : '']">
<label for="meta_keywords" class="required">{{ __('admin::app.cms.pages.meta_keywords') }}</label>
<div class="control-group" :class="[errors.has('{{$locale}}[url_key]') ? 'has-error' : '']">
<label for="url-key" class="required">{{ __('admin::app.cms.pages.url-key') }}</label>
<textarea type="text" class="control" name="meta_keywords" v-validate="'required'" data-vv-as="&quot;{{ __('admin::app.cms.pages.meta_keywords') }}&quot;">{{ $page->meta_keywords ?? old('meta_keywords') }}</textarea>
<input type="text" class="control" name="{{$locale}}[url_key]" v-validate="'required'" value="{{ old($locale)['url_key'] ?? ($page->translate($locale)['url_key'] ?? '') }}" data-vv-as="&quot;{{ __('admin::app.cms.pages.url-key') }}&quot;">
<span class="control-error" v-if="errors.has('meta_keywords')">@{{ errors.first('meta_keywords') }}</span>
<span class="control-error" v-if="errors.has('{{$locale}}[url_key]')">@{{ errors.first('{!!$locale!!}[url_key]') }}</span>
</div>
<div class="control-group" :class="[errors.has('meta_description') ? 'has-error' : '']">
<div class="control-group">
<label for="meta_keywords">{{ __('admin::app.cms.pages.meta_keywords') }}</label>
<textarea type="text" class="control" name="{{$locale}}[meta_keywords]">
{{ old($locale)['meta_keywords'] ?? ($page->translate($locale)['meta_keywords'] ?? '') }}
</textarea>
</div>
<div class="control-group">
<label for="meta_description">{{ __('admin::app.cms.pages.meta_description') }}</label>
<textarea type="text" class="control" name="meta_description" data-vv-as="&quot;{{ __('admin::app.cms.pages.meta_description') }}&quot;">{{ $page->meta_description ?? old('meta_description') }}</textarea>
<span class="control-error" v-if="errors.has('meta_description')">@{{ errors.first('meta_description') }}</span>
<textarea type="text" class="control" name="{{$locale}}[meta_description]">
{{ old($locale)['meta_description'] ?? ($page->translate($locale)['meta_description'] ?? '') }}
</textarea>
</div>
</div>
</accordian>
@ -108,27 +130,10 @@
<script>
$(document).ready(function () {
$('#preview').on('click', function(e) {
var form = $('#page-form').serialize();
// var url = '{{ route('admin.cms.preview', $page->id) }}' + '?' + form;
var url = '{{ route('admin.cms.preview', $page->id) }}';
window.open(url, '_blank').focus();
return false;
});
$('#channel-switcher, #locale-switcher').on('change', function (e) {
$('#channel-switcher').val()
var query = '?channel=' + $('#channel-switcher').val() + '&locale=' + $('#locale-switcher').val();
window.location.href = "{{ route('admin.cms.edit', $page->id) }}" + query;
});
tinymce.init({
selector: 'textarea#content',
height: 200,
width: "70%",
width: "100%",
plugins: 'image imagetools media wordcount save fullscreen code',
toolbar1: 'formatselect | bold italic strikethrough forecolor backcolor | link | alignleft aligncenter alignright alignjustify | numlist bullist outdent indent | removeformat | code',
image_advtab: true,

View File

@ -7,7 +7,7 @@
@section('content')
<div class="content">
<form method="POST" action="{{ route('admin.currencies.store') }}" @submit.prevent="onSubmit">
<form method="POST" action="{{ route('admin.currencies.store') }}" @submit.prevent="onSubmit" enctype="multipart/form-data">
<div class="page-header">
<div class="page-title">
<h1>

View File

@ -7,7 +7,7 @@
@section('content')
<div class="content">
<form method="POST" action="{{ route('admin.currencies.update', $currency->id) }}" @submit.prevent="onSubmit">
<form method="POST" action="{{ route('admin.currencies.update', $currency->id) }}" @submit.prevent="onSubmit" enctype="multipart/form-data">
<div class="page-header">
<div class="page-title">
<h1>

View File

@ -2,6 +2,6 @@
namespace Webkul\CMS\Contracts;
interface CMS
interface CmsPage
{
}

View File

@ -0,0 +1,7 @@
<?php
namespace Webkul\CMS\Contracts;
interface CmsPageTranslation
{
}

View File

@ -0,0 +1,41 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCmsPageTranslationsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('cms_page_translations', function (Blueprint $table) {
$table->increments('id');
$table->string('page_title');
$table->string('url_key');
$table->text('html_content')->nullable();
$table->text('meta_title')->nullable();
$table->text('meta_description')->nullable();
$table->text('meta_keywords')->nullable();
$table->string('locale');
$table->integer('cms_page_id')->unsigned();
$table->unique(['cms_page_id', 'url_key', 'locale']);
$table->foreign('cms_page_id')->references('id')->on('cms_pages')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('cms_page_translations');
}
}

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class RemoveColumnsFromCmsPagesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('cms_pages', function (Blueprint $table) {
$table->dropForeign('cms_pages_locale_id_foreign');
$table->dropForeign('cms_pages_channel_id_foreign');
$table->dropColumn(['url_key', 'html_content', 'page_title', 'meta_title', 'meta_description', 'meta_keywords', 'content', 'locale_id', 'channel_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('cms_pages', function (Blueprint $table) {
//
});
}
}

View File

@ -0,0 +1,35 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCmsPageChannelsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('cms_page_channels', function (Blueprint $table) {
$table->integer('cms_page_id')->unsigned();
$table->integer('channel_id')->unsigned();
$table->unique(['cms_page_id', 'channel_id']);
$table->foreign('cms_page_id')->references('id')->on('cms_pages')->onDelete('cascade');
$table->foreign('channel_id')->references('id')->on('channels')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('cms_page_channels');
}
}

View File

@ -4,6 +4,7 @@ namespace Webkul\CMS\Database\Seeders;
use Illuminate\Database\Seeder;
use DB;
use Carbon\Carbon;
class CMSPagesTableSeeder extends Seeder
{
@ -13,101 +14,99 @@ class CMSPagesTableSeeder extends Seeder
DB::table('cms_pages')->insert([
[
'id' => '1',
'id' => 1,
'created_at' => Carbon::now(),
'updated_at' => Carbon::now()
], [
'id' => 2,
'created_at' => Carbon::now(),
'updated_at' => Carbon::now()
], [
'id' => 3,
'created_at' => Carbon::now(),
'updated_at' => Carbon::now()
], [
'id' => 4,
'created_at' => Carbon::now(),
'updated_at' => Carbon::now()
], [
'id' => 5,
'created_at' => Carbon::now(),
'updated_at' => Carbon::now()
], [
'id' => 6,
'created_at' => Carbon::now(),
'updated_at' => Carbon::now()
]
]);
DB::table('cms_page_translations')->insert([
[
'locale' => 'en',
'cms_page_id' => 1,
'url_key' => 'about-us',
'html_content' => '<div class="static-container one-column">
'html_content' => '<div class="static-container">
<div class="mb-5">About us page content</div>
</div>',
'page_title' => 'About Us',
'meta_title' => 'about us',
'meta_description' => '',
'meta_keywords' => 'aboutus',
'content' => '{"html": "<div class=\"static-container one-column\">\r\n<div class=\"mb-5\">About us page content</div>\r\n</div>",
"meta_title": "about us",
"page_title": "About Us",
"meta_keywords": "aboutus ", "meta_description": ""}',
'channel_id' => 1,
'locale_id' => 1
'meta_keywords' => 'aboutus'
], [
'id' => '2',
'locale' => 'en',
'cms_page_id' => 2,
'url_key' => 'return-policy',
'html_content' => '<div class="static-container one-column">
'html_content' => '<div class="static-container">
<div class="mb-5">Return policy page content</div>
</div>',
'page_title' => 'Return Policy',
'meta_title' => 'return policy',
'meta_description' => '',
'meta_keywords' => 'return, policy',
'content' => '{"html": "<div class=\"static-container one-column\">\r\n<div class=\"mb-5\">Return policy page content</div>\r\n</div>",
"meta_title": "return policy",
"page_title": "Return Policy",
"meta_keywords": "return, policy ", "meta_description": ""}',
'channel_id' => 1,
'locale_id' => 1
'meta_keywords' => 'return, policy'
], [
'id' => '3',
'locale' => 'en',
'cms_page_id' => 3,
'url_key' => 'refund-policy',
'html_content' => '<div class="static-container one-column">
'html_content' => '<div class="static-container">
<div class="mb-5">Refund policy page content</div>
</div>',
'page_title' => 'Refund Policy',
'meta_title' => 'Refund policy',
'meta_description' => '',
'meta_keywords' => 'refund, policy',
'content' => '{"html": "<div class=\"static-container one-column\">\r\n<div class=\"mb-5\">Refund policy page content</div>\r\n</div>",
"meta_title": "Refund policy",
"page_title": "Refund Policy",
"meta_keywords": "refund,policy ", "meta_description": ""}',
'channel_id' => 1,
'locale_id' => 1
'meta_keywords' => 'refund, policy'
], [
'id' => '4',
'locale' => 'en',
'cms_page_id' => 4,
'url_key' => 'terms-conditions',
'html_content' => '<div class="static-container one-column">
'html_content' => '<div class="static-container">
<div class="mb-5">Terms & conditions page content</div>
</div>',
'page_title' => 'Terms & Conditions',
'meta_title' => 'Terms & Conditions',
'meta_description' => '',
'meta_keywords' => 'term, conditions',
'content' => '{"html": "<div class=\"static-container one-column\">\r\n<div class=\"mb-5\">Terms & conditions page content</div>\r\n</div>",
"meta_title": "Terms & Conditions",
"page_title": "Terms & Conditions",
"meta_keywords": "terms, conditions ", "meta_description": ""}',
'channel_id' => 1,
'locale_id' => 1
'meta_keywords' => 'term, conditions'
], [
'id' => '5',
'locale' => 'en',
'cms_page_id' => 5,
'url_key' => 'terms-of-use',
'html_content' => '<div class="static-container one-column">
'html_content' => '<div class="static-container">
<div class="mb-5">Terms of use page content</div>
</div>',
'page_title' => 'Terms of use',
'meta_title' => 'Terms of use',
'meta_description' => '',
'meta_keywords' => 'term, use',
'content' => '{"html": "<div class=\"static-container one-column\">\r\n<div class=\"mb-5\">Terms of use page content</div>\r\n</div>",
"meta_title": "Terms of use",
"page_title": "Terms of use",
"meta_keywords": "terms, use ", "meta_description": ""}',
'channel_id' => 1,
'locale_id' => 1
'meta_keywords' => 'term, use'
], [
'id' => '6',
'locale' => 'en',
'cms_page_id' => 6,
'url_key' => 'contact-us',
'html_content' => '<div class="static-container one-column">
'html_content' => '<div class="static-container">
<div class="mb-5">Contact us page content</div>
</div>',
'page_title' => 'Contact Us',
'meta_title' => 'Contact Us',
'meta_description' => '',
'meta_keywords' => 'contact, us',
'content' => '{"html": "<div class=\"static-container one-column\">\r\n<div class=\"mb-5\">Contact us page content</div>\r\n</div>",
"meta_title": "Contact Us",
"page_title": "Contact Us",
"meta_keywords": "contact, us ", "meta_description": ""}',
'channel_id' => 1,
'locale_id' => 1
'meta_keywords' => 'contact, us'
]
]);
}

View File

@ -3,67 +3,49 @@
namespace Webkul\CMS\Http\Controllers\Admin;
use Webkul\CMS\Http\Controllers\Controller;
use Webkul\CMS\Repositories\CMSRepository as CMS;
use Webkul\Core\Repositories\ChannelRepository as Channel;
use Webkul\Core\Repositories\LocaleRepository as Locale;
use Webkul\CMS\Repositories\CmsRepository;
/**
* CMS controller
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @author Jitendra Singh <jitendra@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class PageController extends Controller
{
/**
* To hold the request variables from route file
*
* @var array
*/
protected $_config;
/**
* To hold the channel reposotry instance
*/
protected $channel;
/**
* To hold the locale reposotry instance
*/
protected $locale;
/**
* To hold the CMSRepository instance
*
* @var Object
*/
protected $cms;
protected $cmsRepository;
public function __construct(Channel $channel, Locale $locale, CMS $cms)
/**
* Create a new controller instance.
*
* @param \Webkul\CMS\Repositories\CmsRepository $cmsRepository
* @return void
*/
public function __construct(CmsRepository $cmsRepository)
{
/**
* Pass the class instance through admin middleware
*/
// $this->middleware('auth:admin');
$this->middleware('admin');
/**
* Channel repository instance
*/
$this->channel = $channel;
/**
* Locale repository instance
*/
$this->locale = $locale;
/**
* CMS repository instance
*/
$this->cms = $cms;
$this->cmsRepository = $cmsRepository;
$this->_config = request('_config');
}
/**
* Loads the index page showing the static pages resources
*
* @return \Illuminate\View\View
*/
public function index()
{
@ -73,7 +55,7 @@ use Webkul\Core\Repositories\LocaleRepository as Locale;
/**
* To create a new CMS page
*
* @return view
* @return \Illuminate\View\View
*/
public function create()
{
@ -83,74 +65,22 @@ use Webkul\Core\Repositories\LocaleRepository as Locale;
/**
* To store a new CMS page in storage
*
* @return view
* @return \Illuminate\Http\Response
*/
public function store()
{
$data = request()->all();
// part one of the validation in case partials pages were generated or generating partial pages
$this->validate(request(), [
'url_key' => ['required', 'unique:cms_page_translations,url_key', new \Webkul\Core\Contracts\Validations\Slug],
'page_title' => 'required',
'channels' => 'required',
'locales' => 'required',
'url_key' => 'required'
'html_content' => 'required'
]);
$page = $this->cmsRepository->create(request()->all());
$channels = $data['channels'];
$locales = $data['locales'];
$this->validate(request(), [
'html_content' => 'required|string',
'page_title' => 'required|string',
'meta_title' => 'required|string',
'meta_description' => 'string',
'meta_keywords' => 'required|string'
]);
$data['content']['html'] = $data['html_content'];
$data['content']['page_title'] = $data['page_title'];
$data['content']['meta_keywords'] = $data['meta_keywords'];
$data['content']['meta_title'] = $data['meta_title'];
$data['content']['meta_description'] = $data['meta_description'];
$data['content'] = json_encode($data['content']);
$totalCount = 0;
$actualCount = 0;
foreach ($channels as $channel) {
foreach ($locales as $locale) {
$pageFound = $this->cms->findOneWhere([
'channel_id' => $channel,
'locale_id' => $locale,
'url_key' => $data['url_key']
]);
$totalCount++;
$data['channel_id'] = $channel;
$data['locale_id'] = $locale;
if (! $pageFound) {
$result = $this->cms->create($data);
if ($result) {
$actualCount++;
}
}
unset($pageFound);
}
}
if (($actualCount != 0 && $totalCount != 0) && ($actualCount == $totalCount)) {
session()->flash('success', trans('admin::app.cms.pages.create-success'));
} else if (($actualCount != 0 && $totalCount != 0) && ($actualCount != $totalCount)) {
session()->flash('warning', trans('admin::app.cms.pages.create-partial'));
} else {
session()->flash('error', trans('admin::app.cms.pages.create-failure'));
}
session()->flash('success', trans('admin::app.response.create-success', ['name' => 'page']));
return redirect()->route($this->_config['redirect']);
}
@ -158,105 +88,53 @@ use Webkul\Core\Repositories\LocaleRepository as Locale;
/**
* To edit a previously created CMS page
*
* @return view
* @param integer $id
* @return \Illuminate\View\View
*/
public function edit($id)
{
$page = $this->cms->findOrFail($id);
$page = $this->cmsRepository->findOrFail($id);
if (request()->has('channel') && request()->has('locale')) {
$channel = $this->channel->findOneWhere([
'code' => request()->input('channel')
]);
$locale = $this->locale->findOneWhere([
'code' => request()->input('locale')
]);
$page = $this->cms->findOneWhere([
'channel_id' => $channel->id,
'locale_id' => $locale->id,
'url_key' => $page->url_key
]);
if (! $page) {
$page = $this->cms->create([
'url_key' => str_random(8),
'channel' => $channel->code,
'locale' => $locale->code
]);
return redirect()->route('admin.cms.edit', $page->id);
}
} else {
$page = $this->cms->findOrFail($id);
}
return view($this->_config['view'])->with('page', $page);
return view($this->_config['view'], compact('page'));
}
/**
* To update the previously created CMS page in storage
*
* @param Integer $id
*
* @return View
* @param integer $id
* @return \Illuminate\Http\Response
*/
public function update($id)
{
$page = $this->cms->findOrFail($id);
$data = request()->all();
$locale = request()->get('locale') ?: app()->getLocale();
$this->validate(request(), [
'page_title' => 'required|string',
'html_content' => 'required|string',
'meta_title' => 'required|string',
'meta_description' => 'string',
'meta_keywords' => 'required|string'
$locale . '.url_key' => ['required', new \Webkul\Core\Contracts\Validations\Slug, function ($attribute, $value, $fail) use ($id) {
if (! $this->cmsRepository->isUrlKeyUnique($id, $value))
$fail(trans('admin::app.response.already-taken', ['name' => 'Page']));
}],
$locale . '.page_title' => 'required',
$locale . '.html_content' => 'required',
'channels' => 'required'
]);
$data['content']['html'] = $data['html_content'];
$data['content']['page_title'] = $data['page_title'];
$data['content']['meta_keywords'] = $data['meta_keywords'];
$data['content']['meta_title'] = $data['meta_title'];
$data['content']['meta_description'] = $data['meta_description'];
$data['content'] = json_encode($data['content']);
$this->cmsRepository->update(request()->all(), $id);
$result = $this->cms->update($data, $id);
session()->flash('success', trans('admin::app.response.update-success', ['name' => 'Page']));
if ($result) {
session()->flash('success', trans('admin::app.cms.pages.update-success'));
} else {
session()->flash('success', trans('admin::app.cms.pages.update-failure'));
}
return redirect()->route($this->_config['redirect']);
}
/**
* To preview the content of the currently creating page or previously creating page
*
* @param Integer $id
*
* @return mixed
*/
public function preview($id)
{
$page = $this->cms->findOrFail($id);
return view('shop::cms.page')->with('page', $page);
}
/**
* To delete the previously create CMS page
*
* @param Integer $id
* @param integer $id
*
* @return Response JSON
* @return \Illuminate\Http\Response
*/
public function delete($id)
{
$page = $this->cms->findOrFail($id);
$page = $this->cmsRepository->findOrFail($id);
if ($page->delete()) {
session()->flash('success', trans('admin::app.cms.pages.delete-success'));
@ -272,7 +150,7 @@ use Webkul\Core\Repositories\LocaleRepository as Locale;
/**
* To mass delete the CMS resource from storage
*
* @return Response redirect
* @return \Illuminate\Http\Response
*/
public function massDelete()
{
@ -281,13 +159,10 @@ use Webkul\Core\Repositories\LocaleRepository as Locale;
if ($data['indexes']) {
$pageIDs = explode(',', $data['indexes']);
$actualCount = count($pageIDs);
$count = 0;
foreach ($pageIDs as $pageId) {
$page = $this->cms->find($pageId);
$page = $this->cmsRepository->find($pageId);
if ($page) {
$page->delete();
@ -296,7 +171,7 @@ use Webkul\Core\Repositories\LocaleRepository as Locale;
}
}
if ($actualCount == $count) {
if (count($pageIDs) == $count) {
session()->flash('success', trans('admin::app.datagrid.mass-ops.delete-success', [
'resource' => 'CMS Pages'
]));

View File

@ -3,66 +3,43 @@
namespace Webkul\CMS\Http\Controllers\Shop;
use Webkul\CMS\Http\Controllers\Controller;
use Webkul\CMS\Repositories\CMSRepository;
use Webkul\Core\Repositories\LocaleRepository;
use Webkul\CMS\Repositories\CmsRepository;
/**
* PagePresenter controller
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @author Jitendra Singh <jitendra@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class PagePresenterController extends Controller
{
/**
* CMSRepository object
* CmsRepository object
*
* @var Object
*/
protected $cmsRepository;
/**
* LocaleRepository object
*
* @var Object
*/
protected $localeRepository;
/**
* Create a new controller instance.
*
* @param \Webkul\CMS\Repositories\CMSRepository $cmsRepository
* @param \Webkul\Core\Repositories\LocaleRepository $localeRepository
* @param \Webkul\CMS\Repositories\CmsRepository $cmsRepository
* @return void
*/
public function __construct(
CMSRepository $cmsRepository,
LocaleRepository $localeRepository
)
public function __construct(CmsRepository $cmsRepository)
{
$this->cmsRepository = $cmsRepository;
$this->localeRepository = $localeRepository;
}
/**
* To extract the page content and load it in the respective view file
*
* @param string $slug
* @param string $urlKey
* @return \Illuminate\View\View
*/
public function presenter($slug)
public function presenter($urlKey)
{
$currentLocale = $this->localeRepository->findOneByField('code', app()->getLocale());
$page = $this->cmsRepository->findOneWhere([
'url_key' => $slug,
'locale_id' => $currentLocale->id,
'channel_id' => core()->getCurrentChannel()->id
]);
if (! $page)
abort(404);
$page = $this->cmsRepository->findByUrlKeyOrFail($urlKey);
return view('shop::cms.page')->with('page', $page);
}

View File

@ -1,13 +0,0 @@
<?php
namespace Webkul\CMS\Models;
use Illuminate\Database\Eloquent\Model;
use Webkul\CMS\Contracts\CMS as CMSContract;
class CMS extends Model implements CMSContract
{
protected $table = 'cms_pages';
protected $fillable = ['content', 'meta_description', 'meta_title', 'page_title', 'meta_keywords', 'html_content', 'url_key', 'layout', 'channel_id', 'locale_id'];
}

View File

@ -0,0 +1,24 @@
<?php
namespace Webkul\CMS\Models;
use Webkul\Core\Eloquent\TranslatableModel;
use Webkul\CMS\Contracts\CmsPage as CmsPageContract;
use Webkul\Core\Models\ChannelProxy;
class CmsPage extends TranslatableModel implements CmsPageContract
{
protected $fillable = ['layout'];
public $translatedAttributes = ['content', 'meta_description', 'meta_title', 'page_title', 'meta_keywords', 'html_content', 'url_key'];
protected $with = ['translations'];
/**
* Get the channels.
*/
public function channels()
{
return $this->belongsToMany(ChannelProxy::modelClass(), 'cms_page_channels');
}
}

View File

@ -4,7 +4,7 @@ namespace Webkul\CMS\Models;
use Konekt\Concord\Proxies\ModelProxy;
class CMSProxy extends ModelProxy
class CmsPageProxy extends ModelProxy
{
}

View File

@ -0,0 +1,13 @@
<?php
namespace Webkul\CMS\Models;
use Illuminate\Database\Eloquent\Model;
use Webkul\CMS\Contracts\CmsPageTranslation as CmsPageTranslationContract;
class CmsPageTranslation extends Model implements CmsPageTranslationContract
{
public $timestamps = false;
protected $fillable = ['page_title', 'url_key', 'html_content', 'meta_title', 'meta_description', 'meta_keywords', 'locale', 'cms_page_id'];
}

View File

@ -0,0 +1,10 @@
<?php
namespace Webkul\CMS\Models;
use Konekt\Concord\Proxies\ModelProxy;
class CmsPageTranslationProxy extends ModelProxy
{
}

View File

@ -3,15 +3,12 @@
namespace Webkul\CMS\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Routing\Router;
use Webkul\CMS\Providers\ModuleServiceProvider;
class CMSServiceProvider extends ServiceProvider
{
public function boot(Router $router)
public function boot()
{
$this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'cms');
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
}
}

View File

@ -7,6 +7,7 @@ use Konekt\Concord\BaseModuleServiceProvider;
class ModuleServiceProvider extends BaseModuleServiceProvider
{
protected $models = [
\Webkul\CMS\Models\CMS::class
\Webkul\CMS\Models\CmsPage::class,
\Webkul\CMS\Models\CmsPageTranslation::class
];
}

View File

@ -1,57 +0,0 @@
<?php
namespace Webkul\CMS\Repositories;
use Webkul\Core\Eloquent\Repository;
use Illuminate\Container\Container as App;
use Webkul\Core\Repositories\ChannelRepository as Channel;
use Webkul\Core\Repositories\LocaleRepository as Locale;
/**
* CMS Reposotory
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class CMSRepository extends Repository
{
/**
* To hold the channel reposotry instance
*/
protected $channel;
/**
* To hold the locale reposotry instance
*/
protected $locale;
public function __construct(Channel $channel, Locale $locale, App $app)
{
$this->channel = $channel;
$this->locale = $locale;
parent::__construct($app);
}
/**
* Specify Model class name
*
* @return mixed
*/
function model()
{
return 'Webkul\CMS\Contracts\CMS';
}
public function create(array $data)
{
$result = $this->model->create($data);
if ($result) {
return $result;
} else {
return $result;
}
}
}

View File

@ -0,0 +1,110 @@
<?php
namespace Webkul\CMS\Repositories;
use Illuminate\Support\Facades\Event;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Webkul\Core\Eloquent\Repository;
use Webkul\CMS\Models\CmsPageTranslation;
/**
* CMS Reposotory
*
* @author Jitendra Singh <jitendra@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class CmsRepository extends Repository
{
/**
* Specify Model class name
*
* @return mixed
*/
function model()
{
return 'Webkul\CMS\Contracts\CmsPage';
}
/**
* @param array $data
* @return mixed
*/
public function create(array $data)
{
Event::fire('cms.pages.create.before');
$model = $this->getModel();
foreach (core()->getAllLocales() as $locale) {
foreach ($model->translatedAttributes as $attribute) {
if (isset($data[$attribute]))
$data[$locale->code][$attribute] = $data[$attribute];
}
}
$page = parent::create($data);
$page->channels()->sync($data['channels']);
Event::fire('cms.pages.create.after', $page);
return $page;
}
/**
* @param array $data
* @param integer $id
* @param string $attribute
* @return mixed
*/
public function update(array $data, $id, $attribute = "id")
{
$page = $this->find($id);
Event::fire('cms.pages.update.before', $id);
parent::update($data, $id, $attribute);
$page->channels()->sync($data['channels']);
Event::fire('cms.pages.update.after', $id);
return $page;
}
/**
* Checks slug is unique or not based on locale
*
* @param integer $id
* @param string $urlKey
* @return boolean
*/
public function isUrlKeyUnique($id, $urlKey)
{
$exists = CmsPageTranslation::where('cms_page_id', '<>', $id)
->where('url_key', $urlKey)
->limit(1)
->select(\DB::raw(1))
->exists();
return $exists ? false : true;
}
/**
* Retrive category from slug
*
* @param string $urlKey
* @return mixed
*/
public function findByUrlKeyOrFail($urlKey)
{
$page = $this->model->whereTranslation('url_key', $urlKey)->first();
if ($page)
return $page;
throw (new ModelNotFoundException)->setModel(
get_class($this->model), $urlKey
);
}
}

View File

@ -18,16 +18,6 @@ use Illuminate\Database\Eloquent\ModelNotFoundException;
*/
class CategoryRepository extends Repository
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(App $app)
{
parent::__construct($app);
}
/**
* Specify Model class name
*

View File

@ -2,10 +2,11 @@
namespace Webkul\Core\Repositories;
use Illuminate\Container\Container as App;
use Webkul\Core\Eloquent\Repository;
use Webkul\Core\Repositories\ChannelRepository;
use Storage;
use Webkul\Core\Eloquent\Repository;
use Illuminate\Support\Facades\Event;
use Illuminate\Container\Container as App;
use Webkul\Core\Repositories\ChannelRepository;
/**
* Slider Repository
@ -54,6 +55,8 @@ class SliderRepository extends Repository
*/
public function save(array $data)
{
Event::fire('core.settings.slider.create.before', $id);
$channelName = $this->channelRepository->find($data['channel_id'])->name;
$dir = 'slider_images/' . $channelName;
@ -82,7 +85,11 @@ class SliderRepository extends Repository
unset($data['image']);
}
return $this->create($data);
$slider = $this->create($data);
Event::fire('core.settings.slider.create.after', $slider);
return true;
}
/**
@ -91,6 +98,8 @@ class SliderRepository extends Repository
*/
public function updateItem(array $data, $id)
{
Event::fire('core.settings.slider.update.before', $id);
$channelName = $this->channelRepository->find($data['channel_id'])->name;
$dir = 'slider_images/' . $channelName;
@ -119,7 +128,9 @@ class SliderRepository extends Repository
unset($data['image']);
}
$this->update($data, $id);
$slider = $this->update($data, $id);
Event::fire('core.settings.slider.update.after', $slider);
return true;
}

View File

@ -597,9 +597,8 @@ abstract class AbstractType
/**
* Get request quantity
*
* @param Product $product
* @param array $data
* @return CartItem|void
* @param array $data
* @return array
*/
public function getQtyRequest($data)
{

View File

@ -405,7 +405,9 @@ class Bundle extends AbstractType
*/
public function prepareForCart($data)
{
if (! isset($data['bundle_options']))
$data['bundle_options'] = array_filter($this->validateBundleOptionForCart($data['bundle_options']));
if (! isset($data['bundle_options']) || ! count($data['bundle_options']))
return trans('shop::app.checkout.cart.integrity.missing_options');
$products = parent::prepareForCart($data);
@ -419,6 +421,9 @@ class Bundle extends AbstractType
return $cartProduct;
$cartProduct[0]['parent_id'] = $this->product->id;
$cartProduct[0]['quantity'] = $data['quantity'];
$cartProduct[0]['total_weight'] = $cartProduct[0]['weight'] * $data['quantity'];
$cartProduct[0]['base_total_weight'] = $cartProduct[0]['weight'] * $data['quantity'];
$products = array_merge($products, $cartProduct);
@ -426,9 +431,9 @@ class Bundle extends AbstractType
$products[0]['base_price'] += $cartProduct[0]['base_total'];
$products[0]['total'] += $cartProduct[0]['total'];
$products[0]['base_total'] += $cartProduct[0]['base_total'];
$products[0]['weight'] += $cartProduct[0]['weight'];
$products[0]['total_weight'] += $cartProduct[0]['total_weight'];
$products[0]['base_total_weight'] += $cartProduct[0]['base_total_weight'];
$products[0]['weight'] += ($cartProduct[0]['weight'] * $products[0]['quantity']);
$products[0]['total_weight'] += ($cartProduct[0]['total_weight'] * $products[0]['quantity']);
$products[0]['base_total_weight'] += ($cartProduct[0]['base_total_weight'] * $products[0]['quantity']);
}
return $products;
@ -483,7 +488,29 @@ class Bundle extends AbstractType
if ($this->product->id != $options2['product_id'])
return false;
return $options1['bundle_options'] == $options2['bundle_options'];
return $options1['bundle_options'] == $options2['bundle_options']
&& $options1['bundle_option_qty'] == $this->getOptionQuantities($options2);
}
/**
* Remove invalid options from add to cart request
*
* @param array $data
* @return array
*/
public function validateBundleOptionForCart($data)
{
foreach ($data as $key => $value) {
if (is_array($value)) {
$data[$key] = $this->validateBundleOptionForCart($value);
} elseif ($value && $value) {
$data[$key] = (int)$value;
} else {
unset($data[$key]);
}
}
return $data;
}
/**
@ -506,6 +533,9 @@ class Bundle extends AbstractType
$optionProduct = $this->productBundleOptionProductRepository->find($optionProductId);
$qty = $data['bundle_option_qty'][$optionId] ?? $optionProduct->qty;
if (! isset($data['bundle_option_qty'][$optionId]))
$data['bundle_option_qty'][$optionId] = $qty;
$labels[] = $qty . ' x ' . $optionProduct->product->name . ' ' . core()->currency($optionProduct->product->getTypeInstance()->getMinimalPrice());
}
@ -522,6 +552,36 @@ class Bundle extends AbstractType
return $data;
}
/**
* Returns additional information for items
*
* @param array $data
* @return array
*/
public function getOptionQuantities($data)
{
$optionQuantities = [];
foreach ($data['bundle_options'] as $optionId => $optionProductIds) {
foreach ($optionProductIds as $optionProductId) {
if (! $optionProductId)
continue;
if (isset($data['bundle_option_qty'][$optionId])) {
$optionQuantities[$optionId] = $data['bundle_option_qty'][$optionId];
continue;
}
$optionProduct = $this->productBundleOptionProductRepository->find($optionProductId);
$optionQuantities[$optionId] = $optionProduct->qty;
}
}
return $optionQuantities;
}
/**
* Validate cart item product price
*

View File

@ -18,7 +18,8 @@ require("ez-plus/src/jquery.ez-plus.js");
Vue.use(VeeValidate, {
dictionary: {
ar: { messages: localeMessages.ar }
}
},
events: 'input|change|blur',
});
Vue.prototype.$http = axios

View File

@ -10,7 +10,7 @@
@push('scripts')
@include('shop::checkout.cart.coupon')
<script type="text/x-template" id="checkout-template">
<div id="checkout" class="checkout-process">
<div class="col-main">
@ -234,7 +234,7 @@
},
isCustomerExist: function() {
this.$validator.attach('email', 'required|email');
this.$validator.attach({ name: "email", rules: "required|email" });
var this_this = this;

View File

@ -98,6 +98,7 @@
<div v-if="option.type == 'multiselect'">
<select class="control" :name="'bundle_options[' + option.id + '][]'" v-model="selected_product" v-validate="option.is_required ? 'required' : ''" :data-vv-as="'&quot;' + option.label + '&quot;'" multiple>
<option value="0" v-if="! option.is_required">{{ __('shop::app.products.none') }}</option>
<option v-for="(product, index2) in option.products" :value="product.id">
@{{ product.name + ' + ' + product.price.final_price.formated_price }}
</option>