SureGifts - Version 1.0.1

Version Notes

Initial Release

Download this release

Release Info

Developer Michael Adeyeri
Extension SureGifts
Version 1.0.1
Comparing to
See all releases


Version 1.0.1

app/code/community/SureGifts/GiftCardsIntegrator/Helper/Data.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class SureGifts_GiftCardsIntegrator_Helper_Data
3
+ extends Mage_Core_Helper_Abstract
4
+ {
5
+ }
app/code/community/SureGifts/GiftCardsIntegrator/Model/Observer.php ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Our class name should follow the directory structure of
4
+ * our Observer.php model, starting from the namespace,
5
+ * replacing directory separators with underscores.
6
+ * i.e. app/code/local/SmashingMagazine/
7
+ * LogProductUpdate/Model/Observer.php
8
+ */
9
+ class SureGifts_GiftCardsIntegrator_Model_Observer
10
+ {
11
+ /**
12
+ * Magento passes a Varien_Event_Observer object as
13
+ * the first parameter of dispatched events.
14
+ */
15
+
16
+ public function updateNotice(Varien_Event_Observer $observer){
17
+
18
+ // $this->loadLayout();
19
+ $msg = Mage::getStoreConfig('sg_section/sg_group/sg_notice',Mage::app()->getStore());
20
+
21
+ //die($mode);
22
+ if (!empty($msg )){
23
+ $message= $msg.'. <a href="http://www.suregifts.com.ng" target="_blank">Suregifts.com</a>';
24
+
25
+ }else{
26
+ $message= 'enter your <a href="http://www.suregifts.com.ng" target="_blank">Suregifts.com</a> giftcard code';
27
+ }
28
+ Mage::getSingleton('core/session')->addNotice($message);
29
+
30
+ }
31
+
32
+
33
+ public function processCoupon(Varien_Event_Observer $observer)
34
+ {
35
+
36
+ $username = Mage::getStoreConfig('sg_section/sg_group/sg_username',Mage::app()->getStore());
37
+ //$mode = Mage::getStoreConfig('sg_section/sg_group/sg_mode',Mage::app()->getStore());
38
+ $coupon_code = $_REQUEST['coupon_code'];
39
+ $remove = $_REQUEST['remove'];
40
+ if($remove == 0){
41
+ $coupon_value = $this -> validateCouponCode($coupon_code);
42
+ if ($coupon_value != 0 ){
43
+ $this -> generateRule("Suregifts giftcard",$coupon_code,$coupon_value);
44
+ // Mage::getSingleton('core/session')->getMessages(true);
45
+ }
46
+ }
47
+ else{
48
+ //Mage::getSingleton('core/session')->getMessages(true);
49
+ }
50
+
51
+
52
+
53
+ //die($observer);
54
+ }
55
+
56
+ public function validateCouponCode($the_coupon_code){
57
+ $coupon_value = 0;
58
+ $username = Mage::getStoreConfig('sg_section/sg_group/sg_username',Mage::app()->getStore());
59
+ $password = Mage::getStoreConfig('sg_section/sg_group/sg_password',Mage::app()->getStore());
60
+ $mode = Mage::getStoreConfig('sg_section/sg_group/sg_mode',Mage::app()->getStore());
61
+
62
+
63
+ $auth = $username.':'.$password;
64
+
65
+ if ($mode == 1 ){
66
+ $ch = curl_init("https://stagging.oms-suregifts.com/api/voucher/?vouchercode=".$the_coupon_code);
67
+ }else{
68
+ $ch = curl_init("https://oms-suregifts.com/api/voucher/?vouchercode=".$the_coupon_code);
69
+ }
70
+
71
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
72
+ curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
73
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
74
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
75
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
76
+ "Authorization: Basic ".base64_encode($auth),
77
+ )
78
+ );
79
+ $response = curl_exec($ch);
80
+ $returnCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
81
+ curl_close($ch);
82
+
83
+ try {
84
+ $res = json_decode($response, true);
85
+ Mage::log($res['AmountToUse'] , null, 'mode.log');
86
+ if ($res['AmountToUse'] != 0){
87
+
88
+ $data = array(
89
+ "AmountToUse" => $res['AmountToUse'] ,
90
+ //"AmountToUse" => 2000,
91
+ "VoucherCode" => $the_coupon_code,
92
+ "WebsiteHost" => ""
93
+ );
94
+
95
+ $data_string = json_encode($data);
96
+
97
+ if ($mode == 1 ){
98
+ $ch = curl_init('https://stagging.oms-suregifts.com/api/voucher');
99
+ }else{
100
+ $ch = curl_init('https://oms-suregifts.com/api/voucher');
101
+ }
102
+
103
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
104
+ curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
105
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
106
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
107
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
108
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
109
+ 'Content-Type: application/json',
110
+ //,
111
+ 'Content-Length: ' . strlen($data_string),
112
+ "Authorization: Basic ".base64_encode($auth),
113
+ )
114
+ );
115
+ $result = curl_exec($ch);
116
+ $coupon_res = json_decode($result, true);
117
+
118
+ $coupon_res_code = $coupon_res['Response'];
119
+
120
+ Mage::log($coupon_res, null, 'salesrule.log');
121
+ if ($coupon_res_code == "00"){
122
+ $coupon_value = $res['AmountToUse'] ;
123
+ //$coupon_value = 2000 ;
124
+ return $coupon_value;
125
+ } else {
126
+ $coupon_value = 0;
127
+ return $coupon_value; }
128
+ }
129
+
130
+ else {
131
+ $coupon_value = 0;
132
+ return $coupon_value; }
133
+ }
134
+ catch (Exception $e) {
135
+ Mage::log($e->getMessage());
136
+ }
137
+ }
138
+
139
+ public function generateRule($name = null, $coupon_code = null, $discount = 0)
140
+ {
141
+ if ($name != null && $coupon_code != null)
142
+ {
143
+ $rule = Mage::getModel('salesrule/rule');
144
+ $customer_groups = array(0, 1, 2, 3);
145
+ $rule->setName($name)
146
+ ->setDescription($name)
147
+ ->setFromDate('')
148
+ ->setCouponType(2)
149
+ ->setCouponCode($coupon_code)
150
+ ->setUsesPerCustomer(1)
151
+ ->setUsesPerCoupon(1)
152
+ ->setCustomerGroupIds($customer_groups) //an array of customer grou pids
153
+ ->setIsActive(1)
154
+ ->setConditionsSerialized('')
155
+ ->setActionsSerialized('')
156
+ ->setStopRulesProcessing(0)
157
+ ->setIsAdvanced(1)
158
+ ->setProductIds('')
159
+ ->setSortOrder(0)
160
+ ->setSimpleAction('cart_fixed')
161
+ ->setDiscountAmount($discount)
162
+ ->setDiscountQty(null)
163
+ ->setDiscountStep(0)
164
+ ->setSimpleFreeShipping('0')
165
+ ->setApplyToShipping('0')
166
+ ->setIsRss(0)
167
+ ->setWebsiteIds(array(1));
168
+
169
+ /* $item_found = Mage::getModel('salesrule/rule_condition_product_found')
170
+ ->setType('salesrule/rule_condition_product_found')
171
+ ->setValue(1) // 1 == FOUND
172
+ ->setAggregator('all'); // match ALL conditions
173
+ $rule->getConditions()->addCondition($item_found);
174
+ $conditions = Mage::getModel('salesrule/rule_condition_product')
175
+ ->setType('salesrule/rule_condition_product')
176
+ ->setAttribute('')
177
+ ->setOperator('==')
178
+ ->setValue($sku);
179
+ $item_found->addCondition($conditions);*/
180
+
181
+ /* $actions = Mage::getModel('salesrule/rule_condition_product')
182
+ ->setType('salesrule/rule_condition_product')
183
+ ->setAttribute('')
184
+ ->setOperator('==')
185
+ ->setValue($sku);
186
+ $rule->getActions()->addCondition($actions);*/
187
+
188
+ try {
189
+ $rule->save();
190
+ } catch (Exception $e) {
191
+ Mage::log($e->getMessage());
192
+ }
193
+ }
194
+ }
195
+ }
app/code/community/SureGifts/GiftCardsIntegrator/etc/adminhtml.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <acl>
4
+ <resources>
5
+ <admin>
6
+ <children>
7
+ <system>
8
+ <children>
9
+ <config>
10
+ <children>
11
+ <sg_section translate="title" module="suregifts_giftcardsintegrator">
12
+ <title>Options</title>
13
+ <sort_order>100</sort_order>
14
+ </sg_section>
15
+ </children>
16
+ </config>
17
+ </children>
18
+ </system>
19
+ </children>
20
+ </admin>
21
+ </resources>
22
+ </acl>
23
+ </config>
app/code/community/SureGifts/GiftCardsIntegrator/etc/config.xml ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+
3
+ <!-- The root node for Magento module configuration -->
4
+ <config>
5
+
6
+ <!--
7
+ The module's node contains basic
8
+ information about each Magento module
9
+ -->
10
+ <modules>
11
+
12
+ <!--
13
+ This must exactly match the namespace and module's folder
14
+ names, with directory separators replaced by underscores
15
+ -->
16
+ <SureGifts_GiftCardsIntegrator>
17
+
18
+ <!-- The version of our module, starting at 0.0.1 -->
19
+ <version>1.0.0.1</version>
20
+
21
+ </SureGifts_GiftCardsIntegrator>
22
+
23
+ </modules>
24
+
25
+
26
+
27
+ <!-- Configure our module's behavior in the global scope -->
28
+ <global>
29
+
30
+
31
+
32
+
33
+ <!-- Defining models -->
34
+ <models>
35
+
36
+ <!--
37
+ Unique identifier in the model's node.
38
+ By convention, we put the module's name in lowercase.
39
+ -->
40
+ <suregifts_giftcardsintegrator>
41
+
42
+ <!--
43
+ The path to our models directory, with directory
44
+ separators replaced by underscores
45
+ -->
46
+ <class>SureGifts_GiftCardsIntegrator_Model</class>
47
+
48
+
49
+ </suregifts_giftcardsintegrator>
50
+
51
+ </models>
52
+
53
+ <helpers>
54
+ <suregifts_giftcardsintegrator>
55
+ <class>SureGifts_GiftCardsIntegrator_Helper</class>
56
+ </suregifts_giftcardsintegrator>
57
+ </helpers>
58
+
59
+ <!-- Defining an event observer -->
60
+ <events>
61
+
62
+ <!-- The code of the event we want to observe -->
63
+ <controller_action_predispatch_checkout_cart_couponPost>
64
+
65
+ <!-- Defining an observer for this event -->
66
+ <observers>
67
+
68
+ <!--
69
+ Unique identifier within the
70
+ catalog_product_save_after node.
71
+ By convention, we write the module's
72
+ name in lowercase.
73
+ -->
74
+ <suregifts_giftcardsintegrator>
75
+
76
+ <!-- The model to be instantiated -->
77
+ <class>suregifts_giftcardsintegrator/observer</class>
78
+
79
+ <!-- The method of the class to be called -->
80
+ <method>processCoupon</method>
81
+
82
+ <!-- The type of class to instantiate -->
83
+ <type>singleton</type>
84
+
85
+ </suregifts_giftcardsintegrator>
86
+
87
+ </observers>
88
+
89
+ </controller_action_predispatch_checkout_cart_couponPost>
90
+
91
+ <controller_action_predispatch_checkout_cart_index>
92
+ <observers>
93
+ <suregifts_giftcardsintegrator>
94
+ <class>suregifts_giftcardsintegrator/observer</class>
95
+ <method>updateNotice</method>
96
+ <type>singleton</type>
97
+ </suregifts_giftcardsintegrator>
98
+ </observers>
99
+ </controller_action_predispatch_checkout_cart_index>
100
+
101
+
102
+
103
+ </events>
104
+
105
+ </global>
106
+
107
+
108
+ <default>
109
+ <sg_section>
110
+ <sg_group>
111
+ <sg_mode>0</sg_mode>
112
+ </sg_group>
113
+ </sg_section>
114
+ </default>
115
+
116
+
117
+ </config>
app/code/community/SureGifts/GiftCardsIntegrator/etc/system.xml ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <config>
3
+ <tabs>
4
+ <sg_tab module="suregifts_giftcardsintegrator" translate="label">
5
+ <label>Suregifts Checkout</label>
6
+ <sort_order>100</sort_order>
7
+ </sg_tab>
8
+ </tabs>
9
+ <sections>
10
+ <sg_section module="suregifts_giftcardsintegrator" translate="label">
11
+ <label>Options</label>
12
+ <sort_order>200</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
+ <tab>sg_tab</tab>
17
+ <groups>
18
+ <sg_group translate="label">
19
+ <label>Suregifts Coupon Integrator Details</label>
20
+ <comment>Enter the merchant username and password provided to you by SUREGIFTS</comment>
21
+ <sort_order>10</sort_order>
22
+ <show_in_default>1</show_in_default>
23
+ <show_in_website>1</show_in_website>
24
+ <show_in_store>1</show_in_store>
25
+ <fields>
26
+ <sg_username translate="label">
27
+ <label>Username: </label>
28
+ <comment>Enter the merchant username</comment>
29
+ <frontend_type>text</frontend_type>
30
+ <sort_order>20</sort_order>
31
+ <show_in_default>1</show_in_default>
32
+ <show_in_website>1</show_in_website>
33
+ <show_in_store>1</show_in_store>
34
+ </sg_username>
35
+ <sg_password translate="label">
36
+ <label>Password: </label>
37
+ <comment>Enter the merchant password</comment>
38
+ <frontend_type>text</frontend_type>
39
+ <sort_order>30</sort_order>
40
+ <show_in_default>1</show_in_default>
41
+ <show_in_website>1</show_in_website>
42
+ <show_in_store>1</show_in_store>
43
+ </sg_password>
44
+ <sg_notice translate="label">
45
+ <label>Message: </label>
46
+ <comment>Enter the store notice</comment>
47
+ <frontend_type>text</frontend_type>
48
+ <sort_order>40</sort_order>
49
+ <show_in_default>1</show_in_default>
50
+ <show_in_website>1</show_in_website>
51
+ <show_in_store>1</show_in_store>
52
+ </sg_notice>
53
+
54
+ <sg_mode translate="label">
55
+ <label>Test Mode </label>
56
+ <comment>selct 'No' to authenticate with live server</comment>
57
+ <frontend_type>select</frontend_type>
58
+ <sort_order>50</sort_order>
59
+ <show_in_default>1</show_in_default>
60
+ <show_in_website>1</show_in_website>
61
+ <show_in_store>1</show_in_store>
62
+ <source_model>adminhtml/system_config_source_yesno</source_model>
63
+ </sg_mode>
64
+ </fields>
65
+ </sg_group>
66
+
67
+ </groups>
68
+ </sg_section>
69
+ </sections>
70
+ </config>
app/code/community/SureGifts/desktop.ini ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ [ViewState]
2
+ Mode=
3
+ Vid=
4
+ FolderType=Generic
app/etc/modules/SureGifts_GiftCardsIntegrator.xml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <SureGifts_GiftCardsIntegrator>
5
+
6
+ <!-- Whether our module is active: true or false -->
7
+ <active>true</active>
8
+
9
+ <!-- Which code pool to use: core, community or local -->
10
+ <codePool>community</codePool>
11
+
12
+ </SureGifts_GiftCardsIntegrator>
13
+ </modules>
14
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>SureGifts</name>
4
+ <version>1.0.1</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License v. 3.0 (OSL-3.0)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Integrates SureGifts gift card codes with your store&#x2019;s coupon/discount field on cart/checkout page</summary>
10
+ <description>Integrates SureGifts gift card codes with your store&#x2019;s coupon/discount field on cart/checkout page</description>
11
+ <notes>Initial Release</notes>
12
+ <authors><author><name>Michael Adeyeri</name><user>michael_adeyeri</user><email>adeyerimichael@gmail.com</email></author></authors>
13
+ <date>2014-07-30</date>
14
+ <time>21:14:03</time>
15
+ <contents><target name="magecommunity"><dir name="SureGifts"><dir name="GiftCardsIntegrator"><dir name="Helper"><file name="Data.php" hash="7e85a45db5bd44ef823f61c3fe9bca90"/></dir><dir name="Model"><file name="Observer.php" hash="3f34232e5830ed07dacfe6d70aa60b50"/></dir><dir name="etc"><file name="adminhtml.xml" hash="bbed614a560feaffdcfad1046a5ca6ec"/><file name="config.xml" hash="273cd3238c38a32478e0e1199917d565"/><file name="system.xml" hash="1ca69683b257bcd2c598d26c8e6a0ed2"/></dir></dir><file name="desktop.ini" hash="15478b340a8362bb79fd2a6ea0dde1a0"/></dir></target><target name="mageetc"><dir name="modules"><file name="SureGifts_GiftCardsIntegrator.xml" hash="fb003392d5b16d17798ef75cefcc0019"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>