Sendex - вызов в нескольких экземплярах
Добрый день.
Никто не заморачивался с тем, чтобы вызывать Sendex в нескольких экземплярах на одной странице?
Хочу сделать три разных типа подписки (новости, скидки, и еще что-нибудь. ) Вызываю на странице соответственно
[[!Sendex? &id=`1` ]]
[[!Sendex? &id=`2` ]]
[[!Sendex? &id=`3` ]]
На странице появляются все три подписки с предложением добавить email и подписаться на соответствующий раздел. Но: куда ни добавляй email, подписываешься только в первый. Судя по всему при отправке не фиксируется на какую подписку все это должно уходить.
В принципе и в чанке подписки нет такого:
Никто не заморачивался с тем, чтобы вызывать Sendex в нескольких экземплярах на одной странице?
Хочу сделать три разных типа подписки (новости, скидки, и еще что-нибудь. ) Вызываю на странице соответственно
[[!Sendex? &id=`1` ]]
[[!Sendex? &id=`2` ]]
[[!Sendex? &id=`3` ]]
На странице появляются все три подписки с предложением добавить email и подписаться на соответствующий раздел. Но: куда ни добавляй email, подписываешься только в первый. Судя по всему при отправке не фиксируется на какую подписку все это должно уходить.
В принципе и в чанке подписки нет такого:
<form action="" method="post" class="form-subscribe">
<p>
[[%sendex_subscribe_intro?name=`[[+name]]`]]
<small>[[+description]]</small>
</p>
<input type="textfield" name="email" value="" placeholder="Email">
<input type="hidden" name="sx_action" value="subscribe">
<button type="submit">[[%sendex_btn_subscribe]]</button>
[[+message]]
</form>
Мне кажется в чанке подписки в hidden поде должно передаваться ID подписки? Комментарии: 1
Скопируй снипет Sendex и назови его Sendex2
Содержимое тоже необходимо поправить:
Содержимое тоже необходимо поправить:
<?php
/** @var array $scriptProperties */
/** @var Sendex $Sendex */
$Sendex = $modx->getService('sendex','Sendex',$modx->getOption('sendex_core_path',null,$modx->getOption('core_path').'components/sendex/').'model/sendex/',$scriptProperties);
if (!($Sendex instanceof Sendex)) return '';
if (empty($tplSubscribeAuth)) {$tplSubscribeAuth = 'tpl.Sendex.subscribe.auth';}
if (empty($tplSubscribeGuest)) {$tplSubscribeGuest = 'tpl.Sendex.subscribe.guest';}
if (empty($tplUnsubscribe)) {$tplUnsubscribe = 'tpl.Sendex.unsubscribe';}
if (empty($tplActivate)) {$tplActivate = 'tpl.Sendex.activate';}
if (empty($linkTTL)) {$linkTTL = 1800;}
if (empty($id) || !$newsletter = $modx->getObject('sxNewsletter', $id)) {
return $modx->lexicon('sendex_newsletter_err_ns');
}
/** @var sxNewsletter $newsletter */
if (!$newsletter->active && empty($showInactive)) {
return $modx->lexicon('sendex_newsletter_err_disabled');
}
$placeholders = $newsletter->toArray();
$placeholders['message'] = '';
$placeholders['error'] = 0;
if ($modx->user->isAuthenticated($modx->context->key)) {
$placeholders = array_merge(
$modx->user->toArray(),
$modx->user->Profile->toArray(),
$placeholders
);
}
$isAuthenticated = $modx->user->isAuthenticated($modx->context->key);
if (!empty($_REQUEST['sx_action2'])) {
$isAjax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
$params = $_GET;
unset($params[$modx->getOption('request_param_alias')]);
unset($params[$modx->getOption('request_param_id')]);
switch ($_REQUEST['sx_action2']) {
case 'subscribe':
if ($isAuthenticated && $modx->user->id) {
if (!$response = $newsletter->Subscribe($modx->user->id)) {
$placeholders['message'] = $modx->lexicon('sendex_subscribe_err_email_wrong');
$placeholders['error'] = 1;
}
}
elseif (!empty($_REQUEST['email'])) {
$email = htmlentities(strip_tags(urldecode($_REQUEST['email'])));
$response = $newsletter->checkEmail($email, $modx->user->id, $linkTTL);
if ($response === true) {
$placeholders['message'] = $modx->lexicon('sendex_subscribe_err_already');
}
elseif ($response === false) {
$placeholders['message'] = $modx->lexicon('sendex_subscribe_err_email_wrong');
$placeholders['error'] = 1;
}
else {
$params['hash'] = $response;
$params['sx_action2'] = 'confirm';
$placeholders['link'] = $modx->makeUrl($modx->resource->id, $modx->context->key, $params, 'full');
$placeholders['email_body'] = $modx->getChunk($tplActivate, $placeholders);
$response = $Sendex->sendEmail($email, $placeholders);
if ($response !== true) {
$placeholders['message'] = $modx->lexicon('sendex_subscribe_err_email_send');
$placeholders['error'] = 1;
} else {
$params['sx_subscribed'] = 1;
}
}
}
else {
$placeholders['message'] = $modx->lexicon('sendex_subscribe_err_email_ns');
$placeholders['error'] = 1;
}
unset($params['email'], $params['hash']);
break;
case 'confirm':
if (!empty($_REQUEST['hash'])) {
$response = $newsletter->confirmEmail($_REQUEST['hash']);
$params['sx_confirmed'] = 1;
unset($params['hash']);
}
break;
case 'unsubscribe':
if (!empty($_REQUEST['code'])) {
$response = $newsletter->unSubscribe($_REQUEST['code']);
$params['sx_unsubscribed'] = 1;
}
unset($params['code']);
break;
}
unset($params['sx_action2']);
if (!$isAjax && empty($placeholders['message'])) {
$modx->sendRedirect($modx->makeUrl($modx->resource->id, $modx->context->key, $params, 'full'));
}
}
if ($isAuthenticated && $id = $newsletter->isSubscribed($modx->user->id)) {
if ($subscriber = $modx->getObject('sxSubscriber', $id)) {
$placeholders = array_merge($subscriber->toArray(), $placeholders);
}
$output = $modx->getChunk($tplUnsubscribe, $placeholders);
}
else {
$output = $isAuthenticated
? $modx->getChunk($tplSubscribeAuth, $placeholders)
: $modx->getChunk($tplSubscribeGuest, $placeholders);
}
if (!empty($isAjax)) {
@session_write_close();
exit($output);
}
else {
return $output;
}
Таким образом я реализовал у себя 2 подписки на одной странице.
Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.