diff --git a/packages/Webkul/Admin/src/Resources/views/catalog/attributes/edit.blade.php b/packages/Webkul/Admin/src/Resources/views/catalog/attributes/edit.blade.php index 278cd80fb..0535631b6 100755 --- a/packages/Webkul/Admin/src/Resources/views/catalog/attributes/edit.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/catalog/attributes/edit.blade.php @@ -1,3 +1,7 @@ +@php + $allLocales = app('Webkul\Core\Repositories\LocaleRepository')->all(); +@endphp + @extends('admin::layouts.content') @section('page_title') @@ -27,25 +31,29 @@
@csrf() + {!! view_render_event('bagisto.admin.catalog.attribute.edit_form_accordian.general.before', ['attribute' => $attribute]) !!}
- {!! view_render_event('bagisto.admin.catalog.attribute.edit_form_accordian.general.controls.before', ['attribute' => $attribute]) !!}
- @{{ errors.first('code') }} +
- type ?> + @php + $selectedOption = old('type') ?: $attribute->type; + @endphp + + +
@@ -90,39 +99,32 @@ {!! view_render_event('bagisto.admin.catalog.attribute.edit_form_accordian.general.after', ['attribute' => $attribute]) !!} - {!! view_render_event('bagisto.admin.catalog.attribute.edit_form_accordian.attributes.before', ['attribute' => $attribute]) !!}
- {!! view_render_event('bagisto.admin.catalog.attribute.edit_form_accordian.attributes.controls.before', ['attribute' => $attribute]) !!}
- @{{ errors.first('admin_name') }} +
- @foreach (app('Webkul\Core\Repositories\LocaleRepository')->all() as $locale) - + @foreach ($allLocales as $locale)
- @endforeach {!! view_render_event('bagisto.admin.catalog.attribute.edit_form_accordian.attributes.controls.after', ['attribute' => $attribute]) !!} -
{!! view_render_event('bagisto.admin.catalog.attribute.edit_form_accordian.attributes.after', ['attribute' => $attribute]) !!} -
- {!! view_render_event('bagisto.admin.catalog.attribute.edit_form_accordian.options.before', ['attribute' => $attribute]) !!} @@ -130,7 +132,10 @@ {!! view_render_event('bagisto.admin.catalog.attribute.edit_form_accordian.options.controls.before', ['attribute' => $attribute]) !!} - + {!! view_render_event('bagisto.admin.catalog.attribute.edit_form_accordian.options.controls.after', ['attribute' => $attribute]) !!} @@ -138,14 +143,12 @@ {!! view_render_event('bagisto.admin.catalog.attribute.edit_form_accordian.options.after', ['attribute' => $attribute]) !!} -
{!! view_render_event('bagisto.admin.catalog.attribute.edit_form_accordian.validations.before', ['attribute' => $attribute]) !!}
- {!! view_render_event('bagisto.admin.catalog.attribute.edit_form_accordian.validations.controls.before', ['attribute' => $attribute]) !!}
@@ -190,18 +193,15 @@
{!! view_render_event('bagisto.admin.catalog.attribute.edit_form_accordian.validations.controls.after', ['attribute' => $attribute]) !!} -
{!! view_render_event('bagisto.admin.catalog.attribute.edit_form_accordian.validations.after', ['attribute' => $attribute]) !!} - {!! view_render_event('bagisto.admin.catalog.attribute.edit_form_accordian.configuration.before', ['attribute' => $attribute]) !!}
- {!! view_render_event('bagisto.admin.catalog.attribute.edit_form_accordian.configuration.controls.before', ['attribute' => $attribute]) !!}
@@ -291,7 +291,6 @@
{!! view_render_event('bagisto.admin.catalog.attribute.edit_form_accordian.configuration.controls.after', ['attribute' => $attribute]) !!} -
@@ -332,6 +331,7 @@ + {{ __('admin::app.catalog.attributes.default_null_option') }}
@@ -344,11 +344,7 @@ {{ __('admin::app.catalog.attributes.admin_name') }} - @foreach (app('Webkul\Core\Repositories\LocaleRepository')->all() as $locale) - - {{ $locale->name . ' (' . $locale->code . ')' }} - - @endforeach + {{ __('admin::app.catalog.attributes.position') }} @@ -357,7 +353,9 @@ - + + + @@ -366,30 +364,28 @@
- The image size must be less than 600 KB +
- @{{ errors.first(adminName(row)) }} +
- @foreach (app('Webkul\Core\Repositories\LocaleRepository')->all() as $locale) - -
- - @{{ errors.first(localeInputName(row, '{!! $locale->code !!}')) }} -
- - @endforeach + +
+ + +
+
- @{{ errors.first(sortOrderName(row)) }} +
@@ -401,6 +397,10 @@
+ + @@ -414,11 +414,14 @@ inject: ['$validator'], props: [ - 'src' + 'src', + 'allLocales' ], data: function() { return { + appLocale: '{{ app()->getLocale() }}', + optionPage: 1, optionRowCount: 0, optionRows: [], show_swatch: "{{ $attribute->type == 'select' ? true : false }}", @@ -442,24 +445,28 @@ }, created: function () { - let self = this; - - $('#type').on('change', function (e) { - if (['select'].indexOf($(e.target).val()) === -1) { - self.show_swatch = false; - } else { - self.show_swatch = true; - } - }); - this.getAttributeOptions(); + + this.activateToggleSwatch(); }, methods: { - getAttributeOptions: function (id) { + activateToggleSwatch: function () { let self = this; - axios.get(this.src).then(function (response) { + $('#type').on('change', function (e) { + if (['select'].indexOf($(e.target).val()) === -1) { + self.show_swatch = false; + } else { + self.show_swatch = true; + } + }); + }, + + getAttributeOptions: function () { + let self = this; + + axios.get(`${this.src}?page=${this.optionPage}`).then(function (response) { let options = response.data.data; options.forEach((option) => { @@ -472,7 +479,8 @@ 'swatch_value': option.swatch_value, 'swatch_value_url': option.swatch_value_url, 'notRequired': '', - 'locales': {} + 'locales': {}, + 'isDelete': false, }; if (option.label) { @@ -490,14 +498,20 @@ }); }, + loadMoreOptions: function () { + this.optionPage++; + + this.getAttributeOptions(); + }, + addOptionRow: function (isNullOptionRow) { const rowCount = this.optionRowCount++; const id = 'option_' + rowCount; - let row = {'id': id, 'locales': {}}; + let row = {'id': id, 'locales': {}, 'isDelete': false}; - @foreach (app('Webkul\Core\Repositories\LocaleRepository')->all() as $locale) - row['locales']['{{ $locale->code }}'] = ''; - @endforeach + this.allLocales.forEach((locale) => { + row['locales'][locale.code] = ''; + }); row['notRequired'] = ''; @@ -515,8 +529,8 @@ this.isNullOptionChecked = false; } - const index = this.optionRows.indexOf(row) - Vue.delete(this.optionRows, index); + const index = this.optionRows.indexOf(row); + this.optionRows[index].isDelete = true; }, adminName: function (row) { @@ -536,7 +550,7 @@ return ''; } - return ('{{ app()->getLocale() }}' === localeCode) ? 'required' : ''; + return (this.appLocale === localeCode) ? 'required' : ''; } }, }); diff --git a/packages/Webkul/Attribute/src/Http/Controllers/AttributeController.php b/packages/Webkul/Attribute/src/Http/Controllers/AttributeController.php index b8c686669..459634dfa 100755 --- a/packages/Webkul/Attribute/src/Http/Controllers/AttributeController.php +++ b/packages/Webkul/Attribute/src/Http/Controllers/AttributeController.php @@ -101,7 +101,7 @@ class AttributeController extends Controller { $attribute = $this->attributeRepository->findOrFail($id); - return $attribute->options()->paginate(10); + return $attribute->options()->paginate(50); } /** diff --git a/packages/Webkul/Attribute/src/Repositories/AttributeRepository.php b/packages/Webkul/Attribute/src/Repositories/AttributeRepository.php index 0eba53f4e..2fe7ed964 100755 --- a/packages/Webkul/Attribute/src/Repositories/AttributeRepository.php +++ b/packages/Webkul/Attribute/src/Repositories/AttributeRepository.php @@ -88,8 +88,6 @@ class AttributeRepository extends Repository $attribute->update($data); - $previousOptionIds = $attribute->options()->pluck('id'); - if (in_array($attribute->type, ['select', 'multiselect', 'checkbox'])) { if (isset($data['options'])) { foreach ($data['options'] as $optionId => $optionInputs) { @@ -98,20 +96,18 @@ class AttributeRepository extends Repository 'attribute_id' => $attribute->id, ], $optionInputs)); } else { - if (is_numeric($index = $previousOptionIds->search($optionId))) { - $previousOptionIds->forget($index); - } + $isDelete = $optionInputs['isDelete'] == 'true' ? true : false; - $this->attributeOptionRepository->update($optionInputs, $optionId); + if ($isDelete) { + $this->attributeOptionRepository->delete($optionId); + } else { + $this->attributeOptionRepository->update($optionInputs, $optionId); + } } } } } - foreach ($previousOptionIds as $optionId) { - $this->attributeOptionRepository->delete($optionId); - } - Event::dispatch('catalog.attribute.update.after', $attribute); return $attribute; @@ -160,7 +156,7 @@ class AttributeRepository extends Repository } /** - * + * * @param array $codes * @return array */