fix: prevent deleting last address for each kind
This commit is contained in:
@@ -58,8 +58,25 @@ class CustomerController extends Controller
|
|||||||
|
|
||||||
public function delete_address($id)
|
public function delete_address($id)
|
||||||
{
|
{
|
||||||
$ret = CustomerAddresses::destroy($id);
|
$address = CustomerAddresses::get($id);
|
||||||
|
|
||||||
return redirect()->route('Shop.Customers.edit');
|
if (! $address || (int) $address->customer_id !== (int) Customers::getId()) {
|
||||||
|
abort(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$remaining = CustomerAddresses::getModel()
|
||||||
|
->byCustomer($address->customer_id)
|
||||||
|
->byType($address->type)
|
||||||
|
->count();
|
||||||
|
|
||||||
|
if ($remaining <= 1) {
|
||||||
|
return redirect()->route('Shop.Customers.edit')
|
||||||
|
->with('growl', [__('Vous devez conserver au moins une adresse par type.'), 'warning']);
|
||||||
|
}
|
||||||
|
|
||||||
|
CustomerAddresses::destroy($id);
|
||||||
|
|
||||||
|
return redirect()->route('Shop.Customers.edit')
|
||||||
|
->with('growl', [__('Adresse supprimée.'), 'success']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,29 @@
|
|||||||
|
// Simple notification helper used by blade templates (fallback to Bootstrap alerts)
|
||||||
|
window.growl = function(message, type) {
|
||||||
|
var alertTypes = {
|
||||||
|
success: 'alert-success',
|
||||||
|
error: 'alert-danger',
|
||||||
|
warning: 'alert-warning',
|
||||||
|
info: 'alert-info'
|
||||||
|
};
|
||||||
|
var cssClass = alertTypes[type] || alertTypes.info;
|
||||||
|
var $container = $('#growl-container');
|
||||||
|
|
||||||
|
if (!$container.length) {
|
||||||
|
$container = $('<div id="growl-container" class="growl-container position-fixed w-100" style="top: 1rem; left: 0; z-index: 1080; pointer-events: none;"></div>');
|
||||||
|
$('body').append($container);
|
||||||
|
}
|
||||||
|
|
||||||
|
var $alert = $('<div class="alert ' + cssClass + ' alert-dismissible fade show mx-auto shadow" role="alert" style="max-width: 420px; pointer-events: all;"></div>');
|
||||||
|
$alert.append($('<span></span>').text(message));
|
||||||
|
$alert.append('<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>');
|
||||||
|
$container.append($alert);
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
$alert.alert('close');
|
||||||
|
}, 4000);
|
||||||
|
};
|
||||||
|
|
||||||
// Prevent closing from click inside dropdown
|
// Prevent closing from click inside dropdown
|
||||||
$(document).on('click', '.dropdown-menu', function (e) {
|
$(document).on('click', '.dropdown-menu', function (e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|||||||
Reference in New Issue
Block a user