Merge pull request #10 from bagisto/master

This commit is contained in:
Glenn Hermans 2021-06-17 03:38:51 +02:00 committed by GitHub
commit 41d2eed47f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 662 additions and 563 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
{
"/js/admin.js": "/js/admin.js?id=e2c223b41f0fee5494cd",
"/js/admin.js": "/js/admin.js?id=3829c36ba5d70b31abab",
"/css/admin.css": "/css/admin.css?id=b24aa6544b82f674840f"
}

View File

@ -2,7 +2,7 @@
<div class="control-group" :class="[errors.has(name) ? 'has-error' : '']">
<label :for="name" :class="checkValidations">
{{ label }}
<span class="locale"> {{ channel_locale ? `[${channel_locale}]` : '' }} </span>
<span class="locale"> {{ channel_locale }} </span>
</label>
<select v-if="this.options.length" v-validate="checkValidations" class="control" :id = "name" :name = "name" v-model="savedValue"

View File

@ -0,0 +1,125 @@
@php
$dependField = $coreConfigRepository->getDependentFieldOrValue($field);
$dependValue = $coreConfigRepository->getDependentFieldOrValue($field, 'value');
$dependNameKey = $item['key'] . '.' . $dependField;
$dependName = $coreConfigRepository->getNameField($dependNameKey);
$field['options'] = $coreConfigRepository->getDependentFieldOptions($field, $value);
$selectedOption = core()->getConfigData($nameKey, $channel, $locale) ?? '';
$dependSelectedOption = core()->getConfigData($dependNameKey, $channel, $locale) ?? '';
@endphp
@if (strpos($field['validation'], 'required_if') !== false)
<required-if
:name = "'{{ $name }}'"
:label = "'{{ trans($field['title']) }}'"
:info = "'{{ trans(isset($field['info']) ? $field['info'] : '') }}'"
:options = '@json($field['options'])'
:result = "'{{ $selectedOption }}'"
:validations = "'{{ $validations }}'"
:depend = "'{{ $dependName }}'"
:depend-result= "'{{ $dependSelectedOption }}'"
:channel_locale = "'{{ $channelLocaleInfo }}'"
></required-if>
@else
<depends
:options = '@json($field['options'])'
:name = "'{{ $name }}'"
:validations = "'{{ $validations }}'"
:depend = "'{{ $dependName }}'"
:value = "'{{ $dependValue }}'"
:field_name = "'{{ trans($field['title']) }}'"
:channel_locale = "'{{ $channelLocaleInfo }}'"
:result = "'{{ $selectedOption }}'"
:depend-saved-value= "'{{ $dependSelectedOption }}'"
></depends>
@endif
@push('scripts')
<script type="text/x-template" id="depends-template">
<div class="control-group" :class="[errors.has(name) ? 'has-error' : '']" v-if="this.isVisible">
<label :for="name" :class="[ isRequire ? 'required' : '']">
@{{ field_name }}
<span class="locale"> @{{ channel_locale }} </span>
</label>
<select v-if="this.options.length" v-validate= "validations" class="control" :id = "name" :name = "name" v-model="savedValue"
:data-vv-as="field_name">
<option v-for='(option, index) in this.options' :value="option.value"> @{{ option.title }} </option>
</select>
<input v-else type="text" class="control" v-validate= "validations" :id = "name" :name = "name" v-model="savedValue"
:data-vv-as="field_name">
<span class="control-error" v-if="errors.has(name)">
@{{ errors.first(name) }}
</span>
</div>
</script>
<script>
Vue.component('depends', {
template: '#depends-template',
inject: ['$validator'],
props: ['options', 'name', 'validations', 'depend', 'value', 'field_name', 'channel_locale', 'repository', 'result'],
data: function() {
return {
isRequire: false,
isVisible: false,
savedValue: "",
}
},
mounted: function () {
let self = this;
self.savedValue = self.result;
if (self.validations || (self.validations.indexOf("required") != -1)) {
self.isRequire = true;
}
$(document).ready(function(){
let dependentElement = document.getElementById(self.depend);
let dependValue = self.value;
if (dependValue == 'true') {
dependValue = 1;
} else if (dependValue == 'false') {
dependValue = 0;
}
$(document).on("change", "select.control", function() {
if (self.depend == this.name) {
if (self.value == this.value) {
self.isVisible = true;
} else {
self.isVisible = false;
}
}
})
if (dependentElement && dependentElement.value == dependValue) {
self.isVisible = true;
} else {
self.isVisible = false;
}
if (self.result) {
if (dependentElement.value == self.value) {
self.isVisible = true;
} else {
self.isVisible = false;
}
}
});
}
});
</script>
@endpush

View File

@ -1,510 +1,307 @@
<?php
$validations = [];
$disabled = false;
@inject('coreConfigRepository', 'Webkul\Core\Repositories\CoreConfigRepository')
if (isset($field['validation'])) {
array_push($validations, $field['validation']);
}
@php
$nameKey = $item['key'] . '.' . $field['name'];
$validations = implode('|', array_filter($validations));
$name = $coreConfigRepository->getNameField($nameKey);
$key = $item['key'];
$key = explode(".", $key);
$firstField = current($key);
$secondField = next($key);
$thirdField = end($key);
$value = $coreConfigRepository->getValueByRepository($field);
$name = $item['key'] . '.' . $field['name'];
$validations = $coreConfigRepository->getValidations($field);
if (isset($field['repository'])) {
$temp = explode("@", $field['repository']);
$class = app(current($temp));
$method = end($temp);
$value = $class->$method();
}
$channelLocaleInfo = $coreConfigRepository->getChannelLocaleInfo($field, $channel, $locale);
@endphp
$channel_locale = [];
@if ($field['type'] == 'depends')
if (isset($field['channel_based']) && $field['channel_based'])
{
array_push($channel_locale, $channel);
}
@include('admin::configuration.dependent-field-type')
if (isset($field['locale_based']) && $field['locale_based']) {
array_push($channel_locale, $locale);
}
?>
@else
<div class="control-group {{ $field['type'] }}" @if ($field['type'] == 'multiselect') :class="[errors.has('{{ $name }}[]') ? 'has-error' : '']" @else :class="[errors.has('{{ $name }}') ? 'has-error' : '']" @endif>
@if ($field['type'] == 'depends')
<label for="{{ $name }}" {{ !isset($field['validation']) || preg_match('/\brequired\b/', $field['validation']) == false ? '' : 'class=required' }}>
<?php
{{ trans($field['title']) }}
$depends = explode(":", $field['depend']);
$dependField = current($depends);
$dependValue = end($depends);
<span class="locale">{{ $channelLocaleInfo }}</span>
if (count($channel_locale)) {
$channel_locale = implode(' - ', $channel_locale);
} else {
$channel_locale = '';
}
if (isset($value) && $value) {
$i = 0;
foreach ($value as $key => $result) {
$data['title'] = $result;
$data['value'] = $key;
$options[$i] = $data;
$i++;
}
$field['options'] = $options;
}
if (! isset($field['options'])) {
$field['options'] = '';
}
$selectedOption = core()->getConfigData($name, $channel, $locale) ?? '';
$dependSelectedOption = core()->getConfigData(implode('.', [$firstField, $secondField, $thirdField, $dependField]), $channel, $locale) ?? '';
?>
@if (strpos($field['validation'], 'required_if') !== false)
<required-if
:name = "'{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]'"
:label = "'{{ trans($field['title']) }}'"
:info = "'{{ trans(isset($field['info']) ? $field['info'] : '') }}'"
:options = '@json($field['options'])'
:result = "'{{ $selectedOption }}'"
:validations = "'{{ $validations }}'"
:depend = "'{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $dependField }}]'"
:depend-result= "'{{ $dependSelectedOption }}'"
:channel_locale = "'{{ $channel_locale }}'"
></required-if>
@else
<depends
:options = '@json($field['options'])'
:name = "'{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]'"
:validations = "'{{ $validations }}'"
:depend = "'{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $dependField }}]'"
:value = "'{{ $dependValue }}'"
:field_name = "'{{ trans($field['title']) }}'"
:channel_locale = "'{{ $channel_locale }}'"
:result = "'{{ $selectedOption }}'"
:depend-saved-value= "'{{ $dependSelectedOption }}'"
></depends>
@endif
@else
<div class="control-group {{ $field['type'] }}" @if ($field['type'] == 'multiselect') :class="[errors.has('{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}][]') ? 'has-error' : '']" @else :class="[errors.has('{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]') ? 'has-error' : '']" @endif>
<label for="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" {{ !isset($field['validation']) || preg_match('/\brequired\b/', $field['validation']) == false ? '' : 'class=required' }}>
{{ trans($field['title']) }}
@if (count($channel_locale))
<span class="locale">[{{ implode(' - ', $channel_locale) }}]</span>
@endif
</label>
@if ($field['type'] == 'text')
<input type="text" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: (core()->getConfigData($name, $channel, $locale) ? core()->getConfigData($name, $channel, $locale) : (isset($field['default_value']) ? $field['default_value'] : '')) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;">
@elseif ($field['type'] == 'password')
<input type="password" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name, $channel, $locale) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;">
@elseif ($field['type'] == 'number')
<input type="number" min="0" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name, $channel, $locale) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;">
@elseif ($field['type'] == 'color')
<input type="color" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name, $channel, $locale) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;">
@elseif ($field['type'] == 'textarea')
<textarea v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" data-vv-as="&quot;{{ trans($field['title']) }}&quot;">{{ old($name) ?: core()->getConfigData($name, $channel, $locale) ?: (isset($field['default_value']) ? $field['default_value'] : '') }}</textarea>
@elseif ($field['type'] == 'select')
<select v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" data-vv-as="&quot;{{ trans($field['title']) }}&quot;" >
<?php
$selectedOption = core()->getConfigData($name, $channel, $locale) ?? '';
?>
@if (isset($field['repository']))
@foreach ($value as $key => $option)
<option value="{{ $key }}" {{ $key == $selectedOption ? 'selected' : ''}}>
{{ trans($option) }}
</option>
@endforeach
@else
@foreach ($field['options'] as $option)
<?php
if (! isset($option['value'])) {
$value = null;
} else {
$value = $option['value'];
if (! $value) {
$value = 0;
}
}
?>
<option value="{{ $value }}" {{ $value == $selectedOption ? 'selected' : ''}}>
{{ trans($option['title']) }}
</option>
@endforeach
@endif
</select>
@elseif ($field['type'] == 'multiselect')
<select v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}][]" data-vv-as="&quot;{{ trans($field['title']) }}&quot;" multiple>
<?php
$selectedOption = core()->getConfigData($name, $channel, $locale) ?? '';
?>
@if (isset($field['repository']))
@foreach ($value as $key => $option)
<option value="{{ $key }}" {{ in_array($key, explode(',', $selectedOption)) ? 'selected' : ''}}>
{{ trans($value[$key]) }}
</option>
@endforeach
@else
@foreach ($field['options'] as $option)
<?php
if (! isset($option['value'])) {
$value = null;
} else {
$value = $option['value'];
if (! $value) {
$value = 0;
}
}
?>
<option value="{{ $value }}" {{ in_array($option['value'], explode(',', $selectedOption)) ? 'selected' : ''}}>
{{ trans($option['title']) }}
</option>
@endforeach
@endif
</select>
@elseif ($field['type'] == 'country')
<?php
$countryCode = core()->getConfigData($name, $channel, $locale) ?? '';
?>
<country
:country_code = "'{{ $countryCode }}'"
:validations = "'{{ $validations }}'"
:name = "'{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]'"
></country>
@elseif ($field['type'] == 'state')
<?php
$stateCode = core()->getConfigData($name, $channel, $locale) ?? '';
?>
<state
:state_code = "'{{ $stateCode }}'"
:validations = "'{{ $validations }}'"
:name = "'{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]'"
></state>
@elseif ($field['type'] == 'boolean')
<?php $selectedOption = core()->getConfigData($name, $channel, $locale) ?? (isset($field['default_value']) ? $field['default_value'] : ''); ?>
<label class="switch">
<input type="hidden" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="0" />
<input type="checkbox" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="1" {{ $selectedOption ? 'checked' : '' }}>
<span class="slider round"></span>
</label>
@elseif ($field['type'] == 'image')
<?php
$src = Storage::url(core()->getConfigData($name, $channel, $locale));
$result = core()->getConfigData($name, $channel, $locale);
?>
@if ($result)
<a href="{{ $src }}" target="_blank">
<img src="{{ $src }}" class="configuration-image"/>
</a>
@endif
<input type="file" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name, $channel, $locale) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;" style="padding-top: 5px;">
@if ($result)
<div class="control-group" style="margin-top: 5px;">
<span class="checkbox">
<input type="checkbox" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}][delete]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}][delete]" value="1">
<label class="checkbox-view" for="delete"></label>
{{ __('admin::app.configuration.delete') }}
</span>
</div>
@endif
@elseif ($field['type'] == 'file')
<?php
$result = core()->getConfigData($name, $channel, $locale);
$src = explode("/", $result);
$path = end($src);
?>
@if ($result)
<a href="{{ route('admin.configuration.download', [request()->route('slug'), request()->route('slug2'), $path]) }}">
<i class="icon sort-down-icon download"></i>
</a>
@endif
<input type="file" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name, $channel, $locale) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;" style="padding-top: 5px;">
@if ($result)
<div class="control-group" style="margin-top: 5px;">
<span class="checkbox">
<input type="checkbox" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}][delete]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}][delete]" value="1">
<label class="checkbox-view" for="delete"></label>
{{ __('admin::app.configuration.delete') }}
</span>
</div>
@endif
@endif
@if (isset($field['info']))
<span class="control-info mt-10">{{ trans($field['info']) }}</span>
@endif
<span class="control-error" @if ($field['type'] == 'multiselect') v-if="errors.has('{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}][]')" @else v-if="errors.has('{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]')" @endif
>
@if ($field['type'] == 'multiselect')
@{{ errors.first('{!! $firstField !!}[{!! $secondField !!}][{!! $thirdField !!}][{!! $field['name'] !!}][]') }}
@else
@{{ errors.first('{!! $firstField !!}[{!! $secondField !!}][{!! $thirdField !!}][{!! $field['name'] !!}]') }}
@endif
</span>
</div>
@endif
@push('scripts')
<?php if ($field['type'] == 'country'): ?>
<script type="text/x-template" id="country-template">
<div>
<select type="text" v-validate="validations" class="control" :id="name" :name="name" v-model="country" data-vv-as="&quot;{{ __('admin::app.customers.customers.country') }}&quot;" @change="sendCountryCode">
<option value=""></option>
@foreach (core()->countries() as $country)
<option value="{{ $country->code }}">{{ $country->name }}</option>
@endforeach
</select>
</div>
</script>
<script>
Vue.component('country', {
template: '#country-template',
inject: ['$validator'],
props: ['country_code', 'name', 'validations'],
data: function () {
return {
country: "",
}
},
mounted: function () {
this.country = this.country_code;
this.sendCountryCode()
},
methods: {
sendCountryCode: function () {
this.$root.$emit('countryCode', this.country)
},
}
});
</script>
<script type="text/x-template" id="state-template">
<div>
<input type="text" v-validate="validations" v-if="!haveStates()" class="control" v-model="state" :id="name" :name="name" data-vv-as="&quot;{{ __('admin::app.customers.customers.state') }}&quot;"/>
<select v-validate="validations" v-if="haveStates()" class="control" v-model="state" :id="name" :name="name" data-vv-as="&quot;{{ __('admin::app.customers.customers.state') }}&quot;" >
<option value="">{{ __('admin::app.customers.customers.select-state') }}</option>
<option v-for='(state, index) in countryStates[country]' :value="state.code">
@{{ state.default_name }}
</option>
</select>
</div>
</script>
<script>
Vue.component('state', {
template: '#state-template',
inject: ['$validator'],
props: ['state_code', 'name', 'validations'],
data: function () {
return {
state: "",
country: "",
countryStates: @json(core()->groupedStatesByCountries())
}
},
mounted: function () {
this.state = this.state_code
},
methods: {
haveStates: function () {
var this_this = this;
this_this.$root.$on('countryCode', function (country) {
this_this.country = country;
});
if (this.countryStates[this.country] && this.countryStates[this.country].length)
return true;
return false;
},
}
});
</script>
<?php endif; ?>
<script type="text/x-template" id="depends-template">
<div class="control-group" :class="[errors.has(name) ? 'has-error' : '']" v-if="this.isVisible">
<label :for="name" :class="[ isRequire ? 'required' : '']">
@{{ field_name }}
<span class="locale"> [@{{ channel_locale }}] </span>
</label>
<select v-if="this.options.length" v-validate= "validations" class="control" :id = "name" :name = "name" v-model="savedValue"
:data-vv-as="field_name">
<option v-for='(option, index) in this.options' :value="option.value"> @{{ option.title }} </option>
</select>
@if ($field['type'] == 'text')
<input v-else type="text" class="control" v-validate= "validations" :id = "name" :name = "name" v-model="savedValue"
:data-vv-as="field_name">
<input type="text" v-validate="'{{ $validations }}'" class="control" id="{{ $name }}" name="{{ $name }}" value="{{ old($nameKey) ?: (core()->getConfigData($nameKey, $channel, $locale) ? core()->getConfigData($nameKey, $channel, $locale) : (isset($field['default_value']) ? $field['default_value'] : '')) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;">
<span class="control-error" v-if="errors.has(name)">
@{{ errors.first(name) }}
@elseif ($field['type'] == 'password')
<input type="password" v-validate="'{{ $validations }}'" class="control" id="{{ $name }}" name="{{ $name }}" value="{{ old($nameKey) ?: core()->getConfigData($nameKey, $channel, $locale) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;">
@elseif ($field['type'] == 'number')
<input type="number" min="0" v-validate="'{{ $validations }}'" class="control" id="{{ $name }}" name="{{ $name }}" value="{{ old($nameKey) ?: core()->getConfigData($nameKey, $channel, $locale) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;">
@elseif ($field['type'] == 'color')
<input type="color" v-validate="'{{ $validations }}'" class="control" id="{{ $name }}" name="{{ $name }}" value="{{ old($nameKey) ?: core()->getConfigData($nameKey, $channel, $locale) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;">
@elseif ($field['type'] == 'textarea')
<textarea v-validate="'{{ $validations }}'" class="control" id="{{ $name }}" name="{{ $name }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;">{{ old($nameKey) ?: core()->getConfigData($nameKey, $channel, $locale) ?: (isset($field['default_value']) ? $field['default_value'] : '') }}</textarea>
@elseif ($field['type'] == 'select')
<select v-validate="'{{ $validations }}'" class="control" id="{{ $name }}" name="{{ $name }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;" >
@php $selectedOption = core()->getConfigData($nameKey, $channel, $locale) ?? ''; @endphp
@if (isset($field['repository']))
@foreach ($value as $key => $option)
<option value="{{ $key }}" {{ $key == $selectedOption ? 'selected' : ''}}>
{{ trans($option) }}
</option>
@endforeach
@else
@foreach ($field['options'] as $option)
@php
$value = ! isset($option['value']) ? null : ( $value = ! $option['value'] ? 0 : $option['value'] );
@endphp
<option value="{{ $value }}" {{ $value == $selectedOption ? 'selected' : ''}}>
{{ trans($option['title']) }}
</option>
@endforeach
@endif
</select>
@elseif ($field['type'] == 'multiselect')
<select v-validate="'{{ $validations }}'" class="control" id="{{ $name }}" name="{{ $name }}[]" data-vv-as="&quot;{{ trans($field['title']) }}&quot;" multiple>
@php $selectedOption = core()->getConfigData($nameKey, $channel, $locale) ?? ''; @endphp
@if (isset($field['repository']))
@foreach ($value as $key => $option)
<option value="{{ $key }}" {{ in_array($key, explode(',', $selectedOption)) ? 'selected' : ''}}>
{{ trans($value[$key]) }}
</option>
@endforeach
@else
@foreach ($field['options'] as $option)
@php
$value = ! isset($option['value']) ? null : ( $value = ! $option['value'] ? 0 : $option['value'] );
@endphp
<option value="{{ $value }}" {{ in_array($option['value'], explode(',', $selectedOption)) ? 'selected' : ''}}>
{{ trans($option['title']) }}
</option>
@endforeach
@endif
</select>
@elseif ($field['type'] == 'country')
@php $countryCode = core()->getConfigData($nameKey, $channel, $locale) ?? ''; @endphp
<country
:country_code = "'{{ $countryCode }}'"
:validations = "'{{ $validations }}'"
:name = "'{{ $name }}'"
></country>
@elseif ($field['type'] == 'state')
@php $stateCode = core()->getConfigData($nameKey, $channel, $locale) ?? ''; @endphp
<state
:state_code = "'{{ $stateCode }}'"
:validations = "'{{ $validations }}'"
:name = "'{{ $name }}'"
></state>
@elseif ($field['type'] == 'boolean')
@php $selectedOption = core()->getConfigData($nameKey, $channel, $locale) ?? (isset($field['default_value']) ? $field['default_value'] : ''); @endphp
<label class="switch">
<input type="hidden" name="{{ $name }}" value="0" />
<input type="checkbox" id="{{ $name }}" name="{{ $name }}" value="1" {{ $selectedOption ? 'checked' : '' }}>
<span class="slider round"></span>
</label>
@elseif ($field['type'] == 'image')
@php
$src = Storage::url(core()->getConfigData($nameKey, $channel, $locale));
$result = core()->getConfigData($nameKey, $channel, $locale);
@endphp
@if ($result)
<a href="{{ $src }}" target="_blank">
<img src="{{ $src }}" class="configuration-image"/>
</a>
@endif
<input type="file" v-validate="'{{ $validations }}'" class="control" id="{{ $name }}" name="{{ $name }}" value="{{ old($nameKey) ?: core()->getConfigData($nameKey, $channel, $locale) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;" style="padding-top: 5px;">
@if ($result)
<div class="control-group" style="margin-top: 5px;">
<span class="checkbox">
<input type="checkbox" id="{{ $name }}[delete]" name="{{ $name }}[delete]" value="1">
<label class="checkbox-view" for="delete"></label>
{{ __('admin::app.configuration.delete') }}
</span>
</div>
@endif
@elseif ($field['type'] == 'file')
@php
$result = core()->getConfigData($nameKey, $channel, $locale);
$src = explode("/", $result);
$path = end($src);
@endphp
@if ($result)
<a href="{{ route('admin.configuration.download', [request()->route('slug'), request()->route('slug2'), $path]) }}">
<i class="icon sort-down-icon download"></i>
</a>
@endif
<input type="file" v-validate="'{{ $validations }}'" class="control" id="{{ $name }}" name="{{ $name }}" value="{{ old($nameKey) ?: core()->getConfigData($nameKey, $channel, $locale) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;" style="padding-top: 5px;">
@if ($result)
<div class="control-group" style="margin-top: 5px;">
<span class="checkbox">
<input type="checkbox" id="{{ $name }}[delete]" name="{{ $name }}[delete]" value="1">
<label class="checkbox-view" for="delete"></label>
{{ __('admin::app.configuration.delete') }}
</span>
</div>
@endif
@endif
@if (isset($field['info']))
<span class="control-info mt-10">{{ trans($field['info']) }}</span>
@endif
<span class="control-error" @if ($field['type'] == 'multiselect') v-if="errors.has('{{ $name }}[]')" @else v-if="errors.has('{{ $name }}')" @endif>
@if ($field['type'] == 'multiselect')
@{{ errors.first('{!! $name !!}[]') }}
@else
@{{ errors.first('{!! $name !!}') }}
@endif
</span>
</div>
</script>
@endif
<script>
Vue.component('depends', {
@push('scripts')
@if ($field['type'] == 'country')
<script type="text/x-template" id="country-template">
<div>
<select type="text" v-validate="validations" class="control" :id="name" :name="name" v-model="country" data-vv-as="&quot;{{ __('admin::app.customers.customers.country') }}&quot;" @change="sendCountryCode">
<option value=""></option>
template: '#depends-template',
@foreach (core()->countries() as $country)
inject: ['$validator'],
<option value="{{ $country->code }}">{{ $country->name }}</option>
props: ['options', 'name', 'validations', 'depend', 'value', 'field_name', 'channel_locale', 'repository', 'result'],
@endforeach
</select>
</div>
</script>
data: function() {
return {
isRequire: false,
isVisible: false,
savedValue: "",
}
},
<script>
Vue.component('country', {
mounted: function () {
var this_this = this;
template: '#country-template',
this_this.savedValue = this_this.result;
inject: ['$validator'],
if (this_this.validations || (this_this.validations.indexOf("required") != -1)) {
this_this.isRequire = true;
}
props: ['country_code', 'name', 'validations'],
$(document).ready(function(){
var dependentElement = document.getElementById(this_this.depend);
var dependValue = this_this.value;
if (dependValue == 'true') {
dependValue = 1;
} else if (dependValue == 'false') {
dependValue = 0;
}
$(document).on("change", "select.control", function() {
if (this_this.depend == this.name) {
if (this_this.value == this.value) {
this_this.isVisible = true;
} else {
this_this.isVisible = false;
}
data: function () {
return {
country: "",
}
})
},
if (dependentElement && dependentElement.value == dependValue) {
this_this.isVisible = true;
} else {
this_this.isVisible = false;
}
mounted: function () {
this.country = this.country_code;
this.sendCountryCode()
},
if (this_this.result) {
if (dependentElement.value == this_this.value) {
this_this.isVisible = true;
} else {
this_this.isVisible = false;
}
methods: {
sendCountryCode: function () {
this.$root.$emit('countryCode', this.country)
},
}
});
}
});
</script>
</script>
<script type="text/x-template" id="state-template">
<div>
<input type="text" v-validate="validations" v-if="!haveStates()" class="control" v-model="state" :id="name" :name="name" data-vv-as="&quot;{{ __('admin::app.customers.customers.state') }}&quot;"/>
<select v-validate="validations" v-if="haveStates()" class="control" v-model="state" :id="name" :name="name" data-vv-as="&quot;{{ __('admin::app.customers.customers.state') }}&quot;" >
<option value="">{{ __('admin::app.customers.customers.select-state') }}</option>
<option v-for='(state, index) in countryStates[country]' :value="state.code">
@{{ state.default_name }}
</option>
</select>
</div>
</script>
<script>
Vue.component('state', {
template: '#state-template',
inject: ['$validator'],
props: ['state_code', 'name', 'validations'],
data: function () {
return {
state: "",
country: "",
countryStates: @json(core()->groupedStatesByCountries())
}
},
mounted: function () {
this.state = this.state_code
},
methods: {
haveStates: function () {
let self = this;
self.$root.$on('countryCode', function (country) {
self.country = country;
});
if (this.countryStates[this.country] && this.countryStates[this.country].length)
return true;
return false;
},
}
});
</script>
@endif
@endpush

View File

@ -66,7 +66,7 @@
@foreach ($item['fields'] as $field)
@include ('admin::configuration.field-type', ['field' => $field])
@include ('admin::configuration.field-type')
@php ($hint = $field['title'] . '-hint')
@if ($hint !== __($hint))

View File

@ -7,7 +7,7 @@ use Illuminate\Database\Seeder;
use Webkul\Category\Repositories\CategoryRepository;
/*
* CategoryBulkTableSeeder
* Category bulk table seeder.
*
* Command: php artisan db:seed --class=Webkul\\Category\\Database\\Seeders\\CategoryBulkTableSeeder
*
@ -22,8 +22,7 @@ class CategoryBulkTableSeeder extends Seeder
public function __construct(
Faker $faker,
CategoryRepository $categoryRepository
)
{
) {
$this->faker = $faker;
$this->categoryRepository = $categoryRepository;
}

View File

@ -2,10 +2,15 @@
namespace Webkul\Category\Database\Seeders;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Seeder;
use Carbon\Carbon;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
/*
* Category table seeder.
*
* Command: php artisan db:seed --class=Webkul\\Category\\Database\\Seeders\\CategoryTableSeeder
*/
class CategoryTableSeeder extends Seeder
{
public function run()
@ -32,7 +37,6 @@ class CategoryTableSeeder extends Seeder
DB::table('category_translations')->insert([
[
'id' => '1',
'name' => 'Root',
'slug' => 'root',
'description' => 'Root',
@ -41,6 +45,46 @@ class CategoryTableSeeder extends Seeder
'meta_keywords' => '',
'category_id' => '1',
'locale' => 'en',
],
[
'name' => 'Raíz',
'slug' => 'root',
'description' => 'Raíz',
'meta_title' => '',
'meta_description' => '',
'meta_keywords' => '',
'category_id' => '1',
'locale' => 'es',
],
[
'name' => 'Racine',
'slug' => 'root',
'description' => 'Racine',
'meta_title' => '',
'meta_description' => '',
'meta_keywords' => '',
'category_id' => '1',
'locale' => 'fr',
],
[
'name' => 'Hoofdcategorie',
'slug' => 'root',
'description' => 'Hoofdcategorie',
'meta_title' => '',
'meta_description' => '',
'meta_keywords' => '',
'category_id' => '1',
'locale' => 'nl',
],
[
'name' => 'Kök',
'slug' => 'root',
'description' => 'Kök',
'meta_title' => '',
'meta_description' => '',
'meta_keywords' => '',
'category_id' => '1',
'locale' => 'tr',
]
]);
}

View File

@ -3,39 +3,43 @@
namespace Webkul\Core\Repositories;
use Webkul\Core\Eloquent\Repository;
use Webkul\Core\Contracts\CoreConfig;
use Illuminate\Support\Facades\Storage;
use Webkul\Core\Traits\CoreConfigField;
use Prettus\Repository\Traits\CacheableRepository;
class CoreConfigRepository extends Repository
{
use CacheableRepository;
use CoreConfigField, CacheableRepository;
/**
* Specify Model class name
* Specify model class name.
*
* @return mixed
* @return string
*/
function model()
function model(): string
{
return 'Webkul\Core\Contracts\CoreConfig';
return CoreConfig::class;
}
/**
* Create.
*
* @param array $data
* @return \Webkul\Core\Contracts\CoreConfig
*/
public function create(array $data)
{
if ($data['locale'] || $data['channel']) {
$locale = $data['locale'];
$channel = $data['channel'];
$locale = $data['locale'];
$channel = $data['channel'];
unset($data['locale']);
unset($data['channel']);
unset($data['locale']);
unset($data['channel']);
}
foreach ($data as $method => $fieldData) {
$recurssiveData = $this->recuressiveArray($fieldData , $method);
$recurssiveData = $this->recuressiveArray($fieldData, $method);
foreach ($recurssiveData as $fieldName => $value) {
$field = core()->getConfigField($fieldName);
@ -89,7 +93,7 @@ class CoreConfigRepository extends Repository
foreach ($coreConfigValue as $coreConfig) {
Storage::delete($coreConfig['value']);
if(isset($value['delete'])) {
if (isset($value['delete'])) {
$this->model->destroy($coreConfig['id']);
} else {
$coreConfig->update([
@ -106,11 +110,14 @@ class CoreConfigRepository extends Repository
}
/**
* Recursive array.
*
* @param array $formData
* @param string $method
* @return array
*/
public function recuressiveArray(array $formData, $method) {
public function recuressiveArray(array $formData, $method)
{
static $data = [];
static $recuressiveArrayData = [];
@ -145,11 +152,11 @@ class CoreConfigRepository extends Repository
}
/**
* Return dimension of array
* Return dimension of the array.
*
* @param array $array
* @return int
*/
*/
public function countDim($array)
{
if (is_array(reset($array))) {

View File

@ -2,10 +2,11 @@
namespace Webkul\Core\Repositories;
use Storage;
use Carbon\Carbon;
use Illuminate\Support\Arr;
use Webkul\Core\Eloquent\Repository;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Storage;
use Illuminate\Container\Container as App;
use Prettus\Repository\Traits\CacheableRepository;
@ -14,7 +15,7 @@ class SliderRepository extends Repository
use CacheableRepository;
/**
* ChannelRepository object
* Channel repository instance.
*
* @var \Webkul\Core\Repositories\ChannelRepository
*/
@ -30,15 +31,14 @@ class SliderRepository extends Repository
public function __construct(
ChannelRepository $channelRepository,
App $app
)
{
) {
$this->channelRepository = $channelRepository;
parent::__construct($app);
}
/**
* Specify Model class name
* Specify model class name.
*
* @return mixed
*/
@ -48,8 +48,10 @@ class SliderRepository extends Repository
}
/**
* Save slider.
*
* @param array $data
* @return \Webkul\Core\Contracts\Slider
* @return bool|\Webkul\Core\Contracts\Slider
*/
public function save(array $data)
{
@ -91,7 +93,10 @@ class SliderRepository extends Repository
}
/**
* Update item.
*
* @param array $data
* @param int $id
* @return bool
*/
public function updateItem(array $data, $id)
@ -134,7 +139,7 @@ class SliderRepository extends Repository
}
/**
* Delete a slider item and delete the image from the disk or where ever it is
* Delete a slider item and delete the image from the disk or where ever it is.
*
* @param int $id
* @return bool
@ -149,4 +154,26 @@ class SliderRepository extends Repository
return $this->model->destroy($id);
}
/**
* Get only active sliders.
*
* @return array
*/
public function getActiveSliders()
{
$currentChannel = core()->getCurrentChannel();
$currentLocale = core()->getCurrentLocale();
return $this->where('channel_id', $currentChannel->id)
->whereRaw("find_in_set(?, locale)", [$currentLocale->code])
->where(function ($query) {
$query->where('expired_at', '>=', Carbon::now()->format('Y-m-d'))
->orWhereNull('expired_at');
})
->orderBy('sort_order', 'ASC')
->get()
->toArray();
}
}

View File

@ -0,0 +1,122 @@
<?php
namespace Webkul\Core\Traits;
trait CoreConfigField
{
/**
* Get name field for forms in configuration page.
*
* @param string $key
* @return string
*/
public function getNameField($key)
{
$nameField = '';
foreach (explode('.', $key) as $key => $field) {
$nameField .= $key === 0 ? $field : '[' . $field . ']';
}
return $nameField;
}
/**
* Get validations for forms in configuration page.
*
* @param array $field
* @return string
*/
public function getValidations($field)
{
return isset($field['validation'])
? $field['validation']
: '';
}
/**
* Get value from repositories, if developer wants to do.
*
* @param array $field
* @return mixed
*/
public function getValueByRepository($field)
{
if (isset($field['repository'])) {
$temp = explode("@", $field['repository']);
$class = app(current($temp));
$method = end($temp);
return $class->$method();
}
return null;
}
/**
* Get dependent field or value based on arguments.
*
* @param array $field
* @param string $fieldOrValue
* @return string
*/
public function getDependentFieldOrValue($field, $fieldOrValue = 'field')
{
$depends = explode(":", $field['depend']);
return $fieldOrValue === 'field'
? current($depends) : end($depends);
}
/**
* Get dependent field options.
*
* @param array $field
* @param array $dependentValues
* @return mixed
*/
public function getDependentFieldOptions($field, $dependentValues)
{
$fieldOptions = null;
if ($dependentValues) {
$i = 0;
foreach ($dependentValues as $key => $result) {
$data['title'] = $result;
$data['value'] = $key;
$options[$i] = $data;
$i++;
}
$fieldOptions = $options;
}
return ! isset($field['options'])
? ''
: $fieldOptions;
}
/**
* Get channel/locale indicator for form fields. So, that form fields can be detected,
* whether it is channel based or locale based or both.
*
* @param array $field
* @param string $channel
* @param string $locale
* @return string
*/
public function getChannelLocaleInfo($field, $channel, $locale)
{
$info = [];
if (isset($field['channel_based']) && $field['channel_based']) {
$info[] = $channel;
}
if (isset($field['locale_based']) && $field['locale_based']) {
$info[] = $locale;
}
return ! empty($info) ? '[' . implode(' - ', $info) . ']' : '';
}
}

View File

@ -321,7 +321,7 @@ class Product extends Model implements ProductContract
public function getAttribute($key)
{
if (! method_exists(static::class, $key)
&& ! in_array($key, ['parent_id', 'attribute_family_id'])
&& ! in_array($key, ['pivot', 'parent_id', 'attribute_family_id'])
&& ! isset($this->attributes[$key])
) {
if (isset($this->id)) {

View File

@ -2,7 +2,6 @@
namespace Webkul\Shop\Http\Controllers;
use Carbon\Carbon;
use Webkul\Shop\Http\Controllers\Controller;
use Webkul\Core\Repositories\SliderRepository;
use Webkul\Product\Repositories\SearchRepository;
@ -10,17 +9,17 @@ use Webkul\Product\Repositories\SearchRepository;
class HomeController extends Controller
{
/**
* SliderRepository object
* Slider repository instance.
*
* @var \Webkul\Core\Repositories\SliderRepository
*/
*/
protected $sliderRepository;
/**
* SearchRepository object
* Search repository instance.
*
* @var \Webkul\Core\Repositories\SearchRepository
*/
*/
protected $searchRepository;
/**
@ -29,12 +28,11 @@ class HomeController extends Controller
* @param \Webkul\Core\Repositories\SliderRepository $sliderRepository
* @param \Webkul\Product\Repositories\SearchRepository $searchRepository
* @return void
*/
*/
public function __construct(
SliderRepository $sliderRepository,
SearchRepository $searchRepository
)
{
) {
$this->sliderRepository = $sliderRepository;
$this->searchRepository = $searchRepository;
@ -43,39 +41,19 @@ class HomeController extends Controller
}
/**
* loads the home page for the storefront
* Loads the home page for the storefront.
*
* @return \Illuminate\View\View
*/
public function index()
{
$currentChannel = core()->getCurrentChannel();
$currentLocale = core()->getCurrentLocale();
$sliderData = $this->sliderRepository
->where('channel_id', $currentChannel->id)
->whereRaw("find_in_set(?, locale)", [$currentLocale->code])
->where(function ($query) {
$query->where('expired_at', '>=', Carbon::now()->format('Y-m-d'))
->orWhereNull('expired_at');
})
->get()
->toArray();
usort($sliderData, function ($a, $b) {
if ($a['sort_order'] == $b['sort_order']) {
return 0;
}
return ($a['sort_order'] < $b['sort_order']) ? -1 : 1;
});
$sliderData = $this->sliderRepository->getActiveSliders();
return view($this->_config['view'], compact('sliderData'));
}
/**
* loads the home page for the storefront
* Loads the home page for the storefront if something wrong.
*
* @return \Exception
*/
@ -85,14 +63,12 @@ class HomeController extends Controller
}
/**
* Upload image for product search with machine learning
* Upload image for product search with machine learning.
*
* @return \Illuminate\Http\Response
*/
public function upload()
{
$url = $this->searchRepository->uploadSearchImage(request()->all());
return $url;
return $this->searchRepository->uploadSearchImage(request()->all());
}
}

View File

@ -1,45 +1,53 @@
<?php
namespace Webkul\Shop\Http\Controllers;
use Illuminate\Http\Request;
use Webkul\Category\Repositories\CategoryRepository;
use Webkul\Core\Repositories\SliderRepository;
use Webkul\Product\Repositories\ProductRepository;
use Webkul\Category\Repositories\CategoryRepository;
class ProductsCategoriesProxyController extends Controller
{
/**
* CategoryRepository object
* Category repository instance.
*
* @var \Webkul\Category\Repositories\CategoryRepository
*/
protected $categoryRepository;
/**
* ProductRepository object
* Product repository instance.
*
* @var \Webkul\Product\Repositories\ProductRepository
*/
protected $productRepository;
/**
* Slider repository instance.
*
* @var \Webkul\Core\Repositories\SliderRepository
*/
protected $sliderRepository;
/**
* Create a new controller instance.
*
* @param \Webkul\Category\Repositories\CategoryRepository $categoryRepository
* @param \Webkul\Product\Repositories\ProductRepository $productRepository
*
* @return void
*/
public function __construct(
CategoryRepository $categoryRepository,
ProductRepository $productRepository
)
{
ProductRepository $productRepository,
SliderRepository $sliderRepository
) {
$this->categoryRepository = $categoryRepository;
$this->productRepository = $productRepository;
$this->sliderRepository = $sliderRepository;
parent::__construct();
}
@ -73,13 +81,7 @@ class ProductsCategoriesProxyController extends Controller
abort(404);
}
$sliderRepository = app('Webkul\Core\Repositories\SliderRepository');
$sliderData = $sliderRepository
->where('channel_id', core()->getCurrentChannel()->id)
->where('locale', core()->getCurrentLocale()->code)
->get()
->toArray();
$sliderData = $this->sliderRepository->getActiveSliders();
return view('shop::home.index', compact('sliderData'));
}