0

我想在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==’&lt;?php echo $this->__('Enter Your Email Here') ?>’)this.value=’’;” onblur="if(this.value==’’)this.value=’&lt;?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) 在页面 \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();
} 
4

2 回答 2

0

由于无法发表评论并且此问题尚未标记为已解决,因此我假设您仍然需要答案。

我建议将unsubscribe.phtml文件放在/template/newsletter/

对于第 2 步,您可以使用此代码

{{block type="core/template" template="newsletter/unsubscribe.phtml"}}

因此该页面将包含您的表单。

如果您已经知道如何做到这一点,请进一步发布您自己问题的答案。

于 2014-11-04T09:26:15.533 回答
0

在订阅按钮旁边添加一个取消订阅按钮(或允许在块调用中将其设置为是/否显示的变量)是一个想法 - 这样您就可以捕获两者

于 2014-11-06T15:58:04.960 回答