Thebod_Shippingrates - Version 1.0.3

Version Notes

* Added country filter

Download this release

Release Info

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


Code changes from version 1.0.2 to 1.0.3

app/code/community/Thebod/Shippingrates/Block/Adminhtml/Config.php CHANGED
@@ -17,21 +17,29 @@
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
 
37
  $html = '<div id="shippingconfig_template" style="display:none">';
@@ -48,7 +56,7 @@ class Thebod_Shippingrates_Block_Adminhtml_Config extends Mage_Adminhtml_Block_S
48
  filter_btn = btn;
49
  $(\'shippingconfig_filter_name\').update($(btn).up(1).down(\'.name\').value);
50
  if($(btn).up(1).down(\'.filter\').value == \'\') {
51
- $(btn).up(1).down(\'.filter\').value = \'min_qty:;max_qty:;min_subtotal:;max_subtotal:;min_weight:;max_weight:;\';
52
  }
53
 
54
  filter = $(btn).up(1).down(\'.filter\').value.split(\';\').each(function(e,i) {
@@ -70,6 +78,7 @@ class Thebod_Shippingrates_Block_Adminhtml_Config extends Mage_Adminhtml_Block_S
70
  filter += \'max_subtotal:\' + $(\'shippingconfig_filter_max_subtotal\').value + \';\';
71
  filter += \'min_weight:\' + $(\'shippingconfig_filter_min_weight\').value + \';\';
72
  filter += \'max_weight:\' + $(\'shippingconfig_filter_max_weight\').value + \';\';
 
73
 
74
  $(btn).up(1).down(\'.filter\').value = filter;
75
 
@@ -92,6 +101,9 @@ class Thebod_Shippingrates_Block_Adminhtml_Config extends Mage_Adminhtml_Block_S
92
  <td>' . $this->__('min. weight:') . '</td><td><input class="input-text" style="width: 100px;" id="shippingconfig_filter_min_weight"/></td>
93
  <td>' . $this->__('max. weight:') . '</td><td><input class="input-text" style="width: 100px;" id="shippingconfig_filter_max_weight"/></td>
94
  </tr>
 
 
 
95
  </table>
96
  <div style="text-align: right;">
97
  <button onclick="shippingconfig_filter_hide()" type="button">' . $this->__('save filter') . '</button>
@@ -128,7 +140,8 @@ class Thebod_Shippingrates_Block_Adminhtml_Config extends Mage_Adminhtml_Block_S
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;">';
134
  $html .= '<input class="name input-text ' . $this->_getDisabled() . '" style="vertical-align: top; width: 100px; margin: 0 6px;" name="' . $this->getElement()->getName() . '[code][]" value="' . $this->_getValue('code/' . $key) . '"/>';
@@ -149,7 +162,8 @@ class Thebod_Shippingrates_Block_Adminhtml_Config extends Mage_Adminhtml_Block_S
149
  *
150
  * @return string
151
  */
152
- protected function _getDisabled() {
 
153
  return $this->getElement()->getDisabled() ? ' disabled' : '';
154
  }
155
 
@@ -159,27 +173,29 @@ class Thebod_Shippingrates_Block_Adminhtml_Config extends Mage_Adminhtml_Block_S
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')
177
- ->setType('button')
178
- ->setClass('add ' . $this->_getDisabled())
179
- ->setLabel($this->__($title))
180
- ->setOnClick("Element.insert($('" . $container . "'), {bottom: $('" . $template . "').innerHTML})")
181
- ->setDisabled($this->_getDisabled())
182
- ->toHtml();
183
  }
184
  return $this->_addRowButtonHtml[$container];
185
  }
@@ -191,16 +207,16 @@ class Thebod_Shippingrates_Block_Adminhtml_Config extends Mage_Adminhtml_Block_S
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')
197
- ->setType('button')
198
- ->setClass('delete ' . $this->_getDisabled())
199
- ->setOnClick("Element.remove($(this).up('" . $selector . "'))")
200
- ->setDisabled($this->_getDisabled())
201
- ->toHtml();
202
  }
203
  return $this->_removeRowButtonHtml;
204
  }
205
-
206
  }
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
+ class Thebod_Shippingrates_Block_Adminhtml_Config extends Mage_Adminhtml_Block_System_Config_Form_Field
22
+ {
23
+ /**
24
+ * @var array Add buttons
25
+ */
26
  protected $_addRowButtonHtml = array();
27
+
28
+ /**
29
+ * @var array Remove buttons
30
+ */
31
  protected $_removeRowButtonHtml = array();
32
 
33
  /**
34
  * basic template for shipping rates configurator
35
  *
36
+ * @todo move inline html into templates
37
+ *
38
  * @param Varien_Data_Form_Element_Abstract $element
39
  * @return string
40
  */
41
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
42
+ {
43
  $this->setElement($element);
44
 
45
  $html = '<div id="shippingconfig_template" style="display:none">';
56
  filter_btn = btn;
57
  $(\'shippingconfig_filter_name\').update($(btn).up(1).down(\'.name\').value);
58
  if($(btn).up(1).down(\'.filter\').value == \'\') {
59
+ $(btn).up(1).down(\'.filter\').value = \'min_qty:;max_qty:;min_subtotal:;max_subtotal:;min_weight:;max_weight:;countries:;\';
60
  }
61
 
62
  filter = $(btn).up(1).down(\'.filter\').value.split(\';\').each(function(e,i) {
78
  filter += \'max_subtotal:\' + $(\'shippingconfig_filter_max_subtotal\').value + \';\';
79
  filter += \'min_weight:\' + $(\'shippingconfig_filter_min_weight\').value + \';\';
80
  filter += \'max_weight:\' + $(\'shippingconfig_filter_max_weight\').value + \';\';
81
+ filter += \'countries:\' + $(\'shippingconfig_filter_countries\').value + \';\';
82
 
83
  $(btn).up(1).down(\'.filter\').value = filter;
84
 
101
  <td>' . $this->__('min. weight:') . '</td><td><input class="input-text" style="width: 100px;" id="shippingconfig_filter_min_weight"/></td>
102
  <td>' . $this->__('max. weight:') . '</td><td><input class="input-text" style="width: 100px;" id="shippingconfig_filter_max_weight"/></td>
103
  </tr>
104
+ <tr>
105
+ <td colspan="2">' . $this->__('limit to countries: (2-characters, comma-separated, e.g. "DE" or "DE,AT,CH")') . '</td><td colspan="2"><input class="input-text" style="width: 100px;" id="shippingconfig_filter_countries"/></td>
106
+ </tr>
107
  </table>
108
  <div style="text-align: right;">
109
  <button onclick="shippingconfig_filter_hide()" type="button">' . $this->__('save filter') . '</button>
140
  * @param int $key
141
  * @return string
142
  */
143
+ protected function _getRowTemplateHtml($key = 0)
144
+ {
145
  $html = '<li style="display: block; width: 550px;">';
146
  $html .= '<div style="float: left;">';
147
  $html .= '<input class="name input-text ' . $this->_getDisabled() . '" style="vertical-align: top; width: 100px; margin: 0 6px;" name="' . $this->getElement()->getName() . '[code][]" value="' . $this->_getValue('code/' . $key) . '"/>';
162
  *
163
  * @return string
164
  */
165
+ protected function _getDisabled()
166
+ {
167
  return $this->getElement()->getDisabled() ? ' disabled' : '';
168
  }
169
 
173
  * @param string $key
174
  * @return string
175
  */
176
+ protected function _getValue($key)
177
+ {
178
  return $this->getElement()->getData('value/' . $key);
179
  }
180
 
181
  /**
182
  * returns 'add' button html code
183
  *
184
+ * @param string $container
185
+ * @param string $template
186
  * @param string $title
187
  * @return string
188
  */
189
+ protected function _getAddRowButtonHtml($container, $template, $title = 'Add')
190
+ {
191
  if (!isset($this->_addRowButtonHtml[$container])) {
192
  $this->_addRowButtonHtml[$container] = $this->getLayout()->createBlock('adminhtml/widget_button')
193
+ ->setType('button')
194
+ ->setClass('add ' . $this->_getDisabled())
195
+ ->setLabel($this->__($title))
196
+ ->setOnClick("Element.insert($('" . $container . "'), {bottom: $('" . $template . "').innerHTML})")
197
+ ->setDisabled($this->_getDisabled())
198
+ ->toHtml();
199
  }
200
  return $this->_addRowButtonHtml[$container];
201
  }
207
  * @param string $title
208
  * @return array
209
  */
210
+ protected function _getRemoveRowButtonHtml($selector = 'li', $title = 'Delete')
211
+ {
212
  if (!$this->_removeRowButtonHtml) {
213
  $this->_removeRowButtonHtml = $this->getLayout()->createBlock('adminhtml/widget_button')
214
+ ->setType('button')
215
+ ->setClass('delete ' . $this->_getDisabled())
216
+ ->setOnClick("Element.remove($(this).up('" . $selector . "'))")
217
+ ->setDisabled($this->_getDisabled())
218
+ ->toHtml();
219
  }
220
  return $this->_removeRowButtonHtml;
221
  }
 
222
  }
app/code/community/Thebod/Shippingrates/Helper/Data.php CHANGED
@@ -18,6 +18,38 @@
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
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  * @author Bastian Ike <b-ike@b-ike.de>
19
  * @license http://creativecommons.org/licenses/by/3.0/ CC-BY 3.0
20
  */
21
+ class Thebod_Shippingrates_Helper_Data extends Mage_Core_Helper_Abstract
22
+ {
23
+ /**
24
+ * Rearranges the complete shipping rates array
25
+ *
26
+ * @param array $data array(
27
+ * code => array('', 'a', 'b'),
28
+ * price => array('', 10, 20),
29
+ * description => array('', 'desc1', 'desc2')
30
+ * )
31
+ * @return array array(
32
+ * methodid => array(
33
+ * code => 'a',
34
+ * price => 10,
35
+ * description => 'desc1'
36
+ * )
37
+ * )
38
+ */
39
+ public function rearrangeShippingRates($data)
40
+ {
41
+ $methods = array();
42
+ foreach ($data as $key => $value) {
43
+ /*
44
+ * $methodId => id of this method
45
+ * $methodValue => value of this entry
46
+ */
47
+ foreach ($value as $methodId => $methodValue) {
48
+ /* we ignore this if $methodId == 0 */
49
+ if ($methodId) {
50
+ $methods[$methodId][$key] = $methodValue;
51
+ }
52
+ }
53
+ }
54
+ }
55
+ }
app/code/community/Thebod/Shippingrates/Model/Carrier.php CHANGED
@@ -18,8 +18,11 @@
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
 
25
  /**
@@ -28,16 +31,17 @@ class Thebod_Shippingrates_Model_Carrier extends Mage_Shipping_Model_Carrier_Abs
28
  * @param string $code
29
  * @return string
30
  */
31
- public function getNotificationMail($code) {
 
32
  $data = $this->getConfigData('shippingconfig');
33
 
34
- if(!is_array($data)) {
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
  }
@@ -50,59 +54,71 @@ class Thebod_Shippingrates_Model_Carrier extends Mage_Shipping_Model_Carrier_Abs
50
  * @param Mage_Shipping_Model_Rate_Request $request
51
  * @return boolean
52
  */
53
- public function checkRate(array $rate, Mage_Shipping_Model_Rate_Request $request) {
54
- if(!Mage::getSingleton('checkout/session')->hasQuote()) {
 
55
  return true;
56
  }
57
 
58
- if(!isset($rate['filter'])) {
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;
71
  }
72
 
73
- switch($condition) {
74
  case 'min_qty':
75
- if($request->getPackageQty() < $value) {
76
  $passed = false;
77
  }
78
  break;
79
 
80
  case 'max_qty':
81
- if($request->getPackageQty() > $value) {
82
  $passed = false;
83
  }
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;
97
 
98
  case 'min_weight':
99
- if($request->getPackageWeight() < $value) {
100
  $passed = false;
101
  }
102
  break;
103
 
104
  case 'max_weight':
105
- if($request->getPackageWeight() > $value) {
 
 
 
 
 
 
 
 
 
 
 
106
  $passed = false;
107
  }
108
  break;
@@ -118,23 +134,22 @@ class Thebod_Shippingrates_Model_Carrier extends Mage_Shipping_Model_Carrier_Abs
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)) {
 
132
  $method = Mage::getModel('shipping/rate_result_method');
133
 
134
  $method->setCarrier($this->_code);
135
  $method->setCarrierTitle($this->getConfigData('title'));
136
 
137
- //$method->setMethod($this->_code . '_' . $rate['code']);
138
  $method->setMethod($rate['code']);
139
  $method->setMethodTitle($rate['title']);
140
 
@@ -143,7 +158,6 @@ class Thebod_Shippingrates_Model_Carrier extends Mage_Shipping_Model_Carrier_Abs
143
  $result->append($method);
144
  }
145
  }
146
-
147
  return $result;
148
  }
149
 
@@ -153,42 +167,27 @@ class Thebod_Shippingrates_Model_Carrier extends Mage_Shipping_Model_Carrier_Abs
153
  * @param Mage_Shipping_Model_Rate_Request $data
154
  * @return array
155
  */
156
- public function getRates($data) {
157
- $rates = array();
158
- $methods = array();
159
-
160
- if(!is_array($data)) {
161
  $data = unserialize(base64_decode($data));
162
  }
163
 
164
- /* rearrange array */
165
- /* $data: array(code => array('', 'a', 'b'), price => array('', 10, 20), description => array('', 'desc1', 'desc2')) */
166
- /* $key: code, then price, then data - $value: array*/
167
- foreach($data as $key => $value) {
168
- /* $value: array, $methodid: id of this method, $methodvalue: value of this entry */
169
- foreach($value as $methodid => $methodvalue) {
170
- /* we ignore this if methodid == 0 */
171
- if($methodid) {
172
- /* methods = array(methodid => array(code => 'a', price => 10, description => 'desc1')) ... */
173
- $methods[$methodid][$key] = $methodvalue;
174
- }
175
- }
176
- }
177
-
178
- foreach($methods as $method) {
179
- $code = trim($method['code']);
180
- $price = trim($method['price']);
181
  $filter = trim($method['filter']);
182
- $title = nl2br(trim($method['description']));
183
 
184
  $rates[] = array(
185
- 'code' => $code,
186
- 'title' => $title,
187
- 'price' => $price,
188
  'filter' => $filter,
189
  );
190
  }
191
-
192
  krsort($rates);
193
 
194
  return $rates;
@@ -202,9 +201,8 @@ class Thebod_Shippingrates_Model_Carrier extends Mage_Shipping_Model_Carrier_Abs
202
  public function getAllowedMethods()
203
  {
204
  $allowedMethods = array(
205
- $this->_code => $this->getConfigData('name'),
206
  );
207
-
208
  return $allowedMethods;
209
  }
210
- }
18
  * @author Bastian Ike <b-ike@b-ike.de>
19
  * @license http://creativecommons.org/licenses/by/3.0/ CC-BY 3.0
20
  */
21
+ class Thebod_Shippingrates_Model_Carrier extends Mage_Shipping_Model_Carrier_Abstract
22
+ {
23
+ /**
24
+ * @var string Shipping Method Code
25
+ */
26
  protected $_code = 'shippingrates';
27
 
28
  /**
31
  * @param string $code
32
  * @return string
33
  */
34
+ public function getNotificationMail($code)
35
+ {
36
  $data = $this->getConfigData('shippingconfig');
37
 
38
+ if (!is_array($data)) {
39
  $data = unserialize(base64_decode($data));
40
  }
41
 
42
  /* searches correct mail address */
43
+ foreach ($data['code'] as $k => $v) {
44
+ if (($this->_code . '_' . $v) == $code) {
45
  return $data['email'][$k];
46
  }
47
  }
54
  * @param Mage_Shipping_Model_Rate_Request $request
55
  * @return boolean
56
  */
57
+ public function checkRate(array $rate, Mage_Shipping_Model_Rate_Request $request)
58
+ {
59
+ if (!Mage::getSingleton('checkout/session')->hasQuote()) {
60
  return true;
61
  }
62
 
63
+ if (!isset($rate['filter'])) {
64
  return true;
65
  }
66
 
67
  $filters = explode(';', $rate['filter']);
68
  $passed = true;
69
+ foreach ($filters as $filter) {
70
  $filter = explode(':', $filter);
71
  $condition = $filter[0];
72
  $value = isset($filter[1]) && $filter[1] ? $filter[1] : false;
73
 
74
+ if ($value === false) {
75
  continue;
76
  }
77
 
78
+ switch ($condition) {
79
  case 'min_qty':
80
+ if ($request->getPackageQty() < $value) {
81
  $passed = false;
82
  }
83
  break;
84
 
85
  case 'max_qty':
86
+ if ($request->getPackageQty() > $value) {
87
  $passed = false;
88
  }
89
  break;
90
 
91
  case 'min_subtotal':
92
+ if ($request->getPackageValueWithDiscount() < $value) {
93
  $passed = false;
94
  }
95
  break;
96
 
97
  case 'max_subtotal':
98
+ if ($request->getPackageValueWithDiscount() > $value) {
99
  $passed = false;
100
  }
101
  break;
102
 
103
  case 'min_weight':
104
+ if ($request->getPackageWeight() < $value) {
105
  $passed = false;
106
  }
107
  break;
108
 
109
  case 'max_weight':
110
+ if ($request->getPackageWeight() > $value) {
111
+ $passed = false;
112
+ }
113
+ break;
114
+
115
+ case 'countries':
116
+ $dest = strtolower($request->getDestCountryId());
117
+ $allowed = explode(',', strtolower($value));
118
+ foreach($allowed as $k => $v) {
119
+ $allowed[$k] = trim($v);
120
+ }
121
+ if(!in_array($dest, $allowed) && count($allowed)) {
122
  $passed = false;
123
  }
124
  break;
134
  * @param Mage_Shipping_Model_Rate_Request $request
135
  * @return Mage_Shipping_Model_Rate_Result
136
  */
137
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request)
138
+ {
139
+ if (!$this->getConfigFlag('active')) {
140
  return false;
141
  }
142
 
 
 
143
  $rates = $this->getRates($this->getConfigData('shippingconfig'));
144
 
145
+ $result = Mage::getModel('shipping/rate_result');
146
+ foreach ($rates as $rate) {
147
+ if ($this->checkRate($rate, $request)) {
148
  $method = Mage::getModel('shipping/rate_result_method');
149
 
150
  $method->setCarrier($this->_code);
151
  $method->setCarrierTitle($this->getConfigData('title'));
152
 
 
153
  $method->setMethod($rate['code']);
154
  $method->setMethodTitle($rate['title']);
155
 
158
  $result->append($method);
159
  }
160
  }
 
161
  return $result;
162
  }
163
 
167
  * @param Mage_Shipping_Model_Rate_Request $data
168
  * @return array
169
  */
170
+ public function getRates($data)
171
+ {
172
+ if (!is_array($data)) {
 
 
173
  $data = unserialize(base64_decode($data));
174
  }
175
 
176
+ $methods = Mage::helper('shippingrates')->rearrangeShippingRates($data);
177
+ $rates = array();
178
+ foreach ($methods as $method) {
179
+ $code = trim($method['code']);
180
+ $price = trim($method['price']);
 
 
 
 
 
 
 
 
 
 
 
 
181
  $filter = trim($method['filter']);
182
+ $title = nl2br(trim($method['description']));
183
 
184
  $rates[] = array(
185
+ 'code' => $code,
186
+ 'title' => $title,
187
+ 'price' => $price,
188
  'filter' => $filter,
189
  );
190
  }
 
191
  krsort($rates);
192
 
193
  return $rates;
201
  public function getAllowedMethods()
202
  {
203
  $allowedMethods = array(
204
+ $this->_code => $this->getConfigData('name')
205
  );
 
206
  return $allowedMethods;
207
  }
208
+ }
app/code/community/Thebod/Shippingrates/Model/Email.php CHANGED
@@ -18,24 +18,26 @@
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
 
@@ -80,7 +82,8 @@ class Thebod_Shippingrates_Model_Email extends Mage_Core_Model_Abstract {
80
  $mailer->setSender(Mage::getStoreConfig(Mage_Sales_Model_Order::XML_PATH_EMAIL_IDENTITY, $storeId));
81
  $mailer->setStoreId($storeId);
82
  $mailer->setTemplateId($templateId);
83
- $mailer->setTemplateParams(array(
 
84
  'order' => $order,
85
  'billing' => $order->getBillingAddress(),
86
  'payment_html' => $paymentBlockHtml
@@ -90,4 +93,4 @@ class Thebod_Shippingrates_Model_Email extends Mage_Core_Model_Abstract {
90
 
91
  return true;
92
  }
93
- }
18
  * @author Bastian Ike <b-ike@b-ike.de>
19
  * @license http://creativecommons.org/licenses/by/3.0/ CC-BY 3.0
20
  */
21
+ class Thebod_Shippingrates_Model_Email extends Mage_Core_Model_Abstract
22
+ {
 
23
  /**
24
+ * Sends notification mail for selected shipping rate
25
+ *
26
+ * The code for this functionality is based on Mage_Sales_Model_Order::sendNewOrderEmail()
27
  *
28
  * @param Mage_Sales_Model_Order $order
29
  * @return boolean
30
  * @throws Exception
31
  * @see Mage_Sales_Model_Order
32
  */
33
+ public function sendEmailNotification($order)
34
+ {
35
+ if (strncmp($order->getShippingMethod(), 'shippingrates_', 14) != 0) {
36
  return false;
37
  }
38
 
39
  $notificationMail = $order->getShippingCarrier()->getNotificationMail($order->getShippingMethod());
40
+ if (!strlen(trim($notificationMail))) {
41
  return false;
42
  }
43
 
82
  $mailer->setSender(Mage::getStoreConfig(Mage_Sales_Model_Order::XML_PATH_EMAIL_IDENTITY, $storeId));
83
  $mailer->setStoreId($storeId);
84
  $mailer->setTemplateId($templateId);
85
+ $mailer->setTemplateParams(
86
+ array(
87
  'order' => $order,
88
  'billing' => $order->getBillingAddress(),
89
  'payment_html' => $paymentBlockHtml
93
 
94
  return true;
95
  }
96
+ }
app/code/community/Thebod/Shippingrates/Model/Observer.php CHANGED
@@ -18,15 +18,18 @@
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
  }
32
  }
18
  * @author Bastian Ike <b-ike@b-ike.de>
19
  * @license http://creativecommons.org/licenses/by/3.0/ CC-BY 3.0
20
  */
21
+ class Thebod_Shippingrates_Model_Observer
22
+ {
23
  /**
24
  * observer to send mail notification
25
  *
26
+ * @param Varien_Event_Observer $observer
27
+ * @return void
28
  */
29
+ public function checkoutTypeOnepageSaveOrderAfter(Varien_Event_Observer $observer)
30
+ {
31
+ /* @var $shippingModel Thebod_Shippingrates_Model_Email */
32
  $shippingModel = Mage::getModel('shippingrates/email');
33
+ $shippingModel->sendEmailNotification($observer->getOrder());
34
  }
35
  }
app/code/community/Thebod/Shippingrates/Model/System/Config.php CHANGED
@@ -16,14 +16,17 @@
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_System_Config extends Mage_Core_Model_Config_Data {
22
-
23
  /**
24
  * serializes array before saving
 
 
25
  */
26
- protected function _beforeSave() {
 
27
  if (is_array($this->getValue())) {
28
  $this->setValue(base64_encode(serialize($this->getValue())));
29
  }
@@ -31,11 +34,14 @@ class Thebod_Shippingrates_Model_System_Config extends Mage_Core_Model_Config_Da
31
 
32
  /**
33
  * unserializes array after loading
 
 
34
  */
35
- protected function _afterLoad() {
36
- if(!is_array($this->getValue())) {
 
37
  $value = $this->getValue();
38
  $this->setValue(empty($value) ? false : unserialize(base64_decode($value)));
39
  }
40
  }
41
- }
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
+ class Thebod_Shippingrates_Model_System_Config extends Mage_Core_Model_Config_Data
22
+ {
23
  /**
24
  * serializes array before saving
25
+ *
26
+ * @return void
27
  */
28
+ protected function _beforeSave()
29
+ {
30
  if (is_array($this->getValue())) {
31
  $this->setValue(base64_encode(serialize($this->getValue())));
32
  }
34
 
35
  /**
36
  * unserializes array after loading
37
+ *
38
+ * @return void
39
  */
40
+ protected function _afterLoad()
41
+ {
42
+ if (!is_array($this->getValue())) {
43
  $value = $this->getValue();
44
  $this->setValue(empty($value) ? false : unserialize(base64_decode($value)));
45
  }
46
  }
47
+ }
app/code/community/Thebod/Shippingrates/etc/config.xml CHANGED
@@ -53,4 +53,4 @@
53
  </shippingrates>
54
  </carriers>
55
  </default>
56
- </config>
53
  </shippingrates>
54
  </carriers>
55
  </default>
56
+ </config>
app/code/community/Thebod/Shippingrates/etc/system.xml CHANGED
@@ -55,4 +55,4 @@
55
  </groups>
56
  </carriers>
57
  </sections>
58
- </config>
55
  </groups>
56
  </carriers>
57
  </sections>
58
+ </config>
app/etc/modules/Thebod_Shippingrates.xml CHANGED
@@ -4,6 +4,9 @@
4
  <Thebod_Shippingrates>
5
  <active>true</active>
6
  <codePool>community</codePool>
 
 
 
7
  </Thebod_Shippingrates>
8
  </modules>
9
- </config>
4
  <Thebod_Shippingrates>
5
  <active>true</active>
6
  <codePool>community</codePool>
7
+ <depends>
8
+ <Mage_Shipping />
9
+ </depends>
10
  </Thebod_Shippingrates>
11
  </modules>
12
+ </config>
package.xml CHANGED
@@ -1,7 +1,7 @@
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>
@@ -15,13 +15,11 @@ This simple module lets you define as many shipping methods as you need, with an
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>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Thebod_Shippingrates</name>
4
+ <version>1.0.3</version>
5
  <stability>stable</stability>
6
  <license uri="http://creativecommons.org/licenses/by/3.0/">CC-BY 3.0</license>
7
  <channel>community</channel>
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>* Added country filter</notes>
 
 
19
  <authors><author><name>Bastian Ike</name><user>auto-converted</user><email>thebod@thebod.de</email></author></authors>
20
+ <date>2012-03-26</date>
21
+ <time>11:51:37</time>
22
+ <contents><target name="magecommunity"><dir name="Thebod"><dir name="Shippingrates"><dir name="Block"><dir name="Adminhtml"><file name="Config.php" hash="8f644c12b096bc7549f9dfec3b676817"/></dir></dir><dir name="Helper"><file name="Data.php" hash="7b42da8b04f0fd02601694911ee7045d"/></dir><dir name="Model"><dir name="System"><file name="Config.php" hash="bf385822d37c0566d8b3cccf4edb9d59"/></dir><file name="Carrier.php" hash="c5130bdcb828461c3381b0dba4d6f0dc"/><file name="Email.php" hash="b38b57d3c7b5a4ab87dbcb5d2ad00ac1"/><file name="Observer.php" hash="44895836ace80675104b471380bb4497"/></dir><dir name="etc"><file name="config.xml" hash="8f2fd361b067a00a8441233e5870f224"/><file name="system.xml" hash="9d342162dceeebcdeacbfd544dddd350"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Thebod_Shippingrates.xml" hash="3696db1933b77f5e792c2bcc82d8216f"/></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>
23
  <compatible/>
24
  <dependencies/>
25
  </package>