multiselect for configuration
This commit is contained in:
parent
b430d4d4b5
commit
33ac4c1319
|
|
@ -131,7 +131,7 @@ class ConfigurationController extends Controller
|
|||
* @param \Webkul\Admin\Http\Requests\ConfigurationForm $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(ConfigurationForm $request)
|
||||
public function store()
|
||||
{
|
||||
Event::fire('core.configuration.save.after');
|
||||
|
||||
|
|
|
|||
|
|
@ -6,4 +6,4 @@
|
|||
</option>
|
||||
@endforeach
|
||||
|
||||
</select>
|
||||
</select>
|
||||
|
|
|
|||
|
|
@ -16,6 +16,13 @@
|
|||
|
||||
$name = $item['key'] . '.' . $field['name'];
|
||||
|
||||
if (isset($field['repository'])) {
|
||||
$temp = explode("@", $field['repository']);
|
||||
$class = app(current($temp));
|
||||
$method = end($temp);
|
||||
$value = $class->$method();
|
||||
$selectedOption = core()->getConfigData($name) ?? '';
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="control-group {{ $field['type'] }}" :class="[errors.has('{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]') ? 'has-error' : '']">
|
||||
|
|
@ -54,20 +61,39 @@
|
|||
|
||||
<select v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" data-vv-as=""{{ $field['name'] }}"" >
|
||||
|
||||
@foreach($field['options'] as $option)
|
||||
@if (isset($field['repository']))
|
||||
@foreach($value as $option)
|
||||
<option value="{{ $option['name'] }}" {{ $option['name'] == $selectedOption ? 'selected' : ''}} {{ in_array($option['name'], explode(',', $selectedOption)) ? 'selected' : ''}}>
|
||||
{{ $option['name'] }}
|
||||
</option>
|
||||
@endforeach
|
||||
@else
|
||||
@foreach($field['options'] as $option)
|
||||
|
||||
<?php
|
||||
if($option['value'] == false) {
|
||||
$value = 0;
|
||||
}else {
|
||||
$value = $option['value'];
|
||||
}
|
||||
<?php
|
||||
if($option['value'] == false) {
|
||||
$value = 0;
|
||||
} else {
|
||||
$value = $option['value'];
|
||||
}
|
||||
|
||||
$selectedOption = core()->getConfigData($name) ?? '';
|
||||
?>
|
||||
$selectedOption = core()->getConfigData($name) ?? '';
|
||||
?>
|
||||
|
||||
<option value="{{ $value }}" {{ $value == $selectedOption ? 'selected' : ''}}>
|
||||
{{ $option['title'] }}
|
||||
<option value="{{ $value }}" {{ $value == $selectedOption ? 'selected' : ''}}>
|
||||
{{ $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=""{{ $field['name'] }}"" multiple>
|
||||
|
||||
@foreach($value as $option)
|
||||
<option value="{{ $option['name'] }}" {{ $option['name'] == $selectedOption ? 'selected' : ''}} {{ in_array($option['name'], explode(',', $selectedOption)) ? 'selected' : ''}}>
|
||||
{{ $option['name'] }}
|
||||
</option>
|
||||
@endforeach
|
||||
|
||||
|
|
@ -76,4 +102,5 @@
|
|||
@endif
|
||||
|
||||
<span class="control-error" v-if="errors.has('{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]')">@{{ errors.first('{!! $firstField !!}[{!! $secondField !!}][{!! $thirdField !!}][{!! $field['name'] !!}]') }}</span>
|
||||
|
||||
</div>
|
||||
|
|
@ -30,8 +30,7 @@ class CoreConfigRepository extends Repository
|
|||
{
|
||||
unset($data['_token']);
|
||||
|
||||
if ($data['locale'] || $data['channel'])
|
||||
{
|
||||
if ($data['locale'] || $data['channel']) {
|
||||
$locale = $data['locale'];
|
||||
$channel = $data['channel'];
|
||||
unset($data['locale']);
|
||||
|
|
@ -39,6 +38,7 @@ class CoreConfigRepository extends Repository
|
|||
}
|
||||
|
||||
foreach ($data as $method => $fieldData) {
|
||||
|
||||
$recurssiveData = $this->recuressiveArray($fieldData , $method);
|
||||
|
||||
foreach ($recurssiveData as $fieldName => $value) {
|
||||
|
|
@ -55,57 +55,51 @@ class CoreConfigRepository extends Repository
|
|||
$locale_based = true;
|
||||
}
|
||||
|
||||
if (isset($field['channel_based']) && $field['channel_based'])
|
||||
{
|
||||
if (isset($field['locale_based']) && $field['locale_based'])
|
||||
{
|
||||
if (getType($value) == 'array') {
|
||||
$value = implode("," , $value);
|
||||
}
|
||||
|
||||
if (isset($field['channel_based']) && $field['channel_based']) {
|
||||
if (isset($field['locale_based']) && $field['locale_based']) {
|
||||
$coreConfigValue = $this->model
|
||||
->where('code', $fieldName)
|
||||
->where('locale_code', $locale)
|
||||
->where('channel_code', $channel)
|
||||
->get();
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
$coreConfigValue = $this->model
|
||||
->where('code', $fieldName)
|
||||
->where('channel_code', $channel)
|
||||
->get();
|
||||
}
|
||||
} else
|
||||
{
|
||||
if (isset($field['locale_based']) && $field['locale_based'])
|
||||
{
|
||||
} else {
|
||||
if (isset($field['locale_based']) && $field['locale_based']) {
|
||||
$coreConfigValue = $this->model
|
||||
->where('code', $fieldName)
|
||||
->where('locale_code', $locale)
|
||||
->get();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$coreConfigValue = $this->model
|
||||
->where('code', $fieldName)
|
||||
->get();
|
||||
}
|
||||
}
|
||||
|
||||
if (!count($coreConfigValue) > 0)
|
||||
{
|
||||
if (!count($coreConfigValue) > 0) {
|
||||
$this->model->create([
|
||||
'code' => $fieldName,
|
||||
'value' => $value,
|
||||
'locale_code' => $locale_based ? $locale : null,
|
||||
'channel_code' => $channel_based ? $channel : null
|
||||
]);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
$updataData['code'] = $fieldName;
|
||||
$updataData['value'] = $value;
|
||||
$updataData['locale_code'] = $locale_based ? $locale : null;
|
||||
$updataData['channel_code'] = $channel_based ? $channel : null;
|
||||
|
||||
foreach ($coreConfigValue as $coreConfig)
|
||||
{
|
||||
foreach ($coreConfigValue as $coreConfig) {
|
||||
$coreConfig->update($updataData);
|
||||
}
|
||||
}
|
||||
|
|
@ -120,15 +114,49 @@ class CoreConfigRepository extends Repository
|
|||
*/
|
||||
public function recuressiveArray(array $formData, $method) {
|
||||
static $data =[];
|
||||
static $recuressiveArrayData =[];
|
||||
|
||||
foreach ($formData as $form => $formValue) {
|
||||
$value = $method . '.' . $form;
|
||||
if (is_array($formValue)) {
|
||||
$this->recuressiveArray($formValue, $value);
|
||||
} else {
|
||||
$data[$value] = $formValue;
|
||||
$dim = $this->countDim($formValue);
|
||||
if ($dim > 1) {
|
||||
$this->recuressiveArray($formValue, $value);
|
||||
} else if($dim == 1) {
|
||||
$data[$value] = $formValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
foreach($data as $key => $value) {
|
||||
$field = core()->getConfigField($key);
|
||||
|
||||
if ($field) {
|
||||
$recuressiveArrayData[$key] = $value;
|
||||
} else {
|
||||
foreach($value as $key1 => $val) {
|
||||
$recuressiveArrayData[$key . '.' . $key1] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $recuressiveArrayData;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* return dimension of array
|
||||
* @param array $array
|
||||
* @return integer
|
||||
*/
|
||||
public function countDim($array)
|
||||
{
|
||||
if (is_array(reset($array))) {
|
||||
$return = $this->countDim(reset($array)) + 1;
|
||||
}
|
||||
else {
|
||||
$return = 1;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,4 +21,13 @@ class CountryRepository extends Repository
|
|||
{
|
||||
return 'Webkul\Core\Models\Country';
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get country
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllCountry() {
|
||||
return $this->model->get()->toArray();
|
||||
}
|
||||
}
|
||||
|
|
@ -109,7 +109,8 @@ return [
|
|||
[
|
||||
'name' => 'country',
|
||||
'title' => 'Country',
|
||||
'type' => 'text',
|
||||
'type' => 'select',
|
||||
'repository' => 'Webkul\Core\Repositories\CountryRepository@getAllCountry',
|
||||
'validation' => 'required',
|
||||
'channel_based' => true,
|
||||
'locale_based' => false
|
||||
|
|
|
|||
Loading…
Reference in New Issue