Added check for products in category while mass delete
This commit is contained in:
parent
8010d34a3a
commit
09e1984d7a
|
|
@ -339,6 +339,8 @@ Route::group(['middleware' => ['web']], function () {
|
|||
Route::post('categories/massdelete', 'Webkul\Category\Http\Controllers\CategoryController@massDestroy')->defaults('_config', [
|
||||
'redirect' => 'admin.catalog.categories.index',
|
||||
])->name('admin.catalog.categories.massdelete');
|
||||
|
||||
Route::post('/categories/product/count', 'Webkul\Category\Http\Controllers\CategoryController@categoryProductCount')->name('admin.catalog.categories.product.count');
|
||||
|
||||
|
||||
// Catalog Attribute Routes
|
||||
|
|
|
|||
|
|
@ -26,4 +26,41 @@
|
|||
|
||||
{!! view_render_event('bagisto.admin.catalog.categories.list.after') !!}
|
||||
</div>
|
||||
@stop
|
||||
@stop
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$("input[type='checkbox']").change(function() {
|
||||
|
||||
$("input[type='checkbox']").attr('disabled', true);
|
||||
|
||||
var formData = {};
|
||||
$.each($('form').serializeArray(), function(i, field) {
|
||||
formData[field.name] = field.value;
|
||||
});
|
||||
|
||||
if (formData.indexes) {
|
||||
$.ajax({
|
||||
type : 'POST',
|
||||
url : '{{route("admin.catalog.categories.product.count")}}',
|
||||
data : {
|
||||
_token: '{{csrf_token()}}',
|
||||
indexes: formData.indexes
|
||||
},
|
||||
success:function(data) {
|
||||
$("input[type='checkbox']").attr('disabled', false);
|
||||
if (data.product_count > 0) {
|
||||
var message = "{{trans('ui::app.datagrid.massaction.delete-category-product')}}";
|
||||
$('form').attr('onsubmit', 'return confirm("'+message+'")');
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$("input[type='checkbox']").attr('disabled', false);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
|
|
@ -190,7 +190,10 @@ class CategoryController extends Controller
|
|||
$suppressFlash = true;
|
||||
Event::dispatch('catalog.category.delete.before', $categoryId);
|
||||
|
||||
$this->categoryRepository->delete($categoryId);
|
||||
if($category->products->count() > 0) {
|
||||
$category->products()->delete();
|
||||
}
|
||||
$category->delete();
|
||||
|
||||
Event::dispatch('catalog.category.delete.after', $categoryId);
|
||||
|
||||
|
|
@ -207,4 +210,17 @@ class CategoryController extends Controller
|
|||
|
||||
return redirect()->route($this->_config['redirect']);
|
||||
}
|
||||
|
||||
|
||||
public function categoryProductCount() {
|
||||
$indexes = explode(",", request()->input('indexes'));
|
||||
$product_count = 0;
|
||||
|
||||
foreach($indexes as $index) {
|
||||
$category = $this->categoryRepository->find($index);
|
||||
$product_count += $category->products->count();
|
||||
}
|
||||
|
||||
return response()->json(['product_count' => $product_count], 200);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|||
use Webkul\Category\Contracts\Category as CategoryContract;
|
||||
use Webkul\Attribute\Models\AttributeProxy;
|
||||
use Webkul\Category\Repositories\CategoryRepository;
|
||||
use Webkul\Product\Models\ProductProxy;
|
||||
|
||||
/**
|
||||
* Class Category
|
||||
|
|
@ -129,4 +130,12 @@ class Category extends TranslatableModel implements CategoryContract
|
|||
|
||||
return $this->findInTree($category->children);
|
||||
}
|
||||
|
||||
/**
|
||||
* The products that belong to the category.
|
||||
*/
|
||||
public function products()
|
||||
{
|
||||
return $this->belongsToMany(ProductProxy::modelClass(), 'product_categories');
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ return [
|
|||
'mass-update-status' => 'هل تريد حقا تحديث الحالة من منتقى :resource?',
|
||||
'delete' => 'هل تريد حقا حذف هذا :resource?',
|
||||
'edit' => 'هل تريد حقا تحرير هذا :resource?',
|
||||
'delete-category-product' => 'The selected categories contains products. Performing this action will remove the related products. Do you really want to perform this action?'
|
||||
],
|
||||
|
||||
'zero-index' => 'يمكن أن تحتوي أعمدة الفهرس على قيم أكبر من الصفر فقط',
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ return [
|
|||
'mass-update-status' => 'Möchten Sie den Status der ausgewählten :resource wirklich aktualisieren?',
|
||||
'delete' => 'Möchten Sie diese Aktion wirklich ausführen?',
|
||||
'edit' => 'Möchten Sie :resource wirklich bearbeiten?',
|
||||
'delete-category-product' => 'The selected categories contains products. Performing this action will remove the related products. Do you really want to perform this action?'
|
||||
],
|
||||
|
||||
'zero-index' => 'Indexspalten können nur Werte größer als Null haben',
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ return [
|
|||
'mass-update-status' => 'Do you really want to update status of these selected :resource?',
|
||||
'delete' => 'Do you really want to perform this action?',
|
||||
'edit' => 'Do you really want to edit this :resource?',
|
||||
'delete-category-product' => 'The selected categories contains products. Performing this action will remove the related products. Do you really want to perform this action?'
|
||||
],
|
||||
|
||||
'zero-index' => 'Index columns can have values greater than zero only',
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ return [
|
|||
'mass-update-status' => 'آیا واقعاً می خواهید وضعیت انتخاب شده را به روز کنید :resource?',
|
||||
'delete' => 'آیا واقعاً می خواهید این عمل را انجام دهید؟',
|
||||
'edit' => 'آیا واقعاً می خواهید این را ویرایش کنید :resource?',
|
||||
'delete-category-product' => 'The selected categories contains products. Performing this action will remove the related products. Do you really want to perform this action?'
|
||||
],
|
||||
|
||||
'zero-index' => 'ستون های فهرست می توانند مقادیری بیشتر از صفر داشته باشند',
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ return [
|
|||
'mass-update-status' => 'Vuoi aggiornare davvero lo stato dei :resource selezionati?',
|
||||
'delete' => 'Vuoi davvero effettuare questa azione?',
|
||||
'edit' => 'Vuoi davvero modificare questo :resource?',
|
||||
'delete-category-product' => 'The selected categories contains products. Performing this action will remove the related products. Do you really want to perform this action?'
|
||||
],
|
||||
|
||||
'zero-index' => 'Le colonnne indice possono avere solo valori maggiori di zero',
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ return [
|
|||
'mass-update-status' => 'Do you really want to update status of these selected :resource?',
|
||||
'delete' => 'Wilt u deze actie echt uitvoeren?',
|
||||
'edit' => 'Wil je dit echt bewerken :resource?',
|
||||
'delete-category-product' => 'The selected categories contains products. Performing this action will remove the related products. Do you really want to perform this action?'
|
||||
],
|
||||
|
||||
'zero-index' => 'Index columns can have values greater than zero only',
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ return [
|
|||
'mass-update-status' => 'Czy naprawdę chcesz zaktualizować status tych wybranych :resource?',
|
||||
'delete' => 'Czy naprawdę chcesz wykonać tę akcję?',
|
||||
'edit' => 'Czy naprawdę chcesz edytować :resource?',
|
||||
'delete-category-product' => 'The selected categories contains products. Performing this action will remove the related products. Do you really want to perform this action?'
|
||||
],
|
||||
|
||||
'zero-index' => 'Kolumny indeksu mogą mieć wartości większe niż tylko zero',
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ return [
|
|||
'mass-update-status' => 'Você realmente deseja atualizar o status desses itens selecionados :resource?',
|
||||
'delete' => 'Você realmente deseja excluir este :resource?',
|
||||
'edit' => 'Você realmente quer editar este :resource?',
|
||||
'delete-category-product' => 'The selected categories contains products. Performing this action will remove the related products. Do you really want to perform this action?'
|
||||
],
|
||||
|
||||
'zero-index' => 'Colunas do índice podem ter valores maiores que zero apenas',
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ return [
|
|||
'mass-update-status' => 'Seçili :resource kayıtlarının durumunu güncellemek istediğinizden emin misiniz?',
|
||||
'delete' => 'Bu işlemi gerçekleştirmek istediğinizden emin misiniz?',
|
||||
'edit' => ':resource kaydını düzenlemek istediğinizden emin misiniz?',
|
||||
'delete-category-product' => 'The selected categories contains products. Performing this action will remove the related products. Do you really want to perform this action?'
|
||||
],
|
||||
|
||||
'zero-index' => 'Index sütunları sadece sıfırdan büyük değere sahip olmalı',
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
<span class="icon checkbox-dash-icon"></span>
|
||||
</span>
|
||||
|
||||
<form method="POST" id="mass-action-form" style="display: inline-flex;" action="" onsubmit="return confirm('{{ __('ui::app.datagrid.click_on_action') }}')">
|
||||
<form method="POST" id="mass-action-form" style="display: inline-flex;" action="" :onsubmit="`return confirm('${massActionConfirmText}')`">
|
||||
@csrf()
|
||||
|
||||
<input type="hidden" id="indexes" name="indexes" v-model="dataIds">
|
||||
|
|
|
|||
|
|
@ -272,6 +272,7 @@
|
|||
massActions: @json($results['massactions']),
|
||||
massActionsToggle: false,
|
||||
massActionTarget: null,
|
||||
massActionConfirmText: '{{ __('ui::app.datagrid.click_on_action') }}',
|
||||
massActionType: null,
|
||||
massActionValues: [],
|
||||
massActionTargets: [],
|
||||
|
|
@ -457,7 +458,8 @@
|
|||
for (let id in this.massActions) {
|
||||
targetObj = {
|
||||
'type': this.massActions[id].type,
|
||||
'action': this.massActions[id].action
|
||||
'action': this.massActions[id].action,
|
||||
'confirm_text': this.massActions[id].confirm_text
|
||||
};
|
||||
|
||||
this.massActionTargets.push(targetObj);
|
||||
|
|
@ -483,6 +485,7 @@
|
|||
for (let i in this.massActionTargets) {
|
||||
if (this.massActionTargets[i].type === 'delete') {
|
||||
this.massActionTarget = this.massActionTargets[i].action;
|
||||
this.massActionConfirmText = this.massActionTargets[i].confirm_text ? this.massActionTargets[i].confirm_text : this.massActionConfirmText;
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
@ -493,6 +496,7 @@
|
|||
for (let i in this.massActionTargets) {
|
||||
if (this.massActionTargets[i].type === 'update') {
|
||||
this.massActionTarget = this.massActionTargets[i].action;
|
||||
this.massActionConfirmText = this.massActionTargets[i].confirm_text ? this.massActionTargets[i].confirm_text : this.massActionConfirmText;
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue