Я хотел бы создать прямую страницу отказа от подписки в magento, я нашел эту инструкцию для выполнения, но шаги 1 и 2 не ясны, так как я не профессионал. Может кто-нибудь, пожалуйста, помогите мне прояснить эти два шага. Где создать страницу "unsubscribe.phtml"? Как добавить в него только что созданный блок? Заранее благодарим вас.
1. Создайте phtml-страницу, скажем, «unsubscribe.phtml», содержащую код для создания формы отказа от подписки.
<?php $newsletterObj = new Mage_Newsletter_Block_Subscribe(); ?>
<div class="newsletter-unsubscribe">
<div class="newsletter-unsubscribe-title"><?php echo $this->__('Submit your email id to unsubscribe newsletter') ?></div>
<form action="<?php echo $newsletterObj->getUnsubscribeFormActionUrl() ?>” method="post" id="newsletter-validate-detail">
<div class="block-content">
<div class="input-box">
<input type="text" name="email" id="newsletter" title="<?php echo $this->__('Sign up for our newsletter') ?>” class="input-text required-entry validate-email” value="<?php echo $this->__('Enter Your Email Here') ?>” onfocus="if(this.value==’<?php echo $this->__('Enter Your Email Here') ?>’)this.value=’’;” onblur="if(this.value==’’)this.value=’<?php echo $this->__('Enter Your Email Here') ?>’;”
/>
</div>
<div class="actions">
<button type="submit" title="<?php echo $this->__('Submit') ?>” class="button"><span><span><?php echo $this->__('Submit') ?></span></span></button>
</div>
</div>
</form>
<script type="text/javascript\">
//<![CDATA[
var newsletterSubscriberFormDetail = new VarienForm(’newsletter-validate-detail’);
//]]>
</script>
</div>
2) Создайте страницу CMS. Добавьте в него только что созданный блок. Чтобы ваша страница CMS содержала эту форму.
3) Теперь в page \ app \ design \ frontend \ base \ default \ template \ newsletter \ subscribe.phtml добавьте код для добавления ссылки на страницу cms.
<div class="unsubscribe">
<a href="<?php echo Mage::getUrl('unsubscribe-newsletter') ?>"><?php echo $this->__('Unsubscribe') ?></a>
</div>
4) На странице \ app \ code \ core \ Mage \ Newsletter \ Block \ Subscribe.php добавьте функцию для создания URL-адреса действия формы, который вызывается в «unsubscribe.phtml».
public function getUnsubscribeFormActionUrl()
{
return $this->getUrl(’newsletter/subscriber/unsubscribecus’, array(’_secure’ => true));
}
5) Теперь на странице \ app \ code \ core \ Mage \ Newsletter \ controllers \ SubscriberController.php добавлено новое действие для процесса отказа от подписки.
/ ** * Отказаться от подписки на новостную рассылку от внешнего интерфейса * /
public function unsubscribecusAction()
{
$email = $this->getRequest()->getParam(’email’);
$subsModel = Mage::getModel(’newsletter/subscriber’);
$subscriber = $subsModel->loadByEmail($email);
$id = (int) $subsModel->getId();
$code = (string) $subsModel->getCode();
if ($id && $code) {
$session = Mage::getSingleton(’core/session’);
try {
Mage::getModel(’newsletter/subscriber’)->load($id)
->setCheckCode($code)
->unsubscribe();
$session->addSuccess($this->__(’You have been unsubscribed.’));
}
catch (Mage_Core_Exception $e) {
$session->addException($e, $e->getMessage());
}
catch (Exception $e) {
$session->addException($e, $this->__(’There was a problem with the un-subscription.’));
}
}
$this->_redirectReferer();
}