diff --git a/app/assets/javascripts/admin/spree/orders/variant_autocomplete.js.erb b/app/assets/javascripts/admin/spree/orders/variant_autocomplete.js.erb index abfd1bacd6..90e4c9a14d 100644 --- a/app/assets/javascripts/admin/spree/orders/variant_autocomplete.js.erb +++ b/app/assets/javascripts/admin/spree/orders/variant_autocomplete.js.erb @@ -82,7 +82,15 @@ adjustItems = function(shipment_number, variant_id, quantity){ var inventory_units = _.where(shipment.inventory_units, {variant_id: variant_id}); if (quantity == 0 && inventory_units.length == shipment.inventory_units.length) { - ofnAlert(t("js.admin.orders.cannot_remove_last_item")); + ofnCancelOrderAlert((confirm, sendEmailCancellation) => { + if (confirm) { + doAdjustItems(shipment_number, variant_id, quantity, inventory_units, () => { + var redirectTo = new URL(Spree.routes.cancel_order.toString()); + redirectTo.searchParams.append("send_cancellation_email", sendEmailCancellation); + window.location.href = redirectTo.toString(); + }); + } + }); return; } doAdjustItems(shipment_number, variant_id, quantity, inventory_units, () => { @@ -186,6 +194,24 @@ ofnAlert = function(message) { $('#custom-alert').show(); } +ofnCancelOrderAlert = function(callback) { + $('#custom-confirm .message').html( + ` ${t("js.admin.orders.cancel_the_order_html")} +
+ + +
`); + $('#custom-confirm button.confirm').unbind( "click" ).click(() => { + $('#custom-confirm').hide(); + callback(true, $('#send_cancellation_email').is(':checked')); + }); + $('#custom-confirm button.cancel').click(() => { + $('#custom-confirm').hide(); + callback(false) + }); + $('#custom-confirm').show(); +} + ofnConfirm = function(callback) { $('#custom-confirm').data($(event.target).data()); $('#custom-confirm button.confirm').click(callback); diff --git a/app/views/spree/admin/shared/_routes.html.erb b/app/views/spree/admin/shared/_routes.html.erb index a0a854781f..dc8fac6b9d 100644 --- a/app/views/spree/admin/shared/_routes.html.erb +++ b/app/views/spree/admin/shared/_routes.html.erb @@ -9,6 +9,7 @@ :variants_search => spree.admin_search_variants_url(:format => 'json'), :taxons_search => main_app.api_v0_taxons_url(:format => 'json'), :orders_api => main_app.api_v0_orders_url, - :states_search => main_app.api_v0_states_url(:format => 'json') + :states_search => main_app.api_v0_states_url(:format => 'json'), + :cancel_order => spree.fire_admin_order_url(id: @order ? @order.number : "", e: 'cancel') }.to_json %>; diff --git a/app/webpacker/css/admin/orders.scss b/app/webpacker/css/admin/orders.scss index 2316b27f66..8f5b724c35 100644 --- a/app/webpacker/css/admin/orders.scss +++ b/app/webpacker/css/admin/orders.scss @@ -148,5 +148,9 @@ table.index td.actions { .message { font-size: $h5-size; padding: 1.2em 0; + + .form { + padding: 1.2em 0; + } } } diff --git a/config/locales/en.yml b/config/locales/en.yml index 6c23d73022..122f1d0726 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3030,7 +3030,8 @@ See the %{link} to find out more about %{sitename}'s features and to start using invalid: "invalid" quantity_adjusted: "Insufficient stock available. Line item updated to maximum available quantity." quantity_unchanged: "Quantity unchanged from previous amount." - cannot_remove_last_item: "Cannot remove last item from order. Please cancel order instead." + cancel_the_order_html: "This will cancel the current order.
Are you sure you want to proceed?" + cancel_the_order_send_cancelation_email: "Send a cancellation email to the customer" resend_user_email_confirmation: resend: "Resend" sending: "Resend..."