ArchApps_ContactFormDepartments - Version 0.1.2

Version Notes

Release of v0.1.2

Download this release

Release Info

Developer ArchApps
Extension ArchApps_ContactFormDepartments
Version 0.1.2
Comparing to
See all releases


Version 0.1.2

app/code/community/ArchApps/ContactFormDepartments/Block/Adminhtml/Department.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category ArchApps
4
+ * @package ArchApps_ContactFormDepartments
5
+ * @license https://opensource.org/licenses/osl-3.0.php OSL 3.0
6
+ */
7
+
8
+ class ArchApps_ContactFormDepartments_Block_Adminhtml_Department
9
+ extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
10
+ {
11
+ /**
12
+ * Add contact department columns, set template, add values.
13
+ */
14
+ public function __construct()
15
+ {
16
+ /** @var ArchApps_ContactFormDepartments_Helper_Data $helper */
17
+ $helper = Mage::helper('archapps_contactformdepartments');
18
+
19
+ $this->addColumn('name', array(
20
+ 'style' => 'width:200px',
21
+ 'label' => $helper->__('Department Name'),
22
+ ));
23
+
24
+ $this->addColumn('email', array(
25
+ 'style' => 'width:200px',
26
+ 'label' => $helper->__('Email'),
27
+ ));
28
+
29
+ $this->addColumn('position', array(
30
+ 'style' => 'width:80px',
31
+ 'label' => $helper->__('Sort Order'),
32
+ ));
33
+
34
+ $this->_addButtonLabel = $helper->__('Add Department');
35
+ $this->_addAfter = false;
36
+ parent::__construct();
37
+ }
38
+ }
app/code/community/ArchApps/ContactFormDepartments/Helper/Data.php ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category ArchApps
4
+ * @package ArchApps_ContactFormDepartments
5
+ * @license https://opensource.org/licenses/osl-3.0.php OSL 3.0
6
+ */
7
+
8
+ class ArchApps_ContactFormDepartments_Helper_Data extends Mage_Core_Helper_Abstract
9
+ {
10
+ const XML_PATH_ENABLED = 'contacts/departments/enabled';
11
+ const XML_PATH_DEPARTMENTS = 'contacts/departments/departments';
12
+ const XML_PATH_SELECT_LABEL = 'contacts/departments/select_label';
13
+
14
+ const XML_PATH_SHOW_PLACEHOLDER = 'contacts/departments/show_placeholder_option';
15
+ const XML_PATH_PLACEHOLDER_TEXT = 'contacts/departments/placeholder_option_text';
16
+
17
+ /**
18
+ * Whether departments feature is enabled for contact form
19
+ *
20
+ * @return mixed
21
+ */
22
+ public function isEnabled()
23
+ {
24
+ return Mage::getStoreConfig(self::XML_PATH_ENABLED);
25
+ }
26
+
27
+ /**
28
+ * Gets un-serialized array of all contacts departments
29
+ *
30
+ * @return mixed
31
+ */
32
+ public function getDepartments()
33
+ {
34
+ $departments = unserialize(
35
+ Mage::getStoreConfig(self::XML_PATH_DEPARTMENTS)
36
+ );
37
+
38
+ if ($departments) {
39
+ uasort($departments, array(get_class($this), '_sortDepartments'));
40
+ }
41
+
42
+ return $departments;
43
+ }
44
+
45
+ /**
46
+ * Returns target department email or false if email is not found
47
+ *
48
+ * @param $departmentKey string Department key to lookup email by
49
+ * @return bool|string
50
+ */
51
+ public function getDepartmentEmail($departmentKey)
52
+ {
53
+ foreach ($this->getDepartments() as $key => $department) {
54
+ if ($key == $departmentKey) {
55
+ return $department['email'];
56
+ }
57
+ }
58
+
59
+ return false;
60
+ }
61
+
62
+ /**
63
+ * Returns specified label to be displayed for department select
64
+ *
65
+ * @return mixed
66
+ */
67
+ public function getSelectLabel()
68
+ {
69
+ return Mage::getStoreConfig(self::XML_PATH_SELECT_LABEL);
70
+ }
71
+
72
+ /**
73
+ * Whether to display placeholder option in departments select
74
+ *
75
+ * @return mixed
76
+ */
77
+ public function getShowPlaceholderOption()
78
+ {
79
+ return Mage::getStoreConfig(self::XML_PATH_SHOW_PLACEHOLDER);
80
+ }
81
+
82
+ /**
83
+ * Whether to display placeholder option in departments select
84
+ *
85
+ * @return mixed
86
+ */
87
+ public function getPlaceholderOptionText()
88
+ {
89
+ return Mage::getStoreConfig(self::XML_PATH_PLACEHOLDER_TEXT);
90
+ }
91
+
92
+ /**
93
+ * Method used to sort departments array based on their position data
94
+ *
95
+ * @param $departmentA array Department data
96
+ * @param $departmentB array Department data
97
+ * @return mixed
98
+ */
99
+ private static function _sortDepartments($departmentA, $departmentB)
100
+ {
101
+ return $departmentA['position'] - $departmentB['position'];
102
+ }
103
+ }
app/code/community/ArchApps/ContactFormDepartments/Model/Observer.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category ArchApps
4
+ * @package ArchApps_ContactFormDepartments
5
+ * @license https://opensource.org/licenses/osl-3.0.php OSL 3.0
6
+ */
7
+
8
+ class ArchApps_ContactFormDepartments_Model_Observer
9
+ {
10
+ /**
11
+ * Set contact form recipient email to one specified in the department
12
+ *
13
+ * @param Varien_Event_Observer $observer Default event observer object
14
+ */
15
+ public function setDepartmentRecipient(Varien_Event_Observer $observer)
16
+ {
17
+ /** @var ArchApps_ContactFormDepartments_Helper_Data $helper */
18
+ $helper = Mage::helper('archapps_contactformdepartments');
19
+
20
+ if (!$helper->isEnabled()) {
21
+ return;
22
+ }
23
+
24
+ /** @var Mage_Contacts_IndexController $controller Contacts */
25
+ $controller = $observer->getEvent()->getControllerAction();
26
+ $key = $controller->getRequest()->getPost('department');
27
+
28
+ if (!$key) {
29
+ return;
30
+ }
31
+
32
+ if ($recipient = $helper->getDepartmentEmail($key)) {
33
+ $path = Mage_Contacts_IndexController::XML_PATH_EMAIL_RECIPIENT;
34
+ // Set new department email address to specified config node
35
+ Mage::app()->getStore()->setConfig($path, $recipient);
36
+ }
37
+ }
38
+ }
app/code/community/ArchApps/ContactFormDepartments/etc/config.xml ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category ArchApps
5
+ * @package ArchApps_ContactFormDepartments
6
+ * @license https://opensource.org/licenses/osl-3.0.php OSL 3.0
7
+ */
8
+ -->
9
+ <config>
10
+ <modules>
11
+ <ArchApps_ContactFormDepartments>
12
+ <version>0.1.2</version>
13
+ </ArchApps_ContactFormDepartments>
14
+ </modules>
15
+
16
+ <global>
17
+ <blocks>
18
+ <archapps_contactformdepartments>
19
+ <class>ArchApps_ContactFormDepartments_Block</class>
20
+ </archapps_contactformdepartments>
21
+ </blocks>
22
+
23
+ <helpers>
24
+ <archapps_contactformdepartments>
25
+ <class>ArchApps_ContactFormDepartments_Helper</class>
26
+ </archapps_contactformdepartments>
27
+ </helpers>
28
+
29
+ <models>
30
+ <archapps_contactformdepartments>
31
+ <class>ArchApps_ContactFormDepartments_Model</class>
32
+ </archapps_contactformdepartments>
33
+ </models>
34
+ </global>
35
+
36
+ <adminhtml>
37
+ <translate>
38
+ <modules>
39
+ <archapps_contactformdepartments>
40
+ <files>
41
+ <default>ArchApps_ContactFormDepartments.csv</default>
42
+ </files>
43
+ </archapps_contactformdepartments>
44
+ </modules>
45
+ </translate>
46
+ </adminhtml>
47
+
48
+ <frontend>
49
+ <layout>
50
+ <updates>
51
+ <archapps_contactformdepartments>
52
+ <file>archapps/contactformdepartments.xml</file>
53
+ </archapps_contactformdepartments>
54
+ </updates>
55
+ </layout>
56
+
57
+ <events>
58
+ <controller_action_predispatch_contacts_index_post>
59
+ <observers>
60
+ <archapps_contactformdepartments>
61
+ <type>singleton</type>
62
+ <method>setDepartmentRecipient</method>
63
+ <class>archapps_contactformdepartments/observer</class>
64
+ </archapps_contactformdepartments>
65
+ </observers>
66
+ </controller_action_predispatch_contacts_index_post>
67
+ </events>
68
+ </frontend>
69
+
70
+ <default>
71
+ <contacts>
72
+ <departments>
73
+ <select_label>Department</select_label>
74
+ <show_placeholder_option>1</show_placeholder_option>
75
+ <placeholder_option_text>-- Select Department --</placeholder_option_text>
76
+ </departments>
77
+ </contacts>
78
+ </default>
79
+ </config>
app/code/community/ArchApps/ContactFormDepartments/etc/system.xml ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category ArchApps
5
+ * @package ArchApps_ContactFormDepartments
6
+ * @license https://opensource.org/licenses/osl-3.0.php OSL 3.0
7
+ */
8
+ -->
9
+ <config>
10
+ <sections>
11
+ <contacts>
12
+ <groups>
13
+ <departments translate="label" module="archapps_contactformdepartments">
14
+ <label>Departments</label>
15
+ <sort_order>200</sort_order>
16
+ <show_in_store>1</show_in_store>
17
+ <show_in_default>1</show_in_default>
18
+ <show_in_website>1</show_in_website>
19
+ <frontend_type>text</frontend_type>
20
+ <fields>
21
+ <enabled translate="label comment">
22
+ <label>Enable Departments</label>
23
+ <frontend_type>select</frontend_type>
24
+ <sort_order>10</sort_order>
25
+ <show_in_store>1</show_in_store>
26
+ <show_in_website>1</show_in_website>
27
+ <show_in_default>1</show_in_default>
28
+ <source_model>adminhtml/system_config_source_yesno</source_model>
29
+ <comment>Whether Departments Feature Is Enabled For Contact Form</comment>
30
+ </enabled>
31
+
32
+ <departments translate="label">
33
+ <label>Departments</label>
34
+ <sort_order>20</sort_order>
35
+ <show_in_store>1</show_in_store>
36
+ <show_in_website>1</show_in_website>
37
+ <show_in_default>1</show_in_default>
38
+ <backend_model>adminhtml/system_config_backend_serialized_array</backend_model>
39
+ <frontend_model>archapps_contactformdepartments/adminhtml_department</frontend_model>
40
+ </departments>
41
+
42
+ <select_label translate="label comment">
43
+ <label>Select Label</label>
44
+ <frontend_type>text</frontend_type>
45
+ <sort_order>30</sort_order>
46
+ <show_in_store>1</show_in_store>
47
+ <show_in_website>1</show_in_website>
48
+ <show_in_default>1</show_in_default>
49
+ <comment>Label / Title To Be Displayed Next To Department Select</comment>
50
+ </select_label>
51
+
52
+ <show_placeholder_option translate="label comment">
53
+ <label>Show Placeholder Option</label>
54
+ <frontend_type>select</frontend_type>
55
+ <sort_order>40</sort_order>
56
+ <show_in_store>1</show_in_store>
57
+ <show_in_website>1</show_in_website>
58
+ <show_in_default>1</show_in_default>
59
+ <source_model>adminhtml/system_config_source_yesno</source_model>
60
+ <comment>Whether To Show Placeholder Option in Departments Select</comment>
61
+ </show_placeholder_option>
62
+
63
+ <placeholder_option_text translate="label comment">
64
+ <label>Placeholder Option Text</label>
65
+ <frontend_type>text</frontend_type>
66
+ <sort_order>50</sort_order>
67
+ <show_in_store>1</show_in_store>
68
+ <show_in_website>1</show_in_website>
69
+ <show_in_default>1</show_in_default>
70
+ <comment>Text To Show In Placeholder Option In Departments Select</comment>
71
+ </placeholder_option_text>
72
+ </fields>
73
+ </departments>
74
+ </groups>
75
+ </contacts>
76
+ </sections>
77
+ </config>
app/design/frontend/base/default/layout/archapps/contactformdepartments.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category ArchApps
5
+ * @package ArchApps_ContactFormDepartments
6
+ * @license https://opensource.org/licenses/osl-3.0.php OSL 3.0
7
+ */
8
+ -->
9
+ <layout>
10
+ <contacts_index_index>
11
+ <reference name="contactForm">
12
+ <!-- Append departments select block to contact form -->
13
+ <block type="core/template" as="departments"
14
+ name="archapps.contactformdepartments.departments"
15
+ template="archapps/contactformdepartments/departments.phtml"/>
16
+ </reference>
17
+ </contacts_index_index>
18
+ </layout>
app/design/frontend/base/default/template/archapps/contactformdepartments/departments.phtml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category ArchApps
4
+ * @package ArchApps_ContactFormDepartments
5
+ * @license https://opensource.org/licenses/osl-3.0.php OSL 3.0
6
+ */
7
+ ?>
8
+ <?php
9
+ /** @var ArchApps_ContactFormDepartments_Helper_Data $helper */
10
+ $helper = Mage::helper('archapps_contactformdepartments');
11
+ ?>
12
+ <?php if ($helper->isEnabled() && ($departments = $helper->getDepartments())): ?>
13
+ <li>
14
+ <?php if ($label = $helper->getSelectLabel()): ?>
15
+ <label for="department" class="required"><em>*</em><?php echo $label ?></label>
16
+ <?php endif; ?>
17
+
18
+ <div class="input-box">
19
+ <select name="department" id="department" class="required-entry"
20
+ title="<?php echo Mage::helper('core')->quoteEscape($helper->getSelectLabel()) ?>">
21
+ <?php if ($helper->getShowPlaceholderOption()): ?>
22
+ <option value=""><?php echo $helper->getPlaceholderOptionText() ?></option>
23
+ <?php endif; ?>
24
+
25
+ <?php foreach ($departments as $id => $department): ?>
26
+ <option value="<?php echo $id ?>"><?php echo $department['name'] ?></option>
27
+ <?php endforeach; ?>
28
+ </select>
29
+ </div>
30
+ </li>
31
+ <?php endif; ?>
app/etc/modules/ArchApps_ContactFormDepartments.xml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category ArchApps
5
+ * @package ArchApps_ContactFormDepartments
6
+ * @license https://opensource.org/licenses/osl-3.0.php OSL 3.0
7
+ */
8
+ -->
9
+ <config>
10
+ <modules>
11
+ <ArchApps_ContactFormDepartments>
12
+ <active>true</active>
13
+ <codePool>community</codePool>
14
+ <depends>
15
+ <Mage_Contacts />
16
+ </depends>
17
+ </ArchApps_ContactFormDepartments>
18
+ </modules>
19
+ </config>
app/locale/en_US/ArchApps_ContactFormDepartments.csv ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Departments", "Departments"
2
+ "Enable Departments", "Enable Departments"
3
+ "Whether Departments Feature Is Enabled For Contact Form", "Whether Departments Feature Is Enabled For Contact Form"
4
+ "Department Name", "Department Name"
5
+ "Email", "Email"
6
+ "Sort Order", "Sort Order"
7
+ "Add Department", "Add Department"
8
+ "Departments", "Departments"
9
+ "Select Label", "Select Label"
10
+ "Label / Title To Be Displayed Next To Department Select", "Label / Title To Be Displayed Next To Department Select"
11
+ "Show Placeholder Option", "Show Placeholder Option"
12
+ "Whether To Show Placeholder Option in Departments Select", "Whether To Show Placeholder Option in Departments Select"
13
+ "Placeholder Option Text", "Placeholder Option Text"
14
+ "Text To Show In Placeholder Option In Departments Select", "Text To Show In Placeholder Option In Departments Select"
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>ArchApps_ContactFormDepartments</name>
4
+ <version>0.1.2</version>
5
+ <stability>stable</stability>
6
+ <license uri="https://opensource.org/licenses/osl-3.0.php">OSL 3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Extend default contact form and sort your incoming contact emails by departments.</summary>
10
+ <description>Contact Departments extension for Magento extends default contact form by adding departments field that helps you sort all incoming contact emails. Easily add any number of contact departments - specify department name, email address to receive emails and set display order within select field for each department. From now on, contact emails will be sent to specified department email address.</description>
11
+ <notes>Release of v0.1.2</notes>
12
+ <authors><author><name>ArchApps</name><user>ArchApps</user><email>raivis@archapps.io</email></author></authors>
13
+ <date>2016-05-13</date>
14
+ <time>13:18:16</time>
15
+ <contents><target name="mage"><dir name="app"><dir name="code"><dir name="community"><dir name="ArchApps"><dir name="ContactFormDepartments"><dir><dir name="Block"><dir name="Adminhtml"><file name="Department.php" hash="8197ef4a9466a5a1263dde202903901a"/></dir></dir><dir name="Helper"><file name="Data.php" hash="5e91d2aa818f026180d266641637040b"/></dir><dir name="Model"><file name="Observer.php" hash="3e2685fbe3e39397c77c95b361c499ec"/></dir><dir name="etc"><file name="config.xml" hash="7e8b819e6f1c1f52b92d49b08012c5d3"/><file name="system.xml" hash="2efde7aed3184455cdc3bc7e23934954"/></dir></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="ArchApps_ContactFormDepartments.xml" hash="b0e49548251eec0a9f551e7ebecf1e07"/></dir></dir><dir name="locale"><dir name="en_US"><file name="ArchApps_ContactFormDepartments.csv" hash="12e8bb914665c1ace1edea9ff72ad98e"/></dir></dir><dir name="design"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="archapps"><file name="contactformdepartments.xml" hash="a8c4ba1e575ecb3c15382dbd8f801ba9"/></dir></dir><dir name="template"><dir name="archapps"><dir name="contactformdepartments"><file name="departments.phtml" hash="2d19bd5671c5c37ce59bb4999b919547"/></dir></dir></dir></dir></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.4.0</min><max>7.0.0</max></php></required></dependencies>
18
+ </package>