Thebod_Shippingrates - Version 1.0.2

Version Notes

* Bugfixes, update recommend

* Tested on 1.6, should work on Magento >= 1.4

Download this release

Release Info

Developer Magento Core Team
Extension Thebod_Shippingrates
Version 1.0.2
Comparing to
See all releases


Code changes from version 1.0.0 to 1.0.2

app/code/community/Thebod/Shippingrates/Block/Adminhtml/Config.php CHANGED
@@ -16,13 +16,21 @@
16
* @package Thebod_Shippingrates
17
* @copyright Copyright (c) 2012 Bastian Ike (http://thebod.de/)
18
* @author Bastian Ike <b-ike@b-ike.de>
19
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
*/
21
class Thebod_Shippingrates_Block_Adminhtml_Config extends Mage_Adminhtml_Block_System_Config_Form_Field {
22
23
protected $_addRowButtonHtml = array();
24
protected $_removeRowButtonHtml = array();
25
26
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
27
$this->setElement($element);
28
@@ -114,6 +122,12 @@ class Thebod_Shippingrates_Block_Adminhtml_Config extends Mage_Adminhtml_Block_S
114
return $html;
115
}
116
117
protected function _getRowTemplateHtml($key = 0) {
118
$html = '<li style="display: block; width: 550px;">';
119
$html .= '<div style="float: left;">';
@@ -130,14 +144,33 @@ class Thebod_Shippingrates_Block_Adminhtml_Config extends Mage_Adminhtml_Block_S
130
return $html;
131
}
132
133
protected function _getDisabled() {
134
return $this->getElement()->getDisabled() ? ' disabled' : '';
135
}
136
137
protected function _getValue($key) {
138
return $this->getElement()->getData('value/' . $key);
139
}
140
141
protected function _getAddRowButtonHtml($container, $template, $title = 'Add') {
142
if (!isset($this->_addRowButtonHtml[$container])) {
143
$this->_addRowButtonHtml[$container] = $this->getLayout()->createBlock('adminhtml/widget_button')
@@ -151,6 +184,13 @@ class Thebod_Shippingrates_Block_Adminhtml_Config extends Mage_Adminhtml_Block_S
151
return $this->_addRowButtonHtml[$container];
152
}
153
154
protected function _getRemoveRowButtonHtml($selector = 'li', $title = 'Delete') {
155
if (!$this->_removeRowButtonHtml) {
156
$this->_removeRowButtonHtml = $this->getLayout()->createBlock('adminhtml/widget_button')
16
* @package Thebod_Shippingrates
17
* @copyright Copyright (c) 2012 Bastian Ike (http://thebod.de/)
18
* @author Bastian Ike <b-ike@b-ike.de>
19
+ * @license http://creativecommons.org/licenses/by/3.0/ CC-BY 3.0
20
+ * @todo move inline html into templates
21
*/
22
+
23
class Thebod_Shippingrates_Block_Adminhtml_Config extends Mage_Adminhtml_Block_System_Config_Form_Field {
24
25
protected $_addRowButtonHtml = array();
26
protected $_removeRowButtonHtml = array();
27
28
+ /**
29
+ * basic template for shipping rates configurator
30
+ *
31
+ * @param Varien_Data_Form_Element_Abstract $element
32
+ * @return string
33
+ */
34
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
35
$this->setElement($element);
36
122
return $html;
123
}
124
125
+ /**
126
+ * build config line
127
+ *
128
+ * @param int $key
129
+ * @return string
130
+ */
131
protected function _getRowTemplateHtml($key = 0) {
132
$html = '<li style="display: block; width: 550px;">';
133
$html .= '<div style="float: left;">';
144
return $html;
145
}
146
147
+ /**
148
+ * sets 'disabled' mark for css class
149
+ *
150
+ * @return string
151
+ */
152
protected function _getDisabled() {
153
return $this->getElement()->getDisabled() ? ' disabled' : '';
154
}
155
156
+ /**
157
+ * config value getter
158
+ *
159
+ * @param string $key
160
+ * @return string
161
+ */
162
protected function _getValue($key) {
163
return $this->getElement()->getData('value/' . $key);
164
}
165
166
+ /**
167
+ * returns 'add' button html code
168
+ *
169
+ * @param $container
170
+ * @param $template
171
+ * @param string $title
172
+ * @return string
173
+ */
174
protected function _getAddRowButtonHtml($container, $template, $title = 'Add') {
175
if (!isset($this->_addRowButtonHtml[$container])) {
176
$this->_addRowButtonHtml[$container] = $this->getLayout()->createBlock('adminhtml/widget_button')
184
return $this->_addRowButtonHtml[$container];
185
}
186
187
+ /**
188
+ * returns 'delete' button html code
189
+ *
190
+ * @param string $selector
191
+ * @param string $title
192
+ * @return array
193
+ */
194
protected function _getRemoveRowButtonHtml($selector = 'li', $title = 'Delete') {
195
if (!$this->_removeRowButtonHtml) {
196
$this->_removeRowButtonHtml = $this->getLayout()->createBlock('adminhtml/widget_button')
app/code/community/Thebod/Shippingrates/Helper/Data.php CHANGED
@@ -16,8 +16,8 @@
16
* @package Thebod_Shippingrates
17
* @copyright Copyright (c) 2012 Bastian Ike (http://thebod.de/)
18
* @author Bastian Ike <b-ike@b-ike.de>
19
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
*/
21
- class Thebod_Shippingrates_Helper_Data extends Mage_Core_Helper_Abstract {
22
23
}
16
* @package Thebod_Shippingrates
17
* @copyright Copyright (c) 2012 Bastian Ike (http://thebod.de/)
18
* @author Bastian Ike <b-ike@b-ike.de>
19
+ * @license http://creativecommons.org/licenses/by/3.0/ CC-BY 3.0
20
*/
21
22
+ class Thebod_Shippingrates_Helper_Data extends Mage_Core_Helper_Abstract {
23
}
app/code/community/Thebod/Shippingrates/Model/Carrier.php CHANGED
@@ -16,8 +16,9 @@
16
* @package Thebod_Shippingrates
17
* @copyright Copyright (c) 2012 Bastian Ike (http://thebod.de/)
18
* @author Bastian Ike <b-ike@b-ike.de>
19
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
*/
21
class Thebod_Shippingrates_Model_Carrier extends Mage_Shipping_Model_Carrier_Abstract {
22
protected $_code = 'shippingrates';
23
@@ -34,8 +35,9 @@ class Thebod_Shippingrates_Model_Carrier extends Mage_Shipping_Model_Carrier_Abs
34
$data = unserialize(base64_decode($data));
35
}
36
37
foreach($data['code'] as $k => $v) {
38
- if($this->_code . '_' . $v == $code) {
39
return $data['email'][$k];
40
}
41
}
@@ -57,12 +59,12 @@ class Thebod_Shippingrates_Model_Carrier extends Mage_Shipping_Model_Carrier_Abs
57
return true;
58
}
59
60
- $filter = explode(';', $rate['filter']);
61
$passed = true;
62
- foreach($filter as $f) {
63
- $f = explode(':', $f);
64
- $condition = $f[0];
65
- $value = isset($f[1]) && $f[1] ? $f[1] : false;
66
67
if($value === false) {
68
continue;
@@ -82,17 +84,13 @@ class Thebod_Shippingrates_Model_Carrier extends Mage_Shipping_Model_Carrier_Abs
82
break;
83
84
case 'min_subtotal':
85
- Mage::getSingleton('checkout/session')->getQuote()->collectTotals();
86
- $subtotal = Mage::getSingleton('checkout/session')->getQuote()->getSubtotal();
87
- if($subtotal < $value) {
88
$passed = false;
89
}
90
break;
91
92
case 'max_subtotal':
93
- Mage::getSingleton('checkout/session')->getQuote()->collectTotals();
94
- $subtotal = Mage::getSingleton('checkout/session')->getQuote()->getSubtotal();
95
- if($subtotal > $value) {
96
$passed = false;
97
}
98
break;
@@ -110,6 +108,7 @@ class Thebod_Shippingrates_Model_Carrier extends Mage_Shipping_Model_Carrier_Abs
110
break;
111
}
112
}
113
return $passed;
114
}
115
@@ -119,15 +118,14 @@ class Thebod_Shippingrates_Model_Carrier extends Mage_Shipping_Model_Carrier_Abs
119
* @param Mage_Shipping_Model_Rate_Request $request
120
* @return Mage_Shipping_Model_Rate_Result
121
*/
122
- public function collectRates(Mage_Shipping_Model_Rate_Request $request)
123
- {
124
if(!$this->getConfigFlag('active')) {
125
return false;
126
}
127
128
$result = Mage::getModel('shipping/rate_result');
129
130
- $rates = $this->getRate($this->getConfigData('shippingconfig'));
131
132
foreach($rates as $rate) {
133
if($this->checkRate($rate, $request)) {
@@ -155,7 +153,7 @@ class Thebod_Shippingrates_Model_Carrier extends Mage_Shipping_Model_Carrier_Abs
155
* @param Mage_Shipping_Model_Rate_Request $data
156
* @return array
157
*/
158
- public function getRate($data) {
159
$rates = array();
160
$methods = array();
161
@@ -183,8 +181,6 @@ class Thebod_Shippingrates_Model_Carrier extends Mage_Shipping_Model_Carrier_Abs
183
$filter = trim($method['filter']);
184
$title = nl2br(trim($method['description']));
185
186
- $title = str_replace(array('=>', '<='), array('<strong>', '</strong>'), $title);
187
-
188
$rates[] = array(
189
'code' => $code,
190
'title' => $title,
16
* @package Thebod_Shippingrates
17
* @copyright Copyright (c) 2012 Bastian Ike (http://thebod.de/)
18
* @author Bastian Ike <b-ike@b-ike.de>
19
+ * @license http://creativecommons.org/licenses/by/3.0/ CC-BY 3.0
20
*/
21
+
22
class Thebod_Shippingrates_Model_Carrier extends Mage_Shipping_Model_Carrier_Abstract {
23
protected $_code = 'shippingrates';
24
35
$data = unserialize(base64_decode($data));
36
}
37
38
+ /* searches correct mail address */
39
foreach($data['code'] as $k => $v) {
40
+ if(($this->_code . '_' . $v) == $code) {
41
return $data['email'][$k];
42
}
43
}
59
return true;
60
}
61
62
+ $filters = explode(';', $rate['filter']);
63
$passed = true;
64
+ foreach($filters as $filter) {
65
+ $filter = explode(':', $filter);
66
+ $condition = $filter[0];
67
+ $value = isset($filter[1]) && $filter[1] ? $filter[1] : false;
68
69
if($value === false) {
70
continue;
84
break;
85
86
case 'min_subtotal':
87
+ if($request->getPackageValueWithDiscount() < $value) {
88
$passed = false;
89
}
90
break;
91
92
case 'max_subtotal':
93
+ if($request->getPackageValueWithDiscount() > $value) {
94
$passed = false;
95
}
96
break;
108
break;
109
}
110
}
111
+
112
return $passed;
113
}
114
118
* @param Mage_Shipping_Model_Rate_Request $request
119
* @return Mage_Shipping_Model_Rate_Result
120
*/
121
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request) {
122
if(!$this->getConfigFlag('active')) {
123
return false;
124
}
125
126
$result = Mage::getModel('shipping/rate_result');
127
128
+ $rates = $this->getRates($this->getConfigData('shippingconfig'));
129
130
foreach($rates as $rate) {
131
if($this->checkRate($rate, $request)) {
153
* @param Mage_Shipping_Model_Rate_Request $data
154
* @return array
155
*/
156
+ public function getRates($data) {
157
$rates = array();
158
$methods = array();
159
181
$filter = trim($method['filter']);
182
$title = nl2br(trim($method['description']));
183
184
$rates[] = array(
185
'code' => $code,
186
'title' => $title,
app/code/community/Thebod/Shippingrates/Model/Email.php CHANGED
@@ -16,18 +16,27 @@
16
* @package Thebod_Shippingrates
17
* @copyright Copyright (c) 2012 Bastian Ike (http://thebod.de/)
18
* @author Bastian Ike <b-ike@b-ike.de>
19
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
*/
21
class Thebod_Shippingrates_Model_Email extends Mage_Core_Model_Abstract {
22
/* code based on Mage_Sales_Model_Order::sendNewOrderEmail() */
23
public function sendEmailNotification($order) {
24
if(strncmp($order->getShippingMethod(), 'shippingrates_', 14) != 0) {
25
- return;
26
}
27
28
$notificationMail = $order->getShippingCarrier()->getNotificationMail($order->getShippingMethod());
29
if(!strlen(trim($notificationMail))) {
30
- return;
31
}
32
33
$storeId = $order->getStore()->getId();
@@ -78,5 +87,7 @@ class Thebod_Shippingrates_Model_Email extends Mage_Core_Model_Abstract {
78
)
79
);
80
$mailer->send();
81
}
82
}
16
* @package Thebod_Shippingrates
17
* @copyright Copyright (c) 2012 Bastian Ike (http://thebod.de/)
18
* @author Bastian Ike <b-ike@b-ike.de>
19
+ * @license http://creativecommons.org/licenses/by/3.0/ CC-BY 3.0
20
*/
21
+
22
class Thebod_Shippingrates_Model_Email extends Mage_Core_Model_Abstract {
23
/* code based on Mage_Sales_Model_Order::sendNewOrderEmail() */
24
+ /**
25
+ * sends notification mail for selected shipping rate
26
+ *
27
+ * @param Mage_Sales_Model_Order $order
28
+ * @return boolean
29
+ * @throws Exception
30
+ * @see Mage_Sales_Model_Order
31
+ */
32
public function sendEmailNotification($order) {
33
if(strncmp($order->getShippingMethod(), 'shippingrates_', 14) != 0) {
34
+ return false;
35
}
36
37
$notificationMail = $order->getShippingCarrier()->getNotificationMail($order->getShippingMethod());
38
if(!strlen(trim($notificationMail))) {
39
+ return false;
40
}
41
42
$storeId = $order->getStore()->getId();
87
)
88
);
89
$mailer->send();
90
+
91
+ return true;
92
}
93
}
app/code/community/Thebod/Shippingrates/Model/Observer.php CHANGED
@@ -16,10 +16,16 @@
16
* @package Thebod_Shippingrates
17
* @copyright Copyright (c) 2012 Bastian Ike (http://thebod.de/)
18
* @author Bastian Ike <b-ike@b-ike.de>
19
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
*/
21
class Thebod_Shippingrates_Model_Observer {
22
- public function checkout_type_onepage_save_order_after($event) {
23
$shippingModel = Mage::getModel('shippingrates/email');
24
$shippingModel->sendEmailNotification($event->getOrder());
25
}
16
* @package Thebod_Shippingrates
17
* @copyright Copyright (c) 2012 Bastian Ike (http://thebod.de/)
18
* @author Bastian Ike <b-ike@b-ike.de>
19
+ * @license http://creativecommons.org/licenses/by/3.0/ CC-BY 3.0
20
*/
21
+
22
class Thebod_Shippingrates_Model_Observer {
23
+ /**
24
+ * observer to send mail notification
25
+ *
26
+ * @param $event
27
+ */
28
+ public function checkoutTypeOnepageSaveOrderAfter($event) {
29
$shippingModel = Mage::getModel('shippingrates/email');
30
$shippingModel->sendEmailNotification($event->getOrder());
31
}
app/code/community/Thebod/Shippingrates/etc/config.xml CHANGED
@@ -25,7 +25,7 @@
25
<shippingrates>
26
<type>singleton</type>
27
<class>shippingrates/observer</class>
28
- <method>checkout_type_onepage_save_order_after</method>
29
</shippingrates>
30
</observers>
31
</checkout_type_onepage_save_order_after>
25
<shippingrates>
26
<type>singleton</type>
27
<class>shippingrates/observer</class>
28
+ <method>checkoutTypeOnepageSaveOrderAfter</method>
29
</shippingrates>
30
</observers>
31
</checkout_type_onepage_save_order_after>
package.xml CHANGED
@@ -1,9 +1,9 @@
1
<?xml version="1.0"?>
2
<package>
3
<name>Thebod_Shippingrates</name>
4
- <version>1.0.0</version>
5
<stability>stable</stability>
6
- <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL 3.0)</license>
7
<channel>community</channel>
8
<extends/>
9
<summary>Simple configurable shippingrates for Magento</summary>
@@ -12,12 +12,16 @@
12
Simple configurable shippingrates for Magento.&#xD;
13
&#xD;
14
This simple module lets you define as many shipping methods as you need, with an optional 'notification e-mail'.&#xD;
15
- Very useful for 'pickup-at-store' or if you need a few self-specified fixed rates shipping methods.</description>
16
- <notes>* Tested on 1.6, should work on Magento &gt;= 1.4</notes>
17
<authors><author><name>Bastian Ike</name><user>auto-converted</user><email>thebod@thebod.de</email></author></authors>
18
- <date>2012-02-03</date>
19
- <time>07:44:50</time>
20
- <contents><target name="magecommunity"><dir name="Thebod"><dir name="Shippingrates"><dir name="Block"><dir name="Adminhtml"><file name="Config.php" hash="e5b88b7f739ef069d4a5c0a915105714"/></dir></dir><dir name="Helper"><file name="Data.php" hash="5a0d2237d0cb5c658c431216005b8443"/></dir><dir name="Model"><dir name="System"><file name="Config.php" hash="d5cc2bc66d01f10939f86fade97d2f12"/></dir><file name="Carrier.php" hash="83c71ed3668963c6742b9f675f8353b7"/><file name="Email.php" hash="4ca850ca6a5de4d9a4b7d3f704ce055d"/><file name="Observer.php" hash="5730e4b8e21425a8545a3ee12f854e73"/></dir><dir name="etc"><file name="config.xml" hash="74172e5d3095c124373e2a11efdf6190"/><file name="system.xml" hash="1b5ed3db08ed13d21c7686705f5f193d"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Thebod_Shippingrates.xml" hash="f4baeb06eea903395d8ef19b187961e0"/></dir></target><target name="magelocale"><dir name="de_DE"><file name="Thebod_Shippingrates.csv" hash="c0e42c61094aa36c8b699b909581615f"/></dir><dir name="pt_PT"><file name="Thebod_Shippingrates.csv" hash="7873741ed92a4370a7280d4c76e7c1ee"/></dir></target></contents>
21
<compatible/>
22
<dependencies/>
23
</package>
1
<?xml version="1.0"?>
2
<package>
3
<name>Thebod_Shippingrates</name>
4
+ <version>1.0.2</version>
5
<stability>stable</stability>
6
+ <license uri="http://creativecommons.org/licenses/by/3.0/">CC-BY 3.0</license>
7
<channel>community</channel>
8
<extends/>
9
<summary>Simple configurable shippingrates for Magento</summary>
12
Simple configurable shippingrates for Magento.&#xD;
13
&#xD;
14
This simple module lets you define as many shipping methods as you need, with an optional 'notification e-mail'.&#xD;
15
+ Very useful for 'pickup-at-store' or if you need a few self-specified fixed rates shipping methods.&#xD;
16
+ &#xD;
17
+ Fork me on Github https://github.com/thebod/Thebod_Shippingrates !</description>
18
+ <notes>* Bugfixes, update recommend&#xD;
19
+ &#xD;
20
+ * Tested on 1.6, should work on Magento &gt;= 1.4</notes>
21
<authors><author><name>Bastian Ike</name><user>auto-converted</user><email>thebod@thebod.de</email></author></authors>
22
+ <date>2012-03-16</date>
23
+ <time>22:08:34</time>
24
+ <contents><target name="magecommunity"><dir name="Thebod"><dir name="Shippingrates"><dir name="Block"><dir name="Adminhtml"><file name="Config.php" hash="6d71e3516df636f42431904e9cad8718"/></dir></dir><dir name="Helper"><file name="Data.php" hash="1729e0de9e6dea4b63bf22d3ef00bf39"/></dir><dir name="Model"><dir name="System"><file name="Config.php" hash="d5cc2bc66d01f10939f86fade97d2f12"/></dir><file name="Carrier.php" hash="0781bbd909e8a78ff75026002e08b91f"/><file name="Email.php" hash="2388584e5573e39e338e02e4440f9666"/><file name="Observer.php" hash="4d141167a2d8a695f7dc0b657e4b0d8f"/></dir><dir name="etc"><file name="config.xml" hash="2569312345c36f0b53ab9d32882ee7c4"/><file name="system.xml" hash="1b5ed3db08ed13d21c7686705f5f193d"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Thebod_Shippingrates.xml" hash="f4baeb06eea903395d8ef19b187961e0"/></dir></target><target name="magelocale"><dir name="de_DE"><file name="Thebod_Shippingrates.csv" hash="c0e42c61094aa36c8b699b909581615f"/></dir><dir name="pt_PT"><file name="Thebod_Shippingrates.csv" hash="7873741ed92a4370a7280d4c76e7c1ee"/></dir></target></contents>
25
<compatible/>
26
<dependencies/>
27
</package>