Magento自定义重定向路由自定义联系人表单模块

问题描述:

我们已经建立了一个自定义的Magento模块,用于联系我们的网上商店查询。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('[email protected]'); 
     $mail->setSubject('Contact aanvraag'); 
     try { 
      $mail->send(); 
     } 
     catch(Exception $ex) { 
      Mage::getSingleton('core/session')->addError('Unable to send email.'); 
     } 

     $this->_redirect('contact/bedankt'); 
    } 
} 
?> 

选项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> 

为了得到你的价值控制器,你做

法师:: getStoreConfig('contactinquiry/GEN eral_option/REDIRECT_URL”,法师::应用程序() - > getStore() - >的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

您也可以在每个包含url的表单中添加一个隐藏字段,以重定向到

+0

是的,感谢您的快速解决方案。我们更喜欢从后端管理路径的选项,也许其他人可以帮助我进一步。 – Michael

+0

您也可以在自定义模块中创建一个system.xml,并为redirecting_url字段添加一个字段并为每个商店范围设置url –

+0

这正是我们正在寻找的地方。不知道如何正确设置system.xml文件。 – Michael