<modification>
    <name>Укркредит</name>
	<version>1.1.0</version>
	<link>https://fringe.com.ua</link>
	<author>Stealth</author>
	<code>ukrcredit_ocmod</code>

	<file path="admin/controller/{extension,extension/extension}/payment.php" error="skip">
		<operation error="skip">
			<search><![CDATA[$extension = basename($file, '.php');]]></search>
			<add position="after"><![CDATA[if ($extension == 'ukrcredits_pp' || $extension == 'ukrcredits_ii' || $extension == 'ukrcredits_mb' || $extension == 'ukrcredits_ab' || $extension == 'ukrcredits_sb' || $extension == 'ukrcredits_aa' || $extension == 'ukrcredits_pl' || $extension == 'ukrcredits_pu') continue;]]></add>
		</operation>
	</file>
	
	<file path="admin/controller/sale/order.php" error="skip">
		<operation error="skip">
			<search><![CDATA[$content = $this->load->controller('payment/' . $order_info['payment_code'] . '/order');]]></search>
			<add position="replace"><![CDATA[
				if (file_exists(DIR_APPLICATION . 'controller/payment/' . $order_info['payment_code'] . '.php')) {
					$content = $this->load->controller('payment/' . $order_info['payment_code'] . '/order');
				} else {
					$content = null;
				}
			]]></add>
		</operation>
	</file>
	
	/* FOR 2.3 */
	<file path="admin/controller/extension/extension/payment.php" error="skip">
		<operation error="skip">
			<search><![CDATA[$this->load->controller('extension/payment/' . $this->request->get['extension'] . '/install');]]></search>
			<add position="before"><![CDATA[
			if ($this->request->get['extension'] == 'ukrcredits') {
				$this->load->controller('payment/' . $this->request->get['extension'] . '/install');
				$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'payment/' . $this->request->get['extension']);
				$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'payment/' . $this->request->get['extension']);
			}
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[$this->load->controller('extension/payment/' . $this->request->get['extension'] . '/uninstall');]]></search>
			<add position="after"><![CDATA[$this->load->controller('payment/' . $this->request->get['extension'] . '/uninstall');]]></add>
		</operation>
	</file>
	<file path="admin/controller/extension/extension/total.php" error="skip">
		<operation error="skip">
			<search><![CDATA[$this->load->controller('extension/total/' . $this->request->get['extension'] . '/install');]]></search>
			<add position="after"><![CDATA[
			if ($this->request->get['extension'] == 'totalukrcredits') {
				$this->load->controller('total/' . $this->request->get['extension'] . '/install');
				$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'total/' . $this->request->get['extension']);
				$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'total/' . $this->request->get['extension']);
			}
			]]></add>
		</operation>
	</file>
	<file path="system/config/catalog.php">
		<operation error="skip">
			<search><![CDATA['model/extension/analytics/*/before']]></search>
			<add position="before"><![CDATA[
	//		'controller/extension/payment/*/before'   => 'event/compatibility/controller',
			]]></add>
		</operation>
	</file>
	/* permission fix FOR 2.3-3.0 */
	<file path="admin/controller/startup/permission.php">
		<operation error="skip">
			<search><![CDATA[if (!in_array($route, $ignore)]]></search>
			<add position="before"><![CDATA[
			if ($route == 'extension/payment/ukrcredits') {
				$route = 'payment/ukrcredits';
			}
			if ($route == 'extension/total/totalukrcredits') {
				$route = 'total/totalukrcredits';
			}
			]]></add>
		</operation>
	</file>	
	
	/* FOR 3.0 */
	<file path="admin/controller/extension/extension/payment.php" error="skip">
		<operation error="skip">
			<search><![CDATA[$files = glob(DIR_APPLICATION . 'controller/extension/payment/*.php');]]></search>
			<add position="replace"><![CDATA[$files = glob(DIR_APPLICATION . 'controller/{extension/payment,payment}/*.php', GLOB_BRACE);]]></add>
		</operation>
	</file>
	<file path="admin/controller/extension/extension/total.php" error="skip">
		<operation error="skip">
			<search><![CDATA[$files = glob(DIR_APPLICATION . 'controller/extension/total/*.php');]]></search>
			<add position="replace"><![CDATA[$files = glob(DIR_APPLICATION . 'controller/{extension/total,total}/*.php', GLOB_BRACE);]]></add>
		</operation>
	</file>
	<file path="system/config/admin.php">
		<operation error="skip">
			<search><![CDATA['controller/*/before' => array(]]></search>
			<add position="after"><![CDATA[
			'payment/ukrcredits/controller',
			]]></add>
		</operation>
	</file>
	<file path="system/config/catalog.php">
		<operation error="skip">
			<search><![CDATA['controller/*/before' => array(]]></search>
			<add position="before"><![CDATA[
			'model/*/before' => array(
				'module/ukrcredits/beforemodel'
			),
			'model/*/after' => array(
				'module/ukrcredits/aftermodel'
			),
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA['controller/*/before' => array(]]></search>
			<add position="after"><![CDATA[
			'module/ukrcredits/controller',
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA['controller/*/after' => array(]]></search>
			<add position="after"><![CDATA[
			'module/ukrcredits/controller',
			]]></add>
		</operation>
	</file>
	<file path="system/engine/loader.php">
		<operation error="skip">
			<search><![CDATA[if (!$this->registry->has('model_']]></search>
			<add position="before"><![CDATA[
		if ($route == 'extension/payment/ukrcredits_pp' || $route == 'extension/payment/ukrcredits_ii' || $route == 'extension/payment/ukrcredits_mb' || $route == 'extension/payment/ukrcredits_ab' || $route == 'extension/payment/ukrcredits_sb' || $route == 'extension/payment/ukrcredits_aa' || $route == 'extension/payment/ukrcredits_pl' || $route == 'extension/payment/ukrcredits_pu' || $route == 'extension/payment/ukrcredits' || $route == 'extension/total/totalukrcredits') {
			$this->registry->get('event')->trigger('model/' . $route . '/before', array(&$route));
		}
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[throw new \Exception('Error: Could not load model ']]></search>
			<add position="after" offset="1"><![CDATA[
			$this->registry->get('event')->trigger('model/'.$route.'/after', array(&$route));
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[include_once($file);]]></search>
			<add position="replace"><![CDATA[
			include_once(modification($file));
			]]></add>
		</operation>		
	</file>
	
	<file path="system/library/session.php">
		<operation error="skip">
			<search><![CDATA[exit();]]></search>
			<add position="after" offset="1"><![CDATA[
	if (version_compare(VERSION,'3.0','>=')) {
		if ($this->adaptor && !session_id()) {
			session_start();
		}
	}
			]]></add>
		</operation>
	</file>
	
	<file path="admin/controller/catalog/category.php">
		<operation>
			<search><![CDATA[public function autocomplete()]]></search>
			<add position="before"><![CDATA[
	 public function productsAutocomplete(){
		 $json=array();
		 
		 if(isset($this->request->get['filter_name'])||isset($this->request->get['filter_model'])||isset($this->request->get['filter_category_id'])){
		 
			 $this->load->model('catalog/product');
			 
			 if(isset($this->request->get['filter_name'])){
				$filter_name=$this->request->get['filter_name'];
			 } else {
				$filter_name='';
			 }
			 
			 if(isset($this->request->get['filter_model'])){
				$filter_model=$this->request->get['filter_model'];
			 } else {
				$filter_model='';
			 }
			 if(isset($this->request->get['filter_category_id'])){
				$filter_category=$this->request->get['filter_category_id'];
			 } else {
				$filter_category='';
			 }
			 if(isset($this->request->get['limit'])){
				$limit=$this->request->get['limit'];
			 } else {
				$limit=5000;
			 }
			 
			 $filter_data=array(
				 'filter_category'=>$filter_category,
				 'filter_name'=>$filter_name,
				 'filter_model'=>$filter_model,
				 'start'=>0,
				 'limit'=>$limit
			 );
			 
			 $results = $this->model_catalog_product->getProducts($filter_data);
			 
			 foreach($results as $result){
				 $json[]=array(
					 'product_id'=>$result['product_id'],
					 'name'=>strip_tags(html_entity_decode($result['name'],ENT_QUOTES,'UTF-8')),
					 'model'=>$result['model'],
					 'price'=>$result['price']
				 );
			 }
		 }
		 $this->response->setOutput(json_encode($json));
	 }
			]]></add>
		</operation>
	</file>	
	<file path="admin/language/r*/catalog/product.php">
		<operation>
			<search ><![CDATA[$_['error_warning']]]></search>
			<add position="before"><![CDATA[
$_['tab_ukrcredits']			= 'Кредиты';
$_['credit_type']				= 'Вид кредитования:';
$_['partsCount']				= 'Максимум месяцев:';
$_['markup']					= 'Коэффициент наценки:';
$_['special']					= 'Запретить акции:';
$_['help_partsCount']			= 'Введите максимальное количество месяцев кредитования';
$_['help_markup']				= 'Если необходимо, установите наценку на стоимость товара, например 1.027, что составляет 2.7%';
$_['help_special']				= 'При включении данной опции, цена товара при оформлении кредита будет без учета акций';
$_['credit_type_ii']			= 'Мгновенная рассрочка (Приватбанк)';
$_['credit_type_pp']			= 'Оплата частями (Приватбанк)';
$_['credit_type_mb']			= 'Покупка частями (Монобанк)';
$_['credit_type_ab']			= 'Легкая рассрочка (Sense bank)';
$_['credit_type_sb']			= 'Кредит (Sense bank)';
$_['credit_type_aa']			= 'Плати частями (А-Банк)';
$_['credit_type_pl']			= 'Плати позже';
$_['credit_type_pu']			= 'Оплата частями (ПУМБ)';
			]]></add>
		</operation>
	</file>
	<file path="admin/language/u*/catalog/product.php">
		<operation>
			<search ><![CDATA[$_['error_warning']]]></search>
			<add position="before"><![CDATA[
$_['tab_ukrcredits'] 			= 'Кредити';
$_['credit_type'] 				= 'Тип кредитування:';
$_['partsCount'] 				= 'Максимум місяців:';
$_['markup'] 					= 'Коефіцієнт націнки:';
$_['special'] 					= 'Заборонити акції:';
$_['help_partsCount'] 			= 'Введіть максимальну кількість місяців кредитування';
$_['help_markup'] 				= 'Якщо необхідно, встановіть націнку на вартість товару, наприклад, 1.027, що становить 2.7%';
$_['help_special'] 				= 'При включенні даної опції ціна товару при оформленні кредиту буде без урахування акцій';
$_['credit_type_ii'] 			= 'Миттєва розстрочка (Приватбанк)';
$_['credit_type_pp'] 			= 'Оплата частинами (Приватбанк)';
$_['credit_type_mb'] 			= 'Покупка частинами (Монобанк)';
$_['credit_type_ab'] 			= 'Легка розстрочка (Sense bank)';
$_['credit_type_sb']			= 'Кредит (Sense bank)';
$_['credit_type_aa'] 			= 'Платі частинами (А-Банк)';
$_['credit_type_pl'] 			= 'Плати пізніше';
$_['credit_type_pu'] 			= 'Оплата частинами (ПУМБ)';
			]]></add>
		</operation>
	</file>
	<file path="admin/controller/catalog/product.php">
		<operation>
			<search ><![CDATA[if (isset($this->request->get['product_id']) &&]]></search>
			<add position="before"><![CDATA[
		$type = version_compare(VERSION,'3.0','>=') ? 'payment_' : '';
		if ($this->config->get($type.'ukrcredits_status')) {
			
			$data['ukrcredits_status'] = true;
			$data['tab_ukrcredits'] = $this->language->get('tab_ukrcredits');
			$data['credit_type'] = $this->language->get('credit_type');
			$data['credit_type_ii'] = $this->language->get('credit_type_ii');
			$data['credit_type_pp'] = $this->language->get('credit_type_pp');
			$data['credit_type_mb'] = $this->language->get('credit_type_mb');
			$data['credit_type_ab'] = $this->language->get('credit_type_ab');
			$data['credit_type_sb'] = $this->language->get('credit_type_sb');
			$data['credit_type_aa'] = $this->language->get('credit_type_aa');
			$data['credit_type_pl'] = $this->language->get('credit_type_pl');
			$data['credit_type_pu'] = $this->language->get('credit_type_pu');
			$data['partsCount'] = $this->language->get('partsCount');
			$data['markup'] = $this->language->get('markup');
			$data['special'] = $this->language->get('special');
			$data['help_partsCount'] = $this->language->get('help_partsCount');
			$data['help_markup'] = $this->language->get('help_markup');	
			$data['help_special'] = $this->language->get('help_special');
			
			$type = version_compare(VERSION,'3.0','>=') ? 'payment_' : '';
			$banks = $this->config->get($type.'ukrcredits_banks');
			$data['banks'] = $banks;
		
            if (isset($this->request->get['product_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
                $credit_info = $this->model_catalog_product->getProductUkrcredits($this->request->get['product_id']);
            }

			$data['partscounts'] = array();
			for($i=24;$i>=1;$i--){
				$data['partscounts'][] = $i;           
			}

			foreach ($banks as $bank) {
				if (isset($this->request->post['product_'.$bank])) {
					$data['product_pp'] = $this->request->post['product_'.$bank];
				} elseif (!empty($credit_info)) {
					$data['product_'.$bank] = $credit_info['product_'.$bank];
				} else {
					$data['product_'.$bank] = '';
				}

				if (isset($this->request->post['partscount_'.$bank])) {
					$data['partscount_pp'] = $this->request->post['partscount_'.$bank];
				} elseif (!empty($credit_info)) {
					$data['partscount_'.$bank] = $credit_info['partscount_'.$bank];
				} else {
					$data['partscount_'.$bank] = '';
				}

				if (isset($this->request->post['markup_'.$bank])) {
					$data['markup_pp'] = $this->request->post['markup_'.$bank];
				} elseif (!empty($credit_info)) {
					$data['markup_'.$bank] = $credit_info['markup_'.$bank];
				} else {
					$data['markup_'.$bank] = '';
				}

				if (isset($this->request->post['special_'.$bank])) {
					$data['special_pp'] = $this->request->post['special_'.$bank];
				} elseif (!empty($credit_info)) {
					$data['special_'.$bank] = $credit_info['special_'.$bank];
				} else {
					$data['special_'.$bank] = '';
				}
			}
			
		} else {
			$data['ukrcredits_status'] = false;
		}
			]]></add>
		</operation>
	</file>	
	<file path="admin/model/catalog/product.php">
		<operation error="log">
			<search ><![CDATA[public function editProduct($product_id, $data) {]]></search>
			<add position="after"><![CDATA[
	if (isset($data['partscount_pp'])) {
		$type = version_compare(VERSION,'3.0','>=') ? 'payment_' : '';
		$banks = $this->config->get($type.'ukrcredits_banks');
		$update = false;
		foreach ($banks as $bank) {
			if ((isset($data['product_'.$bank]) && $data['product_'.$bank]) || (isset($data['partscount_'.$bank]) && $data['partscount_'.$bank])  || (isset($data['markup_'.$bank]) && $data['markup_'.$bank])  || (isset($data['special_'.$bank]) && $data['special_'.$bank])) {
				$update = true;
			}
		}
		if ($update) {
			$this->db->query("DELETE FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_id . "'");
			$sql = "INSERT INTO " . DB_PREFIX . "product_ukrcredits SET product_id = '" . (int)$product_id . "' ";
			foreach ($banks as $bank) {
				$sql .= ", product_".$bank." = '" . $this->db->escape($data['product_'.$bank]) . "', partscount_".$bank." = '" . $this->db->escape($data['partscount_'.$bank]) . "', markup_".$bank." = '" . $this->db->escape($data['markup_'.$bank]) . "',  special_".$bank." = '" . $this->db->escape($data['special_'.$bank]) . "' ";
			}
			$this->db->query($sql);
		}
	}
			]]></add>
		</operation>
		<operation error="log">
			<search ><![CDATA[$product_id = $this->db->getLastId();]]></search>
			<add position="after"><![CDATA[
	if (isset($data['partscount_pp'])) {
		$type = version_compare(VERSION,'3.0','>=') ? 'payment_' : '';
		$banks = $this->config->get($type.'ukrcredits_banks');
		$update = false;
		foreach ($banks as $bank) {
			if ((isset($data['product_'.$bank]) && $data['product_'.$bank]) || (isset($data['partscount_'.$bank]) && $data['partscount_'.$bank])  || (isset($data['markup_'.$bank]) && $data['markup_'.$bank])  || (isset($data['special_'.$bank]) && $data['special_'.$bank])) {
				$update = true;
			}
		}
		if ($update) {
			$sql = "INSERT INTO " . DB_PREFIX . "product_ukrcredits SET product_id = '" . (int)$product_id . "' ";
			foreach ($banks as $bank) {
				$sql .= ", product_".$bank." = '" . $this->db->escape($data['product_'.$bank]) . "', partscount_".$bank." = '" . $this->db->escape($data['partscount_'.$bank]) . "', markup_".$bank." = '" . $this->db->escape($data['markup_'.$bank]) . "',  special_".$bank." = '" . $this->db->escape($data['special_'.$bank]) . "' ";
			}
			$this->db->query($sql);
		}
	}
			]]></add>
		</operation>
		<operation error="log">
			<search ><![CDATA[deleteProduct($product_id) {]]></search>
			<add position="after"><![CDATA[
		$this->db->query("DELETE FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_id . "'");
			]]></add>
		</operation>
		<operation error="log">
			<search index="0"><![CDATA[public function getProductAttributes]]></search>
			<add position="before"><![CDATA[
	public function getProductUkrcredits($product_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_id . "'");

		return $query->row;
	}
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[$data['status'] = '0';]]></search>
			<add position="after"><![CDATA[
		$data = array_merge($data, $this->getProductUkrcredits($product_id));
			]]></add>
		</operation>
	</file>	
	<file path="admin/view/template/catalog/product_form.tpl" error="skip">
		<operation error="skip">
			<search ><![CDATA[<li><a href="#tab-attribute" data-toggle="tab">]]></search>
			<add position="before"><![CDATA[
			<?php if ($ukrcredits_status) { ?>
			<li><a href="#tab-ukrcredits" data-toggle="tab"><?php echo $tab_ukrcredits; ?></a></li>
			<?php } ?>
			]]></add>
		</operation>
		<operation error="skip">
			<search ><![CDATA[<div class="tab-pane" id="tab-attribute">]]></search>
			<add position="before"><![CDATA[
			<?php if ($ukrcredits_status) { ?>
			<div class="tab-pane" id="tab-ukrcredits">
              <div class="table-responsive">
                <table id="ukrcredits" class="table table-bordered table-hover">
                  <thead>
                    <tr>
                      <td class="text-left"><?php echo $credit_type; ?></td>
					  <td class="text-left"><?php echo $entry_status; ?></td>
                      <td class="text-left"><span data-toggle="tooltip" title="<?php echo $help_partsCount; ?>"><?php echo $partsCount; ?></td>
					  <td class="text-left"><span data-toggle="tooltip" title="<?php echo $help_markup; ?>"><?php echo $markup; ?></td>
					  <td class="text-left"><span data-toggle="tooltip" title="<?php echo $help_special; ?>"><?php echo $special; ?></td>
                    </tr>
                  </thead>
                  <tbody>
					<?php foreach ($banks as $bank) { ?>
                    <tr>
					<td class="text-left"><?php echo ${"credit_type_$bank"}; ?></td>
					  <td>
						  <select name="product_<?php echo $bank; ?>" id="input-product_<?php echo $bank; ?>" class="form-control">
							<?php if (${"product_$bank"}) { ?>
								<option value="1" selected="selected"><?php echo $text_enabled; ?></option>
								<option value="0"><?php echo $text_disabled; ?></option>
							<?php } else { ?>
								<option value="1"><?php echo $text_enabled; ?></option>
								<option value="0" selected="selected"><?php echo $text_disabled; ?></option>
							<?php } ?>
						  </select>
					  </td>	
                      <td>
						  <select name="partscount_<?php echo $bank; ?>" id="input-partscount_<?php echo $bank; ?>" class="form-control">
						  <option value=""><?php echo $text_select; ?></option>
							<?php foreach ($partscounts as $partscount) { ?>
							<?php if (${"partscount_$bank"} == $partscount) { ?>
							<option value="<?php echo $partscount; ?>" selected="selected"><?php echo $partscount; ?></option>
							<?php } else { ?>
							<option value="<?php echo $partscount; ?>"><?php echo $partscount; ?></option>
							<?php } ?>
							<?php } ?>
						  </select>
					  </td>
					  <td class="text-left"><input type="text" name="markup_<?php echo $bank; ?>" value="<?php echo ${"markup_$bank"}; ?>" placeholder="1.0000" id="input-markup_<?php echo $bank; ?>" class="form-control" /></td>
					  <td>
						  <select name="special_<?php echo $bank; ?>" id="input-special_<?php echo $bank; ?>" class="form-control">
							<?php if (${"special_$bank"}) { ?>
								<option value="1" selected="selected"><?php echo $text_yes; ?></option>
								<option value="0"><?php echo $text_no; ?></option>
							<?php } else { ?>
								<option value="1"><?php echo $text_yes; ?></option>
								<option value="0" selected="selected"><?php echo $text_no; ?></option>
							<?php } ?>
						  </select>
					  </td>	
                    </tr>
					<?php } ?>

                  </tbody>
                </table>
              </div>			
			</div>
			<?php } ?>
			]]></add>
		</operation>
	</file>	
	<file path="admin/view/template/catalog/product_form.twig" error="skip">
		<operation error="skip">
			<search ><![CDATA[<li><a href="#tab-attribute" data-toggle="tab">{{ tab_attribute }}</a>]]></search>
			<add position="before"><![CDATA[
			{% if ukrcredits_status %}
			<li><a href="#tab-ukrcredits" data-toggle="tab">{{ tab_ukrcredits }}</a></li>
			{% endif %}
			]]></add>
		</operation>
		<operation error="skip">
			<search ><![CDATA[<div class="tab-pane" id="tab-attribute">]]></search>
			<add position="before"><![CDATA[
			{% if ukrcredits_status %}
			<div class="tab-pane" id="tab-ukrcredits">
              <div class="table-responsive">
                <table id="ukrcredits" class="table table-bordered table-hover">
                  <thead>
                    <tr>
                      <td class="text-left">{{ credit_type }}</td>
					  <td class="text-left">{{ entry_status }}</td> 
                      <td class="text-left"><span data-toggle="tooltip" title="{{ help_partsCount }}">{{ partsCount }}</td>
					  <td class="text-left"><span data-toggle="tooltip" title="{{ help_markup }}">{{ markup }}</td>
					  <td class="text-left"><span data-toggle="tooltip" title="{{ help_special }}">{{ special }}</td>
                    </tr>
                  </thead>
                  <tbody>
					{% for bank in banks %}
                    <tr>
                      <td class="text-left">{{ attribute(_context,'credit_type_'~bank) }}</td>
					  <td>
						  <select name="product_{{ bank }}" id="input-product_{{ bank }}" class="form-control">
							{% if attribute(_context,'product_'~bank) %}
								<option value="1" selected="selected">{{ text_enabled }}</option>
								<option value="0">{{ text_disabled }}</option>
							{% else %}
								<option value="1">{{ text_enabled }}</option>
								<option value="0" selected="selected">{{ text_disabled }}</option>
							{% endif %}
						  </select>
					  </td>
                      <td>
						  <select name="partscount_{{ bank }}" id="input-partscount_{{ bank }}" class="form-control">
							<option value="">{{ text_select }}</option>
							{% for partscount in partscounts %}
							{% if attribute(_context,'partscount_'~bank) == partscount %}
							<option value="{{ partscount }}" selected="selected">{{ partscount }}</option>
							{% else %}
							<option value="{{ partscount }}">{{ partscount }}</option>
							{% endif %}
							{% endfor %}
						  </select>
					  </td>
					  <td class="text-left"><input type="text" name="markup_{{ bank }}" value="{{ attribute(_context,'markup_'~bank) }}" placeholder="1.0000" id="input-markup_{{ bank }}" class="form-control" /></td>
					  <td>
						  <select name="special_{{ bank }}" id="input-special_{{ bank }}" class="form-control">
							{% if attribute(_context,'special_'~bank) %}
								<option value="1" selected="selected">{{ text_enabled }}</option>
								<option value="0">{{ text_disabled }}</option>
							{% else %}
								<option value="1">{{ text_enabled }}</option>
								<option value="0" selected="selected">{{ text_disabled }}</option>
							{% endif %}
						  </select>
					  </td>
                    </tr>
					{% endfor %}
                  </tbody>
                </table>
              </div>			
			</div>
			{% endif %}
			]]></add>
		</operation>
	</file>	
	<file path="catalog/controller/product/product.php">
		<operation>
			<search><![CDATA[$data['header']]]></search>
			<add position="before"><![CDATA[
	if (version_compare(VERSION,'3.0','>=')) {
		if ($this->config->get('payment_ukrcredits_status')) {
			$data['ukrcredits_status'] = true;
			$data['ukrcredits'] = str_replace("\n", '', $this->load->controller('module/ukrcredits'));
			$data['ukrcredits_selector_button'] = strip_tags(html_entity_decode($this->config->get('payment_ukrcredits_settings')['selector_button'],ENT_QUOTES,'UTF-8'));
			$data['ukrcredits_selector_block'] = $this->config->get('payment_ukrcredits_settings')['selector_block'];
			$data['ukrcredits_css_custom'] = $this->config->get('payment_ukrcredits_settings')['css_custom'];
		} else {
			$data['ukrcredits_status'] = false;
		}
	} else {
		if ($this->config->get('ukrcredits_status')) {
			$data['ukrcredits_status'] = true;
			$data['ukrcredits'] = str_replace("\n", '', $this->load->controller('module/ukrcredits'));
			$data['ukrcredits_selector_button'] = strip_tags(html_entity_decode($this->config->get('ukrcredits_settings')['selector_button'],ENT_QUOTES,'UTF-8'));
			$data['ukrcredits_selector_block'] = $this->config->get('ukrcredits_settings')['selector_block'];
			$data['ukrcredits_css_custom'] = $this->config->get('ukrcredits_settings')['css_custom'];
		} else {
			$data['ukrcredits_status'] = false;
		}	
	}
			]]></add>
		</operation>
		<operation>
			<search><![CDATA[public function index()]]></search>
			<add position="after"><![CDATA[
			$this->document->addScript ('catalog/view/javascript/jquery/jquery-ui/jquery-ui.min.js');
			$this->document->addScript ('catalog/view/javascript/jquery/jquery-ui/jquery.ui.touch-punch.min.js');
			$this->document->addStyle ('catalog/view/javascript/jquery/magnific/magnific-popup.css');
			$this->document->addScript ('catalog/view/javascript/jquery/magnific/jquery.magnific-popup.min.js');
			]]></add>
		</operation>
	</file>
	<file path="catalog/controller/checkout/checkout.php">
		<operation>
			<search><![CDATA[$this->document->addStyle]]></search>
			<add position="before"><![CDATA[
			$this->document->addScript('catalog/view/javascript/jquery/jquery-ui/jquery-ui.min.js');
			]]></add>
		</operation>
	</file>
	<file path="catalog/controller/checkout/simplecheckout.php" error="skip">
		<operation>
			<search><![CDATA[$this->setOutputContent]]></search>
			<add position="before"><![CDATA[
			$this->document->addScript('catalog/view/javascript/jquery/jquery-ui/jquery-ui.min.js');
			]]></add>
		</operation>
	</file>
	<file path="catalog/controller/checkout/cart.php">
		<operation error="skip">
			<search><![CDATA[unset($this->session->data['payment_method']);]]></search>
			<add position="replace"><![CDATA[
			//unset($this->session->data['payment_method']);
			]]></add>
		</operation>
	</file>
	<file path="catalog/controller/checkout/cart.php">
		<operation error="skip">
			<search><![CDATA[unset($this->session->data['payment_methods']);]]></search>
			<add position="replace"><![CDATA[
			//unset($this->session->data['payment_methods']);
			]]></add>
		</operation>
	</file>
	<file path="catalog/controller/checkout/oct_fastorder.php" error="skip">
		<operation error="skip">
			<search><![CDATA[public function index() {]]></search>
			<add position="after"><![CDATA[
			$this->document->addScript('catalog/view/javascript/jquery/jquery-ui/jquery-ui.min.js');
			]]></add>
		</operation>
	</file>
	<file path="catalog/controller/checkout/onepcheckout.php" error="log">
		<operation error="skip">
			<search><![CDATA[public function index() {]]></search>
			<add position="after"><![CDATA[
			$this->document->addScript('catalog/view/javascript/jquery/jquery-ui/jquery-ui.min.js');
			]]></add>
		</operation>
	</file>
	<file path="catalog/controller/extension/module/template_switcher.php">
		<operation error="skip">
			<search><![CDATA[if (!$this->config->get('module_template_switcher_status')) {]]></search>
			<add position="replace"><![CDATA[
			if (!$this->config->get('module_template_switcher_status') || strpos($route, 'ukrcredits')) {
			]]></add>
		</operation>
	</file>
	<file path="system/library/seopro.php">
		<operation error="skip">
			<search><![CDATA['error/not_found',]]></search>
			<add position="after"><![CDATA[
			'module/ukrcredits/loadpopup',
			]]></add>
		</operation>
	</file>
	<file path="catalog/model/catalog/product.php">
		<operation>
			<search index="0"><![CDATA[public function getProduct($product_id)]]></search>
			<add position="before"><![CDATA[
	public function getProductUkrcredits($product_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_id . "'");

		return $query->row;
	}
			]]></add>
		</operation>
	</file>	
	<file path="catalog/view/theme/*/template/product/product.tpl">
		<operation error="skip">
			<search ><![CDATA[<?php echo $footer; ?>]]></search>
			<add position="before"><![CDATA[
<?php if ($ukrcredits_status) { ?>
<script type="text/javascript"><!--
$('<?php echo $ukrcredits_selector_button; ?>').after('<?php echo $ukrcredits; ?>');
$('body').on('click', '#button-ukrcredits', function(){
  $('[data-toggle="tooltip"]').tooltip('hide');
  $.ajax({
    url: 'index.php?route=module/ukrcredits/checkoptions',
    type: 'post',
    data: $('<?php echo $ukrcredits_selector_block; ?> input[type=\'text\'], <?php echo $ukrcredits_selector_block; ?> input[type=\'hidden\'], <?php echo $ukrcredits_selector_block; ?> input[type=\'radio\']:checked, <?php echo $ukrcredits_selector_block; ?> input[type=\'checkbox\']:checked, <?php echo $ukrcredits_selector_block; ?> select, <?php echo $ukrcredits_selector_block; ?> textarea'),
    dataType: 'json',
    beforeSend: function() {
      $('#button-ukrcredits').button('loading');
    },
    complete: function() {
      $('#button-ukrcredits').button('reset');
    },
    success: function(json) {
      $('.alert, .text-danger').remove();
      $('.form-group').removeClass('has-error');

      if (json['error']) {
        if (json['error']['option']) {
          for (i in json['error']['option']) {
            var element = $('#input-option' + i.replace('_', '-'));

            if (element.parent().hasClass('input-group')) {
              element.parent().after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
            } else {
              element.after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
            }
          }
        }

        if (json['error']['recurring']) {
          $('select[name=\'recurring_id\']').after('<div class="text-danger">' + json['error']['recurring'] + '</div>');
        }

        // Highlight any found errors
        $('.text-danger').parent().addClass('has-error');
      }

      if (json['success']) {
		$.magnificPopup.open({
		//	type:'ajax',
			tLoading: '',
			tLoading: '<img src="catalog/view/theme/default/image/ukrcredits/PP_logo.png" />',
			removalDelay: 300,
			fixedBgPos: true,
			fixedContentPos: true,
			callbacks: {
				beforeOpen: function() {
				   this.st.mainClass = 'mfp-zoom-in';
				}
			},
			items:{
				type:'ajax',
				src:'index.php?route=module/ukrcredits/loadpopup'
			},
			ajax: {
			  settings: {
				type: 'GET',
				data: $('<?php echo $ukrcredits_selector_block; ?> input[type=\'text\'], <?php echo $ukrcredits_selector_block; ?> input[type=\'hidden\'], <?php echo $ukrcredits_selector_block; ?> input[type=\'radio\']:checked, <?php echo $ukrcredits_selector_block; ?> input[type=\'checkbox\']:checked, <?php echo $ukrcredits_selector_block; ?> select, <?php echo $ukrcredits_selector_block; ?> textarea'),
			  }
			}
		});	
      }
    },
    error: function(xhr, ajaxOptions, thrownError) {
      alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
    }
  });
});
//--></script>
<style>
#ukrcredit-popup {
  position: relative;
  background: #FFF;
  padding: 20px;
  width: auto;
  max-width: 750px;
  margin: 20px auto;
}
.mfp-zoom-in .mfp-content > div {
  opacity: 0;
  transition: all 0.2s ease-in-out;
  transform: scale(0.7);
}
.mfp-zoom-in.mfp-ready .mfp-content > div {
  opacity: 1;
  transform: scale(1);
}
.mfp-zoom-in.mfp-removing .mfp-content > div {
  transform: scale(0.7);
  opacity: 0;
}
<?php echo $ukrcredits_css_custom; ?>
</style>
<?php } ?>
			]]></add>
		</operation>
	</file>
	<file path="catalog/view/theme/*/template/product/product.twig">
		<operation>
			<search ><![CDATA[<?php echo $footer; ?>]]></search>
			<add position="before"><![CDATA[
{% if ukrcredits_status %}
<script type="text/javascript"><!--
$('{{ ukrcredits_selector_button }}').after('{{ ukrcredits }}');
$('body').on('click', '#button-ukrcredits', function(){
  $('[data-toggle="tooltip"]').tooltip('hide');
  $.ajax({
    url: 'index.php?route=module/ukrcredits/checkoptions',
    type: 'post',
    data: $('{{ ukrcredits_selector_block }} input[type=\'text\'], {{ ukrcredits_selector_block }} input[type=\'hidden\'], {{ ukrcredits_selector_block }} input[type=\'radio\']:checked, {{ ukrcredits_selector_block }} input[type=\'checkbox\']:checked, {{ ukrcredits_selector_block }} select, {{ ukrcredits_selector_block }} textarea'),
    dataType: 'json',
    beforeSend: function() {
      $('#button-ukrcredits').button('loading');
    },
    complete: function() {
      $('#button-ukrcredits').button('reset');
    },
    success: function(json) {
      $('.alert, .text-danger').remove();
      $('.form-group').removeClass('has-error');

      if (json['error']) {
        if (json['error']['option']) {
          for (i in json['error']['option']) {
            var element = $('#input-option' + i.replace('_', '-'));

            if (element.parent().hasClass('input-group')) {
              element.parent().after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
            } else {
              element.after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
            }
          }
        }

        if (json['error']['recurring']) {
          $('select[name=\'recurring_id\']').after('<div class="text-danger">' + json['error']['recurring'] + '</div>');
        }

        // Highlight any found errors
        $('.text-danger').parent().addClass('has-error');
      }

      if (json['success']) {
		$.magnificPopup.open({
		//	type:'ajax',
			tLoading: '',
			tLoading: '<img src="catalog/view/theme/default/image/ukrcredits/PP_logo.png" />',
			removalDelay: 300,
			fixedBgPos: true,
			fixedContentPos: true,
			callbacks: {
				beforeOpen: function() {
				   this.st.mainClass = 'mfp-zoom-in';
				}
			},
			items:{
				type:'ajax',
				src:'index.php?route=module/ukrcredits/loadpopup'
			},
			ajax: {
			  settings: {
				type: 'GET',
				data: $('{{ ukrcredits_selector_block }} input[type=\'text\'], {{ ukrcredits_selector_block }} input[type=\'hidden\'], {{ ukrcredits_selector_block }} input[type=\'radio\']:checked, {{ ukrcredits_selector_block }} input[type=\'checkbox\']:checked, {{ ukrcredits_selector_block }} select, {{ ukrcredits_selector_block }} textarea'),
			  }
			}
		});	
      }
    },
    error: function(xhr, ajaxOptions, thrownError) {
      alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
    }
  });
});
//--></script>
<style>
#ukrcredit-popup {
  position: relative;
  background: #FFF;
  padding: 20px;
  width: auto;
  max-width: 750px;
  margin: 20px auto;
}
.mfp-zoom-in .mfp-content > div {
  opacity: 0;
  transition: all 0.2s ease-in-out;
  transform: scale(0.7);
}
.mfp-zoom-in.mfp-ready .mfp-content > div {
  opacity: 1;
  transform: scale(1);
}
.mfp-zoom-in.mfp-removing .mfp-content > div {
  transform: scale(0.7);
  opacity: 0;
}
{{ ukrcredits_css_custom }}
</style>
{% endif %}
			]]></add>
		</operation>
	</file>	
	<file path="catalog/controller/checkout/guest.php">
		<operation>
			<search><![CDATA[unset($this->session->data['payment_method']);]]></search>
			<add position="replace"><![CDATA[
//unset($this->session->data['payment_method']);
			]]></add>
		</operation>
	</file>	

	<file path="catalog/view/theme/*/template/checkout/simplecheckout_payment.{tpl,twig}">
		<operation error="skip">
			<search><![CDATA[<input type="hidden" name="payment_method_current]]></search>
			<add position="before"><![CDATA[
<script type="text/javascript">
$('#ukrcredits_ii').parent().after('<div id="uc_ii" style=""></div>');
if ($("#ukrcredits_ii").prop("checked")) {
	$('#uc_ii').load('index.php?route=module/ukrcredits_simple&uctype=ii');
}
$('#ukrcredits_pp').parent().after('<div id="uc_pp" style=""></div>');
if ($("#ukrcredits_pp").prop("checked")) {
	$('#uc_pp').load('index.php?route=module/ukrcredits_simple&uctype=pp');
}
$('#ukrcredits_mb').parent().after('<div id="uc_mb" style=""></div>');
if ($("#ukrcredits_mb").prop("checked")) {
	$('#uc_mb').load('index.php?route=module/ukrcredits_simple&uctype=mb');
}
$('#ukrcredits_ab').parent().after('<div id="uc_ab" style=""></div>');
if ($("#ukrcredits_ab").prop("checked")) {
	$('#uc_ab').load('index.php?route=module/ukrcredits_simple&uctype=ab');
}
$('#ukrcredits_sb').parent().after('<div id="uc_sb" style=""></div>');
if ($("#ukrcredits_sb").prop("checked")) {
	$('#uc_sb').load('index.php?route=module/ukrcredits_simple&uctype=sb');
}
$('#ukrcredits_aa').parent().after('<div id="uc_aa" style=""></div>');
if ($("#ukrcredits_aa").prop("checked")) {
	$('#uc_aa').load('index.php?route=module/ukrcredits_simple&uctype=aa');
}
$('#ukrcredits_pl').parent().after('<div id="uc_pl" style=""></div>');
if ($("#ukrcredits_pl").prop("checked")) {
	$('#uc_pl').load('index.php?route=module/ukrcredits_simple&uctype=pl');
}
$('#ukrcredits_pu').parent().after('<div id="uc_pu" style=""></div>');
if ($("#ukrcredits_pu").prop("checked")) {
	$('#uc_pu').load('index.php?route=module/ukrcredits_simple&uctype=pu');
}
</script>
			]]></add>
		</operation>
	</file>	

	
	<file path="system/library/cart/cart.php">
		<operation error="log">
			<search><![CDATA[public function getProducts(]]></search>
			<add position="after"><![CDATA[
				$type = version_compare(VERSION,'3.0','>=') ? 'payment_' : '';
				$typetotal = version_compare(VERSION,'3.0','>=') ? 'total_' : '';
				$setting = $this->config->get($type.'ukrcredits_settings');
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[$price = $product_discount_query->row['price'];]]></search>
			<add position="replace"><![CDATA[
					if	(
							(	
								isset($this->session->data['payment_method']['code']) && 
								(
								($this->session->data['payment_method']['code'] == 'ukrcredits_pp' && !$setting['pp_discount'])
								|| 
								($this->session->data['payment_method']['code'] == 'ukrcredits_ii' && !$setting['ii_discount'])
								||
								($this->session->data['payment_method']['code'] == 'ukrcredits_mb' && !$setting['mb_discount'])
								||
								($this->session->data['payment_method']['code'] == 'ukrcredits_ab' && !$setting['ab_discount'])
								||
								($this->session->data['payment_method']['code'] == 'ukrcredits_aa' && !$setting['aa_discount'])
								||
								($this->session->data['payment_method']['code'] == 'ukrcredits_pl' && !$setting['pl_discount'])
								||
								($this->session->data['payment_method']['code'] == 'ukrcredits_pu' && !$setting['pu_discount'])
								||
								($this->session->data['payment_method']['code'] == 'ukrcredits_sb' && !$setting['sb_discount'])
								)
							)
							||
							(
								isset($this->session->data['payment_method']['code']) 
								&& 
								$this->session->data['payment_method']['code'] != 'ukrcredits_pp'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_ii'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_mb'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_ab'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_aa'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_pl'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_pu'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_sb'
							)
							||
							!isset($this->session->data['payment_method']['code'])
						)
					{
						$price = $product_discount_query->row['price'];
					}
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[$price = $product_special_query->row['price'];]]></search>
			<add position="replace"><![CDATA[
					$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
					if	(
							(	
								isset($this->session->data['payment_method']['code']) && 
								(
								($this->session->data['payment_method']['code'] == 'ukrcredits_pp' && !$setting['pp_special'] && ((isset($ukrcredits_query->row['special_pp']) && !$ukrcredits_query->row['special_pp']) || !isset($ukrcredits_query->row['special_pp'])))
								|| 
								($this->session->data['payment_method']['code'] == 'ukrcredits_ii' && !$setting['ii_special'] && ((isset($ukrcredits_query->row['special_ii']) && !$ukrcredits_query->row['special_ii']) || !isset($ukrcredits_query->row['special_ii'])))
								||
								($this->session->data['payment_method']['code'] == 'ukrcredits_mb' && !$setting['mb_special'] && ((isset($ukrcredits_query->row['special_mb']) && !$ukrcredits_query->row['special_mb']) || !isset($ukrcredits_query->row['special_mb'])))
								||
								($this->session->data['payment_method']['code'] == 'ukrcredits_ab' && !$setting['ab_special'] && ((isset($ukrcredits_query->row['special_ab']) && !$ukrcredits_query->row['special_ab']) || !isset($ukrcredits_query->row['special_ab'])))
								|| 
								($this->session->data['payment_method']['code'] == 'ukrcredits_aa' && !$setting['aa_special'] && ((isset($ukrcredits_query->row['special_aa']) && !$ukrcredits_query->row['special_aa']) || !isset($ukrcredits_query->row['special_aa'])))
								|| 
								($this->session->data['payment_method']['code'] == 'ukrcredits_pl' && !$setting['pl_special'] && ((isset($ukrcredits_query->row['special_pl']) && !$ukrcredits_query->row['special_pl']) || !isset($ukrcredits_query->row['special_pl'])))
								|| 
								($this->session->data['payment_method']['code'] == 'ukrcredits_pu' && !$setting['pu_special'] && ((isset($ukrcredits_query->row['special_pu']) && !$ukrcredits_query->row['special_pu']) || !isset($ukrcredits_query->row['special_pu'])))
								|| 
								($this->session->data['payment_method']['code'] == 'ukrcredits_sb' && !$setting['sb_special'] && ((isset($ukrcredits_query->row['special_sb']) && !$ukrcredits_query->row['special_sb']) || !isset($ukrcredits_query->row['special_sb'])))

								)
							)
							||
							(
								isset($this->session->data['payment_method']['code']) 
								&& 
								$this->session->data['payment_method']['code'] != 'ukrcredits_pp'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_ii'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_mb'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_ab'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_aa'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_pl'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_pu'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_sb'
							)
							||
							!isset($this->session->data['payment_method']['code'])
						)
					{
						$price = $product_special_query->row['price'];
					}
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[$product_data[] = array(]]></search>
			<add position="before"><![CDATA[
				$ucmarkup = 1;	
				if (!$this->config->get($typetotal.'totalukrcredits_status')) {
					if (isset($this->session->data['payment_method']['code'])) {
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_pp') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_pp']) && $ukrcredits_query->row['markup_pp'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_pp'];
								} else {
									$ucmarkup = $setting['pp_markup'];
								}
							}
							if ($setting['pp_markup_type'] == 'custom') {
								$ukrcredits_pp_sel = isset($this->session->data['ukrcredits_pp_sel'])?$this->session->data['ukrcredits_pp_sel']:1;
								$ucmarkup = ($setting['pp_markup_custom_PP'][$ukrcredits_pp_sel] + $setting['pp_markup_acquiring']) / 100 + 1;
							}
						}
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_ii') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_ii']) && $ukrcredits_query->row['markup_ii'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_ii'];
								} else {
									$ucmarkup = $setting['ii_markup'];
								}
							}
							if ($setting['ii_markup_type'] == 'custom') {
								$ukrcredits_ii_sel = isset($this->session->data['ukrcredits_ii_sel'])?$this->session->data['ukrcredits_ii_sel']:1;
								$ucmarkup = ($setting['ii_markup_custom_II'][$ukrcredits_ii_sel] + $setting['ii_markup_acquiring']) / 100 + 1;
							}
						}
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_mb') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_mb']) && $ukrcredits_query->row['markup_mb'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_mb'];
								} else {
									$ucmarkup = $setting['mb_markup'];
								}
							}
							if ($setting['mb_markup_type'] == 'custom') {
								$ukrcredits_mb_sel = isset($this->session->data['ukrcredits_mb_sel'])?$this->session->data['ukrcredits_mb_sel']:2;
								$ucmarkup = ($setting['mb_markup_custom_MB'][$ukrcredits_mb_sel] + $setting['mb_markup_acquiring']) / 100 + 1;
							}
						}
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_ab') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_ab']) && $ukrcredits_query->row['markup_ab'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_ab'];
								} else {
									$ucmarkup = $setting['ab_markup'];
								}
							}
							if ($setting['ab_markup_type'] == 'custom') {
								$ukrcredits_ab_sel = isset($this->session->data['ukrcredits_ab_sel'])?$this->session->data['ukrcredits_ab_sel']:3;
								$ucmarkup = ($setting['ab_markup_custom_AB'][$ukrcredits_ab_sel] + $setting['ab_markup_acquiring']) / 100 + 1;
							}
						}
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_aa') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_aa']) && $ukrcredits_query->row['markup_aa'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_aa'];
								} else {
									$ucmarkup = $setting['aa_markup'];
								}
							}
							if ($setting['aa_markup_type'] == 'custom') {
								$ukrcredits_aa_sel = isset($this->session->data['ukrcredits_aa_sel'])?$this->session->data['ukrcredits_aa_sel']:3;
								$ucmarkup = ($setting['aa_markup_custom_AA'][$ukrcredits_aa_sel] + $setting['aa_markup_acquiring']) / 100 + 1;
							}
						}
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_pl') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_pl']) && $ukrcredits_query->row['markup_pl'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_pl'];
								} else {
									$ucmarkup = $setting['pl_markup'];
								}
							}
							if ($setting['pl_markup_type'] == 'custom') {
								$ukrcredits_pl_sel = isset($this->session->data['ukrcredits_pl_sel'])?$this->session->data['ukrcredits_pl_sel']:3;
								$ucmarkup = ($setting['pl_markup_custom_PL'][$ukrcredits_pl_sel] + $setting['pl_markup_acquiring']) / 100 + 1;
							}
						}
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_pu') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_pu']) && $ukrcredits_query->row['markup_pu'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_pu'];
								} else {
									$ucmarkup = $setting['pu_markup'];
								}
							}
							if ($setting['pu_markup_type'] == 'custom') {
								$ukrcredits_pu_sel = isset($this->session->data['ukrcredits_pu_sel'])?$this->session->data['ukrcredits_pu_sel']:2;
								$ucmarkup = ($setting['pu_markup_custom_PU'][$ukrcredits_pu_sel] + $setting['pu_markup_acquiring']) / 100 + 1;
							}
						}
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_sb') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_sb']) && $ukrcredits_query->row['markup_sb'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_sb'];
								} else {
									$ucmarkup = $setting['sb_markup'];
								}
							}
							if ($setting['sb_markup_type'] == 'custom') {
								$ukrcredits_sb_sel = isset($this->session->data['ukrcredits_sb_sel'])?$this->session->data['ukrcredits_sb_sel']:2;
								$ucmarkup = ($setting['sb_markup_custom_sb'][$ukrcredits_sb_sel] + $setting['sb_markup_acquiring']) / 100 + 1;
							}
						}
					}
				}
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[($price + $option_price)]]></search>
			<add position="replace"><![CDATA[($price + $option_price) * $ucmarkup]]></add>
		</operation>
	</file>	
	
	<file path="system/library/cart.php">
		<operation error="log">
			<search><![CDATA[public function getProducts(]]></search>
			<add position="after"><![CDATA[
				$type = version_compare(VERSION,'3.0','>=') ? 'payment_' : '';
				$typetotal = version_compare(VERSION,'3.0','>=') ? 'total_' : '';
				$setting = $this->config->get($type.'ukrcredits_settings');
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[$price = $product_discount_query->row['price'];]]></search>
			<add position="replace"><![CDATA[
					if	(
							(	
								isset($this->session->data['payment_method']['code']) && 
								(
								($this->session->data['payment_method']['code'] == 'ukrcredits_pp' && !$setting['pp_discount'])
								|| 
								($this->session->data['payment_method']['code'] == 'ukrcredits_ii' && !$setting['ii_discount'])
								||
								($this->session->data['payment_method']['code'] == 'ukrcredits_mb' && !$setting['mb_discount'])
								||
								($this->session->data['payment_method']['code'] == 'ukrcredits_ab' && !$setting['ab_discount'])
								||
								($this->session->data['payment_method']['code'] == 'ukrcredits_aa' && !$setting['aa_discount'])
								||
								($this->session->data['payment_method']['code'] == 'ukrcredits_pl' && !$setting['pl_discount'])
								||
								($this->session->data['payment_method']['code'] == 'ukrcredits_pu' && !$setting['pu_discount'])
								||
								($this->session->data['payment_method']['code'] == 'ukrcredits_sb' && !$setting['sb_discount'])
								)
							)
							||
							(
								isset($this->session->data['payment_method']['code']) 
								&& 
								$this->session->data['payment_method']['code'] != 'ukrcredits_pp'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_ii'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_mb'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_ab'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_aa'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_pl'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_pu'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_sb'
							)
							||
							!isset($this->session->data['payment_method']['code'])
						)
					{
						$price = $product_discount_query->row['price'];
					}
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[$price = $product_special_query->row['price'];]]></search>
			<add position="replace"><![CDATA[
					$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
					if	(
							(	
								isset($this->session->data['payment_method']['code']) && 
								(
								($this->session->data['payment_method']['code'] == 'ukrcredits_pp' && !$setting['pp_special'] && ((isset($ukrcredits_query->row['special_pp']) && !$ukrcredits_query->row['special_pp']) || !isset($ukrcredits_query->row['special_pp'])))
								|| 
								($this->session->data['payment_method']['code'] == 'ukrcredits_ii' && !$setting['ii_special'] && ((isset($ukrcredits_query->row['special_ii']) && !$ukrcredits_query->row['special_ii']) || !isset($ukrcredits_query->row['special_ii'])))
								||
								($this->session->data['payment_method']['code'] == 'ukrcredits_mb' && !$setting['mb_special'] && ((isset($ukrcredits_query->row['special_mb']) && !$ukrcredits_query->row['special_mb']) || !isset($ukrcredits_query->row['special_mb'])))
								||
								($this->session->data['payment_method']['code'] == 'ukrcredits_ab' && !$setting['ab_special'] && ((isset($ukrcredits_query->row['special_ab']) && !$ukrcredits_query->row['special_ab']) || !isset($ukrcredits_query->row['special_ab'])))
								|| 
								($this->session->data['payment_method']['code'] == 'ukrcredits_aa' && !$setting['aa_special'] && ((isset($ukrcredits_query->row['special_aa']) && !$ukrcredits_query->row['special_aa']) || !isset($ukrcredits_query->row['special_aa'])))
								|| 
								($this->session->data['payment_method']['code'] == 'ukrcredits_pl' && !$setting['pl_special'] && ((isset($ukrcredits_query->row['special_pl']) && !$ukrcredits_query->row['special_pl']) || !isset($ukrcredits_query->row['special_pl'])))
								|| 
								($this->session->data['payment_method']['code'] == 'ukrcredits_pu' && !$setting['pu_special'] && ((isset($ukrcredits_query->row['special_pu']) && !$ukrcredits_query->row['special_pu']) || !isset($ukrcredits_query->row['special_pu'])))
								|| 
								($this->session->data['payment_method']['code'] == 'ukrcredits_sb' && !$setting['sb_special'] && ((isset($ukrcredits_query->row['special_sb']) && !$ukrcredits_query->row['special_sb']) || !isset($ukrcredits_query->row['special_sb'])))

								)
							)
							||
							(
								isset($this->session->data['payment_method']['code']) 
								&& 
								$this->session->data['payment_method']['code'] != 'ukrcredits_pp'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_ii'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_mb'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_ab'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_aa'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_pl'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_pu'
								&&
								$this->session->data['payment_method']['code'] != 'ukrcredits_sb'
							)
							||
							!isset($this->session->data['payment_method']['code'])
						)
					{
						$price = $product_special_query->row['price'];
					}
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[$this->data[$key] = array(]]></search>
			<add position="before"><![CDATA[
				$ucmarkup = 1;	
				if (!$this->config->get($typetotal.'totalukrcredits_status')) {
					if (isset($this->session->data['payment_method']['code'])) {
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_pp') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_pp']) && $ukrcredits_query->row['markup_pp'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_pp'];
								} else {
									$ucmarkup = $setting['pp_markup'];
								}
							}
							if ($setting['pp_markup_type'] == 'custom') {
								$ukrcredits_pp_sel = isset($this->session->data['ukrcredits_pp_sel'])?$this->session->data['ukrcredits_pp_sel']:1;
								$ucmarkup = ($setting['pp_markup_custom_PP'][$ukrcredits_pp_sel] + $setting['pp_markup_acquiring']) / 100 + 1;
							}
						}
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_ii') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_ii']) && $ukrcredits_query->row['markup_ii'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_ii'];
								} else {
									$ucmarkup = $setting['ii_markup'];
								}
							}
							if ($setting['ii_markup_type'] == 'custom') {
								$ukrcredits_ii_sel = isset($this->session->data['ukrcredits_ii_sel'])?$this->session->data['ukrcredits_ii_sel']:1;
								$ucmarkup = ($setting['ii_markup_custom_II'][$ukrcredits_ii_sel] + $setting['ii_markup_acquiring']) / 100 + 1;
							}
						}
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_mb') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_mb']) && $ukrcredits_query->row['markup_mb'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_mb'];
								} else {
									$ucmarkup = $setting['mb_markup'];
								}
							}
							if ($setting['mb_markup_type'] == 'custom') {
								$ukrcredits_mb_sel = isset($this->session->data['ukrcredits_mb_sel'])?$this->session->data['ukrcredits_mb_sel']:2;
								$ucmarkup = ($setting['mb_markup_custom_MB'][$ukrcredits_mb_sel] + $setting['mb_markup_acquiring']) / 100 + 1;
							}
						}
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_ab') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_ab']) && $ukrcredits_query->row['markup_ab'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_ab'];
								} else {
									$ucmarkup = $setting['ab_markup'];
								}
							}
							if ($setting['ab_markup_type'] == 'custom') {
								$ukrcredits_ab_sel = isset($this->session->data['ukrcredits_ab_sel'])?$this->session->data['ukrcredits_ab_sel']:3;
								$ucmarkup = ($setting['ab_markup_custom_AB'][$ukrcredits_ab_sel] + $setting['ab_markup_acquiring']) / 100 + 1;
							}
						}
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_aa') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_aa']) && $ukrcredits_query->row['markup_aa'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_aa'];
								} else {
									$ucmarkup = $setting['aa_markup'];
								}
							}
							if ($setting['aa_markup_type'] == 'custom') {
								$ukrcredits_aa_sel = isset($this->session->data['ukrcredits_aa_sel'])?$this->session->data['ukrcredits_aa_sel']:3;
								$ucmarkup = ($setting['aa_markup_custom_AA'][$ukrcredits_aa_sel] + $setting['aa_markup_acquiring']) / 100 + 1;
							}
						}
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_pl') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_pl']) && $ukrcredits_query->row['markup_pl'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_pl'];
								} else {
									$ucmarkup = $setting['pl_markup'];
								}
							}
							if ($setting['pl_markup_type'] == 'custom') {
								$ukrcredits_pl_sel = isset($this->session->data['ukrcredits_pl_sel'])?$this->session->data['ukrcredits_pl_sel']:3;
								$ucmarkup = ($setting['pl_markup_custom_PL'][$ukrcredits_pl_sel] + $setting['pl_markup_acquiring']) / 100 + 1;
							}
						}
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_pu') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_pu']) && $ukrcredits_query->row['markup_pu'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_pu'];
								} else {
									$ucmarkup = $setting['pu_markup'];
								}
							}
							if ($setting['pu_markup_type'] == 'custom') {
								$ukrcredits_pu_sel = isset($this->session->data['ukrcredits_pu_sel'])?$this->session->data['ukrcredits_pu_sel']:2;
								$ucmarkup = ($setting['pu_markup_custom_PU'][$ukrcredits_pu_sel] + $setting['pu_markup_acquiring']) / 100 + 1;
							}
						}
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_sb') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_sb']) && $ukrcredits_query->row['markup_sb'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_sb'];
								} else {
									$ucmarkup = $setting['sb_markup'];
								}
							}
							if ($setting['sb_markup_type'] == 'custom') {
								$ukrcredits_sb_sel = isset($this->session->data['ukrcredits_sb_sel'])?$this->session->data['ukrcredits_sb_sel']:2;
								$ucmarkup = ($setting['sb_markup_custom_sb'][$ukrcredits_sb_sel] + $setting['sb_markup_acquiring']) / 100 + 1;
							}
						}
					}
				}
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[$product_data[] = array(]]></search>
			<add position="before"><![CDATA[
				$ucmarkup = 1;	
				if (!$this->config->get($typetotal.'totalukrcredits_status')) {
					if (isset($this->session->data['payment_method']['code'])) {
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_pp') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_pp']) && $ukrcredits_query->row['markup_pp'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_pp'];
								} else {
									$ucmarkup = $setting['pp_markup'];
								}
							}
							if ($setting['pp_markup_type'] == 'custom') {
								$ukrcredits_pp_sel = isset($this->session->data['ukrcredits_pp_sel'])?$this->session->data['ukrcredits_pp_sel']:1;
								$ucmarkup = ($setting['pp_markup_custom_PP'][$ukrcredits_pp_sel] + $setting['pp_markup_acquiring']) / 100 + 1;
							}
						}
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_ii') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_ii']) && $ukrcredits_query->row['markup_ii'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_ii'];
								} else {
									$ucmarkup = $setting['ii_markup'];
								}
							}
							if ($setting['ii_markup_type'] == 'custom') {
								$ukrcredits_ii_sel = isset($this->session->data['ukrcredits_ii_sel'])?$this->session->data['ukrcredits_ii_sel']:1;
								$ucmarkup = ($setting['ii_markup_custom_II'][$ukrcredits_ii_sel] + $setting['ii_markup_acquiring']) / 100 + 1;
							}
						}
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_mb') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_mb']) && $ukrcredits_query->row['markup_mb'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_mb'];
								} else {
									$ucmarkup = $setting['mb_markup'];
								}
							}
							if ($setting['mb_markup_type'] == 'custom') {
								$ukrcredits_mb_sel = isset($this->session->data['ukrcredits_mb_sel'])?$this->session->data['ukrcredits_mb_sel']:2;
								$ucmarkup = ($setting['mb_markup_custom_MB'][$ukrcredits_mb_sel] + $setting['mb_markup_acquiring']) / 100 + 1;
							}
						}
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_ab') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_ab']) && $ukrcredits_query->row['markup_ab'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_ab'];
								} else {
									$ucmarkup = $setting['ab_markup'];
								}
							}
							if ($setting['ab_markup_type'] == 'custom') {
								$ukrcredits_ab_sel = isset($this->session->data['ukrcredits_ab_sel'])?$this->session->data['ukrcredits_ab_sel']:2;
								$ucmarkup = ($setting['ab_markup_custom_AB'][$ukrcredits_ab_sel] + $setting['ab_markup_acquiring']) / 100 + 1;
							}
						}
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_aa') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_aa']) && $ukrcredits_query->row['markup_aa'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_aa'];
								} else {
									$ucmarkup = $setting['aa_markup'];
								}
							}
							if ($setting['aa_markup_type'] == 'custom') {
								$ukrcredits_aa_sel = isset($this->session->data['ukrcredits_aa_sel'])?$this->session->data['ukrcredits_aa_sel']:2;
								$ucmarkup = ($setting['aa_markup_custom_AA'][$ukrcredits_aa_sel] + $setting['aa_markup_acquiring']) / 100 + 1;
							}
						}	
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_pl') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_pl']) && $ukrcredits_query->row['markup_pl'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_pl'];
								} else {
									$ucmarkup = $setting['pl_markup'];
								}
							}
							if ($setting['pl_markup_type'] == 'custom') {
								$ukrcredits_pl_sel = isset($this->session->data['ukrcredits_pl_sel'])?$this->session->data['ukrcredits_pl_sel']:2;
								$ucmarkup = ($setting['pl_markup_custom_PL'][$ukrcredits_pl_sel] + $setting['pl_markup_acquiring']) / 100 + 1;
							}
						}		
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_pu') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_pu']) && $ukrcredits_query->row['markup_pu'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_pu'];
								} else {
									$ucmarkup = $setting['pu_markup'];
								}
							}
							if ($setting['pu_markup_type'] == 'custom') {
								$ukrcredits_pu_sel = isset($this->session->data['ukrcredits_pu_sel'])?$this->session->data['ukrcredits_pu_sel']:2;
								$ucmarkup = ($setting['pu_markup_custom_PU'][$ukrcredits_pu_sel] + $setting['pu_markup_acquiring']) / 100 + 1;
							}
						}	
						if ($this->session->data['payment_method']['code'] == 'ukrcredits_sb') {
							$ukrcredits_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_ukrcredits WHERE product_id = '" . (int)$product_query->row['product_id'] . "'");
							if (isset($ukrcredits_query->row)) {
								if (isset($ukrcredits_query->row['markup_sb']) && $ukrcredits_query->row['markup_sb'] != 0) {
									$ucmarkup = $ukrcredits_query->row['markup_sb'];
								} else {
									$ucmarkup = $setting['sb_markup'];
								}
							}
							if ($setting['sb_markup_type'] == 'custom') {
								$ukrcredits_sb_sel = isset($this->session->data['ukrcredits_sb_sel'])?$this->session->data['ukrcredits_sb_sel']:2;
								$ucmarkup = ($setting['sb_markup_custom_sb'][$ukrcredits_sb_sel] + $setting['sb_markup_acquiring']) / 100 + 1;
							}
						}
					}
				}
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[($price + $option_price)]]></search>
			<add position="replace"><![CDATA[($price + $option_price) * $ucmarkup]]></add>
		</operation>
	</file>	
	<file path="catalog/model/checkout/order.php">
		<operation>
			<search index="0"><![CDATA[public function addOrderHistory]]></search>
			<add position="before"><![CDATA[
	public function setUkrcreditsOrderId($order_id, $paymenttype, $mono_order_id, $mono_order_status, $mono_order_substatus = false) {
		$order_info=$this->getOrder($order_id);

		if ( $order_info && !$order_info['order_status_id'] ) {
			$this->db->query("DELETE FROM " . DB_PREFIX . "order_ukrcredits WHERE order_id = '" . (int)$order_id . "'");
			$this->db->query("INSERT INTO " . DB_PREFIX . "order_ukrcredits SET order_id = '" . (int)$order_id . "', ukrcredits_payment_type = '" . $this->db->escape($paymenttype) . "', ukrcredits_order_id = '" . $this->db->escape($mono_order_id) . "', ukrcredits_order_status = '" . $this->db->escape($mono_order_status) . "', ukrcredits_order_substatus = '" . $this->db->escape($mono_order_substatus) . "'");
	 	}		
	}			
	public function getOrderMb($mono_order_id) {
		$ordermb_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_ukrcredits` WHERE ukrcredits_order_id = '" . $this->db->escape($mono_order_id) . "'");
		if ($ordermb_query->num_rows) {
			return $ordermb_query->row;			
		} else {
			return false;
		}
	}
	public function updateUkrcreditsOrderMono($order_id, $state, $substate) {
		$this->db->query("UPDATE " . DB_PREFIX . "order_ukrcredits SET ukrcredits_order_status = '" . $this->db->escape($state) . "', ukrcredits_order_substatus = '" . $this->db->escape($substate) . "' WHERE order_id = '" . (int)$order_id . "'");
	}
	public function updateUkrcreditsOrderPrivat($order_id, $privat_order_status) {
		$this->db->query("UPDATE " . DB_PREFIX . "order_ukrcredits SET ukrcredits_order_status = '" . $this->db->escape($privat_order_status) . "' WHERE order_id = '" . (int)$order_id . "'");
	}
			]]></add>
		</operation>
	</file>
	
	<file path="catalog/controller/checkout/success.php">
		<operation>
			<search><![CDATA[public function index]]></search>
			<add position="before"><![CDATA[
public function joinValues($dto) {
    $values = array();
    $keys = array(
        'login','frameSecretKey','clientPhone', 'clientMail', 'clientFirstName', 'clientLastName',
        'clientMiddleName','partnerId','subProduct','shopId','gracePeriod', 'initialPaymentAmount'
    );
    $merchandiseKeys = array('code','name','quantity');
    foreach ($keys as $k) {
        if (isset($dto[$k])) {
            array_push($values,$dto[$k]);
        }
    }
    if (isset($dto['merchandises'])) {
        foreach ($dto['merchandises'] as $m) {
            foreach ($merchandiseKeys as $k) {
                if (isset($m[$k])) array_push($values,$m[$k]);
            }
        }
    }
    return implode(':',$values);
}

public function sense_loan_online_widget($args) {
  $type = version_compare(VERSION,'3.0','>=') ? 'payment_' : '';
  $setting = $this->config->get($type.'ukrcredits_settings');
  $API_URL = 'https://emoney-test.sensebank.kyiv.ua/onlineCreditUniversalApiPartners';
  if ($setting['sb_mode']) $API_URL = $args['apiUrl'];

  $buttonClass = isset($args['buttonClass'])?$args['buttonClass']:"";
  $buttonText = isset($args['buttonText'])?$args['buttonText']:"Кредит від Sense Банк";
  $debug = isset($args['debug']) && $args['debug']===true;
  $values = $this->joinValues($args);
  $token = hash('sha512', $values);

  unset($args["login"]);
  unset($args["frameSecretKey"]);
  unset($args["buttonClass"]);
  unset($args["apiUrl"]);
  unset($args["buttonText"]);
  unset($args["debug"]);
  $debugFragment = "";
  if ($debug) {
      $debugFragment =
        "SENSE_CLIENT.signTemplate = \"$values\"";
  }

  $json = json_encode($args,JSON_UNESCAPED_UNICODE);
  $apiScriptSrc = $API_URL . "/api/external/easy-start.js?partnerId=" . $args['partnerId'];
  echo(
	<<<EOL
	<script onerror="alert('Помилка завантаження. Перезавантажте сторінку через декілька хвилин.')" src="$apiScriptSrc"></script>
	<script>
	    console.log('%cЗупиніться!',"color:red;font-size:25px;");
        console.log(`%cЦя функція браузера призначена для розробників. Якщо хтось сказав вам щось скопіювати і вставити сюди - це шахраї. %cВиконавши ці дії, Ви надасте їм доступ до конфіденційної інформації!`,'font-size:20px','font-size:20px;font-weight:bold');
		var SENSE = window.SENSE || {};
		var SENSE_CLIENT = {
			token: "$token",
			version: 2,
			data: $json
		}
		$debugFragment
            document.addEventListener("DOMContentLoaded", (event)=>{
                SENSE.loanMe();
            }
            );		
	</script>

EOL
  );

}
			]]></add>
		</operation>
		<operation>
			<search><![CDATA[public function index]]></search>
			<add position="after"><![CDATA[
		if (isset($this->session->data['order_id']) && !empty($this->session->data['order_id']) && isset($this->session->data['payment_method']['code']) && $this->session->data['payment_method']['code'] == 'ukrcredits_sb') {
			$this->session->data['sb_order_id'] = $this->session->data['order_id'];

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

			$sb_order_info = $this->model_checkout_order->getOrder($this->session->data['sb_order_id']);
			$sb_order_products = $this->model_account_order->getOrderProducts($this->session->data['sb_order_id']);
			
			$type = version_compare(VERSION,'3.0','>=') ? 'payment_' : '';
			$setting = $this->config->get($type.'ukrcredits_settings');
			
			$telephone = str_replace(['+','(', ')', '-', ' '], '', $sb_order_info['telephone']);
			if (substr($telephone, 0, 1) == 0) {
			$telephone = '+38' . $telephone;
			} else if (substr($telephone, 0, 2) == 80) {
			$telephone = '+3' . $telephone;
			} else {
			$telephone = '+' . $telephone;	
			}

			$merchandises = array();
			foreach ($sb_order_products as $sb_product) {
				$merchandises[] = array(
					'name' =>		$sb_product['name'],
					'quantity' =>	$sb_product['quantity'],
					'price' =>		number_format($sb_product['price'], 2, '.', ''),
					'code' =>		$sb_product['model']				
				);
			}
	
			$args = array(
				'login'=> 				$setting['sb_login'],
				'frameSecretKey'=>		$setting['sb_frameSecretKey'],
				'merchandises'=>		$merchandises,
				'clientPhone'=>			$telephone,
				'clientFirstName'=>		$sb_order_info['firstname'],
				'clientLastName'=>		$sb_order_info['lastname'],
				'clientMiddleName'=>	'',
				'partnerId'=>			$setting['sb_partnerId'],
				'subProduct'=>			(isset($this->session->data['ukrcredits_sb_sel']) && $this->session->data['ukrcredits_sb_sel'])?$setting['sb_id_data'][$this->session->data['ukrcredits_sb_sel']]:$setting['sb_id_data'][key($setting['sb_id_data'])],
				'gracePeriod'=>			(isset($this->session->data['ukrcredits_sb_sel']) && $this->session->data['ukrcredits_sb_sel'])?$this->session->data['ukrcredits_sb_sel']:3,
				'shopId'=>				$setting['sb_shopId'],
				'invoiceNumber'=>		'INVOICE_NUM_'.$this->session->data['sb_order_id'],
				'invoiceDate'=>			gmdate('Y-m-d', time()),
				'initialPaymentAmount'=>'0',
				'buttonClass'=>			'button sell-button whatever-you-need',
				'buttonText'=>			'SENSE',
				'apiUrl'=>'https://emoney.sensebank.com.ua/onlineCreditUniversalApi'
			);

			$this->sense_loan_online_widget($args);
		}
			]]></add>
		</operation>
	</file>
</modification>