mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-31 21:37:16 +00:00
On last item deletion, prevent user on order canceling and cancellation email
... with a modal. User can cancel the modal or confirm the last item deletion & order cancelation with or without sending a cancellation email to the consumer.
This commit is contained in:
@@ -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")}
|
||||
<div class="form">
|
||||
<input type="checkbox" name="send_cancellation_email" value="1" id="send_cancellation_email" />
|
||||
<label for="send_cancellation_email">${t("js.admin.orders.cancel_the_order_send_cancelation_email")}</label>
|
||||
</div>`);
|
||||
$('#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);
|
||||
|
||||
@@ -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 %>;
|
||||
</script>
|
||||
|
||||
@@ -148,5 +148,9 @@ table.index td.actions {
|
||||
.message {
|
||||
font-size: $h5-size;
|
||||
padding: 1.2em 0;
|
||||
|
||||
.form {
|
||||
padding: 1.2em 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.<br />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..."
|
||||
|
||||
Reference in New Issue
Block a user