No OC version posted. However, the reason why that is for deleting one order at a time is due to the enforced use of the API with the default installation of Opencart. Since this request is about deletion rather than updating, there might be another option on doing this by rather capturing an array to delete all required orders at once to speed things up as I don't see how it would create any impact.
There seem to be available extensions on the marketplace but none that involves implicit use of the API.
In admin/view/template/sale/order_list.twig file,
find:
Code: Select all
<button type="submit" id="button-invoice" form="form-order" formaction="{{ invoice }}" formtarget="_blank" data-toggle="tooltip" title="{{ button_invoice_print }}" class="btn btn-info"><i class="fa fa-print"></i></button>
add below:
Code: Select all
<button type="submit" id="button-delete" form="form-order" data-toggle="tooltip" title="{{ button_delete }}" class="btn btn-info"><i class="fa fa-print"></i></button>
Then, find:
Code: Select all
$('#form-order li:last-child a').on('click', function(e) {
add above:
Code: Select all
$('#button-delete').on('click', function(e) {
e.preventDefault();
var element = this;
if (confirm('{{ text_confirm }}')) {
var selectedValues = $("input[name='selected[]']").map(function() {
return $(this).val();
}).get();
$.ajax({
url: '{{ catalog }}index.php?route=api/order/delete&api_token={{ api_token }}&store_id={{ store_id }}&order_ids=' + encodeURIComponent(selectedValues),
dataType: 'json',
beforeSend: function() {
$(element).parent().parent().parent().find('button').button('loading');
},
complete: function() {
$(element).parent().parent().parent().find('button').button('reset');
},
success: function(json) {
$('.alert-dismissible').remove();
if (json['error']) {
$('#content > .container-fluid').prepend('<div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + ' <button type="button" class="close" data-dismiss="alert">×</button></div>');
}
if (json['success']) {
location = '{{ delete }}';
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
}
});
In catalog/controller/api/order.php file,
find:
Code: Select all
if (isset($this->request->get['order_id'])) {
$order_id = $this->request->get['order_id'];
} else {
$order_id = 0;
}
$order_info = $this->model_checkout_order->getOrder($order_id);
if ($order_info) {
$this->model_checkout_order->deleteOrder($order_id);
$json['success'] = $this->language->get('text_success');
} else {
$json['error'] = $this->language->get('error_not_found');
}
replace with:
Code: Select all
if (!empty($this->request->get['order_ids'])) {
$multi_orders_check = array();
$order_ids = explode(',', trim($this->request->get['order_ids']));
foreach ($order_ids as $order_id) {
$order_info = $this->model_checkout_order->getOrder($order_id);
if ($order_info) {
$this->model_checkout_order->deleteOrder($order_id);
$multi_orders_check[] = true;
}
}
}
if (!empty($multi_orders_check)) {
if (in_array(true, $multi_orders_check)) {
$json['success'] = $this->language->get('text_success');
} elseif (!in_array(true, $multi_orders_check)) {
$json['error'] = $this->language->get('error_not_found');
}
}
if (empty($multi_orders_check)) {
if (isset($this->request->get['order_id'])) {
$order_id = $this->request->get['order_id'];
} else {
$order_id = 0;
}
$order_info = $this->model_checkout_order->getOrder($order_id);
if ($order_info) {
$this->model_checkout_order->deleteOrder($order_id);
$json['success'] = $this->language->get('text_success');
} else {
$json['error'] = $this->language->get('error_not_found');
}
}
This should rectify the issue.