xonu_FGP - Version 2.0.0

Version Notes

Made compatible with Magento versions older than 1.6. Applies to orders created in the backend too. Made compatible with a specific Magento configuration.

Download this release

Release Info

Developer Pawel Kazakow
Extension xonu_FGP
Version 2.0.0
Comparing to
See all releases


Code changes from version 1.0.0 to 2.0.0

app/code/community/Xonu/FGP/Model/Calculation.php CHANGED
@@ -1,30 +1,38 @@
1
  <?php
2
  /**
3
- * @copyright (c) 2012, Pawel Kazakow <support@xonu.de>
4
- * @license http://xonu.de/license/ xonu.de EULA
5
- */
6
  class Xonu_FGP_Model_Calculation extends Mage_Tax_Model_Calculation
7
  {
 
 
 
8
  public function getRateOriginRequest($store = null)
9
  {
10
- // set origin to destination
11
-
12
- $request = new Varien_Object();
13
-
14
- $session = Mage::getSingleton('checkout/session');
15
- if($session->hasQuote()) // getQuote() would lead to infinite loop here when switching currency
16
  {
17
- // use quote destination if quote exists
18
-
19
- $quote = $session->getQuote();
20
- $request = $this->getRateRequest(
21
- $quote->getShippingAddress(),
22
- $quote->getBillingAddress(),
23
- $quote->getCustomerTaxClassId(),
24
- $store
25
- );
26
-
27
- return $request;
 
 
 
 
 
28
  }
29
  else // quote is not available when switching the currency
30
  {
@@ -32,11 +40,126 @@ class Xonu_FGP_Model_Calculation extends Mage_Tax_Model_Calculation
32
  }
33
  }
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  private function getDefaultDestination($store = null)
36
  {
37
- $address = new Varien_Object();
38
  $request = new Varien_Object();
39
-
40
  $address
41
  ->setCountryId(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_COUNTRY, $store))
42
  ->setRegionId(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_REGION, $store))
@@ -44,20 +167,21 @@ class Xonu_FGP_Model_Calculation extends Mage_Tax_Model_Calculation
44
 
45
  $customerTaxClass = null;
46
  $customer = $this->getCustomer();
47
-
48
- if (is_null($customerTaxClass) && $customer) {
49
- $customerTaxClass = $customer->getTaxClassId();
50
- } elseif (($customerTaxClass === false) || !$customer) {
51
- $customerTaxClass = $this->getDefaultCustomerTaxClass($store);
52
- }
53
-
54
- $request
55
- ->setCountryId($address->getCountryId())
56
- ->setRegionId($address->getRegionId())
57
- ->setPostcode($address->getPostcode())
58
- ->setStore($store)
59
- ->setCustomerClassId($customerTaxClass);
60
-
 
61
  return $request;
62
  }
63
  }
1
  <?php
2
  /**
3
+ * @copyright (c) 2013, Pawel Kazakow <support@xonu.de>
4
+ * @license http://xonu.de/license/ xonu.de EULA
5
+ */
6
  class Xonu_FGP_Model_Calculation extends Mage_Tax_Model_Calculation
7
  {
8
+ protected $adminSession = false;
9
+
10
+ // set origin to destination
11
  public function getRateOriginRequest($store = null)
12
  {
13
+ if (Mage::app()->getStore()->isAdmin() || Mage::getDesign()->getArea() == 'adminhtml') {
14
+ $this->adminSession = true; // creating order in the backend
15
+ }
16
+
17
+ $session = $this->getSession();
18
+ if($session->hasQuote() || $this->adminSession) // getQuote() would lead to infinite loop here when switching currency
19
  {
20
+ $quote = $session->getQuote();
21
+ if($quote->getIsActive() || $this->adminSession)
22
+ {
23
+ // use destination of the existing quote as origin if quote exists
24
+ $request = $this->getRateRequest(
25
+ $quote->getShippingAddress(),
26
+ $quote->getBillingAddress(),
27
+ $quote->getCustomerTaxClassId(),
28
+ $store
29
+ );
30
+
31
+ return $request;
32
+ }
33
+ else{
34
+ return $this->getDefaultDestination();
35
+ }
36
  }
37
  else // quote is not available when switching the currency
38
  {
40
  }
41
  }
42
 
43
+ public function getSession()
44
+ {
45
+ if ($this->adminSession) {
46
+ return Mage::getSingleton('adminhtml/session_quote'); // order creation in the backend
47
+ } else {
48
+ return Mage::getSingleton('checkout/session'); // default order creation in the frontend
49
+ }
50
+ }
51
+
52
+ // sometimes it is required to use shipping address from the quote instead of the default address
53
+ public function getRateRequest(
54
+ $shippingAddress = null,
55
+ $billingAddress = null,
56
+ $customerTaxClass = null,
57
+ $store = null)
58
+ {
59
+ if ($shippingAddress === false && $billingAddress === false && $customerTaxClass === false) {
60
+ return $this->getRateOriginRequest($store);
61
+ }
62
+ $address = new Varien_Object();
63
+ $customer = $this->getCustomer();
64
+ $basedOn = Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_BASED_ON, $store);
65
+
66
+ if (($shippingAddress === false && $basedOn == 'shipping')
67
+ || ($billingAddress === false && $basedOn == 'billing')) {
68
+ $basedOn = 'default';
69
+ } else {
70
+ if ((($billingAddress === false || is_null($billingAddress) || !$billingAddress->getCountryId())
71
+ && $basedOn == 'billing')
72
+ || (($shippingAddress === false || is_null($shippingAddress) || !$shippingAddress->getCountryId())
73
+ && $basedOn == 'shipping')
74
+ ){
75
+ $session = Mage::getSingleton('checkout/session');
76
+ if ($customer) {
77
+ $defBilling = $customer->getDefaultBillingAddress();
78
+ $defShipping = $customer->getDefaultShippingAddress();
79
+
80
+ if ($basedOn == 'billing' && $defBilling && $defBilling->getCountryId()) {
81
+ $billingAddress = $defBilling;
82
+ } else if ($basedOn == 'shipping' && $defShipping && $defShipping->getCountryId()) {
83
+ $shippingAddress = $defShipping;
84
+ } else {
85
+ if($session->hasQuote() || $this->adminSession)
86
+ {
87
+ $quote = $session->getQuote();
88
+ $isActive = $quote->getIsActive();
89
+ if($isActive)
90
+ {
91
+ $shippingAddress = $quote->getShippingAddress();
92
+ $billingAddress = $quote->getBillingAddress();
93
+ }
94
+ else{
95
+ $basedOn = 'default';
96
+ }
97
+ }
98
+ else{
99
+ $basedOn = 'default';
100
+ }
101
+ }
102
+ } else {
103
+
104
+ if($session->hasQuote() || $this->adminSession)
105
+ {
106
+ $quote = $session->getQuote();
107
+ $isActive = $quote->getIsActive();
108
+ if($isActive)
109
+ {
110
+ $shippingAddress = $quote->getShippingAddress();
111
+ $billingAddress = $quote->getBillingAddress();
112
+ }
113
+ else {
114
+ $basedOn = 'default';
115
+ }
116
+ }
117
+ else {
118
+ $basedOn = 'default';
119
+ }
120
+ }
121
+ }
122
+ }
123
+ switch ($basedOn) {
124
+ case 'billing':
125
+ $address = $billingAddress;
126
+ break;
127
+ case 'shipping':
128
+ $address = $shippingAddress;
129
+ break;
130
+ case 'origin':
131
+ $address = $this->getRateOriginRequest($store);
132
+ break;
133
+ case 'default':
134
+ $address
135
+ ->setCountryId(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_COUNTRY, $store))
136
+ ->setRegionId(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_REGION, $store))
137
+ ->setPostcode(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_POSTCODE, $store));
138
+ break;
139
+ }
140
+
141
+ if (is_null($customerTaxClass) && $customer) {
142
+ $customerTaxClass = $customer->getTaxClassId();
143
+ } elseif (($customerTaxClass === false) || !$customer) {
144
+ $customerTaxClass = $this->getDefaultCustomerTaxClass($store);
145
+ }
146
+
147
+ $request = new Varien_Object();
148
+ $request
149
+ ->setCountryId($address->getCountryId())
150
+ ->setRegionId($address->getRegionId())
151
+ ->setPostcode($address->getPostcode())
152
+ ->setStore($store)
153
+ ->setCustomerClassId($customerTaxClass);
154
+ return $request;
155
+ }
156
+
157
+
158
  private function getDefaultDestination($store = null)
159
  {
160
+ $address = new Varien_Object();
161
  $request = new Varien_Object();
162
+
163
  $address
164
  ->setCountryId(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_COUNTRY, $store))
165
  ->setRegionId(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_REGION, $store))
167
 
168
  $customerTaxClass = null;
169
  $customer = $this->getCustomer();
170
+
171
+ if (is_null($customerTaxClass) && $customer) {
172
+ $customerTaxClass = $customer->getTaxClassId();
173
+ } elseif (($customerTaxClass === false) || !$customer) {
174
+ $customerTaxClass = $this->getDefaultCustomerTaxClass($store);
175
+ }
176
+
177
+ $request
178
+ ->setCountryId($address->getCountryId())
179
+ ->setRegionId($address->getRegionId())
180
+ ->setPostcode($address->getPostcode())
181
+ ->setStore($store)
182
+ ->setCustomerClassId($customerTaxClass);
183
+
184
+
185
  return $request;
186
  }
187
  }
app/code/community/Xonu/FGP/Model/Session.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @copyright (c) 2013, Pawel Kazakow <support@xonu.de>
4
+ * @license http://xonu.de/license/ xonu.de EULA
5
+ */
6
+
7
+ class Xonu_FGP_Model_Session extends Mage_Checkout_Model_Session {
8
+ // implements hasQuote() method for Magento versions older than 1.6
9
+ public function hasQuote()
10
+ {
11
+ return isset($this->_quote);
12
+ }
13
+ }
app/code/community/Xonu/FGP/etc/config.xml CHANGED
@@ -1,23 +1,28 @@
1
  <?xml version="1.0" encoding="UTF-8"?>
2
  <!--
3
  /**
4
- * @copyright (c) 2012, Pawel Kazakow <support@xonu.de>
5
  * @license http://xonu.de/license/ xonu.de EULA
6
  */
7
  -->
8
  <config>
9
  <modules>
10
  <Xonu_SBE>
11
- <version>1.0.0</version>
12
  </Xonu_SBE>
13
  </modules>
14
  <global>
15
- <models>
16
- <tax>
17
- <rewrite>
18
- <calculation>Xonu_FGP_Model_Calculation</calculation>
19
- </rewrite>
20
- </tax>
21
- </models>
 
 
 
 
 
22
  </global>
23
  </config>
1
  <?xml version="1.0" encoding="UTF-8"?>
2
  <!--
3
  /**
4
+ * @copyright (c) 2013, Pawel Kazakow <support@xonu.de>
5
  * @license http://xonu.de/license/ xonu.de EULA
6
  */
7
  -->
8
  <config>
9
  <modules>
10
  <Xonu_SBE>
11
+ <version>2.0.0</version>
12
  </Xonu_SBE>
13
  </modules>
14
  <global>
15
+ <models>
16
+ <tax>
17
+ <rewrite>
18
+ <calculation>Xonu_FGP_Model_Calculation</calculation>
19
+ </rewrite>
20
+ </tax>
21
+ <checkout>
22
+ <rewrite>
23
+ <session>Xonu_FGP_Model_Session</session>
24
+ </rewrite>
25
+ </checkout>
26
+ </models>
27
  </global>
28
  </config>
app/etc/modules/{xonu_FGP.xml → Xonu_FGP.xml} RENAMED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0" encoding="UTF-8"?>
2
  <!--
3
  /**
4
- * @copyright (c) 2012, Pawel Kazakow <support@xonu.de>
5
  * @license http://xonu.de/license/ xonu.de EULA
6
  */
7
  -->
1
  <?xml version="1.0" encoding="UTF-8"?>
2
  <!--
3
  /**
4
+ * @copyright (c) 2013, Pawel Kazakow <support@xonu.de>
5
  * @license http://xonu.de/license/ xonu.de EULA
6
  */
7
  -->
package.xml CHANGED
@@ -1,22 +1,22 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>xonu_FGP</name>
4
- <version>1.0.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://xonu.de/license/">EULA</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Fixes the gross price instead of the net price.</summary>
10
- <description>By default Magento works with fixed net prices. Tax rate included in the gross price you specify in backend depends on the origin country setting.&#xD;
11
  &#xD;
12
- If your customer's destination country has a higher tax rate a new higher subtotal gross price is calculated for the customer.&#xD;
13
  &#xD;
14
  This extension makes Magento work with fixed gross prices. All customers pay the same subtotal gross price, but get a different tax value shown according to the destination tax rate.</description>
15
- <notes>First release.</notes>
16
  <authors><author><name>Pawel Kazakow</name><user>xonu</user><email>support@xonu.de</email></author></authors>
17
- <date>2012-12-03</date>
18
- <time>15:53:51</time>
19
- <contents><target name="magecommunity"><dir name="Xonu"><dir name="FGP"><dir name="Model"><file name="Calculation.php" hash="d2ab415bf41d2ef8e75aa8cb8a33d5f2"/></dir><dir name="etc"><file name="config.xml" hash="8d43adda7291a6894b85b44e7bb13db1"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="xonu_FGP.xml" hash="684fc8affc328c500bca7232b78636b8"/></dir></target></contents>
20
  <compatible/>
21
- <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
22
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>xonu_FGP</name>
4
+ <version>2.0.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://xonu.de/license/">EULA</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Fixes the gross price instead of the net price.</summary>
10
+ <description>By default Magento works with fixed net prices. Tax rate included in the gross price you set in the backend depends on the origin country setting.&#xD;
11
  &#xD;
12
+ If your customer's destination country has a higher tax rate, a new higher subtotal gross price is calculated for the customer.&#xD;
13
  &#xD;
14
  This extension makes Magento work with fixed gross prices. All customers pay the same subtotal gross price, but get a different tax value shown according to the destination tax rate.</description>
15
+ <notes>Made compatible with Magento versions older than 1.6. Applies to orders created in the backend too. Made compatible with a specific Magento configuration.</notes>
16
  <authors><author><name>Pawel Kazakow</name><user>xonu</user><email>support@xonu.de</email></author></authors>
17
+ <date>2013-06-26</date>
18
+ <time>09:54:11</time>
19
+ <contents><target name="magecommunity"><dir name="Xonu"><dir name="FGP"><dir name="Model"><file name="Calculation.php" hash="53ee9caa49c7875d0f03a6516da4ce9c"/><file name="Session.php" hash="dbb6f4d86ff04fd7f2f50f650853b509"/></dir><dir name="etc"><file name="config.xml" hash="d0e42448ceb3e7528387000478244c0c"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Xonu_FGP.xml" hash="6cd1d4bb483492bbae772413b16a16f0"/></dir></target></contents>
20
  <compatible/>
21
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
22
  </package>