Информация в статье устарела! Мы сделали бесплатный модуль, который решает эту проблему.
Работа с БД.
Перед началом изменения БД необходимо сделать дамп (экспорт данных).
Для этого можно сделать Backup БД в панели хостинга.
Если в панели хостинга данного функционала нет, то необходимо:
Зайти в СУБД например PhpMyadmin, выбрать БД Вашего магазина.
Сделать Дамп БД
После того, как у нас есть данные для восстановления, необходимо открыть нашу БД в PhpMyadmin и вставить в поле SQL нижеперечисленные запросы.
ALTER TABLE `ok_comments`
ADD `license_agree` int(1) NOT NULL DEFAULT '0';
ALTER TABLE `ok_callbacks`
ADD `license_agree` int(1) NOT NULL DEFAULT '0';
ALTER TABLE `ok_subscribe_mailing`
ADD `license_agree` int(1) NOT NULL DEFAULT '0';
ALTER TABLE `ok_users`
ADD `license_agree` int(1) NOT NULL DEFAULT '0';
ALTER TABLE `ok_orders`
ADD `license_agree` int(1) NOT NULL DEFAULT '0';
2. Необходимо в админке добавить переводы, используя нижеперечисленные названия переводов.
license_agree – текст лицензионного соглашения
form_error_license_agree – текст, который увидит пользователь, если не поставит галочку.
3. Галочка в корзине
Заходим в файл /design/okay_shop/html/cart.tpl (примечание: если у вас стоит нестандартная тема, то открываете файлы темы в папке design и смотрите, файл tpl, в котором находится верстка данной формы).
В этих файлах вставьте код в блоки кода предоставленные ниже. Необходимо добавить код, который выделен комментариями {*license_agree*} …{*/license_agree*} или /*license_agree*/…/*/license_agree*/
В /design/okay_shop/html/cart.tpl
{* Form error messages *}
{if $error}
<div class="message_error">
{if $error == 'empty_name'}
<span data-language="form_enter_name">{$lang->form_enter_name}</span>
{/if}
{if $error == 'empty_email'}
<span data-language="form_enter_email">{$lang->form_enter_email}</span>
{/if}
{if $error == 'captcha'}
<span data-language="form_error_captcha">{$lang->form_error_captcha}</span>
{/if}
{if $error == 'empty_phone'}
<span data-language="form_error_phone">{$lang->form_error_phone}</span>
{/if}
{*license_agree*}
{if $error == 'empty_license_agree'}
<span data-language="form_error_license_agree">{$lang->form_error_license_agree}</span>
{/if}
{*/license_agree*}
</div>
{/if}
И
{* User's message *}
<div class="form_group">
<textarea class="form_textarea" rows="5" name="comment" data-language="cart_order_comment" placeholder="{$lang->cart_order_comment}">{$comment|escape}</textarea>
</div>
{*license_agree*}
{* License-agree *}
<div class="form_group">
<input type="checkbox" id="license_agree" name="license_agree" onclick="this.value='1';this.checked = true" value="" autocomplete="off"/>
{$lang->license_agree}
</div>
{*/license_agree*}
В api/Orders.php
/*Выборка конкретного заказа*/
public function get_order($id) {
if (empty($id)) {
return false;
}
if(is_int($id)) {
$where = $this->db->placehold('AND o.id=? ', intval($id));
} else {
$where = $this->db->placehold('AND o.url=? ', $id);
}
$query = $this->db->placehold("SELECT
o.id,
o.delivery_id,
o.delivery_price,
o.separate_delivery,
o.payment_method_id,
o.paid,
o.payment_date,
o.closed,
o.discount,
o.coupon_code,
o.coupon_discount,
o.date,
o.user_id,
o.name,
o.address,
o.phone,
o.email,
o.comment,
o.status_id,
o.url,
o.total_price,
o.note,
o.ip,
o.lang_id,
/*license_agree*/
o.license_agree
/*/license_agree*/
FROM s_orders o
WHERE
1
$where
LIMIT 1
");
И
// Выбираем заказы
$query = $this->db->placehold("SELECT
o.id,
o.delivery_id,
o.delivery_price,
o.separate_delivery,
o.payment_method_id,
o.paid,
o.payment_date,
o.closed,
o.discount,
o.coupon_code,
o.coupon_discount,
o.date,
o.user_id,
o.name,
o.address,
o.phone,
o.email,
o.comment,
o.status_id,
o.url,
o.total_price,
o.note,
o.lang_id,
/*license_agree*/
o.license_agree
/*/license_agree*/
FROM s_orders AS o
LEFT JOIN s_orders_labels AS ol ON o.id=ol.order_id
WHERE
В view/CartView.php
/*Оформление заказа*/
if(isset($_POST['checkout'])) {
$order = new stdClass;
$order->payment_method_id = $this->request->post('payment_method_id', 'integer');
$order->delivery_id = $this->request->post('delivery_id', 'integer');
$order->name = $this->request->post('name');
$order->email = $this->request->post('email');
$order->address = $this->request->post('address');
$order->phone = $this->request->post('phone');
$order->comment = $this->request->post('comment');
$order->ip = $_SERVER['REMOTE_ADDR'];
/*license_agree*/
$order->license_agree = $this->request->post('license_agree');
/*/license_agree*/
$this->design->assign('delivery_id', $order->delivery_id);
$this->design->assign('name', $order->name);
$this->design->assign('email', $order->email);
$this->design->assign('phone', $order->phone);
$this->design->assign('address', $order->address);
/*license_agree*/
$this->design->assign('license_agree', $order->license_agree);
/*/license_agree*/
$captcha_code = $this->request->post('captcha_code', 'string');
И
/*Валидация данных клиента*/
if(!$this->validate->is_name($order->name, true)) {
$this->design->assign('error', 'empty_name');
} elseif(!$this->validate->is_email($order->email, true)) {
$this->design->assign('error', 'empty_email');
} elseif(!$this->validate->is_phone($order->phone)) {
$this->design->assign('error', 'empty_phone');
} elseif(!$this->validate->is_address($order->address)) {
$this->design->assign('error', 'empty_address');
} elseif(!$this->validate->is_comment($order->comment)) {
$this->design->assign('error', 'empty_comment');
} elseif($this->settings->captcha_cart && (($_SESSION['captcha_cart'] != $captcha_code || empty($captcha_code)) || empty($_SESSION['captcha_cart']))) {
$this->design->assign('error', 'captcha');
/*license_agree*/
} elseif($order->license_agree!=1) {
$this->design->assign('error', 'empty_license_agree');
/*/license_agree*/
} else {
После чего проверяем работоспособность галочки в корзине
4. Галочка в форме регистрации
В design/okay_shop/html/register.tpl (примечание: если у вас стоит нестандартная тема, то открываете файлы темы в папке design и смотрите, файл tpl, в котором находится верстка данной формы)
В этих файлах вставьте код в блоки кода предоставленные ниже. Необходимо добавить код, который выделен комментариями {*license_agree*} …{*/license_agree*} или /*license_agree*/…/*/license_agree*/
В design/okay_shop/html/register.tpl
{* Form error messages *}
{if $error}
<div class="message_error">
{if $error == 'empty_name'}
<span data-language="form_enter_name">{$lang->form_enter_name}</span>
{elseif $error == 'empty_email'}
<span data-language="form_enter_email">{$lang->form_enter_email}</span>
{elseif $error == 'empty_password'}
<span data-language="form_enter_password">{$lang->form_enter_password}</span>
{elseif $error == 'user_exists'}
<span data-language="register_user_registered">{$lang->register_user_registered}</span>
{elseif $error == 'captcha'}
<span data-language="form_error_captcha">{$lang->form_error_captcha}</span>
{*license_agree*}
{elseif $error == 'empty_license_agree'}
<span data-language="form_error_license_agree">{$lang->form_error_license_agree}</span>
{*license_agree*}
{else}
{$error}
{/if}
</div>
{/if}
И
{* User's password *}
<div class="form_group">
<input class="form_input" type="password" name="password" value="" data-language="form_enter_password" placeholder="{$lang->form_enter_password}*"/>
</div>
{*license_agree*}
{* User's license-agree *}
<div class="form_group">
<input type="checkbox" id="license_agree" name="license_agree" onclick="this.value='1';this.checked = true" value="" autocomplete="off"/>
{$lang->license_agree}
</div>
{*license_agree*}
В api/Users.php
// Выбираем пользователей
$query = $this->db->placehold("SELECT
u.id,
u.email,
u.password,
u.name,
u.phone,
u.address,
u.group_id,
u.last_ip,
u.created,
/*license_agree*/
u.license_agree,
/*license_agree*/
g.discount,
g.name as group_name
И
// Выбираем пользователя
$query = $this->db->placehold("SELECT
u.id,
u.email,
u.password,
u.name,
u.phone,
u.address,
u.group_id,
u.last_ip,
u.created,
/*license_agree*/
u.license_agree,
/*license_agree*/
g.discount,
g.name as group_name
FROM s_users u
LEFT JOIN s_groups g ON u.group_id=g.id
WHERE
В view/RegisterView.php
/*Прием данных для регистрации*/
if($this->request->method('post') && $this->request->post('register')) {
$user = new stdClass();
$user->last_ip = $_SERVER['REMOTE_ADDR'];
$user->name = $this->request->post('name');
$user->email = $this->request->post('email');
$user->phone = $this->request->post('phone');
$user->address = $this->request->post('address');
$user->password = $this->request->post('password');
$captcha_code = $this->request->post('captcha_code');
/*license_agree*/
$user->license_agree = $this->request->post('license_agree');
/*/license_agree*/
$this->design->assign('name', $user->name);
$this->design->assign('email', $user->email);
$this->design->assign('phone', $user->phone);
$this->design->assign('address', $user->address);
/*license_agree*/
$this->design->assign('license_agree', $user->license_agree);
/*/license_agree*/
И
/*Валидация данных клиента*/
if($user_exists) {
$this->design->assign('error', 'user_exists');
} elseif(!$this->validate->is_name($user->name, true)) {
$this->design->assign('error', 'empty_name');
} elseif(!$this->validate->is_email($user->email, true)) {
$this->design->assign('error', 'empty_email');
} elseif(!$this->validate->is_phone($user->phone)) {
$this->design->assign('error', 'empty_phone');
} elseif(!$this->validate->is_address($user->address)) {
$this->design->assign('error', 'empty_address');
} elseif(empty($user->password)) {
$this->design->assign('error', 'empty_password');
} elseif($this->settings->captcha_register && (($_SESSION['captcha_register'] != $captcha_code || empty($captcha_code)) || empty($_SESSION['captcha_register']))) {
$this->design->assign('error', 'captcha');
} elseif($user_id = $this->users->add_user($user)) {
$_SESSION['user_id'] = $user_id;
header('Location: '.$this->config->root_url.'/'.$this->lang_link.'user');
/*license_agree*/
} elseif($user->license_agree!=1) {
$this->design->assign('error', 'empty_license_agree');
/*/license_agree*/
} else {
$this->design->assign('error', 'unknown error');
}
После чего проверяем работоспособность галочки в форме регистрации.
5. Галочка в форме обратного звонка.
В design/okay_shop/html/callback.tpl (примечание: если у вас стоит нестандартная тема, то открываете файлы темы в папке design и смотрите, файл tpl, в котором находится верстка данной формы)
В этих файлах вставьте код в блоки кода предоставленные ниже. Необходимо добавить код, который выделен комментариями {*license_agree*} …{*/license_agree*} или /*license_agree*/…/*/license_agree*
В design/okay_shop/html/callback.tpl
{if $call_error}
<div class="message_error">
{if $call_error=='captcha'}
<span data-language="form_error_captcha">{$lang->form_error_captcha}</span>
{elseif $call_error=='empty_name'}
<span data-language="form_enter_name">{$lang->form_enter_name}</span>
{elseif $call_error=='empty_phone'}
<span data-language="form_enter_phone">{$lang->form_enter_phone}</span>
{elseif $call_error=='empty_comment'}
<span data-language="form_enter_comment">{$lang->form_enter_comment}</span>
{*license_agree*}
{elseif $call_error == 'empty_license_agree'}
<span data-language="form_enter_license_agree">{$lang->form_error_license_agree}</span>
{*license_agree*}
{else}
<span>{$call_error}</span>
{/if}
</div>
И
{* User's message *}
<div class="form_group">
<textarea class="form_textarea" rows="3" name="message" data-language="form_enter_message" placeholder="{$lang->form_enter_message}">{$callmessage|escape}</textarea>
</div>
{*license_agree*}
{* User's license-agree *}
<div class="form_group">
<input type="checkbox" id="license_agree" name="license_agree" onclick="this.value='1';this.checked = true" value="{if $call_license_agree}{$call_license_agree|escape}{/if}" autocomplete="off"/>
{$lang->license_agree}
</div>
{*/license_agree*}
В api/Callbacks.php
/*Выбираем конкретную заявку на обратный звонок*/
public function get_callback($id) {
$query = $this->db->placehold("SELECT
c.id,
c.name,
c.phone,
c.message,
c.date,
c.processed,
c.url,
c.admin_notes,
/*license_agree*/
c.license_agree
/*license_agree*/
FROM s_callbacks c
WHERE id=?
LIMIT 1
", intval($id));
И
/*Выбираем заявки на обратный звонок*/
public function get_callbacks($filter = array()) {
// По умолчанию
$limit = 1000;
$page = 1;
$processed = '';
if(isset($filter['limit'])) {
$limit = max(1, intval($filter['limit']));
}
if(isset($filter['page'])) {
$page = max(1, intval($filter['page']));
}
if(isset($filter['processed'])) {
$processed = $this->db->placehold('AND c.processed=?',$filter['processed']);
}
$sql_limit = $this->db->placehold(' LIMIT ?, ? ', ($page-1)*$limit, $limit);
$query = $this->db->placehold("SELECT
c.id,
c.name,
c.phone,
c.date,
c.message,
c.processed,
c.url,
c.admin_notes,
/*license_agree*/
c.license_agree
/*license_agree*/
FROM s_callbacks c
В view/IndexView.php
public function fetch() {
/*Принимаем данные с формы заказа обратного звонка*/
if($this->request->method('post') && $this->request->post('callback')) {
$callback = new stdClass();
$callback->phone = $this->request->post('phone');
$callback->name = $this->request->post('name');
$callback->url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$callback->message = $this->request->post('message');
$captcha_code = $this->request->post('captcha_code', 'string');
/*license_agree*/
$callback->license_agree = $this->request->post('license_agree');
/*/license_agree*/
$this->design->assign('callname', $callback->name);
$this->design->assign('callphone', $callback->phone);
$this->design->assign('callmessage', $callback->message);
/*license_agree*/
/*$this->design->assign('call_license_agree', $callback->license_agree);*/
/*/license_agree*/
И
/*Валидация данных клиента*/
if (!$this->validate->is_name($callback->name, true)) {
$this->design->assign('call_error', 'empty_name');
} elseif(!$this->validate->is_phone($callback->phone, true)) {
$this->design->assign('call_error', 'empty_phone');
} elseif(!$this->validate->is_comment($callback->message)) {
$this->design->assign('call_error', 'empty_comment');
} elseif($this->settings->captcha_callback && (($_SESSION['captcha_callback'] != $captcha_code || empty($captcha_code)) || empty($_SESSION['captcha_callback']))) {
$this->design->assign('call_error', 'captcha');
} elseif($callback_id = $this->callbacks->add_callback($callback)) {
$this->design->assign('call_sent', true);
// Отправляем email
$this->callbacks->email_callback_admin($callback_id);
/*license_agree*/
} elseif($callback->license_agree!=1) {
$this->design->assign('call_error', 'empty_license_agree');
/*/license_agree*/
} else {
$this->design->assign('call_error', 'unknown error');
}
После чего проверяем работоспособность галочки в форме обратного звонка
6. Галочка в форме комментария к товару
В design/okay_shop/html/product.tpl (примечание: если у вас стоит нестандартная тема, то открываете файлы темы в папке design и смотрите, файл tpl, в котором находится верстка данной формы)
В этих файлах вставьте код в блоки кода предоставленные ниже. Необходимо добавить код, который выделен комментариями {*license_agree*} …{*/license_agree*} или /*license_agree*/…/*/license_agree
В design/okay_shop/html/product.tpl
{* Form error messages *}
{if $error}
<div class="message_error">
{if $error=='captcha'}
<span data-language="form_error_captcha">{$lang->form_error_captcha}</span>
{elseif $error=='empty_name'}
<span data-language="form_enter_name">{$lang->form_enter_name}</span>
{elseif $error=='empty_comment'}
<span data-language="form_enter_comment">{$lang->form_enter_comment}</span>
{elseif $error=='empty_email'}
<span data-language="form_enter_email">{$lang->form_enter_email}</span>
{*license_agree*}
{elseif $error == 'empty_license_agree'}
<span data-language="form_enter_license_agree">{$lang->form_error_license_agree}</span>
{*/license_agree*}
{/if}
</div>
{/if}
И
{* User's comment *}
<div class="form_group">
<textarea class="form_textarea" rows="3" name="text" placeholder="{$lang->form_enter_comment}*">{$comment_text}</textarea>
</div>
{*license_agree*}
{* User's license-agree *}
<div class="form_group">
<input type="checkbox" id="license_agree" name="license_agree" onclick="this.value='1';this.checked = true" value="" autocomplete="off"/>
{$lang->license_agree}
</div>
{*/license_agree*}
В api/Comments.php
/*Выбираем конкретный комментарий*/
public function get_comment($id) {
if (empty($id)) {
return false;
}
$comment_id_filter = $this->db->placehold('AND c.id=?', intval($id));
$query = $this->db->placehold("SELECT
c.id,
c.parent_id,
c.object_id,
c.name,
c.email,
c.ip,
c.type,
c.text,
c.date,
c.approved,
/*license_agree*/
c.license_agree,
/*license_agree*/
c.lang_id
FROM s_comments c
WHERE
1
$comment_id_filter
LIMIT 1
И
$sort='DESC';
$query = $this->db->placehold("SELECT
c.id,
c.parent_id,
c.object_id,
c.ip,
c.name,
c.email,
c.text,
c.type,
c.date,
c.approved,
/*license_agree*/
c.license_agree,
/*license_agree*/
c.lang_id
FROM s_comments c
WHERE
В view/ProductView.php
// Принимаем комментарий
if ($this->request->method('post') && $this->request->post('comment')) {
$comment = new stdClass;
$comment->name = $this->request->post('name');
$comment->email = $this->request->post('email');
$comment->text = $this->request->post('text');
$captcha_code = $this->request->post('captcha_code', 'string');
/*license_agree*/
$comment->license_agree = $this->request->post('license_agree');
/*/license_agree*/
// Передадим комментарий обратно в шаблон - при ошибке нужно будет заполнить форму
$this->design->assign('comment_text', $comment->text);
$this->design->assign('comment_name', $comment->name);
$this->design->assign('comment_email', $comment->email);
/*license_agree*/
$this->design->assign('comment_email', $comment->license_agree);
/*/license_agree*/
И
// Проверяем капчу и заполнение формы
if ($this->settings->captcha_product && ($_SESSION['captcha_product'] != $captcha_code || empty($captcha_code))) {
$this->design->assign('error', 'captcha');
} elseif (!$this->validate->is_name($comment->name, true)) {
$this->design->assign('error', 'empty_name');
} elseif (!$this->validate->is_comment($comment->text, true)) {
$this->design->assign('error', 'empty_comment');
} elseif (!$this->validate->is_email($comment->email)) {
$this->design->assign('error', 'empty_email');
/*license_agree*/
} elseif($comment->license_agree!=1) {
$this->design->assign('error', 'empty_license_agree');
/*/license_agree*/
} else {
После чего проверяем работоспособность галочки в форме комментария в товаре.
7. Галочка в форме подписки
В design/okay_shop/html/index.tpl (примечание: если у вас стоит нестандартная тема, то открываете файлы темы в папке design и смотрите, файл tpl, в котором находится верстка данной формы)
В этих файлах вставьте код в блоки кода предоставленные ниже. Необходимо добавить код, который выделен комментариями {*license_agree*} …{*/license_agree*} или /*license_agree*/…/*/license_agree
В design/okay_shop/html/index.tpl
{* Subscribing *}
<div id="subscribe_container">
<div class="h3">
<span data-language="subscribe_heading">{$lang->subscribe_heading}</span>
</div>
<form style="border: none" class="subscribe_form fn_validate_subscribe" method="post">
<input type="hidden" name="subscribe" value="1"/>
<input class="subscribe_input" type="email" name="subscribe_email" value="" data-format="email" placeholder="{$lang->form_email}"/>
<button class="subscribe_button" type="submit"><span data-language="subscribe_button">{$lang->subscribe_button}</span></button>
{*license_agree*}
<div class="subscribe_promotext">
<input type="checkbox" id="license_agree" name="license_agree" onclick="this.value='1';this.checked = true" value="" autocomplete="off"/>
{$lang->license_agree}
</div>
{*/license_agree*}
{if $subscribe_error}
<div id="subscribe_error" class="popup">
{if $subscribe_error == 'email_exist'}
<span data-language="subscribe_already">{$lang->index_subscribe_already}</span>
{/if}
{if $subscribe_error == 'empty_email'}
<span data-language="form_enter_email">{$lang->form_enter_email}</span>
{/if}
{*license_agree*}
{if $subscribe_error == 'empty_license_agree'}
<span data-language="form_error_license_agree">{$lang->form_error_license_agree}</span>
{/if}
{*/license_agree*}
</div>
{/if}
В api/Subscribes.php
$query = $this->db->placehold("SELECT
s.id,
s.email,
/*license_agree*/
s.license_agree
/*/license_agree*/
FROM s_subscribe_mailing s
WHERE
В view/IndexView.php
/*E-mail подписка*/
if ($this->request->post('subscribe')) {
/*license_agree*/
$subscribe = new stdClass;
$license_agree = $this->request->post('license_agree');
/*/license_agree*/
$email = $this->request->post('subscribe_email');
$this->db->query("select count(id) as cnt from s_subscribe_mailing where email=?", $email);
$cnt = $this->db->result('cnt');
if (!$this->validate->is_email($email, true)) {
$this->design->assign('subscribe_error', 'empty_email');
/*license_agree*/
} elseif($license_agree!=1) {
$this->design->assign('subscribe_error', 'empty_license_agree');
/*/license_agree*/
} elseif ($cnt > 0) {
$this->design->assign('subscribe_error', 'email_exist');
} else {
/*$this->db->query("insert into s_subscribe_mailing set email=?", $email);*/
/*license_agree*/ $this->db->query("INSERT INTO `ok_subscribe_mailing` (`email`, `license_agree`)VALUES ('$email' , '$license_agree')"); /*/license_agree*/
$this->design->assign('subscribe_success', '1');
}
}
Так-же необходимо сделать небольшие изменения в файле
design/okay_shop/css/style.css
.subscribe_form { position: relative; width: 315px; max-width: 100%; /*border: 1px solid #ccc;*/ border-radius: 2px; font-weight: bold; font-size: 12px; } .subscribe_input { width: 100%; height: 32px; padding: 0 125px 0 10px; background-color: #fff; /*border: none;*/ color: #827f7f; border: 1px solid #ccc; }
После чего проверяем работоспособность галочки в форме подписки.
После всех проделанный операций, в вашем магазине перед тем, как пользователь совершит покупку, он обязательно примет соглашение, и доказательством этого будет служить значение полей license_agree в БД которое будет равным 1.
Написать комментарий
можно сделать по аналогии с комментариями?