Post by banarsumboro07 » Sat Dec 09, 2017 8:27 pm

How to make mass delete button for order_list?

I have put this

Code: Select all

<button type="submit" form="form-order" formaction="{{ delete }}" data-toggle="tooltip" title="{{ button_delete }}" class="btn btn-danger" onclick="confirm('{{ text_confirm }}') ? $('#form-order').submit() : false;"><i class="fa fa-trash-o"></i></button>
in admin/view/template/sale/order_list.twig

the result is... delete button appears but not functioning well. So every time I select all orders I want to delete, and click the delete button, it just reload the page without deleting the list

how to solve this?


Posts

Joined
Fri Dec 01, 2017 6:18 pm

Post by straightlight » Mon Dec 11, 2017 12:10 am

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">&times;</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.
Last edited by straightlight on Mon Dec 11, 2017 12:47 am, edited 2 times in total.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


Legendary Member
Online

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by straightlight » Mon Dec 11, 2017 12:41 am

Posted updated above.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


Legendary Member
Online

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by kg0925 » Sat Mar 30, 2019 10:04 pm

straightlight wrote:
Mon Dec 11, 2017 12:10 am
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">&times;</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.
it's not working properly. it's deleting all orders available on page even if it's not selected.

New member

Posts

Joined
Wed Mar 29, 2017 11:09 pm

Post by straightlight » Sat Mar 30, 2019 11:25 pm

it's not working properly.
OC version? Forum rules.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


Legendary Member
Online

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by kg0925 » Sun Apr 07, 2019 5:34 pm

OC version 3.0.3.1

New member

Posts

Joined
Wed Mar 29, 2017 11:09 pm

Post by hermes23 » Sat Oct 12, 2019 2:51 pm

Not working in 3.0.3.2. Can you update the code if you have time?
Thanks :)

Newbie

Posts

Joined
Mon Apr 16, 2018 8:29 am
Who is online

Users browsing this forum: No registered users and 15 guests