<?xml version="1.0" encoding="utf-8"?>
<modification>
	<name>Tmd Currency Price</name>
	<id>Tmd Currency Price</id>
	<code>Tmd Currency Price</code>
	<version>3.x.x</version>
	<author>TMD(opencartextensions.in)</author>
	
	<file path="admin/controller/catalog/product.php">
		<operation error="log">
			<search><![CDATA[$product_option_value_data[] = array(]]></search>
			<add position="before"><![CDATA[
			// xml area currency_group
					$currencygroups = array();
					$this->load->model('localisation/currency');
					$data['entry_currency_price'] = $this->language->get('entry_currency_price');
					$data['entry_cprice'] = $this->language->get('entry_cprice');
					$currencys_groups = $this->model_localisation_currency->getCurrencies();
					foreach($currencys_groups as $groups) {
						$price='';
						if(isset($this->request->get['product_id'])){
						$price = $this->model_catalog_product->getCurrencyGroupOptions($this->request->get['product_id'],$groups['currency_id'],$product_option_value['product_option_value_id']);			
						}
						$currencygroups[$groups['currency_id']] =$price;
					}
					
			// xml area currency_group ends
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA['price_prefix'            => $product_option_value['price_prefix']]]></search>
			<add position="before"><![CDATA['currencys_groups'        => $currencygroups,]]></add>
		</operation>
		
		<operation error="log">
			<search><![CDATA[$data['layouts'] = $this->model_design_layout->getLayouts();]]></search>
			<add position="before"><![CDATA[
				// xml area currency_group
				$data['entry_currency_price'] = $this->language->get('entry_currency_price');
				$data['entry_cprice'] = $this->language->get('entry_cprice');
				if (isset($this->request->post['currency_group'])) {
						$data['currency_group'] = $this->request->post['currency_group'];
					} elseif (isset($this->request->get['product_id'])) {
						$data['currency_group'] = $this->model_catalog_product->getCurrencyPrice($this->request->get['product_id']);
					} else {
						$data['currency_group'] = array();

					}

					$this->load->model('localisation/currency');
					$data['options'] = $this->model_localisation_currency->getCurrencies();
				// xml area currency_group ends
			]]></add>
		</operation>
		
		<operation error="log">
			<search><![CDATA[$data['product_options'] = array();]]></search>
			<add position="before"><![CDATA[
				// xml area currency_group
				$this->load->model('localisation/currency');
				$data['currency_groups'] = $this->model_localisation_currency->getCurrencies();
				// xml area currency_group ends
			]]></add>
		</operation>

		<operation error="log">
			<search><![CDATA[foreach ($product_specials as $product_special) {]]></search>
			<add position="after"><![CDATA[
				// xml area special price
				$specialcurrencys_groups = $this->model_localisation_currency->getCurrencies();
				foreach($specialcurrencys_groups as $specialgroups) {
						$price='';
						$price = $this->model_catalog_product->getSpecialCurrencyGroupOptions($this->request->get['product_id'],$specialgroups['currency_id'],$product_special['product_special_id']);			
						$specialcurrencygroups[$specialgroups['currency_id']] =$price;
						
					}
				// xml area special price
			]]></add>
		</operation>

		<operation error="log">
			<search><![CDATA['price'             => $product_special['price'],]]></search>
			<add position="before"><![CDATA[
				// xml area special price
				'specialcurrencys_groups' => $specialcurrencygroups,
				// xml area special price
			]]></add>
		</operation>

		<operation error="log">
			<search><![CDATA[foreach ($product_discounts as $product_discount) {]]></search>
			<add position="after"><![CDATA[
				// xml area discount price
				$discountcurrencys_groups = $this->model_localisation_currency->getCurrencies();
				foreach($discountcurrencys_groups as $discountgroups) {
						if (isset($product_discount['product_discount_id'])) {
							$product_discount_id = $product_discount['product_discount_id'];
						}else{
							$product_discount_id = 0;
						}
						$price='';
						$price = $this->model_catalog_product->getDiscountCurrencyGroupOptions($this->request->get['product_id'],$discountgroups['currency_id'],$product_discount_id);			
						$discountcurrencygroups[$discountgroups['currency_id']] =$price;
						
					}
				// xml area discount price
			]]></add>
		</operation>

		<operation error="log">
			<search><![CDATA['price'             => $product_discount['price'],]]></search>
			<add position="before"><![CDATA[
				// xml area discount price
				'discountcurrencys_groups' => $discountcurrencygroups,
				// xml area discount price
			]]></add>
		</operation>

	</file>
	
	<file path="admin/language/*/catalog/product.php">
		<operation error="log">
			<search><![CDATA[$_['heading_title']          = 'Products';]]></search>
			<add position="before"><![CDATA[
				// xml currency_group
				$_['entry_currency_price']   = 'Curreny Price';
				$_['entry_cprice']   		 = 'Price';
				// xml currency_group ends
			]]></add>
		</operation>
	</file>
	
	<file path="admin/model/catalog/product.php">
		<operation error="log">
			<search><![CDATA[$this->db->query("INSERT INTO " . DB_PREFIX . "product_option_value SET product_option_id = '" . (int)$product_option_id . "', product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', option_value_id = '" . (int)$product_option_value['option_value_id'] . "', quantity = '" . (int)$product_option_value['quantity'] . "', subtract = '" . (int)$product_option_value['subtract'] . "', price = '" . (float)$product_option_value['price'] . "', price_prefix = '" . $this->db->escape($product_option_value['price_prefix']) . "', points = '" . (int)$product_option_value['points'] . "', points_prefix = '" . $this->db->escape($product_option_value['points_prefix']) . "', weight = '" . (float)$product_option_value['weight'] . "', weight_prefix = '" . $this->db->escape($product_option_value['weight_prefix']) . "'");]]></search>
			<add position="after"><![CDATA[
				// xml area currency_group
				$product_option_value_id = $this->db->getLastId();
				if (isset($product_option_value['currencygroup_option'])) {
					foreach ($product_option_value['currencygroup_option'] as $key => $groups) {
						$this->db->query("INSERT INTO " . DB_PREFIX . "product_currency_optionvalue SET 
						product_option_id 		= '" . (int)$product_option_id . "', 
						product_option_value_id = '" . (int)$product_option_value_id . "', 
						product_id 				= '" . (int)$product_id . "',
						option_value_id 		= '" . (int)$product_option_value['option_value_id'] . "', 
						option_id 				= '" . (int)$product_option['option_id'] . "',
		 				currency_id 		= '" . (int)$key . "',
						price 					= '" . (float)$groups['price'] . "'");
					}
				}
				// xml area currency_group ends
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[$this->db->query("INSERT INTO " . DB_PREFIX . "product_option_value SET product_option_value_id = '" . (int)$product_option_value['product_option_value_id'] . "', product_option_id = '" . (int)$product_option_id . "', product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', option_value_id = '" . (int)$product_option_value['option_value_id'] . "', quantity = '" . (int)$product_option_value['quantity'] . "', subtract = '" . (int)$product_option_value['subtract'] . "', price = '" . (float)$product_option_value['price'] . "', price_prefix = '" . $this->db->escape($product_option_value['price_prefix']) . "', points = '" . (int)$product_option_value['points'] . "', points_prefix = '" . $this->db->escape($product_option_value['points_prefix']) . "', weight = '" . (float)$product_option_value['weight'] . "', weight_prefix = '" . $this->db->escape($product_option_value['weight_prefix']) . "'");]]></search>
			<add position="after"><![CDATA[
				// xml area currency_group
				
				$product_option_value_id = $this->db->getLastId();
				if (isset($product_option_value['currencygroup_option'])) {
					foreach ($product_option_value['currencygroup_option'] as $key => $groups) {
						$this->db->query("INSERT INTO " . DB_PREFIX . "product_currency_optionvalue SET 
						product_option_id 		= '" . (int)$product_option_id . "', 
						product_option_value_id = '" . (int)$product_option_value_id. "', 
						product_id 				= '" . (int)$product_id . "',
						option_value_id 		= '" . (int)$product_option_value['option_value_id'] . "', 
						option_id 				= '" . (int)$product_option['option_id'] . "',
		 				currency_id 		= '" . (int)$key . "',
						price 					= '" . (float)$groups['price'] . "'");
					}
				}
				// xml area currency_group ends
			]]></add>
		</operation>
	
		<operation error="log">
			<search><![CDATA[if (isset($data['product_related'])) {]]></search>
			<add position="before"><![CDATA[
			// xml area currency_group
		        if (isset($data['currency_group'])) {
			    foreach ($data['currency_group'] as $key => $group) {
				  $this->db->query("INSERT INTO " . DB_PREFIX . "product_currency_price SET 
					product_id = '" . (int)$product_id . "',
					  currency_id = '" . (int)$key . "',
					    price  = '".$this->db->escape($group['price'])."'");
			    }
		    }
		    // xml area currency_group ends
		]]></add>
		</operation>
		
		<operation error="log">
			<search><![CDATA[$this->db->query("DELETE FROM " . DB_PREFIX . "product_option_value WHERE product_id = '" . (int)$product_id . "'");]]></search>
			<add position="before"><![CDATA[
				// xml area currency_group
				if (isset($data['currency_group'])) {
			        foreach ($data['currency_group'] as $key => $group) {
				      $this->db->query("INSERT INTO " . DB_PREFIX . "product_currency_price SET 
					  product_id = '" . (int)$product_id . "',
					  currency_id = '" . (int)$key . "',
					  price  = '".$this->db->escape($group['price'])."'");
			        }
		        }
				// xml area currency_group ends]]></add>
		</operation>

		<operation error="log">
			<search><![CDATA[$this->db->query("INSERT INTO " . DB_PREFIX . "product_special SET product_id = '" . (int)$product_id . "']]></search>
			<add position="after"><![CDATA[
				// xml area special_group
				$product_special_id = $this->db->getLastId();
				if (isset($product_special['currencygroup_special'])) {
					foreach ($product_special['currencygroup_special'] as $key => $specialgroups) {
						$this->db->query("INSERT INTO " . DB_PREFIX . "special_currency_price SET 
						product_special_id 				= '" . (int)$product_special_id . "',
						product_id 				= '" . (int)$product_id . "',
						currency_id 		= '" . (int)$key . "',
						price 					= '" . (float)$specialgroups['price'] . "'");
					}
				}
				// xml area special_group ends]]></add>
		</operation>

		<operation error="log">
			<search><![CDATA[$this->db->query("INSERT INTO " . DB_PREFIX . "product_discount SET product_id = '" . (int)$product_id . "']]></search>
			<add position="after"><![CDATA[
				// xml area discount_group
				$product_discount_id = $this->db->getLastId();
				if (isset($product_discount['currencygroup_discount'])) {
					foreach ($product_discount['currencygroup_discount'] as $key => $discountgroups) {
						$this->db->query("INSERT INTO " . DB_PREFIX . "discount_currency_price SET 
						product_discount_id 				= '" . (int)$product_discount_id . "',
						product_id 				= '" . (int)$product_id . "',
						currency_id 		= '" . (int)$key . "',
						price 					= '" . (float)$discountgroups['price'] . "'");
					}
				}
				// xml area discount_group ends]]></add>
		</operation>

		<operation error="log">
			<search><![CDATA[if (isset($data['product_option'])) {]]></search>
			<add position="before"><![CDATA[
				// xml area special_group
				$this->db->query("DELETE FROM " . DB_PREFIX . "discount_currency_price WHERE product_id = '" . (int)$product_id . "'");
				$this->db->query("DELETE FROM " . DB_PREFIX . "special_currency_price WHERE product_id = '" . (int)$product_id . "'");
				$this->db->query("DELETE FROM " . DB_PREFIX . "product_currency_optionvalue WHERE product_id = '" . (int)$product_id . "'");
				$this->db->query("DELETE FROM " . DB_PREFIX . "product_currency_price WHERE product_id = '" . (int)$product_id . "'");
				// xml area special_group ends]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[$this->db->query("DELETE FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product_id . "'");]]></search>
			<add position="before"><![CDATA[
				// xml area special_group
				$this->db->query("DELETE FROM " . DB_PREFIX . "discount_currency_price WHERE product_id = '" . (int)$product_id . "'");
				$this->db->query("DELETE FROM " . DB_PREFIX . "special_currency_price WHERE product_id = '" . (int)$product_id . "'");
				$this->db->query("DELETE FROM " . DB_PREFIX . "product_currency_optionvalue WHERE product_id = '" . (int)$product_id . "'");
				$this->db->query("DELETE FROM " . DB_PREFIX . "product_currency_price WHERE product_id = '" . (int)$product_id . "'");
				// xml area special_group ends]]></add>
		</operation>
	
		<operation error="log">
			<search><![CDATA[public function getTotalProductsByLayoutId($layout_id) {]]></search>
			<add position="before"><![CDATA[
				// xml area discount_group
				public function getDiscountCurrencyGroupOptions($product_id,$currency_id,$product_discount_id) {
					$discountgroup_query = $this->db->query("SELECT * FROM " .DB_PREFIX. "discount_currency_price WHERE product_id = '".(int)$product_id."' and product_discount_id='".(int)$product_discount_id."' and currency_id='".$currency_id."'");
					$price='';
					if (isset($discountgroup_query->row['price'])) {
					$price = $discountgroup_query->row['price'];
					}
					return $price;
				}
				// xml area discount_group
			// xml area currency_group
				  public function getCurrencyPrice($product_id) {
		          $currency_group_data = array();

		          $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_currency_price WHERE product_id = '" . (int)$product_id . "'");

		          foreach ($query->rows as $group) {
			      $currency_group_data[$group['currency_id']] = array('price' => $group['price']);
		        }

		           return $currency_group_data;
	        }
		
	                public function getCurrencyGroupOptions($product_id,$currency_id,$product_option_value_id) {
		            $group_query = $this->db->query("SELECT * FROM " .DB_PREFIX. "product_currency_optionvalue WHERE product_id = '".(int)$product_id."' and product_option_value_id='".(int)$product_option_value_id."' and currency_id='".$currency_id."'");
		            $price='';
		              if (isset($group_query->row['price'])) {
			            $price = $group_query->row['price'];
		            }
		          return $price;
	            }
	         
				
				public function getSpecialCurrencyGroupOptions($product_id,$currency_id,$product_special_id) {
					$specialgroup_query = $this->db->query("SELECT * FROM " .DB_PREFIX. "special_currency_price WHERE product_id = '".(int)$product_id."' and product_special_id='".(int)$product_special_id."' and currency_id='".$currency_id."'");
					$price='';
					if (isset($specialgroup_query->row['price'])) {
					$price = $specialgroup_query->row['price'];
					}
					return $price;
				}
	         // xml area currency_group ends
			
				]]></add>
		</operation>

		
	</file>
	<file path="admin/view/template/catalog/product_form.twig">
		<operation error="log">
			<search><![CDATA[<label class="col-sm-2 control-label" for="input-tax-class">{{ entry_tax_class }}</label>]]></search>
			<add position="before" offset="1"><![CDATA[
			<!--xml currency group price start-->
              <div class="form-group">
                <label class="col-sm-2 control-label" for="input-price">{{ entry_currency_price }}</label>
                <div class="table-responsive">
                <table class="table table-bordered table-hover">
                  <thead>
                    <tr>
                      <td class="text-left">{{ entry_currency_price }}</td>
                      <td class="text-left">{{ entry_cprice }}</td>
                    </tr>
                  </thead>
                  <tbody>
                    {% for currencygroup in currency_groups %}
                    <tr>
                      <td class="text-left">{{ currencygroup.title }}</td>
                      <td class="text-left"><input type="text" name="currency_group[{{ currencygroup.currency_id }}][price]" value="{{ currency_group[currencygroup.currency_id] ? currency_group[currencygroup.currency_id].price }}" placeholder="{{ entry_cprice }}" class="form-control" /></td>
                    </tr>
                    {% endfor %}
                  </tbody>
                </table>
              </div>
              </div>
			  <!--xml currency group price end-->
             ]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[<td class="text-right"><select name="product_option[{{ option_row }}][product_option_value][{{ option_value_row }}][price_prefix]" class="form-control">]]></search>
			<add position="replace"><![CDATA[
			<td class="text-right">
                    <table class="table table-bordered">
                        <thead>
                             <tr>
                                <td>{{ entry_currency_price }}</td>
                                <td>{{ entry_cprice }}</td>
                                </tr>
                                {% if currency_groups %}
                                 {% for currencygroup in currency_groups %}
                                <tr>
                                <td class="text-left">{{ currencygroup.title }}</td>
                                <td class="text-left"><input type="text" name="product_option[{{ option_row }}][product_option_value][{{ option_value_row }}][currencygroup_option][{{ currencygroup.currency_id }}][price]" value="{{ product_option_value.currencys_groups[currencygroup.currency_id] }}" placeholder="{{ entry_cprice }}" class="form-control" /></td>
                                </tr> 
                                {% endfor %}
                                {% endif %}
                        </thead>
                    </table>
					<select name="product_option[{{ option_row }}][product_option_value][{{ option_value_row }}][price_prefix]" class="form-control">
            ]]></add>
		</operation>

		<operation error="log">
			<search><![CDATA[<td class="text-right"><input type="text" name="product_special[{{ special_row }}][price]" value="{{ product_special.price }}" placeholder="{{ entry_price }}" class="form-control"/></td>]]></search>
			<add position="replace"><![CDATA[
				<!-- xml specail price -->
				<td class="text-right">
				<table class="table table-bordered">
					<thead>
						<tr>
							<td>{{ entry_currency_price }}</td>
							<td>{{ entry_cprice }}</td>
						</tr>
						{% if currency_groups %}
							{% for currencygroup in currency_groups %}
							<tr>
								<td class="text-left">{{ currencygroup.title }}</td>
								<td class="text-left"><input type="text" name="product_special[{{ special_row }}][currencygroup_special][{{ currencygroup.currency_id }}][price]" value="{{ product_special.specialcurrencys_groups[currencygroup.currency_id] }}" placeholder="{{ entry_cprice }}" class="form-control" /></td>
							</tr> 
							{% endfor %}
						{% endif %}
					</thead>
				</table>
				<input type="text" name="product_special[{{ special_row }}][price]" value="{{ product_special.price }}" placeholder="{{ entry_price }}" class="form-control"/></td>
				<!-- xml specail price -->

            ]]></add>
		</operation>

		<operation error="log">
			<search><![CDATA[<td class="text-right"><input type="text" name="product_discount[{{ discount_row }}][price]" value="{{ product_discount.price }}" placeholder="{{ entry_price }}" class="form-control"/></td>]]></search>
			<add position="replace"><![CDATA[
				<!-- xml discount price -->
				<td class="text-right">
				<table class="table table-bordered">
					<thead>
						<tr>
							<td>{{ entry_currency_price }}</td>
							<td>{{ entry_cprice }}</td>
						</tr>
						{% if currency_groups %}
							{% for currencygroup in currency_groups %}
							<tr>
								<td class="text-left">{{ currencygroup.title }}</td>
								<td class="text-left"><input type="text" name="product_discount[{{ discount_row }}][currencygroup_discount][{{ currencygroup.currency_id }}][price]" value="{{ product_discount.discountcurrencys_groups[currencygroup.currency_id] }}" placeholder="{{ entry_cprice }}" class="form-control" /></td>
							</tr> 
							{% endfor %}
						{% endif %}
					</thead>
				</table>
				<input type="text" name="product_discount[{{ discount_row }}][price]" value="{{ product_discount.price }}" placeholder="{{ entry_price }}" class="form-control"/></td>
				<!-- xml discount price -->

            ]]></add>
		</operation>

		<operation error="log">
			<search><![CDATA[html += '  <td class="text-right"><select name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][price_prefix]" class="form-control">';]]></search>
			<add position="replace"><![CDATA[
					html +='  <td class="text-right">';
					html +='<table class="table table-bordered">';
                   html += '<thead>';
                   html += '<tr>';
                   html += '<th>{{ entry_currency_price }}</th>';
                   html += '<th>{{ entry_cprice }}</th>';
                   html += '</tr>';
                  {% for currencygroup in currency_groups %}
                   html += '<tr>';
                   html += '<td class="text-left">{{ currencygroup.title }}</td>';
                   html += '<td class="text-left"><input type="text" name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][currencygroup_option][{{ currencygroup.currency_id }}][price]" placeholder="{{ entry_cprice }}" class="form-control" /></td>';
                   html += '</tr>';
                   {% endfor %}
                   html += '</thead>';
                   html += '</table>';
                   html +='<select name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][price_prefix]" class="form-control">';
            ]]></add>
		</operation>

		<operation error="log">
			<search><![CDATA[html += '  <td class="text-right"><input type="text" name="product_special[' + special_row + '][price]" value="" placeholder="{{ entry_price }}" class="form-control" /></td>';]]></search>
			<add position="replace"><![CDATA[
			//xml special price//
				html += '  <td class="text-right">';
				html +='<table class="table table-bordered">';
	               html += '<thead>';
	               html += '<tr>';
	               html += '<th>{{ entry_currency_price }}</th>';
	               html += '<th>{{ entry_cprice }}</th>';
	               html += '</tr>';
	              {% for specialcurrencygroup in currency_groups %}
	               html += '<tr>';
	               html += '<td class="text-left">{{ specialcurrencygroup.title }}</td>';
	               html += '<td class="text-left"><input type="text" name="product_special[' + special_row + '][currencygroup_special][{{ specialcurrencygroup.currency_id }}][price]" placeholder="{{ entry_cprice }}" class="form-control" /></td>';
	               html += '</tr>';
	               {% endfor %}
	               html += '</thead>';
	               html += '</table>';
	               html += '<input type="text" name="product_special[' + special_row + '][price]" value="" placeholder="{{ entry_price }}" class="form-control" /></td>';
	       //xml special price//
            ]]></add>
		</operation>

		<operation error="log">
			<search><![CDATA[html += '  <td class="text-right"><input type="text" name="product_discount[' + discount_row + '][price]" value="" placeholder="{{ entry_price }}" class="form-control" /></td>';]]></search>
			<add position="replace"><![CDATA[
			//xml discount price//
				html += '  <td class="text-right">';
				html +='<table class="table table-bordered">';
	               html += '<thead>';
	               html += '<tr>';
	               html += '<th>{{ entry_currency_price }}</th>';
	               html += '<th>{{ entry_cprice }}</th>';
	               html += '</tr>';
	              {% for discountcurrencygroup in currency_groups %}
	               html += '<tr>';
	               html += '<td class="text-left">{{ discountcurrencygroup.title }}</td>';
	               html += '<td class="text-left"><input type="text" name="product_discount[' + discount_row + '][currencygroup_discount][{{ discountcurrencygroup.currency_id }}][price]" placeholder="{{ entry_cprice }}" class="form-control" /></td>';
	               html += '</tr>';
	               {% endfor %}
	               html += '</thead>';
	               html += '</table>';
	               html += '<input type="text" name="product_discount[' + discount_row + '][price]" value="" placeholder="{{ entry_price }}" class="form-control" /></td>';
	       //xml discount price//
            ]]></add>
		</operation>

	</file>

	<file path="catalog/model/catalog/product.php">
		<operation error="log">
			<search><![CDATA[return array(]]></search>
			<add position="before"><![CDATA[
			// xml area currency_group
			$currency_ids = $this->getCurrency();
			$groupprice_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_currency_price WHERE product_id = '" . (int)$product_id . "' and currency_id='".$currency_ids['currency_id']."'");
			if ($groupprice_query->num_rows) 
			{
				if($groupprice_query->row['price']!='0.0')
				{
					$query->row['price']=$this->currency->convert($groupprice_query->row['price'],$this->session->data['currency'],$this->config->get('config_currency'));
				}
			}
			$specialprice_query = $this->db->query("SELECT scp.price as price,ps.price as special FROM " . DB_PREFIX . "product_special ps LEFT JOIN " . DB_PREFIX ."special_currency_price scp ON (ps.product_id = scp.product_id) WHERE ps.product_id = '".$product_id."' and currency_id='".$currency_ids['currency_id']."'  and ps.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "'  AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND  (ps.date_end = '0000-00-00' OR ps.date_end > NOW()))");

			if ($specialprice_query->num_rows) 
			{
				if($specialprice_query->row['price']!='0.0')
				{
					$query->row['special']=$this->currency->convert($specialprice_query->row['price'],$this->session->data['currency'],$this->config->get('config_currency'));
				}
			}
		    // xml area currency_group ends
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[public function getProductDiscounts($product_id) {]]></search>
			<add position="before"><![CDATA[
			// xml area currency_group
				public function getTmdProductDiscounts($product_id) {
		$currency_ids = $this->getCurrency();
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND quantity > 1 AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity ASC, priority ASC, price ASC");
		$tmddiscountprice = array();
		foreach ($query->rows as $value) {
			$discountprice_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "discount_currency_price WHERE product_id = '".$product_id."' and currency_id='".$currency_ids['currency_id']."' AND product_discount_id = '".$value['product_discount_id']."'");
			if(isset($discountprice_query->row['price'])){
			$discountprice_query->row['price']=$this->currency->convert($discountprice_query->row['price'],$this->session->data['currency'],$this->config->get('config_currency'));
			$tmddiscountprice[] = array(
				'product_discount_id' 	=> $value['product_discount_id'],
				'price' 				=> $discountprice_query->row['price'],
				'customer_group_id' 	=> $value['customer_group_id'],
				'quantity' 				=> $value['quantity'],
			);
			}
		}
		//print_r($tmddiscountprice);die();
		return $tmddiscountprice;
	}
		    // xml area currency_group ends
			]]></add>
		</operation>
		
		<operation error="log">
			<search><![CDATA[$product_option_value_data[] = array(]]></search>
			<add position="before"><![CDATA[
				$currency_ids = $this->getCurrency();
			    $optionprice_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_currency_optionvalue WHERE product_option_value_id = '" . (int)$product_option_value['product_option_value_id'] . "' and currency_id='".$currency_ids['currency_id']."'");

				if ($optionprice_query->num_rows) {
					if($optionprice_query->row['price']!='0.0'){
						$product_option_value['price']=$this->currency->convert($optionprice_query->row['price'],$this->session->data['currency'],$this->config->get('config_currency'));
					}
			    }
			]]></add>
		</operation>
		
		<operation error="log">
			<search><![CDATA[public function getTotalProductSpecials() {]]></search>
			<add position="before"><![CDATA[
				/* xml start */
				public function getCurrency() {
					
					$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "currency where code='".$this->session->data['currency']."'");
					
					return $query->row;
				}
				/* xml end */
			]]></add>
		</operation>
	</file>	
	
	
		<file path="system/library/cart/cart.php">
			<operation error="log">
				<search><![CDATA[$this->tax = $registry->get('tax');]]></search>
				<add position="after"><![CDATA[
					$this->currency = $registry->get('currency');
				]]></add>
			</operation>
			<operation error="log">
				<search><![CDATA[public function getProducts() {]]></search>
				<add position="after"><![CDATA[
					$currency_ids = $this->db->query("SELECT * FROM " . DB_PREFIX . "currency where code='".$this->session->data['currency']."'")->row;
				]]></add>
			</operation>
			<operation error="log">
				<search><![CDATA[if ($option_value_query->num_rows) {]]></search>
				<add position="after"><![CDATA[
					if(empty($product_option_value_id))
					{
						$product_option_value_id=$value;
					}
					$optionprice_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_currency_optionvalue WHERE currency_id='".$currency_ids['currency_id']."' and product_option_value_id='".$product_option_value_id."'");
					$product_option_value_id='';
					if ($optionprice_query->num_rows) 
					{
						if($optionprice_query->row['price']!='0.0')
						{
							$option_value_query->row['price']=$this->currency->convert($optionprice_query->row['price'],$this->session->data['currency'],$this->config->get('config_currency'));
						}
				    }
				]]></add>
			</operation>
		<operation error="log">
			<search><![CDATA[$price = $product_query->row['price'];]]></search>
			<add position="before"><![CDATA[
				/* xml start */
				$groupprice_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_currency_price WHERE product_id = '" . (int)$cart['product_id'] . "' and currency_id='".$currency_ids['currency_id']."'");
				if ($groupprice_query->num_rows) 
				{
					if($groupprice_query->row['price']!='0.0')
					{
						$product_query->row['price']=$this->currency->convert($groupprice_query->row['price'],$this->session->data['currency'],$this->config->get('config_currency'));
					}
				}
				/* xml end */
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[$product_special_query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_special]]></search>
			<add position="before"><![CDATA[
				/* xml start */
				$discountprice_query = $this->db->query("SELECT dcp.price as price,ps.price as discount,ps.quantity as quantity FROM " . DB_PREFIX . "product_discount ps LEFT JOIN " . DB_PREFIX ."discount_currency_price dcp ON (ps.product_discount_id = dcp.product_discount_id) WHERE ps.product_id = '".$cart['product_id']."' and  quantity <= '" . (int)$discount_quantity . "' and  currency_id='".$currency_ids['currency_id']."'  and ps.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "'  AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND  (ps.date_end = '0000-00-00' OR ps.date_end > NOW()))ORDER BY ps.quantity DESC, ps.priority ASC, dcp.price ASC LIMIT 1");
			
				if ($discountprice_query->num_rows) {
					if($discountprice_query->row['price']!='0.0')
					{
					 	$price = $this->currency->convert($discountprice_query->row['price'],$this->session->data['currency'],$this->config->get('config_currency'));
					}
				}
				/* xml end */
			]]></add>
		</operation>
		<operation error="log">
			<search><![CDATA[// Reward Points]]></search>
			<add position="before"><![CDATA[
				/* xml start */
				$specialprice_query = $this->db->query("SELECT scp.price as price,ps.price as special FROM " . DB_PREFIX . "product_special ps LEFT JOIN " . DB_PREFIX ."special_currency_price scp ON (ps.product_id = scp.product_id) WHERE ps.product_id = '".$cart['product_id']."' and currency_id='".$currency_ids['currency_id']."'  and ps.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "'  AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND  (ps.date_end = '0000-00-00' OR ps.date_end > NOW()))");
				if ($specialprice_query->num_rows) {
					if($specialprice_query->row['price']!='0.0')
					{
					 	$price = $this->currency->convert($specialprice_query->row['price'],$this->session->data['currency'],$this->config->get('config_currency'));
					}
				}
				/* xml end */
			]]></add>
		</operation>
	</file>
		<file path="catalog/model/journal2/product.php">
		<operation error="log">
			<search><![CDATA[$product_option_value_data[] = array(]]></search>
			<add position="before"><![CDATA[
				$currency_ids = $this->model_catalog_product->getCurrency();
			    $optionprice_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_currency_optionvalue WHERE product_option_value_id = '" . (int)$product_option_value['product_option_value_id'] . "' and currency_id='".$currency_ids['currency_id']."'");
					
				if ($optionprice_query->num_rows) {
					if($optionprice_query->row['price']!='0.0'){
					 	$product_option_value['price']=$this->currency->convert($optionprice_query->row['price'],$this->session->data['currency'],$this->config->get('config_currency'));
					}
			    }
			]]></add>
		</operation>
		</file>
		<file path="catalog/model/journal3/product.php">
		<operation error="log">
			<search><![CDATA[public function getProduct($product_id) {]]></search>
			<add position="before"><![CDATA[
				/* xml start */
				public function getCurrency() {					
					$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "currency where code='".$this->session->data['currency']."'");					
					return $query->row;
				}
				/* xml end */
			]]></add>
		</operation>	
		<operation error="log">
			<search><![CDATA[$result[$row['product_id']] = array(]]></search>
			<add position="before"><![CDATA[
				// xml area currency_group
				$currency_ids = $this->getCurrency();
				$groupprice_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_currency_price WHERE product_id = '" . (int)$row['product_id'] . "' and currency_id='".$currency_ids['currency_id']."'");
				if ($groupprice_query->num_rows) {
					if($groupprice_query->row['price']!='0.0'){
						$row['price'] = $this->currency->convert($groupprice_query->row['price'],$this->session->data['currency'],$this->config->get('config_currency'));
					}
				}
			
				$specialprice_query = $this->db->query("SELECT scp.price as price,ps.price as special FROM " . DB_PREFIX . "product_special ps LEFT JOIN " . DB_PREFIX ."special_currency_price scp ON (ps.product_special_id = scp.product_special_id) WHERE ps.product_id = '".$row['product_id']."' and currency_id='".$currency_ids['currency_id']."'  and ps.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "'  AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND  (ps.date_end = '0000-00-00' OR ps.date_end > NOW()))");
					
				if ($specialprice_query->num_rows) {
					if($specialprice_query->row['price']!='0.0'){
					 	$row['special'] = $this->currency->convert($specialprice_query->row['price'],$this->session->data['currency'],$this->config->get('config_currency'));
					}
				}
					
		    // xml area currency_group ends

			]]></add>
		</operation>
		</file>
		<file path="catalog/controller/journal3/price.php">
		<operation error="log">
			<search><![CDATA[foreach ($product_option_values as $product_option_value) {]]></search>
			<add position="after"><![CDATA[
				$currency_ids = $this->model_catalog_product->getCurrency();
			    $optionprice_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_currency_optionvalue WHERE product_option_value_id = '" . (int)$product_option_value['product_option_value_id'] . "' and currency_id='".$currency_ids['currency_id']."'");
					
				if ($optionprice_query->num_rows) {
					if($optionprice_query->row['price']!='0.0'){
					 	$product_option_value['price'] = $this->currency->convert($optionprice_query->row['price'],$this->session->data['currency'],$this->config->get('config_currency'));
					}
			    }
			]]></add>
		</operation>
		</file>
		<file path="catalog/controller/product/product.php">
		<operation error="log">
			<search><![CDATA[$this->model_catalog_product->getProductDiscounts($this->request->get['product_id']);]]></search>
			<add position="replace"><![CDATA[
				$discounts = $this->model_catalog_product->getTmdProductDiscounts($this->request->get['product_id']);
			]]></add>
		</operation>
		</file>
</modification>