0

我正在寻找一个新的联系表来询问 Magento Eshop 的报价。

此“请求报价”表单将为访问者提供填写某些字段的选项,并像默认联系表单一样发送电子邮件。

与默认联系表单的唯一区别是访问者无需登录即可发送电子邮件。

所以到目前为止我的方法是将文件contacts/form.phtml复制contacts/askforanoffer.phtml

当然,我在文件夹layout/askforanoffer.xml中创建了新的xml

问题是这样的。 我应该在哪里更改代码,以便用户不必登录才能发送带有此请求报价表的电子邮件?

4

3 回答 3

2

您必须为此创建单独的模块。我还在这里创建和共享代码。表单提交是通过ajax。可能是我错过了要删除或重命名的内容。尝试纠正它。

app\etc\modules\namespace_modulename.xml

<Namespace_Modulename>
        <active>true</active>
        <codePool>local</codePool>
    </Namespace_Modulename>

app\code\local\Namespace\Modulename\Helper\Data.php

<?php class Namespace_Modulename_Helper_Data extends Mage_Core_Helper_Abstract
{

}
?>

app\code\local\Namespace\Modulename\etc\config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Namespace_Modulename>
            <version>0.0.01</version>
        </Namespace_Modulename>
    </modules>
    <frontend>

        <routers>
            <contacts>
                <args>
                    <modules>
                        <Namespace_Modulename before="Mage_Contacts">Namespace_Modulename</Namespace_Modulename>
                    </modules>
                </args>
            </contacts>
        </routers>

    </frontend>

    <global>
        <helpers>
            <Modulename>
                <class>Namespace_Modulename_Helper</class>
            </Modulename>
        </helpers>
        <template>
            <email>
                <havequestion_email_email_template translate="label" module="contacts">
                    <label>Have a Question Form</label>
                    <file>havequestion_form.html</file>
                    <type>text</type>
                </havequestion_email_email_template>
            </email>
        </template>
    </global>

</config>

app\code\local\Namespace\Modulename\controller\IndexController.php

 public function havequestionpostAction()
    {
        $template_path = 'havequestion_email_email_template';
        //$post = $this->getRequest()->getPost();
        $post = array (
                'name' => $this->getRequest()->getParam('name'), 
                'email' => $this->getRequest()->getParam('email'),
                'comment' => $this->getRequest()->getParam('comment')

                );

        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 (Zend_Validate::is(trim($post['hideit']), 'NotEmpty')) {
                    $error = true;                  
                }

                if ($error) {
                    throw new Exception();
                }

                $mailTemplate = Mage::getModel('core/email_template');

                /* @var $mailTemplate Mage_Core_Model_Email_Template */


                $senderDetail = Mage::getStoreConfig('trans_email/ident_'.Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER));
                $senderDetail['name'] = $post['name'];

                $mailTemplate->setDesignConfig(array('area' => 'frontend'))
                    ->setReplyTo($post['email'])
                    ->sendTransactional(
                        $template_path,
                        $senderDetail,
                        //Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
                        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->_redirectUrl($post['currentpage']);
                echo 'SUCCESS';

                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->_redirectUrl($post['currentpage']);
                echo '<div class="error-msg">Unable to submit your request. Please, try again later.</div>';                
                return;
            }

        } else {
            echo '<div class="error-msg">Unable to submit your request. Please, try again later.</div>';
            //$this->_redirectUrl($post['currentpage']);
            return;
        }
    }

}

app\design\frontend\default\YOUR_TEMPLATE_PATH\template\contacts\havequestionform.phtml

<div class="form-add">
<form action="<?php echo $this->getUrl('') ?>contacts/index/havequestionpost/" id="havequestionForm" method="post">
        <div class="question-ajax-msg"></div>
        <ul class="form-list">
            <li class="fields">
                <div class="field">
                    <label for="name" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Name') ?></label>
                    <div class="input-box">
                        <input name="name" id="name" title="<?php echo Mage::helper('contacts')->__('Name') ?>" value="<?php echo $this->htmlEscape($this->helper('contacts')->getUserName()) ?>" class="input-text required-entry" type="text" />
                    </div>
                </div>
                <div class="field">
                    <label for="email" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Email') ?></label>
                    <div class="input-box">
                        <input name="email" id="email" title="<?php echo Mage::helper('contacts')->__('Email') ?>" value="<?php echo $this->htmlEscape($this->helper('contacts')->getUserEmail()) ?>" class="input-text required-entry validate-email" type="text" />
                    </div>
                </div>
            </li>           
            <li class="wide">
                <label for="comment" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Comment') ?></label>
                <div class="input-box">
                    <textarea name="comment" id="comment" title="<?php echo Mage::helper('contacts')->__('Comment') ?>" class="required-entry input-text" cols="5" rows="3"></textarea>
                </div>
            </li>
        </ul>

    <div class="">
        <p class="required" style="text-align:left"><?php echo Mage::helper('contacts')->__('* Required Fields') ?></p>
                    <button type="submit" title="<?php echo Mage::helper('contacts')->__('Submit') ?>" class="button"><span><span><?php echo Mage::helper('contacts')->__('Submit') ?></span></span></button>
        <span class="question-ajax-loading">&nbsp;</span>
    </div>
</form>
<script type="text/javascript">
//<![CDATA[
    var havequestionForm = new VarienForm('havequestionForm', true);

    // submit have a question by ajax
        jQuery('#havequestionForm').submit(function (e){
            e.preventDefault();
            jQuery(".question-ajax-loading").css('display','block');

            var name = jQuery("#name").val();
            var email = jQuery("#email").val();
            var comment = jQuery("#comment").val();
            var hideit = jQuery("#hideit").val();
            var prosku = jQuery("#prosku").val();
            var prostyle = jQuery("#prostyle").val();
            var procolor = jQuery("#procolor").val();
            var currentpage = jQuery("#currentpage").val();

            var dataString = 'name='+ name + '&email=' + email + '&comment=' + comment + '&hideit=' + hideit + '&prosku=' + prosku + '&prostyle=' + prostyle + '&procolor=' + procolor + '&currentpage=' + currentpage;

            url = jQuery('#havequestionForm').attr('action');

            jQuery.ajax( {
                url : url,
                Type : "POST",
                data: dataString, 
                success: function(data) {
                    jQuery(".question-ajax-msg").css('display','block');

                    if(data == 'SUCCESS'){
                        var successMsg = '<div class="success-msg">Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.</div>';
                        jQuery(".question-ajax-msg").html(successMsg);                      
                        jQuery("#comment").val('');
                    }                   
                    else {                      
                        jQuery(".question-ajax-msg").html(data);
                        jQuery("#comment").val('');
                    }

                    jQuery(".question-ajax-loading").css('display','none');
                    jQuery('.question-ajax-msg').delay(5000).fadeOut('slow');


                }

            });

            return false;
        });
//]]>
</script>
</div>
于 2013-09-19T09:23:46.903 回答
1

您可以创建自定义联系表格,

参考:http: //inhoo.net/ecommerce/magento/magento-email/magento-custom-email-contact-form-with-notification-system/

于 2013-09-19T09:14:08.777 回答
1

您可以使用以下文档

具有自定义数据库表的自定义模块

http://www.magentocommerce.com/wiki/5__-_modules_and_development/0__-_module_development_in_magento/custom_module_with_custom_database_table

Magento Commerce 的前端编辑器扩展

http://www.youtube.com/watch?v=ALgdsMCVuH4

请看上面的网址。

希望这对你有帮助,

于 2013-09-19T09:17:45.457 回答