Mage_Exactor_Tax - Version 2014.09.05

Version Notes

Supported Magento 1.5.0.0 - 1.7.x, Magento Enterprise 1.8-1.12.x

Download this release

Release Info

Developer Exactor, Inc.
Extension Mage_Exactor_Tax
Version 2014.09.05
Comparing to
See all releases


Code changes from version 2014.03.04 to 2014.09.05

Files changed (33) hide show
  1. app/code/local/Exactor/Core/Model/Mysql4/MerchantSettings/Collection.php~ +0 -40
  2. app/code/local/{Exactor → ZzzzzExactor}/Core/Helper/SessionCache.php +1 -1
  3. app/code/local/{Exactor → ZzzzzExactor}/Core/Model/ExactorTransaction.php +3 -3
  4. app/code/local/{Exactor → ZzzzzExactor}/Core/Model/MerchantSettings.php +1 -1
  5. app/code/local/{Exactor → ZzzzzExactor}/Core/Model/Mysql4/ExactorTransaction.php +1 -1
  6. app/code/local/{Exactor/Core/Model/Mysql4/MerchantSettings → ZzzzzExactor/Core/Model/Mysql4/ExactorTransaction}/Collection.php +3 -3
  7. app/code/local/{Exactor → ZzzzzExactor}/Core/Model/Mysql4/MerchantSettings.php +1 -1
  8. app/code/local/{Exactor/Core/Model/Mysql4/ExactorTransaction → ZzzzzExactor/Core/Model/Mysql4/MerchantSettings}/Collection.php +3 -3
  9. app/code/local/{Exactor → ZzzzzExactor}/Core/Model/Type/Onepage.php +1 -1
  10. app/code/local/{Exactor → ZzzzzExactor}/Core/etc/config.xml +11 -11
  11. app/code/local/{Exactor → ZzzzzExactor}/ExactorSettings/Block/Form.php +5 -5
  12. app/code/local/{Exactor → ZzzzzExactor}/ExactorSettings/Helper/Data.php +7 -7
  13. app/code/local/{Exactor → ZzzzzExactor}/ExactorSettings/Helper/VersionResolver.php +1 -1
  14. app/code/local/{Exactor → ZzzzzExactor}/ExactorSettings/controllers/Adminhtml/FormController.php +8 -8
  15. app/code/local/{Exactor → ZzzzzExactor}/ExactorSettings/controllers/AjaxController.php +1 -1
  16. app/code/local/{Exactor → ZzzzzExactor}/ExactorSettings/controllers/IndexController.php +2 -2
  17. app/code/local/{Exactor → ZzzzzExactor}/ExactorSettings/etc/config.xml +11 -11
  18. app/code/local/{Exactor → ZzzzzExactor}/ExactorSettings/sql/ExactorSettings_setup/mysql4-install-14.04.2012.php +1 -1
  19. app/code/local/{Exactor → ZzzzzExactor}/ExactorSettings/sql/ExactorSettings_setup/upgrade-2012.06.14-2012.09.25.php +1 -1
  20. app/code/local/{Exactor → ZzzzzExactor}/Sales/Model/Observer.php +179 -91
  21. app/code/local/{Exactor → ZzzzzExactor}/Sales/etc/config.xml +32 -12
  22. app/code/local/{Exactor → ZzzzzExactor}/Tax/Helper/Calculation.php +1 -1
  23. app/code/local/{Exactor → ZzzzzExactor}/Tax/Helper/Mapping.php +298 -165
  24. app/code/local/{Exactor → ZzzzzExactor}/Tax/Model/Sales/Total/Quote/Nominal/Tax.php +1 -1
  25. app/code/local/{Exactor → ZzzzzExactor}/Tax/Model/Sales/Total/Quote/Tax.php +168 -94
  26. app/code/local/{Exactor → ZzzzzExactor}/Tax/etc/config.xml +22 -9
  27. app/design/adminhtml/default/default/layout/exactorsettings.xml +1 -1
  28. app/etc/modules/{Exactor.xml → ZzzzzExactor.xml} +8 -8
  29. lib/ExactorCommons/ExactorCommons.php +7 -0
  30. lib/ExactorCommons/ExactorDomainObjects.php +84 -1
  31. lib/ExactorCommons/Magento.php +7 -7
  32. lib/ExactorCommons/config.php +10 -2
  33. package.xml +4 -4
app/code/local/Exactor/Core/Model/Mysql4/MerchantSettings/Collection.php~ DELETED
@@ -1,40 +0,0 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/osl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * DISCLAIMER
16
- *
17
- * Do not edit or add to this file if you wish to upgrade Magento to newer
18
- * versions in the future. If you wish to customize Magento for your
19
- * needs please refer to http://www.magentocommerce.com for more information.
20
- *
21
- * @category Exactor
22
- * @package Exactor_Exactordetails
23
- * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
- */
26
-
27
- /**
28
- * Exactor Exactordetails collection
29
- *
30
- * @category Exactor
31
- * @package Exactor_Exactordetails
32
- * @author Magento Core Team <core@magentocommerce.com>
33
- */
34
- class Exactor_Core_Model_Mysql4_MerchantSettings_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
35
-
36
- protected function _construct()
37
- {
38
- $this->_init('core/MerchantSettings');
39
- }
40
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/{Exactor → ZzzzzExactor}/Core/Helper/SessionCache.php RENAMED
@@ -5,7 +5,7 @@
5
  * Time: 7:05 PM
6
  */
7
 
8
- class Exactor_Core_Helper_SessionCache extends Mage_Core_Helper_Abstract{
9
  /**
10
  * @var IExactorLogger
11
  */
5
  * Time: 7:05 PM
6
  */
7
 
8
+ class ZzzzzExactor_Core_Helper_SessionCache extends Mage_Core_Helper_Abstract{
9
  /**
10
  * @var IExactorLogger
11
  */
app/code/local/{Exactor → ZzzzzExactor}/Core/Model/ExactorTransaction.php RENAMED
@@ -19,7 +19,7 @@
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category Exactor
22
- * @package Exactor_Exactordetails
23
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
@@ -29,10 +29,10 @@
29
  * Exactor Transaction
30
  *
31
  * @category Exactor
32
- * @package Exactor_ExactorSettings
33
  */
34
 
35
- class Exactor_Core_Model_ExactorTransaction extends Mage_Core_Model_Abstract
36
  {
37
  protected function _construct() {
38
  $this->_init('ExactorTransaction/ExactorTransaction');
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category Exactor
22
+ * @package ZzzzzExactor_Exactordetails
23
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
29
  * Exactor Transaction
30
  *
31
  * @category Exactor
32
+ * @package ZzzzzExactor_ExactorSettings
33
  */
34
 
35
+ class ZzzzzExactor_Core_Model_ExactorTransaction extends Mage_Core_Model_Abstract
36
  {
37
  protected function _construct() {
38
  $this->_init('ExactorTransaction/ExactorTransaction');
app/code/local/{Exactor → ZzzzzExactor}/Core/Model/MerchantSettings.php RENAMED
@@ -5,7 +5,7 @@
5
  * Time: 4:46 PM
6
  */
7
 
8
- class Exactor_Core_Model_MerchantSettings extends Mage_Core_Model_Abstract
9
  {
10
  // Commit Options
11
  const COMMIT_ON_SALES_ORDER = "SL";
5
  * Time: 4:46 PM
6
  */
7
 
8
+ class ZzzzzExactor_Core_Model_MerchantSettings extends Mage_Core_Model_Abstract
9
  {
10
  // Commit Options
11
  const COMMIT_ON_SALES_ORDER = "SL";
app/code/local/{Exactor → ZzzzzExactor}/Core/Model/Mysql4/ExactorTransaction.php RENAMED
@@ -1 +1 @@
1
- <?php
2
  * Magento
3
  *
4
  * NOTICE OF LICENSE
5
  *
6
  * This source file is subject to the Open Software License (OSL 3.0)
7
  * that is bundled with this package in the file LICENSE.txt.
8
  * It is also available through the world-wide-web at this URL:
9
  * http://opensource.org/licenses/osl-3.0.php
10
  * If you did not receive a copy of the license and are unable to
11
  * obtain it through the world-wide-web, please send an email
12
  * to license@magentocommerce.com so we can send you a copy immediately.
13
  *
14
  * DISCLAIMER
15
  *
16
  * Do not edit or add to this file if you wish to upgrade Magento to newer
17
  * versions in the future. If you wish to customize Magento for your
18
  * needs please refer to http://www.magentocommerce.com for more information.
19
  *
20
  * @category Exactor
21
  * @package Exactor_Exactordetails
22
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
23
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
24
  */
25
  * Resource model for Exactor Exactordetails
26
  *
27
  * @category Exactor
28
  * @package Exactor_Exactordetails
29
  * @author Magento Core Team <core@magentocommerce.com>
30
  */
31
 
32
  protected function _construct()
33
  {
34
  $this->_init('ExactorTransaction/ExactorTransaction', 'ID');
35
  }
 
36
  * Magento
37
  *
38
  * NOTICE OF LICENSE
39
  *
40
  * This source file is subject to the Open Software License (OSL 3.0)
41
  * that is bundled with this package in the file LICENSE.txt.
42
  * It is also available through the world-wide-web at this URL:
43
  * http://opensource.org/licenses/osl-3.0.php
44
  * If you did not receive a copy of the license and are unable to
45
  * obtain it through the world-wide-web, please send an email
46
  * to license@magentocommerce.com so we can send you a copy immediately.
47
  *
48
  * DISCLAIMER
49
  *
50
  * Do not edit or add to this file if you wish to upgrade Magento to newer
51
  * versions in the future. If you wish to customize Magento for your
52
  * needs please refer to http://www.magentocommerce.com for more information.
53
  *
54
  * @category Exactor
55
  * @package ZzzzzExactor_Exactordetails
56
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
57
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
58
  */
59
  * Resource model for Exactor Exactordetails
60
  *
61
  * @category Exactor
62
  * @package ZzzzzExactor_Exactordetails
63
  * @author Magento Core Team <core@magentocommerce.com>
64
  */
65
 
66
  protected function _construct()
67
  {
68
  $this->_init('ExactorTransaction/ExactorTransaction', 'ID');
69
  }
 
1
  * Magento
2
  *
3
  * NOTICE OF LICENSE
4
  *
5
  * This source file is subject to the Open Software License (OSL 3.0)
6
  * that is bundled with this package in the file LICENSE.txt.
7
  * It is also available through the world-wide-web at this URL:
8
  * http://opensource.org/licenses/osl-3.0.php
9
  * If you did not receive a copy of the license and are unable to
10
  * obtain it through the world-wide-web, please send an email
11
  * to license@magentocommerce.com so we can send you a copy immediately.
12
  *
13
  * DISCLAIMER
14
  *
15
  * Do not edit or add to this file if you wish to upgrade Magento to newer
16
  * versions in the future. If you wish to customize Magento for your
17
  * needs please refer to http://www.magentocommerce.com for more information.
18
  *
19
  * @category Exactor
20
  * @package Exactor_Exactordetails
21
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
22
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
23
  */
24
  * Resource model for Exactor Exactordetails
25
  *
26
  * @category Exactor
27
  * @package Exactor_Exactordetails
28
  * @author Magento Core Team <core@magentocommerce.com>
29
  */
30
 
31
  protected function _construct()
32
  {
33
  $this->_init('ExactorTransaction/ExactorTransaction', 'ID');
34
  }
35
+ <?php
36
  * Magento
37
  *
38
  * NOTICE OF LICENSE
39
  *
40
  * This source file is subject to the Open Software License (OSL 3.0)
41
  * that is bundled with this package in the file LICENSE.txt.
42
  * It is also available through the world-wide-web at this URL:
43
  * http://opensource.org/licenses/osl-3.0.php
44
  * If you did not receive a copy of the license and are unable to
45
  * obtain it through the world-wide-web, please send an email
46
  * to license@magentocommerce.com so we can send you a copy immediately.
47
  *
48
  * DISCLAIMER
49
  *
50
  * Do not edit or add to this file if you wish to upgrade Magento to newer
51
  * versions in the future. If you wish to customize Magento for your
52
  * needs please refer to http://www.magentocommerce.com for more information.
53
  *
54
  * @category Exactor
55
  * @package ZzzzzExactor_Exactordetails
56
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
57
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
58
  */
59
  * Resource model for Exactor Exactordetails
60
  *
61
  * @category Exactor
62
  * @package ZzzzzExactor_Exactordetails
63
  * @author Magento Core Team <core@magentocommerce.com>
64
  */
65
 
66
  protected function _construct()
67
  {
68
  $this->_init('ExactorTransaction/ExactorTransaction', 'ID');
69
  }
app/code/local/{Exactor/Core/Model/Mysql4/MerchantSettings → ZzzzzExactor/Core/Model/Mysql4/ExactorTransaction}/Collection.php RENAMED
@@ -19,16 +19,16 @@
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category Exactor
22
- * @package Exactor_Exactordetails
23
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
27
 
28
- class Exactor_Core_Model_Mysql4_MerchantSettings_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
29
 
30
  protected function _construct()
31
  {
32
- $this->_init('Exactor_Core_Model_MerchantSettings');
33
  }
34
  }
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category Exactor
22
+ * @package ZzzzzExactor_Exactordetails
23
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
27
 
28
+ class ZzzzzExactor_Core_Model_Mysql4_ExactorTransaction_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
29
 
30
  protected function _construct()
31
  {
32
+ $this->_init('ZzzzzExactor_Core_Model_ExactorTransaction');
33
  }
34
  }
app/code/local/{Exactor → ZzzzzExactor}/Core/Model/Mysql4/MerchantSettings.php RENAMED
@@ -1 +1 @@
1
- <?php
2
  * Magento
3
  *
4
  * NOTICE OF LICENSE
5
  *
6
  * This source file is subject to the Open Software License (OSL 3.0)
7
  * that is bundled with this package in the file LICENSE.txt.
8
  * It is also available through the world-wide-web at this URL:
9
  * http://opensource.org/licenses/osl-3.0.php
10
  * If you did not receive a copy of the license and are unable to
11
  * obtain it through the world-wide-web, please send an email
12
  * to license@magentocommerce.com so we can send you a copy immediately.
13
  *
14
  * DISCLAIMER
15
  *
16
  * Do not edit or add to this file if you wish to upgrade Magento to newer
17
  * versions in the future. If you wish to customize Magento for your
18
  * needs please refer to http://www.magentocommerce.com for more information.
19
  *
20
  * @category Exactor
21
  * @package Exactor_Exactordetails
22
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
23
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
24
  */
25
  * Resource model for Exactor Exactordetails
26
  *
27
  * @category Exactor
28
  * @package Exactor_Exactordetails
29
  * @author Magento Core Team <core@magentocommerce.com>
30
  */
31
 
32
  protected function _construct()
33
  {
34
  $this->_init('MerchantSettings/MerchantSettings', 'ID');
35
  }
 
36
  * Magento
37
  *
38
  * NOTICE OF LICENSE
39
  *
40
  * This source file is subject to the Open Software License (OSL 3.0)
41
  * that is bundled with this package in the file LICENSE.txt.
42
  * It is also available through the world-wide-web at this URL:
43
  * http://opensource.org/licenses/osl-3.0.php
44
  * If you did not receive a copy of the license and are unable to
45
  * obtain it through the world-wide-web, please send an email
46
  * to license@magentocommerce.com so we can send you a copy immediately.
47
  *
48
  * DISCLAIMER
49
  *
50
  * Do not edit or add to this file if you wish to upgrade Magento to newer
51
  * versions in the future. If you wish to customize Magento for your
52
  * needs please refer to http://www.magentocommerce.com for more information.
53
  *
54
  * @category Exactor
55
  * @package ZzzzzExactor_Exactordetails
56
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
57
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
58
  */
59
  * Resource model for Exactor Exactordetails
60
  *
61
  * @category Exactor
62
  * @package ZzzzzExactor_Exactordetails
63
  * @author Magento Core Team <core@magentocommerce.com>
64
  */
65
 
66
  protected function _construct()
67
  {
68
  $this->_init('MerchantSettings/MerchantSettings', 'ID');
69
  }
 
1
  * Magento
2
  *
3
  * NOTICE OF LICENSE
4
  *
5
  * This source file is subject to the Open Software License (OSL 3.0)
6
  * that is bundled with this package in the file LICENSE.txt.
7
  * It is also available through the world-wide-web at this URL:
8
  * http://opensource.org/licenses/osl-3.0.php
9
  * If you did not receive a copy of the license and are unable to
10
  * obtain it through the world-wide-web, please send an email
11
  * to license@magentocommerce.com so we can send you a copy immediately.
12
  *
13
  * DISCLAIMER
14
  *
15
  * Do not edit or add to this file if you wish to upgrade Magento to newer
16
  * versions in the future. If you wish to customize Magento for your
17
  * needs please refer to http://www.magentocommerce.com for more information.
18
  *
19
  * @category Exactor
20
  * @package Exactor_Exactordetails
21
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
22
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
23
  */
24
  * Resource model for Exactor Exactordetails
25
  *
26
  * @category Exactor
27
  * @package Exactor_Exactordetails
28
  * @author Magento Core Team <core@magentocommerce.com>
29
  */
30
 
31
  protected function _construct()
32
  {
33
  $this->_init('MerchantSettings/MerchantSettings', 'ID');
34
  }
35
+ <?php
36
  * Magento
37
  *
38
  * NOTICE OF LICENSE
39
  *
40
  * This source file is subject to the Open Software License (OSL 3.0)
41
  * that is bundled with this package in the file LICENSE.txt.
42
  * It is also available through the world-wide-web at this URL:
43
  * http://opensource.org/licenses/osl-3.0.php
44
  * If you did not receive a copy of the license and are unable to
45
  * obtain it through the world-wide-web, please send an email
46
  * to license@magentocommerce.com so we can send you a copy immediately.
47
  *
48
  * DISCLAIMER
49
  *
50
  * Do not edit or add to this file if you wish to upgrade Magento to newer
51
  * versions in the future. If you wish to customize Magento for your
52
  * needs please refer to http://www.magentocommerce.com for more information.
53
  *
54
  * @category Exactor
55
  * @package ZzzzzExactor_Exactordetails
56
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
57
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
58
  */
59
  * Resource model for Exactor Exactordetails
60
  *
61
  * @category Exactor
62
  * @package ZzzzzExactor_Exactordetails
63
  * @author Magento Core Team <core@magentocommerce.com>
64
  */
65
 
66
  protected function _construct()
67
  {
68
  $this->_init('MerchantSettings/MerchantSettings', 'ID');
69
  }
app/code/local/{Exactor/Core/Model/Mysql4/ExactorTransaction → ZzzzzExactor/Core/Model/Mysql4/MerchantSettings}/Collection.php RENAMED
@@ -19,16 +19,16 @@
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category Exactor
22
- * @package Exactor_Exactordetails
23
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
27
 
28
- class Exactor_Core_Model_Mysql4_ExactorTransaction_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
29
 
30
  protected function _construct()
31
  {
32
- $this->_init('Exactor_Core_Model_ExactorTransaction');
33
  }
34
  }
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category Exactor
22
+ * @package ZzzzzExactor_Exactordetails
23
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
27
 
28
+ class ZzzzzExactor_Core_Model_Mysql4_MerchantSettings_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
29
 
30
  protected function _construct()
31
  {
32
+ $this->_init('ZzzzzExactor_Core_Model_MerchantSettings');
33
  }
34
  }
app/code/local/{Exactor → ZzzzzExactor}/Core/Model/Type/Onepage.php RENAMED
@@ -1,6 +1,6 @@
1
  <?php
2
 
3
- class Exactor_Core_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onepage{
4
  /** @var Mage_Core_Model_Session_Abstract */
5
  private $session;
6
 
1
  <?php
2
 
3
+ class ZzzzzExactor_Core_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onepage{
4
  /** @var Mage_Core_Model_Session_Abstract */
5
  private $session;
6
 
app/code/local/{Exactor → ZzzzzExactor}/Core/etc/config.xml RENAMED
@@ -20,51 +20,51 @@
20
  * needs please refer to http://www.magentocommerce.com for more information.
21
  *
22
  * @category Exactor
23
- * @package Exactor_Tax
24
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
28
  <config>
29
  <modules>
30
- <Exactor_Core>
31
  <version>2012.07.17</version>
32
- </Exactor_Core>
33
  </modules>
34
  <global>
35
  <models>
36
  <checkout>
37
  <rewrite>
38
- <type_onepage>Exactor_Core_Model_Type_Onepage</type_onepage>
39
  </rewrite>
40
  </checkout>
41
  <!-- Settings -->
42
  <MerchantSettings>
43
- <class>Exactor_Core_Model_MerchantSettings</class>
44
  <resourceModel>MerchantSettings_mysql4</resourceModel>
45
  </MerchantSettings>
46
  <MerchantSettings_mysql4>
47
- <class>Exactor_Core_Model_Mysql4</class>
48
  <entities>
49
  <MerchantSettings><table>exactor_account</table></MerchantSettings>
50
  </entities>
51
  </MerchantSettings_mysql4>
52
  <!-- Transaction data -->
53
  <ExactorTransaction>
54
- <class>Exactor_Core_Model_ExactorTransaction</class>
55
  <resourceModel>ExactorTransaction_mysql4</resourceModel>
56
  </ExactorTransaction>
57
  <ExactorTransaction_mysql4>
58
- <class>Exactor_Core_Model_Mysql4</class>
59
  <entities>
60
  <ExactorTransaction><table>exactor_transaction_order</table></ExactorTransaction>
61
  </entities>
62
  </ExactorTransaction_mysql4>
63
  </models>
64
  <helpers>
65
- <Exactor_Core_SessionCache>
66
- <class>Exactor_Core_Helper_SessionCache</class>
67
- </Exactor_Core_SessionCache>
68
  </helpers>
69
  <resources>
70
  <!-- Exactor Merchant Settings -->
20
  * needs please refer to http://www.magentocommerce.com for more information.
21
  *
22
  * @category Exactor
23
+ * @package ZzzzzExactor_Tax
24
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
28
  <config>
29
  <modules>
30
+ <ZzzzzExactor_Core>
31
  <version>2012.07.17</version>
32
+ </ZzzzzExactor_Core>
33
  </modules>
34
  <global>
35
  <models>
36
  <checkout>
37
  <rewrite>
38
+ <type_onepage>ZzzzzExactor_Core_Model_Type_Onepage</type_onepage>
39
  </rewrite>
40
  </checkout>
41
  <!-- Settings -->
42
  <MerchantSettings>
43
+ <class>ZzzzzExactor_Core_Model_MerchantSettings</class>
44
  <resourceModel>MerchantSettings_mysql4</resourceModel>
45
  </MerchantSettings>
46
  <MerchantSettings_mysql4>
47
+ <class>ZzzzzExactor_Core_Model_Mysql4</class>
48
  <entities>
49
  <MerchantSettings><table>exactor_account</table></MerchantSettings>
50
  </entities>
51
  </MerchantSettings_mysql4>
52
  <!-- Transaction data -->
53
  <ExactorTransaction>
54
+ <class>ZzzzzExactor_Core_Model_ExactorTransaction</class>
55
  <resourceModel>ExactorTransaction_mysql4</resourceModel>
56
  </ExactorTransaction>
57
  <ExactorTransaction_mysql4>
58
+ <class>ZzzzzExactor_Core_Model_Mysql4</class>
59
  <entities>
60
  <ExactorTransaction><table>exactor_transaction_order</table></ExactorTransaction>
61
  </entities>
62
  </ExactorTransaction_mysql4>
63
  </models>
64
  <helpers>
65
+ <ZzzzzExactor_Core_SessionCache>
66
+ <class>ZzzzzExactor_Core_Helper_SessionCache</class>
67
+ </ZzzzzExactor_Core_SessionCache>
68
  </helpers>
69
  <resources>
70
  <!-- Exactor Merchant Settings -->
app/code/local/{Exactor → ZzzzzExactor}/ExactorSettings/Block/Form.php RENAMED
@@ -19,7 +19,7 @@
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category Exactor
22
- * @package Exactor_ExactorSettings
23
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
@@ -28,16 +28,16 @@
28
  * ExactorSettings block
29
  *
30
  * @category Exactor
31
- * @package Exactor_ExactorSettingss
32
  */
33
 
34
- class Exactor_ExactorSettings_Block_Form extends Mage_Core_Block_Template {
35
 
36
- //const MODEL_MERCHANT_SETTINGS = "Exactor_Core_Model_MerchantSettings";
37
 
38
  private $storeViewId = 0;
39
 
40
- /** @var \Exactor_ExactorSettings_Helper_Data */
41
  private $exactorSettingsHelper;
42
 
43
  public function __construct() {
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category Exactor
22
+ * @package ZzzzzExactor_ExactorSettings
23
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
28
  * ExactorSettings block
29
  *
30
  * @category Exactor
31
+ * @package ZzzzzExactor_ExactorSettingss
32
  */
33
 
34
+ class ZzzzzExactor_ExactorSettings_Block_Form extends Mage_Core_Block_Template {
35
 
36
+ //const MODEL_MERCHANT_SETTINGS = "ZzzzzExactor_Core_Model_MerchantSettings";
37
 
38
  private $storeViewId = 0;
39
 
40
+ /** @var \ZzzzzExactor_ExactorSettings_Helper_Data */
41
  private $exactorSettingsHelper;
42
 
43
  public function __construct() {
app/code/local/{Exactor → ZzzzzExactor}/ExactorSettings/Helper/Data.php RENAMED
@@ -19,7 +19,7 @@
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category Exactor
22
- * @package Exactor_ExactorSettings
23
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
@@ -30,14 +30,14 @@
30
  * Time: 5:12 PM
31
  */
32
 
33
- class Exactor_ExactorSettings_Helper_Data extends Mage_Core_Helper_Abstract{
34
 
35
- const MODEL_MERCHANT_SETTINGS = "Exactor_Core_Model_MerchantSettings";
36
 
37
  /**
38
  * Returns merchant settings from DB or null if there is no any record
39
  * @param null $storeViewId
40
- * @return Exactor_Core_Model_MerchantSettings|null
41
  */
42
  function loadMerchantSettings($storeViewId=null){
43
  $merchantSettingsModel = $this->loadMerchantSettingsOrEmptyObject($storeViewId);
@@ -46,9 +46,9 @@ class Exactor_ExactorSettings_Helper_Data extends Mage_Core_Helper_Abstract{
46
  }
47
 
48
  /**
49
- * Returns merchant settings from DB or empty Exactor_Core_Model_MerchantSettings if there is no any record
50
  * @param null $storeViewId
51
- * @return Exactor_Core_Model_MerchantSettings|null
52
  */
53
  function loadMerchantSettingsOrEmptyObject($storeViewId=null){
54
  //if ($storeViewId == null) $storeViewId = 1; // 1 - ID of the default store view
@@ -73,7 +73,7 @@ class Exactor_ExactorSettings_Helper_Data extends Mage_Core_Helper_Abstract{
73
  * Returns merchant settings from DB
74
  * or null if there is <strong>no any record</strong> or settings <strong>are not populated</strong>
75
  * @param null $storeViewId
76
- * @return Exactor_Core_Model_MerchantSettings|null
77
  */
78
  public function loadValidMerchantSettings($storeViewId=null){
79
  return $this->loadMerchantSettings($storeViewId);
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category Exactor
22
+ * @package ZzzzzExactor_ExactorSettings
23
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
30
  * Time: 5:12 PM
31
  */
32
 
33
+ class ZzzzzExactor_ExactorSettings_Helper_Data extends Mage_Core_Helper_Abstract{
34
 
35
+ const MODEL_MERCHANT_SETTINGS = "ZzzzzExactor_Core_Model_MerchantSettings";
36
 
37
  /**
38
  * Returns merchant settings from DB or null if there is no any record
39
  * @param null $storeViewId
40
+ * @return ZzzzzExactor_Core_Model_MerchantSettings|null
41
  */
42
  function loadMerchantSettings($storeViewId=null){
43
  $merchantSettingsModel = $this->loadMerchantSettingsOrEmptyObject($storeViewId);
46
  }
47
 
48
  /**
49
+ * Returns merchant settings from DB or empty ZzzzzExactor_Core_Model_MerchantSettings if there is no any record
50
  * @param null $storeViewId
51
+ * @return ZzzzzExactor_Core_Model_MerchantSettings|null
52
  */
53
  function loadMerchantSettingsOrEmptyObject($storeViewId=null){
54
  //if ($storeViewId == null) $storeViewId = 1; // 1 - ID of the default store view
73
  * Returns merchant settings from DB
74
  * or null if there is <strong>no any record</strong> or settings <strong>are not populated</strong>
75
  * @param null $storeViewId
76
+ * @return ZzzzzExactor_Core_Model_MerchantSettings|null
77
  */
78
  public function loadValidMerchantSettings($storeViewId=null){
79
  return $this->loadMerchantSettings($storeViewId);
app/code/local/{Exactor → ZzzzzExactor}/ExactorSettings/Helper/VersionResolver.php RENAMED
@@ -10,7 +10,7 @@
10
  * Time: 2:35 PM
11
  */
12
 
13
- class Exactor_Exactordetails_Helper_VersionResolver extends Mage_Core_Helper_Abstract{
14
  function __construct() {
15
  #call the model function here
16
  $this->magentoVersion = Mage::getVersion();
10
  * Time: 2:35 PM
11
  */
12
 
13
+ class ZzzzzExactor_Exactordetails_Helper_VersionResolver extends Mage_Core_Helper_Abstract{
14
  function __construct() {
15
  #call the model function here
16
  $this->magentoVersion = Mage::getVersion();
app/code/local/{Exactor → ZzzzzExactor}/ExactorSettings/controllers/Adminhtml/FormController.php RENAMED
@@ -19,7 +19,7 @@
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category Exactor
22
- * @package Exactor_ExactorSettings
23
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
@@ -28,12 +28,12 @@
28
  * Exactor Settings controller
29
  *
30
  * @category Exactor
31
- * @package Exactor_ExactorSettings
32
  */
33
 
34
- class Exactor_ExactorSettings_Adminhtml_FormController extends Mage_Adminhtml_Controller_Action
35
  {
36
- const MODEL_MERCHANT_SETTINGS = "Exactor_Core_Model_MerchantSettings";
37
  const FORM_PARAM_CONTAINER = 'exactordetailsform';
38
 
39
  private $EXACTOR_ADDRESS_ERROR_CODES = array(13,14);
@@ -68,7 +68,7 @@ class Exactor_ExactorSettings_Adminhtml_FormController extends Mage_Adminhtml_Co
68
  $this->getLayout()->getBlock('ExactorSettingsForm')->setStoreViewId($storeViewId);
69
  // Additional Actions
70
  if ($this->getRequest()->getParam('action_del_settings',null) != null) {
71
- /** @var Exactor_ExactorSettings_Helper_Data $exactorSettingsHelper */
72
  $exactorSettingsHelper = Mage::helper('ExactorSettings');
73
  $exactorSettingsHelper->removeSettings($this->getRequest()->getParam('action_del_settings',null));
74
  $this->sendSuccess("Successfully cleared settings");
@@ -83,7 +83,7 @@ class Exactor_ExactorSettings_Adminhtml_FormController extends Mage_Adminhtml_Co
83
 
84
  /**
85
  * Will be called before validation
86
- * @param Exactor_Core_Model_MerchantSettings $merchantSettings
87
  * @return void
88
  */
89
  protected function preprocessInput($merchantSettings){
@@ -135,7 +135,7 @@ class Exactor_ExactorSettings_Adminhtml_FormController extends Mage_Adminhtml_Co
135
  public function postAction()
136
  {
137
  $this->setupExactorCommonLibrary();
138
- /** @var Exactor_ExactorSettings_Helper_Data $exactorSettingsHelper */
139
  $exactorSettingsHelper = Mage::helper('ExactorSettings');
140
  $formData = null;
141
  // Validate if we need all needed information from client
@@ -174,7 +174,7 @@ class Exactor_ExactorSettings_Adminhtml_FormController extends Mage_Adminhtml_Co
174
  /**
175
  * Do validation and returns true if there are no any errors,
176
  * Otherwise - returns false and populates $this->validationMessages array with error messages
177
- * @param Exactor_Core_Model_MerchantSettings $merchantSettings
178
  * @return bool
179
  */
180
  private function validate($merchantSettings){
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category Exactor
22
+ * @package ZzzzzExactor_ExactorSettings
23
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
28
  * Exactor Settings controller
29
  *
30
  * @category Exactor
31
+ * @package ZzzzzExactor_ExactorSettings
32
  */
33
 
34
+ class ZzzzzExactor_ExactorSettings_Adminhtml_FormController extends Mage_Adminhtml_Controller_Action
35
  {
36
+ const MODEL_MERCHANT_SETTINGS = "ZzzzzExactor_Core_Model_MerchantSettings";
37
  const FORM_PARAM_CONTAINER = 'exactordetailsform';
38
 
39
  private $EXACTOR_ADDRESS_ERROR_CODES = array(13,14);
68
  $this->getLayout()->getBlock('ExactorSettingsForm')->setStoreViewId($storeViewId);
69
  // Additional Actions
70
  if ($this->getRequest()->getParam('action_del_settings',null) != null) {
71
+ /** @var ZzzzzExactor_ExactorSettings_Helper_Data $exactorSettingsHelper */
72
  $exactorSettingsHelper = Mage::helper('ExactorSettings');
73
  $exactorSettingsHelper->removeSettings($this->getRequest()->getParam('action_del_settings',null));
74
  $this->sendSuccess("Successfully cleared settings");
83
 
84
  /**
85
  * Will be called before validation
86
+ * @param ZzzzzExactor_Core_Model_MerchantSettings $merchantSettings
87
  * @return void
88
  */
89
  protected function preprocessInput($merchantSettings){
135
  public function postAction()
136
  {
137
  $this->setupExactorCommonLibrary();
138
+ /** @var ZzzzzExactor_ExactorSettings_Helper_Data $exactorSettingsHelper */
139
  $exactorSettingsHelper = Mage::helper('ExactorSettings');
140
  $formData = null;
141
  // Validate if we need all needed information from client
174
  /**
175
  * Do validation and returns true if there are no any errors,
176
  * Otherwise - returns false and populates $this->validationMessages array with error messages
177
+ * @param ZzzzzExactor_Core_Model_MerchantSettings $merchantSettings
178
  * @return bool
179
  */
180
  private function validate($merchantSettings){
app/code/local/{Exactor → ZzzzzExactor}/ExactorSettings/controllers/AjaxController.php RENAMED
@@ -5,7 +5,7 @@
5
  * Time: 1:13 PM
6
  */
7
 
8
- class Exactor_ExactorSettings_AjaxController extends Mage_Core_Controller_Front_Action{
9
  const FIELD_EXACTOR_STATUS = "exactor_status";
10
 
11
  /** @var Mage_Core_Model_Session_Abstract */
5
  * Time: 1:13 PM
6
  */
7
 
8
+ class ZzzzzExactor_ExactorSettings_AjaxController extends Mage_Core_Controller_Front_Action{
9
  const FIELD_EXACTOR_STATUS = "exactor_status";
10
 
11
  /** @var Mage_Core_Model_Session_Abstract */
app/code/local/{Exactor → ZzzzzExactor}/ExactorSettings/controllers/IndexController.php RENAMED
@@ -19,12 +19,12 @@
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category Exactor
22
- * @package Exactor_ExactorSettings
23
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
27
- class Exactor_ExactorSettings_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
28
  {
29
  public function loginAction()
30
  {
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category Exactor
22
+ * @package ZzzzzExactor_ExactorSettings
23
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
27
+ class ZzzzzExactor_ExactorSettings_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
28
  {
29
  public function loginAction()
30
  {
app/code/local/{Exactor → ZzzzzExactor}/ExactorSettings/etc/config.xml RENAMED
@@ -20,25 +20,25 @@
20
  * needs please refer to http://www.magentocommerce.com for more information.
21
  *
22
  * @category Exactor
23
- * @package Exactor_Exactordetails
24
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
28
  <config>
29
  <modules>
30
- <Exactor_ExactorSettings>
31
  <version>2012.09.25</version>
32
- </Exactor_ExactorSettings>
33
  </modules>
34
 
35
  <global>
36
  <helpers>
37
  <ExactorSettings>
38
- <class>Exactor_ExactorSettings_Helper</class>
39
  </ExactorSettings>
40
  <ExactorSettings_versionresolver>
41
- <class>Exactor_ExactorSettings_Helper_VersionResolver</class>
42
  </ExactorSettings_versionresolver>
43
  </helpers>
44
 
@@ -47,7 +47,7 @@
47
  <!-- [start] -->
48
  <ExactorSettings_setup>
49
  <setup>
50
- <module>Exactor_ExactorSettings</module>
51
  </setup>
52
  <connection>
53
  <use>core_setup</use>
@@ -58,7 +58,7 @@
58
 
59
  <blocks>
60
  <ExactorSettings>
61
- <class>Exactor_ExactorSettings_Block_Form</class>
62
  </ExactorSettings>
63
  </blocks>
64
 
@@ -69,7 +69,7 @@
69
  <ExactorSettings>
70
  <use>admin</use>
71
  <args>
72
- <module>Exactor_ExactorSettings</module>
73
  <frontName>ExactorSettings</frontName>
74
  </args>
75
  </ExactorSettings>
@@ -79,11 +79,11 @@
79
  <adminhtml>
80
  <!--<translate>
81
  <modules>
82
- <Exactor_adminhtml>
83
  <files>
84
- <ExactorSettings>Exactor_Exactordetails.csv</ExactorSettings>
85
  </files>
86
- </Exactor_adminhtml>
87
  </modules>
88
  </translate>-->
89
 
20
  * needs please refer to http://www.magentocommerce.com for more information.
21
  *
22
  * @category Exactor
23
+ * @package ZzzzzExactor_Exactordetails
24
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
28
  <config>
29
  <modules>
30
+ <ZzzzzExactor_ExactorSettings>
31
  <version>2012.09.25</version>
32
+ </ZzzzzExactor_ExactorSettings>
33
  </modules>
34
 
35
  <global>
36
  <helpers>
37
  <ExactorSettings>
38
+ <class>ZzzzzExactor_ExactorSettings_Helper</class>
39
  </ExactorSettings>
40
  <ExactorSettings_versionresolver>
41
+ <class>ZzzzzExactor_ExactorSettings_Helper_VersionResolver</class>
42
  </ExactorSettings_versionresolver>
43
  </helpers>
44
 
47
  <!-- [start] -->
48
  <ExactorSettings_setup>
49
  <setup>
50
+ <module>ZzzzzExactor_ExactorSettings</module>
51
  </setup>
52
  <connection>
53
  <use>core_setup</use>
58
 
59
  <blocks>
60
  <ExactorSettings>
61
+ <class>ZzzzzExactor_ExactorSettings_Block_Form</class>
62
  </ExactorSettings>
63
  </blocks>
64
 
69
  <ExactorSettings>
70
  <use>admin</use>
71
  <args>
72
+ <module>ZzzzzExactor_ExactorSettings</module>
73
  <frontName>ExactorSettings</frontName>
74
  </args>
75
  </ExactorSettings>
79
  <adminhtml>
80
  <!--<translate>
81
  <modules>
82
+ <ZzzzzExactor_adminhtml>
83
  <files>
84
+ <ExactorSettings>ZzzzzExactor_Exactordetails.csv</ExactorSettings>
85
  </files>
86
+ </ZzzzzExactor_adminhtml>
87
  </modules>
88
  </translate>-->
89
 
app/code/local/{Exactor → ZzzzzExactor}/ExactorSettings/sql/ExactorSettings_setup/mysql4-install-14.04.2012.php RENAMED
@@ -19,7 +19,7 @@
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category Exactor
22
- * @package Exactor_Exactordetails
23
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category Exactor
22
+ * @package ZzzzzExactor_Exactordetails
23
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
app/code/local/{Exactor → ZzzzzExactor}/ExactorSettings/sql/ExactorSettings_setup/upgrade-2012.06.14-2012.09.25.php RENAMED
@@ -19,7 +19,7 @@
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category Exactor
22
- * @package Exactor_Exactordetails
23
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category Exactor
22
+ * @package ZzzzzExactor_Exactordetails
23
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
app/code/local/{Exactor → ZzzzzExactor}/Sales/Model/Observer.php RENAMED
@@ -1,23 +1,27 @@
1
  <?php
 
2
  /**
3
  * User: Dmitry Berezovsky
4
  * Date: 11/28/11
5
  * Time: 12:02 PM
6
  */
 
 
7
 
8
- class Exactor_Sales_Model_Observer {
9
-
10
- /** @var Exactor_ExactorSettings_Helper_Data */
11
  private $exactorSettingsHelper;
12
- /** @var Exactor_Core_Helper_SessionCache */
13
  private $sessionCache;
14
- /** @var ExactorProcessingService*/
15
  private $exactorProcessingService;
16
  /**
17
- * @var Exactor_Tax_Helper_Mapping
18
  */
19
  private $exactorMappingHelper;
20
 
 
 
 
21
  /** @var IExactorLogger */
22
  private $logger;
23
 
@@ -33,7 +37,8 @@ class Exactor_Sales_Model_Observer {
33
  */
34
  private $invoiceProcessingCompatibilityList = array();
35
 
36
- private function setupExactorCommonLibrary(){
 
37
  $libDir = Mage::getBaseDir("lib") . '/ExactorCommons';
38
  require_once($libDir . '/XmlProcessing.php');
39
  require_once($libDir . '/ExactorDomainObjects.php');
@@ -49,27 +54,29 @@ class Exactor_Sales_Model_Observer {
49
  $this->setupExactorCommonLibrary();
50
  $this->logger = ExactorLoggingFactory::getInstance()->getLogger($this);
51
  $this->exactorSettingsHelper = Mage::helper('ExactorSettings');
52
- $this->sessionCache = Mage::helper('Exactor_Core_SessionCache/');
 
53
  $this->exactorMappingHelper = Mage::helper('tax/mapping');
54
  }
55
 
56
  /**
57
  * @param Mage_Sales_Model_Order|null $order
58
- * @return Exactor_Core_Model_MerchantSettings|null
59
  */
60
- private function loadMerchantSettings($order=null){
 
61
  $logger = ExactorLoggingFactory::getInstance()->getLogger($this);
62
  $storeViewId = $this->getStoreViewId($order);
63
  $merchantSettings = $this->exactorSettingsHelper->loadValidMerchantSettings($storeViewId);
64
 
65
- if ($merchantSettings == null){
66
  $logger->error('Settings are not populated.', 'buildExactorProcessingService');
67
  $this->exactorProcessingService = null;
68
  return null;
69
- }else{
70
  $this->exactorProcessingService = ExactorProcessingServiceFactory::getInstance()->buildExactorProcessingService(
71
- $merchantSettings->getMerchantID(),
72
- $merchantSettings->getUserID());
73
  }
74
  return $merchantSettings;
75
  }
@@ -78,9 +85,10 @@ class Exactor_Sales_Model_Observer {
78
  * @param Mage_Sales_Model_Order_Invoice $invoice
79
  * @return null|string
80
  */
81
- private function getInvoiceIncrementId($invoice) {
 
82
  if ($invoice->getIncrementId() == null) {
83
- try{
84
  $entityType = Mage::getModel('eav/entity_type')->loadByCode("invoice");
85
  $invoice->setIncrementId($entityType->fetchNewIncrementId($invoice->getStoreId()));
86
  } catch (Exception $e) {
@@ -93,17 +101,18 @@ class Exactor_Sales_Model_Observer {
93
 
94
  /**
95
  * @param Mage_Sales_Model_Order_Invoice $invoice
96
- * @param Exactor_Core_Model_MerchantSettings $merchantSettings
97
  * @return null
98
  */
99
- private function commitTransactionForInvoice($invoice, $merchantSettings) {
 
100
  try {
101
- if (!$this->underEffectiveDate($merchantSettings->getEffectiveDate(), $invoice->getOrder()->getCreatedAt())){
102
- $this->logger->info("Order " . $invoice->getOrder()->getIncrementId() ." is not under effective date. Skipping.", "commitTransactionForInvoice");
103
  return;
104
  }
105
  $exactorProcessingService = ExactorProcessingServiceFactory::getInstance()
106
- ->buildExactorProcessingService($merchantSettings->getMerchantID(), $merchantSettings->getUserID());
107
  $invoiceRequests = $this->exactorMappingHelper->buildInvoiceRequestForMagentoInvoice($invoice, $merchantSettings);
108
  foreach ($invoiceRequests as $invoiceRequest) {
109
  $config = ExactorPluginConfig::getInstance();
@@ -113,7 +122,9 @@ class Exactor_Sales_Model_Observer {
113
  return null;
114
  }
115
  }
116
- $exactorProcessingService->partialPayment($invoiceRequest, new DateTime(), $this->getInvoiceIncrementId($invoice));
 
 
117
  }
118
  } catch (Exception $e) {
119
  $this->logger->error("Can't commit transaction. See details above. :" . $e->getMessage() . $e->getTraceAsString(), 'commitTransactionForInvoice');
@@ -122,15 +133,16 @@ class Exactor_Sales_Model_Observer {
122
 
123
  /**
124
  * @param Mage_Sales_Model_Order_Invoice $invoice
125
- * @param Exactor_Core_Model_MerchantSettings $merchantSettings
126
  * @return null
127
  */
128
- private function refundTransactionForInvoice($invoice, $merchantSettings) {
 
129
  try {
130
  $exactorProcessingService = ExactorProcessingServiceFactory::getInstance()
131
- ->buildExactorProcessingService($merchantSettings->getMerchantID(), $merchantSettings->getUserID());
132
- if (!$this->underEffectiveDate($merchantSettings->getEffectiveDate(), $invoice->getOrder()->getCreatedAt())){
133
- $this->logger->info("Order " . $invoice->getOrder()->getIncrementId() ." is not under effective date. Skipping.", "refundTransactionForInvoice");
134
  return;
135
  }
136
  $invoiceRequests = $this->exactorMappingHelper->buildInvoiceRequestForMagentoInvoice($invoice, $merchantSettings);
@@ -151,11 +163,12 @@ class Exactor_Sales_Model_Observer {
151
 
152
  /**
153
  * @param Mage_Sales_Model_Order $order
154
- * @param Exactor_Core_Model_MerchantSettings $merchantSettings
155
  */
156
- private function refundAllInvoicesForOrder($order, $merchantSettings) {
157
- try{
158
- foreach ($order->getInvoiceCollection() as $invoice){
 
159
  $this->refundTransactionForInvoice($invoice, $merchantSettings);
160
  }
161
  } catch (Exception $e) {
@@ -163,10 +176,11 @@ class Exactor_Sales_Model_Observer {
163
  }
164
  }
165
 
166
- private function refundTransactionForOrder($order, $merchantSettings){
167
- try{
 
168
  $exactorProcessingService = ExactorProcessingServiceFactory::getInstance()
169
- ->buildExactorProcessingService($merchantSettings->getMerchantID(), $merchantSettings->getUserID());
170
  $config = ExactorPluginConfig::getInstance();
171
  if ($config->getFeatureConfig()->isFeatureEnabled(EXACTOR_CONFIG_FEATURE_TRN_FILTER)) {
172
  if (!$this->exactorMappingHelper->isAllowedLocation($config->get(EXACTOR_CONFIG_TRN_FILTER), $order->getShippingAddress())) {
@@ -175,7 +189,7 @@ class Exactor_Sales_Model_Observer {
175
  }
176
  }
177
  $exactorProcessingService->refundTransactionForOrder($order->getIncrementId());
178
- }catch (Exception $e){
179
  $this->logger->error("Can't commit transaction. See details above.", 'refundTransactionForOrder');
180
  }
181
  }
@@ -187,17 +201,18 @@ class Exactor_Sales_Model_Observer {
187
  * @param Mage_Sales_Model_Order $order
188
  * @return bool
189
  */
190
- private function processFinishedOrder($order){
 
191
  $merchantSettings = $this->loadMerchantSettings($order);
192
- if ($merchantSettings==null) return false;
193
- if (!$this->underEffectiveDate($merchantSettings->getEffectiveDate(), $order->getCreatedAt())){
194
- $this->logger->info("Order " . $order->getIncrementId() ." is not under effective date. Skipping.",
195
  "processFinishedOrder");
196
  }
197
  $exactorProcessingService = ExactorProcessingServiceFactory::getInstance()
198
- ->buildExactorProcessingService($merchantSettings->getMerchantID(), $merchantSettings->getUserID());
199
  $transactionInfo = $this->sessionCache->popTransactionInfo();
200
- if ($transactionInfo == null){
201
  $this->logger->error('Nothing to process. There is no transaction in the session cache', 'processFinishedOrder');
202
  return false;
203
  }
@@ -205,11 +220,10 @@ class Exactor_Sales_Model_Observer {
205
  $orderId = $order->getIncrementId();
206
  $transactionInfo->setShoppingCartTrnId($orderId);
207
  // Push latest transaction from the Session to DB
208
- $this->exactorProcessingService->getPluginCallback()->saveTransactionInfo($transactionInfo,$transactionInfo->getSignature());
209
  // if CommitOption is set up to commit on sales order - do commit the
210
  // latest transaction from the session storage
211
- if ($merchantSettings->getCommitOption() == Exactor_Core_Model_MerchantSettings::COMMIT_ON_SALES_ORDER)
212
- {
213
  $this->logger->info("Commiting transaction for order $orderId - " . $transactionInfo->getExactorTrnId(), 'processFinishedOrder');
214
  try {
215
  $invoiceRequests = $this->exactorMappingHelper->buildInvoiceRequestForMagentoOrder($order, $merchantSettings);
@@ -219,6 +233,7 @@ class Exactor_Sales_Model_Observer {
219
  }
220
  //$this->exactorProcessingService->commitExistingInvoiceForOrder($orderId);
221
  }
 
222
  return true;
223
  }
224
 
@@ -226,16 +241,17 @@ class Exactor_Sales_Model_Observer {
226
  * Returns TaxResponse on success, and null - otherwise.
227
  *
228
  * @param \Mage_Sales_Model_Order $order
229
- * @param \Exactor_Core_Model_MerchantSettings $merchantSettings
230
  * @return TaxResponseType
231
  */
232
- public function commitTransactionForOrder($order, $merchantSettings) {
 
233
  $exactorProcessingService = ExactorProcessingServiceFactory::getInstance()
234
- ->buildExactorProcessingService($merchantSettings->getMerchantID(), $merchantSettings->getUserID());
235
  try {
236
- if (!$this->underEffectiveDate($merchantSettings->getEffectiveDate(), $order->getCreatedAt())){
237
- $this->logger->info("Order " . $order->getIncrementId() ." is not under effective date. Skipping.",
238
- "commitTransactionForOrder");
239
  }
240
  $exactorTransaction = $exactorProcessingService->loadTransactionInfoByOrderId($order->getIncrementId());
241
  $invoiceRequests = $this->exactorMappingHelper->buildInvoiceRequestForMagentoOrder($order, $merchantSettings);
@@ -252,7 +268,7 @@ class Exactor_Sales_Model_Observer {
252
  $exactorTransaction->setIsCommited(true);
253
  $exactorTransaction->setExactorTrnId($taxResponse->getFirstCommit()->getTransactionId());
254
  $exactorProcessingService->getPluginCallback()
255
- ->saveTransactionInfo($exactorTransaction, $exactorTransaction->getSignature());
256
  return $taxResponse;
257
  } else {
258
  $this->logger->error("New order should be represented by the single exactor transaction. Is", 'processFinishedOrder');
@@ -266,13 +282,14 @@ class Exactor_Sales_Model_Observer {
266
  /**
267
  * @param Varien_Event_Observer $observer
268
  */
269
- public function handleAllOrdersCompleted($observer){
 
270
  $this->logger->trace('called', 'handleAllOrdersCompleted');
271
  if (is_array($observer->getOrders()))
272
  $orders = array_reverse($observer->getOrders());
273
  else
274
  $orders = array($observer->getOrder());
275
- foreach($orders as $order){
276
  $this->processFinishedOrder($order);
277
  }
278
  // We need to clean the session storage here
@@ -282,17 +299,18 @@ class Exactor_Sales_Model_Observer {
282
  /**
283
  * @param Mage_Sales_Model_Order_Creditmemo $creditMemo
284
  */
285
- private function partialRefund($creditMemo){
 
286
  $merchantSettings = $this->loadMerchantSettings($creditMemo->getOrder());
287
- if ($merchantSettings==null) return;
288
- if (!$this->underEffectiveDate($merchantSettings->getEffectiveDate(), $creditMemo->getOrder()->getCreatedAt())){
289
- $this->logger->info("Order " . $creditMemo->getOrder()->getIncrementId() ." is not under effective date. Skipping.", "partialRefund");
290
  return;
291
  }
292
  $invoiceRequests = $this->exactorMappingHelper->buildInvoiceRequestsForCreditMemo($creditMemo, $merchantSettings);
293
  $config = ExactorPluginConfig::getInstance();
294
  $exactorProcessingService = ExactorProcessingServiceFactory::getInstance()->buildExactorProcessingService($merchantSettings->getMerchantID(),
295
- $merchantSettings->getUserID());
296
  foreach ($invoiceRequests as $invoice) {
297
  if ($config->getFeatureConfig()->isFeatureEnabled(EXACTOR_CONFIG_FEATURE_TRN_FILTER)) {
298
  if (!$this->exactorMappingHelper->isAllowedLocation($config->get(EXACTOR_CONFIG_TRN_FILTER), $invoice->getShipTo())) {
@@ -308,12 +326,52 @@ class Exactor_Sales_Model_Observer {
308
  // =================================== EVENT HANDLERS =================================================================
309
  // ====================================================================================================================
310
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
311
  /**
312
  * Event will be fired once new order has been created
313
  * @param Varien_Event_Observer $observer
314
  * @return void
315
  */
316
- public function handleCreatedOrder($observer){
 
317
  $this->logger->trace('called', 'handleCreatedOrder');
318
  if ($this->shouldOrderProcessingRunInCompatibilityMode($observer->getOrder())) {
319
  $this->logger->info('Order processing started in compatibility mode.', 'handleCreatedOrder');
@@ -322,9 +380,11 @@ class Exactor_Sales_Model_Observer {
322
  }
323
  }
324
 
325
- private function shouldOrderProcessingRunInCompatibilityMode($order) {
 
326
  if ($order->getPayment() != null &&
327
- strpos($order->getPayment()->getMethod(), "paypal_express") !== false){
 
328
  $this->logger->info('PayPal order detected', 'shouldOrderProcessingRunInCompatibilityMode');
329
  return true;
330
  }
@@ -335,7 +395,7 @@ class Exactor_Sales_Model_Observer {
335
  }
336
 
337
  $mageEdition = Mage::getEdition();
338
- if ($mageEdition == Mage::EDITION_ENTERPRISE && $mageVersionInfo['major']==1 && $mageVersionInfo['minor'] == 8){
339
  $this->logger->info('Magento Enterprise detected', 'shouldOrderProcessingRunInCompatibilityMode');
340
  return true;
341
  }
@@ -345,21 +405,22 @@ class Exactor_Sales_Model_Observer {
345
  /**
346
  * @param Varien_Event_Observer $observer
347
  */
348
- public function handleNewCreditMemo(Varien_Event_Observer $observer){
 
349
  $this->logger->trace('called', 'handleNewCreditMemo');
350
  $merchantSettings = $this->loadMerchantSettings($observer->getCreditmemo()->getOrder());
351
- if ($merchantSettings==null) return;
352
  // TODO: What about COMMIT on shipment
353
- if ($merchantSettings->getCommitOption() != Exactor_Core_Model_MerchantSettings::COMMIT_NEVER) {
354
- if ($merchantSettings->getCommitOption() == Exactor_Core_Model_MerchantSettings::COMMIT_ON_SHIPMENT) {
355
  $exactorTrnInfo = $this->exactorProcessingService->loadTransactionInfoByOrderId(
356
  $observer->getCreditmemo()->getOrder()->getIncrementId());
357
- if ($exactorTrnInfo != null && $exactorTrnInfo->getIsCommited()){
358
- try{
359
  $this->refundTransactionForOrder($observer->getCreditmemo()->getOrder(), $merchantSettings);
360
  $exactorTrnInfo->setIsCommited(false);
361
  $this->exactorProcessingService->getPluginCallback()
362
- ->saveTransactionInfo($exactorTrnInfo, $exactorTrnInfo->getSignature());
363
  } catch (Exception $e) {
364
  $this->logger->error("Can't refund credit memo", 'handleNewCreditMemo');
365
  }
@@ -370,11 +431,12 @@ class Exactor_Sales_Model_Observer {
370
  }
371
  }
372
 
373
- public function handleCancelOrder(Varien_Event_Observer $observer){
 
374
  $this->logger->trace('called', 'handleCancelOrder');
375
  $merchantSettings = $this->loadMerchantSettings($observer->getPayment()->getOrder());
376
- if ($merchantSettings==null) return;
377
- if ($merchantSettings->getCommitOption() == Exactor_Core_Model_MerchantSettings::COMMIT_ON_INVOICE) {
378
  // Just do nothing
379
  //$this->refundAllInvoicesForOrder($observer->getPayment()->getOrder(), $merchantSettings);
380
  } else {
@@ -382,45 +444,70 @@ class Exactor_Sales_Model_Observer {
382
  }
383
  }
384
 
385
- public function handleNewShipment(Varien_Event_Observer $observer){
 
386
  $this->logger->trace('called', 'handleNewShipment');
387
  $merchantSettings = $this->loadMerchantSettings($observer->getShipment()->getOrder());
388
- if ($merchantSettings==null) return;
389
- if ($merchantSettings->getCommitOption() == Exactor_Core_Model_MerchantSettings::COMMIT_ON_SHIPMENT){
390
  $this->commitTransactionForOrder($observer->getShipment()->getOrder(), $merchantSettings);
391
  }
392
  }
393
-
394
- public function handleCancelInvoice(Varien_Event_Observer $observer){
 
395
  $this->logger->trace('called', 'handleNewInvoice');
396
  $merchantSettings = $this->loadMerchantSettings($observer->getInvoice()->getOrder());
397
- if ($merchantSettings==null) return;
398
- if ($merchantSettings->getCommitOption() == Exactor_Core_Model_MerchantSettings::COMMIT_ON_INVOICE){
399
  $this->refundTransactionForInvoice($observer->getInvoice(), $merchantSettings);
400
  }
401
  }
402
 
403
- public function handleNewInvoice(Varien_Event_Observer $observer){
 
 
 
 
404
  $this->logger->trace('called', 'handleNewInvoice');
405
- $merchantSettings = $this->loadMerchantSettings($observer->getInvoice()->getOrder());
406
- if ($merchantSettings==null) return;
407
- // TODO: REMOVE THIS COMMENTED CODE
408
- //$incrementOrderId = $observer->getInvoice()->getOrder()->getIncrementId();
409
- if ($merchantSettings->getCommitOption() == Exactor_Core_Model_MerchantSettings::COMMIT_ON_INVOICE
410
- /* && !in_array($incrementOrderId, $this->invoiceProcessingCompatibilityList)*/ ){ // If flag is set this means that invoice has been handled already in compatibility mode.
411
- $this->commitTransactionForInvoice($observer->getInvoice(), $merchantSettings);
 
 
 
 
 
 
 
 
412
  /*$this->invoiceProcessingCompatibilityList[]= $incrementOrderId;*/
413
  }
414
  }
415
 
 
 
 
 
 
 
 
 
 
 
416
  /**
417
  * Checks if target date is under effective date, false - otherwise.
418
  *
419
  * @param $effectiveDate - Effective date
420
- * @param $targetDate - Date to check
421
  * @return boolean
422
  */
423
- private function underEffectiveDate($effectiveDate, $targetDate){
 
424
  $effectiveTimestamp = strtotime($effectiveDate);
425
  $targetTimestamp = strtotime('now');
426
  if ($targetDate != null) {
@@ -433,9 +520,10 @@ class Exactor_Sales_Model_Observer {
433
  * @param Mage_Sales_Model_Order|null $order
434
  * @return int
435
  */
436
- public function getStoreViewId($order=null){
 
437
  $storeId = Mage::app()->getStore()->getId();
438
- if ($order!=null){
439
  $storeId = $order->getStoreId() ? $order->getStoreId() : 0;
440
  }
441
  return $storeId != 0 ? $storeId : Mage::app()->getDefaultStoreView()->getId();
1
  <?php
2
+
3
  /**
4
  * User: Dmitry Berezovsky
5
  * Date: 11/28/11
6
  * Time: 12:02 PM
7
  */
8
+ class ZzzzzExactor_Sales_Model_Observer
9
+ {
10
 
11
+ /** @var ZzzzzExactor_ExactorSettings_Helper_Data */
 
 
12
  private $exactorSettingsHelper;
13
+ /** @var ZzzzzExactor_Core_Helper_SessionCache */
14
  private $sessionCache;
15
+ /** @var ExactorProcessingService */
16
  private $exactorProcessingService;
17
  /**
18
+ * @var ZzzzzExactor_Tax_Helper_Mapping
19
  */
20
  private $exactorMappingHelper;
21
 
22
+ /** @var Mage_Core_Model_Session_Abstract */
23
+ private $session;
24
+
25
  /** @var IExactorLogger */
26
  private $logger;
27
 
37
  */
38
  private $invoiceProcessingCompatibilityList = array();
39
 
40
+ private function setupExactorCommonLibrary()
41
+ {
42
  $libDir = Mage::getBaseDir("lib") . '/ExactorCommons';
43
  require_once($libDir . '/XmlProcessing.php');
44
  require_once($libDir . '/ExactorDomainObjects.php');
54
  $this->setupExactorCommonLibrary();
55
  $this->logger = ExactorLoggingFactory::getInstance()->getLogger($this);
56
  $this->exactorSettingsHelper = Mage::helper('ExactorSettings');
57
+ $this->sessionCache = Mage::helper('ZzzzzExactor_Core_SessionCache/');
58
+ $this->session = Mage::getSingleton('core/session', array('name' => 'frontend'));
59
  $this->exactorMappingHelper = Mage::helper('tax/mapping');
60
  }
61
 
62
  /**
63
  * @param Mage_Sales_Model_Order|null $order
64
+ * @return ZzzzzExactor_Core_Model_MerchantSettings|null
65
  */
66
+ private function loadMerchantSettings($order = null)
67
+ {
68
  $logger = ExactorLoggingFactory::getInstance()->getLogger($this);
69
  $storeViewId = $this->getStoreViewId($order);
70
  $merchantSettings = $this->exactorSettingsHelper->loadValidMerchantSettings($storeViewId);
71
 
72
+ if ($merchantSettings == null) {
73
  $logger->error('Settings are not populated.', 'buildExactorProcessingService');
74
  $this->exactorProcessingService = null;
75
  return null;
76
+ } else {
77
  $this->exactorProcessingService = ExactorProcessingServiceFactory::getInstance()->buildExactorProcessingService(
78
+ $merchantSettings->getMerchantID(),
79
+ $merchantSettings->getUserID());
80
  }
81
  return $merchantSettings;
82
  }
85
  * @param Mage_Sales_Model_Order_Invoice $invoice
86
  * @return null|string
87
  */
88
+ private function getInvoiceIncrementId($invoice)
89
+ {
90
  if ($invoice->getIncrementId() == null) {
91
+ try {
92
  $entityType = Mage::getModel('eav/entity_type')->loadByCode("invoice");
93
  $invoice->setIncrementId($entityType->fetchNewIncrementId($invoice->getStoreId()));
94
  } catch (Exception $e) {
101
 
102
  /**
103
  * @param Mage_Sales_Model_Order_Invoice $invoice
104
+ * @param ZzzzzExactor_Core_Model_MerchantSettings $merchantSettings
105
  * @return null
106
  */
107
+ private function commitTransactionForInvoice($invoice, $merchantSettings)
108
+ {
109
  try {
110
+ if (!$this->underEffectiveDate($merchantSettings->getEffectiveDate(), $invoice->getOrder()->getCreatedAt())) {
111
+ $this->logger->info("Order " . $invoice->getOrder()->getIncrementId() . " is not under effective date. Skipping.", "commitTransactionForInvoice");
112
  return;
113
  }
114
  $exactorProcessingService = ExactorProcessingServiceFactory::getInstance()
115
+ ->buildExactorProcessingService($merchantSettings->getMerchantID(), $merchantSettings->getUserID());
116
  $invoiceRequests = $this->exactorMappingHelper->buildInvoiceRequestForMagentoInvoice($invoice, $merchantSettings);
117
  foreach ($invoiceRequests as $invoiceRequest) {
118
  $config = ExactorPluginConfig::getInstance();
122
  return null;
123
  }
124
  }
125
+ $this->_lastInvoiceRequest = $invoiceRequest;
126
+ $this->_lastIncrementId = $this->getInvoiceIncrementId($invoice);
127
+ $exactorProcessingService->partialPayment($invoiceRequest, new DateTime(), $this->_lastIncrementId);
128
  }
129
  } catch (Exception $e) {
130
  $this->logger->error("Can't commit transaction. See details above. :" . $e->getMessage() . $e->getTraceAsString(), 'commitTransactionForInvoice');
133
 
134
  /**
135
  * @param Mage_Sales_Model_Order_Invoice $invoice
136
+ * @param ZzzzzExactor_Core_Model_MerchantSettings $merchantSettings
137
  * @return null
138
  */
139
+ private function refundTransactionForInvoice($invoice, $merchantSettings)
140
+ {
141
  try {
142
  $exactorProcessingService = ExactorProcessingServiceFactory::getInstance()
143
+ ->buildExactorProcessingService($merchantSettings->getMerchantID(), $merchantSettings->getUserID());
144
+ if (!$this->underEffectiveDate($merchantSettings->getEffectiveDate(), $invoice->getOrder()->getCreatedAt())) {
145
+ $this->logger->info("Order " . $invoice->getOrder()->getIncrementId() . " is not under effective date. Skipping.", "refundTransactionForInvoice");
146
  return;
147
  }
148
  $invoiceRequests = $this->exactorMappingHelper->buildInvoiceRequestForMagentoInvoice($invoice, $merchantSettings);
163
 
164
  /**
165
  * @param Mage_Sales_Model_Order $order
166
+ * @param ZzzzzExactor_Core_Model_MerchantSettings $merchantSettings
167
  */
168
+ private function refundAllInvoicesForOrder($order, $merchantSettings)
169
+ {
170
+ try {
171
+ foreach ($order->getInvoiceCollection() as $invoice) {
172
  $this->refundTransactionForInvoice($invoice, $merchantSettings);
173
  }
174
  } catch (Exception $e) {
176
  }
177
  }
178
 
179
+ private function refundTransactionForOrder($order, $merchantSettings)
180
+ {
181
+ try {
182
  $exactorProcessingService = ExactorProcessingServiceFactory::getInstance()
183
+ ->buildExactorProcessingService($merchantSettings->getMerchantID(), $merchantSettings->getUserID());
184
  $config = ExactorPluginConfig::getInstance();
185
  if ($config->getFeatureConfig()->isFeatureEnabled(EXACTOR_CONFIG_FEATURE_TRN_FILTER)) {
186
  if (!$this->exactorMappingHelper->isAllowedLocation($config->get(EXACTOR_CONFIG_TRN_FILTER), $order->getShippingAddress())) {
189
  }
190
  }
191
  $exactorProcessingService->refundTransactionForOrder($order->getIncrementId());
192
+ } catch (Exception $e) {
193
  $this->logger->error("Can't commit transaction. See details above.", 'refundTransactionForOrder');
194
  }
195
  }
201
  * @param Mage_Sales_Model_Order $order
202
  * @return bool
203
  */
204
+ private function processFinishedOrder($order)
205
+ {
206
  $merchantSettings = $this->loadMerchantSettings($order);
207
+ if ($merchantSettings == null) return false;
208
+ if (!$this->underEffectiveDate($merchantSettings->getEffectiveDate(), $order->getCreatedAt())) {
209
+ $this->logger->info("Order " . $order->getIncrementId() . " is not under effective date. Skipping.",
210
  "processFinishedOrder");
211
  }
212
  $exactorProcessingService = ExactorProcessingServiceFactory::getInstance()
213
+ ->buildExactorProcessingService($merchantSettings->getMerchantID(), $merchantSettings->getUserID());
214
  $transactionInfo = $this->sessionCache->popTransactionInfo();
215
+ if ($transactionInfo == null) {
216
  $this->logger->error('Nothing to process. There is no transaction in the session cache', 'processFinishedOrder');
217
  return false;
218
  }
220
  $orderId = $order->getIncrementId();
221
  $transactionInfo->setShoppingCartTrnId($orderId);
222
  // Push latest transaction from the Session to DB
223
+ $this->exactorProcessingService->getPluginCallback()->saveTransactionInfo($transactionInfo, $transactionInfo->getSignature());
224
  // if CommitOption is set up to commit on sales order - do commit the
225
  // latest transaction from the session storage
226
+ if ($merchantSettings->getCommitOption() == ZzzzzExactor_Core_Model_MerchantSettings::COMMIT_ON_SALES_ORDER) {
 
227
  $this->logger->info("Commiting transaction for order $orderId - " . $transactionInfo->getExactorTrnId(), 'processFinishedOrder');
228
  try {
229
  $invoiceRequests = $this->exactorMappingHelper->buildInvoiceRequestForMagentoOrder($order, $merchantSettings);
233
  }
234
  //$this->exactorProcessingService->commitExistingInvoiceForOrder($orderId);
235
  }
236
+ $this->session->setLastInvoiceResponse(null);
237
  return true;
238
  }
239
 
241
  * Returns TaxResponse on success, and null - otherwise.
242
  *
243
  * @param \Mage_Sales_Model_Order $order
244
+ * @param \ZzzzzExactor_Core_Model_MerchantSettings $merchantSettings
245
  * @return TaxResponseType
246
  */
247
+ public function commitTransactionForOrder($order, $merchantSettings)
248
+ {
249
  $exactorProcessingService = ExactorProcessingServiceFactory::getInstance()
250
+ ->buildExactorProcessingService($merchantSettings->getMerchantID(), $merchantSettings->getUserID());
251
  try {
252
+ if (!$this->underEffectiveDate($merchantSettings->getEffectiveDate(), $order->getCreatedAt())) {
253
+ $this->logger->info("Order " . $order->getIncrementId() . " is not under effective date. Skipping.",
254
+ "commitTransactionForOrder");
255
  }
256
  $exactorTransaction = $exactorProcessingService->loadTransactionInfoByOrderId($order->getIncrementId());
257
  $invoiceRequests = $this->exactorMappingHelper->buildInvoiceRequestForMagentoOrder($order, $merchantSettings);
268
  $exactorTransaction->setIsCommited(true);
269
  $exactorTransaction->setExactorTrnId($taxResponse->getFirstCommit()->getTransactionId());
270
  $exactorProcessingService->getPluginCallback()
271
+ ->saveTransactionInfo($exactorTransaction, $exactorTransaction->getSignature());
272
  return $taxResponse;
273
  } else {
274
  $this->logger->error("New order should be represented by the single exactor transaction. Is", 'processFinishedOrder');
282
  /**
283
  * @param Varien_Event_Observer $observer
284
  */
285
+ public function handleAllOrdersCompleted($observer)
286
+ {
287
  $this->logger->trace('called', 'handleAllOrdersCompleted');
288
  if (is_array($observer->getOrders()))
289
  $orders = array_reverse($observer->getOrders());
290
  else
291
  $orders = array($observer->getOrder());
292
+ foreach ($orders as $order) {
293
  $this->processFinishedOrder($order);
294
  }
295
  // We need to clean the session storage here
299
  /**
300
  * @param Mage_Sales_Model_Order_Creditmemo $creditMemo
301
  */
302
+ private function partialRefund($creditMemo)
303
+ {
304
  $merchantSettings = $this->loadMerchantSettings($creditMemo->getOrder());
305
+ if ($merchantSettings == null) return;
306
+ if (!$this->underEffectiveDate($merchantSettings->getEffectiveDate(), $creditMemo->getOrder()->getCreatedAt())) {
307
+ $this->logger->info("Order " . $creditMemo->getOrder()->getIncrementId() . " is not under effective date. Skipping.", "partialRefund");
308
  return;
309
  }
310
  $invoiceRequests = $this->exactorMappingHelper->buildInvoiceRequestsForCreditMemo($creditMemo, $merchantSettings);
311
  $config = ExactorPluginConfig::getInstance();
312
  $exactorProcessingService = ExactorProcessingServiceFactory::getInstance()->buildExactorProcessingService($merchantSettings->getMerchantID(),
313
+ $merchantSettings->getUserID());
314
  foreach ($invoiceRequests as $invoice) {
315
  if ($config->getFeatureConfig()->isFeatureEnabled(EXACTOR_CONFIG_FEATURE_TRN_FILTER)) {
316
  if (!$this->exactorMappingHelper->isAllowedLocation($config->get(EXACTOR_CONFIG_TRN_FILTER), $invoice->getShipTo())) {
326
  // =================================== EVENT HANDLERS =================================================================
327
  // ====================================================================================================================
328
 
329
+ public function handleBeforeSaveQuote($observer)
330
+ {
331
+ $invoiceResponse = unserialize($this->session->getLastInvoiceResponse());
332
+ if (!$invoiceResponse) return;
333
+ // Restore line item tax broken by third-party extensions
334
+ $quote = $observer->getQuote();
335
+
336
+ /**
337
+ * @var Mage_Sales_Model_Quote_Item $item
338
+ */
339
+ foreach ($quote->getAllItems() as $item) {
340
+ $taxResultItem = $invoiceResponse->getItemById($this->exactorMappingHelper->buildExactorItemId($item));
341
+ // If there is no item in response - set tax to 0
342
+ if ($taxResultItem == null) {
343
+ $item->setTaxAmount(0);
344
+ $item->setBaseTaxAmount(0);
345
+ $item->setTaxPercent(0);
346
+ } else { // Else - Apply tax to the item
347
+ $item->setTaxAmount($taxResultItem->getTotalTaxAmount());
348
+ $item->setBaseTaxAmount($taxResultItem->getTotalTaxAmount());
349
+ $this->applyTaxPercent($item, $taxResultItem);
350
+ }
351
+ }
352
+ }
353
+
354
+ /**
355
+ * @param Mage_Sales_Model_Quote_Item $quoteItem
356
+ * @param ResponseLineItem $resultItem
357
+ */
358
+ private function applyTaxPercent($quoteItem, $resultItem)
359
+ {
360
+ $taxPercent = 0;
361
+ foreach ($resultItem->getTaxInfo() as $taxInfo) {
362
+ $taxPercent += $taxInfo->getTaxRate();
363
+ }
364
+ $taxPercent *= 100;
365
+ $quoteItem->setTaxPercent($taxPercent);
366
+ }
367
+
368
  /**
369
  * Event will be fired once new order has been created
370
  * @param Varien_Event_Observer $observer
371
  * @return void
372
  */
373
+ public function handleCreatedOrder($observer)
374
+ {
375
  $this->logger->trace('called', 'handleCreatedOrder');
376
  if ($this->shouldOrderProcessingRunInCompatibilityMode($observer->getOrder())) {
377
  $this->logger->info('Order processing started in compatibility mode.', 'handleCreatedOrder');
380
  }
381
  }
382
 
383
+ private function shouldOrderProcessingRunInCompatibilityMode($order)
384
+ {
385
  if ($order->getPayment() != null &&
386
+ strpos($order->getPayment()->getMethod(), "paypal_express") !== false
387
+ ) {
388
  $this->logger->info('PayPal order detected', 'shouldOrderProcessingRunInCompatibilityMode');
389
  return true;
390
  }
395
  }
396
 
397
  $mageEdition = Mage::getEdition();
398
+ if ($mageEdition == Mage::EDITION_ENTERPRISE && $mageVersionInfo['major'] == 1 && $mageVersionInfo['minor'] == 8) {
399
  $this->logger->info('Magento Enterprise detected', 'shouldOrderProcessingRunInCompatibilityMode');
400
  return true;
401
  }
405
  /**
406
  * @param Varien_Event_Observer $observer
407
  */
408
+ public function handleNewCreditMemo(Varien_Event_Observer $observer)
409
+ {
410
  $this->logger->trace('called', 'handleNewCreditMemo');
411
  $merchantSettings = $this->loadMerchantSettings($observer->getCreditmemo()->getOrder());
412
+ if ($merchantSettings == null) return;
413
  // TODO: What about COMMIT on shipment
414
+ if ($merchantSettings->getCommitOption() != ZzzzzExactor_Core_Model_MerchantSettings::COMMIT_NEVER) {
415
+ if ($merchantSettings->getCommitOption() == ZzzzzExactor_Core_Model_MerchantSettings::COMMIT_ON_SHIPMENT) {
416
  $exactorTrnInfo = $this->exactorProcessingService->loadTransactionInfoByOrderId(
417
  $observer->getCreditmemo()->getOrder()->getIncrementId());
418
+ if ($exactorTrnInfo != null && $exactorTrnInfo->getIsCommited()) {
419
+ try {
420
  $this->refundTransactionForOrder($observer->getCreditmemo()->getOrder(), $merchantSettings);
421
  $exactorTrnInfo->setIsCommited(false);
422
  $this->exactorProcessingService->getPluginCallback()
423
+ ->saveTransactionInfo($exactorTrnInfo, $exactorTrnInfo->getSignature());
424
  } catch (Exception $e) {
425
  $this->logger->error("Can't refund credit memo", 'handleNewCreditMemo');
426
  }
431
  }
432
  }
433
 
434
+ public function handleCancelOrder(Varien_Event_Observer $observer)
435
+ {
436
  $this->logger->trace('called', 'handleCancelOrder');
437
  $merchantSettings = $this->loadMerchantSettings($observer->getPayment()->getOrder());
438
+ if ($merchantSettings == null) return;
439
+ if ($merchantSettings->getCommitOption() == ZzzzzExactor_Core_Model_MerchantSettings::COMMIT_ON_INVOICE) {
440
  // Just do nothing
441
  //$this->refundAllInvoicesForOrder($observer->getPayment()->getOrder(), $merchantSettings);
442
  } else {
444
  }
445
  }
446
 
447
+ public function handleNewShipment(Varien_Event_Observer $observer)
448
+ {
449
  $this->logger->trace('called', 'handleNewShipment');
450
  $merchantSettings = $this->loadMerchantSettings($observer->getShipment()->getOrder());
451
+ if ($merchantSettings == null) return;
452
+ if ($merchantSettings->getCommitOption() == ZzzzzExactor_Core_Model_MerchantSettings::COMMIT_ON_SHIPMENT) {
453
  $this->commitTransactionForOrder($observer->getShipment()->getOrder(), $merchantSettings);
454
  }
455
  }
456
+
457
+ public function handleCancelInvoice(Varien_Event_Observer $observer)
458
+ {
459
  $this->logger->trace('called', 'handleNewInvoice');
460
  $merchantSettings = $this->loadMerchantSettings($observer->getInvoice()->getOrder());
461
+ if ($merchantSettings == null) return;
462
+ if ($merchantSettings->getCommitOption() == ZzzzzExactor_Core_Model_MerchantSettings::COMMIT_ON_INVOICE) {
463
  $this->refundTransactionForInvoice($observer->getInvoice(), $merchantSettings);
464
  }
465
  }
466
 
467
+ private $_lastInvoiceRequest = null;
468
+ private $_lastIncrementId = null;
469
+
470
+ public function handleNewInvoice(Varien_Event_Observer $observer)
471
+ {
472
  $this->logger->trace('called', 'handleNewInvoice');
473
+ $this->_lastInvoiceRequest = null;
474
+ $this->_lastIncrementId = null;
475
+ $invoice = $observer->getInvoice();
476
+ $merchantSettings = $this->loadMerchantSettings($invoice->getOrder());
477
+ if ($merchantSettings == null) return;
478
+
479
+ if ($invoice->getOrder()->getPayment()->getMethodInstance()->isGateway() && $invoice->roundPrice($invoice->getBaseGrandTotal()) <= 0) {
480
+ $this->logger->info('Order ' . $invoice->getOrder()->getIncrementId() . ' with zero amount cannot be paid with Gateway!', 'handleNewInvoice');
481
+ return;
482
+ }
483
+
484
+ if ($merchantSettings->getCommitOption() == ZzzzzExactor_Core_Model_MerchantSettings::COMMIT_ON_INVOICE
485
+ /* && !in_array($incrementOrderId, $this->invoiceProcessingCompatibilityList)*/
486
+ ) { // If flag is set this means that invoice has been handled already in compatibility mode.
487
+ $this->commitTransactionForInvoice($invoice, $merchantSettings);
488
  /*$this->invoiceProcessingCompatibilityList[]= $incrementOrderId;*/
489
  }
490
  }
491
 
492
+ public function handleSubmitFailure(Varien_Event_Observer $observer)
493
+ {
494
+ $this->logger->trace('called', 'handleSubmitFailure');
495
+ if ($this->_lastInvoiceRequest == null) return;
496
+ $merchantSettings = $this->loadMerchantSettings($observer->getOrder());
497
+ $exactorProcessingService = ExactorProcessingServiceFactory::getInstance()
498
+ ->buildExactorProcessingService($merchantSettings->getMerchantID(), $merchantSettings->getUserID());
499
+ $exactorProcessingService->partialRefund($this->_lastInvoiceRequest, new DateTime(), $this->_lastIncrementId);
500
+ }
501
+
502
  /**
503
  * Checks if target date is under effective date, false - otherwise.
504
  *
505
  * @param $effectiveDate - Effective date
506
+ * @param $targetDate - Date to check
507
  * @return boolean
508
  */
509
+ private function underEffectiveDate($effectiveDate, $targetDate)
510
+ {
511
  $effectiveTimestamp = strtotime($effectiveDate);
512
  $targetTimestamp = strtotime('now');
513
  if ($targetDate != null) {
520
  * @param Mage_Sales_Model_Order|null $order
521
  * @return int
522
  */
523
+ public function getStoreViewId($order = null)
524
+ {
525
  $storeId = Mage::app()->getStore()->getId();
526
+ if ($order != null) {
527
  $storeId = $order->getStoreId() ? $order->getStoreId() : 0;
528
  }
529
  return $storeId != 0 ? $storeId : Mage::app()->getDefaultStoreView()->getId();
app/code/local/{Exactor → ZzzzzExactor}/Sales/etc/config.xml RENAMED
@@ -20,24 +20,34 @@
20
  * needs please refer to http://www.magentocommerce.com for more information.
21
  *
22
  * @category Exactor
23
- * @package Exactor_Sales
24
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
28
  <config>
29
- <modules>
30
- <Exactor_Sales>
31
  <version>2012.10.19</version>
32
- </Exactor_Sales>
33
  </modules>
34
  <global>
35
  <events>
 
 
 
 
 
 
 
 
 
 
36
  <checkout_submit_all_after>
37
  <observers>
38
  <exactor_sales_observer>
39
  <type>singleton</type>
40
- <class>Exactor_Sales_Model_Observer</class>
41
  <method>handleAllOrdersCompleted</method>
42
  </exactor_sales_observer>
43
  </observers>
@@ -46,7 +56,7 @@
46
  <observers>
47
  <exactor_sales_observer>
48
  <type>singleton</type>
49
- <class>Exactor_Sales_Model_Observer</class>
50
  <method>handleCreatedOrder</method>
51
  </exactor_sales_observer>
52
  </observers>
@@ -55,16 +65,25 @@
55
  <observers>
56
  <exactor_sales_observer>
57
  <type>singleton</type>
58
- <class>Exactor_Sales_Model_Observer</class>
59
  <method>handleNewCreditMemo</method>
60
  </exactor_sales_observer>
61
  </observers>
62
  </sales_order_creditmemo_refund>
 
 
 
 
 
 
 
 
 
63
  <sales_order_payment_cancel>
64
  <observers>
65
  <exactor_sales_observer>
66
  <type>singleton</type>
67
- <class>Exactor_Sales_Model_Observer</class>
68
  <method>handleCancelOrder</method>
69
  </exactor_sales_observer>
70
  </observers>
@@ -73,7 +92,7 @@
73
  <observers>
74
  <exactor_sales_observer>
75
  <type>singleton</type>
76
- <class>Exactor_Sales_Model_Observer</class>
77
  <method>handleNewShipment</method>
78
  </exactor_sales_observer>
79
  </observers>
@@ -82,7 +101,7 @@
82
  <observers>
83
  <exactor_sales_observer>
84
  <type>singleton</type>
85
- <class>Exactor_Sales_Model_Observer</class>
86
  <method>handleNewInvoice</method>
87
  </exactor_sales_observer>
88
  </observers>
@@ -91,7 +110,7 @@
91
  <observers>
92
  <exactor_sales_observer>
93
  <type>singleton</type>
94
- <class>Exactor_Sales_Model_Observer</class>
95
  <method>handleCancelInvoice</method>
96
  </exactor_sales_observer>
97
  </observers>
@@ -100,7 +119,8 @@
100
  <models>
101
  <tax>
102
  <rewrite>
103
- <sales_model_order_creditmemo_total_tax>Exactor_Sales_Model_Order_Creditmemo_Total_Tax</sales_model_order_creditmemo_total_tax>
 
104
  </rewrite>
105
  </tax>
106
  </models>
20
  * needs please refer to http://www.magentocommerce.com for more information.
21
  *
22
  * @category Exactor
23
+ * @package ZzzzzExactor_Sales
24
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
28
  <config>
29
+ <modules>
30
+ <ZzzzzExactor_Sales>
31
  <version>2012.10.19</version>
32
+ </ZzzzzExactor_Sales>
33
  </modules>
34
  <global>
35
  <events>
36
+
37
+ <sales_quote_save_before>
38
+ <observers>
39
+ <exactor_sales_observer>
40
+ <type>singleton</type>
41
+ <class>ZzzzzExactor_Sales_Model_Observer</class>
42
+ <method>handleBeforeSaveQuote</method>
43
+ </exactor_sales_observer>
44
+ </observers>
45
+ </sales_quote_save_before>
46
  <checkout_submit_all_after>
47
  <observers>
48
  <exactor_sales_observer>
49
  <type>singleton</type>
50
+ <class>ZzzzzExactor_Sales_Model_Observer</class>
51
  <method>handleAllOrdersCompleted</method>
52
  </exactor_sales_observer>
53
  </observers>
56
  <observers>
57
  <exactor_sales_observer>
58
  <type>singleton</type>
59
+ <class>ZzzzzExactor_Sales_Model_Observer</class>
60
  <method>handleCreatedOrder</method>
61
  </exactor_sales_observer>
62
  </observers>
65
  <observers>
66
  <exactor_sales_observer>
67
  <type>singleton</type>
68
+ <class>ZzzzzExactor_Sales_Model_Observer</class>
69
  <method>handleNewCreditMemo</method>
70
  </exactor_sales_observer>
71
  </observers>
72
  </sales_order_creditmemo_refund>
73
+ <sales_model_service_quote_submit_failure>
74
+ <observers>
75
+ <exactor_sales_observer>
76
+ <type>singleton</type>
77
+ <class>ZzzzzExactor_Sales_Model_Observer</class>
78
+ <method>handleSubmitFailure</method>
79
+ </exactor_sales_observer>
80
+ </observers>
81
+ </sales_model_service_quote_submit_failure>
82
  <sales_order_payment_cancel>
83
  <observers>
84
  <exactor_sales_observer>
85
  <type>singleton</type>
86
+ <class>ZzzzzExactor_Sales_Model_Observer</class>
87
  <method>handleCancelOrder</method>
88
  </exactor_sales_observer>
89
  </observers>
92
  <observers>
93
  <exactor_sales_observer>
94
  <type>singleton</type>
95
+ <class>ZzzzzExactor_Sales_Model_Observer</class>
96
  <method>handleNewShipment</method>
97
  </exactor_sales_observer>
98
  </observers>
101
  <observers>
102
  <exactor_sales_observer>
103
  <type>singleton</type>
104
+ <class>ZzzzzExactor_Sales_Model_Observer</class>
105
  <method>handleNewInvoice</method>
106
  </exactor_sales_observer>
107
  </observers>
110
  <observers>
111
  <exactor_sales_observer>
112
  <type>singleton</type>
113
+ <class>ZzzzzExactor_Sales_Model_Observer</class>
114
  <method>handleCancelInvoice</method>
115
  </exactor_sales_observer>
116
  </observers>
119
  <models>
120
  <tax>
121
  <rewrite>
122
+ <sales_model_order_creditmemo_total_tax>ZzzzzExactor_Sales_Model_Order_Creditmemo_Total_Tax
123
+ </sales_model_order_creditmemo_total_tax>
124
  </rewrite>
125
  </tax>
126
  </models>
app/code/local/{Exactor → ZzzzzExactor}/Tax/Helper/Calculation.php RENAMED
@@ -5,7 +5,7 @@
5
  * Time: 1:12 PM
6
  */
7
 
8
- class Exactor_Tax_Helper_Calculation extends Mage_Core_Helper_Abstract {
9
 
10
  private $logger;
11
 
5
  * Time: 1:12 PM
6
  */
7
 
8
+ class ZzzzzExactor_Tax_Helper_Calculation extends Mage_Core_Helper_Abstract {
9
 
10
  private $logger;
11
 
app/code/local/{Exactor → ZzzzzExactor}/Tax/Helper/Mapping.php RENAMED
@@ -4,18 +4,22 @@
4
  * Date: 4/20/12
5
  * Time: 1:12 PM
6
  */
7
-
8
- class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
9
 
10
- const EUC_SHIPPING_COMMON_CARRIER='EUC-13010204';
11
- const EUC_SHIPPING_USPS='EUC-13030202';
12
- const EUC_SHIPPING_AND_HANDLING='EUC-13010101';
 
 
 
13
  const EUC_HANDLING = 'EUC-13010301';
14
  const EUC_NON_TAXABLE = 'EUC-99990101';
15
  const EUC_GIFT_CARD = self::EUC_NON_TAXABLE;
16
- const EUC_STORE_CREDIT = self::EUC_NON_TAXABLE;
17
 
 
 
 
18
  const MSG_DEFAULT_SHIPPING_NAME = 'Default Shipping';
 
19
  const MSG_HANDLING_FEE = 'Handling Fee';
20
  const MSG_ADJUSTMENTS = 'Adjustments';
21
  const MSG_SHIPPING_DESCRIPTION_PREFIX = 'Shipping Fee: ';
@@ -23,29 +27,30 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
23
  const MSG_DISCOUNTED_BY = 'Discounted by $';
24
  const MSG_ADJUSTMENTS_REFUND = "Adjustments Refund";
25
  const MSG_GIFT_CARD_ITEM = "Gift card(-s)";
26
- const MSG_STORE_CREDIT_ITEM = "Store credit";
27
 
 
28
  const LINE_ITEM_ID_SHIPPING = "SHIPPING";
29
  const LINE_ITEM_ID_HANDLING = "HANDLING";
30
  const LINE_ITEM_ID_ADJUSTMENTS = "ADJUSTMENTS";
31
  const LINE_ITEM_ID_GIFT_CARD = "GIFT_CARD";
32
  const LINE_ITEM_ID_STORE_CREDIT = "STORE_CREDIT";
 
 
33
  const INDEXED_LINE_ITEM_ID_PREFIX = '_';
34
 
35
  const ATTRIBUTE_NAME_EXEMPTION = 'taxvat';
36
 
37
  const MAX_SKU_CODE_LENGTH = 32;
38
 
39
- private $logger;
40
 
 
41
 
42
  const PO_ESTIMATE_TEXT = 'Estimated Tax ';
43
-
44
  const UNKNOWN_STREET_TEXT = "";
45
  const UNKNOWN_STATE_NAME = "UNKNOWN";
46
- const UNKNOWN_ZIP_CODE = "00000";
47
 
48
 
 
49
  const PRICE_TYPE_DYNAMIC = 0;
50
 
51
  /**
@@ -55,7 +60,7 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
55
  public function buildExactorItemId($magentoItem)
56
  {
57
  $itemId = $magentoItem->getId();
58
- if ((defined('EXACTOR_BUILD_CUSTOM_ITEM_KEY') && constant('EXACTOR_BUILD_CUSTOM_ITEM_KEY')) || empty($itemId)){
59
  $itemId = base64_encode(join(':', array($magentoItem->getSku(), $magentoItem->getProductId(),
60
  $magentoItem->getRowTotal(), $magentoItem->getQtyOrdered())));
61
  $this->getLogger()->info("Building custom item key: " . $itemId);
@@ -63,8 +68,9 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
63
  return self::INDEXED_LINE_ITEM_ID_PREFIX . $itemId;
64
  }
65
 
66
- private function getLogger(){
67
- if ($this->logger==null)
 
68
  $this->logger = ExactorLoggingFactory::getInstance()->getLogger($this);
69
  return $this->logger;
70
  }
@@ -80,7 +86,8 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
80
  * @param $middleName
81
  * @return string
82
  */
83
- private function buildFullName($firstName, $lastName, $middleName=null){
 
84
  $parts = array($firstName, $middleName, $lastName);
85
  return join(' ', $parts);
86
  }
@@ -89,15 +96,16 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
89
  * @param Mage_Customer_Model_Address_Abstract $address
90
  * @return AddressType|null
91
  */
92
- private function buildExactorAddressForAbstractAddress($address){
 
93
  $exactorAddress = new AddressType();
94
- if ($address==null) return null;
95
  // Set defaults
96
  $exactorAddress->setStreet1(self::UNKNOWN_STREET_TEXT);
97
  $exactorAddress->setFullName("Unknown Buyer");
98
  //
99
- $fullName = trim($address->getName());//trim($this->buildFullName($address->getFirstname(), $address->getLastname(), $address->getMiddlename()));
100
- if (strlen($fullName)>0)
101
  $exactorAddress->setFullName($fullName);
102
  if ($address->getStreetFull() != null)
103
  $exactorAddress->setStreet1($address->getStreetFull());
@@ -107,7 +115,7 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
107
  $exactorAddress->setPostalCode($address->getPostcode());
108
  // It is possible that postal code or state will be missing (e.g. the tax estimation form)
109
  // In this case we will try to determine region basing on the given Postal Code
110
- if (strlen(trim($exactorAddress->getStateOrProvince()))==0 && strlen(trim($exactorAddress->getPostalCode()))!=0){
111
  $exactorAddress->setStateOrProvince(RegionResolver::getInstance()->getStateOrProvinceByCode(trim($exactorAddress->getPostalCode())));
112
  }
113
  if (!$exactorAddress->hasData()) return null;
@@ -118,7 +126,8 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
118
  * @param Mage_Sales_Model_Order_Address $address
119
  * @return AddressType|null
120
  */
121
- public function buildExactorAddressForOrderAddress($address){
 
122
  return $this->buildExactorAddressForAbstractAddress($address);
123
  }
124
 
@@ -126,47 +135,50 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
126
  * @param Mage_Sales_Model_Quote_Address $address
127
  * @return AddressType|null
128
  */
129
- public function buildExactorAddressForQuoteAddress($address){
 
130
  return $this->buildExactorAddressForAbstractAddress($address);
131
  }
132
 
133
  /**
134
  * @param Mage_Sales_Model_Quote_Item_Abstract $magentoItem
135
- * @param Exactor_Core_Model_MerchantSettings $merchantSettings
136
  * @return string
137
  */
138
- public function getSKUForItem($magentoItem, $merchantSettings){
139
- $sku='';
 
140
  $product = $magentoItem->getProduct();
141
  if ($product == null)
142
  $product = Mage::getModel('catalog/product')
143
  ->setStoreId($magentoItem->getStoreId())
144
  ->load($magentoItem->getProductId());
145
- switch ($merchantSettings->getSourceOfSKU()){
146
- case Exactor_Core_Model_MerchantSettings::SKU_SOURCE_NONE:
147
  $sku = '';
148
  break;
149
- case Exactor_Core_Model_MerchantSettings::SKU_SOURCE_SKU_FIELD:
150
  $sku = $magentoItem->getSku();
151
  break;
152
- case Exactor_Core_Model_MerchantSettings::SKU_SOURCE_ATTRIBUTE_NAME:
153
  $attributeSetName = 'Default';
154
- try{
155
  $attributeSetModel = Mage::getModel("eav/entity_attribute_set");
156
  $attributeSetModel->load($product->getAttributeSetId());
157
- $attributeSetName = $attributeSetModel->getAttributeSetName();
158
- }catch(Exception $e){}
 
159
  $sku = $attributeSetName;
160
  break;
161
- case Exactor_Core_Model_MerchantSettings::SKU_SOURCE_PRODUCT_CATEGORY:
162
  $category = $product->getCategory();
163
  if ($category != null)
164
  $sku = $category->getName();
165
  break;
166
- case Exactor_Core_Model_MerchantSettings::SKU_SOURCE_TAX_CLASS:
167
- /** @var Mage_Tax_Model_Mysql4_Class_Collection $taxClassCollection */
168
  $taxClassCollection = Mage::getModel('tax/class')->getCollection();
169
- /** @var Mage_Tax_Model_Class $taxClass */
170
  $taxClass = $taxClassCollection->getItemById($product->getTaxClassId());
171
  if ($taxClass == null) $sku = ''; else $sku = $taxClass->getClassName();
172
  break;
@@ -174,11 +186,12 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
174
  return substr($sku, self::PRICE_TYPE_DYNAMIC, self::MAX_SKU_CODE_LENGTH); // Max length for SKU is 32 characters
175
  }
176
 
177
- private function isUSPSShipping($methodName){
 
178
  $uspsShippingNames = array('USPS', 'Mail', 'Post', 'USPostal');
179
  // Remove all spaces and dots from the original name to simplify search
180
- $methodName = preg_replace('/[\.\s]/','',$methodName);
181
- foreach($uspsShippingNames as $currName){
182
  if (stristr($methodName, $currName)) return true;
183
  }
184
  return false;
@@ -186,30 +199,32 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
186
 
187
  /**
188
  * @param Mage_Sales_Model_Quote_Address $quoteAddress
189
- * @param Exactor_Core_Model_MerchantSettings $merchantSettings
190
  * @return LineItemType|null
191
  */
192
- public function getShippingLineItemForQuoteAddress($quoteAddress, $merchantSettings) {
 
193
 
194
  if ($quoteAddress->getAddressType() == Mage_Sales_Model_Quote_Address::TYPE_BILLING) return null; // There is no shipping fees there
195
- if ($quoteAddress->getShippingAmount()==0) return null;
196
  $shippingLineItem = $this->getShippingLineItem($merchantSettings, $quoteAddress->getShippingMethod(),
197
- $quoteAddress->getShippingDescription(),
198
- $quoteAddress->getShippingAmount(),
199
- $quoteAddress->getShippingDiscountAmount());
200
  return $shippingLineItem;
201
  }
202
 
203
  /**
204
  * @param Mage_Sales_Model_Order_Creditmemo $creditMemo
205
- * @param Exactor_Core_Model_MerchantSettings $merchantSettings
206
  * @return LineItemType|null
207
  */
208
- public function getShippingLineItemForCreditMemo($creditMemo, $merchantSettings){
209
- if ($creditMemo->getShippingAmount()==0) return null;
 
210
  $lineItem = $this->getShippingLineItem($merchantSettings, $creditMemo->getOrder()->getShippingMethod(),
211
- $creditMemo->getOrder()->getShippingDescription(),
212
- $creditMemo->getShippingAmount());
213
  // For refunds we shouldn't subtract handling amount
214
  $lineItem->setGrossAmount($creditMemo->getShippingAmount());
215
  return $lineItem;
@@ -217,46 +232,54 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
217
 
218
  /**
219
  * @param Mage_Sales_Model_Order $order
220
- * @param Exactor_Core_Model_MerchantSettings $merchantSettings
221
  * @return LineItemType|null
222
  */
223
- public function getShippingLineItemForOrder($order, $merchantSettings) {
 
224
  if ($order->getBaseShippingAmount() == 0) return null;
225
  $lineItem = $this->getShippingLineItem($merchantSettings, $order->getShippingMethod(),
226
- $order->getShippingDescription(),
227
- $order->getBaseShippingAmount());
 
228
  return $lineItem;
229
  }
230
 
231
  /**
232
  * @param Mage_Sales_Model_Order_Invoice $invoice
233
- * @param Exactor_Core_Model_MerchantSettings $merchantSettings
234
  * @return LineItemType|null
235
  */
236
- public function getShippingLineItemForInvoice($invoice, $merchantSettings) {
 
237
  if ($invoice->getBaseShippingAmount() == 0) return null;
238
  return $this->getShippingLineItemForOrder($invoice->getOrder(), $merchantSettings);
239
  }
240
 
241
  /**
242
- * @param Exactor_Core_Model_MerchantSettings $merchantSettings
243
  * @param $carrierName
244
  * @param $carrierDescription
245
  * @param $amount
246
  * @param int $discount
247
  * @return LineItemType
248
  */
249
- private function getShippingLineItem($merchantSettings, $carrierName, $carrierDescription, $amount, $discount=0){
 
 
250
  $shippingLineItem = new LineItemType();
251
  $shippingLineItem->setDescription(self::MSG_SHIPPING_DESCRIPTION_PREFIX . $carrierDescription);
252
- if (trim($shippingLineItem->getDescription())==''){
253
  $shippingLineItem->setDescription(self::MSG_DEFAULT_SHIPPING_NAME);
254
  }
255
  // Get EUC code for shipping
256
  $shippingEUC = self::EUC_SHIPPING_COMMON_CARRIER;
257
- if ($merchantSettings->isShippingIncludeHandling()){
 
 
 
258
  $shippingEUC = self::EUC_SHIPPING_AND_HANDLING;
259
- }else if ($this->isUSPSShipping($carrierName)){
260
  $shippingEUC = self::EUC_SHIPPING_USPS;
261
  }
262
  $shippingLineItem->setSKU($shippingEUC);
@@ -264,72 +287,140 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
264
  $shippingLineItem->setId(self::LINE_ITEM_ID_SHIPPING);
265
  $shippingLineItem->setQuantity(1);
266
  // If shipping doesn't include handling we should subtract handling from the total shipping amount
267
- if (!$merchantSettings->isShippingIncludeHandling()){
268
- $amount -= $this->getHandlingFeeByMethodName($carrierName);
269
  }
270
  $shippingLineItem->setGrossAmount($amount);
271
- $this->applyDiscountToLineItem($shippingLineItem,$discount);
272
  return $shippingLineItem;
273
  }
274
 
275
-
276
-
277
  /**
278
  * Returns handling feed amount by given name, or 0 if there is no handling
279
  * @param $name
280
- * @return void
281
  */
282
- private function getHandlingFeeByMethodName($name){
283
- if (strpos($name, "_")) $name = substr($name, self::PRICE_TYPE_DYNAMIC,strpos($name, "_"));
284
- if ($name == null) $name="";
 
285
  // Fetch carriers information from Magento config to determine handling amount
286
  $carriers = Mage::getStoreConfig('carriers');
287
  if (!array_key_exists($name, $carriers)) return self::PRICE_TYPE_DYNAMIC;
288
- foreach($carriers as $id => $carrier){
289
- if (array_key_exists('handling_fee', $carrier)){
290
- if ($id == $name)
291
- return $carrier['handling_fee'];
292
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
293
  }
294
- return self::PRICE_TYPE_DYNAMIC;
 
295
  }
296
 
 
 
297
  /**
298
- * @param Exactor_Core_Model_MerchantSettings $merchantSettings
299
  * @param $carrierName
300
  * @return LineItemType|null
301
  */
302
- public function getHandlingLineItem($merchantSettings, $carrierName){
303
- if ($merchantSettings->isShippingIncludeHandling()) return null; // Handling already included in the shipping
 
 
 
 
304
  $handlingLineItem = new LineItemType();
305
  $handlingLineItem->setId(self::LINE_ITEM_ID_HANDLING);
306
  $handlingLineItem->setDescription(self::MSG_HANDLING_FEE);
307
  $handlingLineItem->setSKU(self::EUC_HANDLING);
308
  $handlingLineItem->setQuantity(1);
309
- $handlingLineItem->setGrossAmount($this->getHandlingFeeByMethodName($carrierName));
310
- if ($handlingLineItem->getGrossAmount()== self::PRICE_TYPE_DYNAMIC) return null;
311
  return $handlingLineItem;
312
  }
313
 
314
  /**
315
  * @param Mage_Sales_Model_Quote_Address $quoteAddress
316
- * @param Exactor_Core_Model_MerchantSettings $merchantSettings
317
  * @return LineItemType|null
318
  */
319
- private function getHandlingLineItemForQuoteAddress($quoteAddress, $merchantSettings){
 
320
  if ($quoteAddress->getAddressType() == Mage_Sales_Model_Quote_Address::TYPE_BILLING) return null; // There is no shipping fees there
321
- return $this->getHandlingLineItem($merchantSettings, $quoteAddress->getShippingMethod());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322
  }
323
 
324
  /**
325
  * @param \Mage_Sales_Model_Quote_Address_Item|\Mage_Sales_Model_Quote_Item $magentoItem
326
  * @param Mage_Sales_Model_Quote_Address $quoteAddress
327
- * @param Exactor_Core_Model_MerchantSettings $merchantSettings
328
  * @return LineItemType
329
  */
330
  public function buildLineItemForMagentoItem($magentoItem,
331
  $quoteAddress,
332
- $merchantSettings){
 
333
  $lineItem = new LineItemType();
334
  $lineItem->setDescription($magentoItem->getName());
335
  if ($magentoItem->getBaseRowTotal())
@@ -337,9 +428,9 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
337
  else
338
  $lineItem->setGrossAmount(0.0);
339
  $lineItem->setQuantity($magentoItem->getTotalQty());
340
- if ($magentoItem instanceof Mage_Sales_Model_Order_Creditmemo_Item){
341
  $lineItem->setSKU($this->getSKUForItem($magentoItem->getOrderItem(), $merchantSettings));
342
- }else{
343
  $lineItem->setSKU($this->getSKUForItem($magentoItem, $merchantSettings));
344
  }
345
  if (!$this->isDiscountExempt($magentoItem)) {
@@ -354,7 +445,7 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
354
  $product = Mage::getModel('catalog/product')
355
  ->setStoreId($magentoItem->getStoreId())
356
  ->load($magentoItem->getProductId());
357
- }
358
  if (in_array($product->getTypeId(), array(Mage_Catalog_Model_Product_Type::TYPE_BUNDLE))) {
359
  if ($product->getPriceType() == self::PRICE_TYPE_DYNAMIC) {
360
  $lineItem->setGrossAmount(0);
@@ -369,13 +460,14 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
369
  * @param \Mage_Sales_Model_Quote_Address_Item|\Mage_Sales_Model_Quote_Item $magentoItem
370
  * @return void
371
  */
372
- private function isDiscountExempt($magentoItem){
 
373
  try {
374
  $config = ExactorPluginConfig::getInstance();
375
  if (!$config->getFeatureConfig()->isFeatureEnabled(EXACTOR_CONFIG_FEATURE_EXEMPT_DISCOUNTS)) return false;
376
  $exempted = $config->get(EXACTOR_CONFIG_FEATURE_EXEMPT_DISCOUNTS);
377
  if (!isset($exempted)) return false;
378
- if ($magentoItem->getOrderItem() != null){
379
  $magentoItem = $magentoItem->getOrderItem();
380
  }
381
  $actual = preg_split('/,/', $magentoItem->getAppliedRuleIds());
@@ -395,8 +487,9 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
395
  * @param LineItemType $item
396
  * @param int $discountAmount
397
  */
398
- private function applyDiscountToLineItem($item, $discountAmount=0){
399
- if ($discountAmount > 0){
 
400
  $discountedLine = self::MSG_DISCOUNTED_BY . $discountAmount;
401
  $item->setDescription($item->getDescription() . " ($discountedLine)");
402
  $item->setGrossAmount($item->getGrossAmount() - $discountAmount);
@@ -405,45 +498,48 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
405
 
406
  /**
407
  * @param Mage_Sales_Model_Quote_Address $quoteAddress
408
- * @param Exactor_Core_Model_MerchantSettings $merchantSettings
409
  * @return mixed|string
410
  */
411
  private function getExemptionIdForQuoteAddress($quoteAddress,
412
- $merchantSettings){
 
413
  $exemptionId = '';
414
- if ($merchantSettings->getExemptionsSupported()){
415
  $customerExemptionId = $quoteAddress->getQuote()->getCustomer()->getData(self::ATTRIBUTE_NAME_EXEMPTION);
416
- if ($customerExemptionId!=null) $exemptionId=$customerExemptionId;
417
  }
418
  return $exemptionId;
419
  }
420
 
421
  /**
422
  * @param Mage_Sales_Model_Order_Creditmemo $creditMemo
423
- * @param Exactor_Core_Model_MerchantSettings $merchantSettings
424
  * @return string
425
  */
426
  private function getExemptionIdForCreditMemo($creditMemo,
427
- $merchantSettings){
 
428
  $exemptionId = '';
429
- if ($merchantSettings->getExemptionsSupported()){
430
  $customerExemptionId = $creditMemo->getOrder()->getCustomerTaxvat();
431
- if ($customerExemptionId!=null) $exemptionId=$customerExemptionId;
432
  }
433
  return $exemptionId;
434
  }
435
 
436
  /**
437
  * @param Mage_Sales_Model_Order $order
438
- * @param Exactor_Core_Model_MerchantSettings $merchantSettings
439
  * @return string
440
  */
441
  private function getExemptionIdForOrder($order,
442
- $merchantSettings){
 
443
  $exemptionId = '';
444
- if ($merchantSettings->getExemptionsSupported()){
445
  $customerExemptionId = $order->getCustomerTaxvat();
446
- if ($customerExemptionId!=null) $exemptionId=$customerExemptionId;
447
  }
448
  return $exemptionId;
449
  }
@@ -452,9 +548,10 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
452
  * @param Mage_Sales_Model_Quote_Address $quoteAddress
453
  * @return string
454
  */
455
- private function getCurrentCurrencyCode($quoteAddress){
 
456
  $store = Mage::app()->getStore();
457
- if ($quoteAddress->getQuote() != null && $quoteAddress->getQuote()->getStoreId() != null){
458
  $store = $quoteAddress->getQuote()->getStore();
459
  }
460
  return $this->getCurrencyCodeForStore($store);
@@ -464,15 +561,17 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
464
  * @param Mage_Core_Model_Store $store
465
  * @return string
466
  */
467
- private function getCurrencyCodeForStore($store){
 
468
  $currency = 'USD';
469
- if ($store != null){
470
- $currency = $store->getBaseCurrencyCode()!=null ? $store->getBaseCurrencyCode() : $currency;
471
  }
472
  return $currency;
473
  }
474
 
475
- private function buildGiftCardLineItem($amount){
 
476
  $lineItem = new LineItemType();
477
  $lineItem->setGrossAmount($amount);
478
  $lineItem->setQuantity(1);
@@ -482,7 +581,8 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
482
  return $lineItem;
483
  }
484
 
485
- private function buildStoreCreditLineItem($amount){
 
486
  $lineItem = new LineItemType();
487
  $lineItem->setGrossAmount($amount);
488
  $lineItem->setQuantity(1);
@@ -494,34 +594,34 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
494
 
495
  /**
496
  * @param Mage_Sales_Model_Quote_Address $quoteAddress
497
- * @param Exactor_Core_Model_MerchantSettings $merchantSettings
498
  * @param bool $isMultishipping
499
  * @param $isEstimation
500
  * @return InvoiceRequestType
501
  */
502
  public function buildInvoiceRequestForQuoteAddress($quoteAddress,
503
  $merchantSettings,
504
- $isMultishipping, $isEstimation){
 
505
  // Building Invoice Parts
506
  $shipToAddress = $this->buildExactorAddressForQuoteAddress($quoteAddress);
507
  // Trying to find billing address in the quote
508
  $billingAddress = $this->buildExactorAddressForQuoteAddress($quoteAddress->getQuote()->getBillingAddress());
509
 
510
- if ($isEstimation)
511
- $shipToAddress->setFullName(self::MSG_ESTIMATION_REQUEST);
 
 
512
  // If this is just tax estimation for not logged in user
513
  // we just need to use shipping as billing
514
- if ($isEstimation){
515
  $billingAddress = $shipToAddress;
 
516
  }
517
- // If shipping info unavailable - fallback to billing information
518
- if ($shipToAddress == null || !$shipToAddress->hasData()) $shipToAddress=$billingAddress;
519
- if ($shipToAddress == null || !$shipToAddress->hasData()) $shipToAddress=null;
520
- if ($shipToAddress == null) return null;
521
  // Composing invoice object
522
  $invoiceRequest = new InvoiceRequestType();
523
  $invoiceRequest->setSaleDate(new DateTime());
524
- $invoiceRequest->setPurchaseOrderNumber(self::PO_ESTIMATE_TEXT .$quoteAddress->getId());
525
  $invoiceRequest->setShipTo($shipToAddress);
526
  $invoiceRequest->setBillTo($billingAddress);
527
  $invoiceRequest->setCurrencyCode($this->getCurrentCurrencyCode($quoteAddress));
@@ -539,8 +639,8 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
539
  $exactorLineItem->setId($this->buildExactorItemId($magentoItem));
540
  // If this is non-multishipping request we should set
541
  // ship to address to billing address for VIRTUAL ITEMS
542
- if (!$isMultishipping){
543
- if ($magentoItem->getProduct()->getIsVirtual()){
544
  // Previouse requirements was to set BillTo address for wi as Shipping info for virtual products
545
  /*$virtualShipToAddress = $invoiceRequest->getShipTo(); //( $isEstimation ? $invoiceRequest->getShipFrom() : $billingAddress);
546
  $exactorLineItem->setShipTo($virtualShipToAddress);
@@ -550,7 +650,7 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
550
  $invoiceRequest->addLineItem($exactorLineItem);
551
  }
552
  // Gift Cards
553
- if ($quoteAddress->getBaseGiftCardsAmount() != null && $quoteAddress->getBaseGiftCardsAmount() != 0){
554
  $invoiceRequest->addLineItem($this->buildGiftCardLineItem(-1 * $quoteAddress->getBaseGiftCardsAmount()));
555
  }
556
  // Store Credit
@@ -558,9 +658,21 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
558
  if ($storeCreditAmount != null && $storeCreditAmount != 0) {
559
  $invoiceRequest->addLineItem($this->buildStoreCreditLineItem(-1 * $storeCreditAmount));
560
  }
 
561
  // Shipping & Handling
562
- $invoiceRequest->addLineItem($this->getShippingLineItemForQuoteAddress($quoteAddress, $merchantSettings));
563
- $invoiceRequest->addLineItem($this->getHandlingLineItemForQuoteAddress($quoteAddress, $merchantSettings));
 
 
 
 
 
 
 
 
 
 
 
564
  return $invoiceRequest;
565
  }
566
 
@@ -576,25 +688,27 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
576
  */
577
  private function calculateProratedShippingAndHandling($orderedShippingAmount, $alreadyProcessedAmount,
578
  $targetShippingAmount, $handlingTotalAmount,
579
- $store) {
 
580
  // $orderedShippingAmount = $invoice->getOrder()->getBaseShippingAmount();
581
  // $alreadyProcessedAmount = $invoice->getOrder()->getBaseShippingRefunded();
582
  // $targetShippingAmount = $invoice->getBaseShippingAmount();
583
  // $handlingTotalAmount = $handlingLineItem->getGrossAmount();
584
  $delta = $orderedShippingAmount - $alreadyProcessedAmount + $targetShippingAmount;
585
  $shippingFactor = $targetShippingAmount / $delta;
586
- $handlingAmount = $handlingTotalAmount*$shippingFactor;
587
  $shippingAmount = $targetShippingAmount - $handlingAmount;
588
  return array($store->roundPrice($shippingAmount),
589
- $store->roundPrice($shippingAmount));
590
  }
591
 
592
  /** Return invoice requests by credit memo. In case if credit memo contains adjustments - returns 2 separated invoices
593
  * @param Mage_Sales_Model_Order_Creditmemo $creditMemo
594
- * @param Exactor_Core_Model_MerchantSettings $merchantSettings
595
  * @return array InvoiceRequestType
596
  */
597
- public function buildInvoiceRequestsForCreditMemo($creditMemo, $merchantSettings){
 
598
  $result = array();
599
  $invoiceRequest = new InvoiceRequestType();
600
  $invoiceRequest->setBillTo($this->buildExactorAddressForOrderAddress($creditMemo->getBillingAddress()));
@@ -606,9 +720,9 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
606
  $invoiceRequest->setExemptionId($this->getExemptionIdForCreditMemo($creditMemo, $merchantSettings));
607
  // Line items
608
  $magentoItems = $creditMemo->getAllItems();
609
- foreach ($magentoItems as $magentoItem){
610
  $exactorLineItem = $this->buildLineItemForMagentoItem($magentoItem, new Mage_Sales_Model_Quote_Address(), $merchantSettings);
611
- if ($exactorLineItem != null){
612
  $exactorLineItem->setQuantity($magentoItem->getQty());
613
  }
614
  $invoiceRequest->addLineItem($exactorLineItem);
@@ -617,12 +731,12 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
617
  $shippingLineItem = $this->getShippingLineItemForCreditMemo($creditMemo, $merchantSettings);
618
  $handlingLineItem = null;
619
 
620
- if ($shippingLineItem!=null) {
621
- $handlingLineItem = $this->getHandlingLineItem($merchantSettings, $creditMemo->getOrder()->getShippingMethod());
622
- if ($handlingLineItem!=null){ // TODO: use common method: calculateProratedShippingAndHandling(...)
623
  $delta = $creditMemo->getOrder()->getBaseShippingAmount() - $creditMemo->getOrder()->getBaseShippingRefunded() + $creditMemo->getBaseShippingAmount();
624
  $shippingFactor = $creditMemo->getBaseShippingAmount() / $delta;
625
- $handlingAmount = $handlingLineItem->getGrossAmount()*$shippingFactor;
626
  $shippingAmount = $creditMemo->getBaseShippingAmount() - $handlingAmount;
627
  // Update amounts
628
  $shippingLineItem->setGrossAmount($creditMemo->getStore()->roundPrice($shippingAmount));
@@ -632,6 +746,7 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
632
 
633
  $invoiceRequest->addLineItem($shippingLineItem);
634
  $invoiceRequest->addLineItem($handlingLineItem);
 
635
 
636
  $result[] = $invoiceRequest;
637
  // Adjustments
@@ -640,19 +755,19 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
640
  $adjustmentsItem->setDescription(self::MSG_ADJUSTMENTS);
641
  $adjustmentsItem->setQuantity(1);
642
  $adjustmentsItem->setSKU(self::EUC_NON_TAXABLE);
643
- $adjustmentsItem->setGrossAmount($creditMemo->getAdjustmentPositive()-$creditMemo->getAdjustmentNegative());
644
  if ($adjustmentsItem->getGrossAmount() != 0
645
- || $creditMemo->getBaseGiftCardsAmount() != null && $creditMemo->getBaseGiftCardsAmount() != 0
646
- || $creditMemo->getBaseCustomerBalanceAmount() != null && $creditMemo->getBaseCustomerBalanceAmount() != 0
647
  ) {
648
  $adjustmentInvoice = clone $invoiceRequest;
649
  $adjustmentInvoice->setPurchaseOrderNumber(self::MSG_ADJUSTMENTS_REFUND);
650
  $adjustmentInvoice->setLineItems(array());
651
- if ($adjustmentsItem->getGrossAmount() != 0){
652
  $adjustmentInvoice->addLineItem($adjustmentsItem);
653
  }
654
  // Gift Cards
655
- if ($creditMemo->getBaseGiftCardsAmount() != null && $creditMemo->getBaseGiftCardsAmount() != 0){
656
  $adjustmentInvoice->addLineItem($this->buildGiftCardLineItem(-1 * $creditMemo->getBaseGiftCardsAmount()));
657
  }
658
  // Store Credit
@@ -670,23 +785,25 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
670
  * @param string $default
671
  * @return DateTime
672
  */
673
- private function getCreatedAtDateForMageOrder($order, $default='now') {
 
674
  $res = $default;
675
- try{
676
- $res= '@'.$order->getCreatedAtDate()->getTimestamp();
677
  } catch (Exception $e) {
678
  $this->logger->error("Can't get date. Using default value." . $e->getMessage(),
679
- 'getCreatedAtDateForMageInvoice');
680
  }
681
  return new DateTime($res);
682
  }
683
 
684
  /**
685
  * @param Mage_Sales_Model_Order_Invoice $invoice
686
- * @param Exactor_Core_Model_MerchantSettings $merchantSettings
687
  * @return array
688
  */
689
- public function buildInvoiceRequestForMagentoInvoice($invoice, $merchantSettings){
 
690
  $result = array();
691
  $invoiceRequest = new InvoiceRequestType();
692
  $invoiceRequest->setBillTo($this->buildExactorAddressForOrderAddress($invoice->getBillingAddress()));
@@ -699,9 +816,9 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
699
  //$invoiceRequest->setExemptionId($this->getExemptionIdForCreditMemo($creditMemo, $merchantSettings));
700
  // Line items
701
  $magentoItems = $invoice->getAllItems();
702
- foreach ($magentoItems as $magentoItem){
703
  $exactorLineItem = $this->buildLineItemForMagentoItem($magentoItem, new Mage_Sales_Model_Quote_Address(), $merchantSettings);
704
- if ($exactorLineItem != null){
705
  $exactorLineItem->setQuantity($magentoItem->getQty());
706
  }
707
  $invoiceRequest->addLineItem($exactorLineItem);
@@ -709,13 +826,17 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
709
  // Shipping & Handling
710
  $shippingLineItem = $this->getShippingLineItemForInvoice($invoice, $merchantSettings);
711
  $handlingLineItem = null;
712
- if ($shippingLineItem!=null) {
713
- $handlingLineItem = $this->getHandlingLineItem($merchantSettings, $invoice->getOrder()->getShippingMethod());
 
 
 
 
714
  }
715
  $invoiceRequest->addLineItem($shippingLineItem);
716
  $invoiceRequest->addLineItem($handlingLineItem);
717
  // Gift cards
718
- if ($invoice->getBaseGiftCardsAmount() != null && $invoice->getBaseGiftCardsAmount() != 0){
719
  $invoiceRequest->addLineItem($this->buildGiftCardLineItem(-1 * $invoice->getBaseGiftCardsAmount()));
720
  }
721
  // Store Credit
@@ -723,16 +844,19 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
723
  if ($storeCreditAmount != null && $storeCreditAmount != 0) {
724
  $invoiceRequest->addLineItem($this->buildStoreCreditLineItem(-1 * $storeCreditAmount));
725
  }
 
 
726
  $result[] = $invoiceRequest;
727
  return $result;
728
  }
729
 
730
  /**
731
  * @param Mage_Sales_Model_Order $order
732
- * @param Exactor_Core_Model_MerchantSettings $merchantSettings
733
  * @return array
734
  */
735
- public function buildInvoiceRequestForMagentoOrder($order, $merchantSettings){
 
736
  $result = array();
737
  $invoiceRequest = new InvoiceRequestType();
738
  $invoiceRequest->setBillTo($this->buildExactorAddressForOrderAddress($order->getBillingAddress()));
@@ -744,9 +868,9 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
744
  $invoiceRequest->setExemptionId($this->getExemptionIdForOrder($order, $merchantSettings));
745
  // Line items
746
  $magentoItems = $order->getAllItems();
747
- foreach ($magentoItems as $magentoItem){
748
  $exactorLineItem = $this->buildLineItemForMagentoItem($magentoItem, new Mage_Sales_Model_Quote_Address(), $merchantSettings);
749
- if ($exactorLineItem != null){
750
  $exactorLineItem->setQuantity($magentoItem->getQtyOrdered());
751
  $exactorLineItem->setId($this->buildExactorItemId($magentoItem));
752
  }
@@ -755,13 +879,17 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
755
  // Shipping & Handling
756
  $shippingLineItem = $this->getShippingLineItemForOrder($order, $merchantSettings);
757
  $handlingLineItem = null;
758
- if ($shippingLineItem!=null) {
759
- $handlingLineItem = $this->getHandlingLineItem($merchantSettings, $order->getShippingMethod());
 
 
 
 
760
  }
761
  $invoiceRequest->addLineItem($shippingLineItem);
762
  $invoiceRequest->addLineItem($handlingLineItem);
763
  // Gift cards
764
- if ($order->getBaseGiftCardsAmount() != null && $order->getBaseGiftCardsAmount() != 0){
765
  $invoiceRequest->addLineItem($this->buildGiftCardLineItem(-1 * $order->getBaseGiftCardsAmount()));
766
  }
767
  // Store Credit
@@ -769,6 +897,8 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
769
  if ($storeCreditAmount != null && $storeCreditAmount != 0) {
770
  $invoiceRequest->addLineItem($this->buildStoreCreditLineItem(-1 * $storeCreditAmount));
771
  }
 
 
772
  $result[] = $invoiceRequest;
773
  return $result;
774
  }
@@ -778,7 +908,8 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
778
  * @param Mage_Customer_Model_Address_Abstract|AddressType $address
779
  * @return bool
780
  */
781
- public function isAllowedLocation($filter, $address) {
 
782
  /* Filter has the following structure:
783
  countryName1: array(state1, state2, state3)
784
  countryName1: array(state1, state2, state3)
@@ -802,8 +933,9 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
802
  * @param AddressType $address
803
  * @return bool
804
  */
805
- private function isAddessFullyPopulated($address) {
806
- if ($address==null || !$address->hasData()) return false;
 
807
  return strlen(trim($address->getStreet1())) > 0
808
  && strlen(trim($address->getFullName())) > 0
809
  && strlen(trim($address->getCity())) > 0;
@@ -817,9 +949,10 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
817
  * @param InvoiceRequestType $invoice
818
  * @return bool
819
  */
820
- public function isInvoiceAddressesFullyPopulated($invoice) {
 
821
  if ($invoice == null) return false;
822
  return $this->isAddessFullyPopulated($invoice->getShipTo());
823
- //&& $this->isAddessFullyPopulated($invoice->getBillTo());
824
  }
825
  }
4
  * Date: 4/20/12
5
  * Time: 1:12 PM
6
  */
 
 
7
 
8
+ class ZzzzzExactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract
9
+ {
10
+
11
+ const EUC_SHIPPING_COMMON_CARRIER = 'EUC-13010204';
12
+ const EUC_SHIPPING_USPS = 'EUC-13030202';
13
+ const EUC_SHIPPING_AND_HANDLING = 'EUC-13010101';
14
  const EUC_HANDLING = 'EUC-13010301';
15
  const EUC_NON_TAXABLE = 'EUC-99990101';
16
  const EUC_GIFT_CARD = self::EUC_NON_TAXABLE;
 
17
 
18
+ const SKU_FOOMAN_SURCHARGE = 'FOOMAN_SURCHARGE';
19
+
20
+ const EUC_STORE_CREDIT = self::EUC_NON_TAXABLE;
21
  const MSG_DEFAULT_SHIPPING_NAME = 'Default Shipping';
22
+ const MSG_DEFAULT_FOOMAN_SURCHARGE = 'Fooman Surcharge';
23
  const MSG_HANDLING_FEE = 'Handling Fee';
24
  const MSG_ADJUSTMENTS = 'Adjustments';
25
  const MSG_SHIPPING_DESCRIPTION_PREFIX = 'Shipping Fee: ';
27
  const MSG_DISCOUNTED_BY = 'Discounted by $';
28
  const MSG_ADJUSTMENTS_REFUND = "Adjustments Refund";
29
  const MSG_GIFT_CARD_ITEM = "Gift card(-s)";
 
30
 
31
+ const MSG_STORE_CREDIT_ITEM = "Store credit";
32
  const LINE_ITEM_ID_SHIPPING = "SHIPPING";
33
  const LINE_ITEM_ID_HANDLING = "HANDLING";
34
  const LINE_ITEM_ID_ADJUSTMENTS = "ADJUSTMENTS";
35
  const LINE_ITEM_ID_GIFT_CARD = "GIFT_CARD";
36
  const LINE_ITEM_ID_STORE_CREDIT = "STORE_CREDIT";
37
+ const LINE_ITEM_ID_FOOMAN_SURCHARGE = 'FOOMAN_SURCHARGE';
38
+
39
  const INDEXED_LINE_ITEM_ID_PREFIX = '_';
40
 
41
  const ATTRIBUTE_NAME_EXEMPTION = 'taxvat';
42
 
43
  const MAX_SKU_CODE_LENGTH = 32;
44
 
 
45
 
46
+ private $logger;
47
 
48
  const PO_ESTIMATE_TEXT = 'Estimated Tax ';
 
49
  const UNKNOWN_STREET_TEXT = "";
50
  const UNKNOWN_STATE_NAME = "UNKNOWN";
 
51
 
52
 
53
+ const UNKNOWN_ZIP_CODE = "00000";
54
  const PRICE_TYPE_DYNAMIC = 0;
55
 
56
  /**
60
  public function buildExactorItemId($magentoItem)
61
  {
62
  $itemId = $magentoItem->getId();
63
+ if ((defined('EXACTOR_BUILD_CUSTOM_ITEM_KEY') && constant('EXACTOR_BUILD_CUSTOM_ITEM_KEY')) || empty($itemId)) {
64
  $itemId = base64_encode(join(':', array($magentoItem->getSku(), $magentoItem->getProductId(),
65
  $magentoItem->getRowTotal(), $magentoItem->getQtyOrdered())));
66
  $this->getLogger()->info("Building custom item key: " . $itemId);
68
  return self::INDEXED_LINE_ITEM_ID_PREFIX . $itemId;
69
  }
70
 
71
+ private function getLogger()
72
+ {
73
+ if ($this->logger == null)
74
  $this->logger = ExactorLoggingFactory::getInstance()->getLogger($this);
75
  return $this->logger;
76
  }
86
  * @param $middleName
87
  * @return string
88
  */
89
+ private function buildFullName($firstName, $lastName, $middleName = null)
90
+ {
91
  $parts = array($firstName, $middleName, $lastName);
92
  return join(' ', $parts);
93
  }
96
  * @param Mage_Customer_Model_Address_Abstract $address
97
  * @return AddressType|null
98
  */
99
+ private function buildExactorAddressForAbstractAddress($address)
100
+ {
101
  $exactorAddress = new AddressType();
102
+ if ($address == null) return null;
103
  // Set defaults
104
  $exactorAddress->setStreet1(self::UNKNOWN_STREET_TEXT);
105
  $exactorAddress->setFullName("Unknown Buyer");
106
  //
107
+ $fullName = trim($address->getName()); //trim($this->buildFullName($address->getFirstname(), $address->getLastname(), $address->getMiddlename()));
108
+ if (strlen($fullName) > 0)
109
  $exactorAddress->setFullName($fullName);
110
  if ($address->getStreetFull() != null)
111
  $exactorAddress->setStreet1($address->getStreetFull());
115
  $exactorAddress->setPostalCode($address->getPostcode());
116
  // It is possible that postal code or state will be missing (e.g. the tax estimation form)
117
  // In this case we will try to determine region basing on the given Postal Code
118
+ if (strlen(trim($exactorAddress->getStateOrProvince())) == 0 && strlen(trim($exactorAddress->getPostalCode())) != 0) {
119
  $exactorAddress->setStateOrProvince(RegionResolver::getInstance()->getStateOrProvinceByCode(trim($exactorAddress->getPostalCode())));
120
  }
121
  if (!$exactorAddress->hasData()) return null;
126
  * @param Mage_Sales_Model_Order_Address $address
127
  * @return AddressType|null
128
  */
129
+ public function buildExactorAddressForOrderAddress($address)
130
+ {
131
  return $this->buildExactorAddressForAbstractAddress($address);
132
  }
133
 
135
  * @param Mage_Sales_Model_Quote_Address $address
136
  * @return AddressType|null
137
  */
138
+ public function buildExactorAddressForQuoteAddress($address)
139
+ {
140
  return $this->buildExactorAddressForAbstractAddress($address);
141
  }
142
 
143
  /**
144
  * @param Mage_Sales_Model_Quote_Item_Abstract $magentoItem
145
+ * @param ZzzzzExactor_Core_Model_MerchantSettings $merchantSettings
146
  * @return string
147
  */
148
+ public function getSKUForItem($magentoItem, $merchantSettings)
149
+ {
150
+ $sku = '';
151
  $product = $magentoItem->getProduct();
152
  if ($product == null)
153
  $product = Mage::getModel('catalog/product')
154
  ->setStoreId($magentoItem->getStoreId())
155
  ->load($magentoItem->getProductId());
156
+ switch ($merchantSettings->getSourceOfSKU()) {
157
+ case ZzzzzExactor_Core_Model_MerchantSettings::SKU_SOURCE_NONE:
158
  $sku = '';
159
  break;
160
+ case ZzzzzExactor_Core_Model_MerchantSettings::SKU_SOURCE_SKU_FIELD:
161
  $sku = $magentoItem->getSku();
162
  break;
163
+ case ZzzzzExactor_Core_Model_MerchantSettings::SKU_SOURCE_ATTRIBUTE_NAME:
164
  $attributeSetName = 'Default';
165
+ try {
166
  $attributeSetModel = Mage::getModel("eav/entity_attribute_set");
167
  $attributeSetModel->load($product->getAttributeSetId());
168
+ $attributeSetName = $attributeSetModel->getAttributeSetName();
169
+ } catch (Exception $e) {
170
+ }
171
  $sku = $attributeSetName;
172
  break;
173
+ case ZzzzzExactor_Core_Model_MerchantSettings::SKU_SOURCE_PRODUCT_CATEGORY:
174
  $category = $product->getCategory();
175
  if ($category != null)
176
  $sku = $category->getName();
177
  break;
178
+ case ZzzzzExactor_Core_Model_MerchantSettings::SKU_SOURCE_TAX_CLASS:
179
+ /** @var Mage_Tax_Model_Mysql4_Class_Collection $taxClassCollection */
180
  $taxClassCollection = Mage::getModel('tax/class')->getCollection();
181
+ /** @var Mage_Tax_Model_Class $taxClass */
182
  $taxClass = $taxClassCollection->getItemById($product->getTaxClassId());
183
  if ($taxClass == null) $sku = ''; else $sku = $taxClass->getClassName();
184
  break;
186
  return substr($sku, self::PRICE_TYPE_DYNAMIC, self::MAX_SKU_CODE_LENGTH); // Max length for SKU is 32 characters
187
  }
188
 
189
+ private function isUSPSShipping($methodName)
190
+ {
191
  $uspsShippingNames = array('USPS', 'Mail', 'Post', 'USPostal');
192
  // Remove all spaces and dots from the original name to simplify search
193
+ $methodName = preg_replace('/[\.\s]/', '', $methodName);
194
+ foreach ($uspsShippingNames as $currName) {
195
  if (stristr($methodName, $currName)) return true;
196
  }
197
  return false;
199
 
200
  /**
201
  * @param Mage_Sales_Model_Quote_Address $quoteAddress
202
+ * @param ZzzzzExactor_Core_Model_MerchantSettings $merchantSettings
203
  * @return LineItemType|null
204
  */
205
+ public function getShippingLineItemForQuoteAddress($quoteAddress, $merchantSettings)
206
+ {
207
 
208
  if ($quoteAddress->getAddressType() == Mage_Sales_Model_Quote_Address::TYPE_BILLING) return null; // There is no shipping fees there
209
+ if ($quoteAddress->getShippingAmount() == 0) return null;
210
  $shippingLineItem = $this->getShippingLineItem($merchantSettings, $quoteAddress->getShippingMethod(),
211
+ $quoteAddress->getShippingDescription(),
212
+ $quoteAddress->getShippingAmount(),
213
+ $quoteAddress->getShippingDiscountAmount());
214
  return $shippingLineItem;
215
  }
216
 
217
  /**
218
  * @param Mage_Sales_Model_Order_Creditmemo $creditMemo
219
+ * @param ZzzzzExactor_Core_Model_MerchantSettings $merchantSettings
220
  * @return LineItemType|null
221
  */
222
+ public function getShippingLineItemForCreditMemo($creditMemo, $merchantSettings)
223
+ {
224
+ if ($creditMemo->getShippingAmount() == 0) return null;
225
  $lineItem = $this->getShippingLineItem($merchantSettings, $creditMemo->getOrder()->getShippingMethod(),
226
+ $creditMemo->getOrder()->getShippingDescription(),
227
+ $creditMemo->getShippingAmount());
228
  // For refunds we shouldn't subtract handling amount
229
  $lineItem->setGrossAmount($creditMemo->getShippingAmount());
230
  return $lineItem;
232
 
233
  /**
234
  * @param Mage_Sales_Model_Order $order
235
+ * @param ZzzzzExactor_Core_Model_MerchantSettings $merchantSettings
236
  * @return LineItemType|null
237
  */
238
+ public function getShippingLineItemForOrder($order, $merchantSettings)
239
+ {
240
  if ($order->getBaseShippingAmount() == 0) return null;
241
  $lineItem = $this->getShippingLineItem($merchantSettings, $order->getShippingMethod(),
242
+ $order->getShippingDescription(),
243
+ $order->getBaseShippingAmount(),
244
+ $order->getBaseShippingDiscountAmount());
245
  return $lineItem;
246
  }
247
 
248
  /**
249
  * @param Mage_Sales_Model_Order_Invoice $invoice
250
+ * @param ZzzzzExactor_Core_Model_MerchantSettings $merchantSettings
251
  * @return LineItemType|null
252
  */
253
+ public function getShippingLineItemForInvoice($invoice, $merchantSettings)
254
+ {
255
  if ($invoice->getBaseShippingAmount() == 0) return null;
256
  return $this->getShippingLineItemForOrder($invoice->getOrder(), $merchantSettings);
257
  }
258
 
259
  /**
260
+ * @param ZzzzzExactor_Core_Model_MerchantSettings $merchantSettings
261
  * @param $carrierName
262
  * @param $carrierDescription
263
  * @param $amount
264
  * @param int $discount
265
  * @return LineItemType
266
  */
267
+ private function getShippingLineItem($merchantSettings, $carrierName, $carrierDescription, $amount, $discount = 0)
268
+ {
269
+ $discount = Mage::app()->getStore()->roundPrice($discount);
270
  $shippingLineItem = new LineItemType();
271
  $shippingLineItem->setDescription(self::MSG_SHIPPING_DESCRIPTION_PREFIX . $carrierDescription);
272
+ if (trim($shippingLineItem->getDescription()) == '') {
273
  $shippingLineItem->setDescription(self::MSG_DEFAULT_SHIPPING_NAME);
274
  }
275
  // Get EUC code for shipping
276
  $shippingEUC = self::EUC_SHIPPING_COMMON_CARRIER;
277
+ $shippingIncludeHandling = $merchantSettings->isShippingIncludeHandling()
278
+ || $discount > 0
279
+ || $this->getHandlingFeeByMethodNameIfPossible($carrierName, $amount) === self::CODE_UNABLE_TO_EXTRACT;
280
+ if ($shippingIncludeHandling) {
281
  $shippingEUC = self::EUC_SHIPPING_AND_HANDLING;
282
+ } else if ($this->isUSPSShipping($carrierName)) {
283
  $shippingEUC = self::EUC_SHIPPING_USPS;
284
  }
285
  $shippingLineItem->setSKU($shippingEUC);
287
  $shippingLineItem->setId(self::LINE_ITEM_ID_SHIPPING);
288
  $shippingLineItem->setQuantity(1);
289
  // If shipping doesn't include handling we should subtract handling from the total shipping amount
290
+ if (!$shippingIncludeHandling) {
291
+ $amount -= $this->getHandlingFeeByMethodName($carrierName, $amount);
292
  }
293
  $shippingLineItem->setGrossAmount($amount);
294
+ $this->applyDiscountToLineItem($shippingLineItem, $discount);
295
  return $shippingLineItem;
296
  }
297
 
 
 
298
  /**
299
  * Returns handling feed amount by given name, or 0 if there is no handling
300
  * @param $name
301
+ * @return number
302
  */
303
+ private function getHandlingFeeByMethodName($name, $shippingWithHandlingAmount)
304
+ {
305
+ if (strpos($name, "_")) $name = substr($name, self::PRICE_TYPE_DYNAMIC, strpos($name, "_"));
306
+ if ($name == null) $name = "";
307
  // Fetch carriers information from Magento config to determine handling amount
308
  $carriers = Mage::getStoreConfig('carriers');
309
  if (!array_key_exists($name, $carriers)) return self::PRICE_TYPE_DYNAMIC;
310
+ return $this->getHandlingFeeByMethodNameIfPossible($name, $shippingWithHandlingAmount);
311
+ }
312
+
313
+
314
+ private function getHandlingFeeByMethodNameIfPossible($name, $shippingWithHandlingAmount)
315
+ {
316
+ if (strpos($name, "_")) $name = substr($name, self::PRICE_TYPE_DYNAMIC, strpos($name, "_"));
317
+ if ($name == null) $name = "";
318
+ // Fetch carriers information from Magento config to determine handling amount
319
+ $carriers = Mage::getStoreConfig('carriers');
320
+ if (!array_key_exists($name, $carriers)) return self::CODE_UNABLE_TO_EXTRACT;
321
+ $carrier = $carriers[$name];
322
+ if (!array_key_exists('handling_fee', $carrier)) return self::PRICE_TYPE_DYNAMIC;
323
+ if (!$carrier['handling_fee']) return self::PRICE_TYPE_DYNAMIC;
324
+
325
+ return $this->extractHandling($carrier, $shippingWithHandlingAmount);
326
+ }
327
+
328
+ private function extractHandling($carrierMap, $shippingWithHandlingAmount)
329
+ {
330
+ $carrierModel = Mage::getModel($carrierMap['model']);
331
+ $handlingAction = $carrierModel->getConfigData('handling_action');
332
+ if (!$handlingAction) {
333
+ $handlingAction = Mage_Shipping_Model_Carrier_Abstract::HANDLING_ACTION_PERORDER;
334
+ }
335
+ if ($handlingAction != Mage_Shipping_Model_Carrier_Abstract::HANDLING_ACTION_PERORDER) return self::CODE_UNABLE_TO_EXTRACT;
336
+
337
+ $handlingType = $carrierModel->getConfigData('handling_type');
338
+ if (!$handlingType) {
339
+ $handlingType = Mage_Shipping_Model_Carrier_Abstract::HANDLING_TYPE_FIXED;
340
+ }
341
+
342
+ $handlingFee = $carrierMap['handling_fee'];
343
+
344
+ if ($handlingType == Mage_Shipping_Model_Carrier_Abstract::HANDLING_TYPE_PERCENT) {
345
+ $shipping = 100 * $shippingWithHandlingAmount / (100 + $handlingFee);
346
+ return $shipping * $handlingFee / 100;
347
  }
348
+
349
+ return $handlingFee;
350
  }
351
 
352
+ const CODE_UNABLE_TO_EXTRACT = 'UNABLE_TO_EXTRACT';
353
+
354
  /**
355
+ * @param ZzzzzExactor_Core_Model_MerchantSettings $merchantSettings
356
  * @param $carrierName
357
  * @return LineItemType|null
358
  */
359
+ public function getHandlingLineItem($merchantSettings, $carrierName, $shippingWithHandlingAmount, $shippingDiscount)
360
+ {
361
+ $shippingIncludeHandling = $merchantSettings->isShippingIncludeHandling()
362
+ || $shippingDiscount > 0
363
+ || $this->getHandlingFeeByMethodNameIfPossible($carrierName, $shippingWithHandlingAmount) === self::CODE_UNABLE_TO_EXTRACT;
364
+ if ($shippingIncludeHandling) return null; // Handling already included in the shipping
365
  $handlingLineItem = new LineItemType();
366
  $handlingLineItem->setId(self::LINE_ITEM_ID_HANDLING);
367
  $handlingLineItem->setDescription(self::MSG_HANDLING_FEE);
368
  $handlingLineItem->setSKU(self::EUC_HANDLING);
369
  $handlingLineItem->setQuantity(1);
370
+ $handlingLineItem->setGrossAmount($this->getHandlingFeeByMethodName($carrierName, $shippingWithHandlingAmount));
371
+ if ($handlingLineItem->getGrossAmount() == self::PRICE_TYPE_DYNAMIC) return null;
372
  return $handlingLineItem;
373
  }
374
 
375
  /**
376
  * @param Mage_Sales_Model_Quote_Address $quoteAddress
377
+ * @param ZzzzzExactor_Core_Model_MerchantSettings $merchantSettings
378
  * @return LineItemType|null
379
  */
380
+ private function getHandlingLineItemForQuoteAddress($quoteAddress, $merchantSettings)
381
+ {
382
  if ($quoteAddress->getAddressType() == Mage_Sales_Model_Quote_Address::TYPE_BILLING) return null; // There is no shipping fees there
383
+ return $this->getHandlingLineItem(
384
+ $merchantSettings,
385
+ $quoteAddress->getShippingMethod(),
386
+ $quoteAddress->getShippingAmount(),
387
+ $quoteAddress->getShippingDiscountAmount());
388
+ }
389
+
390
+ public function getFoomanSurchargeLineItem($entity)
391
+ {
392
+ if (!Mage::helper('core')->isModuleEnabled('Fooman_Surcharge')) return null;
393
+
394
+ $foomanSurchargeAmount = Mage::app()->getStore()->roundPrice($entity->getFoomanSurchargeAmount());
395
+ if (!$foomanSurchargeAmount) return null;
396
+
397
+ $lineItem = new LineItemType();
398
+ $lineItem->setId(self::LINE_ITEM_ID_FOOMAN_SURCHARGE);
399
+ $lineItem->setSKU(self::SKU_FOOMAN_SURCHARGE);
400
+ if ($entity->getOrder() != null) {
401
+ $description = $entity->getOrder()->getFoomanSurchargeDescription();
402
+ } else {
403
+ $description = $entity->getFoomanSurchargeDescription();
404
+ }
405
+ if (!$description) {
406
+ $description = self::MSG_DEFAULT_FOOMAN_SURCHARGE;
407
+ }
408
+
409
+ $lineItem->setDescription($description);
410
+ $lineItem->setGrossAmount($foomanSurchargeAmount);
411
+ return $lineItem;
412
  }
413
 
414
  /**
415
  * @param \Mage_Sales_Model_Quote_Address_Item|\Mage_Sales_Model_Quote_Item $magentoItem
416
  * @param Mage_Sales_Model_Quote_Address $quoteAddress
417
+ * @param ZzzzzExactor_Core_Model_MerchantSettings $merchantSettings
418
  * @return LineItemType
419
  */
420
  public function buildLineItemForMagentoItem($magentoItem,
421
  $quoteAddress,
422
+ $merchantSettings)
423
+ {
424
  $lineItem = new LineItemType();
425
  $lineItem->setDescription($magentoItem->getName());
426
  if ($magentoItem->getBaseRowTotal())
428
  else
429
  $lineItem->setGrossAmount(0.0);
430
  $lineItem->setQuantity($magentoItem->getTotalQty());
431
+ if ($magentoItem instanceof Mage_Sales_Model_Order_Creditmemo_Item) {
432
  $lineItem->setSKU($this->getSKUForItem($magentoItem->getOrderItem(), $merchantSettings));
433
+ } else {
434
  $lineItem->setSKU($this->getSKUForItem($magentoItem, $merchantSettings));
435
  }
436
  if (!$this->isDiscountExempt($magentoItem)) {
445
  $product = Mage::getModel('catalog/product')
446
  ->setStoreId($magentoItem->getStoreId())
447
  ->load($magentoItem->getProductId());
448
+ }
449
  if (in_array($product->getTypeId(), array(Mage_Catalog_Model_Product_Type::TYPE_BUNDLE))) {
450
  if ($product->getPriceType() == self::PRICE_TYPE_DYNAMIC) {
451
  $lineItem->setGrossAmount(0);
460
  * @param \Mage_Sales_Model_Quote_Address_Item|\Mage_Sales_Model_Quote_Item $magentoItem
461
  * @return void
462
  */
463
+ private function isDiscountExempt($magentoItem)
464
+ {
465
  try {
466
  $config = ExactorPluginConfig::getInstance();
467
  if (!$config->getFeatureConfig()->isFeatureEnabled(EXACTOR_CONFIG_FEATURE_EXEMPT_DISCOUNTS)) return false;
468
  $exempted = $config->get(EXACTOR_CONFIG_FEATURE_EXEMPT_DISCOUNTS);
469
  if (!isset($exempted)) return false;
470
+ if ($magentoItem->getOrderItem() != null) {
471
  $magentoItem = $magentoItem->getOrderItem();
472
  }
473
  $actual = preg_split('/,/', $magentoItem->getAppliedRuleIds());
487
  * @param LineItemType $item
488
  * @param int $discountAmount
489
  */
490
+ private function applyDiscountToLineItem($item, $discountAmount = 0)
491
+ {
492
+ if ($discountAmount > 0) {
493
  $discountedLine = self::MSG_DISCOUNTED_BY . $discountAmount;
494
  $item->setDescription($item->getDescription() . " ($discountedLine)");
495
  $item->setGrossAmount($item->getGrossAmount() - $discountAmount);
498
 
499
  /**
500
  * @param Mage_Sales_Model_Quote_Address $quoteAddress
501
+ * @param ZzzzzExactor_Core_Model_MerchantSettings $merchantSettings
502
  * @return mixed|string
503
  */
504
  private function getExemptionIdForQuoteAddress($quoteAddress,
505
+ $merchantSettings)
506
+ {
507
  $exemptionId = '';
508
+ if ($merchantSettings->getExemptionsSupported()) {
509
  $customerExemptionId = $quoteAddress->getQuote()->getCustomer()->getData(self::ATTRIBUTE_NAME_EXEMPTION);
510
+ if ($customerExemptionId != null) $exemptionId = $customerExemptionId;
511
  }
512
  return $exemptionId;
513
  }
514
 
515
  /**
516
  * @param Mage_Sales_Model_Order_Creditmemo $creditMemo
517
+ * @param ZzzzzExactor_Core_Model_MerchantSettings $merchantSettings
518
  * @return string
519
  */
520
  private function getExemptionIdForCreditMemo($creditMemo,
521
+ $merchantSettings)
522
+ {
523
  $exemptionId = '';
524
+ if ($merchantSettings->getExemptionsSupported()) {
525
  $customerExemptionId = $creditMemo->getOrder()->getCustomerTaxvat();
526
+ if ($customerExemptionId != null) $exemptionId = $customerExemptionId;
527
  }
528
  return $exemptionId;
529
  }
530
 
531
  /**
532
  * @param Mage_Sales_Model_Order $order
533
+ * @param ZzzzzExactor_Core_Model_MerchantSettings $merchantSettings
534
  * @return string
535
  */
536
  private function getExemptionIdForOrder($order,
537
+ $merchantSettings)
538
+ {
539
  $exemptionId = '';
540
+ if ($merchantSettings->getExemptionsSupported()) {
541
  $customerExemptionId = $order->getCustomerTaxvat();
542
+ if ($customerExemptionId != null) $exemptionId = $customerExemptionId;
543
  }
544
  return $exemptionId;
545
  }
548
  * @param Mage_Sales_Model_Quote_Address $quoteAddress
549
  * @return string
550
  */
551
+ private function getCurrentCurrencyCode($quoteAddress)
552
+ {
553
  $store = Mage::app()->getStore();
554
+ if ($quoteAddress->getQuote() != null && $quoteAddress->getQuote()->getStoreId() != null) {
555
  $store = $quoteAddress->getQuote()->getStore();
556
  }
557
  return $this->getCurrencyCodeForStore($store);
561
  * @param Mage_Core_Model_Store $store
562
  * @return string
563
  */
564
+ private function getCurrencyCodeForStore($store)
565
+ {
566
  $currency = 'USD';
567
+ if ($store != null) {
568
+ $currency = $store->getBaseCurrencyCode() != null ? $store->getBaseCurrencyCode() : $currency;
569
  }
570
  return $currency;
571
  }
572
 
573
+ private function buildGiftCardLineItem($amount)
574
+ {
575
  $lineItem = new LineItemType();
576
  $lineItem->setGrossAmount($amount);
577
  $lineItem->setQuantity(1);
581
  return $lineItem;
582
  }
583
 
584
+ private function buildStoreCreditLineItem($amount)
585
+ {
586
  $lineItem = new LineItemType();
587
  $lineItem->setGrossAmount($amount);
588
  $lineItem->setQuantity(1);
594
 
595
  /**
596
  * @param Mage_Sales_Model_Quote_Address $quoteAddress
597
+ * @param ZzzzzExactor_Core_Model_MerchantSettings $merchantSettings
598
  * @param bool $isMultishipping
599
  * @param $isEstimation
600
  * @return InvoiceRequestType
601
  */
602
  public function buildInvoiceRequestForQuoteAddress($quoteAddress,
603
  $merchantSettings,
604
+ $isMultishipping, $isEstimation)
605
+ {
606
  // Building Invoice Parts
607
  $shipToAddress = $this->buildExactorAddressForQuoteAddress($quoteAddress);
608
  // Trying to find billing address in the quote
609
  $billingAddress = $this->buildExactorAddressForQuoteAddress($quoteAddress->getQuote()->getBillingAddress());
610
 
611
+ // If shipping info unavailable - fallback to billing information
612
+ if ($shipToAddress == null || !$shipToAddress->hasData()) $shipToAddress = $billingAddress;
613
+ if ($shipToAddress == null || !$shipToAddress->hasData()) $shipToAddress = null;
614
+ if ($shipToAddress == null) return null;
615
  // If this is just tax estimation for not logged in user
616
  // we just need to use shipping as billing
617
+ if ($isEstimation) {
618
  $billingAddress = $shipToAddress;
619
+ $shipToAddress->setFullName(self::MSG_ESTIMATION_REQUEST);
620
  }
 
 
 
 
621
  // Composing invoice object
622
  $invoiceRequest = new InvoiceRequestType();
623
  $invoiceRequest->setSaleDate(new DateTime());
624
+ $invoiceRequest->setPurchaseOrderNumber(self::PO_ESTIMATE_TEXT . $quoteAddress->getId());
625
  $invoiceRequest->setShipTo($shipToAddress);
626
  $invoiceRequest->setBillTo($billingAddress);
627
  $invoiceRequest->setCurrencyCode($this->getCurrentCurrencyCode($quoteAddress));
639
  $exactorLineItem->setId($this->buildExactorItemId($magentoItem));
640
  // If this is non-multishipping request we should set
641
  // ship to address to billing address for VIRTUAL ITEMS
642
+ if (!$isMultishipping) {
643
+ if ($magentoItem->getProduct()->getIsVirtual()) {
644
  // Previouse requirements was to set BillTo address for wi as Shipping info for virtual products
645
  /*$virtualShipToAddress = $invoiceRequest->getShipTo(); //( $isEstimation ? $invoiceRequest->getShipFrom() : $billingAddress);
646
  $exactorLineItem->setShipTo($virtualShipToAddress);
650
  $invoiceRequest->addLineItem($exactorLineItem);
651
  }
652
  // Gift Cards
653
+ if ($quoteAddress->getBaseGiftCardsAmount() != null && $quoteAddress->getBaseGiftCardsAmount() != 0) {
654
  $invoiceRequest->addLineItem($this->buildGiftCardLineItem(-1 * $quoteAddress->getBaseGiftCardsAmount()));
655
  }
656
  // Store Credit
658
  if ($storeCreditAmount != null && $storeCreditAmount != 0) {
659
  $invoiceRequest->addLineItem($this->buildStoreCreditLineItem(-1 * $storeCreditAmount));
660
  }
661
+
662
  // Shipping & Handling
663
+ $shippingLineItem = $this->getShippingLineItemForQuoteAddress($quoteAddress, $merchantSettings);
664
+ $handlingLineItem = null;
665
+ if ($shippingLineItem != null) {
666
+ $handlingLineItem = $this->getHandlingLineItemForQuoteAddress(
667
+ $quoteAddress,
668
+ $merchantSettings,
669
+ $quoteAddress->getShippingAmount());
670
+ }
671
+ $invoiceRequest->addLineItem($shippingLineItem);
672
+ $invoiceRequest->addLineItem($handlingLineItem);
673
+
674
+ $invoiceRequest->addLineItem($this->getFoomanSurchargeLineItem($quoteAddress));
675
+
676
  return $invoiceRequest;
677
  }
678
 
688
  */
689
  private function calculateProratedShippingAndHandling($orderedShippingAmount, $alreadyProcessedAmount,
690
  $targetShippingAmount, $handlingTotalAmount,
691
+ $store)
692
+ {
693
  // $orderedShippingAmount = $invoice->getOrder()->getBaseShippingAmount();
694
  // $alreadyProcessedAmount = $invoice->getOrder()->getBaseShippingRefunded();
695
  // $targetShippingAmount = $invoice->getBaseShippingAmount();
696
  // $handlingTotalAmount = $handlingLineItem->getGrossAmount();
697
  $delta = $orderedShippingAmount - $alreadyProcessedAmount + $targetShippingAmount;
698
  $shippingFactor = $targetShippingAmount / $delta;
699
+ $handlingAmount = $handlingTotalAmount * $shippingFactor;
700
  $shippingAmount = $targetShippingAmount - $handlingAmount;
701
  return array($store->roundPrice($shippingAmount),
702
+ $store->roundPrice($shippingAmount));
703
  }
704
 
705
  /** Return invoice requests by credit memo. In case if credit memo contains adjustments - returns 2 separated invoices
706
  * @param Mage_Sales_Model_Order_Creditmemo $creditMemo
707
+ * @param ZzzzzExactor_Core_Model_MerchantSettings $merchantSettings
708
  * @return array InvoiceRequestType
709
  */
710
+ public function buildInvoiceRequestsForCreditMemo($creditMemo, $merchantSettings)
711
+ {
712
  $result = array();
713
  $invoiceRequest = new InvoiceRequestType();
714
  $invoiceRequest->setBillTo($this->buildExactorAddressForOrderAddress($creditMemo->getBillingAddress()));
720
  $invoiceRequest->setExemptionId($this->getExemptionIdForCreditMemo($creditMemo, $merchantSettings));
721
  // Line items
722
  $magentoItems = $creditMemo->getAllItems();
723
+ foreach ($magentoItems as $magentoItem) {
724
  $exactorLineItem = $this->buildLineItemForMagentoItem($magentoItem, new Mage_Sales_Model_Quote_Address(), $merchantSettings);
725
+ if ($exactorLineItem != null) {
726
  $exactorLineItem->setQuantity($magentoItem->getQty());
727
  }
728
  $invoiceRequest->addLineItem($exactorLineItem);
731
  $shippingLineItem = $this->getShippingLineItemForCreditMemo($creditMemo, $merchantSettings);
732
  $handlingLineItem = null;
733
 
734
+ if ($shippingLineItem != null) {
735
+ $handlingLineItem = $this->getHandlingLineItem($merchantSettings, $creditMemo->getOrder()->getShippingMethod(), $creditMemo->getOrder()->getBaseShippingAmount(), 0);
736
+ if ($handlingLineItem != null) { // TODO: use common method: calculateProratedShippingAndHandling(...)
737
  $delta = $creditMemo->getOrder()->getBaseShippingAmount() - $creditMemo->getOrder()->getBaseShippingRefunded() + $creditMemo->getBaseShippingAmount();
738
  $shippingFactor = $creditMemo->getBaseShippingAmount() / $delta;
739
+ $handlingAmount = $handlingLineItem->getGrossAmount() * $shippingFactor;
740
  $shippingAmount = $creditMemo->getBaseShippingAmount() - $handlingAmount;
741
  // Update amounts
742
  $shippingLineItem->setGrossAmount($creditMemo->getStore()->roundPrice($shippingAmount));
746
 
747
  $invoiceRequest->addLineItem($shippingLineItem);
748
  $invoiceRequest->addLineItem($handlingLineItem);
749
+ $invoiceRequest->addLineItem($this->getFoomanSurchargeLineItem($creditMemo));
750
 
751
  $result[] = $invoiceRequest;
752
  // Adjustments
755
  $adjustmentsItem->setDescription(self::MSG_ADJUSTMENTS);
756
  $adjustmentsItem->setQuantity(1);
757
  $adjustmentsItem->setSKU(self::EUC_NON_TAXABLE);
758
+ $adjustmentsItem->setGrossAmount($creditMemo->getAdjustmentPositive() - $creditMemo->getAdjustmentNegative());
759
  if ($adjustmentsItem->getGrossAmount() != 0
760
+ || $creditMemo->getBaseGiftCardsAmount() != null && $creditMemo->getBaseGiftCardsAmount() != 0
761
+ || $creditMemo->getBaseCustomerBalanceAmount() != null && $creditMemo->getBaseCustomerBalanceAmount() != 0
762
  ) {
763
  $adjustmentInvoice = clone $invoiceRequest;
764
  $adjustmentInvoice->setPurchaseOrderNumber(self::MSG_ADJUSTMENTS_REFUND);
765
  $adjustmentInvoice->setLineItems(array());
766
+ if ($adjustmentsItem->getGrossAmount() != 0) {
767
  $adjustmentInvoice->addLineItem($adjustmentsItem);
768
  }
769
  // Gift Cards
770
+ if ($creditMemo->getBaseGiftCardsAmount() != null && $creditMemo->getBaseGiftCardsAmount() != 0) {
771
  $adjustmentInvoice->addLineItem($this->buildGiftCardLineItem(-1 * $creditMemo->getBaseGiftCardsAmount()));
772
  }
773
  // Store Credit
785
  * @param string $default
786
  * @return DateTime
787
  */
788
+ private function getCreatedAtDateForMageOrder($order, $default = 'now')
789
+ {
790
  $res = $default;
791
+ try {
792
+ $res = '@' . $order->getCreatedAtDate()->getTimestamp();
793
  } catch (Exception $e) {
794
  $this->logger->error("Can't get date. Using default value." . $e->getMessage(),
795
+ 'getCreatedAtDateForMageInvoice');
796
  }
797
  return new DateTime($res);
798
  }
799
 
800
  /**
801
  * @param Mage_Sales_Model_Order_Invoice $invoice
802
+ * @param ZzzzzExactor_Core_Model_MerchantSettings $merchantSettings
803
  * @return array
804
  */
805
+ public function buildInvoiceRequestForMagentoInvoice($invoice, $merchantSettings)
806
+ {
807
  $result = array();
808
  $invoiceRequest = new InvoiceRequestType();
809
  $invoiceRequest->setBillTo($this->buildExactorAddressForOrderAddress($invoice->getBillingAddress()));
816
  //$invoiceRequest->setExemptionId($this->getExemptionIdForCreditMemo($creditMemo, $merchantSettings));
817
  // Line items
818
  $magentoItems = $invoice->getAllItems();
819
+ foreach ($magentoItems as $magentoItem) {
820
  $exactorLineItem = $this->buildLineItemForMagentoItem($magentoItem, new Mage_Sales_Model_Quote_Address(), $merchantSettings);
821
+ if ($exactorLineItem != null) {
822
  $exactorLineItem->setQuantity($magentoItem->getQty());
823
  }
824
  $invoiceRequest->addLineItem($exactorLineItem);
826
  // Shipping & Handling
827
  $shippingLineItem = $this->getShippingLineItemForInvoice($invoice, $merchantSettings);
828
  $handlingLineItem = null;
829
+ if ($shippingLineItem != null) {
830
+ $handlingLineItem = $this->getHandlingLineItem(
831
+ $merchantSettings,
832
+ $invoice->getOrder()->getShippingMethod(),
833
+ $invoice->getOrder()->getBaseShippingAmount(),
834
+ $invoice->getOrder()->getBaseShippingDiscountAmount());
835
  }
836
  $invoiceRequest->addLineItem($shippingLineItem);
837
  $invoiceRequest->addLineItem($handlingLineItem);
838
  // Gift cards
839
+ if ($invoice->getBaseGiftCardsAmount() != null && $invoice->getBaseGiftCardsAmount() != 0) {
840
  $invoiceRequest->addLineItem($this->buildGiftCardLineItem(-1 * $invoice->getBaseGiftCardsAmount()));
841
  }
842
  // Store Credit
844
  if ($storeCreditAmount != null && $storeCreditAmount != 0) {
845
  $invoiceRequest->addLineItem($this->buildStoreCreditLineItem(-1 * $storeCreditAmount));
846
  }
847
+ $invoiceRequest->addLineItem($this->getFoomanSurchargeLineItem($invoice));
848
+
849
  $result[] = $invoiceRequest;
850
  return $result;
851
  }
852
 
853
  /**
854
  * @param Mage_Sales_Model_Order $order
855
+ * @param ZzzzzExactor_Core_Model_MerchantSettings $merchantSettings
856
  * @return array
857
  */
858
+ public function buildInvoiceRequestForMagentoOrder($order, $merchantSettings)
859
+ {
860
  $result = array();
861
  $invoiceRequest = new InvoiceRequestType();
862
  $invoiceRequest->setBillTo($this->buildExactorAddressForOrderAddress($order->getBillingAddress()));
868
  $invoiceRequest->setExemptionId($this->getExemptionIdForOrder($order, $merchantSettings));
869
  // Line items
870
  $magentoItems = $order->getAllItems();
871
+ foreach ($magentoItems as $magentoItem) {
872
  $exactorLineItem = $this->buildLineItemForMagentoItem($magentoItem, new Mage_Sales_Model_Quote_Address(), $merchantSettings);
873
+ if ($exactorLineItem != null) {
874
  $exactorLineItem->setQuantity($magentoItem->getQtyOrdered());
875
  $exactorLineItem->setId($this->buildExactorItemId($magentoItem));
876
  }
879
  // Shipping & Handling
880
  $shippingLineItem = $this->getShippingLineItemForOrder($order, $merchantSettings);
881
  $handlingLineItem = null;
882
+ if ($shippingLineItem != null) {
883
+ $handlingLineItem = $this->getHandlingLineItem(
884
+ $merchantSettings,
885
+ $order->getShippingMethod(),
886
+ $order->getBaseShippingAmount(),
887
+ $order->getBaseShippingDiscountAmount());
888
  }
889
  $invoiceRequest->addLineItem($shippingLineItem);
890
  $invoiceRequest->addLineItem($handlingLineItem);
891
  // Gift cards
892
+ if ($order->getBaseGiftCardsAmount() != null && $order->getBaseGiftCardsAmount() != 0) {
893
  $invoiceRequest->addLineItem($this->buildGiftCardLineItem(-1 * $order->getBaseGiftCardsAmount()));
894
  }
895
  // Store Credit
897
  if ($storeCreditAmount != null && $storeCreditAmount != 0) {
898
  $invoiceRequest->addLineItem($this->buildStoreCreditLineItem(-1 * $storeCreditAmount));
899
  }
900
+ $invoiceRequest->addLineItem($this->getFoomanSurchargeLineItem($order));
901
+
902
  $result[] = $invoiceRequest;
903
  return $result;
904
  }
908
  * @param Mage_Customer_Model_Address_Abstract|AddressType $address
909
  * @return bool
910
  */
911
+ public function isAllowedLocation($filter, $address)
912
+ {
913
  /* Filter has the following structure:
914
  countryName1: array(state1, state2, state3)
915
  countryName1: array(state1, state2, state3)
933
  * @param AddressType $address
934
  * @return bool
935
  */
936
+ private function isAddessFullyPopulated($address)
937
+ {
938
+ if ($address == null || !$address->hasData()) return false;
939
  return strlen(trim($address->getStreet1())) > 0
940
  && strlen(trim($address->getFullName())) > 0
941
  && strlen(trim($address->getCity())) > 0;
949
  * @param InvoiceRequestType $invoice
950
  * @return bool
951
  */
952
+ public function isInvoiceAddressesFullyPopulated($invoice)
953
+ {
954
  if ($invoice == null) return false;
955
  return $this->isAddessFullyPopulated($invoice->getShipTo());
956
+ //&& $this->isAddessFullyPopulated($invoice->getBillTo());
957
  }
958
  }
app/code/local/{Exactor → ZzzzzExactor}/Tax/Model/Sales/Total/Quote/Nominal/Tax.php RENAMED
@@ -5,7 +5,7 @@
5
  * Time: 8:39 AM
6
  */
7
 
8
- class Exactor_Tax_Model_Sales_Total_Quote_Nominal_Tax extends Mage_Sales_Model_Quote_Address_Total_Abstract
9
  {
10
 
11
  public function collect(Mage_Sales_Model_Quote_Address $address)
5
  * Time: 8:39 AM
6
  */
7
 
8
+ class ZzzzzExactor_Tax_Model_Sales_Total_Quote_Nominal_Tax extends Mage_Sales_Model_Quote_Address_Total_Abstract
9
  {
10
 
11
  public function collect(Mage_Sales_Model_Quote_Address $address)
app/code/local/{Exactor → ZzzzzExactor}/Tax/Model/Sales/Total/Quote/Tax.php RENAMED
@@ -4,9 +4,10 @@
4
  * This class will be used by Magento Core to collect Tax total per address
5
  * In magento 1.3 and earlier Mage_Tax_Model_Sales_Total_Quote_Tax
6
  */
7
- class Exactor_Tax_Model_Sales_Total_Quote_Tax extends Mage_Sales_Model_Quote_Address_Total_Abstract {//Mage_Tax_Model_Sales_Total_Quote_Tax { //{
 
8
 
9
- const MODEL_MERCHANT_SETTINGS = "Exactor_Core_Model_MerchantSettings";
10
 
11
  const LOG_MESSAGE_TAX_CALC_FAILED = 'Tax calculation failed due to the following reason: ';
12
 
@@ -19,7 +20,8 @@ class Exactor_Tax_Model_Sales_Total_Quote_Tax extends Mage_Sales_Model_Quote_Add
19
 
20
  /**Show message to the buyer on errors listed below, all other Exactor errors will be displayed as General errors
21
  * @see self::MSG_GENERAL_ERROR
22
- * @var array */
 
23
  private $notifyUserErrorCodes;
24
 
25
  /**
@@ -30,12 +32,12 @@ class Exactor_Tax_Model_Sales_Total_Quote_Tax extends Mage_Sales_Model_Quote_Add
30
  protected $_helper;
31
 
32
  /**
33
- * @var Exactor_Tax_Helper_Calculation
34
  */
35
  private $exactorTaxCalculation;
36
 
37
  /**
38
- * @var Exactor_Tax_Helper_Mapping
39
  */
40
  private $exactorMappingHelper;
41
 
@@ -43,7 +45,7 @@ class Exactor_Tax_Model_Sales_Total_Quote_Tax extends Mage_Sales_Model_Quote_Add
43
  private $session;
44
 
45
  /**
46
- * @var Exactor_Core_Helper_SessionCache
47
  */
48
  private $exactorSessionCache;
49
  /**
@@ -53,10 +55,11 @@ class Exactor_Tax_Model_Sales_Total_Quote_Tax extends Mage_Sales_Model_Quote_Add
53
  */
54
  protected $_config;
55
 
56
- /** @var \Exactor_ExactorSettings_Helper_Data */
57
  private $exactorSettingsHelper;
58
 
59
- private function setupExactorCommonLibrary(){
 
60
  $libDir = Mage::getBaseDir("lib") . '/ExactorCommons';
61
  require_once($libDir . '/XmlProcessing.php');
62
  require_once($libDir . '/ExactorDomainObjects.php');
@@ -70,28 +73,29 @@ class Exactor_Tax_Model_Sales_Total_Quote_Tax extends Mage_Sales_Model_Quote_Add
70
  public function __construct()
71
  {
72
  $this->setCode('tax');
73
- $this->_helper = Mage::helper('tax');
74
- $this->_config = Mage::getSingleton('tax/config');
75
  $this->setupExactorCommonLibrary();
76
  $this->logger = ExactorLoggingFactory::getInstance()->getLogger($this);
77
  $this->exactorTaxCalculation = Mage::helper('tax/calculation');
78
  $this->exactorMappingHelper = Mage::helper('tax/mapping');
79
- $this->exactorSessionCache = Mage::helper('Exactor_Core_SessionCache/');
80
  $this->exactorSettingsHelper = Mage::helper('ExactorSettings');
81
  $this->session = Mage::getSingleton('core/session', array('name' => 'frontend'));
82
  $this->notifyUserErrorCodes = array(ErrorResponseType::ERROR_MISSING_LINE_ITEMS,
83
- ErrorResponseType::ERROR_INVALID_SHIP_TO_ADDRESS,
84
- ErrorResponseType::ERROR_INVALID_CURRENCY_CODE);
85
  }
86
 
87
 
88
  /**
89
  * Load merchantSettings from the database
90
  * @param Mage_Sales_Model_Quote_Address $address
91
- * @return Exactor_Core_Model_MerchantSettings
92
  */
93
- public function loadMerchantSettings($address=null){
94
- $storeViewId = $address->getQuote()->getStoreId();//Mage::app()->getStore()->getId();
 
95
  return $this->exactorSettingsHelper->loadValidMerchantSettings($storeViewId);
96
  }
97
 
@@ -99,9 +103,10 @@ class Exactor_Tax_Model_Sales_Total_Quote_Tax extends Mage_Sales_Model_Quote_Add
99
  * Return True if there is multi-shipping request
100
  * @return bool
101
  */
102
- private function isMultishippingRequest(){
 
103
  $controller = Mage::app()->getRequest()->getControllerName();
104
- return (strstr("multishipping",$controller)>0);
105
  }
106
 
107
  /**
@@ -114,7 +119,7 @@ class Exactor_Tax_Model_Sales_Total_Quote_Tax extends Mage_Sales_Model_Quote_Add
114
  {
115
  //parent::collect($address);
116
  $this->_setAddress($address);
117
- if (count($address->getAllItems())<=0) return; // Skip addresses without items
118
  if ($address->getId() == null) return; // Skip if there is no address
119
  //$this->_setAmount(0);
120
  //$this->logger->trace('Called for address #' . $address->getId() . ' (' . $address->getAddressType() . ')','collect');
@@ -138,8 +143,8 @@ class Exactor_Tax_Model_Sales_Total_Quote_Tax extends Mage_Sales_Model_Quote_Add
138
  return $internalTaxCalculator->collect($address);
139
  }
140
  }
141
- $this->logger->trace('Invoice ' . serialize($invoiceRequest),'collect');
142
- if ($invoiceRequest != null && $this->checkIfCalculationNeeded($invoiceRequest, $merchantSettings)){
143
  if ($config->getFeatureConfig()->isFeatureEnabled(EXACTOR_CONFIG_FEATURE_DISABLE_ESTIMATES)) {
144
  if (!$this->exactorMappingHelper->isInvoiceAddressesFullyPopulated($invoiceRequest)) {
145
  $this->logger->info('Skipping tax estimate due to the Exactor plug-in configuration', 'collect');
@@ -148,23 +153,27 @@ class Exactor_Tax_Model_Sales_Total_Quote_Tax extends Mage_Sales_Model_Quote_Add
148
  }
149
  // Sending to Exactor Tax Calculation Request to Exactor
150
  $exactorProcessingService = ExactorProcessingServiceFactory::getInstance()->buildExactorProcessingService($merchantSettings->getMerchantID(),
151
- $merchantSettings->getUserID());
152
  $calculatedTax = 0;
153
- try{
154
  $exactorResponse = $exactorProcessingService->calculateTax($invoiceRequest);
155
- if ($exactorResponse->hasErrors()){ // Exactor unable to calculate tax
156
  $msg = self::MSG_GENERAL_ERROR . 'EX' . $exactorResponse->getFirstError()->getErrorCode();
157
  if (in_array($exactorResponse->getFirstError()->getErrorCode(), $this->notifyUserErrorCodes))
158
  $msg = $exactorResponse->getFirstError()->getErrorDescription();
159
  return $this->processTaxCalculationFail($msg);
160
- }else{
161
  $invoiceResponse = $exactorResponse->getFirstInvoice();
162
- if ($invoiceResponse!=null){
163
  $calculatedTax = $invoiceResponse->getTotalTaxAmount();
164
  $this->applyTaxForItems($address, $invoiceResponse);
 
 
 
 
165
  }
166
  }
167
- }catch(Exception $e){ // Critical Exactor communication error - Network timeout for instance
168
  $this->applyTax(0);
169
  $this->resetTaxForItems($address);
170
  $this->logger->error(self::LOG_MESSAGE_TAX_CALC_FAILED . $e->getMessage(), 'collect');
@@ -173,37 +182,12 @@ class Exactor_Tax_Model_Sales_Total_Quote_Tax extends Mage_Sales_Model_Quote_Add
173
  $this->applyTax($calculatedTax);
174
  $address->setTaxAmount($calculatedTax);
175
  $address->setBaseTaxAmount($calculatedTax);
176
- }else{
177
- $this->applyTax($address->getTaxAmount());
178
- // For some reason shipping tax is 0 on this point
179
- // We can't fetch it from the anywhere because we don't store any amounts,
180
- // Thus the only solution for us - to calculate it. It's a little bit hacky way...
181
- /**
182
- * @var Mage_Sales_Model_Quote_Item $item
183
- */
184
- $shippingTax = $address->getTaxAmount();
185
- foreach ($address->getAllItems() as $item) {
186
- $shippingTax -= $item->getTaxAmount();
187
- }
188
- $shippingTax = Mage::app()->getStore()->roundPrice($shippingTax);
189
- // The following code is workaraund for the bug in Magento 1.6.2 - Tax applied to the QuoteAddress object
190
- // can be missed by Magento for some reason. This issue can be reproduced in very trickily manner:
191
- // 1. login
192
- // 2. add product to the cart
193
- // 3. logout
194
- // 4. login again
195
- // 5. proceed to purchase
196
- // 6. select FREE SHIPPING
197
- // 7. tax will be zero in front-end, negative in fact. The reason - $address->getTaxAmount() will return 0,
198
- // while line items still contains valid tax
199
- // IMPORTANT: Issue can be reproduced only once per session (first attempt), thus you should clear cookies before login.
200
- if ($shippingTax < 0){
201
- $this->applyTax(-1 * $shippingTax);
202
- $shippingTax = 0;
203
  }
204
- //
205
- $address->setShippingTaxAmount($shippingTax);
206
- $address->setBaseShippingTaxAmount($shippingTax);
207
  }
208
  return $this;
209
  }
@@ -216,7 +200,7 @@ class Exactor_Tax_Model_Sales_Total_Quote_Tax extends Mage_Sales_Model_Quote_Add
216
  private function isEstimation()
217
  {
218
  return strpos($this->session->getLastUrl(), "estimatePost") != false
219
- || strpos($this->session->getLastUrl(),"estimateUpdatePost") != false;
220
  }
221
 
222
  /**
@@ -225,44 +209,78 @@ class Exactor_Tax_Model_Sales_Total_Quote_Tax extends Mage_Sales_Model_Quote_Add
225
  * @param InvoiceResponseType $invoice
226
  * @return void
227
  */
228
- private function applyTaxForItems(Mage_Sales_Model_Quote_Address $address, InvoiceResponseType $invoice){
 
229
  $i = 0;
230
  /**
231
  * @var Mage_Sales_Model_Quote_Item $item
232
  */
233
- foreach ($address->getAllItems() as $item){
234
  $taxResultItem = $invoice->getItemById($this->exactorMappingHelper->buildExactorItemId($item));
235
  // If there is no item in response - set tax to 0
236
- if ($taxResultItem==null){
237
  $item->setTaxAmount(0);
238
  $item->setBaseTaxAmount(0);
239
- }else{ // Else - Apply tax to the item
 
240
  $item->setTaxAmount($taxResultItem->getTotalTaxAmount());
241
  $item->setBaseTaxAmount($taxResultItem->getTotalTaxAmount());
 
242
  }
243
  }
244
  // Set Shipping + handling tax
245
  $totalShippingTax = 0;
246
- $shippingTaxItem = $invoice->getItemById(Exactor_Tax_Helper_Mapping::LINE_ITEM_ID_SHIPPING);
247
- $handlingTaxItem = $invoice->getItemById(Exactor_Tax_Helper_Mapping::LINE_ITEM_ID_HANDLING);
248
- if ($shippingTaxItem != null) $totalShippingTax+=$shippingTaxItem->getTotalTaxAmount();
249
- if ($handlingTaxItem != null) $totalShippingTax+=$handlingTaxItem->getTotalTaxAmount();
250
  $address->setShippingTaxAmount($totalShippingTax);
251
  $address->setBaseShippingTaxAmount($totalShippingTax);
 
 
 
 
 
 
 
 
252
  }
253
 
254
- private function resetTaxForItems(Mage_Sales_Model_Quote_Address $address){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255
  /**
256
  * @var Mage_Sales_Model_Quote_Item $item
257
  */
258
- foreach ($address->getAllItems() as $item){
259
  $item->setTaxAmount(0);
260
  $item->setBaseTaxAmount(0);
 
261
  }
262
  $address->setShippingTaxAmount(0);
 
 
 
 
 
 
263
  }
264
 
265
- private function applyTax($amount){
 
266
  $this->_setBaseAmount($amount);
267
  $this->_setAmount($amount);
268
  }
@@ -270,10 +288,11 @@ class Exactor_Tax_Model_Sales_Total_Quote_Tax extends Mage_Sales_Model_Quote_Add
270
  /**
271
  * Return TRUE if tax calculation IS needed, FALSE - otherwise
272
  * @param InvoiceRequestType $invoiceRequest
273
- * @param Exactor_Core_Model_MerchantSettings $merchantSettings
274
  * @return bool
275
  */
276
- private function checkIfCalculationNeeded($invoiceRequest, $merchantSettings){
 
277
  // Calculating digital signature for the current request
278
  if ($invoiceRequest == null || $invoiceRequest->getLineItems() == null) return false;
279
  $taxRequest = ExactorConnectionFactory::getInstance()->buildRequest($merchantSettings->getMerchantID(), $merchantSettings->getUserID());
@@ -283,26 +302,28 @@ class Exactor_Tax_Model_Sales_Total_Quote_Tax extends Mage_Sales_Model_Quote_Add
283
  $signature = $signatureBuilder->buildDigitalSignature();
284
  // Loading previous one from the session cache
285
  $prviousTrnInfo = $this->exactorSessionCache->getLatestTransactionInfo($invoiceRequest->getPurchaseOrderNumber());
286
- if ($prviousTrnInfo==null) return true;
287
  if ($prviousTrnInfo->getSignature() == $signature) return false;
288
  return true;
289
  }
290
 
291
- private function reportError($msg){
 
292
  $errObj = Mage::getSingleton('core/message')->error($msg);
293
- foreach ($this->session->getMessages()->getErrors() as $message){
294
  if ($message->getCode() == $errObj->getCode())
295
  return;
296
  }
297
  $this->session->addMessage($errObj);
298
  }
299
-
300
  /**
301
  * Do postprocessing after failed tax calculation
302
  * @param $reason
303
- * @return Exactor_Tax_Model_Sales_Total_Quote_Tax
304
  */
305
- private function processTaxCalculationFail($reason){
 
306
  $this->applyTax(0);
307
  $this->logger->error(self::LOG_MESSAGE_TAX_CALC_FAILED . $reason, 'collect');
308
  $this->reportError($reason);
@@ -321,23 +342,23 @@ class Exactor_Tax_Model_Sales_Total_Quote_Tax extends Mage_Sales_Model_Quote_Add
321
 
322
  public function fetch(Mage_Sales_Model_Quote_Address $address)
323
  {
324
- $applied = $address->getAppliedTaxes();
325
- $store = $address->getQuote()->getStore();
326
- $amount = $address->getTaxAmount();
327
- $area = null;
328
  if ($this->_config->displayCartTaxWithGrandTotal($store) && $address->getGrandTotal()) {
329
- $area = 'taxes';
330
  }
331
 
332
  // if (is_array($applied) && (($amount!=0) || ($this->_config->displayCartZeroTax($store)))) {
333
- $address->addTotal(array(
334
- 'code' => $this->getCode(),
335
- 'title' => $this->getLabel(),
336
- 'full_info' => $applied ? $applied : array(),
337
- 'value' => $amount,
338
- 'area' => $area
339
- ));
340
- // }
341
 
342
  $store = $address->getQuote()->getStore();
343
  /**
@@ -347,13 +368,13 @@ class Exactor_Tax_Model_Sales_Total_Quote_Tax extends Mage_Sales_Model_Quote_Add
347
  if ($address->getSubtotalInclTax() > 0) {
348
  $subtotalInclTax = $address->getSubtotalInclTax();
349
  } else {
350
- $subtotalInclTax = $address->getSubtotal()+$address->getTaxAmount()-$address->getShippingTaxAmount();
351
  }
352
 
353
  $address->addTotal(array(
354
- 'code' => 'subtotal',
355
- 'title' => Mage::helper('sales')->__('Subtotal'),
356
- 'value' => $subtotalInclTax,
357
  'value_incl_tax' => $subtotalInclTax,
358
  'value_excl_tax' => $address->getSubtotal(),
359
  ));
@@ -361,4 +382,57 @@ class Exactor_Tax_Model_Sales_Total_Quote_Tax extends Mage_Sales_Model_Quote_Add
361
 
362
  return $this;
363
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
364
  }
4
  * This class will be used by Magento Core to collect Tax total per address
5
  * In magento 1.3 and earlier Mage_Tax_Model_Sales_Total_Quote_Tax
6
  */
7
+ class ZzzzzExactor_Tax_Model_Sales_Total_Quote_Tax extends Mage_Sales_Model_Quote_Address_Total_Abstract
8
+ { //Mage_Tax_Model_Sales_Total_Quote_Tax { //{
9
 
10
+ const MODEL_MERCHANT_SETTINGS = "ZzzzzExactor_Core_Model_MerchantSettings";
11
 
12
  const LOG_MESSAGE_TAX_CALC_FAILED = 'Tax calculation failed due to the following reason: ';
13
 
20
 
21
  /**Show message to the buyer on errors listed below, all other Exactor errors will be displayed as General errors
22
  * @see self::MSG_GENERAL_ERROR
23
+ * @var array
24
+ */
25
  private $notifyUserErrorCodes;
26
 
27
  /**
32
  protected $_helper;
33
 
34
  /**
35
+ * @var ZzzzzExactor_Tax_Helper_Calculation
36
  */
37
  private $exactorTaxCalculation;
38
 
39
  /**
40
+ * @var ZzzzzExactor_Tax_Helper_Mapping
41
  */
42
  private $exactorMappingHelper;
43
 
45
  private $session;
46
 
47
  /**
48
+ * @var ZzzzzExactor_Core_Helper_SessionCache
49
  */
50
  private $exactorSessionCache;
51
  /**
55
  */
56
  protected $_config;
57
 
58
+ /** @var \ZzzzzExactor_ExactorSettings_Helper_Data */
59
  private $exactorSettingsHelper;
60
 
61
+ private function setupExactorCommonLibrary()
62
+ {
63
  $libDir = Mage::getBaseDir("lib") . '/ExactorCommons';
64
  require_once($libDir . '/XmlProcessing.php');
65
  require_once($libDir . '/ExactorDomainObjects.php');
73
  public function __construct()
74
  {
75
  $this->setCode('tax');
76
+ $this->_helper = Mage::helper('tax');
77
+ $this->_config = Mage::getSingleton('tax/config');
78
  $this->setupExactorCommonLibrary();
79
  $this->logger = ExactorLoggingFactory::getInstance()->getLogger($this);
80
  $this->exactorTaxCalculation = Mage::helper('tax/calculation');
81
  $this->exactorMappingHelper = Mage::helper('tax/mapping');
82
+ $this->exactorSessionCache = Mage::helper('ZzzzzExactor_Core_SessionCache/');
83
  $this->exactorSettingsHelper = Mage::helper('ExactorSettings');
84
  $this->session = Mage::getSingleton('core/session', array('name' => 'frontend'));
85
  $this->notifyUserErrorCodes = array(ErrorResponseType::ERROR_MISSING_LINE_ITEMS,
86
+ ErrorResponseType::ERROR_INVALID_SHIP_TO_ADDRESS,
87
+ ErrorResponseType::ERROR_INVALID_CURRENCY_CODE);
88
  }
89
 
90
 
91
  /**
92
  * Load merchantSettings from the database
93
  * @param Mage_Sales_Model_Quote_Address $address
94
+ * @return ZzzzzExactor_Core_Model_MerchantSettings
95
  */
96
+ public function loadMerchantSettings($address = null)
97
+ {
98
+ $storeViewId = $address->getQuote()->getStoreId(); //Mage::app()->getStore()->getId();
99
  return $this->exactorSettingsHelper->loadValidMerchantSettings($storeViewId);
100
  }
101
 
103
  * Return True if there is multi-shipping request
104
  * @return bool
105
  */
106
+ private function isMultishippingRequest()
107
+ {
108
  $controller = Mage::app()->getRequest()->getControllerName();
109
+ return (strstr("multishipping", $controller) > 0);
110
  }
111
 
112
  /**
119
  {
120
  //parent::collect($address);
121
  $this->_setAddress($address);
122
+ if (count($address->getAllItems()) <= 0) return; // Skip addresses without items
123
  if ($address->getId() == null) return; // Skip if there is no address
124
  //$this->_setAmount(0);
125
  //$this->logger->trace('Called for address #' . $address->getId() . ' (' . $address->getAddressType() . ')','collect');
143
  return $internalTaxCalculator->collect($address);
144
  }
145
  }
146
+ $this->logger->trace('Invoice ' . serialize($invoiceRequest), 'collect');
147
+ if ($invoiceRequest != null && $this->checkIfCalculationNeeded($invoiceRequest, $merchantSettings)) {
148
  if ($config->getFeatureConfig()->isFeatureEnabled(EXACTOR_CONFIG_FEATURE_DISABLE_ESTIMATES)) {
149
  if (!$this->exactorMappingHelper->isInvoiceAddressesFullyPopulated($invoiceRequest)) {
150
  $this->logger->info('Skipping tax estimate due to the Exactor plug-in configuration', 'collect');
153
  }
154
  // Sending to Exactor Tax Calculation Request to Exactor
155
  $exactorProcessingService = ExactorProcessingServiceFactory::getInstance()->buildExactorProcessingService($merchantSettings->getMerchantID(),
156
+ $merchantSettings->getUserID());
157
  $calculatedTax = 0;
158
+ try {
159
  $exactorResponse = $exactorProcessingService->calculateTax($invoiceRequest);
160
+ if ($exactorResponse->hasErrors()) { // Exactor unable to calculate tax
161
  $msg = self::MSG_GENERAL_ERROR . 'EX' . $exactorResponse->getFirstError()->getErrorCode();
162
  if (in_array($exactorResponse->getFirstError()->getErrorCode(), $this->notifyUserErrorCodes))
163
  $msg = $exactorResponse->getFirstError()->getErrorDescription();
164
  return $this->processTaxCalculationFail($msg);
165
+ } else {
166
  $invoiceResponse = $exactorResponse->getFirstInvoice();
167
+ if ($invoiceResponse != null) {
168
  $calculatedTax = $invoiceResponse->getTotalTaxAmount();
169
  $this->applyTaxForItems($address, $invoiceResponse);
170
+
171
+ if ($config->get(EXACTOR_CONFIG_ALWAYS_OVERRIDE_TAX) === true) {
172
+ $this->session->setLastInvoiceResponse(serialize($invoiceResponse));
173
+ }
174
  }
175
  }
176
+ } catch (Exception $e) { // Critical Exactor communication error - Network timeout for instance
177
  $this->applyTax(0);
178
  $this->resetTaxForItems($address);
179
  $this->logger->error(self::LOG_MESSAGE_TAX_CALC_FAILED . $e->getMessage(), 'collect');
182
  $this->applyTax($calculatedTax);
183
  $address->setTaxAmount($calculatedTax);
184
  $address->setBaseTaxAmount($calculatedTax);
185
+ } else {
186
+ if ($config->get(EXACTOR_CONFIG_ALWAYS_OVERRIDE_TAX) === true) {
187
+ $this->processTaxOverridingRequired($address);
188
+ } else {
189
+ $this->processCalculationIsNotRequired($address);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  }
 
 
 
191
  }
192
  return $this;
193
  }
200
  private function isEstimation()
201
  {
202
  return strpos($this->session->getLastUrl(), "estimatePost") != false
203
+ || strpos($this->session->getLastUrl(), "estimateUpdatePost") != false;
204
  }
205
 
206
  /**
209
  * @param InvoiceResponseType $invoice
210
  * @return void
211
  */
212
+ private function applyTaxForItems(Mage_Sales_Model_Quote_Address $address, InvoiceResponseType $invoice)
213
+ {
214
  $i = 0;
215
  /**
216
  * @var Mage_Sales_Model_Quote_Item $item
217
  */
218
+ foreach ($address->getAllItems() as $item) {
219
  $taxResultItem = $invoice->getItemById($this->exactorMappingHelper->buildExactorItemId($item));
220
  // If there is no item in response - set tax to 0
221
+ if ($taxResultItem == null) {
222
  $item->setTaxAmount(0);
223
  $item->setBaseTaxAmount(0);
224
+ $item->setTaxPercent(0);
225
+ } else { // Else - Apply tax to the item
226
  $item->setTaxAmount($taxResultItem->getTotalTaxAmount());
227
  $item->setBaseTaxAmount($taxResultItem->getTotalTaxAmount());
228
+ $this->applyTaxPercent($item, $taxResultItem);
229
  }
230
  }
231
  // Set Shipping + handling tax
232
  $totalShippingTax = 0;
233
+ $shippingTaxItem = $invoice->getItemById(ZzzzzExactor_Tax_Helper_Mapping::LINE_ITEM_ID_SHIPPING);
234
+ $handlingTaxItem = $invoice->getItemById(ZzzzzExactor_Tax_Helper_Mapping::LINE_ITEM_ID_HANDLING);
235
+ if ($shippingTaxItem != null) $totalShippingTax += $shippingTaxItem->getTotalTaxAmount();
236
+ if ($handlingTaxItem != null) $totalShippingTax += $handlingTaxItem->getTotalTaxAmount();
237
  $address->setShippingTaxAmount($totalShippingTax);
238
  $address->setBaseShippingTaxAmount($totalShippingTax);
239
+
240
+ if (Mage::helper('core')->isModuleEnabled('Fooman_Surcharge')) {
241
+ $foomanSurchargeTaxItem = $invoice->getItemById(ZzzzzExactor_Tax_Helper_Mapping::LINE_ITEM_ID_FOOMAN_SURCHARGE);
242
+ $foomanSurchargeTax = $foomanSurchargeTaxItem != null ? $foomanSurchargeTaxItem->getTotalTaxAmount() : 0;
243
+ $address->setFoomanSurchargeTaxAmount($foomanSurchargeTax);
244
+ $address->setBaseFoomanSurchargeTaxAmount($foomanSurchargeTax);
245
+ $this->session->setFoomanSurchargeTaxAmount($foomanSurchargeTax);
246
+ }
247
  }
248
 
249
+ /**
250
+ * @param Mage_Sales_Model_Quote_Item $quoteItem
251
+ * @param ResponseLineItem $resultItem
252
+ */
253
+ private function applyTaxPercent($quoteItem, $resultItem)
254
+ {
255
+ $taxPercent = 0;
256
+ foreach ($resultItem->getTaxInfo() as $taxInfo) {
257
+ $taxPercent += $taxInfo->getTaxRate();
258
+ }
259
+ $taxPercent *= 100;
260
+ $quoteItem->setTaxPercent($taxPercent);
261
+ }
262
+
263
+ private function resetTaxForItems(Mage_Sales_Model_Quote_Address $address)
264
+ {
265
  /**
266
  * @var Mage_Sales_Model_Quote_Item $item
267
  */
268
+ foreach ($address->getAllItems() as $item) {
269
  $item->setTaxAmount(0);
270
  $item->setBaseTaxAmount(0);
271
+ $item->setTaxPercent(0);
272
  }
273
  $address->setShippingTaxAmount(0);
274
+
275
+ if (Mage::helper('core')->isModuleEnabled('Fooman_Surcharge')) {
276
+ $address->setFoomanSurchargeTaxAmount(0);
277
+ $address->setBaseFoomanSurchargeTaxAmount(0);
278
+ $this->session->setFoomanSurchargeTaxAmount(0);
279
+ }
280
  }
281
 
282
+ private function applyTax($amount)
283
+ {
284
  $this->_setBaseAmount($amount);
285
  $this->_setAmount($amount);
286
  }
288
  /**
289
  * Return TRUE if tax calculation IS needed, FALSE - otherwise
290
  * @param InvoiceRequestType $invoiceRequest
291
+ * @param ZzzzzExactor_Core_Model_MerchantSettings $merchantSettings
292
  * @return bool
293
  */
294
+ private function checkIfCalculationNeeded($invoiceRequest, $merchantSettings)
295
+ {
296
  // Calculating digital signature for the current request
297
  if ($invoiceRequest == null || $invoiceRequest->getLineItems() == null) return false;
298
  $taxRequest = ExactorConnectionFactory::getInstance()->buildRequest($merchantSettings->getMerchantID(), $merchantSettings->getUserID());
302
  $signature = $signatureBuilder->buildDigitalSignature();
303
  // Loading previous one from the session cache
304
  $prviousTrnInfo = $this->exactorSessionCache->getLatestTransactionInfo($invoiceRequest->getPurchaseOrderNumber());
305
+ if ($prviousTrnInfo == null) return true;
306
  if ($prviousTrnInfo->getSignature() == $signature) return false;
307
  return true;
308
  }
309
 
310
+ private function reportError($msg)
311
+ {
312
  $errObj = Mage::getSingleton('core/message')->error($msg);
313
+ foreach ($this->session->getMessages()->getErrors() as $message) {
314
  if ($message->getCode() == $errObj->getCode())
315
  return;
316
  }
317
  $this->session->addMessage($errObj);
318
  }
319
+
320
  /**
321
  * Do postprocessing after failed tax calculation
322
  * @param $reason
323
+ * @return ZzzzzExactor_Tax_Model_Sales_Total_Quote_Tax
324
  */
325
+ private function processTaxCalculationFail($reason)
326
+ {
327
  $this->applyTax(0);
328
  $this->logger->error(self::LOG_MESSAGE_TAX_CALC_FAILED . $reason, 'collect');
329
  $this->reportError($reason);
342
 
343
  public function fetch(Mage_Sales_Model_Quote_Address $address)
344
  {
345
+ $applied = $address->getAppliedTaxes();
346
+ $store = $address->getQuote()->getStore();
347
+ $amount = $address->getTaxAmount();
348
+ $area = null;
349
  if ($this->_config->displayCartTaxWithGrandTotal($store) && $address->getGrandTotal()) {
350
+ $area = 'taxes';
351
  }
352
 
353
  // if (is_array($applied) && (($amount!=0) || ($this->_config->displayCartZeroTax($store)))) {
354
+ $address->addTotal(array(
355
+ 'code' => $this->getCode(),
356
+ 'title' => $this->getLabel(),
357
+ 'full_info' => $applied ? $applied : array(),
358
+ 'value' => $amount,
359
+ 'area' => $area
360
+ ));
361
+ // }
362
 
363
  $store = $address->getQuote()->getStore();
364
  /**
368
  if ($address->getSubtotalInclTax() > 0) {
369
  $subtotalInclTax = $address->getSubtotalInclTax();
370
  } else {
371
+ $subtotalInclTax = $address->getSubtotal() + $address->getTaxAmount() - $address->getShippingTaxAmount();
372
  }
373
 
374
  $address->addTotal(array(
375
+ 'code' => 'subtotal',
376
+ 'title' => Mage::helper('sales')->__('Subtotal'),
377
+ 'value' => $subtotalInclTax,
378
  'value_incl_tax' => $subtotalInclTax,
379
  'value_excl_tax' => $address->getSubtotal(),
380
  ));
382
 
383
  return $this;
384
  }
385
+
386
+ private function processTaxOverridingRequired(Mage_Sales_Model_Quote_Address $address)
387
+ {
388
+ $invoiceResponse = unserialize($this->session->getLastInvoiceResponse());
389
+ if (!$invoiceResponse) return;
390
+ $calculatedTax = $invoiceResponse->getTotalTaxAmount();
391
+ $this->applyTaxForItems($address, $invoiceResponse);
392
+ $this->applyTax($calculatedTax);
393
+ $address->setTaxAmount($calculatedTax);
394
+ $address->setBaseTaxAmount($calculatedTax);
395
+ }
396
+
397
+ private function processCalculationIsNotRequired(Mage_Sales_Model_Quote_Address $address)
398
+ {
399
+ $this->applyTax($address->getTaxAmount());
400
+ // For some reason shipping tax is 0 on this point
401
+ // We can't fetch it from the anywhere because we don't store any amounts,
402
+ // Thus the only solution for us - to calculate it. It's a little bit hacky way...
403
+ /**
404
+ * @var Mage_Sales_Model_Quote_Item $item
405
+ */
406
+ $shippingTax = $address->getTaxAmount();
407
+ foreach ($address->getAllItems() as $item) {
408
+ $shippingTax -= $item->getTaxAmount();
409
+ }
410
+
411
+ if (Mage::helper('core')->isModuleEnabled('Fooman_Surcharge')) {
412
+ $foomanSurchargeTax = $this->session->getFoomanSurchargeTaxAmount();
413
+ $address->setFoomanSurchargeTaxAmount($foomanSurchargeTax);
414
+ $address->setBaseFoomanSurchargeTaxAmount($foomanSurchargeTax);
415
+ $shippingTax -= $foomanSurchargeTax;
416
+ }
417
+
418
+ $shippingTax = Mage::app()->getStore()->roundPrice($shippingTax);
419
+ // The following code is workaraund for the bug in Magento 1.6.2 - Tax applied to the QuoteAddress object
420
+ // can be missed by Magento for some reason. This issue can be reproduced in very trickily manner:
421
+ // 1. login
422
+ // 2. add product to the cart
423
+ // 3. logout
424
+ // 4. login again
425
+ // 5. proceed to purchase
426
+ // 6. select FREE SHIPPING
427
+ // 7. tax will be zero in front-end, negative in fact. The reason - $address->getTaxAmount() will return 0,
428
+ // while line items still contains valid tax
429
+ // IMPORTANT: Issue can be reproduced only once per session (first attempt), thus you should clear cookies before login.
430
+ if ($shippingTax < 0) {
431
+ $this->applyTax(-1 * $shippingTax);
432
+ $shippingTax = 0;
433
+ }
434
+ //
435
+ $address->setShippingTaxAmount($shippingTax);
436
+ $address->setBaseShippingTaxAmount($shippingTax);
437
+ }
438
  }
app/code/local/{Exactor → ZzzzzExactor}/Tax/etc/config.xml RENAMED
@@ -20,38 +20,51 @@
20
  * needs please refer to http://www.magentocommerce.com for more information.
21
  *
22
  * @category Exactor
23
- * @package Exactor_Tax
24
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
28
  <config>
29
  <modules>
30
- <Exactor_Tax>
31
  <version>2012.12.05</version>
32
- </Exactor_Tax>
33
  </modules>
34
  <global>
35
  <models>
36
  <exactor_tax>
37
- <class>Exactor_Tax_Model</class>
38
  </exactor_tax>
39
  <tax>
40
  <rewrite>
41
- <sales_total_quote_nominal_tax>Exactor_Tax_Model_Sales_Total_Quote_Nominal_Tax</sales_total_quote_nominal_tax>
42
- <sales_total_quote_tax>Exactor_Tax_Model_Sales_Total_Quote_Tax</sales_total_quote_tax>
43
- <sales_quote_address_total_tax>Exactor_Tax_Model_Sales_Total_Quote_Tax</sales_quote_address_total_tax>
 
 
 
 
44
  </rewrite>
45
  </tax>
46
  </models>
47
  <helpers>
48
  <tax>
49
  <rewrite>
50
- <calculation>Exactor_Tax_Helper_Calculation</calculation>
51
- <mapping>Exactor_Tax_Helper_Mapping</mapping>
52
  </rewrite>
53
  </tax>
54
  </helpers>
 
 
 
 
 
 
 
 
 
55
  </global>
56
 
57
  </config>
20
  * needs please refer to http://www.magentocommerce.com for more information.
21
  *
22
  * @category Exactor
23
+ * @package ZzzzzExactor_Tax
24
  * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
28
  <config>
29
  <modules>
30
+ <ZzzzzExactor_Tax>
31
  <version>2012.12.05</version>
32
+ </ZzzzzExactor_Tax>
33
  </modules>
34
  <global>
35
  <models>
36
  <exactor_tax>
37
+ <class>ZzzzzExactor_Tax_Model</class>
38
  </exactor_tax>
39
  <tax>
40
  <rewrite>
41
+ <!-- Disable tax calculators -->
42
+ <sales_total_quote_nominal_tax>ZzzzzExactor_Tax_Model_Sales_Total_Quote_Nominal_Tax</sales_total_quote_nominal_tax>
43
+ <sales_total_quote_subtotal>ZzzzzExactor_Tax_Model_Sales_Total_Quote_Nominal_Tax</sales_total_quote_subtotal>
44
+
45
+ <!--Apply Exactor tax calculator-->
46
+ <sales_total_quote_tax>ZzzzzExactor_Tax_Model_Sales_Total_Quote_Tax</sales_total_quote_tax>
47
+ <sales_quote_address_total_tax>ZzzzzExactor_Tax_Model_Sales_Total_Quote_Tax</sales_quote_address_total_tax>
48
  </rewrite>
49
  </tax>
50
  </models>
51
  <helpers>
52
  <tax>
53
  <rewrite>
54
+ <calculation>ZzzzzExactor_Tax_Helper_Calculation</calculation>
55
+ <mapping>ZzzzzExactor_Tax_Helper_Mapping</mapping>
56
  </rewrite>
57
  </tax>
58
  </helpers>
59
+ <sales>
60
+ <quote>
61
+ <totals>
62
+ <tax>
63
+ <after>subtotal,shipping,discount,fooman_surcharge</after>
64
+ </tax>
65
+ </totals>
66
+ </quote>
67
+ </sales>
68
  </global>
69
 
70
  </config>
app/design/adminhtml/default/default/layout/exactorsettings.xml CHANGED
@@ -29,7 +29,7 @@
29
  <layout>
30
  <exactorsettings_adminhtml_form_index>
31
  <reference name="content">
32
- <block type="Exactor_ExactorSettings_Block_Form" name="ExactorSettingsForm" template="ExactorSettings/settingsform.phtml" />
33
  </reference>
34
  </exactorsettings_adminhtml_form_index>
35
  </layout>
29
  <layout>
30
  <exactorsettings_adminhtml_form_index>
31
  <reference name="content">
32
+ <block type="ZzzzzExactor_ExactorSettings_Block_Form" name="ExactorSettingsForm" template="ExactorSettings/settingsform.phtml" />
33
  </reference>
34
  </exactorsettings_adminhtml_form_index>
35
  </layout>
app/etc/modules/{Exactor.xml → ZzzzzExactor.xml} RENAMED
@@ -27,21 +27,21 @@
27
  -->
28
  <config>
29
  <modules>
30
- <Exactor_Tax>
31
  <codePool>local</codePool>
32
  <active>true</active>
33
- </Exactor_Tax>
34
- <Exactor_Core>
35
  <codePool>local</codePool>
36
  <active>true</active>
37
- </Exactor_Core>
38
- <Exactor_ExactorSettings>
39
  <codePool>local</codePool>
40
  <active>true</active>
41
- </Exactor_ExactorSettings>
42
- <Exactor_Sales>
43
  <codePool>local</codePool>
44
  <active>true</active>
45
- </Exactor_Sales>
46
  </modules>
47
  </config>
27
  -->
28
  <config>
29
  <modules>
30
+ <ZzzzzExactor_Tax>
31
  <codePool>local</codePool>
32
  <active>true</active>
33
+ </ZzzzzExactor_Tax>
34
+ <ZzzzzExactor_Core>
35
  <codePool>local</codePool>
36
  <active>true</active>
37
+ </ZzzzzExactor_Core>
38
+ <ZzzzzExactor_ExactorSettings>
39
  <codePool>local</codePool>
40
  <active>true</active>
41
+ </ZzzzzExactor_ExactorSettings>
42
+ <ZzzzzExactor_Sales>
43
  <codePool>local</codePool>
44
  <active>true</active>
45
+ </ZzzzzExactor_Sales>
46
  </modules>
47
  </config>
lib/ExactorCommons/ExactorCommons.php CHANGED
@@ -534,7 +534,14 @@ class ExactorDigitalSignatureBuilder{
534
  $this->appendAddressFields($invoice->getShipFrom());
535
  if ($invoice->getLineItems() == null) return;
536
  foreach ($invoice->getLineItems() as $lineItem){
 
 
 
 
537
  $this->appendValue($lineItem->getGrossAmount());
 
 
 
538
  }
539
  }
540
 
534
  $this->appendAddressFields($invoice->getShipFrom());
535
  if ($invoice->getLineItems() == null) return;
536
  foreach ($invoice->getLineItems() as $lineItem){
537
+ $this->appendValue($lineItem->getId());
538
+ $this->appendValue($lineItem->getSKU());
539
+ $this->appendValue($lineItem->getDescription());
540
+ $this->appendValue($lineItem->getQuantity());
541
  $this->appendValue($lineItem->getGrossAmount());
542
+ $this->appendAddressFields($lineItem->getShipFrom());
543
+ $this->appendAddressFields($lineItem->getBillTo());
544
+ $this->appendAddressFields($lineItem->getShipTo());
545
  }
546
  }
547
 
lib/ExactorCommons/ExactorDomainObjects.php CHANGED
@@ -600,6 +600,86 @@ class DeleteRequestType extends XmlSerializationSupport {
600
 
601
  /* ========================= Response Types ========================== */
602
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
603
  class ResponseLineItem extends XmlSerializationSupport{
604
  public $GrossAmount;
605
  public $TaxDirection;
@@ -610,7 +690,7 @@ class ResponseLineItem extends XmlSerializationSupport{
610
  protected function defineBindingRules()
611
  {
612
  $this->setBindingRulesFor('id')->xmlName('id')->toXmlAttribute();
613
- }
614
 
615
  public function setGrossAmount($GrossAmount)
616
  {
@@ -637,6 +717,9 @@ class ResponseLineItem extends XmlSerializationSupport{
637
  $this->TaxInfo = $TaxInfo;
638
  }
639
 
 
 
 
640
  public function getTaxInfo()
641
  {
642
  return $this->TaxInfo;
600
 
601
  /* ========================= Response Types ========================== */
602
 
603
+ class TaxInfo extends XmlSerializationSupport {
604
+ public $AuthorityLevel;
605
+ public $AuthorityName;
606
+ public $CityOrCountyOrDistrict;
607
+ public $StateOrProvince;
608
+ public $Country;
609
+ public $TaxAmount;
610
+ public $TaxRate;
611
+
612
+ public function setAuthorityLevel($AuthorityLevel)
613
+ {
614
+ $this->AuthorityLevel = $AuthorityLevel;
615
+ }
616
+
617
+ public function getAuthorityLevel()
618
+ {
619
+ return $this->AuthorityLevel;
620
+ }
621
+
622
+ public function setAuthorityName($AuthorityName)
623
+ {
624
+ $this->AuthorityName = $AuthorityName;
625
+ }
626
+
627
+ public function getAuthorityName()
628
+ {
629
+ return $this->AuthorityName;
630
+ }
631
+
632
+ public function setCityOrCountyOrDistrict($CityOrCountyOrDistrict)
633
+ {
634
+ $this->CityOrCountyOrDistrict = $CityOrCountyOrDistrict;
635
+ }
636
+
637
+ public function getCityOrCountyOrDistrict()
638
+ {
639
+ return $this->CityOrCountyOrDistrict;
640
+ }
641
+
642
+ public function setCountry($Country)
643
+ {
644
+ $this->Country = $Country;
645
+ }
646
+
647
+ public function getCountry()
648
+ {
649
+ return $this->Country;
650
+ }
651
+
652
+ public function setStateOrProvince($StateOrProvince)
653
+ {
654
+ $this->StateOrProvince = $StateOrProvince;
655
+ }
656
+
657
+ public function getStateOrProvince()
658
+ {
659
+ return $this->StateOrProvince;
660
+ }
661
+
662
+ public function setTaxAmount($TaxAmount)
663
+ {
664
+ $this->TaxAmount = $TaxAmount;
665
+ }
666
+
667
+ public function getTaxAmount()
668
+ {
669
+ return $this->TaxAmount;
670
+ }
671
+
672
+ public function setTaxRate($TaxRate)
673
+ {
674
+ $this->TaxRate = $TaxRate;
675
+ }
676
+
677
+ public function getTaxRate()
678
+ {
679
+ return $this->TaxRate;
680
+ }
681
+ }
682
+
683
  class ResponseLineItem extends XmlSerializationSupport{
684
  public $GrossAmount;
685
  public $TaxDirection;
690
  protected function defineBindingRules()
691
  {
692
  $this->setBindingRulesFor('id')->xmlName('id')->toXmlAttribute();
693
+ $this->setBindingRulesFor('TaxInfo')->objectType('array TaxInfo')->xmlName('TaxInfo');}
694
 
695
  public function setGrossAmount($GrossAmount)
696
  {
717
  $this->TaxInfo = $TaxInfo;
718
  }
719
 
720
+ /**
721
+ * @return TaxInfo[]
722
+ */
723
  public function getTaxInfo()
724
  {
725
  return $this->TaxInfo;
lib/ExactorCommons/Magento.php CHANGED
@@ -16,13 +16,13 @@ class MagentoExactorCallback extends IExactorPluginCallback{
16
 
17
  private $logger;
18
  /**
19
- * @var Exactor_Core_Helper_SessionCache
20
  */
21
  private $sessionCache;
22
 
23
  public function __construct(){
24
  $this->logger = ExactorLoggingFactory::getInstance()->getLogger($this);
25
- $this->sessionCache = Mage::helper('Exactor_Core_SessionCache/');
26
  }
27
 
28
  /**
@@ -34,8 +34,8 @@ class MagentoExactorCallback extends IExactorPluginCallback{
34
  function loadTransactionInfo($shoppingCartTrnId)
35
  {
36
  $this->logger->trace('called', 'loadTransactionInfo');
37
- /** @var Exactor_Core_Model_ExactorTransaction $exatorTransaction */
38
- $exatorTransaction = Mage::getModel('Exactor_Core_Model_ExactorTransaction');
39
  $exatorTransaction = $exatorTransaction->getCollection()->addFilter("OrderID",$shoppingCartTrnId)->getFirstItem();
40
  if (!$exatorTransaction->hasData()) return null;
41
  // Populating common object with DB dat
@@ -61,11 +61,11 @@ class MagentoExactorCallback extends IExactorPluginCallback{
61
  function saveTransactionInfo(ExactorTransactionInfo $transactionInfo, $requestKey)
62
  {
63
  $this->logger->trace('called', 'saveTransactionInfo');
64
- /** @var Exactor_Core_Model_ExactorTransaction $exatorTransaction */
65
- $exatorTransaction = Mage::getModel('Exactor_Core_Model_ExactorTransaction');
66
  $exatorTransaction = $exatorTransaction->getCollection()
67
  ->addFilter("OrderID",$transactionInfo->getShoppingCartTrnId())->getFirstItem();
68
- if (!$exatorTransaction->hasData()) $exatorTransaction = Mage::getModel('Exactor_Core_Model_ExactorTransaction');
69
 
70
  $transactionInfo->setSignature($requestKey);
71
  $exatorTransaction->setCommited($transactionInfo->getIsCommited());
16
 
17
  private $logger;
18
  /**
19
+ * @var ZzzzzExactor_Core_Helper_SessionCache
20
  */
21
  private $sessionCache;
22
 
23
  public function __construct(){
24
  $this->logger = ExactorLoggingFactory::getInstance()->getLogger($this);
25
+ $this->sessionCache = Mage::helper('ZzzzzExactor_Core_SessionCache/');
26
  }
27
 
28
  /**
34
  function loadTransactionInfo($shoppingCartTrnId)
35
  {
36
  $this->logger->trace('called', 'loadTransactionInfo');
37
+ /** @var ZzzzzExactor_Core_Model_ExactorTransaction $exatorTransaction */
38
+ $exatorTransaction = Mage::getModel('ZzzzzExactor_Core_Model_ExactorTransaction');
39
  $exatorTransaction = $exatorTransaction->getCollection()->addFilter("OrderID",$shoppingCartTrnId)->getFirstItem();
40
  if (!$exatorTransaction->hasData()) return null;
41
  // Populating common object with DB dat
61
  function saveTransactionInfo(ExactorTransactionInfo $transactionInfo, $requestKey)
62
  {
63
  $this->logger->trace('called', 'saveTransactionInfo');
64
+ /** @var ZzzzzExactor_Core_Model_ExactorTransaction $exatorTransaction */
65
+ $exatorTransaction = Mage::getModel('ZzzzzExactor_Core_Model_ExactorTransaction');
66
  $exatorTransaction = $exatorTransaction->getCollection()
67
  ->addFilter("OrderID",$transactionInfo->getShoppingCartTrnId())->getFirstItem();
68
+ if (!$exatorTransaction->hasData()) $exatorTransaction = Mage::getModel('ZzzzzExactor_Core_Model_ExactorTransaction');
69
 
70
  $transactionInfo->setSignature($requestKey);
71
  $exatorTransaction->setCommited($transactionInfo->getIsCommited());
lib/ExactorCommons/config.php CHANGED
@@ -14,9 +14,16 @@ define('EXACTOR_CONFIG_FEATURE_TRN_FILTER', 'trn-filter');
14
 
15
  define('EXACTOR_CONFIG_FEATURE_DISABLE_ESTIMATES', 'disable-estimates');
16
 
 
 
 
 
 
 
 
17
  /* Initializing factories */
18
  ExactorLoggingFactory::getInstance()->setup('MagentoLogger', IExactorLogger::DEBUG);
19
- ExactorConnectionFactory::getInstance()->setup('Magento','20140304');
20
  ExactorProcessingServiceFactory::getInstance()->setup(new MagentoExactorCallback());
21
 
22
  /* Initializing configuration object */
@@ -24,4 +31,5 @@ $config = ExactorPluginConfig::getInstance();
24
  $config->pushFeatureConfigString('');
25
 
26
  /* Pushing parameters */
27
- $config->set(EXACTOR_CONFIG_EXEMPT_DISCOUNTS, array());
 
14
 
15
  define('EXACTOR_CONFIG_FEATURE_DISABLE_ESTIMATES', 'disable-estimates');
16
 
17
+ /*
18
+ * Enable this option to always override tax in quotes instead of overriding only if quote checksum changes.
19
+ * Is useful in case if user installed other plug-ins overriding tax.
20
+ * WARNING: this option increases RAM memory consuming.
21
+ * */
22
+ define('EXACTOR_CONFIG_ALWAYS_OVERRIDE_TAX', 'always-override-tax');
23
+
24
  /* Initializing factories */
25
  ExactorLoggingFactory::getInstance()->setup('MagentoLogger', IExactorLogger::DEBUG);
26
+ ExactorConnectionFactory::getInstance()->setup('Magento','20140905');
27
  ExactorProcessingServiceFactory::getInstance()->setup(new MagentoExactorCallback());
28
 
29
  /* Initializing configuration object */
31
  $config->pushFeatureConfigString('');
32
 
33
  /* Pushing parameters */
34
+ $config->set(EXACTOR_CONFIG_EXEMPT_DISCOUNTS, array());
35
+ //$config->set(EXACTOR_CONFIG_ALWAYS_OVERRIDE_TAX, true);
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Mage_Exactor_Tax</name>
4
- <version>2014.03.04</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>
@@ -12,9 +12,9 @@ Once installed, neither the merchant, nor the customer, need to perform any addi
12
  For additional information, please refer to the Exactor Magento User Guide that is attached to the plug-in, or which you can download directly from the Exactor control panel (navigate to Account Management Integration Points &amp; PlugIns).</description>
13
  <notes>Supported Magento 1.5.0.0 - 1.7.x, Magento Enterprise 1.8-1.12.x</notes>
14
  <authors><author><name>Exactor, Inc.</name><user>exactor</user><email>support@exactor.com</email></author></authors>
15
- <date>2014-03-04</date>
16
- <time>15:47:40</time>
17
- <contents><target name="magelocal"><dir name="Exactor"><dir name="Core"><dir name="Helper"><file name="SessionCache.php" hash="72692a33574f8ba2f1858e2e93aa4edf"/></dir><dir name="Model"><file name="ExactorTransaction.php" hash="852aa20f6e3b7aa0001439d4bffe9724"/><file name="MerchantSettings.php" hash="71a7c2308f6f0eda102ae84dd90df751"/><dir name="Mysql4"><dir name="ExactorTransaction"><file name="Collection.php" hash="c7b890b4d3ab35e65a3856ae0e2fdf72"/></dir><file name="ExactorTransaction.php" hash="c91aebaae767613acf1c439a8b513c3b"/><dir name="MerchantSettings"><file name="Collection.php" hash="c1593f52e582e601409c4651c37495af"/><file name="Collection.php~" hash="d360e202eb30432ac41dc023ce13ffc0"/></dir><file name="MerchantSettings.php" hash="8f22b76bb64cdc7b1deb6f0e38889905"/></dir><dir name="Type"><file name="Onepage.php" hash="2441fb08bbeb579831cea4d3fbd31104"/></dir></dir><dir name="etc"><file name="config.xml" hash="98ecc82a5f7b74ac0bfc0f7ab512afdb"/></dir></dir><dir name="ExactorSettings"><dir name="Block"><file name="Form.php" hash="5ea1d72197306072fe5fad9b97d109e8"/></dir><dir name="Helper"><file name="Data.php" hash="659cee9ec4cb12af6bb9be13c3a4eb55"/><file name="VersionResolver.php" hash="14dce068dfe2a7d3364c4bd29e6f8431"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="FormController.php" hash="2a7c77cd96316601928713f42127f5ee"/></dir><file name="AjaxController.php" hash="c07aeeca00e1408e52945fc027569793"/><file name="IndexController.php" hash="f47cbc274dd68c57c30b60bbee69259e"/></dir><dir name="etc"><file name="config.xml" hash="674c326bfc901d0becf7c94ddcdd1452"/></dir><dir name="sql"><dir name="ExactorSettings_setup"><file name="mysql4-install-14.04.2012.php" hash="f35af1e12921b57479cb4b5677937a0c"/><file name="upgrade-2012.06.14-2012.09.25.php" hash="174fda5224bc23cdf147fb059d079478"/></dir></dir></dir><dir name="Sales"><dir name="Model"><file name="Observer.php" hash="dcba19f763b391c0f648a436651a09e0"/></dir><dir name="etc"><file name="config.xml" hash="ba31618f5165dda20010c40e7ef8dad1"/></dir></dir><dir name="Tax"><dir name="Helper"><file name="Calculation.php" hash="29c5252bdd48b173c90588f449114024"/><file name="Mapping.php" hash="ae5c1b4d261018c403297cdc8181d3a3"/></dir><dir name="Model"><dir name="Sales"><dir name="Total"><dir name="Quote"><dir name="Nominal"><file name="Tax.php" hash="156eff380df5b16db55449759f193490"/></dir><file name="Tax.php" hash="8e8302178f1f50410c11cbfa4b8f31b0"/></dir></dir></dir></dir><dir name="etc"><file name="config.xml" hash="dac507a6a0437f511973c29646bd6a8d"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="exactorsettings.xml" hash="3707eac08d2393c8796eebf1cf7a0bd9"/><file name="exactoronestepcheckout.xml" hash="9fdfa1db5e4e60b4eec8f348c10aab07"/></dir><dir name="template"><dir name="ExactorSettings"><file name="settingsform.phtml" hash="c423218861b708c3d572ac77623c6280"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="exactoronestepcheckout.xml" hash="9fdfa1db5e4e60b4eec8f348c10aab07"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Exactor.xml" hash="e8997e8e36a265141b37790caaef39d6"/></dir></target><target name="mageweb"><dir name="js"><dir name="exactor"><file name="exactor.js" hash="5c23e40f4034e50a6e0df5b1c708b7e1"/></dir></dir></target><target name="magelib"><dir name="ExactorCommons"><file name="ExactorCommons.php" hash="62b8c768d268a70812f3db62f7aaf25a"/><file name="ExactorDomainObjects.php" hash="a7ab4b08aab05061bc554f7c4405fde4"/><file name="Magento.php" hash="76da7333fe0692053a47f8564c7b513a"/><file name="RegionResolver.php" hash="2537638a7895a169cee4b1df786d22fb"/><file name="XmlProcessing.php" hash="1fe961d5c14d507b2bb82fd3dd94237c"/><file name="config.php" hash="48e938a1d440b127ea2ad4618c00ea95"/></dir></target></contents>
18
  <compatible/>
19
  <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
20
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Mage_Exactor_Tax</name>
4
+ <version>2014.09.05</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>
12
  For additional information, please refer to the Exactor Magento User Guide that is attached to the plug-in, or which you can download directly from the Exactor control panel (navigate to Account Management Integration Points &amp; PlugIns).</description>
13
  <notes>Supported Magento 1.5.0.0 - 1.7.x, Magento Enterprise 1.8-1.12.x</notes>
14
  <authors><author><name>Exactor, Inc.</name><user>exactor</user><email>support@exactor.com</email></author></authors>
15
+ <date>2014-09-05</date>
16
+ <time>07:54:52</time>
17
+ <contents><target name="magelocal"><dir name="ZzzzzExactor"><dir name="Core"><dir name="Helper"><file name="SessionCache.php" hash="4a48ea63099201bc04581febe21b7237"/></dir><dir name="Model"><file name="ExactorTransaction.php" hash="aee2205ef1e8b58fe8fead7385af2fdd"/><file name="MerchantSettings.php" hash="b58bcf01d15af966358aa1e0f27b9fbe"/><dir name="Mysql4"><dir name="ExactorTransaction"><file name="Collection.php" hash="5078855300f1b8895c5429fb10f37854"/></dir><file name="ExactorTransaction.php" hash="4b8f45cc739ac05b71be3f38c0138109"/><dir name="MerchantSettings"><file name="Collection.php" hash="4c7e905444d9f02c1e82033cd147afc5"/></dir><file name="MerchantSettings.php" hash="fd98ded15c7dde7bcc1746a40c24aa85"/></dir><dir name="Type"><file name="Onepage.php" hash="8c9c744d769f4064dcc344d4d474dd2a"/></dir></dir><dir name="etc"><file name="config.xml" hash="654bd7d22e5a308722d8769a1233ad80"/></dir></dir><dir name="ExactorSettings"><dir name="Block"><file name="Form.php" hash="3189371ce1fca8f2ff72b165da762e2e"/></dir><dir name="Helper"><file name="Data.php" hash="08ff0be3da068e35731d5cbcb5ca031d"/><file name="VersionResolver.php" hash="e05646123b776551295cdc1050eb80a0"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="FormController.php" hash="83e0faaffe8a93e4fbccf9e0c0b4914f"/></dir><file name="AjaxController.php" hash="e0a9122472eebdf2ba9d703b35e528e6"/><file name="IndexController.php" hash="064275cda39bf28a23f0e30cda85d546"/></dir><dir name="etc"><file name="config.xml" hash="63ed7c63ac663fa72b1a645275499c34"/></dir><dir name="sql"><dir name="ExactorSettings_setup"><file name="mysql4-install-14.04.2012.php" hash="171dcba8395c21dccd336c86cd92db5d"/><file name="upgrade-2012.06.14-2012.09.25.php" hash="217c13f3fecf41decff7f0cbc908f0f8"/></dir></dir></dir><dir name="Sales"><dir name="Model"><file name="Observer.php" hash="2107eccfd9c3525d36c6949d98b5a959"/></dir><dir name="etc"><file name="config.xml" hash="20483c2cc3730e5ea279023ef47c3d14"/></dir></dir><dir name="Tax"><dir name="Helper"><file name="Calculation.php" hash="30378738db4beea10d7caeb256018be6"/><file name="Mapping.php" hash="11e80ef7e4fb3ae7d6964c3b887a5a11"/></dir><dir name="Model"><dir name="Sales"><dir name="Total"><dir name="Quote"><dir name="Nominal"><file name="Tax.php" hash="26eb88861c5f47c410ec837059e28bee"/></dir><file name="Tax.php" hash="f124f0ddcbdb3514fe7b0d4164dc6267"/></dir></dir></dir></dir><dir name="etc"><file name="config.xml" hash="1c3235fa291ec1d81855a5015376cf51"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="exactorsettings.xml" hash="c6411fb02004382e2bde340e2eea8ba1"/><file name="exactoronestepcheckout.xml" hash="9fdfa1db5e4e60b4eec8f348c10aab07"/></dir><dir name="template"><dir name="ExactorSettings"><file name="settingsform.phtml" hash="c423218861b708c3d572ac77623c6280"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="exactoronestepcheckout.xml" hash="9fdfa1db5e4e60b4eec8f348c10aab07"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="ZzzzzExactor.xml" hash="d5d93cb5e6608f3cf87f5a57ed1448c7"/></dir></target><target name="mageweb"><dir name="js"><dir name="exactor"><file name="exactor.js" hash="5c23e40f4034e50a6e0df5b1c708b7e1"/></dir></dir></target><target name="magelib"><dir name="ExactorCommons"><file name="ExactorCommons.php" hash="03b83a20edc9a129a16230b5033f94ce"/><file name="ExactorDomainObjects.php" hash="c708118429f6bea5c5c3a9c4caf28e99"/><file name="Magento.php" hash="07fe9cf20e5368ac6c6dee45c26a07f8"/><file name="RegionResolver.php" hash="2537638a7895a169cee4b1df786d22fb"/><file name="XmlProcessing.php" hash="1fe961d5c14d507b2bb82fd3dd94237c"/><file name="config.php" hash="113b33abb70575f2f924759126dd6552"/></dir></target></contents>
18
  <compatible/>
19
  <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
20
  </package>