Thebod_Shippingrates - Version 1.0.5

Version Notes

* Extended country filters (exclude countries)
* Limit to payment methods

Download this release

Release Info

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


Code changes from version 1.0.4 to 1.0.5

app/code/community/Thebod/Shippingrates/Block/Adminhtml/Config.php CHANGED
@@ -56,7 +56,7 @@ class Thebod_Shippingrates_Block_Adminhtml_Config extends Mage_Adminhtml_Block_S
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) {
@@ -79,6 +79,7 @@ class Thebod_Shippingrates_Block_Adminhtml_Config extends Mage_Adminhtml_Block_S
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
 
@@ -102,7 +103,10 @@ class Thebod_Shippingrates_Block_Adminhtml_Config extends Mage_Adminhtml_Block_S
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;">
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:;payment:;\';
60
  }
61
 
62
  filter = $(btn).up(1).down(\'.filter\').value.split(\';\').each(function(e,i) {
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
+ filter += \'payment:\' + $(\'shippingconfig_filter_payment\').value + \';\';
83
 
84
  $(btn).up(1).down(\'.filter\').value = filter;
85
 
103
  <td>' . $this->__('max. weight:') . '</td><td><input class="input-text" style="width: 100px;" id="shippingconfig_filter_max_weight"/></td>
104
  </tr>
105
  <tr>
106
+ <td colspan="2">' . $this->__('limit to countries: (e.g. "DE" or "DE,AT,CH"). Use ! as first character to exclude from specified countries (e.g. "!DE,AT"). You cannot combine include and exclude right now!') . '</td><td colspan="2"><input class="input-text" style="width: 100px;" id="shippingconfig_filter_countries"/></td>
107
+ </tr>
108
+ <tr>
109
+ <td colspan="2">' . $this->__('limit payment methods: (payment method code, comma-separated, e.g. "checkmo")') . '</td><td colspan="2"><input class="input-text" style="width: 100px;" id="shippingconfig_filter_payment"/></td>
110
  </tr>
111
  </table>
112
  <div style="text-align: right;">
app/code/community/Thebod/Shippingrates/Model/Carrier.php CHANGED
@@ -114,17 +114,29 @@ class Thebod_Shippingrates_Model_Carrier extends Mage_Shipping_Model_Carrier_Abs
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;
125
  }
126
  }
127
-
128
  return $passed;
129
  }
130
 
114
 
115
  case 'countries':
116
  $dest = strtolower($request->getDestCountryId());
117
+ if ($value[0] == '!') {
118
+ $exclude = true;
119
+ $value[0] = ' '; // will be removed with trim() ;-)
120
+ } else {
121
+ $exclude = false;
122
+ }
123
  $allowed = explode(',', strtolower($value));
124
+ foreach ($allowed as $k => $v) {
125
  $allowed[$k] = trim($v);
126
  }
127
+
128
+ if ($exclude) {
129
+ if (in_array($dest, $allowed) && count($allowed)) {
130
+ $passed = false;
131
+ }
132
+ } else {
133
+ if (!in_array($dest, $allowed) && count($allowed)) {
134
+ $passed = false;
135
+ }
136
  }
137
  break;
138
  }
139
  }
 
140
  return $passed;
141
  }
142
 
app/code/community/Thebod/Shippingrates/Model/Observer.php CHANGED
@@ -32,4 +32,66 @@ class Thebod_Shippingrates_Model_Observer
32
  $shippingModel = Mage::getModel('shippingrates/email');
33
  $shippingModel->sendEmailNotification($observer->getOrder());
34
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  }
32
  $shippingModel = Mage::getModel('shippingrates/email');
33
  $shippingModel->sendEmailNotification($observer->getOrder());
34
  }
35
+
36
+ /**
37
+ * check payment filters
38
+ *
39
+ * @param Varien_Event_Observer $observer
40
+ * @return void
41
+ */
42
+ public function paymentMethodIsActive(Varien_Event_Observer $observer)
43
+ {
44
+ if (!Mage::getSingleton('checkout/session')->hasQuote()) {
45
+ return;
46
+ }
47
+
48
+ $shippingMethod = explode('_', $this->_getShippingMethod());
49
+ $shippingConfig = $this->_getShippingConfig();
50
+
51
+ $shippingCarrier = array_shift($shippingMethod);
52
+ $shippingCode = implode('_', $shippingMethod);
53
+
54
+ if ($shippingCarrier != 'shippingrates') {
55
+ return;
56
+ }
57
+
58
+ $configKey = -1;
59
+ foreach ($shippingConfig['code'] as $k => $v) {
60
+ if($v == $shippingCode) {
61
+ $configKey = $k;
62
+ }
63
+ }
64
+ if ($configKey == -1) {
65
+ return;
66
+ }
67
+
68
+ $checkResult = $observer->getEvent()->getResult();
69
+ $method = $observer->getEvent()->getMethodInstance();
70
+
71
+ $filter = explode(';', $shippingConfig['filter'][$configKey]);
72
+ foreach ($filter as $k => $v) {
73
+ $v = explode(':', $v);
74
+ if (isset($v[1]) && ($v[0] == 'payment') && !in_array($method->getCode(), explode(',', $v[1]))) {
75
+ $checkResult->isAvailable = false;
76
+ }
77
+ }
78
+ }
79
+
80
+ /**
81
+ * @return Mage_Shipping_Model_Carrier_Abstract
82
+ */
83
+ protected function _getShippingMethod()
84
+ {
85
+ return Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingMethod();
86
+ }
87
+
88
+ /**
89
+ * @return string
90
+ */
91
+ protected function _getShippingConfig()
92
+ {
93
+ $path = 'carriers/shippingrates/shippingconfig';
94
+
95
+ return unserialize(base64_decode(Mage::getStoreConfig($path, Mage::app()->getStore())));
96
+ }
97
  }
app/code/community/Thebod/Shippingrates/etc/config.xml CHANGED
@@ -29,6 +29,16 @@
29
  </shippingrates>
30
  </observers>
31
  </checkout_type_onepage_save_order_after>
 
 
 
 
 
 
 
 
 
 
32
  </events>
33
  </global>
34
 
29
  </shippingrates>
30
  </observers>
31
  </checkout_type_onepage_save_order_after>
32
+
33
+ <payment_method_is_active>
34
+ <observers>
35
+ <shippingrates>
36
+ <type>singleton</type>
37
+ <class>shippingrates/observer</class>
38
+ <method>paymentMethodIsActive</method>
39
+ </shippingrates>
40
+ </observers>
41
+ </payment_method_is_active>
42
  </events>
43
  </global>
44
 
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Thebod_Shippingrates</name>
4
- <version>1.0.4</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,11 +15,12 @@ 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>* Bugfix</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>14:23:26</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="5354742180f98d13a69deb3a4a9ac89b"/></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>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Thebod_Shippingrates</name>
4
+ <version>1.0.5</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>* Extended country filters (exclude countries)&#xD;
19
+ * Limit to payment methods</notes>
20
  <authors><author><name>Bastian Ike</name><user>auto-converted</user><email>thebod@thebod.de</email></author></authors>
21
+ <date>2012-03-28</date>
22
+ <time>12:16:54</time>
23
+ <contents><target name="magecommunity"><dir name="Thebod"><dir name="Shippingrates"><dir name="Block"><dir name="Adminhtml"><file name="Config.php" hash="c3ff22b4e2f50e0990893a9e2f4e05cb"/></dir></dir><dir name="Helper"><file name="Data.php" hash="5354742180f98d13a69deb3a4a9ac89b"/></dir><dir name="Model"><dir name="System"><file name="Config.php" hash="bf385822d37c0566d8b3cccf4edb9d59"/></dir><file name="Carrier.php" hash="dc2681ec4f83015e239ca8a6a97ccd72"/><file name="Email.php" hash="b38b57d3c7b5a4ab87dbcb5d2ad00ac1"/><file name="Observer.php" hash="c5bec3cf781775b47ef8c0513c53cc37"/></dir><dir name="etc"><file name="config.xml" hash="74bbede3e173d2a184f80051d6dc4838"/><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>
24
  <compatible/>
25
  <dependencies/>
26
  </package>