review.php (3843B)
1 <?php 2 class ModelCatalogReview extends Model { 3 public function addReview($product_id, $data) { 4 $this->db->query("INSERT INTO " . DB_PREFIX . "review SET author = '" . $this->db->escape($data['name']) . "', customer_id = '" . (int)$this->customer->getId() . "', product_id = '" . (int)$product_id . "', text = '" . $this->db->escape($data['text']) . "', rating = '" . (int)$data['rating'] . "', date_added = NOW()"); 5 6 $review_id = $this->db->getLastId(); 7 8 if (in_array('review', (array)$this->config->get('config_mail_alert'))) { 9 $this->load->language('mail/review'); 10 $this->load->model('catalog/product'); 11 12 $product_info = $this->model_catalog_product->getProduct($product_id); 13 14 $subject = sprintf($this->language->get('text_subject'), html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8')); 15 16 $message = $this->language->get('text_waiting') . "\n"; 17 $message .= sprintf($this->language->get('text_product'), html_entity_decode($product_info['name'], ENT_QUOTES, 'UTF-8')) . "\n"; 18 $message .= sprintf($this->language->get('text_reviewer'), html_entity_decode($data['name'], ENT_QUOTES, 'UTF-8')) . "\n"; 19 $message .= sprintf($this->language->get('text_rating'), $data['rating']) . "\n"; 20 $message .= $this->language->get('text_review') . "\n"; 21 $message .= html_entity_decode($data['text'], ENT_QUOTES, 'UTF-8') . "\n\n"; 22 23 $mail = new Mail($this->config->get('config_mail_engine')); 24 $mail->parameter = $this->config->get('config_mail_parameter'); 25 $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname'); 26 $mail->smtp_username = $this->config->get('config_mail_smtp_username'); 27 $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'); 28 $mail->smtp_port = $this->config->get('config_mail_smtp_port'); 29 $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout'); 30 31 $mail->setTo($this->config->get('config_email')); 32 $mail->setFrom($this->config->get('config_email')); 33 $mail->setSender(html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8')); 34 $mail->setSubject($subject); 35 $mail->setText($message); 36 $mail->send(); 37 38 // Send to additional alert emails 39 $emails = explode(',', $this->config->get('config_mail_alert_email')); 40 41 foreach ($emails as $email) { 42 if ($email && filter_var($email, FILTER_VALIDATE_EMAIL)) { 43 $mail->setTo($email); 44 $mail->send(); 45 } 46 } 47 } 48 } 49 50 public function getReviewsByProductId($product_id, $start = 0, $limit = 20) { 51 if ($start < 0) { 52 $start = 0; 53 } 54 55 if ($limit < 1) { 56 $limit = 20; 57 } 58 59 $query = $this->db->query("SELECT r.review_id, r.author, r.rating, r.text, p.product_id, pd.name, p.price, p.image, r.date_added FROM " . DB_PREFIX . "review r LEFT JOIN " . DB_PREFIX . "product p ON (r.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE p.product_id = '" . (int)$product_id . "' AND p.date_available <= NOW() AND p.status = '1' AND r.status = '1' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY r.date_added DESC LIMIT " . (int)$start . "," . (int)$limit); 60 61 return $query->rows; 62 } 63 64 public function getTotalReviewsByProductId($product_id) { 65 $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r LEFT JOIN " . DB_PREFIX . "product p ON (r.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE p.product_id = '" . (int)$product_id . "' AND p.date_available <= NOW() AND p.status = '1' AND r.status = '1' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "'"); 66 67 return $query->row['total']; 68 } 69 }