· 6 years ago · Jul 03, 2019, 12:38 AM
1<?xml version="1.0"?>
2<config>
3 <modules>
4 <VivasIndustries_SmsNotification>
5 <version>1.0.0</version>
6 </VivasIndustries_SmsNotification>
7 </modules>
8 <global>
9 <models>
10 <smsnotification>
11 <class>VivasIndustries_SmsNotification_Model</class>
12 <resourceModel>vivasindustries_smsnotification_resource</resourceModel>
13 </smsnotification>
14 <vivasindustries_smsnotification_resource>
15 <class>VivasIndustries_SmsNotification_Model_Resource</class>
16 <entities>
17 <smsnotification>
18 <table>VivasIndustries_SmsNotification</table>
19 </smsnotification>
20 <smsnotificationhistory>
21 <table>VivasIndustries_SmsHistory</table>
22 </smsnotificationhistory>
23 </entities>
24 </vivasindustries_smsnotification_resource>
25 </models>
26 <resources>
27 <smsnotification_setup>
28 <setup>
29 <module>VivasIndustries_SmsNotification</module>
30 </setup>
31 <connection>
32 <use>core_setup</use>
33 </connection>
34 </smsnotification_setup>
35 <smsnotification_read>
36 <connection>
37 <use>core_read</use>
38 </connection>
39 </smsnotification_read>
40 <smsnotification_write>
41 <connection>
42 <use>core_write</use>
43 </connection>
44 </smsnotification_write>
45 </resources>
46 <events>
47 <checkout_type_onepage_save_order_after> <!-- identifier of the event we want to catch -->
48 <observers>
49 <checkout_type_onepage_save_order_after_smsprice_handler> <!-- identifier of the event handler -->
50 <type>model</type> <!-- class method call type; valid are model, object and singleton -->
51 <class>smsnotification/newordertotalobserver</class> <!-- observers class alias -->
52 <method>saveSmspriceTotal</method> <!-- observer's method to be called -->
53 <args></args> <!-- additional arguments passed to observer -->
54 </checkout_type_onepage_save_order_after_smsprice_handler>
55 </observers>
56 </checkout_type_onepage_save_order_after>
57 <checkout_type_multishipping_create_orders_single> <!-- identifier of the event we want to catch -->
58 <observers>
59 <checkout_type_multishipping_create_orders_single_smsprice_handler> <!-- identifier of the event handler -->
60 <type>model</type> <!-- class method call type; valid are model, object and singleton -->
61 <class>smsnotification/newordertotalobserver</class> <!-- observers class alias -->
62 <method>saveSmspriceTotalForMultishipping</method> <!-- observer's method to be called -->
63 <args></args> <!-- additional arguments passed to observer -->
64 </checkout_type_multishipping_create_orders_single_smsprice_handler>
65 </observers>
66 </checkout_type_multishipping_create_orders_single>
67 <sales_order_save_after>
68 <observers>
69 <vivasindustries_smsnotification>
70 <class>smsnotification/observer</class>
71 <method>orderSaved</method>
72 </vivasindustries_smsnotification>
73 </observers>
74 </sales_order_save_after>
75 </events>
76 <sales>
77 <quote>
78 <totals>
79 <smsprice_total>
80 <class>smsnotification/quote_address_total_smsprice</class>
81 <after>subtotal,freeshipping,tax_subtotal,shipping</after>
82 <before>grand_total</before>
83 </smsprice_total>
84 </totals>
85 </quote>
86 <order_invoice>
87 <totals>
88 <smsprice_total>
89 <class>smsnotification/order_invoice_total_smsprice</class>
90 <after>subtotal,freeshipping,tax_subtotal,shipping</after>
91 <before>grand_total</before>
92 </smsprice_total>
93 </totals>
94 </order_invoice>
95 <order_creditmemo>
96 <totals>
97 <smsprice_total>
98 <class>percentpayment/order_creditmemo_total_smsprice</class>
99 <after>subtotal,freeshipping,tax_subtotal,shipping</after>
100 <before>grand_total</before>
101 </smsprice_total>
102 </totals>
103 </order_creditmemo>
104 </sales>
105 <helpers>
106 <smsnotification>
107 <class>VivasIndustries_SmsNotification_Helper</class>
108 </smsnotification>
109 </helpers>
110 <blocks>
111 <smsnotification>
112 <class>VivasIndustries_SmsNotification_Block</class>
113 </smsnotification>
114 </blocks>
115 </global>
116 <adminhtml>
117 <acl>
118 <resources>
119 <all>
120 <title>Allow Everything</title>
121 </all>
122 <admin>
123 <children>
124 <system>
125 <children>
126 <config>
127 <children>
128 <vivas>
129 <title>Vivas - All</title>
130 </vivas>
131 </children>
132 </config>
133 </children>
134 </system>
135 </children>
136 </admin>
137 </resources>
138 </acl>
139 <layout>
140 <updates>
141 <smsnotification>
142 <file>smsnotification.xml</file>
143 </smsnotification>
144 </updates>
145 </layout>
146 </adminhtml>
147 <admin>
148 <routers>
149 <adminhtml>
150 <args>
151 <modules>
152 <VivasIndustries_SmsNotification before="Mage_Adminhtml">VivasIndustries_SmsNotification_Adminhtml</VivasIndustries_SmsNotification>
153 </modules>
154 </args>
155 </adminhtml>
156 </routers>
157 </admin>
158 <default>
159 <vivas>
160 <smspricegroup>
161 <smsprice_name>SMS Notification</smsprice_name>
162 <smsprice_fee>0.5</smsprice_fee>
163 </smspricegroup>
164 </vivas>
165 </default>
166</config>
167
168<?php
169class VivasIndustries_SmsNotification_Helper_Data extends Mage_Core_Helper_Abstract
170{
171 public function formatFee($amount){
172 $SmspriceLabel = Mage::getStoreConfig('vivas/smspricegroup/smsprice_name');
173 return Mage::helper('smsnotification')->__($SmspriceLabel);
174 }
175}
176
177<?php
178
179class VivasIndustries_SmsNotification_Helper_Adminhtml_Data extends Mage_Adminhtml_Helper_Data
180{
181}
182
183<?php
184class VivasIndustries_SmsNotification_Model_Newordertotalobserver
185{
186 public function saveSmspriceTotal(Varien_Event_Observer $observer)
187 {
188 $order = $observer -> getEvent() -> getOrder();
189 $quote = $observer -> getEvent() -> getQuote();
190 $shippingAddress = $quote -> getShippingAddress();
191 if($shippingAddress && $shippingAddress -> getData('smsprice_total')){
192 $order -> setData('smsprice_total', $shippingAddress -> getData('smsprice_total'));
193 }
194 else{
195 $billingAddress = $quote -> getBillingAddress();
196 $order -> setData('smsprice_total', $billingAddress -> getData('smsprice_total'));
197 }
198 $order -> save();
199 }
200
201 public function saveSmspriceTotalForMultishipping(Varien_Event_Observer $observer)
202 {
203 $order = $observer -> getEvent() -> getOrder();
204 $address = $observer -> getEvent() -> getAddress();
205 $order -> setData('smsprice_total', $shippingAddress -> getData('smsprice_total'));
206 $order -> save();
207 }
208}
209
210<?php
211class VivasIndustries_SmsNotification_Model_Quote_Address_Total_Smsprice extends Mage_Sales_Model_Quote_Address_Total_Abstract
212{
213
214 public function __construct()
215 {
216 $this -> setCode('smsprice_total');
217 }
218
219 public function getSmsPriceStatus()
220 {
221
222 $EnableSmsPrice = Mage::getStoreConfig('vivas/smspricegroup/smsprice_active');
223
224 return ($EnableSmsPrice);
225 }
226
227 public function collect(Mage_Sales_Model_Quote_Address $address)
228 {
229 parent :: collect($address);
230 $items = $this->_getAddressItems($address);
231 if (!count($items)) {
232 return $this;
233 }
234 $quote= $address->getQuote();
235
236 if($this->getSmsPriceStatus())
237 {
238 $discountAmount = Mage::getStoreConfig('vivas/smspricegroup/smsprice_fee');
239
240
241 $address->setSmspriceAmount($discountAmount);
242 $address->setBaseSmspriceAmount($discountAmount);
243
244 $quote->setSmspriceAmount($discountAmount);
245
246
247 //amount definition
248
249 $discountAmount = $quote -> getStore() -> roundPrice($discountAmount);
250 $this -> _setAmount($discountAmount) -> _setBaseAmount($discountAmount);
251 $address->setData('smsprice_total',$discountAmount);
252
253 return $this;
254 }
255 }
256
257
258 public function fetch(Mage_Sales_Model_Quote_Address $address)
259 {
260
261 $EnableSmsPrice = Mage::getStoreConfig('vivas/smspricegroup/smsprice_active');
262 if($this->getSmsPriceStatus())
263 {
264 parent :: fetch($address);
265 $amount = $address -> getTotalAmount($this -> getCode());
266 if ($amount != 0){
267 $address -> addTotal(array(
268 'code' => $this -> getCode(),
269 'title' => $this -> getLabel(),
270 'value' => $amount
271 ));
272 }
273
274 return $address;
275 }
276 }
277
278 public function getLabel()
279 {
280 $SmspriceLabel = Mage::getStoreConfig('vivas/smspricegroup/smsprice_name');
281 return Mage::helper('smsnotification')->__("$SmspriceLabel:");
282 }
283
284}
285
286<?php
287 class VivasIndustries_SmsNotification_Model_Order_Invoice_Total_Smsprice
288 extends Mage_Sales_Model_Order_Invoice_Total_Abstract
289 {
290 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
291 {
292 $order=$invoice->getOrder();
293 $orderDiscountTotal = $order->getSmspriceTotal();
294 if ($orderDiscountTotal&&count($order->getInvoiceCollection())==0) {
295 $invoice->setGrandTotal($invoice->getGrandTotal()+$orderDiscountTotal);
296 $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal()+$orderDiscountTotal);
297 }
298 return $this;
299 }
300 }
301
302<?php
303class VivasIndustries_SmsNotification_Model_Order_Creditmemo_Total_Smsprice
304extends Mage_Sales_Model_Order_Creditmemo_Total_Abstract
305{
306 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
307 {
308
309 return $this;
310
311 $order = $creditmemo->getOrder();
312 $orderDiscountTotal = $order->getSmspriceTotal();
313
314 if ($orderDiscountTotal) {
315 $creditmemo->setGrandTotal($creditmemo->getGrandTotal()+$orderDiscountTotal);
316 $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal()+$orderDiscountTotal);
317 }
318
319 return $this;
320 }
321}
322
323<?php
324class VivasIndustries_SmsNotification_Model_Resource_Smsnotification_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract{
325 protected function _construct(){
326 $this->_init('smsnotification/smsnotification');
327 }
328}
329
330<?php
331$installer=$this;
332$installer->startSetup();
333
334$installer->run("
335CREATE TABLE IF NOT EXISTS `VivasIndustries_SmsNotification` (
336 `id` int(11) NOT NULL AUTO_INCREMENT,
337 `state` varchar(500) NOT NULL,
338 `smstext` varchar(500) NOT NULL,
339 PRIMARY KEY (`id`),
340 KEY `id` (`id`)
341) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
342
343CREATE TABLE IF NOT EXISTS `VivasIndustries_SmsHistory` (
344 `id` int(11) NOT NULL AUTO_INCREMENT,
345 `receiver` varchar(500) NOT NULL,
346 `phone` varchar(500) NOT NULL,
347 `email` varchar(500) NOT NULL,
348 `smstext` text NOT NULL,
349 `date` datetime NOT NULL,
350 PRIMARY KEY (`id`)
351) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
352
353 ");
354
355/*$installer->run("
356
357 ALTER TABLE `".$this->getTable('sales/quote_address')."` ADD `smsprice_total` DECIMAL( 10, 2 ) NOT NULL;
358 ALTER TABLE `".$this->getTable('sales/order')."` ADD `smsprice_total` DECIMAL( 10, 2 ) NOT NULL;
359
360 "); */
361
362$installer->addAttribute("quote_address", "smsprice_total", array("type"=>"varchar"));
363$installer->addAttribute("order", "smsprice_total", array("type"=>"varchar"));
364$installer->endSetup();
365?>
366
367class Company_Sms_Block_Adminhtml_Sales_Order extends Mage_Sales_Block_Order_Totals
368{
369
370 protected function _initTotals()
371 {
372 parent::_initTotals();
373 $smsAmount = $this->getOrder()->getSmsAmount();
374
375 if ($smsAmount != 0)
376 {
377 $this->addTotal(
378 new Varien_Object(
379 array(
380 'code' => 'sms',
381 'value' => $smsAmount,
382 'label' => $helper->__('Some Text'),
383 )
384 ));
385 }
386 return $this;
387 }
388
389}
390
391<adminhtml>
392 <rewrite>
393 <sales_order_totals>Company_Sms_Block_Adminhtml_Sales_Order</sales_order_totals>
394 </rewrite>
395</adminhtml>
396
397<fieldsets>
398 <sales_convert_quote_address>
399 <sms_amount>
400 <to_order>*</to_order>
401 </sms_amount>
402 </sales_convert_quote_address>
403</fieldsets>