<?xml version="1.0" encoding="UTF-8"?>
<modification>
	<name>Enable-Disable Products</name>
	<version>1.05</version>
	<author>AlexDW</author>
	<link>https://www.opencart.com/index.php?route=marketplace/extension&amp;filter_member=AlexDW</link>
	<code>enable-disable-products</code>
	<file path="admin/view/template/catalog/product_list.twig">
		<operation>
			<search index="0"><![CDATA[
<div class="pull-right">
			]]></search>
			<add position="replace"><![CDATA[
<!-- EnableDisable -->
      <div class="pull-right">
		<span style="padding-right:5px;">
        <button type="button" data-toggle="tooltip" title="{{ button_enable_product }}" class="btn btn-success" onclick="$('#form-product').attr('action', '{{ enable_product }}'); $('#form-product').submit();"><i class="fa fa-plus"></i></button>
        <button type="button" data-toggle="tooltip" title="{{ button_disable_product }}" class="btn btn-danger" onclick="$('#form-product').attr('action', '{{ disable_product }}'); $('#form-product').submit();"><i class="fa fa-minus"></i></button>
		</span>
		<span style="padding-right:10px;">
	  <a href="{{ enable_all }}" data-toggle="tooltip" title="{{ button_enable_all }}" data-confirm="{{ button_enable_all }}" class="btn btn-success"><i class="fa fa-check"></i></a>
	  <a href="{{ disable_all }}" data-toggle="tooltip" title="{{ button_disable_all }}" data-confirm="{{ button_disable_all }}" class="btn btn-danger"><i class="fa fa-power-off"></i></a>
		</span>
<!-- EnableDisable -->
			]]></add>
		</operation>
		<operation>
			<search><![CDATA[
{{ button_filter }}</button>
			]]></search>
			<add position="after"><![CDATA[
<!-- EnableDisable -->
			  <div class="pull-right">&nbsp;</div>
              <button type="button" id="button-clear" class="btn btn-info pull-right"><i class="fa fa-eraser"></i> Clear</button>
<!-- EnableDisable -->
			]]></add>
		</operation>
		<operation>
			<search><![CDATA[
{{ footer }}
			]]></search>
			<add position="before"><![CDATA[
<!-- EnableDisable -->
<script type="text/javascript"><!--
$(document).ready(function() {
	$('a[data-confirm]').click(function(ev) {
		var href = $(this).attr('href');
		if (!$('#dataConfirmModal').length) {
			$('body').append('<div id="dataConfirmModal" class="modal" role="dialog" aria-labelledby="dataConfirmLabel" aria-hidden="true"><div class="modal-dialog"><div class="modal-content"><div class="modal-body"></div><div class="modal-footer"><button class="btn btn-default" data-dismiss="modal" aria-hidden="true">{{ text_no }}</button><a class="btn btn-danger" id="dataConfirmOK">{{ text_yes }}</a></div></div></div></div>');
		} 
		$('#dataConfirmModal').find('.modal-body').text($(this).attr('data-confirm')+' ?');
		$('#dataConfirmOK').attr('href', href);
		$('#dataConfirmModal').modal({show:true});
		return false;
	});
});

$('#button-clear').on('click', function() {
	$('select[class=\'form-control\']').val('');
	$('input[class=\'form-control\']').val('');
	$('#button-filter').click();
});

$('input[class=\'form-control\']').keydown(function(e) {
	if (e.keyCode == 13) {
		$('#button-filter').click();
	}
});
//--></script>
			]]></add>
		</operation>
	</file>

	<file path="admin/controller/catalog/product.php">
		<operation error="skip">
			<search><![CDATA[
$data['delete'] = $this->url->link('catalog/product/delete', 'user_token=' . $this->session->data['user_token'] . $url, true);
			]]></search>
			<add position="after"><![CDATA[
		// EnableDisable
			$data['button_enable_all'] = $this->language->get('button_enable_all') !='button_enable_all' ? $this->language->get('button_enable_all') : 'Enable All Products';
			$data['button_disable_all'] = $this->language->get('button_disable_all') !='button_disable_all' ? $this->language->get('button_disable_all') : 'Disable All Products';
			$data['button_enable_product'] = $this->language->get('button_enable_product') !='button_enable_product' ? $this->language->get('button_enable_product') : 'Enable Selected';
			$data['button_disable_product'] = $this->language->get('button_disable_product') !='button_disable_product' ? $this->language->get('button_disable_product') : 'Disable Selected';

			$data['enable_all'] = $this->url->link('catalog/product/enable_all', 'user_token=' . $this->session->data['user_token'] . $url, true);
			$data['disable_all'] = $this->url->link('catalog/product/disable_all', 'user_token=' . $this->session->data['user_token'] . $url, true);
			$data['enable_product'] = $this->url->link('catalog/product/enable_product', 'user_token=' . $this->session->data['user_token'] . $url, true);
			$data['disable_product'] = $this->url->link('catalog/product/disable_product', 'user_token=' . $this->session->data['user_token'] . $url, true);
		// EnableDisable end
			]]></add>
		</operation>
	</file>

	<file path="admin/controller/catalog/product.php">
		<operation>
			<search><![CDATA[
public function delete() {
			]]></search>
			<add position="before"><![CDATA[
		// EnableDisable
	public function disable_all() {
		$this->load->language('catalog/product');
 
		$this->document->setTitle($this->language->get('heading_title'));
		
		$this->load->model('catalog/product');

		if (!$this->user->hasPermission('modify', 'catalog/product')) {
			$this->error['warning'] = $this->language->get('error_permission');

		} else {
			
			$this->model_catalog_product->disableAllProduct();
			
			$this->session->data['success'] = $this->language->get('text_success');

			$url = '';

			if (isset($this->request->get['filter_name'])) {
				$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
			}

			if (isset($this->request->get['filter_model'])) {
				$url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
			}

			if (isset($this->request->get['filter_price'])) {
				$url .= '&filter_price=' . $this->request->get['filter_price'];
			}

			if (isset($this->request->get['filter_quantity'])) {
				$url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
			}

			if (isset($this->request->get['filter_status'])) {
				$url .= '&filter_status=' . $this->request->get['filter_status'];
			}

			if (isset($this->request->get['sort'])) {
				$url .= '&sort=' . $this->request->get['sort'];
			}

			if (isset($this->request->get['order'])) {
				$url .= '&order=' . $this->request->get['order'];
			}

			if (isset($this->request->get['page'])) {
				$url .= '&page=' . $this->request->get['page'];
			}

			$this->response->redirect($this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'] . $url, true));
		}

		$this->getList();
	}

	public function enable_all() {
		$this->language->load('catalog/product');
 
		$this->document->setTitle($this->language->get('heading_title'));
		
		$this->load->model('catalog/product');

		if (!$this->user->hasPermission('modify', 'catalog/product')) {
			$this->error['warning'] = $this->language->get('error_permission');

		} else {
			
			$this->model_catalog_product->enableAllProduct();
			
			$this->session->data['success'] = $this->language->get('text_success');

			$url = '';

			if (isset($this->request->get['filter_name'])) {
				$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
			}

			if (isset($this->request->get['filter_model'])) {
				$url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
			}

			if (isset($this->request->get['filter_price'])) {
				$url .= '&filter_price=' . $this->request->get['filter_price'];
			}

			if (isset($this->request->get['filter_quantity'])) {
				$url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
			}

			if (isset($this->request->get['filter_status'])) {
				$url .= '&filter_status=' . $this->request->get['filter_status'];
			}

			if (isset($this->request->get['sort'])) {
				$url .= '&sort=' . $this->request->get['sort'];
			}

			if (isset($this->request->get['order'])) {
				$url .= '&order=' . $this->request->get['order'];
			}

			if (isset($this->request->get['page'])) {
				$url .= '&page=' . $this->request->get['page'];
			}

			$this->response->redirect($this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'] . $url, true));
		}

		$this->getList();
	}

	public function enable_product() {
		$this->language->load('catalog/product');
 
		$this->document->setTitle($this->language->get('heading_title'));
		
		$this->load->model('catalog/product');

		if (isset($this->request->post['selected']) && $this->validateDelete()) {
			foreach ($this->request->post['selected'] as $product_id) {
			$this->model_catalog_product->enableProduct($product_id);
			}

			$this->session->data['success'] = $this->language->get('text_success');

			$url = '';

			if (isset($this->request->get['filter_name'])) {
				$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
			}

			if (isset($this->request->get['filter_model'])) {
				$url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
			}

			if (isset($this->request->get['filter_price'])) {
				$url .= '&filter_price=' . $this->request->get['filter_price'];
			}

			if (isset($this->request->get['filter_quantity'])) {
				$url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
			}

			if (isset($this->request->get['filter_status'])) {
				$url .= '&filter_status=' . $this->request->get['filter_status'];
			}

			if (isset($this->request->get['sort'])) {
				$url .= '&sort=' . $this->request->get['sort'];
			}

			if (isset($this->request->get['order'])) {
				$url .= '&order=' . $this->request->get['order'];
			}

			if (isset($this->request->get['page'])) {
				$url .= '&page=' . $this->request->get['page'];
			}

			$this->response->redirect($this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'] . $url, true));
		}

		$this->getList();
	}

	public function disable_product() {
		$this->language->load('catalog/product');
 
		$this->document->setTitle($this->language->get('heading_title'));
		
		$this->load->model('catalog/product');

		if (isset($this->request->post['selected']) && $this->validateDelete()) {
			foreach ($this->request->post['selected'] as $product_id) {
			$this->model_catalog_product->disableProduct($product_id);
			}

			$this->session->data['success'] = $this->language->get('text_success');

			$url = '';

			if (isset($this->request->get['filter_name'])) {
				$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
			}

			if (isset($this->request->get['filter_model'])) {
				$url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
			}

			if (isset($this->request->get['filter_price'])) {
				$url .= '&filter_price=' . $this->request->get['filter_price'];
			}

			if (isset($this->request->get['filter_quantity'])) {
				$url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
			}

			if (isset($this->request->get['filter_status'])) {
				$url .= '&filter_status=' . $this->request->get['filter_status'];
			}

			if (isset($this->request->get['sort'])) {
				$url .= '&sort=' . $this->request->get['sort'];
			}

			if (isset($this->request->get['order'])) {
				$url .= '&order=' . $this->request->get['order'];
			}

			if (isset($this->request->get['page'])) {
				$url .= '&page=' . $this->request->get['page'];
			}

			$this->response->redirect($this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'] . $url, true));
		}

		$this->getList();
	}
		// EnableDisable end
			]]></add>
		</operation>
	</file>

	<file path="admin/model/catalog/product.php">		
		<operation>
			<search><![CDATA[
public function getProduct($product_id) {
			]]></search>
			<add position="before"><![CDATA[
	// EnableDisable
		public function disableAllProduct() {
			$query = $this->db->query("UPDATE " . DB_PREFIX . "product SET `status`='0' ");
			$this->cache->delete('product');
		}

		public function enableAllProduct() {
			$query = $this->db->query("UPDATE " . DB_PREFIX . "product SET `status`='1' ");
			$this->cache->delete('product');
		}

		public function enableProduct($product_id) {
			$this->db->query("UPDATE " . DB_PREFIX . "product SET `status`='1' WHERE product_id = '" . (int)$product_id . "'");
			$this->cache->delete('product');	
		}

		public function disableProduct($product_id) {
			$this->db->query("UPDATE " . DB_PREFIX . "product SET `status`='0' WHERE product_id = '" . (int)$product_id . "'");
			$this->cache->delete('product');	
		}
	// EnableDisable end
			]]></add>
		</operation>
	</file>

	<file path="admin/language/ru-ru/catalog/product.php">		
		<operation error="skip">
			<search><![CDATA[
<?php
			]]></search>
			<add position="after"><![CDATA[
			// EnableDisable
				$_['button_enable_all']    = 'Включить все товары';
				$_['button_disable_all']   = 'Отключить все товары';
				$_['button_enable_product']    = 'Включить выбранные';
				$_['button_disable_product']   = 'Отключить выбранные';
			// EnableDisable end
			]]></add>
		</operation>
	</file>
	<file path="admin/language/en-gb/catalog/product.php">		
		<operation error="skip">
			<search><![CDATA[
<?php
			]]></search>
			<add position="after"><![CDATA[
			// EnableDisable
				$_['button_enable_all']    = 'Enable All Products';
				$_['button_disable_all']   = 'Disable All Products';
				$_['button_enable_product']    = 'Enable Selected';
				$_['button_disable_product']   = 'Disable Selected';
			// EnableDisable end
			]]></add>
		</operation>
	</file>
</modification>