<?xml version="1.0" encoding="UTF-8"?>
<modification>
	<name>Mp Tier Price</name>
	<code>mp-tier-price</code>
	<version>1.0</version>
	<author>ModulePoints</author>

	<!-- Admin section starts -->
	<file path="admin/controller/catalog/product.php">
		<operation info="function getlist">
			<search><![CDATA[$data['button_add']]]></search>
			<add position="before"><![CDATA[
			/*mp tier price starts*/
			$this->load->language('catalog/mptierprice');
			$data['entry_tier_price'] = $this->language->get('entry_tier_price');
			$data['entry_from'] = $this->language->get('entry_from');
			$data['entry_to'] = $this->language->get('entry_to');
			$data['entry_price_discount'] = $this->language->get('entry_price_discount');
			$data['entry_discount_type'] = $this->language->get('entry_discount_type');
			$data['entry_customer_group_all'] = $this->language->get('entry_customer_group_all');
			$data['entry_store_all'] = $this->language->get('entry_store_all');

			$data['entry_sort_order'] = $this->language->get('entry_sort_order');
			$data['entry_store'] = $this->language->get('entry_store');
			$data['entry_customer_group'] = $this->language->get('entry_customer_group');
			$data['entry_delete_tier_price'] = $this->language->get('entry_delete_tier_price');

			$data['text_tier_price'] = $this->language->get('text_tier_price');
			$data['text_yes'] = $this->language->get('text_yes');
			$data['text_no'] = $this->language->get('text_no');

			$data['button_bulk_tier_price'] = $this->language->get('button_bulk_tier_price');
			$data['button_cancel'] = $this->language->get('button_cancel');
			$data['button_remove'] = $this->language->get('button_remove');
			$data['button_tierprice_add'] = $this->language->get('button_tierprice_add');

			$data['mptierprice_status'] = $this->config->get('mptierprice_status');

			$this->load->model('customer/customer_group');

			$data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups();

			$this->load->model('setting/store');
			$stores = $this->model_setting_store->getStores();

			$data['mp_stores'] = array();
			$data['mp_stores'][] = array(
				'store_id' => '0',
				'name' => $this->language->get('text_default'),
			);
			foreach ($stores as $key => $value) {
				$data['mp_stores'][] = array(
					'store_id' => $value['store_id'],
					'name' => $value['name'],
				);
			}

			$data['mpdiscount_types'] = array();
			$data['mpdiscount_types'][] = array(
				'type' => 'DP',
				'name' => $this->language->get('entry_discount_percent'),
			);
			$data['mpdiscount_types'][] = array(
				'type' => 'DA',
				'name' => $this->language->get('entry_discount_amount'),
			);
			$data['mpdiscount_types'][] = array(
				'type' => 'FP',
				'name' => $this->language->get('entry_fixed_price'),
			);
			/*mp tier price ends*/
			]]></add>
		</operation>
		<operation info="function getform">
			<search><![CDATA[$data['entry_stock_status']]]></search>
			<add position="before"><![CDATA[
			/*mp tier price starts*/
			$this->load->language('catalog/mptierprice');
			$data['entry_tier_price'] = $this->language->get('entry_tier_price');
			$data['entry_from'] = $this->language->get('entry_from');
			$data['entry_to'] = $this->language->get('entry_to');
			$data['entry_price_discount'] = $this->language->get('entry_price_discount');
			$data['entry_discount_type'] = $this->language->get('entry_discount_type');
			$data['entry_customer_group_all'] = $this->language->get('entry_customer_group_all');
			$data['entry_store_all'] = $this->language->get('entry_store_all');

			$data['button_tierprice_add'] = $this->language->get('button_tierprice_add');
			/*mp tier price ends*/
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[$data['recurrings']]]></search>
			<add position="before"><![CDATA[
			/*mp tier price starts*/
			$data['mptierprice_status'] = $this->config->get('mptierprice_status');

			if (isset($this->request->post['product_mp_tierprices'])) {
				$product_mp_tierprices = $this->request->post['product_mp_tierprices'];
			} elseif (!empty($product_info)) {
				if($this->config->get('mptierprice_status')) {
					$product_mp_tierprices = $this->model_catalog_product->getMpTierPrices($product_info
					['product_id']);
				} else {
					$product_mp_tierprices = array();
				}
			} else {
				$product_mp_tierprices = array();
			}

			$data['product_mp_tierprices'] = array();

			foreach ($product_mp_tierprices as $product_mp_tierprice) {
				$data['product_mp_tierprices'][] = array(
					'product_mptierprices_id' => $product_mp_tierprice['product_mptierprices_id'],
					'product_id' => $product_mp_tierprice['product_id'],
					'customer_group_id' => $product_mp_tierprice['customer_group_id'],
					'from_quantity' => $product_mp_tierprice['from_quantity'],
					'to_quantity' => $product_mp_tierprice['to_quantity'],
					'store_id' => $product_mp_tierprice['store_id'],
					'discount_type' => $product_mp_tierprice['discount_type'],
					'price' => $product_mp_tierprice['price'],
					'sort_order' => $product_mp_tierprice['sort_order'],
				);
			}

			$this->load->model('setting/store');
			$stores = $this->model_setting_store->getStores();

			$data['mp_stores'] = array();
			$data['mp_stores'][] = array(
				'store_id' => '0',
				'name' => $this->language->get('text_default'),
			);
			foreach ($stores as $key => $value) {
				$data['mp_stores'][] = array(
					'store_id' => $value['store_id'],
					'name' => $value['name'],
				);
			}

			$data['mpdiscount_types'] = array();
			$data['mpdiscount_types'][] = array(
				'type' => 'DP',
				'name' => $this->language->get('entry_discount_percent'),
			);
			$data['mpdiscount_types'][] = array(
				'type' => 'DA',
				'name' => $this->language->get('entry_discount_amount'),
			);
			$data['mpdiscount_types'][] = array(
				'type' => 'FP',
				'name' => $this->language->get('entry_fixed_price'),
			);
			/*mp tier price ends*/
			]]></add>
		</operation>
		<operation info="function getform">
			<search><![CDATA[protected function getList() {]]></search>
			<add position="before"><![CDATA[
			/*mp tier price starts*/
			public function mpBulkTierPrice() {
				$json = array();
				$this->load->language('catalog/mptierprice');

				$this->load->model('catalog/product');

				if($this->config->get('mptierprice_status')) {
					if (!isset($this->request->post['selected']) && !isset($this->request->post['product_mp_tierprice'])) {
						$json['warning'] = $this->language->get('error_request_invalid');
					}

					if(empty($this->request->post['selected'])) {
						$json['error']['no_product'] = $this->language->get('error_no_product');
					}
					if(empty($this->request->post['product_mp_tierprice'])) {
						$json['error']['no_tierprice'] = $this->language->get('error_no_tierprice');
					}

					if(!empty($this->request->post['product_mp_tierprice'])) {
						foreach($this->request->post['product_mp_tierprice'] as $key => $product_mp_tierprice) {

							if(empty($product_mp_tierprice['from_quantity'])) {
								$json['error']['product_mp_tierprice']['from_quantity'] = $this->language->get('error_no_quantity');
							}
							if(empty($product_mp_tierprice['price'])) {
								$json['error']['product_mp_tierprice']['price'] = $this->language->get('error_no_price');
							}

						}
					}

					if(!$json) {
						foreach($this->request->post['selected'] as $product_id) {
							$this->model_catalog_product->mpBulkTierPriceAssign($product_id, $this->request->post);
						}
						$json['success'] = $this->language->get('text_success_tier_price');
					}
				} else {
					$json['warning'] = $this->language->get('entry_tier_price');
				}
				$this->response->addHeader('Content-Type: application/json');
				$this->response->setOutput(json_encode($json));
			}
			/*mp tier price ends*/
			]]></add>
		</operation>
	</file>
	<file path="admin/model/catalog/product.php">
		<operation error="log">
			<search><![CDATA[if (isset($data['product_store'])) {]]></search>
			<add position="before"><![CDATA[
			/*mp tier price starts*/
			if($this->config->get('mptierprice_status')) {
				$this->db->query("DELETE FROM " . DB_PREFIX . "product_mptierprices WHERE product_id = '" . (int)$product_id . "'");
				if (isset($data['product_mp_tierprice'])) {
					foreach ($data['product_mp_tierprice'] as $mp_tierprice) {
						$this->db->query("INSERT INTO " . DB_PREFIX . "product_mptierprices SET product_mptierprices_id = '" . (int)$mp_tierprice['product_mptierprices_id'] . "', product_id = '" . (int)$product_id . "', store_id = '" . $this->db->escape($mp_tierprice['store_id']) . "', customer_group_id = '" . $this->db->escape($mp_tierprice['customer_group_id']) . "', from_quantity = '" . (int)$mp_tierprice['from_quantity'] . "', to_quantity = '" . (int)$mp_tierprice['to_quantity'] . "', discount_type = '" . $this->db->escape($mp_tierprice['discount_type']) . "', price = '" . $this->db->escape($mp_tierprice['price']) . "', sort_order = '" . (int)$mp_tierprice['sort_order'] . "'");
					}
				}
			}
			/*mp tier price ends*/
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[public function getProduct(]]></search>
			<add position="before"><![CDATA[
			/*mp tier price starts*/
			public function getMpTierPrices($product_id) {
				$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "product_mptierprices` WHERE product_id = '" . (int)$product_id . "' ORDER BY customer_group_id, sort_order");

				return $query->rows;
			}

			public function mpBulkTierPriceAssign($product_id, $data) {

				if(isset($data['product_mp_tierprice']) && isset($data['delete_tier_price']) && $data['delete_tier_price'] == 1) {
					$this->db->query("DELETE FROM " . DB_PREFIX . "product_mptierprices WHERE product_id = '" . (int)$product_id . "'");
				}

				if (isset($data['product_mp_tierprice'])) {
					foreach ($data['product_mp_tierprice'] as $mp_tierprice) {
						$this->db->query("INSERT INTO " . DB_PREFIX . "product_mptierprices SET  product_id = '" . (int)$product_id . "', store_id = '" . $this->db->escape($mp_tierprice['store_id']) . "', customer_group_id = '" . $this->db->escape($mp_tierprice['customer_group_id']) . "', from_quantity = '" . (int)$mp_tierprice['from_quantity'] . "', to_quantity = '" . (int)$mp_tierprice['to_quantity'] . "', discount_type = '" . $this->db->escape($mp_tierprice['discount_type']) . "', price = '" . $this->db->escape($mp_tierprice['price']) . "', sort_order = '" . (int)$mp_tierprice['sort_order'] . "'");
					}
				}
			}
			/*mp tier price ends*/
			]]></add>
		</operation>
	</file>
	<file path="admin/view/template/catalog/product_list.tpl">
		<operation error="log">
			<search><![CDATA[<button type="button" data-toggle="tooltip" title="<?php echo $button_delete; ?>" class="btn btn-danger" onclick="confirm('<?php echo $text_confirm; ?>') ? $('#form-product').submit() : false;"><i class="fa fa-trash-o"></i></button>]]></search>
			<add position="before"><![CDATA[
				<?php if($mptierprice_status) { ?>
				<!-- /*mp tier price starts*/ -->
				<button type="button" data-toggle="tooltip" title="<?php echo $button_bulk_tier_price; ?>" class="btn btn-warning" id="mp-bulk_tierprice"><i class="fa fa-cogs"></i></button>
				<!-- /*mp tier price ends*/ -->
				<?php } ?>
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[<form action="<?php echo $delete; ?>"]]></search>
			<add position="before"><![CDATA[
				<?php if($mptierprice_status) { ?>
				<!-- /*mp tier price starts*/ -->
				<div class="modal fade" id="mp_bulk_tierprice">
				  <div class="modal-dialog modal-lg" role="document">
				    <div class="modal-content">
				      <div class="modal-header">
				        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				        <h3 class="modal-title"><?php echo $text_tier_price; ?></h3>
				      </div>
				      <div class="modal-body">
				      	<h4><?php echo $entry_tier_price; ?></h4>
				      	<div class="form-horizontal">
				      	  <div class="table-responsive">
						    <table id="mp-tierprice" class="table table-striped table-bordered table-hover">
						      <thead>
						        <tr>
						          <td class="text-left"><?php echo $entry_store; ?></td>
						          <td class="text-left"><?php echo $entry_customer_group; ?></td>
						          <td class="text-left"><?php echo $entry_quantity; ?></td>
						          <td class="text-left"><?php echo $entry_price_discount; ?></td>
						          <td class="text-left"><?php echo $entry_discount_type; ?></td>
						          <td class="text-left"><?php echo $entry_sort_order; ?></td>
						          <td></td>
						        </tr>
						      </thead>
						      <tbody></tbody>
						      <tfoot>
						        <tr>
						          <td colspan="6"></td>
						          <td class="text-left"><button type="button" onclick="addMpTierPrice();" data-toggle="tooltip" title="<?php echo $button_tierprice_add; ?>" class="btn btn-primary mptierprice_add"><i class="fa fa-plus-circle"></i></button></td>
						        </tr>
						      </tfoot>
						    </table>
						  </div>
						  <div class="form-group">
			                <label class="col-sm-2 control-label"><?php echo $entry_delete_tier_price; ?></label>
			                <div class="col-sm-10">
			                  <label class="radio-inline">
			                    <input type="radio" name="delete_tier_price" value="1" />
			                    <?php echo $text_yes; ?>
			                  </label>
			                  <label class="radio-inline">
			                    <input type="radio" name="delete_tier_price" value="0" checked="checked" />
			                    <?php echo $text_no; ?>
			                  </label>
			                </div>
			              </div>
				      	</div>
				      </div>
				      <div class="modal-footer">
				        <button type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo $button_cancel; ?></button>
				        <button type="button" class="btn btn-primary mp_bulk_tier_price"><?php echo $button_bulk_tier_price; ?></button>
				      </div>
				    </div>
				  </div>
				</div>
				<!-- /*mp tier price ends*/ -->
				<?php } ?>
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[<?php echo $footer; ?]]></search>
			<add position="before"><![CDATA[
			<!-- /*mp tier price starts*/ -->
			<?php if($mptierprice_status) { ?>
			<script type="text/javascript"><!--

			var mp_tierprice_row = 0;

			function addMpTierPrice() {
			  html  = '<tr class="mp_tierprice-row" id="mp_tierprice-row' + mp_tierprice_row + '">';
			  html += '  <td class="text-left">';
			  html += '    <input type="hidden" name="product_mp_tierprice[' + mp_tierprice_row + '][product_mptierprices_id]" value="0" />';
			  html += '    <select name="product_mp_tierprice[' + mp_tierprice_row + '][store_id]" class="form-control">';
			  html += '       <option value="*"><?php echo $entry_store_all; ?></option>';
			              <?php foreach ($mp_stores as $store) { ?>
			  html += '       <option value="<?php echo $store['store_id']; ?>"><?php echo $store['name']; ?></option>';
			              <?php } ?>
			  html += '    </select>';
			  html += '  </td>';
			   html += '  <td class="text-left">';
			  html += '    <select name="product_mp_tierprice[' + mp_tierprice_row + '][customer_group_id]" class="form-control">';
			  html += '       <option value="*"><?php echo $entry_customer_group_all; ?></option>';
			              <?php foreach ($customer_groups as $customer_group) { ?>
			  html += '       <option value="<?php echo $customer_group['customer_group_id']; ?>"><?php echo $customer_group['name']; ?></option>';
			              <?php } ?>
			  html += '    </select>';
			  html += '  </td>';
			  html += '  <td class="text-left"><div class="input-group"><input type="text" name="product_mp_tierprice[' + mp_tierprice_row + '][from_quantity]" value="" placeholder="<?php echo $entry_from; ?>" class="form-control" /><span class="input-group-btn"><button class="btn btn-primary" type="button" style="border-radius: 0;"><i class="fa fa-arrows-h"></i></button></span><input type="text" name="product_mp_tierprice[' + mp_tierprice_row + '][to_quantity]" value="" placeholder="<?php echo $entry_to; ?>" class="form-control" /></div></td>';
			  html += '  <td class="text-left"><input type="text" name="product_mp_tierprice[' + mp_tierprice_row + '][price]" value="" placeholder="<?php echo $entry_price_discount; ?>" class="form-control" /></td>';
			     html += '  <td class="text-left">';
			  html += '    <select name="product_mp_tierprice[' + mp_tierprice_row + '][discount_type]" class="form-control">';
			              <?php foreach ($mpdiscount_types as $mpdiscount_type) { ?>
			  html += '       <option value="<?php echo $mpdiscount_type['type']; ?>"><?php echo $mpdiscount_type['name']; ?></option>';
			              <?php } ?>
			  html += '    </select>';
			  html += '  </td>';
			  html += '  <td class="text-left"><input type="text" name="product_mp_tierprice[' + mp_tierprice_row + '][sort_order]" value="" placeholder="<?php echo $entry_sort_order; ?>" class="form-control" /></td>';
			  html += '  <td class="text-left"><button type="button" onclick="$(\'#mp_tierprice-row' + mp_tierprice_row  + '\').remove();" data-toggle="tooltip" title="<?php echo $button_remove; ?>" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>';
			  html += '</tr>';
			  $('#mp-tierprice > tbody').append(html);
			  mp_tierprice_row++;
			}

			$('#mp-bulk_tierprice').on('click', function() {
				$('#mp_bulk_tierprice').modal('show');
			});
			$('#mp_bulk_tierprice').on('hidden.bs.modal', function() {
				$('#mp_bulk_tierprice').find('.alert, .text-danger').remove();
			});
			$('#mp_bulk_tierprice').on('shown.bs.modal', function() {
				if(mp_tierprice_row == 0) {
					$('.mptierprice_add').trigger('click');
				}
			});

			$('.mp_bulk_tier_price').on('click', function() {

				var $this = $(this);

				$('#mp_bulk_tierprice').find('.alert, .text-danger').remove();

				$.ajax({
					url: 'index.php?route=catalog/product/mpBulkTierPrice&token=<?php echo $token; ?>',
					type: 'post',
					data: $('#mp_bulk_tierprice input[type="text"],#mp_bulk_tierprice input[type="radio"]:checked, #mp_bulk_tierprice select, input[name*=\'selected\']:checked'),
					dataType: 'json',
					beforeSend: function() {
						$this.button('loading');
					},
					complete: function() {
						$this.button('reset');
					},
					success: function(json) {
						$('#mp_bulk_tierprice').find('.alert, .text-danger').remove();

						if (json['error']) {
							if(typeof json['error']['no_product'] != 'undefined') {
								$('#mp-tierprice').before('<div class="alert alert-danger"><i class="fa fa-check-circle"></i> ' + json['error']['no_product'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
							}

							if(typeof json['error']['no_tierprice'] != 'undefined') {
								$('#mp-tierprice').before('<div class="alert alert-danger"><i class="fa fa-check-circle"></i> ' + json['error']['no_tierprice'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
							}

							if(typeof json['error']['product_mp_tierprice'] != 'undefined') {
								var error = '';
								for(var i in json['error']['product_mp_tierprice']) {
									error += json['error']['product_mp_tierprice'][i] + '<br/>';
								}
								if(error) {
									$('#mp-tierprice').after('<div class="text text-danger"> ' + error + ' </div>');
								}
							}
						}
						if (json['warning']) {
							$('#mp_bulk_tierprice').find('.modal-header').before('<div class="alert alert-danger"><i class="fa fa-check-circle"></i> ' + json['warning'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
						}

						if (json['success']) {
							$('#mp_bulk_tierprice').find('.modal-header').before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');

							setTimeout(function() {
								$('#mp-tierprice > tbody').html('');
		  						mp_tierprice_row = 0;
		  						$('#mp_bulk_tierprice').modal('hide');
							}, 3000);

						}
					},
					error: function(xhr, ajaxOptions, thrownError) {
						alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
					}
				});
			});
			//--></script>
			<?php } ?>
			<!-- /*mp tier price ends*/ -->
			]]></add>
		</operation>
	</file>
	<file path="admin/view/template/catalog/product_form.tpl">
		<operation error="log">
			<search><![CDATA[<label class="col-sm-2 control-label" for="input-tax-class"><?php echo $entry_tax_class; ?></label>]]></search>
			<add position="before" offset="1"><![CDATA[
			<?php if($mptierprice_status) { ?>
			<!-- /*mp tier price starts*/ -->
			<div class="form-group">
				<label class="col-sm-2 control-label" for="input-tier_price"><?php echo $entry_tier_price; ?></label>
				<div class="col-sm-10">
				  <div class="table-responsive">
				    <table id="mp-tierprice" class="table table-striped table-bordered table-hover">
				      <thead>
				        <tr>
				          <td class="text-left"><?php echo $entry_store; ?></td>
				          <td class="text-left"><?php echo $entry_customer_group; ?></td>
				          <td class="text-left"><?php echo $entry_quantity; ?></td>
				          <td class="text-left"><?php echo $entry_price_discount; ?></td>
				          <td class="text-left"><?php echo $entry_discount_type; ?></td>
				          <td class="text-left"><?php echo $entry_sort_order; ?></td>
				          <td></td>
				        </tr>
				      </thead>
				      <tbody>
				        <?php $mp_tierprice_row = 0; ?>
				        <?php foreach ($product_mp_tierprices as $product_mp_tierprice) { ?>
				        <tr id="mp_tierprice-row<?php echo $mp_tierprice_row; ?>">
				          <td class="text-left">
				            <input type="hidden" name="product_mp_tierprice[<?php echo $mp_tierprice_row; ?>][product_mptierprices_id]" value="<?php echo $product_mp_tierprice['product_mptierprices_id']; ?>" />
				            <select name="product_mp_tierprice[<?php echo $mp_tierprice_row; ?>][store_id]" class="form-control">
				              <option value="*"><?php echo $entry_store_all; ?></option>
				            <?php foreach ($mp_stores as $store) { ?>
				              <?php if ($store['store_id'] == $product_mp_tierprice['store_id']) { ?>
				              <option selected="selected" value="<?php echo $store['store_id']; ?>"><?php echo $store['name']; ?></option>
				            <?php } else { ?>
				            <option value="<?php echo $store['store_id']; ?>"><?php echo $store['name']; ?></option>
				            <?php } ?>
				            <?php } ?>
				            </select>
				          </td>
				          <td class="text-left">
				            <select name="product_mp_tierprice[<?php echo $mp_tierprice_row; ?>][customer_group_id]" class="form-control">
				              <option value="*"><?php echo $entry_customer_group_all; ?></option>
				            <?php foreach ($customer_groups as $customer_group) { ?>
				              <?php if ($customer_group['customer_group_id'] == $product_mp_tierprice['customer_group_id']) { ?>
				              <option selected="selected" value="<?php echo $customer_group['customer_group_id']; ?>"><?php echo $customer_group['name']; ?></option>
				            <?php } else { ?>
				            <option value="<?php echo $customer_group['customer_group_id']; ?>"><?php echo $customer_group['name']; ?></option>
				            <?php } ?>
				            <?php } ?>
				            </select>
				          </td>
				          <td class="text-left"><div class="input-group"><input type="text" name="product_mp_tierprice[<?php echo $mp_tierprice_row; ?>][from_quantity]" value="<?php echo $product_mp_tierprice['from_quantity']; ?>" placeholder="<?php echo $entry_from; ?>" class="form-control" /><span class="input-group-btn"><button class="btn btn-primary" type="button" style="border-radius: 0;"><i class="fa fa-arrows-h"></i></button></span><input type="text" name="product_mp_tierprice[<?php echo $mp_tierprice_row; ?>][to_quantity]" value="<?php echo $product_mp_tierprice['to_quantity'] != '0' ? $product_mp_tierprice['to_quantity'] : ''; ?>" placeholder="<?php echo $entry_to; ?>" class="form-control" /></div></td>
				          <td class="text-left"><input type="text" name="product_mp_tierprice[<?php echo $mp_tierprice_row; ?>][price]" value="<?php echo $product_mp_tierprice['price']; ?>" placeholder="<?php echo $entry_price_discount; ?>" class="form-control" /></td>
				          <td class="text-left">
				            <select name="product_mp_tierprice[<?php echo $mp_tierprice_row; ?>][discount_type]" class="form-control">
				            <?php foreach ($mpdiscount_types as $mpdiscount_type) { ?>
				              <?php if ($mpdiscount_type['type'] == $product_mp_tierprice['discount_type']) { ?>
				              <option selected="selected" value="<?php echo $mpdiscount_type['type']; ?>"><?php echo $mpdiscount_type['name']; ?></option>
				            <?php } else { ?>
				            <option value="<?php echo $mpdiscount_type['type']; ?>"><?php echo $mpdiscount_type['name']; ?></option>
				            <?php } ?>
				            <?php } ?>
				            </select>
				          </td>
				          <td class="text-left"><input type="text" name="product_mp_tierprice[<?php echo $mp_tierprice_row; ?>][sort_order]" value="<?php echo $product_mp_tierprice['sort_order']; ?>" placeholder="<?php echo $entry_sort_order; ?>" class="form-control" /></td>
				          <td class="text-left"><button type="button" onclick="$('#mp_tierprice-row<?php echo $mp_tierprice_row; ?>').remove();" data-toggle="tooltip" title="<?php echo $button_remove; ?>" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>
				        </tr>
				        <?php $mp_tierprice_row++; ?>
				        <?php } ?>
				      </tbody>
				      <tfoot>
				        <tr>
				          <td colspan="6"></td>
				          <td class="text-left"><button type="button" onclick="addMpTierPrice();" data-toggle="tooltip" title="<?php echo $button_tierprice_add; ?>" class="btn btn-primary"><i class="fa fa-plus-circle"></i></button></td>
				        </tr>
				      </tfoot>
				    </table>
				  </div>
				</div>
			</div>
			<!-- /*mp tier price ends*/ -->
			<?php } ?>
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[<?php echo $footer; ?]]></search>
			<add position="before"><![CDATA[
			<!-- /*mp tier price starts*/ -->
			<?php if($mptierprice_status) { ?>
			<script type="text/javascript"><!--
			var mp_tierprice_row = <?php echo $mp_tierprice_row; ?>;

			function addMpTierPrice() {
			  html  = '<tr class="mp_tierprice-row" id="mp_tierprice-row' + mp_tierprice_row + '">';
			  html += '  <td class="text-left">';
			  html += '    <input type="hidden" name="product_mp_tierprice[' + mp_tierprice_row + '][product_mptierprices_id]" value="0" />';
			  html += '    <select name="product_mp_tierprice[' + mp_tierprice_row + '][store_id]" class="form-control">';
			  html += '       <option value="*"><?php echo $entry_store_all; ?></option>';
			              <?php foreach ($mp_stores as $store) { ?>
			  html += '       <option value="<?php echo $store['store_id']; ?>"><?php echo $store['name']; ?></option>';
			              <?php } ?>
			  html += '    </select>';
			  html += '  </td>';
			   html += '  <td class="text-left">';
			  html += '    <select name="product_mp_tierprice[' + mp_tierprice_row + '][customer_group_id]" class="form-control">';
			  html += '       <option value="*"><?php echo $entry_customer_group_all; ?></option>';
			              <?php foreach ($customer_groups as $customer_group) { ?>
			  html += '       <option value="<?php echo $customer_group['customer_group_id']; ?>"><?php echo $customer_group['name']; ?></option>';
			              <?php } ?>
			  html += '    </select>';
			  html += '  </td>';
			  html += '  <td class="text-left"><div class="input-group"><input type="text" name="product_mp_tierprice[' + mp_tierprice_row + '][from_quantity]" value="" placeholder="<?php echo $entry_from; ?>" class="form-control" /><span class="input-group-btn"><button class="btn btn-primary" type="button" style="border-radius: 0;"><i class="fa fa-arrows-h"></i></button></span><input type="text" name="product_mp_tierprice[' + mp_tierprice_row + '][to_quantity]" value="" placeholder="<?php echo $entry_to; ?>" class="form-control" /></div></td>';
			  html += '  <td class="text-left"><input type="text" name="product_mp_tierprice[' + mp_tierprice_row + '][price]" value="" placeholder="<?php echo $entry_price_discount; ?>" class="form-control" /></td>';
			     html += '  <td class="text-left">';
			  html += '    <select name="product_mp_tierprice[' + mp_tierprice_row + '][discount_type]" class="form-control">';
			              <?php foreach ($mpdiscount_types as $mpdiscount_type) { ?>
			  html += '       <option value="<?php echo $mpdiscount_type['type']; ?>"><?php echo $mpdiscount_type['name']; ?></option>';
			              <?php } ?>
			  html += '    </select>';
			  html += '  </td>';
			  html += '  <td class="text-left"><input type="text" name="product_mp_tierprice[' + mp_tierprice_row + '][sort_order]" value="" placeholder="<?php echo $entry_sort_order; ?>" class="form-control" /></td>';
			  html += '  <td class="text-left"><button type="button" onclick="$(\'#mp_tierprice-row' + mp_tierprice_row  + '\').remove();" data-toggle="tooltip" title="<?php echo $button_remove; ?>" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>';
			  html += '</tr>';
			  $('#mp-tierprice > tbody').append(html);
			  mp_tierprice_row++;
			}
			//--></script>
			<?php } ?>
			<!-- /*mp tier price ends*/ -->
			]]></add>
		</operation>
	</file>
	<!-- Admin section ends -->
	<!-- Catalog section starts -->
	<file path="catalog/controller/common/header.php">
		<operation error="log">
			<search><![CDATA[$this->document->getStyles();]]></search>
			<add position="before"><![CDATA[
			/*mp tier price starts*/
			$this->document->addStyle('catalog/view/theme/default/stylesheet/mp_tierprice.css');
			/*mp tier price ends*/
			]]></add>
		</operation>
	</file>
	<file path="catalog/controller/product/product.php">
		<operation error="log">
			<search><![CDATA[$data['options'] = array();]]></search>
			<add position="before"><![CDATA[
			/*mp tier price starts*/
			$data['mptierprice_html'] = $this->load->controller('product/mptierprice/getTierPriceHtml',array('product_id' => $product_info['product_id']));
			/*mp tier price ends*/
			]]></add>
		</operation>
	</file>
	<file path="catalog/view/theme/*/template/product/product.tpl">
		<operation error="log">
			<search><![CDATA[<?php if ($options) { ?>]]></search>
			<add position="before"><![CDATA[
			<!-- /*mp tier price starts*/ -->
			<?php echo $mptierprice_html; ?>
			<!-- /*mp tier price ends*/ -->
			]]></add>
		</operation>
	</file>
	<file path="catalog/controller/module/{bestseller,special,latest}*.php" info="2200x and less">
		<operation error="log">
			<search><![CDATA[$data['products'] = array();]]></search>
			<add position="before"><![CDATA[
			/*mp tier price starts*/
			$this->load->model('catalog/mptierprice');
			$this->load->language('product/mptierprice');
			$data['text_aslowas'] = $this->language->get('text_aslowas');
			$productlist_infotext = $this->config->get('mptierprice_productlist_infotext');
			if(isset($productlist_infotext[(int)$this->config->get('config_language_id')])) {
				$data['text_aslowas'] = $productlist_infotext[(int)$this->config->get('config_language_id')];
			}
			/*mp tier price ends*/
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[$data['products'][] = array(]]></search>
			<add position="before"><![CDATA[
			/*mp tier price starts*/
			if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
				$mptierprice = false;
				$lowest_price = $this->model_catalog_mptierprice->getLowestPrice($result['product_id'], $result);
				if($lowest_price) {
				$mptierprice = $this->currency->format($this->tax->calculate($lowest_price, $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
				}
			} else {
				$mptierprice = false;
			}
			/*mp tier price ends*/
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[$data['products'][] = array(]]></search>
			<add position="after"><![CDATA[
			/*mp tier price starts*/
			'mptierprice'       => $mptierprice,
			/*mp tier price ends*/
			]]></add>
		</operation>
	</file>
	<file path="catalog/controller/product/{search,manufacturer,category,product}*.php" info="2200x and less">
		<operation error="log">
			<search><![CDATA[$data['products'] = array();]]></search>
			<add position="before"><![CDATA[
			/*mp tier price starts*/
			$this->load->model('catalog/mptierprice');
			$this->load->language('product/mptierprice');
			$data['text_aslowas'] = $this->language->get('text_aslowas');
			$productlist_infotext = $this->config->get('mptierprice_productlist_infotext');
			if(isset($productlist_infotext[(int)$this->config->get('config_language_id')])) {
				$data['text_aslowas'] = $productlist_infotext[(int)$this->config->get('config_language_id')];
			}
			/*mp tier price ends*/
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[$data['products'][] = array(]]></search>
			<add position="before"><![CDATA[
			/*mp tier price starts*/
			if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
				$mptierprice = false;
				$lowest_price = $this->model_catalog_mptierprice->getLowestPrice($result['product_id'], $result);
				if($lowest_price) {
				$mptierprice = $this->currency->format($this->tax->calculate($lowest_price, $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
				}
			} else {
				$mptierprice = false;
			}
			/*mp tier price ends*/
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[$data['products'][] = array(]]></search>
			<add position="after"><![CDATA[
			/*mp tier price starts*/
			'mptierprice'       => $mptierprice,
			/*mp tier price ends*/
			]]></add>
		</operation>
	</file>
	<file path="catalog/controller/module/featured.php" info="2200x and less">
		<operation error="log">
			<search><![CDATA[$data['products'] = array();]]></search>
			<add position="before"><![CDATA[
			/*mp tier price starts*/
			$this->load->model('catalog/mptierprice');
			$this->load->language('product/mptierprice');
			$data['text_aslowas'] = $this->language->get('text_aslowas');
			$productlist_infotext = $this->config->get('mptierprice_productlist_infotext');
			if(isset($productlist_infotext[(int)$this->config->get('config_language_id')])) {
				$data['text_aslowas'] = $productlist_infotext[(int)$this->config->get('config_language_id')];
			}
			/*mp tier price ends*/
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[$data['products'][] = array(]]></search>
			<add position="before"><![CDATA[
			/*mp tier price starts*/
			if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
				$mptierprice = false;
				$lowest_price = $this->model_catalog_mptierprice->getLowestPrice($product_info['product_id'], $product_info);
				if($lowest_price) {
				$mptierprice = $this->currency->format($this->tax->calculate($lowest_price, $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
				}
			} else {
				$mptierprice = false;
			}
			/*mp tier price ends*/
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[$data['products'][] = array(]]></search>
			<add position="after"><![CDATA[
			/*mp tier price starts*/
			'mptierprice'       => $mptierprice,
			/*mp tier price ends*/
			]]></add>
		</operation>
	</file>
	<file path="catalog/view/theme/*/template/module/{featured,bestseller,special,latest}*.tpl"  info="2200x and less">
		<operation error="log">
			<search><![CDATA[<?php if ($product['tax']) { ?>]]></search>
			<add position="before"><![CDATA[
			<!-- /*mp tier price starts*/ -->
			<?php if ($product['mptierprice']) { ?>
			<span class="mp-tierprice"> <span class="mp-tierprice-text"><?php echo $text_aslowas; ?></span> <?php echo $product['mptierprice']; ?></span>
			<?php } ?>
			<!-- /*mp tier price ends*/ -->
			]]></add>
		</operation>
	</file>
	<file path="catalog/view/theme/*/template/product/{search,manufacturer_info,category,product}*.tpl"  info="2200x and less">
		<operation error="log">
			<search><![CDATA[<?php if ($product['tax']) { ?>]]></search>
			<add position="before"><![CDATA[
			<!-- /*mp tier price starts*/ -->
			<?php if ($product['mptierprice']) { ?>
			<span class="mp-tierprice"> <span class="mp-tierprice-text"><?php echo $text_aslowas; ?></span> <?php echo $product['mptierprice']; ?></span>
			<?php } ?>
			<!-- /*mp tier price ends*/ -->
			]]></add>
		</operation>
	</file>

	<file path="system/library/cart/cart.php">
		<operation error="log">
			<search><![CDATA[$discount_quantity = 0;]]></search>
			<add position="before"><![CDATA[
			/*mp tier price starts*/
			$mpproduct_regular_price = $price;
			/*mp tier price ends*/
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[$product_data[] = array(]]></search>
			<add position="before"><![CDATA[
			/*mp tier price starts*/
			if($this->config->get('mptierprice_status')) {

				$mpproduct_final_price = $price;

				$mpproduct_apply_price = $price;

				// $mptierprices_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_mptierprices WHERE product_id = '" . (int)$cart['product_id'] . "' AND (store_id='". (int)$this->config->get('config_store_id') ."' OR store_id='*') AND (customer_group_id='". (int)$this->config->get('config_customer_group_id') ."' OR customer_group_id='*') AND from_quantity <= '". $cart['quantity'] ."' AND (to_quantity >= '". $cart['quantity'] ."' OR to_quantity='' OR to_quantity='0') ");
				$mptierprices_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_mptierprices WHERE product_id = '" . (int)$cart['product_id'] . "' AND (store_id='". (int)$this->config->get('config_store_id') ."' OR store_id='*') AND (customer_group_id='". (int)$this->config->get('config_customer_group_id') ."' OR customer_group_id='*') AND (from_quantity <= '". $cart['quantity'] ."' OR (to_quantity = '". $cart['quantity'] ."' OR to_quantity='' OR to_quantity='0')) ");

				// print_r($mptierprices_query);die;

				/*mptierprice_baseprice == 1 regular price*/
				if($this->config->get('mptierprice_baseprice') == 1) {
					$mpproduct_fetch_price = $mpproduct_regular_price;
				} else {
					$mpproduct_fetch_price = $mpproduct_final_price;
				}


				if ($mptierprices_query->row && $mptierprices_query->row['price']) {
					$mptierprices = $mptierprices_query->row;

						// echo "mptierprices <br><br>";
						// print_r($mptierprices);

						/*fixed price*/
						if($mptierprices['discount_type'] == 'FP') {
							$mpproduct_apply_price = $mptierprices['price'];
						}
						/*discounted percentage*/
						if($mptierprices['discount_type'] == 'DP') {
							$mpproduct_apply_price = $mpproduct_fetch_price - ($mpproduct_fetch_price * $mptierprices['price']) / 100 ;
						}
						/*discount amount*/
						if($mptierprices['discount_type'] == 'DA') {
							$mpproduct_apply_price = ($mpproduct_fetch_price - $mptierprices['price']);
						}


				}
				// echo "mpproduct_regular_price: ". $mpproduct_regular_price;
				// echo "<br><br>";
				// echo "mpproduct_final_price: ". $mpproduct_final_price;
				// echo "<br><br>";
				// echo "mpproduct_fetch_price: ". $mpproduct_fetch_price;
				// echo "<br><br>";
				// echo "mpproduct_apply_price: ". $mpproduct_apply_price;
				// echo "<br><br>";

				$price = $mpproduct_apply_price;
			}
			/*mp tier price ends*/
			]]></add>
		</operation>
	</file>
	<!-- Catalog section ends -->
</modification>