覆盖联系人控制器

时间:2017-09-07 07:39:14

标签: php magento

我正在尝试覆盖联系人控制器,但请求不要进入我的模块postAction。 的 1-config.xml中

 <?xml version="1.0"?> <config>    <frontend>
         <routers>
            <contacts>
                 <args>
                     <modules>
                         <Xyz_Contacts before="Mage_Contacts">Xyz_Contacts</Xyz_Contacts>
                    </modules>
                 </args>
            </contacts>
         </routers>
     </frontend> </config>

2控制器

<?php
require_once(Mage::getModuleDir('controllers','Mage_Contacts').DS.'IndexController.php');

    class Xyz_Contacts_IndexController extends Mage_Contacts_IndexController
    {
     public function postAction()
        {
            die('coming');
            $post = $this->getRequest()->getPost();
            if ( $post ) {
                $translate = Mage::getSingleton('core/translate');
                /* @var $translate Mage_Core_Model_Translate */
                $translate->setTranslateInline(false);
                try {
                    $postObject = new Varien_Object();
                    $postObject->setData($post);

                    $error = false;                

                    if (!Zend_Validate::is(trim($post['name']) , 'NotEmpty')) {
                        $error = true;
                    }

                    if (!Zend_Validate::is(trim($post['comment']) , 'NotEmpty')) {
                        $error = true;
                    }

                    if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
                        $error = true;
                    }


                    if ($error) {
                        throw new Exception();
                    }
                    $mailTemplate = Mage::getModel('core/email_template');
                    /* @var $mailTemplate Mage_Core_Model_Email_Template */
                    $mailTemplate->setDesignConfig(array('area' => 'frontend'))
                        ->setReplyTo($post['email'])
                        ->sendTransactional(
                            Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
                            Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
                            //Mage::getStoreConfig('trans_email/ident_custom2/email'),
                            Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
                            null,
                            array('data' => $postObject)
                        );


                    if (!$mailTemplate->getSentSuccess()) {
                        throw new Exception();
                    }


                    $translate->setTranslateInline(true);

                    Mage::getSingleton('customer/session')->addSuccess(Mage::helper('contacts')->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.'));
                    $this->_redirect('*/*/');

                    return;
                } catch (Exception $e) {
                    $translate->setTranslateInline(true);



                    Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please, try again later'));
                    $this->_redirect('*/*/');
                    return;
                }

            } else {
                $this->_redirect('*/*/');
            }
        }

    }

3-模块文件。

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Xyz_Contacts>
            <active>true</active>
            <codePool>local</codePool>
        </Xyz_Contacts>
    </modules>
</config>

我如何检查我的模块是否覆盖了核心联系人控制器方法。我只想检查发布请求是否来自我的控制器,以便我可以进一步处理逻辑。

1 个答案:

答案 0 :(得分:0)

您缺少控制器类中的一个部分,您需要要覆盖要覆盖的原始控制器:

require_once 'Mage/Contacts/controllers/IndexController.php');

查看HERE分步指南