autoshipping - Version 1.0.0

Version Notes

Stable release

Tested under Magent CE 1.7, 1.6.2, 1.6, 1.5.1

Download this release

Release Info

Developer Tony Hou
Extension autoshipping
Version 1.0.0
Comparing to
See all releases


Code changes from version 0.0.1 to 1.0.0

app/code/community/TonyH/AutoShipping/Model/Observer.php CHANGED
@@ -8,30 +8,33 @@ class TonyH_AutoShipping_Model_Observer {
8
  $quote = $checkout->getQuote();
9
  $shippingAddress = $quote->getShippingAddress();
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  //allow shipping rates recalculation
12
  $shippingAddress->setCollectShippingRates(true);
13
 
 
14
  //rest qutoe item counts so that shipping calculation is based on the correct quantity
15
  $quote->collectTotals();
16
 
17
- if ($quote->getItemsCount()) {
18
 
19
- //first use the default Country code
20
- $country = Mage::getStoreConfig('general/country/default');
21
-
22
- //check if the customer has logged in
23
- if (Mage::getSingleton('customer/session')->isLoggedIn()) {
24
- $customer = Mage::getSingleton('customer/session')->getCustomer();
25
- if ($customer->getPrimaryShippingAddress() && $customer->getPrimaryShippingAddress()->getCountry()) {
26
- //use customer's shipping address country if there's one
27
- $country = $customer->getPrimaryShippingAddress()->getCountry();
28
- }
29
- }
30
-
31
- //only set country if it does not exists already
32
- if (!$shippingAddress->getCountryId()) {
33
- $shippingAddress->setCountryId($country);
34
- }
35
 
36
  //get available rates
37
  $rates = $shippingAddress->getGroupedAllShippingRates();
@@ -43,7 +46,7 @@ class TonyH_AutoShipping_Model_Observer {
43
  $rateToApply = $topRate[0]->getCode();
44
 
45
  try {
46
-
47
  //apply shipping
48
  $shippingAddress->setShippingMethod($rateToApply);
49
  $quote->save();
8
  $quote = $checkout->getQuote();
9
  $shippingAddress = $quote->getShippingAddress();
10
 
11
+ //first use the default Country code
12
+ $country = Mage::getStoreConfig('general/country/default');
13
+
14
+ //check if the customer has logged in
15
+ if (Mage::getSingleton('customer/session')->isLoggedIn()) {
16
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
17
+ if ($customer->getPrimaryShippingAddress() && $customer->getPrimaryShippingAddress()->getCountry()) {
18
+ //use customer's shipping address country if there's one
19
+ $country = $customer->getPrimaryShippingAddress()->getCountry();
20
+ }
21
+ }
22
+
23
+ //only set country if it does not exists already
24
+ if (!$shippingAddress->getCountryId()) {
25
+ $shippingAddress->setCountryId($country);
26
+ }
27
+
28
  //allow shipping rates recalculation
29
  $shippingAddress->setCollectShippingRates(true);
30
 
31
+
32
  //rest qutoe item counts so that shipping calculation is based on the correct quantity
33
  $quote->collectTotals();
34
 
35
+ $shippingAddress->collectShippingRates();
36
 
37
+ if ($quote->getItemsCount()) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  //get available rates
40
  $rates = $shippingAddress->getGroupedAllShippingRates();
46
  $rateToApply = $topRate[0]->getCode();
47
 
48
  try {
49
+
50
  //apply shipping
51
  $shippingAddress->setShippingMethod($rateToApply);
52
  $quote->save();
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>autoshipping</name>
4
- <version>0.0.1</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
@@ -35,12 +35,13 @@ Shipping rates will get recalculated when the customer:&#xD;
35
  add items to cart&#xD;
36
  update items in cart&#xD;
37
  remove items from cart</description>
38
- <notes>First Release.&#xD;
39
- Tested under CE 1.7</notes>
 
40
  <authors><author><name>Tony Hou</name><user>tony2523</user><email>t@tonyhou.com</email></author></authors>
41
- <date>2012-06-09</date>
42
- <time>16:15:14</time>
43
- <contents><target name="magecommunity"><dir name="TonyH"><dir name="AutoShipping"><dir name="Model"><file name="Observer.php" hash="09960487de4c45684bcea027cacc954b"/></dir><dir name="etc"><file name="config.xml" hash="030bff6fb5a13927164d4928979ec6c8"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="TonyH_AutoShipping.xml" hash="37a3f804f1e14b7c72a9dede8f455fcf"/></dir></target></contents>
44
  <compatible/>
45
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
46
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>autoshipping</name>
4
+ <version>1.0.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
35
  add items to cart&#xD;
36
  update items in cart&#xD;
37
  remove items from cart</description>
38
+ <notes>Stable release&#xD;
39
+ &#xD;
40
+ Tested under Magent CE 1.7, 1.6.2, 1.6, 1.5.1</notes>
41
  <authors><author><name>Tony Hou</name><user>tony2523</user><email>t@tonyhou.com</email></author></authors>
42
+ <date>2012-06-10</date>
43
+ <time>10:20:18</time>
44
+ <contents><target name="magecommunity"><dir name="TonyH"><dir name="AutoShipping"><dir name="Model"><file name="Observer.php" hash="488cec0f1537369ec0eda07272fa9196"/></dir><dir name="etc"><file name="config.xml" hash="030bff6fb5a13927164d4928979ec6c8"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="TonyH_AutoShipping.xml" hash="37a3f804f1e14b7c72a9dede8f455fcf"/></dir></target></contents>
45
  <compatible/>
46
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
47
  </package>