<?xml version="1.0" encoding="utf-8"?>
<modification>
  <name>Out of Stock Alert</name>
  <code>Out of Stock Alert</code>
  <version>1.0</version>
  <author>Tom</author>
  <link>Out of Stock Alert</link>
	<file path="catalog/model/checkout/order.php">
		<operation>
			<search><![CDATA[$this->db->query("UPDATE " . DB_PREFIX . "product SET quantity = (quantity - " . (int)$order_product['quantity'] . ") WHERE product_id = '" . (int)$order_product['product_id'] . "' AND subtract = '1'");]]></search>
			<add position="after"><![CDATA[ 

				$qry = $this->db->query("SELECT p.quantity, p.model,pd.name FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd on ( p.product_id = pd.product_id ) WHERE p.product_id = '" . (int)$order_product['product_id'] . "'");

			    if ($qry->row['quantity'] < 1) {
                      $this->load->model('setting/store');

					  $product_link = str_replace('&amp;', '&', $this->url->link('product/product', 'product_id=' . $order_product['product_id']));	  
                      $text = 'Закончился товар на складе:<br />'."\n\n";
                      $text .= '<a href="' . $product_link . '">' . $qry->row['name'].'</a> ';

                      $mail = new Mail($this->config->get('config_mail_engine'));
                      $mail->parameter = $this->config->get('config_mail_parameter');
                      $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
                      $mail->smtp_username = $this->config->get('config_mail_smtp_username');
                      $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
                      $mail->smtp_port = $this->config->get('config_mail_smtp_port');
                      $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');

                      $mail->setTo('gmail@gmail.com');
                      $mail->setFrom($this->config->get('config_email'));
                      $mail->setSender(html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8'));
                      $mail->setSubject('Закончился товар на HQDTHAI: '.$qry->row['name']);
					  $mail->setHtml($text);
                      $mail->send();
				
                }
               
               ]]></add>
		</operation>
	</file>
</modification>