2013-11-22 62 views
0

我想在magento中创建一个直接取消订阅页面,我发现这个指令要遵循,但步骤1和2不清楚因为我不是专业人士。 有人可以帮我澄清这两个步骤。在哪里创建“unsubscribe.phtml”页面?如何添加刚创建的块呢? 预先感谢您。
1.创建一个phtml页面,声明“unsubscribe.phtml”,其中包含创建取消订阅表单的代码。如何在magento中创建取消订阅页面

<?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)在页面\应用\代码\核心\法师\通讯\块\ Subscribe.php添加函数来创建表格操作URL被称为在“unsubscribe.phtml”。

public function getUnsubscribeFormActionUrl() 
{ 
return $this->getUrl(’newsletter/subscriber/unsubscribecus’, array(’_secure’ => true)); 
} 

5)现在,在\程序\代码\核心\法师\新闻\控制器\ 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

/** * 取消订阅由于不能发表评论,并为解决尚未没有标记这个问题,我会认为你还需要一个回答。

我会建议放置unsubscribe.phtml文件中/template/newsletter/

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

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

所以页面将包含您的形式。

如果你已经知道如何做到这一点,请在你的问题上进一步回答。

0

在订阅按钮旁边添加一个取消订阅按钮(或者允许块调用中的变量设置为yes/no显示)是否是一个想法 - 通过这种方式,您可以同时捕获