<?xml version="1.0" encoding="UTF-8"?>
<modification>
	<name>Disable add to cart when product out of stock</name>
	<version>1.0</version>
	<code>Disable_add_to_cart_when_product_out_of_stock</code>
	<author>Extensions Bazaar</author>
	<file path="catalog/view/theme/journal3/template/journal3/*.twig">
		<operation>
			<search><![CDATA[class="btn btn-cart"]]></search>
			<add position="replace"><![CDATA[class="btn btn-cart outofstock-{{ product.product_id }}"]]></add>
		</operation>
		<operation>
			<search><![CDATA[<a class="btn btn-extra btn-extra-{{ id }}"]]></search>
			<add position="replace"><![CDATA[<a class="btn btn-extra btn-extra-{{ id }} outofstock-{{ product.product_id }}"]]></add>
		</operation>
	</file>
	<file path="catalog/view/theme/journal3/template/product/product.twig">
		<operation>
			<search><![CDATA[$('#button-cart').button('loading');]]></search>
			<add position="replace"><![CDATA[ //$('#button-cart').button('loading');]]></add>
		</operation>
		<operation>
			<search><![CDATA[$('#button-cart').button('reset');]]></search>
			<add position="replace"><![CDATA[ //$('#button-cart').button('reset');]]></add>
		</operation>
	</file>
	<file path="catalog/controller/common/footer.php">
		<operation>
			<search><![CDATA[public function index() {]]></search>
			<add position="before"><![CDATA[
			public function disableaddtocart(){
				if($this->config->get('module_disable_addtocart_status')){
				$json['changeevents']=array('cart.add');
				$sql = "SELECT p.product_id,p.minimum FROM ".DB_PREFIX."product p LEFT JOIN ".DB_PREFIX."product_description pd ON(p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.quantity < 1 AND p.status = 1 AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "'";
				
				$sql .="AND p.quantity < 1 AND p.stock_status_id IN (". implode(',',$this->config->get('module_disable_addtocart_out_stock_status')).")";
				
				$query = $this->db->query($sql);
				foreach($query->rows as $row){
				   $json['outofstockproducts'][]=array(
					 'product_id' => $row['product_id'],
					 'minimum' 	  => $row['minimum'],
				   );
				}
				
				$json['buttontext'] = ($this->config->get('module_disable_addtocart_button_label'.$this->config->get('config_language_id')) ? html_entity_decode($this->config->get('module_disable_addtocart_button_label'.$this->config->get('config_language_id'))) : '');
				
				$this->response->addHeader('Content-Type: application/json');
				$this->response->setOutput(json_encode($json));
				}
			}
			]]></add>
		</operation>
		<operation>
			<search><![CDATA[$data['contact'] = $this->url->link('information/contact');]]></search>
			<add position="after"><![CDATA[
				$data['module_disable_addtocart_status'] = $this->config->get('module_disable_addtocart_status');
				if($this->config->get('module_disable_addtocart_status')){
					$this->document->addScript('catalog/view/javascript/disableaddtocart.js');
				}
			]]></add>
		</operation>
	</file>
</modification>