Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature: added auto reply to contact form #3615

Merged
merged 27 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8f7c01c
Add email template
kyrena Oct 27, 2023
4e543d7
Add configuration
kyrena Oct 27, 2023
86bce4d
Add email declaration
kyrena Oct 27, 2023
eada26d
Send an email confirmation to the customer
kyrena Oct 27, 2023
dc5159a
Remove next change
kyrena Oct 27, 2023
260377a
Update translations
kyrena Oct 27, 2023
56b5a60
Cancel text change
kyrena Oct 27, 2023
a05bc18
Same text everywhere
kyrena Oct 27, 2023
236230f
Fix translation
kyrena Oct 27, 2023
b47138b
Merge branch 'main' into customer-contact-confirm
fballiano Feb 13, 2024
a33eed4
Reworked the whole PR
fballiano Feb 16, 2024
69f9f47
Merge branch 'main' into customer-contact-confirm
fballiano Feb 16, 2024
5f3990f
Added warning message
fballiano Feb 16, 2024
8065fe0
https://github.com/OpenMage/magento-lts/pull/3615#discussion_r1492412261
fballiano Feb 16, 2024
37a5d61
Merge branch 'main' into customer-contact-confirm
fballiano Feb 16, 2024
e718922
new warning message
fballiano Feb 20, 2024
612a902
Merge branch 'main' into customer-contact-confirm
fballiano Feb 20, 2024
7cc543f
warning-message
addison74 Feb 20, 2024
6341fe0
update warning in language
addison74 Feb 20, 2024
c7dab34
Update Mage_Contacts.csv
addison74 Feb 20, 2024
d56b008
enable-auto-reply-csv
addison74 Feb 20, 2024
fbf94ba
Update system.xml
addison74 Feb 20, 2024
e8e7947
Update IndexController.php
addison74 Feb 20, 2024
638b493
Update config.xml
addison74 Feb 20, 2024
8833fe8
Update system.xml
addison74 Feb 20, 2024
4255dcf
Update Mage_Contacts.csv
addison74 Feb 20, 2024
a104dbc
Update contact_form_auto_reply.html
addison74 Feb 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 37 additions & 25 deletions app/code/core/Mage/Contacts/controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
*/
class Mage_Contacts_IndexController extends Mage_Core_Controller_Front_Action
{
public const XML_PATH_EMAIL_RECIPIENT = 'contacts/email/recipient_email';
public const XML_PATH_EMAIL_SENDER = 'contacts/email/sender_email_identity';
public const XML_PATH_EMAIL_TEMPLATE = 'contacts/email/email_template';
public const XML_PATH_ENABLED = 'contacts/contacts/enabled';
public const XML_PATH_ENABLED = 'contacts/contacts/enabled';
public const XML_PATH_EMAIL_SENDER = 'contacts/email/sender_email_identity';
public const XML_PATH_EMAIL_RECIPIENT = 'contacts/email/recipient_email';
public const XML_PATH_EMAIL_TEMPLATE = 'contacts/email/email_template';
public const XML_PATH_AUTO_REPLY_ENABLED = 'contacts/auto_reply_to_customer/enabled';
public const XML_PATH_AUTO_REPLY_EMAIL_TEMPLATE = 'contacts/auto_reply_to_customer/email_template';

/**
* @return $this
Expand Down Expand Up @@ -61,23 +63,21 @@ public function postAction()
$postObject = new Varien_Object();
$postObject->setData($post);

// check data
$error = false;

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

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

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

if ($error) {
throw new Exception();
Mage::throwException($this->__('Unable to submit your request. Please, try again later'));
}

// send email
$mailTemplate = Mage::getModel('core/email_template');
/** @var Mage_Core_Model_Email_Template $mailTemplate */
$mailTemplate->setDesignConfig(['area' => 'frontend'])
Expand All @@ -91,24 +91,36 @@ public function postAction()
);

if (!$mailTemplate->getSentSuccess()) {
throw new Exception();
Mage::throwException($this->__('Unable to submit your request. Please, try again later'));
}

$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('*/*/');
// send auto reply email to customer
if (Mage::getStoreConfigFlag(self::XML_PATH_AUTO_REPLY_ENABLED)) {
$mailTemplate = Mage::getModel('core/email_template');
/** @var Mage_Core_Model_Email_Template $mailTemplate */
$mailTemplate->setDesignConfig(['area' => 'frontend'])
->setReplyTo(Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT))
->sendTransactional(
Mage::getStoreConfig(self::XML_PATH_AUTO_REPLY_EMAIL_TEMPLATE),
Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
$post['email'],
null,
['data' => $postObject]
);
}

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;
Mage::getSingleton('customer/session')->addSuccess($this->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.'));
} catch (Mage_Core_Exception $e) {
$translate->setTranslateInline(true);
Mage::logException($e);
Mage::getSingleton('customer/session')->addError($e->getMessage());
} catch (Exception $e) {
Mage::logException($e);
Mage::getSingleton('customer/session')->addError($this->__('Unable to submit your request. Please, try again later'));
}
} else {
$this->_redirect('*/*/');
}

$this->_redirect('*/*/');
}
}
7 changes: 5 additions & 2 deletions app/code/core/Mage/Contacts/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@
<file>contact_form.html</file>
<type>text</type>
</contacts_email_email_template>
<contacts_auto_reply_to_customer_email_template translate="label" module="contacts">
<label>Contact Form Auto Reply</label>
<file>contact_form_auto_reply.html</file>
<type>html</type>
</contacts_auto_reply_to_customer_email_template>
</email>
</template>
</global>

<adminhtml>
<translate>
<modules>
Expand All @@ -77,7 +81,6 @@
</modules>
</translate>
</adminhtml>

<default>
<contacts>
<contacts>
Expand Down
44 changes: 36 additions & 8 deletions app/code/core/Mage/Contacts/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,34 +50,62 @@
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<sender_email_identity translate="label">
<label>Email Sender</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_email_identity</source_model>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</sender_email_identity>
<recipient_email translate="label">
<label>Send Emails To</label>
<validate>validate-email required-entry</validate>
<sort_order>10</sort_order>
<sort_order>20</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</recipient_email>
<sender_email_identity translate="label">
<label>Email Sender</label>
<email_template translate="label">
<label>Email Template</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_email_identity</source_model>
<sort_order>20</sort_order>
<source_model>adminhtml/system_config_source_email_template</source_model>
<sort_order>30</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</sender_email_identity>
</email_template>
</fields>
</email>
<auto_reply_to_customer translate="label">
<label>Auto Reply to Customer</label>
<sort_order>50</sort_order>
addison74 marked this conversation as resolved.
Show resolved Hide resolved
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<enabled translate="label comment">
<label>Enable</label>
<comment>Caution: auto reply can be abused to spam, ensure you have implemented necessary security measures (eg: enabling captcha) before proceeding.</comment>
fballiano marked this conversation as resolved.
Show resolved Hide resolved
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>91</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</enabled>
<email_template translate="label">
<label>Email Template</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_email_template</source_model>
<sort_order>30</sort_order>
<sort_order>92</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</email_template>
</fields>
</email>
</auto_reply_to_customer>
</groups>
</contacts>
</sections>
Expand Down
7 changes: 5 additions & 2 deletions app/locale/en_US/Mage_Contacts.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"* Required Fields","* Required Fields"
"Auto Reply to Customer","Auto Reply to Customer"
"Caution: auto reply can be abused to spam, ensure you have implemented necessary security measures (eg: enabling captcha) before proceeding.","Caution: auto reply can be abused to spam, ensure you have implemented necessary security measures (eg: enabling captcha) before proceeding."
"Comment","Comment"
"Contact Form","Contact Form"
"Contact Form Auto Reply","Contact Form Auto Reply"
"Contact Information","Contact Information"
"Contact Us","Contact Us"
"Contact Us Form","Contact Us Form"
Expand All @@ -10,9 +13,9 @@
"Email Sender","Email Sender"
"Email Template","Email Template"
"Enable Contact Us","Enable Contact Us"
"Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.","Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us."
"Name","Name"
"Send Emails To","Send Emails To"
"Submit","Submit"
"Telephone","Telephone"
"Unable to submit your request. Please, try again later","Unable to submit your request. Please, try again later"
"Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.","Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us."
"Unable to submit your request. Please, try again later","Unable to submit your request. Please, try again later"
13 changes: 13 additions & 0 deletions app/locale/en_US/template/email/contact_form_auto_reply.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!--@subject Contact Form Confirmation @-->
<!--@vars
{"var data.name":"Sender Name",
"var data.email":"Sender Email",
"var data.telephone":"Sender Telephone",
"var data.comment":"Comment"}
@-->

Thank you for contacting us, we will reply you shortly.<br>
Have a nice day.
fballiano marked this conversation as resolved.
Show resolved Hide resolved
<br><br>
In case you received this message without using the contact form on our website, please ignore it.<br>
Thank you for your understanding.
addison74 marked this conversation as resolved.
Show resolved Hide resolved
Loading