我们已经在我们的网上商店建立了一个自定义Magento模块,用于联系人查询。
请参阅下面的IndexController。我们想要更改每个商店视图的重定向路由。我们如何才能实现这一目标?
<?php
class MVE_ContactInquiry_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$block = $this->getLayout()->createBlock(
'Mage_Core_Block_Template',
'mve.contact_inquiry',
array(
'template' => 'mve/contact_inquiry.phtml'
)
);
$this->getLayout()->getBlock('content')->append($block);
//$this->getLayout()->getBlock('right')->insert($block, 'catalog.compare.sidebar', true);
$this->_initLayoutMessages('core/session');
$this->renderLayout();
}
public function sendemailAction()
{
$params = $this->getRequest()->getParams();
$mail = new Zend_Mail();
$bodytext = '
Naam: ' . $params['name'] . '
E-mailadres: ' . $params['email'] . '
Telefoonnummer: ' . $params['telephone'] . '
Bericht:
' . $params['comment'];
$mail->setBodyText( $bodytext );
$mail->setFrom($params['email'], $params['name']);
$mail->addTo('example@gmail.com');
$mail->setSubject('Contact aanvraag');
try {
$mail->send();
}
catch(Exception $ex) {
Mage::getSingleton('core/session')->addError('Unable to send email.');
}
$this->_redirect('contact/bedankt');
}
}
?>
答案 0 :(得分:1)
选项1
在/app/code/local/MVE/ContactInquiry/etc/system.xml
假设您想在左侧导航栏中创建自己的标签
<?xml version="1.0"?>
<config>
<tabs>
<mve_tab translate="label" module="contactinquiry">
<label>MVE</label>
<sort_order>900</sort_order>
</mve_tab>
</tabs>
<sections>
<contactinquiry translate="label" module="contactinquiry">
<label>Admin Order Confirmation</label>
<tab>mve_tab</tab>
<sort_order>1001</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<general_option translate="label">
<label>General Options</label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<redirect_url translate="label">
<label>URL </label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</redirect_url>
</fields>
</general_option>
</groups>>
</contactinquiry>
</sections>
</config>
要获得控制器中的值,请执行
Mage :: getStoreConfig('contactinquiry / general_option / redirect_url',Mage :: app() - &gt; getStore() - &gt; getId())
请参阅XML for Admin Configurations获取更多帮助
选项2
if(Mage::app()->getStore()->getStoreId() == 1){
$this->_redirect('contact/...');
}
else if(Mage::app()->getStore()->getStoreId() == ...){
$this->_redirect('contact/..');
}
else{
$this->_redirect('contact/bedankt');
}
选项3
您还可以在每个表单中添加一个隐藏字段,其中包含要重定向到
的网址