Devsters_Gift_Cards - Version 0.2.1

Version Notes

Sell Gift cards as a product and use as a payment type

With this Version: While in processing state now you can just press the submit comment button (with or without a comment) and it will create the Gift Card number and also send an email directly to the client with the card number. Included in the package is a SQL which you can run to create this email template. If you plan to create this transactional email by yourself MAKE SURE it is called "Order Update with Gift Card Number ". AND include the following line for the Gift card number to Show:
Your Gift Card Number is: {{var devstersGiftCardNumber}}

These 2 things are mandatory for this functionality to work.

NOTE: Not yet tested on v1.8.

Thanks and have a great day, hope this free extension helps you further with this add on functionality.
Devsters.

Download this release

Release Info

Developer Magento Core Team
Extension Devsters_Gift_Cards
Version 0.2.1
Comparing to
See all releases


Code changes from version 0.2.0 to 0.2.1

Files changed (40) hide show
  1. app/code/local/Devsters/Gift/Block/Adminhtml/Giftcards.php +13 -0
  2. app/code/local/Devsters/Gift/Block/Adminhtml/Giftcards/Edit.php +70 -0
  3. app/code/local/Devsters/Gift/Block/Adminhtml/Giftcards/Grid.php +73 -0
  4. app/code/local/Devsters/Gift/Block/Adminhtml/Renderer/Balance.php +13 -0
  5. app/code/local/Devsters/Gift/Helper/Data.php +6 -0
  6. app/code/local/Devsters/Gift/Model/CatalogIndex/Data/Cards.php +9 -0
  7. app/code/local/Devsters/Gift/Model/Gift.php +10 -0
  8. app/code/local/Devsters/Gift/Model/Mysql4/Gift.php +9 -0
  9. app/code/local/Devsters/Gift/Model/Mysql4/Gift/Collection.php +10 -0
  10. app/code/local/Devsters/Gift/Model/Observer.php +250 -0
  11. app/code/local/Devsters/Gift/Model/Product/Price.php +6 -0
  12. app/code/local/Devsters/Gift/Model/Product/Type.php +6 -0
  13. app/code/local/Devsters/Gift/Model/Product/Type/Cards.php +19 -0
  14. app/code/local/Devsters/Gift/Model/Sales/Order.php +11 -0
  15. app/code/local/Devsters/Gift/controllers/Adminhtml/GiftcardsController.php +105 -0
  16. app/code/local/Devsters/Gift/etc/adminhtml.xml +23 -0
  17. app/code/local/Devsters/Gift/etc/config.xml +293 -0
  18. app/code/local/Devsters/Gift/sql/gift_setup/mysql4-install-0.1.0.php +35 -0
  19. app/code/local/Devsters/Gift/sql/gift_setup/mysql4-upgrade-0.1.9-0.2.php +35 -0
  20. app/code/local/Devsters/Pay/Adminhtml/Block/Sales/Order/Creditmemo/Totals.php +27 -0
  21. app/code/local/Devsters/Pay/Adminhtml/Block/Sales/Order/Invoice/Totals.php +26 -0
  22. app/code/local/Devsters/Pay/Adminhtml/Block/Sales/Order/Totals.php +27 -0
  23. app/code/local/Devsters/Pay/Block/Form/Pay.php +9 -0
  24. app/code/local/Devsters/Pay/Block/Info/Pay.php +18 -0
  25. app/code/local/Devsters/Pay/Helper/Data.php +6 -0
  26. app/code/local/Devsters/Pay/Model/Method/Pay.php +145 -0
  27. app/code/local/Devsters/Pay/Model/Observer.php +46 -0
  28. app/code/local/Devsters/Pay/Model/Order/Creditmemo.php +21 -0
  29. app/code/local/Devsters/Pay/Model/Order/Invoice.php +17 -0
  30. app/code/local/Devsters/Pay/Model/Quote/Discount.php +74 -0
  31. app/code/local/Devsters/Pay/etc/config.xml +152 -0
  32. app/code/local/Devsters/Pay/etc/system.xml +52 -0
  33. app/code/local/Devsters/Pay/sql/pay_setup/mysql4-install-0.1.0.php +27 -0
  34. app/code/local/Devsters/Pay/sql/pay_setup/mysql4-upgrade-0.1.5-0.1.6.php +27 -0
  35. app/design/adminhtml/default/default/layout/devstersgiftcards.xml +11 -0
  36. app/design/adminhtml/default/default/template/devsters/giftcards/devsterscardbalance.phtml +13 -0
  37. app/design/frontend/default/default/template/devsters/pay/form/pay.phtml +18 -0
  38. app/etc/modules/Devsters_Gift.xml +15 -0
  39. app/etc/modules/Devsters_Pay.xml +15 -0
  40. package.xml +4 -4
app/code/local/Devsters/Gift/Block/Adminhtml/Giftcards.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Devsters_Gift_Block_Adminhtml_Giftcards extends Mage_Adminhtml_Block_Widget_Grid_Container
3
+ {
4
+ public function __construct()
5
+ {
6
+
7
+ $this->_controller = 'adminhtml_giftcards';
8
+ $this->_blockGroup = 'gift';
9
+ $this->_headerText = Mage::helper('gift')->__('Manage Gift Cards');
10
+ parent::__construct();
11
+ $this->removeButton('add');
12
+ }
13
+ }
app/code/local/Devsters/Gift/Block/Adminhtml/Giftcards/Edit.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Devsters_Gift_Block_Adminhtml_Giftcards_Edit extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+ protected $_addButtonLabel = 'Add New Gift Card';
6
+
7
+ public function __construct()
8
+ {
9
+ parent::__construct();
10
+ $this->setId('giftGrid');
11
+ $this->setDefaultSort('gift_card_id');
12
+ $this->setDefaultDir('DESC');
13
+ $this->setSaveParametersInSession(true);
14
+ }
15
+
16
+ protected function _prepareCollection()
17
+ {
18
+ $collection = Mage::getModel('gift/gift')->getCollection();
19
+ $this->setCollection($collection);
20
+ return parent::_prepareCollection();
21
+ }
22
+
23
+ protected function _prepareColumns()
24
+ {
25
+ $this->addColumn('gift_card_id', array(
26
+ 'header' => Mage::helper('gift')->__('ID'),
27
+ 'align' =>'right',
28
+ 'index' => 'gift_card_id',
29
+ ));
30
+
31
+ $this->addColumn('gift_card_number', array(
32
+ 'header' => Mage::helper('gift')->__('Gift Card Number'),
33
+ 'align' =>'left',
34
+ 'index' => 'gift_card_number',
35
+ ));
36
+
37
+ $this->addColumn('gift_card_value', array(
38
+ 'header' => Mage::helper('gift')->__('Gift Card Value'),
39
+ 'align' =>'left',
40
+ 'index' => 'gift_card_value',
41
+ ));
42
+
43
+ $this->addColumn('gift_card_balance', array(
44
+ 'header' => Mage::helper('gift')->__('Gift Card Balance'),
45
+ 'align' =>'left',
46
+ 'renderer' => render($this),
47
+ 'index' => 'gift_card_balance',
48
+ ));
49
+
50
+ $this->addColumn('order_increment_id', array(
51
+ 'header' => Mage::helper('gift')->__('Order ID'),
52
+ 'align' =>'left',
53
+ 'index' => 'order_increment_id',
54
+ ));
55
+
56
+
57
+ return parent::_prepareColumns();
58
+ }
59
+
60
+ public function render(Varien_Object $row)
61
+ {
62
+ $html = Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Input::render($row);
63
+
64
+ $html .= '<button onclick="updateField(this, '. $row->getId() .'); return false">' . Mage::helper('modulename')->__('Update') . '</button>';
65
+
66
+ return $html;
67
+ }
68
+
69
+
70
+ }
app/code/local/Devsters/Gift/Block/Adminhtml/Giftcards/Grid.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Devsters_Gift_Block_Adminhtml_Giftcards_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('giftGrid');
9
+ $this->setDefaultSort('gift_card_id');
10
+ $this->setDefaultDir('DESC');
11
+ $this->setSaveParametersInSession(true);
12
+ }
13
+
14
+ protected function _prepareCollection()
15
+ {
16
+ $collection = Mage::getModel('gift/gift')->getCollection();
17
+ $this->setCollection($collection);
18
+ return parent::_prepareCollection();
19
+ }
20
+
21
+ protected function _prepareColumns()
22
+ {
23
+ $this->addColumn('gift_card_id', array(
24
+ 'header' => Mage::helper('gift')->__('ID'),
25
+ 'align' =>'right',
26
+ 'index' => 'gift_card_id',
27
+ ));
28
+
29
+ $this->addColumn('gift_card_number', array(
30
+ 'header' => Mage::helper('gift')->__('Gift Card Number'),
31
+ 'align' =>'left',
32
+ 'index' => 'gift_card_number',
33
+ ));
34
+
35
+ $this->addColumn('gift_card_value', array(
36
+ 'header' => Mage::helper('gift')->__('Gift Card Value'),
37
+ 'align' =>'left',
38
+ 'index' => 'gift_card_value',
39
+ ));
40
+
41
+ $this->addColumn('gift_card_balance', array(
42
+ 'header' => Mage::helper('gift')->__('Gift Card Balance'),
43
+ 'align' =>'left',
44
+ 'index' => 'gift_card_balance',
45
+ 'renderer' => new Devsters_Gift_Block_Adminhtml_Renderer_Balance(),
46
+ ));
47
+
48
+ $this->addColumn('order_increment_id', array(
49
+ 'header' => Mage::helper('gift')->__('Order ID'),
50
+ 'align' =>'left',
51
+ 'index' => 'order_increment_id',
52
+ ));
53
+ $this->addExportType('*/*/exportCsv', Mage::helper('gift')->__('CSV'));
54
+ $this->addExportType('*/*/exportXml', Mage::helper('gift')->__('XML'));
55
+
56
+ return parent::_prepareColumns();
57
+ }
58
+
59
+ protected function _prepareMassaction()
60
+ {
61
+ $this->setMassactionIdField('gift_card_id');
62
+ $this->getMassactionBlock()->setFormFieldName('gift');
63
+
64
+ $this->getMassactionBlock()->addItem('delete', array(
65
+ 'label' => Mage::helper('gift')->__('Delete'),
66
+ 'url' => $this->getUrl('*/*/massDelete'),
67
+ 'confirm' => Mage::helper('gift')->__('Are you sure?')
68
+ ));
69
+
70
+ return $this;
71
+ }
72
+
73
+ }
app/code/local/Devsters/Gift/Block/Adminhtml/Renderer/Balance.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Devsters_Gift_Block_Adminhtml_Renderer_Balance extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Input
4
+ {
5
+
6
+ public function render(Varien_Object $row)
7
+ {
8
+ $html = parent::render($row);
9
+ $html .= ' <button onclick="updateBalance(this, '. $row->getId() .'); return false;">' . Mage::helper('gift')->__('Update Balance') . '</button>';
10
+ return $html;
11
+ }
12
+
13
+ }
app/code/local/Devsters/Gift/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Devsters_Gift_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ }
app/code/local/Devsters/Gift/Model/CatalogIndex/Data/Cards.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Devsters_Gift_Model_CatalogIndex_Data_Cards extends Mage_CatalogIndex_Model_Data_Abstract
4
+ {
5
+ public function getTypeCode()
6
+ {
7
+ return Devsters_Gift_Model_Product_Type::TYPE_GIFT_PRODUCT;
8
+ }
9
+ }
app/code/local/Devsters/Gift/Model/Gift.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Devsters_Gift_Model_Gift extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('gift/gift'); // this is location of the resource file.
9
+ }
10
+ }
app/code/local/Devsters/Gift/Model/Mysql4/Gift.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Devsters_Gift_Model_Mysql4_Gift extends Mage_Core_Model_Mysql4_Abstract
3
+ {
4
+ public function _construct()
5
+ {
6
+ $this->_init('gift/gift', 'gift_card_id');
7
+
8
+ }
9
+ }
app/code/local/Devsters/Gift/Model/Mysql4/Gift/Collection.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Devsters_Gift_Model_Mysql4_Gift_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('gift/gift');
9
+ }
10
+ }
app/code/local/Devsters/Gift/Model/Observer.php ADDED
@@ -0,0 +1,250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Devsters_Gift_Model_Observer
4
+ {
5
+
6
+
7
+ function createCouponCode() {
8
+ $chars = "ABCDEFGHIJKLMNPQRSTUVWXYZ123456789";
9
+ srand((double)microtime()*1000000);
10
+ $i = 0;
11
+ $code = '' ;
12
+ while ($i <= 8)
13
+ {
14
+ $num = rand() % 33;
15
+ $tmp = substr($chars, $num, 1);
16
+ $code = $code . $tmp;
17
+ $i++;
18
+ }
19
+
20
+ return $code;
21
+ }
22
+
23
+ public function hookIntoCatalogProductNewAction($observer)
24
+ {
25
+ $product = $observer->getEvent()->getProduct();
26
+ //echo'Inside hookIntoCatalogProductNewAction observer...'; exit;
27
+ //Implement the "catalog_product_new_action" hook
28
+ return $this;
29
+ }
30
+
31
+ public function hookIntoCatalogProductEditAction($observer)
32
+ {
33
+ $product = $observer->getEvent()->getProduct();
34
+ //echo'Inside hookIntoCatalogProductEditAction observer...'; exit;
35
+ //Implement the "catalog_product_edit_action" hook
36
+ return $this;
37
+ }
38
+
39
+ public function hookIntoCatalogProductPrepareSave($observer)
40
+ {
41
+ $product = $observer->getEvent()->getProduct();
42
+ $event = $observer->getEvent();
43
+ //echo'Inside hookIntoCatalogProductPrepareSave observer...'; exit;
44
+ //Implement the "catalog_product_prepare_save" hook
45
+ return $this;
46
+ }
47
+
48
+ public function hookIntoSalesOrderItemSaveAfter($observer)
49
+ {
50
+ //$event = $observer->getEvent();
51
+ //echo'Inside hookIntoSalesOrderItemSaveAfter observer...'; exit;
52
+ //Implement the "sales_order_item_save_after" hook
53
+ return $this;
54
+ }
55
+
56
+ public function hookIntoSalesOrderSaveBefore($observer)
57
+ {
58
+ //$event = $observer->getEvent();
59
+ //echo'Inside hookIntoSalesOrderSaveBefore observer...'; exit;
60
+ //Implement the "sales_order_save_before" hook
61
+ return $this;
62
+ }
63
+
64
+ public function hookIntoSalesOrderSaveAfter($observer)
65
+ {
66
+ $product = $observer->getEvent()->getProduct();
67
+ $ordercomments = $observer->getEvent()->getOrder()->getComments();
68
+ $orderNumber = $observer->getEvent()->getOrder()->getIncrementId();
69
+ $order = $observer->getEvent()->getOrder();
70
+ $ordersStatus = $order->getStatus();
71
+ $orderItems = $order->getItemsCollection();
72
+
73
+ if (($ordersStatus == 'gift_card_created')||($ordersStatus == 'complete')){
74
+ return $this; //if gift_card_created gift card has been created or order is already complete hence do nothing
75
+ }
76
+
77
+
78
+ foreach ($orderItems as $item){
79
+
80
+ $product_id = $item->product_id;
81
+ $product_sku = $item->sku;
82
+ $product_name = $item->getName();
83
+ $product_price= $item->getPrice();
84
+ $product_qty = (int)$item->getQtyOrdered();
85
+ $_product = Mage::getModel('catalog/product')->load($product_id);
86
+ $product_type_id = $_product->getTypeId();
87
+ $cats = $_product->getCategoryIds();
88
+ $category_id = $cats[0]; // just grab the first id
89
+ $category = Mage::getModel('catalog/category')->load($category_id);
90
+ $category_name = $category->getName();
91
+
92
+ if($product_type_id == 'gift')
93
+ {
94
+ for ($i = 1; $i <= $product_qty; $i++) {
95
+ $giftcardnumber = $this->createCouponCode().'-'.$this->createCouponCode().'-'.$this->createCouponCode();
96
+ $model = Mage::getModel('gift/gift');
97
+ $model->setGiftCardNumber($giftcardnumber);
98
+ $model->setGiftCardValue($product_price);
99
+ $model->setGiftCardBalance($product_price);
100
+ $model->setOrderIncrementId($orderNumber);
101
+
102
+ try {
103
+
104
+ $insertId = $model->save()->getId();
105
+ $comment = 'Gift Card created with Number : '.$giftcardnumber;
106
+ $state = 'processing';
107
+ $status = 'gift_card_created';
108
+ $isCustomerNotified = false;
109
+ $order->setState($state, $status, $comment, $isCustomerNotified);
110
+ $order->save();
111
+ } catch (Exception $e){
112
+ echo $e->getMessage();
113
+ exit;
114
+ }
115
+ if ($order->getId()) {
116
+ try {
117
+ $translate = Mage::getSingleton('core/translate');
118
+ $email = Mage::getModel('core/email_template');
119
+ $collection = Mage::getResourceSingleton('core/email_template_collection');
120
+ foreach($collection as $value)
121
+ {
122
+ If ($value->getTemplateCode() == "Order Update with Gift Card Number")
123
+ $template = $value->getTemplateId();
124
+ }
125
+ Mage::log('About to Send Email : '.$template,null,'events.log');
126
+
127
+ $sender = array('name' => Mage::getStoreConfig('trans_email/ident_support/name', Mage::app()->getStore()->getId()),'email' => Mage::getStoreConfig('trans_email/ident_support/email', Mage::app()->getStore()->getId()));
128
+
129
+ Mage::log($sender,null,'events.log');
130
+
131
+ $customerName = $order->getShippingAddress()->getFirstname() . " " . $order->getShippingAddress()->getLastname();
132
+ $customerEmail = $order->getPayment()->getOrder()->getCustomerEmail();
133
+
134
+ $vars = Array( 'order' => $order,
135
+ 'devstersGiftCardNumber' => $giftcardnumber );
136
+ Mage::log('About to Pass giftcardnumber : '. $giftcardnumber,null,'events.log');
137
+
138
+ $storeId = Mage::app()->getStore()->getId();
139
+
140
+ $translate = Mage::getSingleton('core/translate');
141
+ Mage::getModel('core/email_template')->sendTransactional($template, $sender, $customerEmail, $customerName, $vars, $storeId);
142
+ $translate->setTranslateInline(true);
143
+ Mage::log('Order successfully sent',null,'events.log');
144
+ } catch (Exception $e) {
145
+ Mage::log($e->getMessage(),null,'events.log');
146
+ }
147
+ } else {
148
+ Mage::log('Order not found',null,'events.log');
149
+ }
150
+
151
+ }
152
+ }
153
+ }
154
+ //Implement the "sales_order_save_after" hook
155
+
156
+ return $this;
157
+ }
158
+
159
+ public function hookIntoCatalogProductDeleteBefore($observer)
160
+ {
161
+ $product = $observer->getEvent()->getProduct();
162
+ //echo'Inside hookIntoCatalogProductDeleteBefore observer...'; exit;
163
+ //Implement the "catalog_product_delete_before" hook
164
+ return $this;
165
+ }
166
+
167
+ public function hookIntoCatalogruleBeforeApply($observer)
168
+ {
169
+ //$event = $observer->getEvent();
170
+ //echo'Inside hookIntoCatalogruleBeforeApply observer...'; exit;
171
+ //Implement the "catalogrule_before_apply" hook
172
+ return $this;
173
+ }
174
+
175
+ public function hookIntoCatalogruleAfterApply($observer)
176
+ {
177
+ //$event = $observer->getEvent();
178
+ //echo'Inside hookIntoCatalogruleAfterApply observer...'; exit;
179
+ //Implement the "catalogrule_after_apply" hook
180
+ return $this;
181
+ }
182
+
183
+ public function hookIntoCatalogProductSaveAfter($observer)
184
+ {
185
+ $product = $observer->getEvent()->getProduct();
186
+ $event = $observer->getEvent();
187
+ //echo'Inside hookIntoCatalogProductSaveAfter observer...'; exit;
188
+ //Implement the "catalog_product_save_after" hook
189
+ return $this;
190
+ }
191
+
192
+ public function hookIntoCatalogProductStatusUpdate($observer)
193
+ {
194
+ $product = $observer->getEvent()->getProduct();
195
+ $event = $observer->getEvent();
196
+ //echo'Inside hookIntoCatalogProductStatusUpdate observer...'; exit;
197
+ //Implement the "catalog_product_status_update" hook
198
+ return $this;
199
+ }
200
+
201
+ public function hookIntoCatalogEntityAttributeSaveAfter($observer)
202
+ {
203
+ //$event = $observer->getEvent();
204
+
205
+ //Implement the "catalog_entity_attribute_save_after" hook
206
+ return $this;
207
+ }
208
+
209
+ public function hookIntoCatalogProductDeleteAfterDone($observer)
210
+ {
211
+ $product = $observer->getEvent()->getProduct();
212
+ $event = $observer->getEvent();
213
+ //echo'Inside hookIntoCatalogProductDeleteAfterDone observer...'; exit;
214
+ //Implement the "catalog_product_delete_after_done" hook
215
+ return $this;
216
+ }
217
+
218
+ public function hookIntoCustomerLogin($observer)
219
+ {
220
+ $event = $observer->getEvent();
221
+ //echo'Inside hookIntoCustomerLogin observer...'; exit;
222
+ //Implement the "customer_login" hook
223
+ return $this;
224
+ }
225
+
226
+ public function hookIntoCustomerLogout($observer)
227
+ {
228
+ $event = $observer->getEvent();
229
+ //echo'Inside hookIntoCustomerLogout observer...'; exit;
230
+ //Implement the "customer_logout" hook
231
+ return $this;
232
+ }
233
+
234
+ public function hookIntoSalesQuoteSaveAfter($observer)
235
+ {
236
+ $event = $observer->getEvent();
237
+ //echo'Inside hookIntoSalesQuoteSaveAfter observer...'; exit;
238
+ //Implement the "sales_quote_save_after" hook
239
+ return $this;
240
+ }
241
+
242
+ public function hookIntoCatalogProductCollectionLoadAfter($observer)
243
+ {
244
+ $event = $observer->getEvent();
245
+ //echo'Inside hookIntoCatalogProductCollectionLoadAfter observer...'; exit;
246
+ //Implement the "catalog_product_collection_load_after" hook
247
+ return $this;
248
+ }
249
+
250
+ }
app/code/local/Devsters/Gift/Model/Product/Price.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Devsters_Gift_Model_Product_Price extends Mage_Catalog_Model_Product_Type_Price
4
+ {
5
+
6
+ }
app/code/local/Devsters/Gift/Model/Product/Type.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Devsters_Gift_Model_Product_Type extends Mage_Catalog_Model_Product_Type_Abstract
4
+ {
5
+ const TYPE_GIFT_PRODUCT = 'gift';
6
+ }
app/code/local/Devsters/Gift/Model/Product/Type/Cards.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ *
6
+ *
7
+ * Mage_Catalog_Model_Product_Type_Abstract
8
+ *
9
+ * Mage_Catalog_Model_Product_Type_Simple
10
+ * Mage_Catalog_Model_Product_Type_Virtual
11
+ * Mage_Catalog_Model_Product_Type_Configurable
12
+ * Mage_Catalog_Model_Product_Type_Grouped
13
+ *
14
+ */
15
+
16
+ class Devsters_Gift_Model_Product_Type_Cards extends Mage_Catalog_Model_Product_Type_Abstract
17
+ {
18
+
19
+ }
app/code/local/Devsters/Gift/Model/Sales/Order.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Devsters_Gift_Sales_Model_Order extends Mage_Sales_Model_Order
4
+ {
5
+ public function getDevstersGiftNumber()
6
+ {
7
+ $order = $this->getOrder();
8
+ $devstersGiftNumber= $order->getGiftCardNumber();
9
+ return $devstersGiftNumber;
10
+ }
11
+ }
app/code/local/Devsters/Gift/controllers/Adminhtml/GiftcardsController.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Devsters_Gift_Adminhtml_GiftcardsController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+
6
+ public function indexAction() {
7
+ $this->getLayout()->createBlock('gift/adminhtml_giftcards');
8
+ $this->loadLayout();
9
+ $this->renderLayout();
10
+ }
11
+
12
+ public function exportCsvAction()
13
+ {
14
+ $fileName = 'devstersgiftcards.csv';
15
+ $content = $this->getLayout()->createBlock('gift/adminhtml_giftcards_grid')
16
+ ->getCsv();
17
+
18
+ $this->_sendUploadResponse($fileName, $content);
19
+ }
20
+
21
+ public function exportXmlAction()
22
+ {
23
+ $fileName = 'devstersgiftcards.xml';
24
+ $content = $this->getLayout()->createBlock('gift/adminhtml_giftcards_grid')
25
+ ->getXml();
26
+
27
+ $this->_sendUploadResponse($fileName, $content);
28
+ }
29
+
30
+ public function deleteAction() {
31
+ if( $this->getRequest()->getParam('id') > 0 ) {
32
+ try {
33
+ $model = Mage::getModel('gift/gift');
34
+
35
+ $model->setId($this->getRequest()->getParam('id'))
36
+ ->delete();
37
+
38
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully deleted'));
39
+ $this->_redirect('*/*/');
40
+ } catch (Exception $e) {
41
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
42
+ $this->_redirect('*/*/index', array('id' => $this->getRequest()->getParam('id')));
43
+ }
44
+ }
45
+ $this->_redirect('*/*/');
46
+ }
47
+
48
+
49
+ public function massDeleteAction() {
50
+ $giftcardIds = $this->getRequest()->getParam('gift');
51
+ if(!is_array($giftcardIds)) {
52
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
53
+ } else {
54
+ try {
55
+ foreach ($giftcardIds as $giftcardId ) {
56
+ $giftcard = Mage::getModel('gift/gift')->load($giftcardId);
57
+ $giftcard->delete();
58
+ }
59
+ Mage::getSingleton('adminhtml/session')->addSuccess(
60
+ Mage::helper('adminhtml')->__(
61
+ 'Total of %d record(s) were successfully deleted', count($giftcardIds)
62
+ )
63
+ );
64
+ } catch (Exception $e) {
65
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
66
+ }
67
+ }
68
+ $this->_redirect('*/*/index');
69
+ }
70
+
71
+ public function updateBalanceAction()
72
+ {
73
+ try {
74
+ $fieldId = (int) $this->getRequest()->getParam('id');
75
+ $giftCardBalance = $this->getRequest()->getParam('gift_card_balance');
76
+ if ($fieldId) {
77
+ $model = Mage::getModel('gift/gift')->load($fieldId);
78
+ $model->setGiftCardBalance(number_format($giftCardBalance,2));
79
+ $model->save();
80
+ $successlog = 'Balance of '.$giftCardBalance. ' was successfully Updated for gift card id: '. $fieldId;
81
+ Mage::getSingleton('adminhtml/session')->addSuccess(
82
+ Mage::helper('adminhtml')->__($successlog)
83
+ );
84
+ }
85
+ } catch (Exception $e) {
86
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
87
+ }
88
+ $this->_redirect('*/*/index');
89
+ }
90
+
91
+ protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream') {
92
+ $response = $this->getResponse();
93
+ $response->setHeader('HTTP/1.1 200 OK', '');
94
+ $response->setHeader('Pragma', 'public', true);
95
+ $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
96
+ $response->setHeader('Content-Disposition', 'attachment; filename=' . $fileName);
97
+ $response->setHeader('Last-Modified', date('r'));
98
+ $response->setHeader('Accept-Ranges', 'bytes');
99
+ $response->setHeader('Content-Length', strlen($content));
100
+ $response->setHeader('Content-type', $contentType);
101
+ $response->setBody($content);
102
+ $response->sendResponse();
103
+ die;
104
+ }
105
+ }
app/code/local/Devsters/Gift/etc/adminhtml.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" ?>
2
+ <config>
3
+ <acl>
4
+ <resources>
5
+ <admin>
6
+ <children>
7
+ <system>
8
+ <children>
9
+ <config>
10
+ <children>
11
+ <giftcardconfig translate="title" module="gift">
12
+ <title>Gift Card Configuration</title>
13
+ <sort_order>100</sort_order>
14
+ </giftcardconfig >
15
+ </children>
16
+ </config>
17
+ </children>
18
+ </system>
19
+ </children>
20
+ </admin>
21
+ </resources>
22
+ </acl>
23
+ </config>
app/code/local/Devsters/Gift/etc/config.xml ADDED
@@ -0,0 +1,293 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <config>
4
+ <modules>
5
+ <Devsters_Gift>
6
+ <version>0.1.9</version>
7
+ </Devsters_Gift>
8
+ </modules>
9
+ <global>
10
+ <helpers>
11
+ <gift>
12
+ <class>Devsters_Gift_Helper</class>
13
+ </gift>
14
+ </helpers>
15
+ <models>
16
+ <gift>
17
+ <class>Devsters_Gift_Model</class>
18
+ <resourceModel>gift_mysql4</resourceModel>
19
+ </gift>
20
+ <gift_mysql4>
21
+ <class>Devsters_Gift_Model_Mysql4</class>
22
+ <entities>
23
+ <gift>
24
+ <table>devsters_gift_cards</table>
25
+ </gift>
26
+ </entities>
27
+ </gift_mysql4>
28
+ <gift_sales>
29
+ <rewrite>
30
+ <order>Devsters_Gift_Sales_Model_Order</order>
31
+ </rewrite>
32
+ </gift_sales>
33
+ </models>
34
+ <blocks>
35
+ <gift>
36
+ <class>Devsters_Gift_Block</class>
37
+ </gift>
38
+ </blocks>
39
+ <resources>
40
+ <gift_setup>
41
+ <setup>
42
+ <module>Devsters_Gift</module>
43
+ <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
44
+ </setup>
45
+ <connection>
46
+ <use>core_setup</use>
47
+ </connection>
48
+ </gift_setup>
49
+ <gift_write>
50
+ <connection>
51
+ <use>core_write</use>
52
+ </connection>
53
+ </gift_write>
54
+ <gift_read>
55
+ <connection>
56
+ <use>core_read</use>
57
+ </connection>
58
+ </gift_read>
59
+ </resources>
60
+
61
+ <catalog>
62
+ <product>
63
+ <type>
64
+ <gift translate="label" module="catalog">
65
+ <label>Devsters Gift Product</label>
66
+ <model>gift/product_type_cards</model>
67
+ <index_data_retreiver>gift/catalogIndex_data_cards</index_data_retreiver>
68
+ <price_model>gift/product_price</price_model>
69
+ <composite>0</composite>
70
+ </gift>
71
+ </type>
72
+ </product>
73
+ </catalog>
74
+ </global>
75
+
76
+ <admin>
77
+ <routers>
78
+ <gift>
79
+ <use>admin</use>
80
+ <args>
81
+ <module>Devsters_Gift</module>
82
+ <frontName>gift</frontName>
83
+ </args>
84
+
85
+ </gift>
86
+ </routers>
87
+ </admin>
88
+ <adminhtml>
89
+ <menu>
90
+ <gift translate="title" module="gift">
91
+ <title>Devsters</title>
92
+ <children>
93
+ <giftcards translate="title" >
94
+ <title>Manage Gift Cards</title>
95
+ <action>gift/adminhtml_giftcards</action>
96
+ <sort_order>0</sort_order>
97
+ </giftcards>
98
+ </children>
99
+ <sort_order>900</sort_order>
100
+ </gift>
101
+ </menu>
102
+ <acl>
103
+ <resources>
104
+ <all>
105
+ <title>Allow Everything</title>
106
+ </all>
107
+ <admin>
108
+ <children>
109
+ <Devsters_Gift>
110
+ <title>Giftcards Module</title>
111
+ <sort_order>10</sort_order>
112
+ </Devsters_Gift>
113
+ </children>
114
+ </admin>
115
+ </resources>
116
+ </acl>
117
+ <layout>
118
+ <updates>
119
+ <gift>
120
+ <file>devstersgiftcards.xml</file>
121
+ </gift>
122
+ </updates>
123
+ </layout>
124
+ <events>
125
+ <catalog_product_new_action>
126
+ <observers>
127
+ <gift_observer_catalog_product_new_action>
128
+ <type>singleton</type>
129
+ <class>gift/observer</class>
130
+ <method>hookIntoCatalogProductNewAction</method>
131
+ </gift_observer_catalog_product_new_action>
132
+ </observers>
133
+ </catalog_product_new_action>
134
+ <catalog_product_edit_action>
135
+ <observers>
136
+ <gift_observer_catalog_product_edit_action>
137
+ <type>singleton</type>
138
+ <class>gift/observer</class>
139
+ <method>hookIntoCatalogProductEditAction</method>
140
+ </gift_observer_catalog_product_edit_action>
141
+ </observers>
142
+ </catalog_product_edit_action>
143
+ <catalog_product_prepare_save>
144
+ <observers>
145
+ <gift_observer_catalog_product_prepare_save>
146
+ <type>singleton</type>
147
+ <class>gift/observer</class>
148
+ <method>hookIntoCatalogProductPrepareSave</method>
149
+ </gift_observer_catalog_product_prepare_save>
150
+ </observers>
151
+ </catalog_product_prepare_save>
152
+ <catalog_product_delete_before>
153
+ <observers>
154
+ <gift_observer_catalog_product_delete_before>
155
+ <type>singleton</type>
156
+ <class>gift/observer</class>
157
+ <method>hookIntoCatalogProductDeleteBefore</method>
158
+ </gift_observer_catalog_product_delete_before>
159
+ </observers>
160
+ </catalog_product_delete_before>
161
+ <catalog_product_save_after>
162
+ <observers>
163
+ <gift_observer_catalog_product_save_after>
164
+ <type>singleton</type>
165
+ <class>gift/observer</class>
166
+ <method>hookIntoCatalogProductSaveAfter</method>
167
+ </gift_observer_catalog_product_save_after>
168
+ </observers>
169
+ </catalog_product_save_after>
170
+ <catalog_product_status_update>
171
+ <observers>
172
+ <gift_observer_catalog_product_status_update>
173
+ <type>singleton</type>
174
+ <class>gift/observer</class>
175
+ <method>hookIntoCatalogProductStatusUpdate</method>
176
+ </gift_observer_catalog_product_status_update>
177
+ </observers>
178
+ </catalog_product_status_update>
179
+
180
+
181
+
182
+
183
+ <sales_order_item_save_after>
184
+ <observers>
185
+ <gift_observer_sales_order_item_save_after>
186
+ <type>singleton</type>
187
+ <class>gift/observer</class>
188
+ <method>hookIntoSalesOrderItemSaveAfter</method>
189
+ </gift_observer_sales_order_item_save_after>
190
+ </observers>
191
+ </sales_order_item_save_after>
192
+
193
+
194
+ <sales_order_save_before>
195
+ <observers>
196
+ <gift_observer_sales_order_save_before>
197
+ <type>singleton</type>
198
+ <class>gift/observer</class>
199
+ <method>hookIntoSalesOrderSaveBefore</method>
200
+ </gift_observer_sales_order_save_before>
201
+ </observers>
202
+ </sales_order_save_before>
203
+ <sales_order_save_after>
204
+ <observers>
205
+ <gift_observer_sales_order_save_after>
206
+ <type>singleton</type>
207
+ <class>gift/observer</class>
208
+ <method>hookIntoSalesOrderSaveAfter</method>
209
+ </gift_observer_sales_order_save_after>
210
+ </observers>
211
+ </sales_order_save_after>
212
+
213
+
214
+
215
+ <catalogrule_before_apply>
216
+ <observers>
217
+ <gift_observer_catalogrule_before_apply>
218
+ <type>singleton</type>
219
+ <class>gift/observer</class>
220
+ <method>hookIntoCatalogruleBeforeApply</method>
221
+ </gift_observer_catalogrule_before_apply>
222
+ </observers>
223
+ </catalogrule_before_apply>
224
+ <catalogrule_after_apply>
225
+ <observers>
226
+ <gift_observer_catalogrule_after_apply>
227
+ <type>singleton</type>
228
+ <class>gift/observer</class>
229
+ <method>hookIntoCatalogruleAfterApply</method>
230
+ </gift_observer_catalogrule_after_apply>
231
+ </observers>
232
+ </catalogrule_after_apply>
233
+ <catalog_entity_attribute_save_after>
234
+ <observers>
235
+ <gift_observer_catalog_entity_attribute_save_after>
236
+ <type>singleton</type>
237
+ <class>gift/observer</class>
238
+ <method>hookIntoCatalogEntityAttributeSaveAfter</method>
239
+ </gift_observer_catalog_entity_attribute_save_after>
240
+ </observers>
241
+ </catalog_entity_attribute_save_after>
242
+ <catalog_product_delete_after_done>
243
+ <observers>
244
+ <gift_observer_catalog_product_delete_after_done>
245
+ <type>singleton</type>
246
+ <class>gift/observer</class>
247
+ <method>hookIntoCatalogProductDeleteAfterDone</method>
248
+ </gift_observer_catalog_product_delete_after_done>
249
+ </observers>
250
+ </catalog_product_delete_after_done>
251
+
252
+ <customer_login>
253
+ <observers>
254
+ <gift_observer_customer_login>
255
+ <type>singleton</type>
256
+ <class>gift/observer</class>
257
+ <method>hookIntoCustomerLogin</method>
258
+ </gift_observer_customer_login>
259
+ </observers>
260
+ </customer_login>
261
+ <customer_logout>
262
+ <observers>
263
+ <gift_observer_customer_logout>
264
+ <type>singleton</type>
265
+ <class>gift/observer</class>
266
+ <method>hookIntoCustomerLogout</method>
267
+ </gift_observer_customer_logout>
268
+ </observers>
269
+ </customer_logout>
270
+ <sales_quote_save_after>
271
+ <observers>
272
+ <gift_observer_sales_quote_save_after>
273
+ <type>singleton</type>
274
+ <class>gift/observer</class>
275
+ <method>hookIntoSalesQuoteSaveAfter</method>
276
+ </gift_observer_sales_quote_save_after>
277
+ </observers>
278
+ </sales_quote_save_after>
279
+ <catalog_product_collection_load_after>
280
+ <observers>
281
+ <gift_observer_catalog_product_collection_load_after>
282
+ <type>singleton</type>
283
+ <class>gift/observer</class>
284
+ <method>hookIntoCatalogProductCollectionLoadAfter</method>
285
+ </gift_observer_catalog_product_collection_load_after>
286
+ </observers>
287
+ </catalog_product_collection_load_after>
288
+ </events>
289
+ </adminhtml>
290
+
291
+
292
+
293
+ </config>
app/code/local/Devsters/Gift/sql/gift_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ /* @var $installer Devsters_Gift_Mysql4_Setup */
5
+
6
+ $installer->startSetup();
7
+
8
+
9
+ $installer->run("
10
+ CREATE TABLE IF NOT EXISTS {$this->getTable('devsters_gift_cards')} (
11
+ `gift_card_id` int(11) unsigned NOT NULL auto_increment,
12
+ `gift_card_number` varchar(50) NOT NULL,
13
+ `gift_card_value` decimal(5,2) NOT NULL,
14
+ `gift_card_balance` decimal(5,2) NOT NULL,
15
+ `order_increment_id` varchar(50) NOT NULL,
16
+ PRIMARY KEY (`gift_card_id`),
17
+ UNIQUE KEY (`gift_card_number`)
18
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
19
+ ");
20
+
21
+ $fieldList = array(
22
+ 'price',
23
+ 'tax_class_id'
24
+ );
25
+
26
+ // make these attributes applicable to downloadable products
27
+ foreach ($fieldList as $field) {
28
+ $applyTo = split(',', $installer->getAttribute('catalog_product', $field, 'apply_to'));
29
+ if (!in_array('gift', $applyTo)) {
30
+ $applyTo[] = 'gift';
31
+ $installer->updateAttribute('catalog_product', $field, 'apply_to', join(',', $applyTo));
32
+ }
33
+ }
34
+
35
+ $installer->endSetup();
app/code/local/Devsters/Gift/sql/gift_setup/mysql4-upgrade-0.1.9-0.2.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+ /* @var $installer mag_core_email_template */
4
+
5
+ $installer->startSetup();
6
+ $installer->run('
7
+
8
+ CREATE TABLE IF NOT EXISTS `mag_core_email_template` (
9
+ `template_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Template Id',
10
+ `template_code` varchar(150) NOT NULL COMMENT 'Template Name',
11
+ `template_text` text NOT NULL COMMENT 'Template Content',
12
+ `template_styles` text COMMENT 'Templste Styles',
13
+ `template_type` int(10) unsigned DEFAULT NULL COMMENT 'Template Type',
14
+ `template_subject` varchar(200) NOT NULL COMMENT 'Template Subject',
15
+ `template_sender_name` varchar(200) DEFAULT NULL COMMENT 'Template Sender Name',
16
+ `template_sender_email` varchar(200) DEFAULT NULL COMMENT 'Template Sender Email',
17
+ `added_at` timestamp NULL DEFAULT NULL COMMENT 'Date of Template Creation',
18
+ `modified_at` timestamp NULL DEFAULT NULL COMMENT 'Date of Template Modification',
19
+ `orig_template_code` varchar(200) DEFAULT NULL COMMENT 'Original Template Code',
20
+ `orig_template_variables` text COMMENT 'Original Template Variables',
21
+ PRIMARY KEY (`template_id`),
22
+ UNIQUE KEY `UNQ_MAG_CORE_EMAIL_TEMPLATE_TEMPLATE_CODE` (`template_code`),
23
+ KEY `IDX_MAG_CORE_EMAIL_TEMPLATE_ADDED_AT` (`added_at`),
24
+ KEY `IDX_MAG_CORE_EMAIL_TEMPLATE_MODIFIED_AT` (`modified_at`)
25
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Email Templates' AUTO_INCREMENT=5 ;
26
+
27
+ --
28
+ -- Dumping data for table `mag_core_email_template`
29
+ --
30
+
31
+ INSERT INTO `mag_core_email_template` (`template_id`, `template_code`, `template_text`, `template_styles`, `template_type`, `template_subject`, `template_sender_name`, `template_sender_email`, `added_at`, `modified_at`, `orig_template_code`, `orig_template_variables`) VALUES
32
+ (444, 'Order Update with Gift Card Number', '<body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">\r\n<div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">\r\n<table cellspacing="0" cellpadding="0" border="0" height="100%" width="100%">\r\n<tr>\r\n <td align="center" valign="top" style="padding:20px 0 20px 0">\r\n <!-- [ header starts here] -->\r\n <table bgcolor="#FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:1px solid #E0E0E0;">\r\n <tr>\r\n <td valign="top"><a href="{{store url=""}}"><img src="{{var logo_url}}" alt="{{var logo_alt}}" style="margin-bottom:10px;" border="0"/></a></td>\r\n </tr>\r\n <!-- [ middle starts here] -->\r\n <tr>\r\n <td valign="top">\r\n <h1 style="font-size:22px; font-weight:normal; line-height:22px; margin:0 0 11px 0;">Dear {{htmlescape var=$order.getCustomerName()}},</h1>\r\n <p style="font-size:12px; line-height:16px; margin:0 0 10px 0;">\r\n Your order {{var order.increment_id}} for a Gift Card has been Completed.<br/>\r\n <strong>{{var order.getStatusLabel()}}</strong>.<br/>\r\n <strong>Your Gift Card Number is: {{var devstersGiftCardNumber}}</strong>\r\n </p>\r\n <p style="font-size:12px; line-height:16px; margin:0 0 10px 0;">You can check the status of your order by <a href="{{store url="customer/account/"}}" style="color:#1E7EC8;">logging into your account</a>.</p>\r\n <p style="font-size:12px; line-height:16px; margin:0 0 10px 0;">{{var comment}}</p>\r\n <p style="font-size:12px; line-height:16px; margin:0;">\r\n If you have any questions, please feel free to contact us at\r\n <a href="mailto:{{config path=''trans_email/ident_support/email''}}" style="color:#1E7EC8;">{{config path=''trans_email/ident_support/email''}}</a>\r\n or by phone at {{config path=''general/store_information/phone''}}.\r\n </p>\r\n </td>\r\n </tr>\r\n <tr>\r\n <td bgcolor="#EAEAEA" align="center" style="background:#EAEAEA; text-align:center;"><center><p style="font-size:12px; margin:0;">Thank you again, <strong>{{var store.getFrontendName()}}</strong></p></center>\r\n </td>\r\n\r\n </tr>\r\n </table>\r\n </td>\r\n</tr>\r\n</table>\r\n</div>\r\n</body>', 'body,td { color:"#2f2f2f"; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; }', 2, '{{var store.getFrontendName()}}: Order number {{var order.increment_id}} update', NULL, NULL, NULL, '2013-11-10 11:01:53', 'sales_email_order_comment_template', '{"store url=\\"\\"":"Store Url","var logo_url":"Email Logo Image Url","var logo_alt":"Email Logo Image Alt","htmlescape var=$order.getCustomerName()":"Customer Name","var order.increment_id":"Order Id","var order.getStatusLabel()":"Order Status","store url=\\"customer/account/\\"":"Customer Account Url","var comment":"Order Comment","var store.getFrontendName()":"Store Name"}');
33
+
34
+ ');
35
+ $installer->endSetup();
app/code/local/Devsters/Pay/Adminhtml/Block/Sales/Order/Creditmemo/Totals.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Devsters_Pay_Adminhtml_Block_Sales_Order_Creditmemo_Totals extends Mage_Sales_Model_Order_Total_Abstract
4
+ {
5
+ /**
6
+ * Initialize order totals array
7
+ *
8
+ * @return Mage_Sales_Block_Order_Totals
9
+ */
10
+ protected function _initTotals()
11
+ {
12
+ parent::_initTotals();
13
+ $order = $this->getOrder();
14
+ $amount = number_format((-$order->getGiftCardValue()),2);
15
+ if ($amount) {
16
+ $this->addTotalBefore(new Varien_Object(array(
17
+ 'code' => 'devtersgiftcard',
18
+ 'value' => $amount,
19
+ 'base_value'=> $amount,
20
+ 'label' => $this->helper('pay')->__('Devsters Gift Card Purchase'),
21
+ ), array('shipping', 'tax')));
22
+ }
23
+
24
+ return $this;
25
+ }
26
+
27
+ }
app/code/local/Devsters/Pay/Adminhtml/Block/Sales/Order/Invoice/Totals.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Devsters_Pay_Adminhtml_Block_Sales_Order_Invoice_Totals extends Mage_Adminhtml_Block_Sales_Order_Totals
4
+ {
5
+ /**
6
+ * Initialize order totals array
7
+ *
8
+ * @return Mage_Sales_Block_Order_Totals
9
+ */
10
+ protected function _initTotals()
11
+ {
12
+ parent::_initTotals();
13
+ $order = $this->getOrder();
14
+ $amount = number_format(($order->getGiftCardValue()),2);
15
+ if ($amount) {
16
+ $this->addTotalBefore(new Varien_Object(array(
17
+ 'code' => 'devtersgiftcard',
18
+ 'value' => $amount,
19
+ 'base_value'=> $amount,
20
+ 'label' => $this->helper('pay')->__('Devsters Gift Card Purchase'),
21
+ ), array('shipping', 'tax')));
22
+ }
23
+
24
+ return $this;
25
+ }
26
+ }
app/code/local/Devsters/Pay/Adminhtml/Block/Sales/Order/Totals.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Devsters_Pay_Adminhtml_Block_Sales_Order_Totals extends Mage_Adminhtml_Block_Sales_Order_Totals
4
+ {
5
+ /**
6
+ * Initialize order totals array
7
+ *
8
+ * @return Mage_Sales_Block_Order_Totals
9
+ */
10
+ protected function _initTotals()
11
+ {
12
+ parent::_initTotals();
13
+
14
+ $amount = number_format($this->getOrder()->getGiftCardValue(),2);
15
+ if ($amount) {
16
+ $this->addTotalBefore(new Varien_Object(array(
17
+ 'code' => 'devstersgiftcard',
18
+ 'value' => $amount,
19
+ 'base_value'=> $amount,
20
+ 'label' => $this->helper('pay')->__('Devsters Gift Card Purchase'),
21
+ ), array('shipping', 'tax')));
22
+ }
23
+
24
+ return $this;
25
+ }
26
+
27
+ }
app/code/local/Devsters/Pay/Block/Form/Pay.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Devsters_Pay_Block_Form_Pay extends Mage_Payment_Block_Form
3
+ {
4
+ protected function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->setTemplate('devsters/pay/form/pay.phtml');
8
+ }
9
+ }
app/code/local/Devsters/Pay/Block/Info/Pay.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Devsters_Pay_Block_Info_Pay extends Mage_Payment_Block_Info
3
+ {
4
+ protected function _prepareSpecificInformation($transport = null)
5
+ {
6
+ if (null !== $this->_paymentSpecificInformation) {
7
+ return $this->_paymentSpecificInformation;
8
+ }
9
+ $info = $this->getInfo();
10
+ $transport = new Varien_Object();
11
+ $transport = parent::_prepareSpecificInformation($transport);
12
+ $transport->addData(array(
13
+ Mage::helper('payment')->__('Gift Card No#') => $info->getGiftCardNo(),
14
+ Mage::helper('payment')->__('Gift Card Value') => $info->getGiftCardValue(),
15
+ ));
16
+ return $transport;
17
+ }
18
+ }
app/code/local/Devsters/Pay/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Devsters_Pay_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ }
app/code/local/Devsters/Pay/Model/Method/Pay.php ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Devsters_Pay_Model_Method_Pay extends Mage_Payment_Model_Method_Abstract
3
+ {
4
+ const PAYMENT_METHOD_DEVSTERSGIFTCARD_CODE = 'devstersgiftcard';
5
+
6
+ /**
7
+ * Payment method code
8
+ *
9
+ * @var string
10
+ */
11
+ protected $_code = self::PAYMENT_METHOD_DEVSTERSGIFTCARD_CODE;
12
+ protected $_formBlockType = 'pay/form_pay';
13
+ protected $_infoBlockType = 'pay/info_pay';
14
+
15
+
16
+ public function assignData($data)
17
+ {
18
+ if (!($data instanceof Varien_Object)) {
19
+ $data = new Varien_Object($data);
20
+ }
21
+ $info = $this->getInfoInstance();
22
+ $info->setGiftCardNo($data->getGiftCardNo());
23
+ return $this;
24
+ }
25
+
26
+
27
+ public function assignGiftCardValueToQuote($gcNumber)
28
+ {
29
+
30
+ $errorMsg = 'Success!!';
31
+
32
+ try {
33
+ $dbRead= Mage::getSingleton('core/resource')->getConnection('core_read');
34
+ $gcSQL= "SELECT gift_card_number,gift_card_balance FROM ".Mage::getConfig()->getTablePrefix()."devsters_gift_cards WHERE gift_card_number = '".$gcNumber."'";
35
+ $qryResult=$dbRead->query($gcSQL);
36
+ $giftCard= $qryResult->fetchAll();
37
+ } catch (Exception $e){
38
+ Mage::throwException($e->getMessage());
39
+ exit;
40
+ }
41
+ if(empty($giftCard[0])){
42
+ $errorCode = 'invalid_data';
43
+ $errorMsg = $this->_getHelper()->__('Gift Card Number does not exist: '.$gcNumber);
44
+ }else {
45
+ $info = $this->getInfoInstance();
46
+ $info->setGiftCardValue(number_format(($giftCard[0]['gift_card_balance']),2));
47
+ $info->setGiftCardNo($gcNumber);
48
+ $quote = $info->getQuote();
49
+ if ($quote){
50
+ $info->getQuote()->setGiftCardValue(number_format(($giftCard[0]['gift_card_balance']),2));
51
+ $info->getQuote()->setGiftCardNo($gcNumber);
52
+ $info->getQuote()->save();
53
+ }
54
+ }
55
+
56
+ if($errorMsg!='Success!!'){
57
+ Mage::throwException($errorMsg);
58
+ }
59
+ return $this;
60
+ }
61
+
62
+ public function assignGiftCardValueToOrder($gcNumber)
63
+ {
64
+
65
+ $errorMsg = 'Success!!';
66
+
67
+ try {
68
+ $dbRead= Mage::getSingleton('core/resource')->getConnection('core_read');
69
+ $gcSQL= "SELECT gift_card_number,gift_card_balance FROM ".Mage::getConfig()->getTablePrefix()."devsters_gift_cards WHERE gift_card_number = '".$gcNumber."'";
70
+ $qryResult=$dbRead->query($gcSQL);
71
+ $giftCard= $qryResult->fetchAll();
72
+ } catch (Exception $e){
73
+ Mage::throwException($e->getMessage());
74
+ exit;
75
+ }
76
+ if(empty($giftCard[0])){
77
+ $errorCode = 'invalid_data';
78
+ $errorMsg = $this->_getHelper()->__('Gift Card Number does not exist: '.$gcNumber);
79
+ }else {
80
+ $order = Mage::getSingleton('sales/order');
81
+ $order->save();
82
+ }
83
+
84
+ if($errorMsg!='Success!!'){
85
+ Mage::throwException($errorMsg);
86
+ }
87
+ return $this;
88
+ }
89
+
90
+ public function validate()
91
+ {
92
+ parent::validate();
93
+ $errorMsg = 'Success!!';
94
+ $info = $this->getInfoInstance();
95
+ $quote = $info->getQuote();
96
+ $no = $info->getGiftCardNo();
97
+ if(empty($quote)){
98
+ $quoteAfter = Mage::getSingleton('checkout/session')->getQuote()->getPayment();
99
+ $no = $quoteAfter->getGiftCardNo();
100
+ $this->assignGiftCardValueToOrder($no);
101
+ $gcValue = $quoteAfter->getGiftCardValue();
102
+ $value = Mage::getSingleton('checkout/session')->getQuote()->getGrandTotal();
103
+ }else if ($quote){
104
+ $this->assignGiftCardValueToQuote($no);
105
+ $gcValue = $quote->getGiftCardValue();
106
+ $value = $quote->getGrandTotal();
107
+ }
108
+ if(empty($no)||empty ($gcValue)){
109
+ $errorCode = 'invalid_data';
110
+ $errorMsg = $this->_getHelper()->__('Gift Card Number is a required field');
111
+ } else {
112
+ if ($gcValue < $value)
113
+ {
114
+ $errorCode = 'invalid_data';
115
+ $errorMsg = $this->_getHelper()->__('Gift Card funds: '.$gcValue. ' have been applied, You will need an additional mode of payment to cover for the remaining cost.');
116
+ }else if ($gcValue > $value)
117
+ {
118
+ $successMsg = $this->_getHelper()->__('Gift Card funds: '.$gcValue. ' have been applied to the total, Your new gift card balance will be '.($gcValue - $value) );
119
+
120
+ }
121
+
122
+ }
123
+
124
+ if($errorMsg!='Success!!'){
125
+ Mage::log($errorMsg);
126
+ Mage::getSingleton('core/session')->addSuccess($errorMsg);
127
+ Header('Location: '.$_SERVER['/checkout/onepage/']);
128
+ Exit();
129
+ }else if ($successMsg)
130
+ {
131
+ if ($value > 0)
132
+ {
133
+ Mage::log($successMsg);
134
+ Mage::getSingleton('core/session')->addSuccess($successMsg);
135
+ }
136
+ return $this;
137
+ }
138
+
139
+
140
+ }
141
+
142
+
143
+
144
+ }
145
+ ?>
app/code/local/Devsters/Pay/Model/Observer.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Devsters_Pay_Model_Observer
4
+ {
5
+
6
+ public function hookIntoCheckoutOnePageSuccessAction($observer)
7
+ {
8
+ $orderId = $observer->getEvent()->getOrderIds();
9
+ $order = Mage::getSingleton('sales/order')->load($orderId);
10
+ $paymentcode = $order->getPayment()->getMethod();
11
+ if (($paymentcode == 'devstersgiftcard')||($order->getGiftCardNo()))
12
+ {
13
+
14
+ try{
15
+ if ($paymentcode == 'devstersgiftcard')
16
+ {
17
+ $gcBalance = number_format(($order->getGiftCardValue()- ($order->getSubtotalInclTax()+$order->getShippingInclTax()+$order->getBaseDiscountAmount())),2);
18
+ if ($gcBalance <0 ){ $gcBalance = 0; }
19
+ }else
20
+ {
21
+ $gcBalance = 0;
22
+ }
23
+ $gcNumber = $order->getGiftCardNo();
24
+ $dbWrite= Mage::getSingleton('core/resource')->getConnection('core_write');
25
+ $gcSQL= "UPDATE ".Mage::getConfig()->getTablePrefix()."devsters_gift_cards SET ".Mage::getConfig()->getTablePrefix()."devsters_gift_cards.gift_card_balance = " .$gcBalance. " WHERE ".Mage::getConfig()->getTablePrefix()."devsters_gift_cards.gift_card_number = '".$gcNumber."'";
26
+ $dbWrite->query($gcSQL);
27
+ } catch (Exception $e){
28
+ Mage::throwException($e->getMessage());
29
+ exit;
30
+ }
31
+ Mage::log("Gift Card Number: ".$gcNumber." Has a new Balance of: ".$gcBalance);
32
+ return $this;
33
+ }
34
+ }
35
+
36
+ public function updatePaypalTotal($observer){
37
+ $cart = $observer->getPaypalCart();
38
+ $salesEntity = $cart->getSalesEntity();
39
+ $cart->updateTotal(Mage_Paypal_Model_Cart::TOTAL_DISCOUNT,$salesEntity->getGiftCardValue());
40
+ Mage::log("Gift Card Total sent to PayPal: ".$salesEntity->getGiftCardValue());
41
+ }
42
+
43
+
44
+ }
45
+
46
+
app/code/local/Devsters/Pay/Model/Order/Creditmemo.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Devsters_Pay_Model_Order_Creditmemo extends Mage_Sales_Model_Order_Creditmemo_Total_Abstract
4
+ {
5
+ public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
6
+ {
7
+ $order = $creditmemo->getOrder();
8
+ $amount = number_format($order->getGiftCardValue(),2);
9
+ if ($amount) {
10
+ if (($creditmemo->getGrandTotal() - $amount)<0){
11
+ $creditmemo->setGrandTotal(number_format(0.00));
12
+ $creditmemo->setBaseGrandTotal(number_format(0.00));
13
+ }else{
14
+ $creditmemo->setGrandTotal($creditmemo->getGrandTotal() - $amount);
15
+ $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() - $amount);
16
+ }
17
+ }
18
+
19
+ return $this;
20
+ }
21
+ }
app/code/local/Devsters/Pay/Model/Order/Invoice.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Devsters_Pay_Model_Order_Invoice extends Mage_Sales_Model_Order_Invoice_Total_Abstract
4
+ {
5
+ public function collect(Mage_Sales_Model_Order_Invoice $invoice)
6
+ {
7
+ $order = $invoice->getOrder();
8
+ $amount = number_format($order->getGiftCardValue(),2);
9
+
10
+ if ($amount) {
11
+ $order->setBaseTotalInvoiced(number_format($order->getBaseTotalPaid(),2));
12
+ $order->save();
13
+ Mage::log("Amount after Invoice created: ".$invoice->getTotalPaid());
14
+ }
15
+ return $this;
16
+ }
17
+ }
app/code/local/Devsters/Pay/Model/Quote/Discount.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Devsters_Pay_Model_Quote_Discount extends Mage_Sales_Model_Quote_Address_Total_Abstract
3
+ {
4
+ public function __construct()
5
+ {
6
+ $this->setCode('devstersgiftcard');
7
+ }
8
+
9
+ /**
10
+ * Get label
11
+ *
12
+ * @return string
13
+ */
14
+ public function getLabel()
15
+ {
16
+ return Mage::helper('pay')->__('Devsters Gift Card');
17
+ }
18
+
19
+ /**
20
+ * Collect totals information about insurance
21
+ *
22
+ * @param Mage_Sales_Model_Quote_Address $address
23
+ */
24
+ public function collect(Mage_Sales_Model_Quote_Address $address)
25
+ {
26
+ parent::collect($address);
27
+ if (($address->getAddressType() == 'billing')) {
28
+ return $this;
29
+ }
30
+
31
+ $amount = number_format($address->getQuote()->getGiftCardValue(),2);
32
+
33
+ $this->_aggregateItemDiscount($amount);
34
+ }
35
+
36
+
37
+
38
+
39
+ /**
40
+ * Aggregate item discount information to address data and related properties
41
+ *
42
+ * @param $amount
43
+ * @return Mage_SalesRule_Model_Quote_Discount
44
+ */
45
+ protected function _aggregateItemDiscount($amount)
46
+ {
47
+ if ($amount) {
48
+ $this->_addAmount(-$amount);
49
+ $this->_addBaseAmount(-$amount);
50
+ }
51
+ return $this;
52
+ }
53
+
54
+ /**
55
+ * Add giftcard totals information to address object
56
+ *
57
+ * @param Mage_Sales_Model_Quote_Address $address
58
+ */
59
+ public function fetch(Mage_Sales_Model_Quote_Address $address)
60
+ {
61
+ if (($address->getAddressType() == 'billing')) {
62
+ $amount = number_format($address->getQuote()->getGiftCardValue(),2);
63
+ if ($amount != 0) {
64
+ $address->addTotal(array(
65
+ 'code' => $this->getCode(),
66
+ 'title' => $this->getLabel(),
67
+ 'value' => $amount
68
+ ));
69
+ }
70
+ }
71
+
72
+ return $this;
73
+ }
74
+ }
app/code/local/Devsters/Pay/etc/config.xml ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Devsters_Pay>
5
+ <version>0.1.9</version>
6
+ </Devsters_Pay>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <pay>
11
+ <use>standard</use>
12
+ <args>
13
+ <module>Devsters_Pay</module>
14
+ <frontName>Devsters Gift Card</frontName>
15
+ </args>
16
+ </pay>
17
+ </routers>
18
+ <layout>
19
+ <updates>
20
+ <pay>
21
+ <file>pay.xml</file>
22
+ </pay>
23
+ </updates>
24
+ </layout>
25
+ </frontend>
26
+ <global>
27
+ <sales>
28
+ <quote>
29
+ <totals>
30
+ <pay>
31
+ <class>pay/quote_discount</class>
32
+ <after>subtotal</after>
33
+ <before>tax</before>
34
+ </pay>
35
+ </totals>
36
+ </quote>
37
+ <order_invoice>
38
+ <totals>
39
+ <pay>
40
+ <class>pay/order_invoice</class>
41
+ <after>subtotal</after>
42
+ <before>tax</before>
43
+ </pay>
44
+ </totals>
45
+ </order_invoice>
46
+ <order_creditmemo>
47
+ <totals>
48
+ <pay>
49
+ <class>pay/order_creditmemo</class>
50
+ <after>subtotal</after>
51
+ <before>tax</before>
52
+ </pay>
53
+ </totals>
54
+ </order_creditmemo>
55
+ <totals_sort>
56
+ <pay>15</pay>
57
+ </totals_sort>
58
+ </sales>
59
+ <fieldsets>
60
+ <sales_convert_quote>
61
+ <gift_card_value>
62
+ <to_order>*</to_order>
63
+ </gift_card_value>
64
+ <gift_card_no>
65
+ <to_order>*</to_order>
66
+ </gift_card_no>
67
+ </sales_convert_quote>
68
+ <sales_convert_quote_payment>
69
+ <gift_card_value>
70
+ <to_order_payment>*</to_order_payment>
71
+ </gift_card_value>
72
+ <gift_card_no>
73
+ <to_order_payment>*</to_order_payment>
74
+ </gift_card_no>
75
+ </sales_convert_quote_payment>
76
+ </fieldsets>
77
+ <models>
78
+ <pay>
79
+ <class>Devsters_Pay_Model</class>
80
+ </pay>
81
+ </models>
82
+ <resources>
83
+ <pay_setup>
84
+ <setup>
85
+ <module>Devsters_Pay</module>
86
+ </setup>
87
+ <connection>
88
+ <use>core_setup</use>
89
+ </connection>
90
+ </pay_setup>
91
+ <pay_write>
92
+ <connection>
93
+ <use>core_write</use>
94
+ </connection>
95
+ </pay_write>
96
+ <pay_read>
97
+ <connection>
98
+ <use>core_read</use>
99
+ </connection>
100
+ </pay_read>
101
+ </resources>
102
+ <blocks>
103
+ <pay>
104
+ <class>Devsters_Pay_Block</class>
105
+ </pay>
106
+ </blocks>
107
+ <blocks>
108
+ <adminhtml>
109
+ <rewrite>
110
+ <sales_order_totals>Devsters_Pay_Adminhtml_Block_Sales_Order_Totals</sales_order_totals>
111
+ <sales_order_invoice_totals>Devsters_Pay_Adminhtml_Block_Sales_Order_Invoice_Totals</sales_order_invoice_totals>
112
+ <sales_order_creditmemo_totals>Devsters_Pay_Adminhtml_Block_Sales_Order_Creditmemo_Totals</sales_order_creditmemo_totals>
113
+ </rewrite>
114
+ </adminhtml>
115
+ </blocks>
116
+ <helpers>
117
+ <pay>
118
+ <class>Devsters_Pay_Helper</class>
119
+ </pay>
120
+ </helpers>
121
+ <events>
122
+ <checkout_onepage_controller_success_action>
123
+ <observers>
124
+ <pay_observer_checkout_onepage_controller_success_action>
125
+ <type>singleton</type>
126
+ <class>pay/observer</class>
127
+ <method>hookIntoCheckoutOnePageSuccessAction</method>
128
+ </pay_observer_checkout_onepage_controller_success_action>
129
+ </observers>
130
+ </checkout_onepage_controller_success_action>
131
+ <paypal_prepare_line_items>
132
+ <observers>
133
+ <paypal_prepare_line_items>
134
+ <class>pay/observer</class>
135
+ <method>updatePaypalTotal</method>
136
+ </paypal_prepare_line_items>
137
+ </observers>
138
+ </paypal_prepare_line_items>
139
+ </events>
140
+ </global>
141
+ <default>
142
+ <payment>
143
+ <devstersgiftcard>
144
+ <active>1</active>
145
+ <model>pay/method_pay</model>
146
+ <order_status>processing</order_status>
147
+ <title>Devsters Gift Card</title>
148
+ <message>Please enter the card number incuding any dashes '-'.</message>
149
+ </devstersgiftcard>
150
+ </payment>
151
+ </default>
152
+ </config>
app/code/local/Devsters/Pay/etc/system.xml ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <sections>
4
+ <payment>
5
+ <groups>
6
+ <devstersgiftcard translate="label" module="pay">
7
+ <label>Devsters Gift Card</label>
8
+ <sort_order>670</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>0</show_in_store>
12
+ <fields>
13
+ <active translate="label">
14
+ <label>Enabled</label>
15
+ <frontend_type>select</frontend_type>
16
+ <source_model>adminhtml/system_config_source_yesno</source_model>
17
+ <sort_order>1</sort_order>
18
+ <show_in_default>1</show_in_default>
19
+ <show_in_website>1</show_in_website>
20
+ <show_in_store>0</show_in_store>
21
+ </active>
22
+ <order_status translate="label">
23
+ <label>New order status</label>
24
+ <frontend_type>select</frontend_type>
25
+ <source_model>adminhtml/system_config_source_order_status_processing</source_model>
26
+ <sort_order>2</sort_order>
27
+ <show_in_default>1</show_in_default>
28
+ <show_in_website>1</show_in_website>
29
+ <show_in_store>0</show_in_store>
30
+ </order_status>
31
+ <title translate="label">
32
+ <label>Title</label>
33
+ <frontend_type>text</frontend_type>
34
+ <sort_order>3</sort_order>
35
+ <show_in_default>1</show_in_default>
36
+ <show_in_website>1</show_in_website>
37
+ <show_in_store>0</show_in_store>
38
+ </title>
39
+ <message translate="label">
40
+ <label>Displayed Message</label>
41
+ <frontend_type>textarea</frontend_type>
42
+ <sort_order>4</sort_order>
43
+ <show_in_default>1</show_in_default>
44
+ <show_in_website>1</show_in_website>
45
+ <show_in_store>1</show_in_store>
46
+ </message>
47
+ </fields>
48
+ </devstersgiftcard>
49
+ </groups>
50
+ </payment>
51
+ </sections>
52
+ </config>
app/code/local/Devsters/Pay/sql/pay_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+ /* @var $installer Mage_Customer_Model_Entity_Setup */
4
+
5
+ $installer->startSetup();
6
+ $installer->run("
7
+
8
+ ALTER TABLE `{$installer->getTable('sales/quote_payment')}` ADD `gift_card_no` VARCHAR( 50 ) NOT NULL ;
9
+ ALTER TABLE `{$installer->getTable('sales/quote_payment')}` ADD `gift_card_value` decimal(5,2) NOT NULL ;
10
+
11
+ ALTER TABLE `{$installer->getTable('sales/quote')}` ADD `gift_card_no` VARCHAR( 50 ) NOT NULL ;
12
+ ALTER TABLE `{$installer->getTable('sales/quote')}` ADD `gift_card_value` decimal(5,2) NOT NULL ;
13
+
14
+ ALTER TABLE `{$installer->getTable('sales/order_payment')}` ADD `gift_card_no` VARCHAR( 50 ) NOT NULL ;
15
+ ALTER TABLE `{$installer->getTable('sales/order_payment')}` ADD `gift_card_value` decimal(5,2) NOT NULL ;
16
+
17
+ ALTER TABLE `".$this->getTable('sales/order')."` ADD `gift_card_value` DECIMAL( 5, 2 ) NOT NULL;
18
+ ALTER TABLE `".$this->getTable('sales/quote_address')."` ADD `gift_card_value` DECIMAL( 5, 2 ) NOT NULL;
19
+ ALTER TABLE `".$this->getTable('sales/order')."` ADD `gift_card_no` VARCHAR( 50 ) NOT NULL;
20
+ ALTER TABLE `".$this->getTable('sales/quote_address')."` ADD `gift_card_no` VARCHAR( 50 ) NOT NULL;
21
+ ALTER TABLE `".$this->getTable('sales/invoice')."` ADD `gift_card_value` DECIMAL( 5, 2 ) NOT NULL;
22
+ ALTER TABLE `".$this->getTable('sales/invoice')."` ADD `gift_card_no` VARCHAR( 50 ) NOT NULL;
23
+ ALTER TABLE `".$this->getTable('sales/creditmemo')."` ADD `gift_card_value` DECIMAL( 5, 2 ) NOT NULL;
24
+ ALTER TABLE `".$this->getTable('sales/creditmemo')."` ADD `gift_card_no` VARCHAR( 50 ) NOT NULL;
25
+
26
+ ");
27
+ $installer->endSetup();
app/code/local/Devsters/Pay/sql/pay_setup/mysql4-upgrade-0.1.5-0.1.6.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+ /* @var $installer Mage_Customer_Model_Entity_Setup */
4
+
5
+ $installer->startSetup();
6
+ $installer->run("
7
+
8
+
9
+ ALTER TABLE `{$installer->getTable('sales/quote_payment')}` MODIFY `gift_card_value` decimal(5,2) NOT NULL ;
10
+
11
+
12
+ ALTER TABLE `{$installer->getTable('sales/quote')}` MODIFY `gift_card_value` decimal(5,2) NOT NULL ;
13
+
14
+
15
+ ALTER TABLE `{$installer->getTable('sales/order_payment')}` MODIFY `gift_card_value` decimal(5,2) NOT NULL ;
16
+
17
+ ALTER TABLE `".$this->getTable('sales/order')."` MODIFY `gift_card_value` DECIMAL( 5, 2 ) NOT NULL;
18
+ ALTER TABLE `".$this->getTable('sales/quote_address')."` MODIFY `gift_card_value` DECIMAL( 5, 2 ) NOT NULL;
19
+
20
+
21
+ ALTER TABLE `".$this->getTable('sales/invoice')."` MODIFY `gift_card_value` DECIMAL( 5, 2 ) NOT NULL;
22
+
23
+ ALTER TABLE `".$this->getTable('sales/creditmemo')."` MODIFY `gift_card_value` DECIMAL( 5, 2 ) NOT NULL;
24
+
25
+
26
+ ");
27
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/devstersgiftcards.xml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <gift_adminhtml_giftcards_index>
4
+ <reference name="content">
5
+ <block type="gift/adminhtml_giftcards" name="giftcards" />
6
+ </reference>
7
+ <reference name="js">
8
+ <block type="core/template" template="devsters/giftcards/devsterscardbalance.phtml" />
9
+ </reference>
10
+ </gift_adminhtml_giftcards_index>
11
+ </layout>
app/design/adminhtml/default/default/template/devsters/giftcards/devsterscardbalance.phtml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script type="text/javascript">
2
+ function updateBalance(button, fieldId)
3
+ {
4
+ var alertstring = "Updating balance to: " + $(button).previous('input').getValue() + " for Card ID :" + fieldId ;
5
+ alert (alertstring);
6
+
7
+ new Ajax.Request('<?php echo Mage::helper('adminhtml')->getUrl('*/*/updateBalance') ?>', {
8
+ method: 'post',
9
+ parameters: { id: fieldId, gift_card_balance: $(button).previous('input').getValue() }
10
+ });
11
+
12
+ }
13
+ </script>
app/design/frontend/default/default/template/devsters/pay/form/pay.phtml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $_code=$this->getMethodCode() ?>
2
+
3
+
4
+ <ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display:none;">
5
+ <li>
6
+ <label for="<?php echo $_code ?>_gift_card_no" class="required"><em>*</em><?php echo $this->__('Gift Card No#') ?></label>
7
+ <span class="input-box">
8
+ <input type="hidden" name= "tvalue" value = "<?php Mage::getSingleton('checkout/session')->getQuote()->getGrandTotal(); ?>" />
9
+ <input type="text" title="<?php echo $this->__('Gift Card No#') ?>" class="input-text required-entry" id="<?php echo $_code ?>_gift_card_no" name="payment[gift_card_no]" value="<?php echo $this->htmlEscape($this->getInfoData('gift_card_no')) ?>" />
10
+ </span>
11
+ </li>
12
+ </ul>
13
+ <div>
14
+ <?php echo $this->getMethod()->getConfigData('message'); ?>
15
+ </div>
16
+
17
+
18
+ <?
app/etc/modules/Devsters_Gift.xml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <config>
4
+ <modules>
5
+ <Devsters_Gift>
6
+ <active>true</active>
7
+ <codePool>local</codePool>
8
+ <depends>
9
+ <Mage_Catalog />
10
+ <Mage_Core />
11
+ <Mage_Payment />
12
+ </depends>
13
+ </Devsters_Gift>
14
+ </modules>
15
+ </config>
app/etc/modules/Devsters_Pay.xml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Devsters_Pay>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ <depends>
8
+ <Mage_Catalog />
9
+ <Mage_Core />
10
+ <Mage_Payment />
11
+ <Devsters_Gift />
12
+ </depends>
13
+ </Devsters_Pay>
14
+ </modules>
15
+ </config>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Devsters_Gift_Cards</name>
4
- <version>0.2.0</version>
5
  <stability>stable</stability>
6
  <license/>
7
  <channel>community</channel>
@@ -28,9 +28,9 @@ NOTE: Not yet tested on v1.8. &#xD;
28
  Thanks and have a great day, hope this free extension helps you further with this add on functionality.&#xD;
29
  Devsters.</notes>
30
  <authors><author><name>Devsters Inc</name><user>auto-converted</user><email>devsters@shopdevsters.com</email></author></authors>
31
- <date>2013-11-10</date>
32
- <time>07:20:26</time>
33
- <contents><target name="magelocal"><dir name="You will be editing: "><dir name="public_html"><dir name="trending"><dir name="app"><dir name="etc"><dir name="modules"><file name="Devsters_Gift.xml" hash=""/><file name="Devsters_Pay.xml" hash=""/></dir></dir></dir></dir></dir></dir></target></contents>
34
  <compatible/>
35
  <dependencies><required><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.6.0.0</min><max>1.7</max></package></required></dependencies>
36
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Devsters_Gift_Cards</name>
4
+ <version>0.2.1</version>
5
  <stability>stable</stability>
6
  <license/>
7
  <channel>community</channel>
28
  Thanks and have a great day, hope this free extension helps you further with this add on functionality.&#xD;
29
  Devsters.</notes>
30
  <authors><author><name>Devsters Inc</name><user>auto-converted</user><email>devsters@shopdevsters.com</email></author></authors>
31
+ <date>2013-12-22</date>
32
+ <time>05:33:14</time>
33
+ <contents><target name="magelocal"><dir name="Devsters"><dir name="Gift"><dir name="Block"><dir name="Adminhtml"><dir name="Giftcards"><file name="Edit.php" hash="cc5fb1db26e11c1b862b86845bf023b9"/><file name="Grid.php" hash="7c503a38fe0a9357424aa7e34d54dc4e"/></dir><dir name="Renderer"><file name="Balance.php" hash="14e5ff6202a8695ffcba94a0c502699c"/></dir><file name="Giftcards.php" hash="72fb28829792326e57798ebb6fba9672"/></dir></dir><dir name="Helper"><file name="Data.php" hash="2e886ebd6eab681d0ac48bb4aeff6e31"/></dir><dir name="Model"><dir name="CatalogIndex"><dir name="Data"><file name="Cards.php" hash="19fea4d7b514a30a60b57e675a9c74f5"/></dir></dir><dir name="Mysql4"><dir name="Gift"><file name="Collection.php" hash="30ee898419be6ae7facd3ba56a6c47cd"/></dir><file name="Gift.php" hash="535569315d2cc29d479db954933cb87b"/></dir><dir name="Product"><dir name="Type"><file name="Cards.php" hash="0e704a545f13c315cebbf825822f1b97"/></dir><file name="Price.php" hash="188bb375d6b4b34f008788128c3373ca"/><file name="Type.php" hash="96512db8764f797887351211500c0a92"/></dir><dir name="Sales"><file name="Order.php" hash="9a44dccd5ad64fb7492acec4d4fba3d7"/></dir><file name="Gift.php" hash="ab1edce984952d9d88113a77e5a5a360"/><file name="Observer.php" hash="b03ce692dc1953442bd3dd6c3c7d05d2"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="GiftcardsController.php" hash="718ae35da12827fb36b793471802086f"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="e474bcc5937e938bba1da1baa8b6c58e"/><file name="config.xml" hash="c86467beb0a5c14da1fe5a13ceb42281"/></dir><dir name="sql"><dir name="gift_setup"><file name="mysql4-install-0.1.0.php" hash="d30b282c8ec998bb1524ae82d8b1e0a0"/><file name="mysql4-upgrade-0.1.9-0.2.php" hash="14e55abeb7538eacefb005013917d4bf"/></dir></dir></dir><dir name="Pay"><dir name="Adminhtml"><dir name="Block"><dir name="Sales"><dir name="Order"><dir name="Creditmemo"><file name="Totals.php" hash="c810c7dded6f40ce8bfb1b84b417b5e4"/></dir><dir name="Invoice"><file name="Totals.php" hash="5600fdcb5d62cb9f9943c76a4a5cb14f"/></dir><file name="Totals.php" hash="43df189c21196a51d0ef800f089f5c93"/></dir></dir></dir></dir><dir name="Block"><dir name="Form"><file name="Pay.php" hash="303ec4ace64068bf5d9b2543c54a015f"/></dir><dir name="Info"><file name="Pay.php" hash="5a94537e4d8c8321ef7d29f498384acb"/></dir></dir><dir name="Helper"><file name="Data.php" hash="c5619c2bc96c43aca2b08f4571375098"/></dir><dir name="Model"><dir name="Method"><file name="Pay.php" hash="9561250deff4592c253ff2791a9efa6b"/></dir><dir name="Order"><file name="Creditmemo.php" hash="c702dec1cec919af93b914f69f24158a"/><file name="Invoice.php" hash="43be8d664812aa7fe21d75540c081cc9"/></dir><dir name="Quote"><file name="Discount.php" hash="207c3e58537f0e7a9b08f94c24dc042f"/></dir><file name="Observer.php" hash="0fb29c1b0280d0c6c5a040e15646d672"/></dir><dir name="etc"><file name="config.xml" hash="6bd7322d9297e9450408278eb1fc9f15"/><file name="system.xml" hash="e45e8ad1efe52553bfc48dff67b61a0f"/></dir><dir name="sql"><dir name="pay_setup"><file name="mysql4-install-0.1.0.php" hash="0bffac58eb39e5b8b952d9dfd64f5752"/><file name="mysql4-upgrade-0.1.5-0.1.6.php" hash="a01b10aec5dcf0ac279e386364559c9e"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Devsters_Gift.xml" hash="77c9c1dc4f4074171cc31c44f8e9bfd1"/><file name="Devsters_Pay.xml" hash="8cf1dfd8c27849ad063cb5bf2921a5ba"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="devstersgiftcards.xml" hash="6e522e07fcd4ef1722cbafff07ac46ae"/></dir><dir name="template"><dir name="devsters"><dir name="giftcards"><file name="devsterscardbalance.phtml" hash="7bffe57307885dd00540e43f7402ce80"/></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="template"><dir name="devsters"><dir name="pay"><dir name="form"><file name="pay.phtml" hash="00409aa9bcd2ba45e25599d37b0ca86f"/></dir></dir></dir></dir></dir></dir></dir></target></contents>
34
  <compatible/>
35
  <dependencies><required><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.6.0.0</min><max>1.7</max></package></required></dependencies>
36
  </package>