url-apply-coupon-code-link-extension-for-magento - Version 1.0.0

Version Notes

Extension v.1.0.0 added

Download this release

Release Info

Developer MagePhobia
Extension url-apply-coupon-code-link-extension-for-magento
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/MP/AutoApplyCoupon/Helper/Data.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category MP
5
+ * @package MP_AutoApplyCoupon
6
+ * @copyright MagePhobia (http://www.magephobia.com)
7
+ */
8
+ class MP_AutoApplyCoupon_Helper_Data extends Mage_Core_Helper_Abstract
9
+ {
10
+
11
+ }
app/code/local/MP/AutoApplyCoupon/Model/Observer.php ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category MP
5
+ * @package MP_AutoApplyCoupon
6
+ * @copyright MagePhobia (http://www.magephobia.com)
7
+ */
8
+ class MP_AutoApplyCoupon_Model_Observer
9
+ {
10
+ public function controllerActionPredispatch(Varien_Event_Observer $observer)
11
+ {
12
+ $params = array_change_key_case(Mage::app()->getRequest()->getParams(), CASE_LOWER);
13
+ $cookie = Mage::getSingleton('core/cookie');
14
+
15
+ if (isset($params['quote_id'])) {
16
+ Mage::getSingleton('core/session')->setDoNotShowDiscountPopup(1);
17
+ $quote = Mage::getModel('sales/quote')->load(intval($params['quote_id']));
18
+ if (is_object($quote) && $quote->getId() && $quote->getIsActive()) {
19
+ if (Mage::getSingleton('customer/session')->isLoggedIn() && $quote->getCustomerId()) {
20
+ if ($quote->getCustomerId() != Mage::getSingleton('customer/session')->getCustomer()->getId()) {
21
+ Mage::getSingleton('customer/session')->logout();
22
+ Mage::app()->getResponse()
23
+ ->setRedirect('/customer/account/login', 301)
24
+ ->sendResponse();
25
+ } else {
26
+ Mage::getSingleton('checkout/session')->setQuoteId($quote->getId());
27
+ }
28
+ } elseif (Mage::getSingleton('customer/session')->isLoggedIn() && !$quote->getCustomerId()) {
29
+ Mage::getSingleton('checkout/session')->setQuoteId($quote->getId());
30
+ } elseif (!Mage::getSingleton('customer/session')->isLoggedIn()) {
31
+ if ($quote->getCustomerId()) {
32
+ Mage::app()->getResponse()
33
+ ->setRedirect('/customer/account/login', 301)
34
+ ->sendResponse();
35
+ } else {
36
+ Mage::getSingleton('checkout/session')->setQuoteId($quote->getId());
37
+ }
38
+ }
39
+ } else {
40
+ Mage::getSingleton('core/session')->addNotice('Sorry, looks like you\'ve got invalid Invalid Cart'
41
+ . ' ID or you have already made a purchase with the cart you are trying to access. Thank you!');
42
+ }
43
+ }
44
+
45
+ $discountEmail = '';
46
+ if (array_key_exists('discount-email', $params) !== false) {
47
+ $discountEmail = $params['discount-email'];
48
+ } elseif (array_key_exists('email', $params) !== false) {
49
+ $discountEmail = $params['email'];
50
+ } elseif (array_key_exists('utm_email', $params) !== false) {
51
+ $discountEmail = $params['utm_email'];
52
+ }
53
+ if (isset($discountEmail)) {
54
+ if ($discountEmail != '') {
55
+ if (Zend_Validate::is($discountEmail, 'EmailAddress')) {
56
+ $cookie = Mage::getSingleton('core/cookie');
57
+ if (Mage::helper('checkout/cart')->getItemsCount()) {
58
+ Mage::getSingleton('checkout/session')
59
+ ->getQuote()
60
+ ->setCustomerEmail($discountEmail)
61
+ ->save();
62
+ $cookie->delete('discount-email');
63
+ } else {
64
+ $cookie->set('discount-email', $discountEmail, time() + 86400, '/');
65
+ }
66
+ }
67
+ }
68
+ }
69
+
70
+ if (isset($params['coupon']) || (isset($params['utm_promocode']))) {
71
+
72
+ if (isset($params['coupon'])) {
73
+ $coupon = $params['coupon'];
74
+ }
75
+
76
+ if (isset($params['utm_promocode'])) {
77
+ $coupon = $params['utm_promocode'];
78
+ }
79
+
80
+ if ($coupon != '') {
81
+ if ($this->_isCouponValid($coupon)) {
82
+ if (Mage::helper('checkout/cart')->getItemsCount()) {
83
+ Mage::getSingleton('checkout/session')
84
+ ->getQuote()
85
+ ->setCouponCode($coupon)
86
+ ->save();
87
+ $cookie->delete('discount_code');
88
+ } else {
89
+ $cookie->set('discount_code', $coupon, time() + 86400, '/');
90
+ }
91
+ }
92
+ }
93
+ } else {
94
+ $this->checkoutCartAddProductComplete();
95
+ }
96
+ }
97
+
98
+ public function checkoutCartAddProductComplete()
99
+ {
100
+ $cookie = Mage::getSingleton('core/cookie');
101
+ $coupon = $cookie->get('discount_code');
102
+ if (($coupon) && ($this->_isCouponValid($coupon)) && (Mage::helper('checkout/cart')->getItemsCount())) {
103
+ Mage::getSingleton('checkout/session')->getQuote()->setCouponCode($coupon)->save();
104
+ $cookie->delete('discount_code');
105
+ }
106
+
107
+ $email = $cookie->get('discount-email');
108
+ if ($email && Zend_Validate::is($email, 'EmailAddress')) {
109
+ if (Mage::helper('checkout/cart')->getItemsCount()) {
110
+ Mage::getSingleton('checkout/session')->getQuote()->setCustomerEmail($email)->save();
111
+ $cookie->delete('discount-email');
112
+ }
113
+ }
114
+ }
115
+
116
+ protected function _isCouponValid($couponCode)
117
+ {
118
+ try {
119
+ $coupon = Mage::getModel('salesrule/coupon')->load($couponCode, 'code');
120
+ if (is_object($coupon)) {
121
+ $rule = Mage::getModel('salesrule/rule')->load($coupon->getRuleId());
122
+ if (is_object($rule)) {
123
+ $conditionsUnSerialized = unserialize($rule->getConditionsSerialized());
124
+ if ($rule->getIsActive()) {
125
+ if (is_array($conditionsUnSerialized) && (isset($conditionsUnSerialized['conditions']))
126
+ && (is_array($conditionsUnSerialized['conditions']))
127
+ ) {
128
+ foreach ($conditionsUnSerialized['conditions'] as $condition) {
129
+ if (isset($condition['attribute']) && ($condition['attribute'] == 'base_subtotal')
130
+ && (isset($condition['operator'])) && ($condition['operator'] == '>=')
131
+ && (isset($condition['value'])) && ($condition['value'] > 0)
132
+ && (Mage::getSingleton('checkout/session')
133
+ ->getQuote()->getSubtotal() < $condition['value'])
134
+ ) {
135
+ $cookie = Mage::getSingleton('core/cookie');
136
+ $cookie->set('discount_code', $couponCode, time() + 86400, '/');
137
+ return false;
138
+ }
139
+ }
140
+ }
141
+
142
+ return true;
143
+ } else {
144
+ return false;
145
+ }
146
+ } else {
147
+ return false;
148
+ }
149
+ } else {
150
+ return false;
151
+ }
152
+ } catch (Exception $e) {
153
+ return false;
154
+ }
155
+ }
156
+ }
app/code/local/MP/AutoApplyCoupon/etc/config.xml ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ * @category MP
4
+ * @package MP_AutoApplyCoupon
5
+ * @copyright MagePhobia (http://www.magephobia.com)
6
+ -->
7
+ <config>
8
+ <modules>
9
+ <MP_AutoApplyCoupon>
10
+ <version>0.1.0</version>
11
+ </MP_AutoApplyCoupon>
12
+ </modules>
13
+ <global>
14
+ <models>
15
+ <mp_autoapplycoupon>
16
+ <class>MP_AutoApplyCoupon_Model</class>
17
+ </mp_autoapplycoupon>
18
+ </models>
19
+ <helpers>
20
+ <mp_autoapplycoupon>
21
+ <class>MP_AutoApplyCoupon_Helper</class>
22
+ </mp_autoapplycoupon>
23
+ </helpers>
24
+ </global>>
25
+ <frontend>
26
+ <events>
27
+ <controller_action_predispatch>
28
+ <observers>
29
+ <mp_autoapplycoupon_observer>
30
+ <type>singleton</type>
31
+ <class>MP_AutoApplyCoupon_Model_Observer</class>
32
+ <method>controllerActionPredispatch</method>
33
+ </mp_autoapplycoupon_observer>
34
+ </observers>
35
+ </controller_action_predispatch>
36
+ <checkout_cart_add_product_complete>
37
+ <observers>
38
+ <mp_autoapplycoupon_observer>
39
+ <type>singleton</type>
40
+ <class>MP_AutoApplyCoupon_Model_Observer</class>
41
+ <method>checkoutCartAddProductComplete</method>
42
+ </mp_autoapplycoupon_observer>
43
+ </observers>
44
+ </checkout_cart_add_product_complete>
45
+ <checkout_cart_save_after>
46
+ <observers>
47
+ <mp_autoapplycoupon_observer>
48
+ <type>singleton</type>
49
+ <class>MP_AutoApplyCoupon_Model_Observer</class>
50
+ <method>checkoutCartAddProductComplete</method>
51
+ </mp_autoapplycoupon_observer>
52
+ </observers>
53
+ </checkout_cart_save_after>
54
+ </events>
55
+ </frontend>
56
+ </config>
app/etc/modules/MP_AutoApplyCoupon.xml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ * @category MP
4
+ * @package MP_AutoApplyCoupon
5
+ * @copyright MagePhobia (http://www.magephobia.com)
6
+ -->
7
+ <config>
8
+ <modules>
9
+ <MP_AutoApplyCoupon>
10
+ <active>true</active>
11
+ <codePool>local</codePool>
12
+ </MP_AutoApplyCoupon>
13
+ </modules>
14
+ </config>
package.xml ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>url-apply-coupon-code-link-extension-for-magento</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.magephobia.com/magento/extensions/magephobia-software-license">MagePhobia Software License</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Allows merchants to use links to any Magento&#xAE; page and apply coupon code on the fly to existing or future cart&#xD;
10
+ </summary>
11
+ <description>&lt;h3&gt;Magento&#xAE; 2 ready extension.&lt;/h3&gt;&lt;br /&gt;&lt;br /&gt;&#xD;
12
+ &#xD;
13
+ Magento&#xAE; merchants often struggle with email campaigns or blog posts that include coupon codes. While promotional emails is a great conversion tool native Magento&#xAE; customers need to copy the coupon code from the email, shop, add items to cart, and then apply the coupon code, which normally result in lower conversion rate. &lt;br /&gt;&lt;br /&gt;&#xD;
14
+ &#xD;
15
+ Apply Coupon Code Link extension for Magento&#xAE; empowers merchants to use links in promotional emails, blog posts, and newsletter campaigns to any Magento&#xAE; page and apply coupon code on the fly to existing or future cart (when product will be added to cart later - after visiting promo code link) without a need for a customer to manually copy, input, and apply Coupon Code on a Shopping Cart Page. The link would look like &lt;br /&gt; http://www.magento-site.com/?coupon=Coupon_Code &lt;br /&gt;&lt;br /&gt;&#xD;
16
+ &#xD;
17
+ Additionally, Apply Coupon Code URL extension for Magento&#xAE; allows merchants to use links to land customers into their Abandoned Shopping Cart via Abandoned Shopping Cart emails and at the same time apply promotional coupon code via the same URL. The link would look like &lt;br /&gt; http://www.magento-site.com/?coupon=Coupon_Code&amp;amp;quote_id=Cart_Id . &lt;br /&gt;Cart_Id should be pulled from sales_flat_quote table while building a list of Abandoned cart emails by a merchant.&lt;br /&gt;&lt;br /&gt;&#xD;
18
+ &#xD;
19
+ &#xD;
20
+ &lt;span style="font-size: 18px; font-weight: 800;"&gt;Please refer to screenshots for more information.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&#xD;
21
+ &#xD;
22
+ &lt;span style="font-size: 18px; font-weight: 800;"&gt;&lt;a href="http://demo.magephobia.com/mp_auto_apply_coupon/women/tops-blouses.html?quote_id=680&amp;coupon=test"&gt;Frontend Demo&lt;/a&gt; | &lt;a href="http://demo.magephobia.com/mp_auto_apply_coupon/index.php/admin/"&gt;Backend Demo&lt;/a&gt; (Username/Password is presented on admin login screen).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Please note that front end demo has a link http://demo.magephobia.com/mp_auto_apply_coupon/women/tops-blouses.html?quote_id=680&amp;coupon=test representing GET parameters Cart Id 680 and Coupon Code 'Test' , it lands Magento&#xAE; customer to his cart and applies Coupon Code 'Test' during landing. &lt;br /&gt; Cart Id is optional, Coupon Code URL link will work without it. &lt;br /&gt;This feature dramatically increase conversion rate.&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&#xD;
23
+ &#xD;
24
+ &lt;span style="font-size: 18px; font-weight: 800;"&gt;MagePhobia Apply Coupon Code Link extension includes free updates for 1 year + 90 days free support.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&#xD;
25
+ &#xD;
26
+ Extension is Compatible with Magento&#xAE; CE 1.5+ and Magento&#xAE; CE 2.0+&lt;br /&gt;&lt;br /&gt;&#xD;
27
+ &#xD;
28
+ &lt;span style="font-size: 18px; font-weight: 800;"&gt;Please &lt;a href="https://www.magephobia.com/customer-support"&gt;Contact Us&lt;/a&gt; if you have any questions. 90 days money back guarantee!&lt;br /&gt;&lt;/span&gt;</description>
29
+ <notes>Extension v.1.0.0 added</notes>
30
+ <authors><author><name>MagePhobia</name><user>MagePhobia</user><email>support@magephobia.com</email></author></authors>
31
+ <date>2016-01-21</date>
32
+ <time>09:14:40</time>
33
+ <contents><target name="magelocal"><dir name="MP"><dir name="AutoApplyCoupon"><dir name="Helper"><file name="Data.php" hash="84a72c8754d6f6d67dd0dba3781f3ef5"/></dir><dir name="Model"><file name="Observer.php" hash="3ee4e9e6ed499f7d6543d39b6d728289"/></dir><dir name="etc"><file name="config.xml" hash="81faaf87ab574322b5b40b57699e0071"/></dir></dir></dir></target><target name="mage"><dir name="app"><dir name="etc"><dir name="modules"><file name="MP_AutoApplyCoupon.xml" hash="e6ae26e0bbfd08dc4c82a86d3da5783d"/></dir></dir></dir></target></contents>
34
+ <compatible/>
35
+ <dependencies><required><php><min>5.2.1</min><max>5.7.1</max></php></required></dependencies>
36
+ </package>