Version Notes
Stable release
Tested under Magent CE 1.7, 1.6.2, 1.6, 1.5.1
Added more comments
Download this release
Release Info
Developer | Tony Hou |
Extension | autoshipping |
Version | 1.0.2 |
Comparing to | |
See all releases |
Code changes from version 1.0.1 to 1.0.2
app/code/community/TonyH/AutoShipping/Model/Observer.php
CHANGED
@@ -7,7 +7,7 @@ class TonyH_AutoShipping_Model_Observer {
|
|
7 |
$checkout = Mage::getSingleton('checkout/session');
|
8 |
$quote = $checkout->getQuote();
|
9 |
$shippingAddress = $quote->getShippingAddress();
|
10 |
-
|
11 |
//first use the default Country code
|
12 |
$country = Mage::getStoreConfig('general/country/default');
|
13 |
|
@@ -15,11 +15,12 @@ class TonyH_AutoShipping_Model_Observer {
|
|
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);
|
@@ -27,11 +28,11 @@ class TonyH_AutoShipping_Model_Observer {
|
|
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()) {
|
@@ -50,13 +51,15 @@ class TonyH_AutoShipping_Model_Observer {
|
|
50 |
//apply shipping
|
51 |
$shippingAddress->setShippingMethod($rateToApply);
|
52 |
$quote->save();
|
|
|
|
|
|
|
53 |
$checkout->resetCheckout();
|
54 |
} catch (Mage_Core_Exception $e) {
|
55 |
$checkout->addError($e->getMessage());
|
56 |
} catch (Exception $e) {
|
57 |
-
$checkout->addException(
|
58 |
-
|
59 |
-
);
|
60 |
}
|
61 |
}
|
62 |
}
|
7 |
$checkout = Mage::getSingleton('checkout/session');
|
8 |
$quote = $checkout->getQuote();
|
9 |
$shippingAddress = $quote->getShippingAddress();
|
10 |
+
|
11 |
//first use the default Country code
|
12 |
$country = Mage::getStoreConfig('general/country/default');
|
13 |
|
15 |
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
|
16 |
$customer = Mage::getSingleton('customer/session')->getCustomer();
|
17 |
if ($customer->getPrimaryShippingAddress() && $customer->getPrimaryShippingAddress()->getCountry()) {
|
18 |
+
|
19 |
//use customer's shipping address country if there's one
|
20 |
$country = $customer->getPrimaryShippingAddress()->getCountry();
|
21 |
}
|
22 |
}
|
23 |
+
|
24 |
//only set country if it does not exists already
|
25 |
if (!$shippingAddress->getCountryId()) {
|
26 |
$shippingAddress->setCountryId($country);
|
28 |
|
29 |
//allow shipping rates recalculation
|
30 |
$shippingAddress->setCollectShippingRates(true);
|
31 |
+
|
32 |
|
33 |
//rest qutoe item counts so that shipping calculation is based on the correct quantity
|
34 |
$quote->collectTotals();
|
35 |
+
|
36 |
$shippingAddress->collectShippingRates();
|
37 |
|
38 |
if ($quote->getItemsCount()) {
|
51 |
//apply shipping
|
52 |
$shippingAddress->setShippingMethod($rateToApply);
|
53 |
$quote->save();
|
54 |
+
|
55 |
+
//set checkoutstate to CHECKOUT_STATE_BEGIN
|
56 |
+
//prevent the address from being removed when init() in Mage_Checkout_Model_Cart is called
|
57 |
$checkout->resetCheckout();
|
58 |
} catch (Mage_Core_Exception $e) {
|
59 |
$checkout->addError($e->getMessage());
|
60 |
} catch (Exception $e) {
|
61 |
+
$checkout->addException($e, Mage::helper('checkout')->__('Cannot set shipping method.'));
|
62 |
+
Mage::logException($e);
|
|
|
63 |
}
|
64 |
}
|
65 |
}
|
app/code/community/TonyH/AutoShipping/etc/config.xml
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
<config>
|
3 |
<modules>
|
4 |
<TonyH_AutoShipping>
|
5 |
-
<version>1.0.
|
6 |
</TonyH_AutoShipping>
|
7 |
</modules>
|
8 |
<global>
|
2 |
<config>
|
3 |
<modules>
|
4 |
<TonyH_AutoShipping>
|
5 |
+
<version>1.0.2</version>
|
6 |
</TonyH_AutoShipping>
|
7 |
</modules>
|
8 |
<global>
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>autoshipping</name>
|
4 |
-
<version>1.0.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
7 |
<channel>community</channel>
|
@@ -37,11 +37,13 @@ update items in cart
|
|
37 |
remove items from cart</description>
|
38 |
<notes>Stable release
|
39 |

|
40 |
-
Tested under Magent CE 1.7, 1.6.2, 1.6, 1.5.1
|
|
|
|
|
41 |
<authors><author><name>Tony Hou</name><user>tony2523</user><email>t@tonyhou.com</email></author></authors>
|
42 |
-
<date>2012-
|
43 |
-
<time>
|
44 |
-
<contents><target name="magecommunity"><dir name="TonyH"><dir name="AutoShipping"><dir name="Model"><file name="Observer.php" hash="
|
45 |
<compatible/>
|
46 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
47 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>autoshipping</name>
|
4 |
+
<version>1.0.2</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>
|
37 |
remove items from cart</description>
|
38 |
<notes>Stable release
|
39 |

|
40 |
+
Tested under Magent CE 1.7, 1.6.2, 1.6, 1.5.1
|
41 |
+

|
42 |
+
Added more comments</notes>
|
43 |
<authors><author><name>Tony Hou</name><user>tony2523</user><email>t@tonyhou.com</email></author></authors>
|
44 |
+
<date>2012-07-04</date>
|
45 |
+
<time>09:02:24</time>
|
46 |
+
<contents><target name="magecommunity"><dir name="TonyH"><dir name="AutoShipping"><dir name="Model"><file name="Observer.php" hash="f861d3ac351885ca3cde1261afae7b00"/></dir><dir name="etc"><file name="config.xml" hash="9a7c4674b5c3fd424f8499c537022725"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="TonyH_AutoShipping.xml" hash="37a3f804f1e14b7c72a9dede8f455fcf"/></dir></target></contents>
|
47 |
<compatible/>
|
48 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
49 |
</package>
|