<modification>
	<id>OC-Extensions.com - Price Match</id>
	<version>1.0</version>
	<vqmver>1.0.8</vqmver>
	<author>oc-extensions.com</author>

	<file name="catalog/controller/product/product.php">
		<operation error="log">
			<search position="after"><![CDATA[$this->language->load('product/product');]]></search>
			<add><![CDATA[	$this->language->load('module/price_match');]]></add>
		</operation>
		
		<operation error="log">
			<search position="before"><![CDATA[$this->model_catalog_product->updateViewed($this->request->get['product_id']);]]></search>
			<add><![CDATA[
			$this->document->addScript('catalog/view/javascript/jquery/jquery.pricematchreveal.js');
			
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/stylesheet/pricematchreveal.css')) {
				$this->document->addStyle('catalog/view/theme/' . $this->config->get('config_template') . '/stylesheet/pricematchreveal.css');
			} else {
				$this->document->addStyle('catalog/view/theme/default/stylesheet/pricematchreveal.css');
			}
			
			$this->data['text_price_match'] = $this->language->get('text_price_match');
			$this->data['heading_price_match'] = sprintf($this->language->get('heading_price_match'), $product_info['name']);
			
			$this->data['entry_price_match_customer_name'] = $this->language->get('entry_price_match_customer_name');
			$this->data['entry_price_match_customer_email'] = $this->language->get('entry_price_match_customer_email');
			$this->data['entry_price_match_customer_telephone'] = $this->language->get('entry_price_match_customer_telephone');
			$this->data['entry_price_match_competitor_link'] = $this->language->get('entry_price_match_competitor_link');
			$this->data['entry_price_match_competitor_price'] = $this->language->get('entry_price_match_competitor_price');
			$this->data['entry_price_match_message'] = $this->language->get('entry_price_match_message');
			
			$this->data['button_price_match_send_now'] = $this->language->get('button_price_match_send_now');
			
			$this->data['price_match_status'] = $this->config->get('price_match_status');
			
			if ($this->customer->isLogged()){
				$this->data['price_match_customer_name']  = $this->customer->getFirstName() . ' ' . $this->customer->getLastName();
				$this->data['price_match_customer_email'] = $this->customer->getEmail();
				$this->data['price_match_customer_telephone'] = $this->customer->getTelephone();
				
			} else {
				$this->data['price_match_customer_name']  = '';
				$this->data['price_match_customer_email'] = '';
				$this->data['price_match_customer_telephone'] = '';
			}
						
			if ((float)$product_info['special']) { 
				$pm_product_price = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')), '', '', false);
				$pm_product_price_no_tax = $this->currency->format($product_info['special'], '', '', false);
				
				
			} else {
				$pm_product_price = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), '', '', false);
				$pm_product_price_no_tax = $this->currency->format($product_info['price'], '', '', false);
			}
			
			$this->data['pm_product_price'] = $pm_product_price_no_tax;  // value without taxes, like in admin area
			$this->data['pm_product_price_with_tax'] = $pm_product_price;  // value without taxes, like in admin area
			$this->data['pm_product_tax'] = $pm_product_price - $pm_product_price_no_tax;
			
			if ($this->customer->isLogged()){
				$this->data['pm_customer_group_id'] = $this->customer->getCustomerGroupId();
			} else {
				$this->data['pm_customer_group_id'] = $this->config->get('config_customer_group_id');
			}
			
			]]></add>
		</operation>
		
	</file>
	
	<file name="catalog/view/theme/*/template/product/product.tpl">
		<operation error="log">
			<search position="before" index="1"><![CDATA[<?php if ($review_status) { ?>]]></search>
			<add><![CDATA[
				<?php if ($price_match_status) { ?> 
				<div class="attention"><?php echo $text_price_match; ?></div>
				<div id="dialog-price-match" class="pricematchreveal-modal">
					 <a class="close-pricematchreveal-modal">&#215;</a>
					<table class="form" id="price-match-form">
						<tbody>
							<tr>
								<td><span class="required">* </span><?php echo $entry_price_match_customer_name; ?></td>
								<td><input type="text" name="price_match_customer_name" value="<?php echo $price_match_customer_name; ?>" size="50"></td>
							</tr>
							<tr>
								<td><span class="required">* </span><?php echo $entry_price_match_customer_email; ?></td>
								<td><input type="text" name="price_match_customer_email" value="<?php echo $price_match_customer_email; ?>" size="50"></td>
							</tr>
							<tr>
								<td><?php echo $entry_price_match_customer_telephone; ?></td>
								<td><input type="text" name="price_match_customer_telephone" value="<?php echo $price_match_customer_telephone; ?>"></td>
							</tr>
							<tr>
								<td><span class="required">* </span><?php echo $entry_price_match_competitor_link; ?></td>
								<td><input type="text" name="price_match_competitor_link" size="50"></td>
							</tr>
							<tr>
								<td><span class="required">* </span><?php echo $entry_price_match_competitor_price; ?></td>
								<td><input type="text" name="price_match_competitor_price" size="10"></td>
							</tr>
							<tr>
								<td><?php echo $entry_price_match_message; ?></td>
								<td><textarea name="price_match_message" cols="50" rows="6"></textarea></td>
							</tr>
						</tbody>
					</table>
					<input type="hidden" name="price_match_product_id" value="<?php echo $product_id; ?>" />
					<input type="hidden" name="price_match_product_price" value="<?php echo $pm_product_price; ?>" />
					<input type="hidden" name="price_match_product_price_with_tax" value="<?php echo $pm_product_price_with_tax; ?>" />
					<input type="hidden" name="price_match_product_tax" value="<?php echo $pm_product_tax; ?>" />
					<input type="hidden" name="price_match_customer_group_id" value="<?php echo $pm_customer_group_id; ?>" />
					
					<div class="buttons">
						<div class="right"><a class="button" id="price-match-send" style="color: #FFF;"><?php echo $button_price_match_send_now; ?></a></div>
					</div>
				</div>
				<?php } ?>
			]]></add>
		</operation>
		
		<operation error="log">
			<search position="before"><![CDATA[<?php echo $footer; ?>]]></search>
			<add><![CDATA[
			<script type="text/javascript"><!--
			$('#price-match-trigger').bind('click', function(){
				$('#dialog-price-match').pricematchreveal();
			});
			
			$('#price-match-send').bind('click', function(){
				$.ajax({
					type: 'POST',
					url: 'index.php?route=module/price_match',
					data: $('#dialog-price-match input[type=\'text\'], #dialog-price-match input[type=\'hidden\'], #dialog-price-match textarea'),
					dataType: 'json',
					success: function(json){
						$('#dialog-price-match .warning').remove();
						$('#dialog-price-match .success').remove();
						
						if (json['error']){
							if (json['error']['warning']){
								$('#price-match-form').before('<div class="warning">' + json['error']['warning'] + '</div>');
								$('#dialog-price-match .success').fadeIn('slow');
							}
						}
						
						if (json['success']){
							$('#price-match-form').before('<div class="success">' + json['success'] + '</div>');
							$('#dialog-price-match .success').fadeIn('slow');
							
							setTimeout(function() {
								$('.close-pricematchreveal-modal').trigger('click');
							}, 2000);
						} 
					}
				});
			});
			//--></script>
			]]></add>
		</operation>
		
	</file>
	
</modification>