theextensionlab_reviewnotifier - Version 1.0.0

Version Notes

Initial Release.

Download this release

Release Info

Developer James Anelay
Extension theextensionlab_reviewnotifier
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/TheExtensionLab/ReviewNotifier/Helper/Data.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php class TheExtensionLab_ReviewNotifier_Helper_Data extends Mage_Core_Helper_Abstract
2
+ {
3
+ const XML_PATH_EMAIL_TEMPLATE = 'catalog/review/alert_email_template';
4
+ const XML_PATH_EMAIL_IDENTITY = 'catalog/review/alert_email_identity';
5
+ const XML_PATH_EMAIL_RECIPIENT = 'catalog/review/alert_email';
6
+
7
+ public function sendNewReviewAlertEmail(Mage_Review_Model_Review $review)
8
+ {
9
+ if (!Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT)) {
10
+ return $this;
11
+ }
12
+
13
+ $translate = Mage::getSingleton('core/translate');
14
+ /* @var $translate Mage_Core_Model_Translate */
15
+ $translate->setTranslateInline(false);
16
+
17
+ $storeId = $review->getStoreId();
18
+ $store = Mage::getModel('core/store')->load($storeId);
19
+
20
+ $moderationUrl = $this->getReviewModerationUrl($review->getId());
21
+
22
+ $vars = array(
23
+ 'review' => $review,
24
+ 'store' => $store,
25
+ 'moderationUrl' => $moderationUrl
26
+ );
27
+
28
+ $emailTemplate = Mage::getModel('core/email_template');
29
+ /* @var $emailTemplate Mage_Core_Model_Email_Template */
30
+
31
+ $emailTemplate->setDesignConfig(array('area' => 'backend'));
32
+
33
+ //Use this event to add/update email variables if needed
34
+ Mage::dispatchEvent('product_review_alert_send_before',array('vars' => $vars, 'email_template' => $emailTemplate));
35
+
36
+ $emailTemplate->sendTransactional(
37
+ Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
38
+ Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY),
39
+ Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
40
+ null,
41
+ $vars
42
+ );
43
+
44
+ $translate->setTranslateInline(true);
45
+
46
+ }
47
+
48
+ public function getReviewModerationUrl($reviewId)
49
+ {
50
+ return Mage::helper("adminhtml")->getUrl("adminhtml/catalog_product_review/edit", array('id' => $reviewId));
51
+ }
52
+
53
+ }
app/code/community/TheExtensionLab/ReviewNotifier/Model/Observer.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php class TheExtensionLab_ReviewNotifier_Model_Observer
2
+ {
3
+ /**
4
+ * @param Varien_Event_Observer $observer
5
+ *
6
+ * @return $this|bool
7
+ */
8
+ public function reviewSaveAfter(Varien_Event_Observer $observer)
9
+ {
10
+ $review = $observer->getEvent()->getObject();
11
+
12
+ //If review is not a new one - don't do anything
13
+ if(!$review->isObjectNew()){
14
+ return false;
15
+ }
16
+
17
+ //Send admin alert e-mail here
18
+
19
+ $helper = $this->getHelper();
20
+ $helper->sendNewReviewAlertEmail($review);
21
+
22
+ return $this;
23
+ }
24
+
25
+ protected function getHelper()
26
+ {
27
+ return Mage::helper('theextensionlab_reviewnotifier');
28
+ }
29
+ }
app/code/community/TheExtensionLab/ReviewNotifier/Test/Config/Main.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php class TheExtensionLab_ReviewNotifier_Test_Config_Main extends EcomDev_PHPUnit_Test_Case_Config
2
+ {
3
+ public function testClassAiases()
4
+ {
5
+ $this->assertModelAlias('theextensionlab_reviewnotifier/observer','TheExtensionLab_ReviewNotifier_Model_Observer');
6
+ $this->assertHelperAlias('theextensionlab_reviewnotifier','TheExtensionLab_ReviewNotifier_Helper_Data');
7
+ }
8
+
9
+ public function testObserverConfig()
10
+ {
11
+ $this->assertEventObserverDefined(
12
+ 'global',
13
+ 'review_save_after',
14
+ 'theextensionlab_reviewnotifier/observer',
15
+ 'reviewSaveAfter'
16
+ );
17
+ }
18
+ }
app/code/community/TheExtensionLab/ReviewNotifier/Test/Helper/Main.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php class TheExtensionLab_ReviewNotifier_Test_Helper_Main extends EcomDev_PHPUnit_Test_Case
2
+ {
3
+ public function testHelperClass()
4
+ {
5
+ $helper = Mage::helper('theextensionlab_reviewnotifier');
6
+ $this->assertInstanceOf('TheExtensionLab_ReviewNotifier_Helper_Data', $helper);
7
+ return $helper;
8
+ }
9
+ }
app/code/community/TheExtensionLab/ReviewNotifier/Test/Model/Observer.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php class TheExtensionLab_ReviewNotifier_Test_Model_Observer extends EcomDev_PHPUnit_Test_Case
2
+ {
3
+ public function testObserverClass()
4
+ {
5
+ $observer = Mage::getModel('theextensionlab_reviewnotifier/observer');
6
+ $this->assertInstanceOf('TheExtensionLab_ReviewNotifier_Model_Observer', $observer);
7
+ return $observer;
8
+ }
9
+ }
app/code/community/TheExtensionLab/ReviewNotifier/etc/config.xml ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <TheExtensionLab_ReviewNotifier>
5
+ <version>1.0.0</version>
6
+ </TheExtensionLab_ReviewNotifier>
7
+ </modules>
8
+
9
+ <global>
10
+ <models>
11
+ <theextensionlab_reviewnotifier>
12
+ <class>TheExtensionLab_ReviewNotifier_Model</class>
13
+ </theextensionlab_reviewnotifier>
14
+ </models>
15
+
16
+ <helpers>
17
+ <theextensionlab_reviewnotifier>
18
+ <class>TheExtensionLab_ReviewNotifier_Helper</class>
19
+ </theextensionlab_reviewnotifier>
20
+ </helpers>
21
+
22
+ <events>
23
+ <review_save_after>
24
+ <observers>
25
+ <theextensionlab_reviewnotifier>
26
+ <class>theextensionlab_reviewnotifier/observer</class>
27
+ <method>reviewSaveAfter</method>
28
+ </theextensionlab_reviewnotifier>
29
+ </observers>
30
+ </review_save_after>
31
+ </events>
32
+
33
+ <template>
34
+ <email>
35
+ <catalog_review_alert_email_template>
36
+ <label>New Review Notification Template</label>
37
+ <file>theextensionlab/reviewnotifier/new_review.html</file>
38
+ <type>html</type>
39
+ </catalog_review_alert_email_template>
40
+ </email>
41
+ </template>
42
+
43
+ </global>
44
+
45
+ <default>
46
+ <catalog>
47
+ <review>
48
+ <enable_alerts>0</enable_alerts>
49
+ <alert_email_identity>general</alert_email_identity>
50
+ <alert_email_template>catalog_review_alert_email_template</alert_email_template>
51
+ </review>
52
+ </catalog>
53
+ </default>
54
+
55
+ <phpunit>
56
+ <suite>
57
+ <modules>
58
+ <TheExtensionLab_ReviewNotifier/>
59
+ </modules>
60
+ </suite>
61
+ </phpunit>
62
+
63
+ </config>
app/code/community/TheExtensionLab/ReviewNotifier/etc/system.xml ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <catalog>
5
+ <groups>
6
+ <review translate="label" module="review">
7
+ <fields>
8
+ <enable_alerts>
9
+ <label>Enable New Review E-mail Alert</label>
10
+ <frontend_type>select</frontend_type>
11
+ <source_model>adminhtml/system_config_source_yesno</source_model>
12
+ <sort_order>120</sort_order>
13
+ <show_in_default>1</show_in_default>
14
+ <show_in_website>0</show_in_website>
15
+ <show_in_store>0</show_in_store>
16
+ </enable_alerts>
17
+ <alert_email translate="label">
18
+ <label>Alert Email Recipient</label>
19
+ <frontend_type>text</frontend_type>
20
+ <sort_order>130</sort_order>
21
+ <show_in_default>1</show_in_default>
22
+ <show_in_website>0</show_in_website>
23
+ <show_in_store>0</show_in_store>
24
+ <depends>
25
+ <enable_alerts>1</enable_alerts>
26
+ </depends>
27
+ </alert_email>
28
+ <alert_email_identity translate="label">
29
+ <label>Alert Email Sender</label>
30
+ <frontend_type>select</frontend_type>
31
+ <source_model>adminhtml/system_config_source_email_identity</source_model>
32
+ <sort_order>140</sort_order>
33
+ <show_in_default>1</show_in_default>
34
+ <show_in_website>0</show_in_website>
35
+ <show_in_store>0</show_in_store>
36
+ <depends>
37
+ <enable_alerts>1</enable_alerts>
38
+ </depends>
39
+ </alert_email_identity>
40
+ <alert_email_template translate="label">
41
+ <label>Alert Email Template</label>
42
+ <frontend_type>select</frontend_type>
43
+ <source_model>adminhtml/system_config_source_email_template</source_model>
44
+ <sort_order>150</sort_order>
45
+ <show_in_default>1</show_in_default>
46
+ <show_in_website>0</show_in_website>
47
+ <show_in_store>0</show_in_store>
48
+ <depends>
49
+ <enable_alerts>1</enable_alerts>
50
+ </depends>
51
+ </alert_email_template>
52
+ </fields>
53
+ </review>
54
+ </groups>
55
+ </catalog>
56
+ </sections>
57
+ </config>
app/etc/modules/TheExtensionLab_ReviewNotifier.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <TheExtensionLab_ReviewNotifier>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </TheExtensionLab_ReviewNotifier>
8
+ </modules>
9
+ </config>
app/locale/en_US/template/email/theextensionlab/reviewnotifier/new_review.html ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--@subject A new product review has been posted and is ready for moderation @-->
2
+ <!--@vars
3
+ {"var review.id":"Review ID",
4
+ "var review.detail":"Review detail",
5
+ "var review.name":"Review name",
6
+ "var review.title":"Review name",
7
+ "var store.name":"Store Name",
8
+ "var moderationUrl":"Moderation Url"
9
+ }
10
+ @-->
11
+
12
+ <!--@styles
13
+ @-->
14
+
15
+ <p>A new review (ID:{{var review.id}}) titled "{{var review.title}}" was posted on {{var store.name}} at {{var review.created_at}} and needs moderation.</p>
16
+
17
+ <p><a href="{{var moderationUrl}}">Click here to moderate.</a></p>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>theextensionlab_reviewnotifier</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/OSL-3.0">Open Software License v3.0 (OSL-3.0)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>An Extension to add new product review notifications via e-mail.</summary>
10
+ <description>An Extension to add new product review notifications via e-mail.</description>
11
+ <notes>Initial Release.</notes>
12
+ <authors><author><name>James Anelay</name><user>TheExtensionLab</user><email>james@theextensionlab.com</email></author></authors>
13
+ <date>2015-02-27</date>
14
+ <time>08:46:05</time>
15
+ <contents><target name="magecommunity"><dir name="TheExtensionLab"><dir name="ReviewNotifier"><dir><dir name="Helper"><file name="Data.php" hash="11fe9a548e511e7832cb25eaab56ab5f"/></dir><dir name="Model"><file name="Observer.php" hash="1f5e4a2444d7f191488df870d5b48e02"/></dir><dir name="Test"><dir name="Config"><file name="Main.php" hash="fe2a26fa38c7ac404620504fb9843c62"/></dir><dir name="Helper"><file name="Main.php" hash="9b3e071fbe52e35b08613e905f244278"/></dir><dir name="Model"><file name="Observer.php" hash="9ead917fbe2fb87eaa1dfc4921afc351"/></dir></dir><dir name="etc"><file name="config.xml" hash="24216f18a18eda22d8a66afef47a0603"/><file name="system.xml" hash="e8edf37061cdffbe8312c98966b720da"/></dir></dir></dir></dir></target><target name="mageweb"><dir name="app"><dir name="locale"><dir name="en_US"><dir name="template"><dir name="email"><dir name="theextensionlab"><dir name="reviewnotifier"><file name="new_review.html" hash="e1cf65071be5e2389befddda6704f44f"/></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="TheExtensionLab_ReviewNotifier.xml" hash="1f0dcedc88e187a50e47aef4705fe4ba"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>