我想在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)现在在页面\ 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)在page \ app \ code \ core \ Mage \ Newsletter \ Block \ Subscribe.php中添加一个函数来创建在“unsubscribe.phtml”中调用的表单操作URL。
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();
}
答案 0 :(得分:0)
由于a不能发表评论且此问题尚未标记为已解决,我将假设您仍需要答案。
我建议将unsubscribe.phtml
文件放在/template/newsletter/
对于第2步,您可以使用此代码
{{block type="core/template" template="newsletter/unsubscribe.phtml"}}
因此页面将包含您的表单。
如果您已经知道如何执行此操作,请进一步回答您自己的问题。
答案 1 :(得分:0)
在订阅按钮旁边添加取消订阅按钮(或允许块调用中的变量将其设置为是/否显示)是不是一个想法 - 这样你就可以捕获它们