Conlabz_Useroptin - Version 1.0.0

Version Notes

Init extension version

Download this release

Release Info

Developer Conlabz GmbH
Extension Conlabz_Useroptin
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/Conlabz/Useroptin/Model/Newsletter/Subscriber.php ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Conlabz_Useroptin_Model_Newsletter_Subscriber extends Mage_Newsletter_Model_Subscriber
3
+ {
4
+
5
+ const XML_PATH_LOGGED_CONFIRM_EMAIL_TEMPLATE = 'newsletter/subscription/confirm_logged_email_template';
6
+
7
+ /**
8
+ * Subscribes by email
9
+ *
10
+ * @param string $email
11
+ * @throws Exception
12
+ * @return int
13
+ */
14
+ public function subscribe($email)
15
+ {
16
+ $this->loadByEmail($email);
17
+ $customerSession = Mage::getSingleton('customer/session');
18
+
19
+ if(!$this->getId()) {
20
+ $this->setSubscriberConfirmCode($this->randomSequence());
21
+ }
22
+
23
+ $isConfirmNeed = (Mage::getStoreConfig(self::XML_PATH_CONFIRMATION_FLAG) == 1) ? true : false;
24
+ $isOwnSubscribes = false;
25
+ $ownerId = Mage::getModel('customer/customer')
26
+ ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
27
+ ->loadByEmail($email)
28
+ ->getId();
29
+ $isSubscribeOwnEmail = $customerSession->isLoggedIn() && $ownerId == $customerSession->getId();
30
+
31
+ if (!$this->getId() || $this->getStatus() == self::STATUS_UNSUBSCRIBED
32
+ || $this->getStatus() == self::STATUS_NOT_ACTIVE
33
+ ) {
34
+ if ($isConfirmNeed === true) {
35
+ // if user subscribes own login email - confirmation is not needed
36
+ $isOwnSubscribes = $isSubscribeOwnEmail;
37
+ if ($isOwnSubscribes == true){
38
+ if (Mage::getStoreConfig(self::XML_PATH_LOGGED_CONFIRM_EMAIL_TEMPLATE) == 1){
39
+ $this->setStatus(self::STATUS_NOT_ACTIVE);
40
+ }else{
41
+ $this->setStatus(self::STATUS_SUBSCRIBED);
42
+ }
43
+ } else {
44
+ $this->setStatus(self::STATUS_NOT_ACTIVE);
45
+ }
46
+ } else {
47
+ $this->setStatus(self::STATUS_SUBSCRIBED);
48
+ }
49
+ $this->setSubscriberEmail($email);
50
+ }
51
+
52
+ if ($isSubscribeOwnEmail) {
53
+ $this->setStoreId($customerSession->getCustomer()->getStoreId());
54
+ $this->setCustomerId($customerSession->getCustomerId());
55
+ } else {
56
+ $this->setStoreId(Mage::app()->getStore()->getId());
57
+ $this->setCustomerId(0);
58
+ }
59
+
60
+ $this->setIsStatusChanged(true);
61
+
62
+ try {
63
+ $this->save();
64
+ if ($isConfirmNeed === true
65
+ && $isOwnSubscribes === false
66
+ ) {
67
+ $this->sendConfirmationRequestEmail();
68
+ } else {
69
+ if (Mage::getStoreConfig(self::XML_PATH_LOGGED_CONFIRM_EMAIL_TEMPLATE) == 1){
70
+ $this->sendConfirmationRequestEmail();
71
+ }else{
72
+ $this->sendConfirmationSuccessEmail();
73
+ }
74
+ }
75
+
76
+ return $this->getStatus();
77
+ } catch (Exception $e) {
78
+ throw new Exception($e->getMessage());
79
+ }
80
+ }
81
+
82
+ }
app/code/local/Conlabz/Useroptin/controllers/AccountController.php ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ include "Mage/Customer/controllers/AccountController.php";
3
+
4
+ class Conlabz_Useroptin_AccountController extends Mage_Customer_AccountController
5
+ {
6
+ /**
7
+ * Create customer account action
8
+ */
9
+ public function createPostAction()
10
+ {
11
+ $session = $this->_getSession();
12
+ if ($session->isLoggedIn()) {
13
+ $this->_redirect('*/*/');
14
+ return;
15
+ }
16
+ $session->setEscapeMessages(true); // prevent XSS injection in user input
17
+ if ($this->getRequest()->isPost()) {
18
+ $errors = array();
19
+
20
+ if (!$customer = Mage::registry('current_customer')) {
21
+ $customer = Mage::getModel('customer/customer')->setId(null);
22
+ }
23
+
24
+ /* @var $customerForm Mage_Customer_Model_Form */
25
+ $customerForm = Mage::getModel('customer/form');
26
+ $customerForm->setFormCode('customer_account_create')
27
+ ->setEntity($customer);
28
+
29
+ $customerData = $customerForm->extractData($this->getRequest());
30
+
31
+ if (Mage::getStoreConfig("newsletter/subscription/confirm_logged_email_template") == 1){
32
+
33
+ $status = Mage::getModel("newsletter/subscriber")->subscribe($this->getRequest()->getPost('email'));
34
+ if ($status == Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE) {
35
+ Mage::getSingleton('customer/session')->addSuccess($this->__('Confirmation request has been sent.'));
36
+ }
37
+ else {
38
+ Mage::getSingleton('customer/session')->addSuccess($this->__('Thank you for your subscription.'));
39
+ }
40
+
41
+ }else{
42
+
43
+
44
+ if ($this->getRequest()->getParam('is_subscribed', false)) {
45
+ $customer->setIsSubscribed(1);
46
+ }
47
+
48
+ }
49
+ /**
50
+ * Initialize customer group id
51
+ */
52
+ $customer->getGroupId();
53
+
54
+ if ($this->getRequest()->getPost('create_address')) {
55
+ /* @var $address Mage_Customer_Model_Address */
56
+ $address = Mage::getModel('customer/address');
57
+ /* @var $addressForm Mage_Customer_Model_Form */
58
+ $addressForm = Mage::getModel('customer/form');
59
+ $addressForm->setFormCode('customer_register_address')
60
+ ->setEntity($address);
61
+
62
+ $addressData = $addressForm->extractData($this->getRequest(), 'address', false);
63
+ $addressErrors = $addressForm->validateData($addressData);
64
+ if ($addressErrors === true) {
65
+ $address->setId(null)
66
+ ->setIsDefaultBilling($this->getRequest()->getParam('default_billing', false))
67
+ ->setIsDefaultShipping($this->getRequest()->getParam('default_shipping', false));
68
+ $addressForm->compactData($addressData);
69
+ $customer->addAddress($address);
70
+
71
+ $addressErrors = $address->validate();
72
+ if (is_array($addressErrors)) {
73
+ $errors = array_merge($errors, $addressErrors);
74
+ }
75
+ } else {
76
+ $errors = array_merge($errors, $addressErrors);
77
+ }
78
+ }
79
+
80
+ try {
81
+ $customerErrors = $customerForm->validateData($customerData);
82
+ if ($customerErrors !== true) {
83
+ $errors = array_merge($customerErrors, $errors);
84
+ } else {
85
+ $customerForm->compactData($customerData);
86
+ $customer->setPassword($this->getRequest()->getPost('password'));
87
+ $customer->setConfirmation($this->getRequest()->getPost('confirmation'));
88
+ $customerErrors = $customer->validate();
89
+ if (is_array($customerErrors)) {
90
+ $errors = array_merge($customerErrors, $errors);
91
+ }
92
+ }
93
+
94
+ $validationResult = count($errors) == 0;
95
+
96
+ if (true === $validationResult) {
97
+ $customer->save();
98
+
99
+ Mage::dispatchEvent('customer_register_success',
100
+ array('account_controller' => $this, 'customer' => $customer)
101
+ );
102
+
103
+ if ($customer->isConfirmationRequired()) {
104
+ $customer->sendNewAccountEmail(
105
+ 'confirmation',
106
+ $session->getBeforeAuthUrl(),
107
+ Mage::app()->getStore()->getId()
108
+ );
109
+ $session->addSuccess($this->__('Account confirmation is required. Please, check your email for the confirmation link. To resend the confirmation email please <a href="%s">click here</a>.', Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail())));
110
+ $this->_redirectSuccess(Mage::getUrl('*/*/index', array('_secure'=>true)));
111
+ return;
112
+ } else {
113
+ $session->setCustomerAsLoggedIn($customer);
114
+ $url = $this->_welcomeCustomer($customer);
115
+ $this->_redirectSuccess($url);
116
+ return;
117
+ }
118
+ } else {
119
+ $session->setCustomerFormData($this->getRequest()->getPost());
120
+ if (is_array($errors)) {
121
+ foreach ($errors as $errorMessage) {
122
+ $session->addError($errorMessage);
123
+ }
124
+ } else {
125
+ $session->addError($this->__('Invalid customer data'));
126
+ }
127
+ }
128
+ } catch (Mage_Core_Exception $e) {
129
+ $session->setCustomerFormData($this->getRequest()->getPost());
130
+ if ($e->getCode() === Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS) {
131
+ $url = Mage::getUrl('customer/account/forgotpassword');
132
+ $message = $this->__('There is already an account with this email address. If you are sure that it is your email address, <a href="%s">click here</a> to get your password and access your account.', $url);
133
+ $session->setEscapeMessages(false);
134
+ } else {
135
+ $message = $e->getMessage();
136
+ }
137
+ $session->addError($message);
138
+ } catch (Exception $e) {
139
+ $session->setCustomerFormData($this->getRequest()->getPost())
140
+ ->addException($e, $this->__('Cannot save the customer.'));
141
+ }
142
+ }
143
+
144
+ $this->_redirectError(Mage::getUrl('*/*/create', array('_secure' => true)));
145
+ }
146
+
147
+
148
+ }
app/code/local/Conlabz/Useroptin/controllers/ManageController.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ include "Mage/Newsletter/controllers/ManageController.php";
3
+ class Conlabz_Useroptin_ManageController extends Mage_Newsletter_ManageController {
4
+
5
+ public function saveAction()
6
+ {
7
+ if (!$this->_validateFormKey()) {
8
+ return $this->_redirect('customer/account/');
9
+ }
10
+ try {
11
+
12
+ if (Mage::getStoreConfig("newsletter/subscription/confirm_logged_email_template") == 1){
13
+
14
+ $status = Mage::getModel("newsletter/subscriber")->subscribe(Mage::getSingleton('customer/session')->getCustomer()->getEmail());
15
+ if ($status == Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE) {
16
+ Mage::getSingleton('customer/session')->addSuccess($this->__('Confirmation request has been sent.'));
17
+ }
18
+ else {
19
+ Mage::getSingleton('customer/session')->addSuccess($this->__('Thank you for your subscription.'));
20
+ }
21
+
22
+ }else{
23
+ Mage::getSingleton('customer/session')->getCustomer()
24
+ ->setStoreId(Mage::app()->getStore()->getId())
25
+ ->setIsSubscribed((boolean)$this->getRequest()->getParam('is_subscribed', false))
26
+ ->save();
27
+ if ((boolean)$this->getRequest()->getParam('is_subscribed', false)) {
28
+ Mage::getSingleton('customer/session')->addSuccess($this->__('The subscription has been saved.'));
29
+ } else {
30
+ Mage::getSingleton('customer/session')->addSuccess($this->__('The subscription has been removed.'));
31
+ }
32
+ }
33
+
34
+ }
35
+ catch (Exception $e) {
36
+ Mage::getSingleton('customer/session')->addError($e->getMessage());
37
+ Mage::getSingleton('customer/session')->addError($this->__('An error occurred while saving your subscription.'));
38
+ }
39
+ $this->_redirect('customer/account/');
40
+ }
41
+
42
+
43
+ }
app/code/local/Conlabz/Useroptin/etc/config.xml ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Conlabz_Useroptin>
5
+ <version>1.0.0</version>
6
+ </Conlabz_Useroptin>
7
+ </modules>
8
+ <global>
9
+ <helpers>
10
+ <useroptin>
11
+ <class>Conlabz_Useroptin_Helper</class>
12
+ </useroptin>
13
+ </helpers>
14
+ <models>
15
+ <newsletter>
16
+ <rewrite>
17
+ <subscriber>Conlabz_Useroptin_Model_Newsletter_Subscriber</subscriber>
18
+ </rewrite>
19
+ </newsletter>
20
+ <useroptin>
21
+ <class>Conlabz_Useroptin_Model</class>
22
+ </useroptin>
23
+ </models>
24
+ </global>
25
+ <frontend>
26
+ <routers>
27
+ <useroptin>
28
+ <use>standard</use>
29
+ <args>
30
+ <module>Conlabz_Useroptin</module>
31
+ <frontName>Useroptin</frontName>
32
+ </args>
33
+ </useroptin>
34
+ <newsletter>
35
+ <use>standard</use>
36
+ <args>
37
+ <modules>
38
+ <Conlabz_Useroptin before="Mage_Newsletter">Conlabz_Useroptin</Conlabz_Useroptin>
39
+ </modules>
40
+ </args>
41
+ </newsletter>
42
+ <customer>
43
+ <args>
44
+ <modules>
45
+ <Conlabz_Useroptin before="Mage_Customer">Conlabz_Useroptin</Conlabz_Useroptin>
46
+ </modules>
47
+ </args>
48
+ </customer>
49
+ </routers>
50
+ <layout>
51
+ <updates>
52
+ <useroptin>
53
+ <file>useroptin.xml</file>
54
+ </useroptin>
55
+ </updates>
56
+ </layout>
57
+ </frontend>
58
+ <adminhtml>
59
+ <translate>
60
+ <modules>
61
+ <Conlabz_Useroptin>
62
+ <files>
63
+ <default>Conlabz_CleverReach.csv</default>
64
+ </files>
65
+ </Conlabz_Useroptin>
66
+ </modules>
67
+ </translate>
68
+ </adminhtml>
69
+ </config>
app/code/local/Conlabz/Useroptin/etc/system.xml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <newsletter>
5
+ <groups>
6
+ <subscription>
7
+ <fields>
8
+ <confirm_logged_email_template translate="label">
9
+ <label>Logged user need to confirm</label>
10
+ <frontend_type>select</frontend_type>
11
+ <source_model>adminhtml/system_config_source_yesno</source_model>
12
+ <sort_order>20</sort_order>
13
+ <show_in_default>1</show_in_default>
14
+ <show_in_website>1</show_in_website>
15
+ <show_in_store>1</show_in_store>
16
+ </confirm_logged_email_template>
17
+ </fields>
18
+ </subscription>
19
+ </groups>
20
+ </newsletter>
21
+ </sections>
22
+ </config>
app/etc/modules/Conlabz_Useroptin.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Conlabz_Useroptin>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Conlabz_Useroptin>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Conlabz_Useroptin</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/gpl-license.php">GNU General Public License (GPL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Newsletter opt-in for registered users</summary>
10
+ <description>Extension will give possibility enable newsletter confirmation (opt-in) for already registered users.&#xD;
11
+ &#xD;
12
+ Die Extension unterst&#xFC;tzt die M&#xF6;glichkeit einer E-Mail Best&#xE4;tigung f&#xFC;r bereits registrierte Nutzer.</description>
13
+ <notes>Init extension version</notes>
14
+ <authors><author><name>Conlabz GmbH</name><user>conlabz</user><email>info@conlabz.de</email></author></authors>
15
+ <date>2012-10-31</date>
16
+ <time>12:35:08</time>
17
+ <contents><target name="magelocal"><dir name="Conlabz"><dir name="Useroptin"><dir><dir name="Model"><dir name="Newsletter"><file name="Subscriber.php" hash="caf374c0edd74e7790156b9e11dbeeb5"/></dir></dir><dir name="controllers"><file name="AccountController.php" hash="ce0480909da1e826004c369683f869f8"/><file name="ManageController.php" hash="5c992a56639ff73d7e11b727d7234bd7"/></dir><dir name="etc"><file name="config.xml" hash="1f8bbe36a855612700d547cbf7d0f65a"/><file name="system.xml" hash="c1b2c86ab52c60983cc2418b351b4b97"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Conlabz_Useroptin.xml" hash="3ea42c7b0f6070edce5ffc159374a8f3"/></dir></target></contents>
18
+ <compatible/>
19
+ <dependencies><required><php><min>5.2.13</min><max>5.4.7</max></php></required></dependencies>
20
+ </package>