Снова Product Comments. Добавляем отправку уведомления о новом отзыве.
Возвращаясь к модулю Product Comments. В нем предусмотрена возможность модерации отзывов, но опять же, как и в случае с рейтингом по умолчанию, есть неприятный момент — уведомление о появлении нового отзыва не высылается владельцу магазина, а следовательно нет возможности осуществлять оперативную модерацию отзывов.
Для того чтобы исправить этот недочет разработчиков необходимо сделать некоторые правки в коде модуля.
Рассмотрим как это сделать на примере более новой версии Prestashop 1.6
Прежде всего нужно внести правки в функцию ajaxProcessAddComment, которая обрабатывает добавление нового отзыва. Функция находится в файле default.php, который расположен в каталоге:
/modules/productcomments/controllers/front/
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
protected function ajaxProcessAddComment() { $module_instance = new ProductComments(); $result = true; $id_guest = 0; $id_customer = $this->context->customer->id; if (!$id_customer) $id_guest = $this->context->cookie->id_guest; $errors = array(); // Validation if (!Validate::isInt(Tools::getValue('id_product'))) $errors[] = $module_instance->l('ID product is incorrect', 'default'); if (!Tools::getValue('title') || !Validate::isGenericName(Tools::getValue('title'))) $errors[] = $module_instance->l('Title is incorrect', 'default'); if (!Tools::getValue('content') || !Validate::isMessage(Tools::getValue('content'))) $errors[] = $module_instance->l('Comment is incorrect', 'default'); if (!$id_customer && (!Tools::isSubmit('customer_name') || !Tools::getValue('customer_name') || !Validate::isGenericName(Tools::getValue('customer_name')))) $errors[] = $module_instance->l('Customer name is incorrect', 'default'); if (!$this->context->customer->id && !Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS')) $errors[] = $module_instance->l('You must be logged in order to send a comment', 'default'); if (!count(Tools::getValue('criterion'))) $errors[] = $module_instance->l('You must give a rating', 'default'); $product = new Product(Tools::getValue('id_product')); if (!$product->id) $errors[] = $module_instance->l('Product not found', 'default'); if (!count($errors)) { $customer_comment = ProductComment::getByCustomer(Tools::getValue('id_product'), $id_customer, true, $id_guest); if (!$customer_comment || ($customer_comment && (strtotime($customer_comment['date_add']) + (int)Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) < time())) { $comment = new ProductComment(); $comment->content = strip_tags(Tools::getValue('content')); $comment->id_product = (int)Tools::getValue('id_product'); $comment->id_customer = (int)$id_customer; $comment->id_guest = $id_guest; $comment->customer_name = Tools::getValue('customer_name'); if (!$comment->customer_name) $comment->customer_name = pSQL($this->context->customer->firstname.' '.$this->context->customer->lastname); $comment->title = Tools::getValue('title'); $comment->grade = 0; $comment->validate = 0; $comment->save(); $grade_sum = 0; foreach(Tools::getValue('criterion') as $id_product_comment_criterion => $grade) { $grade_sum += $grade; $product_comment_criterion = new ProductCommentCriterion($id_product_comment_criterion); if ($product_comment_criterion->id) $product_comment_criterion->addGrade($comment->id, $grade); } if (count(Tools::getValue('criterion')) >= 1) { $comment->grade = $grade_sum / count(Tools::getValue('criterion')); // Update Grade average of comment $comment->save(); } $result = true; Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('productcomments-reviews.tpl')); } else { $result = false; $errors[] = $module_instance->l('You should wait').' '.Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME').' '.$module_instance->l('seconds before posting a new comment'); } } else $result = false; die(Tools::jsonEncode(array( 'result' => $result, 'errors' => $errors ))); } |
Перед строкой:
Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath(‘productcomments-reviews.tpl’));
добавляем следующий код:
|
1 2 3 4 5 6 7 8 9 10 11 12 |
// отправить уведомление о новом отзыве $product_name = Product::getProductName($comment->id_product); $shop_email = Configuration::get('PS_SHOP_EMAIL'); $shop_name = Configuration::get('PS_SHOP_NAME'); Mail::Send(Configuration::get('PS_LANG_DEFAULT'), 'new_comment', Mail::l('New comment added'), array( '{comment_content}' => $comment->content, '{product_name}' => $product_name ), $shop_email, $shop_name, $shop_email); |
Данный код инициирует отправку email, уведомляющий о появлении нового отзыва после того как он был принят системой. Отправка письма будет осуществлятся на основной email вашего магазина, котрый указан в разделе «Настройка» — «Контакты магазина» админки Prestashop. Письмо-уведомление будет содержать текст отзыва и название товара, на который был оставлен отзыв.
После добавления кода не забудьте сделать резервную копию файла default.php — это позволит вам сохранить внесенные изменения в случае обновления модуля productcomments.
Теперь необходимо создать шаблон (вернее два шаблона — для html и текстовой версии) письма. Эти шаблоны в дальнейшем следует скопировать в каталог /mails/XX, где «XX» — каталог шаблонов писем языка по умолчанию вашей версии Prestashop (ru — если это русский язык, uk — если украинский, и т.д.)
Файл шаблона new_comment.html (html-версия):
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" /> <title>Сообщение от {shop_name}</title> <style> @media only screen and (max-width: 300px){ body { width:218px !important; margin:auto !important; } .table {width:195px !important;margin:auto !important;} .logo, .titleblock, .linkbelow, .box, .footer, .space_footer{width:auto !important;display: block !important;} span.title{font-size:20px !important;line-height: 23px !important} span.subtitle{font-size: 14px !important;line-height: 18px !important;padding-top:10px !important;display:block !important;} td.box p{font-size: 12px !important;font-weight: bold !important;} .table-recap table, .table-recap thead, .table-recap tbody, .table-recap th, .table-recap td, .table-recap tr { display: block !important; } .table-recap{width: 200px!important;} .table-recap tr td, .conf_body td{text-align:center !important;} .address{display: block !important;margin-bottom: 10px !important;} .space_address{display: none !important;} } @media only screen and (min-width: 301px) and (max-width: 500px) { body {width:308px!important;margin:auto!important;} .table {width:285px!important;margin:auto!important;} .logo, .titleblock, .linkbelow, .box, .footer, .space_footer{width:auto!important;display: block!important;} .table-recap table, .table-recap thead, .table-recap tbody, .table-recap th, .table-recap td, .table-recap tr { display: block !important; } .table-recap{width: 293px !important;} .table-recap tr td, .conf_body td{text-align:center !important;} } @media only screen and (min-width: 501px) and (max-width: 768px) { body {width:478px!important;margin:auto!important;} .table {width:450px!important;margin:auto!important;} .logo, .titleblock, .linkbelow, .box, .footer, .space_footer{width:auto!important;display: block!important;} } @media only screen and (max-device-width: 480px) { body {width:308px!important;margin:auto!important;} .table {width:285px;margin:auto!important;} .logo, .titleblock, .linkbelow, .box, .footer, .space_footer{width:auto!important;display: block!important;} .table-recap{width: 285px!important;} .table-recap tr td, .conf_body td{text-align:center!important;} .address{display: block !important;margin-bottom: 10px !important;} .space_address{display: none !important;} } </style> </head> <body style="-webkit-text-size-adjust:none;background-color:#fff;width:650px;font-family:Open-sans, sans-serif;color:#555454;font-size:13px;line-height:18px;margin:auto"> <table class="table table-mail" style="width:100%;margin-top:10px;-moz-box-shadow:0 0 5px #afafaf;-webkit-box-shadow:0 0 5px #afafaf;-o-box-shadow:0 0 5px #afafaf;box-shadow:0 0 5px #afafaf;filter:progid:DXImageTransform.Microsoft.Shadow(color=#afafaf,Direction=134,Strength=5)"> <tr> <td class="space" style="width:20px;padding:7px 0"> </td> <td align="center" style="padding:7px 0"> <table class="table" bgcolor="#ffffff" style="width:100%"> <tr> <td align="center" class="logo" style="border-bottom:4px solid #333333;padding:7px 0"> <a title="{shop_name}" href="{shop_url}" style="color:#337ff1"> <img src="{shop_logo}" alt="{shop_name}" /> </a> </td> </tr> <tr> <td align="center" class="titleblock" style="padding:7px 0"> <font size="2" face="Open-sans, sans-serif" color="#555454"> <span class="title" style="font-weight:500;font-size:28px;text-transform:uppercase;line-height:33px">Здравствуйте!</span> </font> </td> </tr> <tr> <td class="space_footer" style="padding:0!important"> </td> </tr> <tr> <td class="box" style="border:1px solid #D6D4D4;background-color:#f8f8f8;padding:7px 0"> <table class="table" style="width:100%"> <tr> <td width="10" style="padding:7px 0"> </td> <td style="padding:7px 0"> <font size="2" face="Open-sans, sans-serif" color="#555454"> <p data-html-only="1" style="border-bottom:1px solid #D6D4D4;margin:3px 0 7px;text-transform:uppercase;font-weight:500;font-size:18px;padding-bottom:10px"> Вы получили новый отзыв о товаре "{product_name}" </p> <span style="color:#777"> {comment_content} </span> </font> </td> <td width="10" style="padding:7px 0"> </td> </tr> </table> </td> </tr> <tr> <td class="space_footer" style="padding:0!important"> </td> </tr> <tr> <td class="footer" style="border-top:4px solid #333333;padding:7px 0"> <span><a href="{shop_url}" style="color:#337ff1">{shop_name}</a></span> </td> </tr> </table> </td> <td class="space" style="width:20px;padding:7px 0"> </td> </tr> </table> </body> </html> |
И new_comment.txt, текстовая версия шаблона:
|
1 2 3 4 5 6 7 8 |
[{shop_url}] Здравствуйте!, Вы получили новый отзыв о товаре "{product_name}" {comment_content} {shop_name} [{shop_url}] |
Тексты в приведенных шаблонах на русском языке, при желании вы можете перевести их на язык по умолчанию вашей установки Prestashop.
Вот и все! Теперь вам будут приходить уведомления о новых отзывах.
P.S. Если вы используете Prestashop 1.5 то не сможете использоват приведенные выше шаблон. Вам нужно будет взять за основу какой-нибудь существующий шаблон, например — log_alert и отредактировать его по аналогии.
