Channel and families completed

This commit is contained in:
jitendra 2018-07-27 11:52:12 +05:30
parent 3a7ab61082
commit 5f7c432dc5
48 changed files with 1428 additions and 476 deletions

View File

@ -29,7 +29,8 @@
"webkul/laravel-core": "self.version",
"webkul/laravel-category": "self.version",
"webkul/laravel-attribute": "self.version",
"webkul/laravel-channel": "self.version"
"webkul/laravel-channel": "self.version",
"webkul/laravel-product": "self.version"
},
"autoload": {
"classmap": [
@ -45,7 +46,8 @@
"Webkul\\Attribute\\": "packages/Webkul/Attribute/src",
"Webkul\\Core\\": "packages/Webkul/Core/src",
"Webkul\\Channel\\": "packages/Webkul/Channel/src",
"Webkul\\Inventory\\": "packages/Webkul/Inventory/src"
"Webkul\\Inventory\\": "packages/Webkul/Inventory/src",
"Webkul\\Product\\": "packages/Webkul/Product/src"
}
},
"autoload-dev": {

View File

@ -171,7 +171,8 @@ return [
Webkul\Attribute\Providers\AttributeServiceProvider::class,
Webkul\Core\Providers\CoreServiceProvider::class,
Webkul\Channel\Providers\ChannelServiceProvider::class,
Webkul\Inventory\Providers\InventoryServiceProvider::class
Webkul\Inventory\Providers\InventoryServiceProvider::class,
Webkul\Product\Providers\ProductServiceProvider::class
],
/*

View File

@ -45,6 +45,15 @@ Route::group(['middleware' => ['web']], function () {
// Catalog Routes
Route::prefix('catalog')->group(function () {
// Catalog Product Routes
Route::get('/products', 'Webkul\Product\Http\Controllers\ProductController@index')->defaults('_config', [
'view' => 'admin::catalog.products.index'
])->name('admin.catalog.products.index');
Route::get('/products/create', 'Webkul\Product\Http\Controllers\ProductController@create')->defaults('_config', [
'view' => 'admin::catalog.products.create'
])->name('admin.catalog.products.create');
// Catalog Category Routes
Route::get('/categories', 'Webkul\Category\Http\Controllers\CategoryController@index')->defaults('_config', [
'view' => 'admin::catalog.categories.index'

View File

@ -39,7 +39,9 @@ class EventServiceProvider extends ServiceProvider
Event::listen('admin.menu.build', function($menu) {
$menu->add('dashboard', 'Dashboard', 'admin.dashboard.index', 1, 'dashboard-icon');
$menu->add('catalog', 'Catalog', 'admin.catalog.categories.index', 3, 'catalog-icon');
$menu->add('catalog', 'Catalog', 'admin.catalog.products.index', 3, 'catalog-icon');
$menu->add('catalog.products', 'Products', 'admin.catalog.products.index', 1);
$menu->add('catalog.categories', 'Categories', 'admin.catalog.categories.index', 2);

View File

@ -63,6 +63,13 @@ return [
]
],
'catalog' => [
'products' => [
'products' => 'products',
'add-product-btn-title' => 'Add Product',
'add-title' => 'Add Product',
'edit-title' => 'Edit Product',
'save-btn-title' => 'Save Product',
],
'attributes' => [
'add-title' => 'Add Attribute',
'edit-title' => 'Edit Attribute',
@ -72,6 +79,8 @@ return [
'type' => 'Attribute Type',
'text' => 'Text',
'textarea' => 'Textarea',
'price' => 'Price',
'boolean' => 'Boolean',
'select' => 'Select',
'multiselect' => 'Multiselect',
'checkbox' => 'Checkbox',
@ -114,7 +123,7 @@ return [
'position' => 'Position',
'attribute-code' => 'Code',
'type' => 'Type',
'add-attribute-title' => 'Add Attribute',
'add-attribute-title' => 'Add Attributes',
'search' => 'Search',
'group-exist-error' => 'Group with same name already exists.'
],

View File

@ -7,7 +7,7 @@
@section('content')
<div class="content">
<form method="POST" action="{{ route('admin.catalog.attributes.store') }}">
<form method="POST" action="{{ route('admin.catalog.attributes.store') }}" @submit.prevent="onSubmit">
<div class="page-header">
<div class="page-title">
@ -38,6 +38,8 @@
<select class="control" id="type" name="type">
<option value="text">{{ __('admin::app.catalog.attributes.text') }}</option>
<option value="textarea">{{ __('admin::app.catalog.attributes.textarea') }}</option>
<option value="price">{{ __('admin::app.catalog.attributes.price') }}</option>
<option value="boolean">{{ __('admin::app.catalog.attributes.boolean') }}</option>
<option value="select">{{ __('admin::app.catalog.attributes.select') }}</option>
<option value="multiselect">{{ __('admin::app.catalog.attributes.multiselect') }}</option>
<option value="checkbox">{{ __('admin::app.catalog.attributes.checkbox') }}</option>
@ -85,16 +87,16 @@
<div class="control-group">
<label for="is_required">{{ __('admin::app.catalog.attributes.is_required') }}</label>
<select class="control" id="is_required" name="is_required">
<option value="1">{{ __('admin::app.catalog.attributes.yes') }}</option>
<option value="0">{{ __('admin::app.catalog.attributes.no') }}</option>
<option value="1">{{ __('admin::app.catalog.attributes.yes') }}</option>
</select>
</div>
<div class="control-group">
<label for="is_unique">{{ __('admin::app.catalog.attributes.is_unique') }}</label>
<select class="control" id="is_unique" name="is_unique">
<option value="1">{{ __('admin::app.catalog.attributes.yes') }}</option>
<option value="0">{{ __('admin::app.catalog.attributes.no') }}</option>
<option value="1">{{ __('admin::app.catalog.attributes.yes') }}</option>
</select>
</div>
@ -126,32 +128,32 @@
<div class="control-group">
<label for="value_per_locale">{{ __('admin::app.catalog.attributes.value_per_locale') }}</label>
<select class="control" id="value_per_locale" name="value_per_locale">
<option value="1">{{ __('admin::app.catalog.attributes.yes') }}</option>
<option value="0">{{ __('admin::app.catalog.attributes.no') }}</option>
<option value="1">{{ __('admin::app.catalog.attributes.yes') }}</option>
</select>
</div>
<div class="control-group">
<label for="value_per_channel">{{ __('admin::app.catalog.attributes.value_per_channel') }}</label>
<select class="control" id="value_per_channel" name="value_per_channel">
<option value="1">{{ __('admin::app.catalog.attributes.yes') }}</option>
<option value="0">{{ __('admin::app.catalog.attributes.no') }}</option>
<option value="1">{{ __('admin::app.catalog.attributes.yes') }}</option>
</select>
</div>
<div class="control-group">
<label for="is_filterable">{{ __('admin::app.catalog.attributes.is_filterable') }}</label>
<select class="control" id="is_filterable" name="is_filterable">
<option value="1">{{ __('admin::app.catalog.attributes.yes') }}</option>
<option value="0">{{ __('admin::app.catalog.attributes.no') }}</option>
<option value="1">{{ __('admin::app.catalog.attributes.yes') }}</option>
</select>
</div>
<div class="control-group">
<label for="is_configurable">{{ __('admin::app.catalog.attributes.is_configurable') }}</label>
<select class="control" id="is_configurable" name="is_configurable">
<option value="1">{{ __('admin::app.catalog.attributes.yes') }}</option>
<option value="0">{{ __('admin::app.catalog.attributes.no') }}</option>
<option value="1">{{ __('admin::app.catalog.attributes.yes') }}</option>
</select>
</div>

View File

@ -7,7 +7,7 @@
@section('content')
<div class="content">
<form method="POST" action="{{ route('admin.catalog.attributes.update', $attribute->id) }}">
<form method="POST" action="{{ route('admin.catalog.attributes.update', $attribute->id) }}" @submit.prevent="onSubmit">
<div class="page-header">
<div class="page-title">
@ -30,22 +30,27 @@
<div slot="body">
<div class="control-group" :class="[errors.has('code') ? 'has-error' : '']">
<label for="code" class="required">{{ __('admin::app.catalog.attributes.code') }}</label>
<input type="hidden" name="code" value="{{ old('code') ?: $attribute->code }}"/>
<input type="text" v-validate="'required'" class="control" id="code" name="code" value="{{ old('code') ?: $attribute->code }}" disabled="disabled"/>
<input type="text" v-validate="'required'" class="control" id="code" name="code" value="{{ $attribute->code }}" disabled="disabled"/>
<input type="hidden" name="code" value="{{ $attribute->code }}"/>
<span class="control-error" v-if="errors.has('code')">@{{ errors.first('code') }}</span>
</div>
<div class="control-group">
<?php $selectedOption = old('type') ?: $attribute->type ?>
<label for="type">{{ __('admin::app.catalog.attributes.type') }}</label>
<input type="hidden" name="type" value="{{ old('type') ?: $attribute->type }}"/>
<select class="control" id="type" name="type" disabled="disabled">
<select class="control" id="type" disabled="disabled">
<option value="text" {{ $selectedOption == 'text' ? 'selected' : '' }}>
{{ __('admin::app.catalog.attributes.text') }}
</option>
<option value="textarea" {{ $selectedOption == 'textarea' ? 'selected' : '' }}>
{{ __('admin::app.catalog.attributes.textarea') }}
</option>
<option value="price" {{ $selectedOption == 'price' ? 'selected' : '' }}>
{{ __('admin::app.catalog.attributes.price') }}
</option>
<option value="boolean" {{ $selectedOption == 'boolean' ? 'selected' : '' }}>
{{ __('admin::app.catalog.attributes.boolean') }}
</option>
<option value="select" {{ $selectedOption == 'select' ? 'selected' : '' }}>
{{ __('admin::app.catalog.attributes.select') }}
</option>
@ -62,6 +67,7 @@
{{ __('admin::app.catalog.attributes.date') }}
</option>
</select>
<input type="hidden" name="type" value="{{ $attribute->type }}"/>
</div>
</div>
</accordian>
@ -103,16 +109,20 @@
<div class="control-group">
<label for="is_required">{{ __('admin::app.catalog.attributes.is_required') }}</label>
<select class="control" id="is_required" name="is_required">
<option value="1" {{ $attribute->is_required ? 'selected' : '' }}>{{ __('admin::app.catalog.attributes.yes') }}</option>
<option value="0" {{ $attribute->is_required ? '' : 'selected' }}>{{ __('admin::app.catalog.attributes.no') }}</option>
<option value="1" {{ $attribute->is_required ? 'selected' : '' }}>{{ __('admin::app.catalog.attributes.yes') }}</option>
</select>
</div>
<div class="control-group">
<label for="is_unique">{{ __('admin::app.catalog.attributes.is_unique') }}</label>
<select class="control" id="is_unique" name="is_unique">
<option value="1" {{ $attribute->is_unique ? 'selected' : '' }}>{{ __('admin::app.catalog.attributes.yes') }}</option>
<option value="0" {{ $attribute->is_unique ? '' : 'selected' }}>{{ __('admin::app.catalog.attributes.no') }}</option>
<option value="0" {{ $attribute->is_unique ? '' : 'selected' }}>
{{ __('admin::app.catalog.attributes.no') }}
</option>
<option value="1" {{ $attribute->is_unique ? 'selected' : '' }}>
{{ __('admin::app.catalog.attributes.yes') }}
</option>
</select>
</div>
@ -157,48 +167,48 @@
<div class="control-group">
<label for="value_per_locale">{{ __('admin::app.catalog.attributes.value_per_locale') }}</label>
<select class="control" id="value_per_locale" name="value_per_locale">
<option value="1" {{ $attribute->value_per_locale ? 'selected' : '' }}>
{{ __('admin::app.catalog.attributes.yes') }}
</option>
<option value="0" {{ $attribute->value_per_locale ? '' : 'selected' }}>
{{ __('admin::app.catalog.attributes.no') }}
</option>
<option value="1" {{ $attribute->value_per_locale ? 'selected' : '' }}>
{{ __('admin::app.catalog.attributes.yes') }}
</option>
</select>
</div>
<div class="control-group">
<label for="value_per_channel">{{ __('admin::app.catalog.attributes.value_per_channel') }}</label>
<select class="control" id="value_per_channel" name="value_per_channel">
<option value="1" {{ $attribute->value_per_channel ? 'selected' : '' }}>
{{ __('admin::app.catalog.attributes.yes') }}
</option>
<option value="0" {{ $attribute->value_per_channel ? '' : 'selected' }}>
{{ __('admin::app.catalog.attributes.no') }}
</option>
<option value="1" {{ $attribute->value_per_channel ? 'selected' : '' }}>
{{ __('admin::app.catalog.attributes.yes') }}
</option>
</select>
</div>
<div class="control-group">
<label for="is_filterable">{{ __('admin::app.catalog.attributes.is_filterable') }}</label>
<select class="control" id="is_filterable" name="is_filterable">
<option value="1" {{ $attribute->is_filterable ? 'selected' : '' }}>
{{ __('admin::app.catalog.attributes.yes') }}
</option>
<option value="0" {{ $attribute->is_filterable ? '' : 'selected' }}>
{{ __('admin::app.catalog.attributes.no') }}
</option>
<option value="1" {{ $attribute->is_filterable ? 'selected' : '' }}>
{{ __('admin::app.catalog.attributes.yes') }}
</option>
</select>
</div>
<div class="control-group">
<label for="is_configurable">{{ __('admin::app.catalog.attributes.is_configurable') }}</label>
<select class="control" id="is_configurable" name="is_configurable">
<option value="1" {{ $attribute->is_configurable ? 'selected' : '' }}>
{{ __('admin::app.catalog.attributes.yes') }}
</option>
<option value="0" {{ $attribute->is_configurable ? '' : 'selected' }}>
{{ __('admin::app.catalog.attributes.no') }}
</option>
<option value="1" {{ $attribute->is_configurable ? 'selected' : '' }}>
{{ __('admin::app.catalog.attributes.yes') }}
</option>
</select>
</div>

View File

@ -7,7 +7,7 @@
@section('content')
<div class="content">
<form method="POST" action="{{ route('admin.catalog.categories.store') }}">
<form method="POST" action="{{ route('admin.catalog.categories.store') }}" @submit.prevent="onSubmit">
<div class="page-header">
<div class="page-title">
@ -69,6 +69,7 @@
</div>
</accordian>
@if($categories->count())
<accordian :title="'{{ __('admin::app.catalog.categories.parent-category') }}'" :active="true">
<div slot="body">
@ -76,6 +77,7 @@
</div>
</accordian>
@endif
<accordian :title="'{{ __('admin::app.catalog.categories.seo') }}'" :active="true">
<div slot="body">

View File

@ -6,9 +6,9 @@
@section('content')
<div class="content">
<?php $locale = request()->get('channel_locale') ?: channel()->getDefaultChannelLocale()->id; ?>
<?php $locale = request()->get('channel_locale') ?: channel()->getDefaultChannelLocaleCode(); ?>
<form method="POST" action="">
<form method="POST" action="" @submit.prevent="onSubmit">
<div class="page-header">
<div class="page-title">
@ -16,13 +16,13 @@
<div class="control-group">
<select class="control" id="locale-switcher" onChange="window.location.href = this.value">
@foreach(Webkul\Channel\Models\Channel::all() as $channel)
@foreach(channel()->getChannelWithLocales() as $channel)
<optgroup label="{{ $channel->name }}">
@foreach($channel->channel_locales as $channelLocale)
<option value="{{ route('admin.catalog.categories.update', $category->id) . '?channel_locale=' . $channelLocale->id }}" {{ $channelLocale->id == $locale ? 'selected' : '' }}>
{{ $channelLocale->locale->name }}
@foreach($channel->locales as $channelLocale)
<option value="{{ route('admin.catalog.categories.update', $category->id) . '?channel_locale=' . $channel->code . '-' . $channelLocale->code }}" {{ ($channel->code . '-' . $channelLocale->code) == $locale ? 'selected' : '' }}>
{{ $channelLocale->name }}
</option>
@endforeach
@ -88,6 +88,7 @@
</div>
</accordian>
@if($categories->count())
<accordian :title="'{{ __('admin::app.catalog.categories.parent-category') }}'" :active="true">
<div slot="body">
@ -95,6 +96,7 @@
</div>
</accordian>
@endif
<accordian :title="'{{ __('admin::app.catalog.categories.seo') }}'" :active="true">
<div slot="body">

View File

@ -6,7 +6,7 @@
@section('content')
<div class="content">
<form method="POST" action="{{ route('admin.catalog.families.store') }}">
<form method="POST" action="{{ route('admin.catalog.families.store') }}" @submit.prevent="onSubmit">
<div class="page-header">
<div class="page-title">
@ -109,13 +109,14 @@
<accordian :title="group.groupName" :active="true">
<div slot="header">
<i class="icon expand-icon left"></i>
<h1>@{{ group.groupName }}</h1>
<i class="icon trash-icon" @click="removeGroup()"></i>
<h1>@{{ group.name ? group.name : group.groupName }}</h1>
<i class="icon trash-icon" @click="removeGroup()" v-if="group.is_user_defined"></i>
</div>
<div slot="body">
<input type="hidden" :name="groupInputName" :value="group.groupName"/>
<input type="hidden":name="groupInputPosition" :value="group.position"/>
<input type="hidden" :name="[groupInputName + '[name]']" :value="group.name ? group.name : group.groupName"/>
<input type="hidden" :name="[groupInputName + '[position]']" :value="group.position"/>
<input type="hidden" :name="[groupInputName + '[is_user_defined]']" :value="group.is_user_defined"/>
<div class="table" v-if="group.attributes.length" style="margin-bottom: 20px;">
<table>
@ -131,13 +132,13 @@
<tbody>
<tr v-for='(attribute, index) in group.attributes'>
<td>
<input type="hidden" :name="groupAttributeInput" :value="attribute.id"/>
<input type="hidden" :name="[groupInputName + '[attributes][][id]']" :value="attribute.id"/>
@{{ attribute.code }}
</td>
<td>@{{ attribute.admin_name }}</td>
<td>@{{ attribute.type }}</td>
<td class="actions">
<i class="icon trash-icon" @click="removeAttribute(attribute)"></i>
<i class="icon trash-icon" @click="removeAttribute(attribute)" v-if="attribute.is_user_defined"></i>
</td>
</tr>
</tbody>
@ -174,163 +175,169 @@
</script>
<script>
// $(document).ready(function () {
var groups = [];
var attributes = @json($attributes);
var groups = @json($attributeFamily ? $attributeFamily->attribute_groups : []);
var attributes = @json($attributes);
Vue.component('group-form', {
Vue.component('group-form', {
data: () => ({
group: {
'groupName': '',
'position': '',
'attributes': []
}
}),
template: '#group-form-template',
methods: {
addGroup (formScope) {
this.$validator.validateAll(formScope).then((result) => {
if (result) {
var this_this = this;
var filteredGroups = groups.filter(function(group) {
return this_this.group.groupName.trim() === group.groupName.trim()
})
if(filteredGroups.length) {
const field = this.$validator.fields.find({ name: 'groupName', scope: 'add-group-form' });
if (field) {
this.$validator.errors.add({
id: field.id,
field: 'groupName',
msg: "{{ __('admin::app.catalog.families.group-exist-error') }}",
scope: 'add-group-form',
});
}
} else {
groups.push(this.group);
groups = this.sortGroups();
this.group = {'groupName': '', 'position': '', 'attributes': []};
this.$parent.closeModal();
}
}
});
},
sortGroups () {
return groups.sort(function(a, b) {
return a.position - b.position;
});
}
data: () => ({
group: {
'groupName': '',
'position': '',
'is_user_defined': 1,
'attributes': []
}
});
}),
Vue.component('group-list', {
template: '#group-form-template',
template: '#group-list-template',
methods: {
addGroup (formScope) {
this.$validator.validateAll(formScope).then((result) => {
if (result) {
var this_this = this;
data: () => ({
groups: groups,
attributes: attributes
}),
var filteredGroups = groups.filter(function(group) {
return this_this.group.groupName.trim() === (group.name ? group.name.trim() : group.groupName.trim())
})
methods: {
removeGroup (group) {
group.attributes.forEach(function(attribute) {
this.attributes.push(attribute);
})
if(filteredGroups.length) {
const field = this.$validator.fields.find({ name: 'groupName', scope: 'add-group-form' });
this.attributes = this.sortAttributes();
if (field) {
this.$validator.errors.add({
id: field.id,
field: 'groupName',
msg: "{{ __('admin::app.catalog.families.group-exist-error') }}",
scope: 'add-group-form',
});
}
} else {
groups.push(this.group);
let index = groups.indexOf(group)
groups = this.sortGroups();
this.group = {'groupName': '', 'position': '', 'is_user_defined': 1, 'attributes': []};
groups.splice(index, 1)
},
this.$parent.closeModal();
}
}
});
},
addAttributes (groupIndex, attributeIds) {
attributeIds.forEach(function(attributeId) {
var attribute = this.attributes.filter(attribute => attribute.id == attributeId)
this.groups[groupIndex].attributes.push(attribute[0]);
sortGroups () {
return groups.sort(function(a, b) {
return a.position - b.position;
});
}
}
});
Vue.component('group-list', {
template: '#group-list-template',
data: () => ({
groups: groups,
attributes: attributes
}),
created () {
this.groups.forEach(function(group) {
group.attributes.forEach(function(attribute) {
var attribute = this.attributes.filter(attributeTemp => attributeTemp.id == attribute.id)
if(attribute.length) {
let index = this.attributes.indexOf(attribute[0])
this.attributes.splice(index, 1)
})
},
}
removeAttribute (groupIndex, attribute) {
let index = this.groups[groupIndex].attributes.indexOf(attribute)
this.groups[groupIndex].attributes.splice(index, 1)
});
});
},
methods: {
removeGroup (group) {
group.attributes.forEach(function(attribute) {
this.attributes.push(attribute);
})
this.attributes = this.sortAttributes();
},
this.attributes = this.sortAttributes();
sortAttributes () {
return this.attributes.sort(function(a, b) {
return a.id - b.id;
});
}
}
})
let index = groups.indexOf(group)
Vue.component('group-item', {
props: ['index', 'group', 'attributes'],
template: "#group-item-template",
computed: {
groupInputName () {
return "attribute_groups[group_" + this.index + "][name]";
},
groupInputPosition () {
return "attribute_groups[group_" + this.index + "][position]";
},
groupAttributeInput () {
return "attribute_groups[group_" + this.index + "][attributes][]";
}
groups.splice(index, 1)
},
methods: {
removeGroup () {
this.$emit('onRemoveGroup', this.group)
},
addAttributes (groupIndex, attributeIds) {
attributeIds.forEach(function(attributeId) {
var attribute = this.attributes.filter(attribute => attribute.id == attributeId)
this.groups[groupIndex].attributes.push(attribute[0]);
addAttributes (e) {
var attributeIds = [];
let index = this.attributes.indexOf(attribute[0])
$(e.target).prev().find('li input').each(function() {
var attributeId = $(this).val();
if($(this).is(':checked')) {
attributeIds.push(attributeId);
this.attributes.splice(index, 1)
})
},
$(this).prop('checked', false);
}
});
removeAttribute (groupIndex, attribute) {
let index = this.groups[groupIndex].attributes.indexOf(attribute)
$('body').trigger('click')
this.groups[groupIndex].attributes.splice(index, 1)
this.$emit('onAttributeAdd', attributeIds)
},
this.attributes.push(attribute);
removeAttribute (attribute) {
this.$emit('onAttributeRemove', attribute)
}
this.attributes = this.sortAttributes();
},
sortAttributes () {
return this.attributes.sort(function(a, b) {
return a.id - b.id;
});
}
});
// });
}
})
Vue.component('group-item', {
props: ['index', 'group', 'attributes'],
template: "#group-item-template",
computed: {
groupInputName () {
return "attribute_groups[group_" + this.index + "]";
}
},
methods: {
removeGroup () {
this.$emit('onRemoveGroup', this.group)
},
addAttributes (e) {
var attributeIds = [];
$(e.target).prev().find('li input').each(function() {
var attributeId = $(this).val();
if($(this).is(':checked')) {
attributeIds.push(attributeId);
$(this).prop('checked', false);
}
});
$('body').trigger('click')
this.$emit('onAttributeAdd', attributeIds)
},
removeAttribute (attribute) {
this.$emit('onAttributeRemove', attribute)
}
}
});
</script>
@stop

View File

@ -6,7 +6,7 @@
@section('content')
<div class="content">
<form method="POST" action="{{ route('admin.catalog.families.update', $attributeFamily->id) }}">
<form method="POST" action="{{ route('admin.catalog.families.update', $attributeFamily->id) }}" @submit.prevent="onSubmit">
<div class="page-header">
<div class="page-title">
@ -30,8 +30,8 @@
<div slot="body">
<div class="control-group" :class="[errors.has('code') ? 'has-error' : '']">
<label for="code" class="required">{{ __('admin::app.catalog.families.code') }}</label>
<input type="text" v-validate="'required'" class="control" id="code" name="code" value="{{ old('code') ?: $attributeFamily->code }}"/>
<input type="text" v-validate="'required'" name="code" class="control" id="code" value="{{ $attributeFamily->code }}" disabled="disabled"/>
<input type="hidden" name="code" value="{{ $attributeFamily->code }}"/>
<span class="control-error" v-if="errors.has('code')">@{{ errors.first('code') }}</span>
</div>
@ -111,12 +111,12 @@
<div slot="header">
<i class="icon expand-icon left"></i>
<h1>@{{ group.name ? group.name : group.groupName }}</h1>
<i class="icon trash-icon" @click="removeGroup()"></i>
<i class="icon trash-icon" @click="removeGroup()" v-if="group.is_user_defined"></i>
</div>
<div slot="body">
<input type="hidden" :name="groupInputName" :value="group.name ? group.name : group.groupName"/>
<input type="hidden":name="groupInputPosition" :value="group.position"/>
<input type="hidden" :name="[groupInputName + '[name]']" :value="group.name ? group.name : group.groupName"/>
<input type="hidden":name="[groupInputName + '[position]']" :value="group.position"/>
<div class="table" v-if="group.attributes.length" style="margin-bottom: 20px;">
<table>
@ -132,13 +132,13 @@
<tbody>
<tr v-for='(attribute, index) in group.attributes'>
<td>
<input type="hidden" :name="groupAttributeInput" :value="attribute.id"/>
<input type="hidden" :name="[groupInputName + '[attributes][][id]']" :value="attribute.id"/>
@{{ attribute.code }}
</td>
<td>@{{ attribute.admin_name }}</td>
<td>@{{ attribute.type }}</td>
<td class="actions">
<i class="icon trash-icon" @click="removeAttribute(attribute)"></i>
<i class="icon trash-icon" @click="removeAttribute(attribute)" v-if="attribute.is_user_defined"></i>
</td>
</tr>
</tbody>
@ -175,187 +175,171 @@
</script>
<script>
// $(document).ready(function () {
var groups = @json($attributeFamily->attribute_groups);
var attributes = @json($attributes);
var groups = @json($attributeFamily->attribute_groups);
var attributes = @json($attributes);
Vue.component('group-form', {
Vue.component('group-form', {
data: () => ({
group: {
'groupName': '',
'position': '',
'attributes': []
}
}),
template: '#group-form-template',
methods: {
addGroup (formScope) {
this.$validator.validateAll(formScope).then((result) => {
if (result) {
var this_this = this;
var filteredGroups = groups.filter(function(group) {
return this_this.group.groupName.trim() === (group.name ? group.name.trim() : group.groupName.trim())
})
if(filteredGroups.length) {
const field = this.$validator.fields.find({ name: 'groupName', scope: 'add-group-form' });
if (field) {
this.$validator.errors.add({
id: field.id,
field: 'groupName',
msg: "{{ __('admin::app.catalog.families.group-exist-error') }}",
scope: 'add-group-form',
});
}
} else {
groups.push(this.group);
groups = this.sortGroups();
this.group = {'groupName': '', 'position': '', 'attributes': []};
this.$parent.closeModal();
}
}
});
},
sortGroups () {
return groups.sort(function(a, b) {
return a.position - b.position;
});
}
data: () => ({
group: {
'groupName': '',
'position': '',
'attributes': []
}
});
}),
Vue.component('group-list', {
template: '#group-form-template',
template: '#group-list-template',
methods: {
addGroup (formScope) {
this.$validator.validateAll(formScope).then((result) => {
if (result) {
var this_this = this;
data: () => ({
groups: groups,
attributes: attributes
}),
var filteredGroups = groups.filter(function(group) {
return this_this.group.groupName.trim() === (group.name ? group.name.trim() : group.groupName.trim())
})
created () {
this.groups.forEach(function(group) {
group.attributes.forEach(function(attribute) {
var attribute = this.attributes.filter(attributeTemp => attributeTemp.id == attribute.id)
if(filteredGroups.length) {
const field = this.$validator.fields.find({ name: 'groupName', scope: 'add-group-form' });
if(attribute.length) {
let index = this.attributes.indexOf(attribute[0])
if (field) {
this.$validator.errors.add({
id: field.id,
field: 'groupName',
msg: "{{ __('admin::app.catalog.families.group-exist-error') }}",
scope: 'add-group-form',
});
}
} else {
groups.push(this.group);
this.attributes.splice(index, 1)
groups = this.sortGroups();
this.group = {'groupName': '', 'position': '', 'attributes': []};
this.$parent.closeModal();
}
});
}
});
},
methods: {
removeGroup (group) {
group.attributes.forEach(function(attribute) {
this.attributes.push(attribute);
})
sortGroups () {
return groups.sort(function(a, b) {
return a.position - b.position;
});
}
}
});
this.attributes = this.sortAttributes();
Vue.component('group-list', {
let index = groups.indexOf(group)
template: '#group-list-template',
groups.splice(index, 1)
},
data: () => ({
groups: groups,
attributes: attributes
}),
addAttributes (groupIndex, attributeIds) {
attributeIds.forEach(function(attributeId) {
var attribute = this.attributes.filter(attribute => attribute.id == attributeId)
this.groups[groupIndex].attributes.push(attribute[0]);
created () {
this.groups.forEach(function(group) {
group.attributes.forEach(function(attribute) {
var attribute = this.attributes.filter(attributeTemp => attributeTemp.id == attribute.id)
if(attribute.length) {
let index = this.attributes.indexOf(attribute[0])
this.attributes.splice(index, 1)
})
},
}
removeAttribute (groupIndex, attribute) {
let index = this.groups[groupIndex].attributes.indexOf(attribute)
this.groups[groupIndex].attributes.splice(index, 1)
});
});
},
methods: {
removeGroup (group) {
group.attributes.forEach(function(attribute) {
this.attributes.push(attribute);
})
this.attributes = this.sortAttributes();
},
this.attributes = this.sortAttributes();
sortAttributes () {
return this.attributes.sort(function(a, b) {
return a.id - b.id;
});
}
}
})
let index = groups.indexOf(group)
Vue.component('group-item', {
props: ['index', 'group', 'attributes'],
template: "#group-item-template",
computed: {
groupInputName () {
if(this.group.id)
return "attribute_groups[" + this.group.id + "][name]";
return "attribute_groups[group_" + this.index + "][name]";
},
groupInputPosition () {
if(this.group.id)
return "attribute_groups[" + this.group.id + "][position]";
return "attribute_groups[group_" + this.index + "][position]";
},
groupAttributeInput () {
if(this.group.id)
return "attribute_groups[" + this.group.id + "][attributes][]";
return "attribute_groups[group_" + this.index + "][attributes][]";
}
groups.splice(index, 1)
},
methods: {
removeGroup () {
this.$emit('onRemoveGroup', this.group)
},
addAttributes (groupIndex, attributeIds) {
attributeIds.forEach(function(attributeId) {
var attribute = this.attributes.filter(attribute => attribute.id == attributeId)
this.groups[groupIndex].attributes.push(attribute[0]);
addAttributes (e) {
var attributeIds = [];
let index = this.attributes.indexOf(attribute[0])
$(e.target).prev().find('li input').each(function() {
var attributeId = $(this).val();
if($(this).is(':checked')) {
attributeIds.push(attributeId);
this.attributes.splice(index, 1)
})
},
$(this).prop('checked', false);
}
});
removeAttribute (groupIndex, attribute) {
let index = this.groups[groupIndex].attributes.indexOf(attribute)
$('body').trigger('click')
this.groups[groupIndex].attributes.splice(index, 1)
this.$emit('onAttributeAdd', attributeIds)
},
this.attributes.push(attribute);
removeAttribute (attribute) {
this.$emit('onAttributeRemove', attribute)
}
this.attributes = this.sortAttributes();
},
sortAttributes () {
return this.attributes.sort(function(a, b) {
return a.id - b.id;
});
}
});
// });
}
})
Vue.component('group-item', {
props: ['index', 'group', 'attributes'],
template: "#group-item-template",
computed: {
groupInputName () {
if(this.group.id)
return "attribute_groups[" + this.group.id + "]";
return "attribute_groups[group_" + this.index + "]";
}
},
methods: {
removeGroup () {
this.$emit('onRemoveGroup', this.group)
},
addAttributes (e) {
var attributeIds = [];
$(e.target).prev().find('li input').each(function() {
var attributeId = $(this).val();
if($(this).is(':checked')) {
attributeIds.push(attributeId);
$(this).prop('checked', false);
}
});
$('body').trigger('click')
this.$emit('onAttributeAdd', attributeIds)
},
removeAttribute (attribute) {
this.$emit('onAttributeRemove', attribute)
}
}
});
</script>
@stop

View File

@ -0,0 +1,21 @@
@extends('admin::layouts.content')
@section('content')
<div class="content">
<div class="page-header">
<div class="page-title">
{{ __('admin::app.catalog.products.products') }}
</div>
<div class="page-action">
<a href="{{ route('admin.catalog.products.create') }}" class="btn btn-lg btn-primary">
{{ __('admin::app.catalog.products.add-product-btn-title') }}
</a>
</div>
</div>
<div class="page-content">
</div>
</div>
@stop

View File

@ -0,0 +1,114 @@
@extends('admin::layouts.content')
@section('page_title')
{{ __('admin::app.settings.channels.edit-title') }}
@stop
@section('content')
<div class="content">
<form method="POST" action="{{ route('admin.channels.update', $channel->id) }}" @submit.prevent="onSubmit">
<div class="page-header">
<div class="page-title">
<h1>{{ __('admin::app.settings.channels.edit-title') }}</h1>
</div>
<div class="page-action">
<button type="submit" class="btn btn-lg btn-primary">
{{ __('admin::app.settings.channels.save-btn-title') }}
</button>
</div>
</div>
<div class="page-content">
<div class="form-container">
@csrf()
<input name="_method" type="hidden" value="PUT">
<accordian :title="'{{ __('admin::app.settings.channels.general') }}'" :active="true">
<div slot="body">
<div class="control-group" :class="[errors.has('code') ? 'has-error' : '']">
<label for="code" class="required">{{ __('admin::app.settings.channels.code') }}</label>
<input v-validate="'required'" class="control" id="code" name="code" value="{{ old('code') ?: $channel->code }}"/>
<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" value="{{ old('name') ?: $channel->name }}"/>
<span class="control-error" v-if="errors.has('name')">@{{ errors.first('name') }}</span>
</div>
<div class="control-group" :class="[errors.has('description') ? 'has-error' : '']">
<label for="description" class="required">{{ __('admin::app.settings.channels.description') }}</label>
<textarea class="control" id="description" name="description">{{ old('description') ?: $channel->description }}</textarea>
<span class="control-error" v-if="errors.has('description')">@{{ errors.first('description') }}</span>
</div>
</div>
</accordian>
<accordian :title="'{{ __('admin::app.settings.channels.currencies-and-locales') }}'" :active="true">
<div slot="body">
<div class="control-group" :class="[errors.has('locales[]') ? 'has-error' : '']">
<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[]" multiple>
@foreach(core()->allLocales() as $locale)
<option value="{{ $locale->id }}" {{ in_array($locale->id, $selectedOptionIds) ? 'selected' : '' }}>
{{ $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('default_locale') ? 'has-error' : '']">
<label for="default_locale" class="required">{{ __('admin::app.settings.channels.default-locale') }}</label>
<?php $selectedOption = old('default_locale') ?: $channel->default_locale ?>
<select v-validate="'required'" class="control" id="default_locale" name="default_locale">
@foreach(core()->allLocales() as $locale)
<option value="{{ $locale->id }}" {{ $selectedOption == $locale->id ? 'selected' : '' }}>
{{ $locale->name }}
</option>
@endforeach
</select>
<span class="control-error" v-if="errors.has('default_locale')">@{{ errors.first('default_locale') }}</span>
</div>
<div class="control-group" :class="[errors.has('currencies[]') ? 'has-error' : '']">
<label for="currencies" class="required">{{ __('admin::app.settings.channels.currencies') }}</label>
<?php $selectedOptionIds = old('currencies') ?: $channel->currencies->pluck('id')->toArray() ?>
<select v-validate="'required'" class="control" id="currencies" name="currencies[]" multiple>
@foreach(core()->allCurrencies() as $currency)
<option value="{{ $currency->id }}" {{ in_array($currency->id, $selectedOptionIds) ? 'selected' : '' }}>
{{ $currency->name }}
</option>
@endforeach
</select>
<span class="control-error" v-if="errors.has('currencies[]')">@{{ errors.first('currencies[]') }}</span>
</div>
<div class="control-group" :class="[errors.has('base_currency') ? 'has-error' : '']">
<label for="base_currency" class="required">{{ __('admin::app.settings.channels.base-currency') }}</label>
<?php $selectedOption = old('base_currency') ?: $channel->base_currency ?>
<select v-validate="'required'" class="control" id="base_currency" name="base_currency">
@foreach(core()->allCurrencies() as $currency)
<option value="{{ $currency->id }}" {{ $selectedOption == $currency->id ? 'selected' : '' }}>
{{ $currency->name }}
</option>
@endforeach
</select>
<span class="control-error" v-if="errors.has('base_currency')">@{{ errors.first('base_currency') }}</span>
</div>
</div>
</accordian>
</div>
</div>
</form>
</div>
@stop

View File

@ -20,7 +20,7 @@ class CreateAttributesTable extends Migration
$table->string('type');
$table->string('validation')->nullable();
$table->integer('position')->nullable();
$table->boolean('is_required')->default(1);
$table->boolean('is_required')->default(0);
$table->boolean('is_unique')->default(0);
$table->boolean('value_per_locale')->default(0);
$table->boolean('value_per_channel')->default(0);

View File

@ -18,10 +18,7 @@ class CreateAttributeFamiliesTable extends Migration
$table->string('code');
$table->string('name');
$table->boolean('status')->default(0);
});
Schema::table('attribute_groups', function($table) {
$table->foreign('attribute_family_id')->references('id')->on('attribute_families')->onDelete('cascade');
$table->boolean('is_user_defined')->default(1);
});
}

View File

@ -16,15 +16,17 @@ class CreateAttributeGroupsTable extends Migration
Schema::create('attribute_groups', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->timestamps();
$table->integer('position');
$table->boolean('is_user_defined')->default(1);
$table->integer('attribute_family_id')->unsigned();
$table->unique(['attribute_family_id', 'name']);
$table->foreign('attribute_family_id')->references('id')->on('attribute_families')->onDelete('cascade');
});
Schema::create('attribute_group_mappings', function (Blueprint $table) {
$table->integer('attribute_id')->unsigned();
$table->integer('attribute_group_id')->unsigned();
$table->integer('position')->nullable();
$table->primary(['attribute_id', 'attribute_group_id']);
$table->foreign('attribute_id')->references('id')->on('attributes')->onDelete('cascade');
$table->foreign('attribute_group_id')->references('id')->on('attribute_groups')->onDelete('cascade');

View File

@ -15,7 +15,7 @@ class CreateAttributeOptionsTable extends Migration
{
Schema::create('attribute_options', function (Blueprint $table) {
$table->increments('id');
$table->integer('sort_order');
$table->integer('sort_order')->nullable();
$table->integer('attribute_id')->unsigned();
$table->foreign('attribute_id')->references('id')->on('attributes')->onDelete('cascade');
});

View File

@ -0,0 +1,140 @@
<?php
namespace Webkul\Attribute\Database\Seeders;
use Illuminate\Database\Seeder;
use Webkul\Attribute\Repositories\AttributeFamilyRepository;
class AttributeFamilyTableSeeder extends Seeder
{
/**
* @var array
*/
protected $rawData = [
[
"code" => "default",
"name" => "Default",
"is_user_defined" => 0,
'attribute_groups' => [
[
"name" => "General",
"is_user_defined" => 0,
"position" => 1,
"attributes" => [
[
'code' => 'name',
'position' => 1
], [
'code' => 'url_key',
'position' => 2
], [
'code' => 'new_from',
'position' => 3
], [
'code' => 'new_to',
'position' => 4
], [
'code' => 'status',
'position' => 5
]
]
], [
"name" => "Description",
"is_user_defined" => 0,
"position" => 2,
"attributes" => [
[
'code' => 'short_description',
'position' => 1
], [
'code' => 'description',
'position' => 2
]
]
], [
"name" => "Meta Description",
"is_user_defined" => 0,
"position" => 3,
"attributes" => [
[
'code' => 'meta_title',
'position' => 1
], [
'code' => 'meta_keywords',
'position' => 2
], [
'code' => 'meta_description',
'position' => 3
]
]
], [
"name" => "Price",
"is_user_defined" => 0,
"position" => 4,
"attributes" => [
[
'code' => 'price',
'position' => 1
], [
'code' => 'cost',
'position' => 2
], [
'code' => 'special_price',
'position' => 3
], [
'code' => 'special_price_from',
'position' => 4
], [
'code' => 'special_price_to',
'position' => 5
]
]
], [
"name" => "Shipping",
"is_user_defined" => 0,
"position" => 5,
"attributes" => [
[
'code' => 'width',
'position' => 1
], [
'code' => 'height',
'position' => 2
], [
'code' => 'depth',
'position' => 3
], [
'code' => 'weight',
'position' => 4
]
]
]
]
]
];
/**
* AttributeFamilyRepository object
*
* @var array
*/
protected $attributeFamily;
/**
* Create a new controller instance.
*
* @param Webkul\Attribute\Repositories\AttributeFamilyRepository $attributeFamily
* @return void
*/
public function __construct(AttributeFamilyRepository $attributeFamily)
{
$this->attributeFamily = $attributeFamily;
}
public function run()
{
foreach($this->rawData as $row) {
$this->attributeFamily->create($row);
}
}
}

View File

@ -0,0 +1,391 @@
<?php
namespace Webkul\Attribute\Database\Seeders;
use Illuminate\Database\Seeder;
use Webkul\Attribute\Repositories\AttributeRepository;
class AttributeTableSeeder extends Seeder
{
/**
* @var array
*/
protected $rawData = [
[
'code' => 'name',
'admin_name' => 'Name',
'en' => [
'name' => 'Name'
],
'type' => 'text',
'position' => 1,
'is_required' => 1,
'value_per_locale' => 1,
'value_per_channel' => 1,
'is_filterable' => 1,
'is_configurable' => 0,
'is_user_defined' => 0
], [
'code' => 'url_key',
'admin_name' => 'URL Key',
'en' => [
'name' => 'URL Key'
],
'type' => 'text',
'position' => 2,
'is_unique' => 1,
'is_required' => 1,
'value_per_locale' => 0,
'value_per_channel' => 0,
'is_filterable' => 0,
'is_configurable' => 0,
'is_user_defined' => 0
], [
'code' => 'new_from',
'admin_name' => 'New From',
'en' => [
'name' => 'New From'
],
'type' => 'datetime',
'position' => 3,
'is_required' => 0,
'value_per_locale' => 0,
'value_per_channel' => 0,
'is_filterable' => 0,
'is_configurable' => 0,
'is_user_defined' => 0
], [
'code' => 'new_to',
'admin_name' => 'New To',
'en' => [
'name' => 'New To'
],
'type' => 'datetime',
'position' => 4,
'is_required' => 0,
'value_per_locale' => 0,
'value_per_channel' => 0,
'is_filterable' => 0,
'is_configurable' => 0,
'is_user_defined' => 0
], [
'code' => 'status',
'admin_name' => 'Status',
'en' => [
'name' => 'Status'
],
'type' => 'boolean',
'position' => 5,
'is_required' => 1,
'value_per_locale' => 0,
'value_per_channel' => 0,
'is_filterable' => 0,
'is_configurable' => 0,
'is_user_defined' => 0
], [
'code' => 'short_description',
'admin_name' => 'Short Description',
'en' => [
'name' => 'Short Description'
],
'type' => 'textarea',
'position' => 6,
'is_required' => 1,
'value_per_locale' => 1,
'value_per_channel' => 1,
'is_filterable' => 0,
'is_configurable' => 0,
'is_user_defined' => 0
], [
'code' => 'description',
'admin_name' => 'Description',
'en' => [
'name' => 'Description'
],
'type' => 'textarea',
'position' => 7,
'is_required' => 1,
'value_per_locale' => 1,
'value_per_channel' => 1,
'is_filterable' => 0,
'is_configurable' => 0,
'is_user_defined' => 0
], [
'code' => 'price',
'admin_name' => 'Price',
'en' => [
'name' => 'Price'
],
'type' => 'price',
'position' => 8,
'is_required' => 1,
'value_per_locale' => 0,
'value_per_channel' => 0,
'is_filterable' => 1,
'is_configurable' => 0,
'is_user_defined' => 0
], [
'code' => 'cost',
'admin_name' => 'Cost',
'en' => [
'name' => 'Cost'
],
'type' => 'price',
'position' => 9,
'is_required' => 0,
'value_per_locale' => 0,
'value_per_channel' => 0,
'is_filterable' => 0,
'is_configurable' => 0,
'is_user_defined' => 1
], [
'code' => 'special_price',
'admin_name' => 'Special Price',
'en' => [
'name' => 'Special Price'
],
'type' => 'price',
'position' => 10,
'is_required' => 0,
'value_per_locale' => 0,
'value_per_channel' => 0,
'is_filterable' => 0,
'is_configurable' => 0,
'is_user_defined' => 0
], [
'code' => 'special_price_from',
'admin_name' => 'Special Price From',
'en' => [
'name' => 'Special Price From'
],
'type' => 'datetime',
'position' => 11,
'is_required' => 0,
'value_per_locale' => 0,
'value_per_channel' => 0,
'is_filterable' => 0,
'is_configurable' => 0,
'is_user_defined' => 0
], [
'code' => 'special_price_to',
'admin_name' => 'Special Price To',
'en' => [
'name' => 'Special Price To'
],
'type' => 'datetime',
'position' => 12,
'is_required' => 0,
'value_per_locale' => 0,
'value_per_channel' => 0,
'is_filterable' => 0,
'is_configurable' => 0,
'is_user_defined' => 0
], [
'code' => 'meta_title',
'admin_name' => 'Meta Title',
'en' => [
'name' => 'Meta Description'
],
'type' => 'textarea',
'position' => 13,
'is_required' => 0,
'value_per_locale' => 1,
'value_per_channel' => 1,
'is_filterable' => 0,
'is_configurable' => 0,
'is_user_defined' => 0
], [
'code' => 'meta_keywords',
'admin_name' => 'Meta Keywords',
'en' => [
'name' => 'Meta Keywords'
],
'type' => 'textarea',
'position' => 14,
'is_required' => 0,
'value_per_locale' => 1,
'value_per_channel' => 1,
'is_filterable' => 0,
'is_configurable' => 0,
'is_user_defined' => 0
], [
'code' => 'meta_description',
'admin_name' => 'Meta Description',
'en' => [
'name' => 'Meta Description'
],
'type' => 'textarea',
'position' => 15,
'is_required' => 0,
'value_per_locale' => 1,
'value_per_channel' => 1,
'is_filterable' => 0,
'is_configurable' => 0,
'is_user_defined' => 1
], [
'code' => 'width',
'admin_name' => 'Width',
'en' => [
'name' => 'Width'
],
'type' => 'text',
'validation' => 'number',
'position' => 16,
'is_required' => 0,
'value_per_locale' => 0,
'value_per_channel' => 0,
'is_filterable' => 0,
'is_configurable' => 0,
'is_user_defined' => 1
], [
'code' => 'height',
'admin_name' => 'Height',
'en' => [
'name' => 'Height'
],
'type' => 'text',
'validation' => 'number',
'position' => 17,
'is_required' => 0,
'value_per_locale' => 0,
'value_per_channel' => 0,
'is_filterable' => 0,
'is_configurable' => 0,
'is_user_defined' => 1
], [
'code' => 'depth',
'admin_name' => 'Depth',
'en' => [
'name' => 'Depth'
],
'type' => 'text',
'validation' => 'number',
'position' => 18,
'is_required' => 0,
'value_per_locale' => 0,
'value_per_channel' => 0,
'is_filterable' => 0,
'is_configurable' => 0,
'is_user_defined' => 1
], [
'code' => 'weight',
'admin_name' => 'Weight',
'en' => [
'name' => 'Weight'
],
'type' => 'text',
'validation' => 'number',
'position' => 19,
'is_required' => 1,
'value_per_locale' => 0,
'value_per_channel' => 0,
'is_filterable' => 0,
'is_configurable' => 0,
'is_user_defined' => 0
], [
'code' => 'color',
'admin_name' => 'Color',
'en' => [
'name' => 'Color'
],
'type' => 'select',
'position' => 20,
'is_required' => 0,
'value_per_locale' => 0,
'value_per_channel' => 0,
'is_filterable' => 1,
'is_configurable' => 1,
'is_user_defined' => 1,
'options' => [
[
'en' => [
'label' => 'Red'
],
'sort_order' => 1
], [
'en' => [
'label' => 'Green'
],
'sort_order' => 2
], [
'en' => [
'label' => 'Yellow'
],
'sort_order' => 3
], [
'en' => [
'label' => 'Black'
],
'sort_order' => 4
], [
'en' => [
'label' => 'White'
],
'sort_order' => 5
]
]
], [
'code' => 'size',
'admin_name' => 'Size',
'en' => [
'name' => 'Size'
],
'type' => 'select',
'position' => 21,
'is_required' => 0,
'value_per_locale' => 0,
'value_per_channel' => 0,
'is_filterable' => 1,
'is_configurable' => 1,
'is_user_defined' => 1,
'options' => [
[
'en' => [
'label' => 'S'
],
'sort_order' => 1
], [
'en' => [
'label' => 'M'
],
'sort_order' => 2
], [
'en' => [
'label' => 'L'
],
'sort_order' => 3
], [
'en' => [
'label' => 'XL'
],
'sort_order' => 4
]
]
]
];
/**
* AttributeRepository object
*
* @var array
*/
protected $attribute;
/**
* Create a new controller instance.
*
* @param Webkul\Attribute\Repositories\AttributeRepository $attribute
* @return void
*/
public function __construct(AttributeRepository $attribute)
{
$this->attribute = $attribute;
}
public function run()
{
foreach($this->rawData as $row) {
$this->attribute->create($row);
}
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Webkul\Attribute\Database\Seeders;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
$this->call(AttributeTableSeeder::class);
$this->call(AttributeFamilyTableSeeder::class);
}
}

View File

@ -61,9 +61,11 @@ class AttributeFamilyController extends Controller
*/
public function create(Attribute $attribute)
{
$attributeFamily = $this->attributeFamily->findBy('code', 'default', ['*'], ['attribute_groups.attributes']);
$attributes = $attribute->all(['id', 'code', 'admin_name', 'type']);
return view($this->_config['view'], compact('attributes'));
return view($this->_config['view'], compact('attributes', 'attributeFamily'));
}
/**

View File

@ -9,7 +9,7 @@ class Attribute extends TranslatableModel
{
public $translatedAttributes = ['name'];
protected $fillable = ['code', 'admin_name', 'type', 'is_required', 'is_unique', 'value_per_locale', 'value_per_channel', 'is_filterable', 'is_configurable'];
protected $fillable = ['code', 'admin_name', 'type', 'position', 'is_required', 'is_unique', 'value_per_locale', 'value_per_channel', 'is_filterable', 'is_configurable'];
/**
* Get the options.

View File

@ -25,6 +25,6 @@ class AttributeFamily extends Model
*/
public function attribute_groups()
{
return $this->hasMany(AttributeGroup::class);
return $this->hasMany(AttributeGroup::class)->orderBy('position');
}
}

View File

@ -9,13 +9,15 @@ class AttributeGroup extends Model
{
public $timestamps = false;
protected $fillable = ['name', 'position'];
protected $fillable = ['name', 'position', 'is_user_defined'];
/**
* Get the attributes that owns the attribute group.
*/
public function attributes()
{
return $this->belongsToMany(Attribute::class, 'attribute_group_mappings');
return $this->belongsToMany(Attribute::class, 'attribute_group_mappings')
->withPivot('position')
->orderBy('pivot_position', 'asc');
}
}

View File

@ -3,7 +3,6 @@
namespace Webkul\Attribute\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\AliasLoader;
use Illuminate\Routing\Router;
class AttributeServiceProvider extends ServiceProvider

View File

@ -3,6 +3,7 @@
namespace Webkul\Attribute\Repositories;
use Webkul\Core\Eloquent\Repository;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Attribute\Repositories\AttributeGroupRepository;
use Illuminate\Container\Container as App;
@ -14,6 +15,13 @@ use Illuminate\Container\Container as App;
*/
class AttributeFamilyRepository extends Repository
{
/**
* AttributeRepository object
*
* @var array
*/
protected $attribute;
/**
* AttributeGroupRepository object
*
@ -24,11 +32,14 @@ class AttributeFamilyRepository extends Repository
/**
* Create a new controller instance.
*
* @param Webkul\Attribute\Repositories\AttributeGroupRepository $attributeGroup
* @param Webkul\Attribute\Repositories\AttributeRepository $attribute
* @param Webkul\Attribute\Repositories\AttributeGroupRepository $attributeGroup
* @return void
*/
public function __construct(AttributeGroupRepository $attributeGroup, App $app)
public function __construct(AttributeRepository $attribute, AttributeGroupRepository $attributeGroup, App $app)
{
$this->attribute = $attribute;
$this->attributeGroup = $attributeGroup;
parent::__construct($app);
@ -50,16 +61,21 @@ class AttributeFamilyRepository extends Repository
*/
public function create(array $data)
{
$attributeGroups = isset($data['attribute_groups']) ? $data['attribute_groups'] : [];
unset($data['attribute_groups']);
$family = $this->model->create($data);
if(isset($data['attribute_groups'])) {
foreach ($data['attribute_groups'] as $group) {
$attributeGroup = $family->attribute_groups()->create($group);
foreach ($attributeGroups as $group) {
$attributes = isset($group['attributes']) ? $group['attributes'] : [];
unset($group['attributes']);
$attributeGroup = $family->attribute_groups()->create($group);
if(isset($group['attributes'])) {
foreach ($group['attributes'] as $attributeId) {
$attributeGroup->attributes()->attach($attributeId);
}
foreach ($attributes as $attribute) {
if(isset($attribute['id'])) {
$attributeGroup->attributes()->attach($attribute['id']);
} else {
$attributeModel = $this->attribute->findBy('code', $attribute['code']);
$attributeGroup->attributes()->save($attributeModel, ['position' => $attribute['position']]);
}
}
}
@ -87,28 +103,32 @@ class AttributeFamilyRepository extends Repository
$attributeGroup = $family->attribute_groups()->create($attributeGroupInputs);
if(isset($attributeGroupInputs['attributes'])) {
foreach ($attributeGroupInputs['attributes'] as $attributeId) {
$attributeGroup->attributes()->attach($attributeId);
foreach ($attributeGroupInputs['attributes'] as $attribute) {
$attributeGroup->attributes()->attach($attribute['id']);
}
}
} else {
if(($index = $previousAttributeGroupIds->search($attributeGroupId)) >= 0) {
if(is_numeric($index = $previousAttributeGroupIds->search($attributeGroupId))) {
$previousAttributeGroupIds->forget($index);
}
$attributeGroup = $this->attributeGroup->findOrFail($attributeGroupId);
$attributeGroup->update($attributeGroupInputs);
$attributeIds = $attributeGroup->attributes()->get()->pluck('id');
$attributeIds = $attributeGroup->attributes()->pluck('id');
foreach ($attributeGroupInputs['attributes'] as $attributeId) {
if(($index = $attributeIds->search($attributeId)) >= 0) {
$attributeIds->forget($index);
if(isset($attributeGroupInputs['attributes'])) {
foreach ($attributeGroupInputs['attributes'] as $attribute) {
if(is_numeric($index = $attributeIds->search($attribute['id']))) {
$attributeIds->forget($index);
} else {
$attributeGroup->attributes()->attach($attribute['id']);
}
}
}
foreach ($attributeIds as $attributeId) {
$attributeGroup->deattach($attributeId);
if($attributeIds->count()) {
$attributeGroup->detach($attributeIds);
}
}
}

View File

@ -50,10 +50,12 @@ class AttributeRepository extends Repository
*/
public function create(array $data)
{
$options = isset($data['options']) ? $data['options'] : [];
unset($data['options']);
$attribute = $this->model->create($data);
if(in_array($attribute->code, ['select', 'multiselect', 'checkbox']) && isset($data['options'])) {
foreach ($data['options'] as $key => $option) {
if(in_array($attribute->type, ['select', 'multiselect', 'checkbox']) && count($options)) {
foreach ($options as $option) {
$attribute->options()->create($option);
}
}
@ -81,7 +83,7 @@ class AttributeRepository extends Repository
if (str_contains($optionId, 'option_')) {
$attribute->options()->create($optionInputs);
} else {
if(($index = $previousOptionIds->search($optionId)) >= 0) {
if(is_numeric($index = $previousOptionIds->search($optionId))) {
$previousOptionIds->forget($index);
}

View File

@ -22,11 +22,9 @@ class CreateCategoryTranslationsTable extends Migration
$table->text('meta_description')->nullable();
$table->text('meta_keywords')->nullable();
$table->integer('category_id')->unsigned();
$table->integer('locale_id')->unsigned();
$table->unique(['category_id', 'locale_id']);
$table->unique(['category_id', 'slug', 'locale_id']);
$table->string('locale');
$table->unique(['category_id', 'slug', 'locale']);
$table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
$table->foreign('locale_id')->references('id')->on('channel_locales')->onDelete('cascade');
});
}

View File

@ -6,7 +6,6 @@ use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Webkul\Category\Repositories\CategoryRepository as Category;
/**
* Catalog category controller
*
@ -59,7 +58,7 @@ class CategoryController extends Controller
*/
public function create()
{
$categories = $this->category->getCategoryTree();
$categories = $this->category->getCategoryTree(null, ['id']);
return view($this->_config['view'], compact('categories'));
}
@ -107,7 +106,7 @@ class CategoryController extends Controller
*/
public function update(Request $request, $id)
{
$locale = request()->get('channel_locale') ?: channel()->getDefaultChannelLocale()->id;
$locale = request()->get('channel_locale') ?: channel()->getDefaultChannelLocaleCode();
$this->validate(request(), [
$locale . '.slug' => ['required', new \Webkul\Core\Contracts\Validations\Slug, function ($attribute, $value, $fail) use ($id) {
if (!$this->category->isSlugUnique($id, $value)) {

View File

@ -14,10 +14,10 @@ class Category extends TranslatableModel
protected $fillable = ['position', 'status', 'parent_id'];
/**
* @return string
* @return boolean
*/
public function getLocaleKey()
protected function isChannelBased()
{
return 'locale_id';
return true;
}
}

View File

@ -4,7 +4,6 @@ namespace Webkul\Category\Repositories;
use Webkul\Core\Eloquent\Repository;
use Webkul\Category\Models\Category;
use Webkul\Channel\Repositories\ChannelLocaleRepository;
use Illuminate\Container\Container as App;
use Webkul\Category\Models\CategoryTranslation;
@ -16,24 +15,13 @@ use Webkul\Category\Models\CategoryTranslation;
*/
class CategoryRepository extends Repository
{
/**
* ChannelLocaleRepository object
*
* @var array
*/
protected $locale;
/**
* Create a new controller instance.
*
* @param Webkul\Core\Repositories\ChannelLocaleRepository $locale
* @return void
*/
public function __construct(ChannelLocaleRepository $locale, App $app)
public function __construct(App $app)
{
$this->locale = $locale;
parent::__construct($app);
}
@ -56,10 +44,14 @@ class CategoryRepository extends Repository
if(isset($data['locale']) && $data['locale'] == 'all') {
$model = app()->make($this->model());
foreach($this->locale->all() as $locale) {
foreach ($model->translatedAttributes as $attribute) {
if(isset($data[$attribute])) {
$data[$locale->id][$attribute] = $data[$attribute];
$channels = channel()->getChannelWithLocales();
foreach($channels as $channel) {
foreach($channel->locales as $locale) {
foreach ($model->translatedAttributes as $attribute) {
if(isset($data[$attribute])) {
$data[$channel->code . '.' . $locale->code][$attribute] = $data[$attribute];
}
}
}
}

View File

@ -6,9 +6,22 @@ use Webkul\Channel\Models\Channel as ChannelModel;
class Channel
{
public function getDefaultChannelLocaleCode() {
$channel = ChannelModel::first();
if(!$channel || !$channel->locales()->count())
return;
return $channel->code . '-' . $channel->locales()->first()->code;
}
public function getDefaultChannelLocale() {
$channel = ChannelModel::first();
return $channel->channel_locales()->first();
return $channel->locales()->first();
}
public function getChannelWithLocales() {
return ChannelModel::with('locales')->get();
}
}

View File

@ -25,6 +25,14 @@ class CreateChannelsTable extends Migration
$table->timestamps();
});
Schema::create('channel_locales', function (Blueprint $table) {
$table->integer('channel_id')->unsigned();
$table->integer('locale_id')->unsigned();
$table->primary(['channel_id', 'locale_id']);
$table->foreign('channel_id')->references('id')->on('channels')->onDelete('cascade');
$table->foreign('locale_id')->references('id')->on('locales')->onDelete('cascade');
});
Schema::create('channel_currencies', function (Blueprint $table) {
$table->integer('channel_id')->unsigned();
$table->integer('currency_id')->unsigned();

View File

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

View File

@ -94,7 +94,7 @@ class ChannelController extends Controller
*/
public function edit($id)
{
$channel = $this->channel->findOrFail($id);
$channel = $this->channel->findOrFail($id, ['*'], ['locales', 'currencies']);
return view($this->_config['view'], compact('channel'));
}

View File

@ -3,7 +3,6 @@
namespace Webkul\Channel\Models;
use Illuminate\Database\Eloquent\Model;
use Webkul\Channel\Models\ChannelLocale;
use Webkul\Core\Models\Locale;
use Webkul\Core\Models\Currency;
@ -14,9 +13,9 @@ class Channel extends Model
/**
* Get the channel locales.
*/
public function channel_locales()
public function locales()
{
return $this->hasMany(ChannelLocale::class);
return $this->belongsToMany(Locale::class, 'channel_locales');
}
/**

View File

@ -1,17 +0,0 @@
<?php
namespace Webkul\Channel\Models;
use Illuminate\Database\Eloquent\Model;
use Webkul\Core\Models\Locale;
class ChannelLocale extends Model
{
/**
* Get the locale
*/
public function locale()
{
return $this->belongsTo(Locale::class);
}
}

View File

@ -30,12 +30,54 @@ class ChannelRepository extends Repository
{
$channel = $this->model->create($data);
foreach ($data['locales'] as $group) {
foreach ($data['locales'] as $locale) {
$channel->locales()->attach($locale);
}
foreach ($data['currencies'] as $group) {
foreach ($data['currencies'] as $currency) {
$channel->currencies()->attach($currency);
}
return $channel;
}
/**
* @param array $data
* @param $id
* @param string $attribute
* @return mixed
*/
public function update(array $data, $id, $attribute = "id")
{
$channel = $this->findOrFail($id);
$channel->update($data);
$previousLocaleIds = $channel->locales()->pluck('id');
foreach ($data['locales'] as $locale) {
if(is_numeric($index = $previousLocaleIds->search($locale))) {
$previousLocaleIds->forget($index);
} else {
$channel->locales()->attach($locale);
}
}
if($previousLocaleIds->count()) {
$channel->locales()->detach($previousLocaleIds);
}
$previousCurrencyIds = $channel->currencies()->pluck('id');
foreach ($data['currencies'] as $currency) {
if(is_numeric($index = $previousCurrencyIds->search($currency))) {
$previousCurrencyIds->forget($index);
} else {
$channel->currencies()->attach($currency);
}
}
if($previousCurrencyIds->count()) {
$channel->currencies()->detach($previousCurrencyIds);
}
return $channel;

View File

@ -5,7 +5,6 @@ namespace Webkul\Core\Eloquent;
use Illuminate\Database\Eloquent\Model;
use Dimsav\Translatable\Translatable;
use Webkul\Core\Models\Locale;
use Webkul\Channel\Models\ChannelLocale;
class TranslatableModel extends Model
{
@ -18,12 +17,12 @@ class TranslatableModel extends Model
*/
protected function isKeyALocale($key)
{
if(is_numeric($key)) {
if(ChannelLocale::find($key))
return true;
} else {
if(Locale::where('code', '=', $key)->first())
$chunks = explode('-', $key);
if(count($chunks) > 1) {
if(Locale::where('code', '=', end($chunks))->first())
return true;
} elseif(Locale::where('code', '=', $key)->first()) {
return true;
}
return false;
@ -34,6 +33,31 @@ class TranslatableModel extends Model
*/
protected function locale()
{
return channel()->getDefaultChannelLocale()->id;
if($this->isChannelBased()) {
return channel()->getDefaultChannelLocaleCode();
} else {
if ($this->defaultLocale) {
return $this->defaultLocale;
}
return config('translatable.locale')
?: app()->make('translator')->getLocale();
}
}
/**
* @return boolean
*/
protected function isChannelBased()
{
return false;
}
/**
* @return string
*/
protected function getLocaleSeparator()
{
return config('translatable.locale_separator', '%');
}
}

1
packages/Webkul/Product/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/node_modules

View File

@ -0,0 +1,27 @@
{
"name": "webkul/laravel-product",
"license": "MIT",
"authors": [
{
"name": "Jitendra Singh",
"email": "jitendra@webkul.com"
}
],
"require": {},
"autoload": {
"psr-4": {
"Webkul\\Product\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Webkul\\Product\\Providers\\ProductServiceProvider"
],
"aliases": {
"Bouncer": "Webkul\\Product\\Facades\\Bouncer"
}
}
},
"minimum-stability": "dev"
}

View File

@ -0,0 +1,13 @@
<?php
namespace Webkul\Product\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}

View File

@ -0,0 +1,125 @@
<?php
namespace Webkul\Product\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Webkul\Product\Repositories\ProductRepository as Product;
/**
* Product controller
*
* @author Jitendra Singh <jitendra@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class ProductController extends Controller
{
/**
* Contains route related configuration
*
* @var array
*/
protected $_config;
/**
* ProductRepository object
*
* @var array
*/
protected $product;
/**
* Create a new controller instance.
*
* @param Webkul\Product\Repositories\ProductRepository $product
* @return void
*/
public function __construct(Product $product)
{
$this->product = $product;
$this->_config = request('_config');
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view($this->_config['view']);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view($this->_config['view']);
}
/**
* Store a newly created resource in storage.
*
* @return \Illuminate\Http\Response
*/
public function store()
{
$this->validate(request(), [
'name' => 'required'
]);
$this->product->create(request()->all());
session()->flash('success', 'Product created successfully.');
return redirect()->route($this->_config['redirect']);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$product = $this->product->findOrFail($id);
return view($this->_config['view'], compact('product'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$this->validate(request(), [
'name' => 'required',
]);
$this->product->update(request()->all(), $id);
session()->flash('success', 'Product updated successfully.');
return redirect()->route($this->_config['redirect']);
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace Webkul\Product\Models;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected $guarded = ['_token'];
}

View File

@ -0,0 +1,29 @@
<?php
namespace Webkul\Product\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Routing\Router;
class ProductServiceProvider extends ServiceProvider
{
/**
* Bootstrap services.
*
* @return void
*/
public function boot(Router $router)
{
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
}
/**
* Register services.
*
* @return void
*/
public function register()
{
}
}

View File

@ -1,16 +1,16 @@
<?php
namespace Webkul\Channel\Repositories;
namespace Webkul\Product\Repositories;
use Webkul\Core\Eloquent\Repository;
/**
* Channel Locale Reposotory
* Product Reposotory
*
* @author Jitendra Singh <jitendra@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class ChannelLocaleRepository extends Repository
class ProductRepository extends Repository
{
/**
* Specify Model class name
@ -19,6 +19,6 @@ class ChannelLocaleRepository extends Repository
*/
function model()
{
return 'Webkul\Channel\Models\ChannelLocale';
return 'Webkul\Product\Models\Product';
}
}

View File

@ -1,15 +0,0 @@
const { mix } = require('laravel-mix');
require('laravel-mix-merge-manifest');
// var publicPath = 'publishable/assets';
var publicPath = '../../../public/vendor/webkul/core/assets';
mix.setPublicPath(publicPath).mergeManifest();
mix.disableNotifications();
mix.copyDirectory( __dirname + '/src/Resources/assets/lang', publicPath + '/lang')
if (mix.inProduction()) {
mix.version();
}