zitec_dpd - Version 1.0.7

Version Notes

Added postcode database management form

Download this release

Release Info

Developer Zitec
Extension zitec_dpd
Version 1.0.7
Comparing to
See all releases


Code changes from version 1.0.5 to 1.0.7

Files changed (131) hide show
  1. app/code/community/Zitec/Dpd/Block/Addresslength.php +138 -138
  2. app/code/community/Zitec/Dpd/Block/Adminhtml/Customer/Edit/Form/Addresslength.php +80 -80
  3. app/code/community/Zitec/Dpd/Block/Adminhtml/Order/Form.php +80 -0
  4. app/code/community/Zitec/Dpd/Block/Adminhtml/Order/Totals/Cashondeliverysurcharge/Newcreditmemo.php +39 -39
  5. app/code/community/Zitec/Dpd/Block/Adminhtml/Postcode/FormContainer.php +52 -0
  6. app/code/community/Zitec/Dpd/Block/Adminhtml/Postcode/Update/Files.php +57 -0
  7. app/code/community/Zitec/Dpd/Block/Adminhtml/Postcode/UpdateForm/Form.php +66 -0
  8. app/code/community/Zitec/Dpd/Block/Adminhtml/Sales/Order/Address/Form/Addresslength.php +107 -107
  9. app/code/community/Zitec/Dpd/Block/Adminhtml/Sales/Order/Shipment/View.php +74 -74
  10. app/code/community/Zitec/Dpd/Block/Adminhtml/Sales/Order/Shipment/View/Tracking.php +80 -80
  11. app/code/community/Zitec/Dpd/Block/Adminhtml/Sales/Shipment/Grid.php +119 -119
  12. app/code/community/Zitec/Dpd/Block/Adminhtml/Sales/Shipment/Grid/Renderer/Manifest.php +52 -52
  13. app/code/community/Zitec/Dpd/Block/Adminhtml/Shipment/Postcode/Autocompleter.php +31 -31
  14. app/code/community/Zitec/Dpd/Block/Adminhtml/System/Config/Button/Export.php +48 -48
  15. app/code/community/Zitec/Dpd/Block/Adminhtml/Tablerate/Grid.php +155 -155
  16. app/code/community/Zitec/Dpd/Block/Checkout/Onepage/Addresslength.php +37 -37
  17. app/code/community/Zitec/Dpd/Block/Customer/Address/Edit/Addresslength.php +37 -37
  18. app/code/community/Zitec/Dpd/Block/Order/Creditmemo/Totals/Cashondeliverysurcharge.php +72 -72
  19. app/code/community/Zitec/Dpd/Block/Order/Invoice/Totals/Cashondeliverysurcharge.php +72 -72
  20. app/code/community/Zitec/Dpd/Block/Order/Totals/Cashondeliverysurchage.php +160 -160
  21. app/code/community/Zitec/Dpd/Block/Tax/Checkout/Cashondeliverysurchage.php +125 -125
  22. app/code/community/Zitec/Dpd/Helper/Compatibility.php +76 -76
  23. app/code/community/Zitec/Dpd/Helper/Data.php +594 -594
  24. app/code/community/Zitec/Dpd/Helper/Layout.php +107 -107
  25. app/code/community/Zitec/Dpd/Helper/Payment.php +56 -56
  26. app/code/community/Zitec/Dpd/Helper/Postcode/Search.php +211 -181
  27. app/code/community/Zitec/Dpd/Helper/Ws.php +395 -395
  28. app/code/community/Zitec/Dpd/Model/Config/Data/Abstract.php +75 -75
  29. app/code/community/Zitec/Dpd/Model/Config/Data/Mode.php +66 -66
  30. app/code/community/Zitec/Dpd/Model/Config/Data/Tablerate.php +47 -47
  31. app/code/community/Zitec/Dpd/Model/Config/Source/Abstract.php +58 -58
  32. app/code/community/Zitec/Dpd/Model/Config/Source/Order/Status/Pendingpayment.php +30 -30
  33. app/code/community/Zitec/Dpd/Model/Config/Source/Service.php +113 -113
  34. app/code/community/Zitec/Dpd/Model/Config/Source/Wscountry.php +57 -57
  35. app/code/community/Zitec/Dpd/Model/Dpd/Manifest.php +296 -296
  36. app/code/community/Zitec/Dpd/Model/Dpd/Pickup.php +41 -41
  37. app/code/community/Zitec/Dpd/Model/Dpd/Ship.php +40 -40
  38. app/code/community/Zitec/Dpd/Model/Mysql4/Carrier/Tablerate.php +734 -734
  39. app/code/community/Zitec/Dpd/Model/Mysql4/Carrier/Tablerate/Collection.php +109 -109
  40. app/code/community/Zitec/Dpd/Model/Mysql4/Dpd/Manifest.php +57 -57
  41. app/code/community/Zitec/Dpd/Model/Mysql4/Dpd/Pickup.php +34 -34
  42. app/code/community/Zitec/Dpd/Model/Mysql4/Dpd/Ship.php +41 -41
  43. app/code/community/Zitec/Dpd/Model/Mysql4/Dpd/Ship/Collection.php +92 -92
  44. app/code/community/Zitec/Dpd/Model/Observer/Address.php +179 -179
  45. app/code/community/Zitec/Dpd/Model/Observer/Manifest.php +54 -54
  46. app/code/community/Zitec/Dpd/Model/Observer/Payment.php +59 -59
  47. app/code/community/Zitec/Dpd/Model/Observer/Pickup.php +80 -80
  48. app/code/community/Zitec/Dpd/Model/Observer/Shipment.php +454 -454
  49. app/code/community/Zitec/Dpd/Model/Payment/Cashondelivery.php +213 -213
  50. app/code/community/Zitec/Dpd/Model/Payment/Cashondelivery/Source/AmountType.php +41 -41
  51. app/code/community/Zitec/Dpd/Model/Payment/Cashondelivery/Source/Codpaymenttype.php +42 -42
  52. app/code/community/Zitec/Dpd/Model/Payment/Cashondelivery/Source/Country.php +64 -64
  53. app/code/community/Zitec/Dpd/Model/Payment/Cashondelivery/Source/Service.php +66 -66
  54. app/code/community/Zitec/Dpd/Model/Sales/Order/Creditmemo/Total/Cashondeliverysurchage.php +61 -61
  55. app/code/community/Zitec/Dpd/Model/Sales/Order/Creditmemo/Total/Tax.php +50 -50
  56. app/code/community/Zitec/Dpd/Model/Sales/Order/Invoice/Total/Cashondeliverysurchage.php +60 -60
  57. app/code/community/Zitec/Dpd/Model/Sales/Order/Invoice/Total/Tax.php +60 -60
  58. app/code/community/Zitec/Dpd/Model/Sales/Order/Pdf/Total/Cashondeliverysurchage.php +113 -113
  59. app/code/community/Zitec/Dpd/Model/Sales/Order/Total/Cashondeliverysurchage.php +41 -41
  60. app/code/community/Zitec/Dpd/Model/Sales/Quote/Address/Total/Cashondeliverysurchage.php +182 -182
  61. app/code/community/Zitec/Dpd/Model/Shipping/Carrier/Abstract.php +87 -87
  62. app/code/community/Zitec/Dpd/Model/Shipping/Carrier/Dpd.php +541 -541
  63. app/code/community/Zitec/Dpd/controllers/Adminhtml/ConfigController.php +39 -39
  64. app/code/community/Zitec/Dpd/controllers/Adminhtml/PostcodeController.php +185 -0
  65. app/code/community/Zitec/Dpd/controllers/Adminhtml/ShipmentController.php +463 -463
  66. app/code/community/Zitec/Dpd/etc/adminhtml.xml +79 -74
  67. app/code/community/Zitec/Dpd/etc/config.xml +397 -397
  68. app/code/community/Zitec/Dpd/etc/system.xml +379 -379
  69. app/code/community/Zitec/Dpd/sql/zitec_dpd_setup/mysql4-install-1.0.0.php +208 -208
  70. app/code/community/Zitec/Dpd/sql/zitec_dpd_setup/mysql4-upgrade-1.0.0-1.0.1.php +43 -43
  71. app/code/community/Zitec/Dpd/sql/zitec_dpd_setup/mysql4-upgrade-1.0.1-1.0.2.php +36 -36
  72. app/code/community/Zitec/Dpd/sql/zitec_dpd_setup/mysql4-upgrade-1.0.2-1.0.3.php +37 -37
  73. app/code/community/Zitec/PackedShipment/Block/Addressvalidationdialog.php +105 -105
  74. app/code/community/Zitec/PackedShipment/Block/Addressvalidationinfojs.php +130 -130
  75. app/code/community/Zitec/PackedShipment/Helper/Data.php +143 -143
  76. app/code/community/Zitec/PackedShipment/Model/Carrier/Interface.php +96 -96
  77. app/code/community/Zitec/PackedShipment/Model/Package.php +272 -272
  78. app/code/community/Zitec/PackedShipment/Model/PackedShipment.php +50 -50
  79. app/code/community/Zitec/PackedShipment/controllers/Adminhtml/IndexController.php +119 -119
  80. app/code/community/Zitec/PackedShipment/etc/config.xml +61 -61
  81. app/code/community/Zitec/PrintShippingLabel/Block/Adminhtml/Sales/Order/Shipment/View.php +63 -63
  82. app/code/community/Zitec/PrintShippingLabel/Block/Adminhtml/Sales/View.php +69 -69
  83. app/code/community/Zitec/PrintShippingLabel/Helper/Data.php +29 -29
  84. app/code/community/Zitec/PrintShippingLabel/controllers/Adminhtml/IndexController.php +148 -148
  85. app/code/community/Zitec/PrintShippingLabel/etc/config.xml +89 -89
  86. app/code/community/Zitec/ReportsCommon/Block/RecordsReport/Grid.php +631 -631
  87. app/code/community/Zitec/ReportsCommon/Block/Renderer/Posnegcurrency.php +43 -43
  88. app/code/community/Zitec/ReportsCommon/Controller/Adminhtml/RecordsreportController.php +115 -115
  89. app/code/community/Zitec/ReportsCommon/Helper/Data.php +29 -29
  90. app/code/community/Zitec/ReportsCommon/etc/adminhtml.xml +31 -31
  91. app/code/community/Zitec/ReportsCommon/etc/config.xml +21 -21
  92. app/code/community/Zitec/ShippingReports/Block/Adminhtml/Profitability.php +47 -47
  93. app/code/community/Zitec/ShippingReports/Block/Adminhtml/Profitability/Grid.php +126 -126
  94. app/code/community/Zitec/ShippingReports/Block/Adminhtml/Profitability/Renderer/Orderref.php +39 -39
  95. app/code/community/Zitec/ShippingReports/Helper/Data.php +28 -28
  96. app/code/community/Zitec/ShippingReports/Model/Mysql4/Profitability/Collection.php +72 -72
  97. app/code/community/Zitec/ShippingReports/Model/Observer/Order.php +58 -58
  98. app/code/community/Zitec/ShippingReports/Model/Observer/Shipment.php +89 -89
  99. app/code/community/Zitec/ShippingReports/controllers/Adminhtml/Reports/ProfitabilityController.php +35 -35
  100. app/code/community/Zitec/ShippingReports/etc/adminhtml.xml +42 -42
  101. app/code/community/Zitec/ShippingReports/etc/config.xml +79 -79
  102. app/code/community/Zitec/ShippingReports/sql/zitec_shippingreports_setup/mysql4-install-1.0.0.php +41 -41
  103. app/code/community/Zitec/TableRates/Block/Adminhtml/Tablerate.php +75 -75
  104. app/code/community/Zitec/TableRates/Block/Adminhtml/Tablerate/Edit.php +356 -356
  105. app/code/community/Zitec/TableRates/Block/Adminhtml/Tablerate/Edit/Form.php +276 -276
  106. app/code/community/Zitec/TableRates/Block/Adminhtml/Tablerate/Export.php +62 -62
  107. app/code/community/Zitec/TableRates/Block/Adminhtml/Tablerate/Export/Form.php +75 -75
  108. app/code/community/Zitec/TableRates/Block/Adminhtml/Tablerate/Grid.php +350 -350
  109. app/code/community/Zitec/TableRates/Block/Adminhtml/Tablerate/Grid/Renderer/Shippingpercentage.php +38 -38
  110. app/code/community/Zitec/TableRates/Block/Adminhtml/Tablerate/Import.php +61 -61
  111. app/code/community/Zitec/TableRates/Block/Adminhtml/Tablerate/Import/Form.php +78 -78
  112. app/code/community/Zitec/TableRates/Block/Adminhtml/Widget/Grid/Column/Filter/Region.php +41 -41
  113. app/code/community/Zitec/TableRates/Helper/Data.php +267 -267
  114. app/code/community/Zitec/TableRates/Helper/Directory.php +75 -75
  115. app/code/community/Zitec/TableRates/Model/Mysql4/Tablerate.php +180 -180
  116. app/code/community/Zitec/TableRates/Model/Mysql4/Tablerate/Collection.php +92 -92
  117. app/code/community/Zitec/TableRates/Model/Source/Website.php +55 -55
  118. app/code/community/Zitec/TableRates/Model/Tablerate.php +88 -88
  119. app/code/community/Zitec/TableRates/controllers/Adminhtml/IndexController.php +461 -461
  120. app/code/community/Zitec/TableRates/etc/adminhtml.xml +21 -21
  121. app/code/community/Zitec/TableRates/etc/config.xml +100 -100
  122. app/design/adminhtml/default/default/layout/zitec_dpd.xml +94 -94
  123. app/design/adminhtml/default/default/layout/zitec_packedshipment.xml +34 -34
  124. app/design/adminhtml/default/default/layout/zitec_shippingreports.xml +7 -7
  125. app/design/adminhtml/default/default/layout/zitec_tablerates.xml +37 -37
  126. app/design/adminhtml/default/default/template/zitec_dpd/potcode/update/available-files.phtml +25 -0
  127. app/design/adminhtml/default/default/template/zitec_dpd/sales/order/address/postcode/alert-problem.phtml +24 -24
  128. app/design/adminhtml/default/default/template/zitec_dpd/sales/order/address/postcode/validate.phtml +37 -37
  129. app/design/adminhtml/default/default/template/zitec_dpd/sales/order/address/street/alert-problem.phtml +22 -22
  130. app/design/adminhtml/default/default/template/zitec_dpd/sales/order/shipment/postcode/autocompleter.phtml +14 -14
  131. app/design/adminhtml/default/default/template/zitec_dpd/sales/order/shipment/view/tracking.phtml +26 -86
app/code/community/Zitec/Dpd/Block/Addresslength.php CHANGED
@@ -1,138 +1,138 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Block_Addresslength extends Mage_Core_Block_Template
25
- {
26
- /**
27
- *
28
- * @return string
29
- */
30
- public function getClassName()
31
- {
32
- return "zitec_dpd-address-length-validate";
33
- }
34
-
35
- /**
36
- *
37
- * @return int
38
- */
39
- public function getMaxLength()
40
- {
41
- return Zitec_Dpd_Api_Configs::SHIPMENT_LIST_RECEIVER_STREET_MAX_LENGTH;
42
- }
43
-
44
- public function getMinLength()
45
- {
46
- return 35;
47
- }
48
-
49
- /**
50
- *
51
- * @return array
52
- */
53
- public function getFieldNames()
54
- {
55
- return array();
56
- }
57
-
58
- /**
59
- *
60
- * @return string
61
- */
62
- public function getMessage()
63
- {
64
- return $this->__("The total length of the address cannot be more than %s characters.", $this->getMaxLength());
65
- }
66
-
67
- /**
68
- *
69
- * @param array $fieldNames
70
- *
71
- * @return string
72
- */
73
- protected function _getHtml(array $fieldNames)
74
- {
75
- if (!$fieldNames) {
76
- return '';
77
- }
78
-
79
- $fieldsHtml = '';
80
- foreach ($fieldNames as $fieldName) {
81
- $fieldsHtml .= "
82
- field = $('{$fieldName}');
83
- if (field) {
84
- fields.push(field);
85
- }";
86
- }
87
-
88
- $html = "
89
- <script type='text/javascript'>
90
- //<![CDATA[
91
- var className = '{$this->getClassName()}',
92
- fields = [],
93
- field = null,
94
- message = '{$this->getMessage()}',
95
- maxLength = {$this->getMaxLength()},
96
- minLength = {$this->getMinLength()};
97
-
98
- {$fieldsHtml}
99
-
100
- new zitecFieldLengths.Validator(className, fields, message, maxLength, minLength);
101
- //]]>
102
- </script>";
103
-
104
- return $html;
105
- }
106
-
107
- /**
108
- *
109
- * @return string
110
- */
111
- protected function _toHtml()
112
- {
113
- if ($this->_showBlock()) {
114
- return $this->_getHtml($this->getFieldNames());
115
- } else {
116
- return '';
117
- }
118
- }
119
-
120
- /**
121
- *
122
- * @return boolean
123
- */
124
- protected function _showBlock()
125
- {
126
- return $this->_getHelper()->moduleIsActive();
127
- }
128
-
129
- /**
130
- *
131
- * @return Zitec_Dpd_Helper_Data
132
- */
133
- protected function _getHelper()
134
- {
135
- return Mage::helper('zitec_dpd');
136
- }
137
- }
138
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Block_Addresslength extends Mage_Core_Block_Template
25
+ {
26
+ /**
27
+ *
28
+ * @return string
29
+ */
30
+ public function getClassName()
31
+ {
32
+ return "zitec_dpd-address-length-validate";
33
+ }
34
+
35
+ /**
36
+ *
37
+ * @return int
38
+ */
39
+ public function getMaxLength()
40
+ {
41
+ return Zitec_Dpd_Api_Configs::SHIPMENT_LIST_RECEIVER_STREET_MAX_LENGTH;
42
+ }
43
+
44
+ public function getMinLength()
45
+ {
46
+ return 35;
47
+ }
48
+
49
+ /**
50
+ *
51
+ * @return array
52
+ */
53
+ public function getFieldNames()
54
+ {
55
+ return array();
56
+ }
57
+
58
+ /**
59
+ *
60
+ * @return string
61
+ */
62
+ public function getMessage()
63
+ {
64
+ return $this->__("The total length of the address cannot be more than %s characters.", $this->getMaxLength());
65
+ }
66
+
67
+ /**
68
+ *
69
+ * @param array $fieldNames
70
+ *
71
+ * @return string
72
+ */
73
+ protected function _getHtml(array $fieldNames)
74
+ {
75
+ if (!$fieldNames) {
76
+ return '';
77
+ }
78
+
79
+ $fieldsHtml = '';
80
+ foreach ($fieldNames as $fieldName) {
81
+ $fieldsHtml .= "
82
+ field = $('{$fieldName}');
83
+ if (field) {
84
+ fields.push(field);
85
+ }";
86
+ }
87
+
88
+ $html = "
89
+ <script type='text/javascript'>
90
+ //<![CDATA[
91
+ var className = '{$this->getClassName()}',
92
+ fields = [],
93
+ field = null,
94
+ message = '{$this->getMessage()}',
95
+ maxLength = {$this->getMaxLength()},
96
+ minLength = {$this->getMinLength()};
97
+
98
+ {$fieldsHtml}
99
+
100
+ new zitecFieldLengths.Validator(className, fields, message, maxLength, minLength);
101
+ //]]>
102
+ </script>";
103
+
104
+ return $html;
105
+ }
106
+
107
+ /**
108
+ *
109
+ * @return string
110
+ */
111
+ protected function _toHtml()
112
+ {
113
+ if ($this->_showBlock()) {
114
+ return $this->_getHtml($this->getFieldNames());
115
+ } else {
116
+ return '';
117
+ }
118
+ }
119
+
120
+ /**
121
+ *
122
+ * @return boolean
123
+ */
124
+ protected function _showBlock()
125
+ {
126
+ return $this->_getHelper()->moduleIsActive();
127
+ }
128
+
129
+ /**
130
+ *
131
+ * @return Zitec_Dpd_Helper_Data
132
+ */
133
+ protected function _getHelper()
134
+ {
135
+ return Mage::helper('zitec_dpd');
136
+ }
137
+ }
138
+
app/code/community/Zitec/Dpd/Block/Adminhtml/Customer/Edit/Form/Addresslength.php CHANGED
@@ -1,80 +1,80 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Block_Adminhtml_Customer_Edit_Form_Addresslength extends Zitec_Dpd_Block_Addresslength
25
- {
26
-
27
-
28
- /**
29
- *
30
- * @return array
31
- */
32
- public function getFieldNames()
33
- {
34
- return array("street0", "street1", "street2", "street3");
35
- }
36
-
37
- /**
38
- *
39
- * @param array $fieldNames
40
- *
41
- * @return string
42
- */
43
- protected function _getHtml(array $fieldNames)
44
- {
45
- if (!$fieldNames) {
46
- return '';
47
- }
48
-
49
- $fieldsHtml = '';
50
- foreach ($fieldNames as $fieldName) {
51
- $fieldsHtml .= "
52
- field = $('{$fieldName}');
53
- if (field) {
54
- fields.push(field);
55
- }";
56
- }
57
-
58
- $html = "
59
- <script type='text/javascript'>
60
- //<![CDATA[
61
- var className = '{$this->getClassName()}',
62
- fields = [],
63
- field = null,
64
- message = '{$this->getMessage()}',
65
- maxLength = {$this->getMaxLength()},
66
- minLength = {$this->getMinLength()};
67
-
68
- {$fieldsHtml}
69
-
70
- new zitecFieldLengths.Validator(className, fields, message, maxLength, minLength);
71
- //]]>
72
- </script>";
73
-
74
- return $html;
75
- }
76
-
77
-
78
- }
79
-
80
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Block_Adminhtml_Customer_Edit_Form_Addresslength extends Zitec_Dpd_Block_Addresslength
25
+ {
26
+
27
+
28
+ /**
29
+ *
30
+ * @return array
31
+ */
32
+ public function getFieldNames()
33
+ {
34
+ return array("street0", "street1", "street2", "street3");
35
+ }
36
+
37
+ /**
38
+ *
39
+ * @param array $fieldNames
40
+ *
41
+ * @return string
42
+ */
43
+ protected function _getHtml(array $fieldNames)
44
+ {
45
+ if (!$fieldNames) {
46
+ return '';
47
+ }
48
+
49
+ $fieldsHtml = '';
50
+ foreach ($fieldNames as $fieldName) {
51
+ $fieldsHtml .= "
52
+ field = $('{$fieldName}');
53
+ if (field) {
54
+ fields.push(field);
55
+ }";
56
+ }
57
+
58
+ $html = "
59
+ <script type='text/javascript'>
60
+ //<![CDATA[
61
+ var className = '{$this->getClassName()}',
62
+ fields = [],
63
+ field = null,
64
+ message = '{$this->getMessage()}',
65
+ maxLength = {$this->getMaxLength()},
66
+ minLength = {$this->getMinLength()};
67
+
68
+ {$fieldsHtml}
69
+
70
+ new zitecFieldLengths.Validator(className, fields, message, maxLength, minLength);
71
+ //]]>
72
+ </script>";
73
+
74
+ return $html;
75
+ }
76
+
77
+
78
+ }
79
+
80
+
app/code/community/Zitec/Dpd/Block/Adminhtml/Order/Form.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Block_Adminhtml_Customer_Edit_Form_Addresslength extends Zitec_Dpd_Block_Addresslength
25
+ {
26
+
27
+
28
+ /**
29
+ *
30
+ * @return array
31
+ */
32
+ public function getFieldNames()
33
+ {
34
+ return array("street0", "street1", "street2", "street3");
35
+ }
36
+
37
+ /**
38
+ *
39
+ * @param array $fieldNames
40
+ *
41
+ * @return string
42
+ */
43
+ protected function _getHtml(array $fieldNames)
44
+ {
45
+ if (!$fieldNames) {
46
+ return '';
47
+ }
48
+
49
+ $fieldsHtml = '';
50
+ foreach ($fieldNames as $fieldName) {
51
+ $fieldsHtml .= "
52
+ field = $('{$fieldName}');
53
+ if (field) {
54
+ fields.push(field);
55
+ }";
56
+ }
57
+
58
+ $html = "
59
+ <script type='text/javascript'>
60
+ //<![CDATA[
61
+ var className = '{$this->getClassName()}',
62
+ fields = [],
63
+ field = null,
64
+ message = '{$this->getMessage()}',
65
+ maxLength = {$this->getMaxLength()},
66
+ minLength = {$this->getMinLength()};
67
+
68
+ {$fieldsHtml}
69
+
70
+ new zitecFieldLengths.Validator(className, fields, message, maxLength, minLength);
71
+ //]]>
72
+ </script>";
73
+
74
+ return $html;
75
+ }
76
+
77
+
78
+ }
79
+
80
+
app/code/community/Zitec/Dpd/Block/Adminhtml/Order/Totals/Cashondeliverysurcharge/Newcreditmemo.php CHANGED
@@ -1,39 +1,39 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Block_Adminhtml_Order_Totals_Cashondeliverysurcharge_Newcreditmemo extends Zitec_Dpd_Block_Order_Creditmemo_Totals_Cashondeliverysurcharge
25
- {
26
-
27
- /**
28
- *
29
- * @return string
30
- */
31
- protected function _getAfter()
32
- {
33
- return $this->_getConfig()->displaySalesSubtotalBoth($this->_getStore()) ? 'subtotal_incl' : 'subtotal';
34
- }
35
-
36
-
37
- }
38
-
39
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Block_Adminhtml_Order_Totals_Cashondeliverysurcharge_Newcreditmemo extends Zitec_Dpd_Block_Order_Creditmemo_Totals_Cashondeliverysurcharge
25
+ {
26
+
27
+ /**
28
+ *
29
+ * @return string
30
+ */
31
+ protected function _getAfter()
32
+ {
33
+ return $this->_getConfig()->displaySalesSubtotalBoth($this->_getStore()) ? 'subtotal_incl' : 'subtotal';
34
+ }
35
+
36
+
37
+ }
38
+
39
+
app/code/community/Zitec/Dpd/Block/Adminhtml/Postcode/FormContainer.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Block_Adminhtml_Postcode_FormContainer extends Mage_Adminhtml_Block_Widget_Form_Container
25
+ {
26
+
27
+
28
+ public function __construct()
29
+ {
30
+ parent::__construct();
31
+ $this->_objectId = 'id';
32
+ $this->_blockGroup = 'zitec_dpd';
33
+ $this->_controller = 'adminhtml_postcode';
34
+ $this->_mode = 'updateForm';
35
+ $this->_headerText = Mage::helper('core')->__('Update postcode database - for DPD Carrier');
36
+
37
+ $this->_updateButton('save', 'label', Mage::helper('core')->__('Import'));
38
+
39
+ }
40
+
41
+
42
+
43
+
44
+ public function getBackUrl()
45
+ {
46
+ return $this->getUrl('*/slider/manage_blocks');
47
+ }
48
+
49
+
50
+ }
51
+
52
+
app/code/community/Zitec/Dpd/Block/Adminhtml/Postcode/Update/Files.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Block_Adminhtml_Postcode_Update_Files extends Mage_Adminhtml_Block_Widget
25
+ {
26
+ public function __construct(){
27
+ $this->setTemplate('zitec_dpd/potcode/update/available-files.phtml');
28
+ }
29
+
30
+ /**
31
+ * return all csv files in the predefined path
32
+ * @return array
33
+ */
34
+ public function getAvailableCsvFiles()
35
+ {
36
+ $path = Mage::helper('zitec_dpd/postcode_search')->getPathToDatabaseUpgradeFiles();
37
+ $files = array();
38
+ if ($handle = opendir($path)) {
39
+ while (false !== ($entry = readdir($handle))) {
40
+ if($entry=='.' || $entry == '..'){
41
+ continue;
42
+ }
43
+ $ext = pathinfo($entry, PATHINFO_EXTENSION);
44
+ if(strtolower($ext) !== 'csv'){
45
+ continue;
46
+ }
47
+ $files[$entry] = filemtime($path.$entry);
48
+ }
49
+ closedir($handle);
50
+ }
51
+ asort ($files);
52
+ return $files;
53
+
54
+ }
55
+ }
56
+
57
+
app/code/community/Zitec/Dpd/Block/Adminhtml/Postcode/UpdateForm/Form.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Block_Adminhtml_Postcode_UpdateForm_Form extends Mage_Adminhtml_Block_Widget_Form
25
+ {
26
+
27
+ /**
28
+ * prepare form fields
29
+ *
30
+ * @return Mage_Adminhtml_Block_Widget_Form
31
+ * @throws Exception
32
+ */
33
+ protected function _prepareForm()
34
+ {
35
+ $form = new Varien_Data_Form(array(
36
+ 'id' => 'edit_form',
37
+ 'action' => $this->getUrl('*/adminhtml_postcode/import', array('id' => $this->getRequest()->getParam('id'))),
38
+ 'enctype' => 'multipart/form-data',
39
+ 'method' => 'post',
40
+ )
41
+ );
42
+
43
+ $fieldset = $form->addFieldset('csv_upload', array('legend' => 'Upload a CSV to update the postcode database - DPD'));
44
+ $fieldset->addField('csv', 'file',
45
+ array(
46
+ 'label' => 'CSV file received from DPD',
47
+ 'name' => 'csv'
48
+ ));
49
+
50
+ $fieldset = $form->addFieldset('csv_file_path', array('legend' => ' Import an existing file'));
51
+ $fieldset->addField('path_to_csv', 'text',
52
+ array(
53
+ 'label' => 'File name of the CSV found in media/dpd/postcode_update',
54
+ 'name' => 'path_to_csv'
55
+ ));
56
+
57
+
58
+ $form->setUseContainer(true);
59
+ $this->setForm($form);
60
+
61
+ return parent::_prepareForm();
62
+ }
63
+
64
+ }
65
+
66
+
app/code/community/Zitec/Dpd/Block/Adminhtml/Sales/Order/Address/Form/Addresslength.php CHANGED
@@ -1,107 +1,107 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Block_Adminhtml_Sales_Order_Address_Form_Addresslength extends Zitec_Dpd_Block_Addresslength
25
- {
26
-
27
- /**
28
- *
29
- * @return array
30
- */
31
- public function getFieldNames()
32
- {
33
- return array("street0", "street1", "street2", "street3");
34
- }
35
-
36
- /**
37
- *
38
- * @return boolean
39
- */
40
- protected function _showBlock()
41
- {
42
- return parent::_showBlock() &&
43
- $this->_getAddress() &&
44
- $this->_getAddress()->getAddressType() == "shipping" &&
45
- $this->_getHelper()->isShippingMethodDpd($this->_getAddress()->getOrder()->getShippingMethod());
46
- }
47
-
48
- /**
49
- *
50
- * @return Mage_Sales_Model_Order_Address
51
- */
52
- protected function _getAddress()
53
- {
54
- return Mage::registry('order_address');
55
- }
56
-
57
-
58
-
59
-
60
- /**
61
- *
62
- * @param array $fieldNames
63
- *
64
- * @return string
65
- */
66
- protected function _getHtml(array $fieldNames)
67
- {
68
-
69
- $dpdCarrier = Mage::helper('zitec_dpd')->isDpdCarrierByOrder($this->_getAddress()->getOrder());
70
- if(!$dpdCarrier){
71
- return '';
72
- }
73
- if (!$fieldNames) {
74
- return '';
75
- }
76
-
77
- $fieldsHtml = '';
78
- foreach ($fieldNames as $fieldName) {
79
- $fieldsHtml .= "
80
- field = $('{$fieldName}');
81
- if (field) {
82
- fields.push(field);
83
- }";
84
- }
85
-
86
- $html = "
87
- <script type='text/javascript'>
88
- //<![CDATA[
89
- var className = '{$this->getClassName()}',
90
- fields = [],
91
- field = null,
92
- message = '{$this->getMessage()}',
93
- maxLength = {$this->getMaxLength()},
94
- minLength = {$this->getMinLength()};
95
-
96
- {$fieldsHtml}
97
-
98
- new zitecFieldLengths.Validator(className, fields, message, maxLength, minLength);
99
- //]]>
100
- </script>";
101
-
102
- return $html;
103
- }
104
-
105
- }
106
-
107
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Block_Adminhtml_Sales_Order_Address_Form_Addresslength extends Zitec_Dpd_Block_Addresslength
25
+ {
26
+
27
+ /**
28
+ *
29
+ * @return array
30
+ */
31
+ public function getFieldNames()
32
+ {
33
+ return array("street0", "street1", "street2", "street3");
34
+ }
35
+
36
+ /**
37
+ *
38
+ * @return boolean
39
+ */
40
+ protected function _showBlock()
41
+ {
42
+ return parent::_showBlock() &&
43
+ $this->_getAddress() &&
44
+ $this->_getAddress()->getAddressType() == "shipping" &&
45
+ $this->_getHelper()->isShippingMethodDpd($this->_getAddress()->getOrder()->getShippingMethod());
46
+ }
47
+
48
+ /**
49
+ *
50
+ * @return Mage_Sales_Model_Order_Address
51
+ */
52
+ protected function _getAddress()
53
+ {
54
+ return Mage::registry('order_address');
55
+ }
56
+
57
+
58
+
59
+
60
+ /**
61
+ *
62
+ * @param array $fieldNames
63
+ *
64
+ * @return string
65
+ */
66
+ protected function _getHtml(array $fieldNames)
67
+ {
68
+
69
+ $dpdCarrier = Mage::helper('zitec_dpd')->isDpdCarrierByOrder($this->_getAddress()->getOrder());
70
+ if(!$dpdCarrier){
71
+ return '';
72
+ }
73
+ if (!$fieldNames) {
74
+ return '';
75
+ }
76
+
77
+ $fieldsHtml = '';
78
+ foreach ($fieldNames as $fieldName) {
79
+ $fieldsHtml .= "
80
+ field = $('{$fieldName}');
81
+ if (field) {
82
+ fields.push(field);
83
+ }";
84
+ }
85
+
86
+ $html = "
87
+ <script type='text/javascript'>
88
+ //<![CDATA[
89
+ var className = '{$this->getClassName()}',
90
+ fields = [],
91
+ field = null,
92
+ message = '{$this->getMessage()}',
93
+ maxLength = {$this->getMaxLength()},
94
+ minLength = {$this->getMinLength()};
95
+
96
+ {$fieldsHtml}
97
+
98
+ new zitecFieldLengths.Validator(className, fields, message, maxLength, minLength);
99
+ //]]>
100
+ </script>";
101
+
102
+ return $html;
103
+ }
104
+
105
+ }
106
+
107
+
app/code/community/Zitec/Dpd/Block/Adminhtml/Sales/Order/Shipment/View.php CHANGED
@@ -1,75 +1,75 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Block_Adminhtml_Sales_Order_Shipment_View extends Mage_Adminhtml_Block_Sales_Order_Shipment_View
25
- {
26
-
27
-
28
- public function __construct()
29
- {
30
-
31
- parent::__construct();
32
-
33
- if (!$this->_getHelper()->moduleIsActive()) {
34
- return;
35
- }
36
-
37
- if (!$this->_getHelper()->isShippingMethodDpd($this->getShipment()->getOrder()->getShippingMethod()) || $this->_getHelper()->isCancelledWithDpd($this->getShipment())) {
38
- return;
39
- }
40
-
41
-
42
- $isManifestClosed = $this->_getHelper()->isManifestClosed($this->getShipment()->getId());
43
- if ($isManifestClosed) {
44
- $onClick = 'setLocation(\'' . $this->_getManifestUrl() . '\')';
45
- } else {
46
- $onClick = "deleteConfirm('"
47
- . $this->_getHelper()->__('Once the manifest is closed, you will not be able to make further changes to the shipping address. Do you want to continue?')
48
- . "', '" . $this->_getManifestUrl() . "')";
49
- }
50
-
51
- $this->_addButton('closemanifest', array(
52
- 'label' => $isManifestClosed ? $this->_getHelper()->__('Print Manifest') : $this->_getHelper()->__('Close Manifest'),
53
- 'class' => 'save',
54
- 'onclick' => $onClick,
55
- 'sort_order' => -10
56
- ));
57
- }
58
-
59
-
60
- protected function _getManifestUrl()
61
- {
62
- return Mage::helper('adminhtml')->getUrl("zitec_dpd/adminhtml_shipment/manifest", array("shipment_ids" => $this->getShipment()->getId()));
63
- }
64
-
65
-
66
- /**
67
- *
68
- * @return Zitec_Dpd_Helper_Data
69
- */
70
- protected function _getHelper()
71
- {
72
- return Mage::helper('zitec_dpd');
73
- }
74
-
75
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Block_Adminhtml_Sales_Order_Shipment_View extends Mage_Adminhtml_Block_Sales_Order_Shipment_View
25
+ {
26
+
27
+
28
+ public function __construct()
29
+ {
30
+
31
+ parent::__construct();
32
+
33
+ if (!$this->_getHelper()->moduleIsActive()) {
34
+ return;
35
+ }
36
+
37
+ if (!$this->_getHelper()->isShippingMethodDpd($this->getShipment()->getOrder()->getShippingMethod()) || $this->_getHelper()->isCancelledWithDpd($this->getShipment())) {
38
+ return;
39
+ }
40
+
41
+
42
+ $isManifestClosed = $this->_getHelper()->isManifestClosed($this->getShipment()->getId());
43
+ if ($isManifestClosed) {
44
+ $onClick = 'setLocation(\'' . $this->_getManifestUrl() . '\')';
45
+ } else {
46
+ $onClick = "deleteConfirm('"
47
+ . $this->_getHelper()->__('Once the manifest is closed, you will not be able to make further changes to the shipping address. Do you want to continue?')
48
+ . "', '" . $this->_getManifestUrl() . "')";
49
+ }
50
+
51
+ $this->_addButton('closemanifest', array(
52
+ 'label' => $isManifestClosed ? $this->_getHelper()->__('Print Manifest') : $this->_getHelper()->__('Close Manifest'),
53
+ 'class' => 'save',
54
+ 'onclick' => $onClick,
55
+ 'sort_order' => -10
56
+ ));
57
+ }
58
+
59
+
60
+ protected function _getManifestUrl()
61
+ {
62
+ return Mage::helper('adminhtml')->getUrl("zitec_dpd/adminhtml_shipment/manifest", array("shipment_ids" => $this->getShipment()->getId()));
63
+ }
64
+
65
+
66
+ /**
67
+ *
68
+ * @return Zitec_Dpd_Helper_Data
69
+ */
70
+ protected function _getHelper()
71
+ {
72
+ return Mage::helper('zitec_dpd');
73
+ }
74
+
75
  }
app/code/community/Zitec/Dpd/Block/Adminhtml/Sales/Order/Shipment/View/Tracking.php CHANGED
@@ -1,81 +1,81 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Block_Adminhtml_Sales_Order_Shipment_View_Tracking extends Mage_Adminhtml_Block_Sales_Order_Shipment_View_Tracking
25
- {
26
-
27
- /**
28
- * check if the carrier code is one of DPD
29
- *
30
- * @return boolean
31
- */
32
- public function isDPD()
33
- {
34
- $shippingMethod = $this->getShipment()->getOrder()->getShippingMethod();
35
-
36
- return $this->_getHelper()->isShippingMethodDpd($shippingMethod);
37
- }
38
-
39
-
40
- public function getShipInfo()
41
- {
42
- return '';
43
- }
44
-
45
-
46
- /**
47
- *
48
- * @param type $track
49
- *
50
- * @return string
51
- */
52
- public function getRemoveUrl($track)
53
- {
54
- if ($this->isDpdTrack($track)) {
55
- Mage::helper('adminhtml')->getUrl("zitec_dpd/adminhtml_shipment/manifest", array("shipment_ids" => $this->getShipment()->getId()));
56
-
57
- return $this->getUrl('zitec_dpd/adminhtml_shipment/delete/', array(
58
- 'shipment_id' => $this->getShipment()->getId(),
59
- 'track_id' => $track->getId()
60
- ));
61
- } else {
62
- return parent::getRemoveUrl($track);
63
- }
64
- }
65
-
66
-
67
- /**
68
- *
69
- * @return Zitec_Dpd_Helper_Data
70
- */
71
- protected function _getHelper()
72
- {
73
- return Mage::helper('zitec_dpd');
74
- }
75
-
76
- public function isDpdTrack(Mage_Sales_Model_Order_Shipment_Track $track)
77
- {
78
- return $this->_getHelper()->isDpdTrack($track);
79
- }
80
-
81
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Block_Adminhtml_Sales_Order_Shipment_View_Tracking extends Mage_Adminhtml_Block_Sales_Order_Shipment_View_Tracking
25
+ {
26
+
27
+ /**
28
+ * check if the carrier code is one of DPD
29
+ *
30
+ * @return boolean
31
+ */
32
+ public function isDPD()
33
+ {
34
+ $shippingMethod = $this->getShipment()->getOrder()->getShippingMethod();
35
+
36
+ return $this->_getHelper()->isShippingMethodDpd($shippingMethod);
37
+ }
38
+
39
+
40
+ public function getShipInfo()
41
+ {
42
+ return '';
43
+ }
44
+
45
+
46
+ /**
47
+ *
48
+ * @param type $track
49
+ *
50
+ * @return string
51
+ */
52
+ public function getRemoveUrl($track)
53
+ {
54
+ if ($this->isDpdTrack($track)) {
55
+ Mage::helper('adminhtml')->getUrl("zitec_dpd/adminhtml_shipment/manifest", array("shipment_ids" => $this->getShipment()->getId()));
56
+
57
+ return $this->getUrl('zitec_dpd/adminhtml_shipment/delete/', array(
58
+ 'shipment_id' => $this->getShipment()->getId(),
59
+ 'track_id' => $track->getId()
60
+ ));
61
+ } else {
62
+ return parent::getRemoveUrl($track);
63
+ }
64
+ }
65
+
66
+
67
+ /**
68
+ *
69
+ * @return Zitec_Dpd_Helper_Data
70
+ */
71
+ protected function _getHelper()
72
+ {
73
+ return Mage::helper('zitec_dpd');
74
+ }
75
+
76
+ public function isDpdTrack(Mage_Sales_Model_Order_Shipment_Track $track)
77
+ {
78
+ return $this->_getHelper()->isDpdTrack($track);
79
+ }
80
+
81
  }
app/code/community/Zitec/Dpd/Block/Adminhtml/Sales/Shipment/Grid.php CHANGED
@@ -1,119 +1,119 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Block_Adminhtml_Sales_Shipment_Grid extends Mage_Adminhtml_Block_Sales_Shipment_Grid
25
- {
26
-
27
-
28
- /**
29
- * Prepare and add columns to grid
30
- *
31
- * @return Mage_Adminhtml_Block_Widget_Grid
32
- */
33
- protected function _prepareColumns()
34
- {
35
- if ($this->_getHelper()->moduleIsActive()) {
36
- $this->addColumn('zitec_dpd_manifest', array(
37
- 'header' => $this->_getHelper()->__('Manifest'),
38
- 'index' => 'zitec_manifest_id',
39
- 'type' => 'text',
40
- 'renderer' => 'Zitec_Dpd_Block_Adminhtml_Sales_Shipment_Grid_Renderer_Manifest',
41
- 'filter_condition_callback' => array($this, '_filterManifesto'),
42
- ));
43
-
44
- $this->addColumnsOrder('zitec_dpd_manifest_closed', 'total_qty');
45
-
46
- /*
47
- * removed column from frontend temporary
48
- *
49
- $this->addColumn('zitec_dpd_pickup_time', array(
50
- 'header' => $this->_getHelper()->__('DPD Pickup'),
51
- 'index' => 'zitec_dpd_pickup_time',
52
- 'type' => 'text',
53
- ));
54
- $this->addColumnsOrder('zitec_dpd_pickup_time', 'zitec_dpd_manifest');
55
- */
56
-
57
- }
58
-
59
- return parent::_prepareColumns();
60
-
61
-
62
- }
63
-
64
- /**
65
- *
66
- * @return Mage_Sales_Model_Resource_Order_Shipment_Grid_Collection
67
- */
68
- public function getCollection()
69
- {
70
- $collection = parent::getCollection();
71
- if ($collection && !$this->getIsI4ShipsJoined()) {
72
- /* @var $collection Mage_Sales_Model_Resource_Order_Shipment_Grid_Collection */
73
- $resource = Mage::getSingleton('core/resource');
74
- /* @var $resource Mage_Core_Model_Resource */
75
- $shipsTableName = $resource->getTableName('zitec_dpd_ships');
76
- $manifestTableName = $resource->getTableName('zitec_dpd_manifest');
77
-
78
- $collection->getSelect()
79
- ->joinLeft(array('ships' => $shipsTableName), 'ships.shipment_id = main_table.entity_id', array('zitec_manifest_id' => 'ships.manifest_id'))
80
- ->joinLeft(array('manifest' => $manifestTableName), 'manifest.manifest_id = ships.manifest_id', array('zitec_manifest_ref' => 'manifest.manifest_ref'));
81
- $this->setIsI4ShipsJoined(true);
82
- }
83
-
84
- return $collection;
85
- }
86
-
87
- /**
88
- *
89
- * @param Mage_Sales_Model_Resource_Order_Shipment_Grid_Collection $collection
90
- * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
91
- *
92
- * @return \Zitec_Dpd_Block_Adminhtml_Sales_Shipment_Grid
93
- */
94
- protected function _filterManifesto($collection, $column)
95
- {
96
- $manifestRef = $column->getFilter()->getCondition();
97
- if ($manifestRef) {
98
- $resource = Mage::getSingleton('core/resource');
99
- /* @var $resource Mage_Core_Model_Resource */
100
- $whereClause = $resource->getConnection("core_read")->quoteInto("manifest.manifest_ref like ? ", $manifestRef);
101
- $collection->getSelect()
102
- ->where($whereClause);
103
- $debug = (string)$collection->getSelect();
104
- }
105
-
106
- return $this;
107
- }
108
-
109
- /**
110
- *
111
- * @return Zitec_Dpd_Helper_Data
112
- */
113
- protected function _getHelper()
114
- {
115
- return Mage::helper('zitec_dpd');
116
- }
117
-
118
- }
119
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Block_Adminhtml_Sales_Shipment_Grid extends Mage_Adminhtml_Block_Sales_Shipment_Grid
25
+ {
26
+
27
+
28
+ /**
29
+ * Prepare and add columns to grid
30
+ *
31
+ * @return Mage_Adminhtml_Block_Widget_Grid
32
+ */
33
+ protected function _prepareColumns()
34
+ {
35
+ if ($this->_getHelper()->moduleIsActive()) {
36
+ $this->addColumn('zitec_dpd_manifest', array(
37
+ 'header' => $this->_getHelper()->__('Manifest'),
38
+ 'index' => 'zitec_manifest_id',
39
+ 'type' => 'text',
40
+ 'renderer' => 'Zitec_Dpd_Block_Adminhtml_Sales_Shipment_Grid_Renderer_Manifest',
41
+ 'filter_condition_callback' => array($this, '_filterManifesto'),
42
+ ));
43
+
44
+ $this->addColumnsOrder('zitec_dpd_manifest_closed', 'total_qty');
45
+
46
+ /*
47
+ * removed column from frontend temporary
48
+ *
49
+ $this->addColumn('zitec_dpd_pickup_time', array(
50
+ 'header' => $this->_getHelper()->__('DPD Pickup'),
51
+ 'index' => 'zitec_dpd_pickup_time',
52
+ 'type' => 'text',
53
+ ));
54
+ $this->addColumnsOrder('zitec_dpd_pickup_time', 'zitec_dpd_manifest');
55
+ */
56
+
57
+ }
58
+
59
+ return parent::_prepareColumns();
60
+
61
+
62
+ }
63
+
64
+ /**
65
+ *
66
+ * @return Mage_Sales_Model_Resource_Order_Shipment_Grid_Collection
67
+ */
68
+ public function getCollection()
69
+ {
70
+ $collection = parent::getCollection();
71
+ if ($collection && !$this->getIsI4ShipsJoined()) {
72
+ /* @var $collection Mage_Sales_Model_Resource_Order_Shipment_Grid_Collection */
73
+ $resource = Mage::getSingleton('core/resource');
74
+ /* @var $resource Mage_Core_Model_Resource */
75
+ $shipsTableName = $resource->getTableName('zitec_dpd_ships');
76
+ $manifestTableName = $resource->getTableName('zitec_dpd_manifest');
77
+
78
+ $collection->getSelect()
79
+ ->joinLeft(array('ships' => $shipsTableName), 'ships.shipment_id = main_table.entity_id', array('zitec_manifest_id' => 'ships.manifest_id'))
80
+ ->joinLeft(array('manifest' => $manifestTableName), 'manifest.manifest_id = ships.manifest_id', array('zitec_manifest_ref' => 'manifest.manifest_ref'));
81
+ $this->setIsI4ShipsJoined(true);
82
+ }
83
+
84
+ return $collection;
85
+ }
86
+
87
+ /**
88
+ *
89
+ * @param Mage_Sales_Model_Resource_Order_Shipment_Grid_Collection $collection
90
+ * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
91
+ *
92
+ * @return \Zitec_Dpd_Block_Adminhtml_Sales_Shipment_Grid
93
+ */
94
+ protected function _filterManifesto($collection, $column)
95
+ {
96
+ $manifestRef = $column->getFilter()->getCondition();
97
+ if ($manifestRef) {
98
+ $resource = Mage::getSingleton('core/resource');
99
+ /* @var $resource Mage_Core_Model_Resource */
100
+ $whereClause = $resource->getConnection("core_read")->quoteInto("manifest.manifest_ref like ? ", $manifestRef);
101
+ $collection->getSelect()
102
+ ->where($whereClause);
103
+ $debug = (string)$collection->getSelect();
104
+ }
105
+
106
+ return $this;
107
+ }
108
+
109
+ /**
110
+ *
111
+ * @return Zitec_Dpd_Helper_Data
112
+ */
113
+ protected function _getHelper()
114
+ {
115
+ return Mage::helper('zitec_dpd');
116
+ }
117
+
118
+ }
119
+
app/code/community/Zitec/Dpd/Block/Adminhtml/Sales/Shipment/Grid/Renderer/Manifest.php CHANGED
@@ -1,52 +1,52 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Block_Adminhtml_Sales_Shipment_Grid_Renderer_Manifest extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
25
- {
26
-
27
- public function render(Varien_Object $row)
28
- {
29
- $manifestId = $row->getData('zitec_manifest_id');
30
- $manifestRef = $row->getData('zitec_manifest_ref');
31
- if ($manifestId && $manifestRef) {
32
- $url = $this->_getHelper()->getDownloadManifestUrl($manifestId);
33
-
34
- return "<a href='{$url}'>{$this->_getHelper()->escapeHtml($manifestRef)}</a>";
35
- } else {
36
- return '';
37
- }
38
-
39
- }
40
-
41
- /**
42
- *
43
- * @return Zitec_Dpd_Helper_Data
44
- */
45
- protected function _getHelper()
46
- {
47
- return Mage::helper('zitec_dpd');
48
- }
49
-
50
- }
51
-
52
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Block_Adminhtml_Sales_Shipment_Grid_Renderer_Manifest extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
25
+ {
26
+
27
+ public function render(Varien_Object $row)
28
+ {
29
+ $manifestId = $row->getData('zitec_manifest_id');
30
+ $manifestRef = $row->getData('zitec_manifest_ref');
31
+ if ($manifestId && $manifestRef) {
32
+ $url = $this->_getHelper()->getDownloadManifestUrl($manifestId);
33
+
34
+ return "<a href='{$url}'>{$this->_getHelper()->escapeHtml($manifestRef)}</a>";
35
+ } else {
36
+ return '';
37
+ }
38
+
39
+ }
40
+
41
+ /**
42
+ *
43
+ * @return Zitec_Dpd_Helper_Data
44
+ */
45
+ protected function _getHelper()
46
+ {
47
+ return Mage::helper('zitec_dpd');
48
+ }
49
+
50
+ }
51
+
52
+
app/code/community/Zitec/Dpd/Block/Adminhtml/Shipment/Postcode/Autocompleter.php CHANGED
@@ -1,31 +1,31 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Block_Adminhtml_Shipment_Postcode_Autocompleter extends Mage_Adminhtml_Block_Template
25
- {
26
-
27
-
28
-
29
-
30
- }
31
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Block_Adminhtml_Shipment_Postcode_Autocompleter extends Mage_Adminhtml_Block_Template
25
+ {
26
+
27
+
28
+
29
+
30
+ }
31
+
app/code/community/Zitec/Dpd/Block/Adminhtml/System/Config/Button/Export.php CHANGED
@@ -1,48 +1,48 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Block_Adminhtml_System_Config_Button_Export extends Mage_Adminhtml_Block_System_Config_Form_Field
25
- {
26
-
27
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
28
- {
29
- $buttonBlock = $element->getForm()->getParent()->getLayout()->createBlock('adminhtml/widget_button');
30
-
31
- $params = array(
32
- 'website' => $buttonBlock->getRequest()->getParam('website')
33
- );
34
-
35
- $data = array(
36
- 'label' => Mage::helper('adminhtml')->__('Export CSV'),
37
- 'onclick' => 'setLocation(\'' . Mage::helper('adminhtml')->getUrl("zitec_dpd/adminhtml_config/exportTablerates", $params) . '\')',
38
- 'class' => '',
39
- );
40
-
41
- $html = $buttonBlock->setData($data)->toHtml();
42
-
43
- return $html;
44
- }
45
-
46
- }
47
-
48
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Block_Adminhtml_System_Config_Button_Export extends Mage_Adminhtml_Block_System_Config_Form_Field
25
+ {
26
+
27
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
28
+ {
29
+ $buttonBlock = $element->getForm()->getParent()->getLayout()->createBlock('adminhtml/widget_button');
30
+
31
+ $params = array(
32
+ 'website' => $buttonBlock->getRequest()->getParam('website')
33
+ );
34
+
35
+ $data = array(
36
+ 'label' => Mage::helper('adminhtml')->__('Export CSV'),
37
+ 'onclick' => 'setLocation(\'' . Mage::helper('adminhtml')->getUrl("zitec_dpd/adminhtml_config/exportTablerates", $params) . '\')',
38
+ 'class' => '',
39
+ );
40
+
41
+ $html = $buttonBlock->setData($data)->toHtml();
42
+
43
+ return $html;
44
+ }
45
+
46
+ }
47
+
48
+
app/code/community/Zitec/Dpd/Block/Adminhtml/Tablerate/Grid.php CHANGED
@@ -1,155 +1,155 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Block_Adminhtml_Tablerate_Grid extends Mage_Adminhtml_Block_Widget_Grid
25
- {
26
-
27
- /**
28
- * Website filter
29
- *
30
- * @var int
31
- */
32
- protected $_websiteId;
33
-
34
-
35
- /**
36
- * Define grid properties
37
- *
38
- * @return void
39
- */
40
- public function __construct()
41
- {
42
- parent::__construct();
43
- $this->setId('zitec_dpd_shippingTablerateGrid');
44
- $this->_exportPageSize = 10000;
45
- }
46
-
47
-
48
- /**
49
- * Set current website
50
- *
51
- * @param int $websiteId
52
- *
53
- * @return Mage_Adminhtml_Block_Shipping_Carrier_Tablerate_Grid
54
- */
55
- public function setWebsiteId($websiteId)
56
- {
57
- $this->_websiteId = Mage::app()->getWebsite($websiteId)->getId();
58
-
59
- return $this;
60
- }
61
-
62
- /**
63
- * Retrieve current website id
64
- *
65
- * @return int
66
- */
67
- public function getWebsiteId()
68
- {
69
- if (is_null($this->_websiteId)) {
70
- $this->_websiteId = Mage::app()->getWebsite()->getId();
71
- }
72
-
73
- return $this->_websiteId;
74
- }
75
-
76
- /**
77
- * Prepare shipping table rate collection
78
- *
79
- * @return Mage_Adminhtml_Block_Shipping_Carrier_Tablerate_Grid
80
- */
81
- protected function _prepareCollection()
82
- {
83
- /** @var $collection Mage_Shipping_Model_Mysql4_Carrier_Tablerate_Collection */
84
- $collection = Mage::getResourceModel('zitec_dpd/carrier_tablerate_collection');
85
- $collection->setWebsiteFilter($this->getWebsiteId());
86
-
87
- $this->setCollection($collection);
88
-
89
- return parent::_prepareCollection();
90
- }
91
-
92
- /**
93
- * Prepare table columns
94
- *
95
- * @return Mage_Adminhtml_Block_Widget_Grid
96
- */
97
- protected function _prepareColumns()
98
- {
99
-
100
- // 'website_id', 'dest_country_id', 'dest_region_id', 'dest_zip', 'weight', 'price', 'method'
101
- $this->addColumn('dest_country', array(
102
- 'header' => Mage::helper('adminhtml')->__('Country'),
103
- 'index' => 'dest_country',
104
- 'default' => '*',
105
- ));
106
-
107
- $this->addColumn('dest_region', array(
108
- 'header' => Mage::helper('adminhtml')->__('Region/State'),
109
- 'index' => 'dest_region',
110
- 'default' => '*',
111
- ));
112
-
113
- $this->addColumn('dest_zip', array(
114
- 'header' => Mage::helper('adminhtml')->__('Zip/Postal Code'),
115
- 'index' => 'dest_zip',
116
- 'default' => '*',
117
- ));
118
-
119
- $this->addColumn('weight', array(
120
- 'header' => 'Weight / Price (and above)',
121
- 'index' => 'weight',
122
- ));
123
-
124
- $this->addColumn('price', array(
125
- 'header' => Mage::helper('adminhtml')->__('Shipping Price/Percentage/Addition'),
126
- 'index' => 'shipping_price',
127
- ));
128
-
129
- $this->addColumn('Method', array(
130
- 'header' => 'Method',
131
- 'index' => 'method',
132
- ));
133
-
134
- $this->addColumn('cashondelivery_surcharge', array(
135
- 'header' => 'Cash On Delivery Surcharge',
136
- 'index' => 'cashondelivery_surcharge',
137
- 'default' => ''
138
- ));
139
-
140
- $this->addColumn('cod_min_surcharge', array(
141
- 'header' => 'Minimum COD Surcharge',
142
- 'index' => 'cod_min_surcharge',
143
- 'default' => ''
144
- ));
145
-
146
- $this->addColumn('price_vs_dest', array(
147
- 'header' => 'Price vs Dest',
148
- 'index' => 'price_vs_dest',
149
- 'default' => '0'
150
- ));
151
-
152
-
153
- return parent::_prepareColumns();
154
- }
155
- }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Block_Adminhtml_Tablerate_Grid extends Mage_Adminhtml_Block_Widget_Grid
25
+ {
26
+
27
+ /**
28
+ * Website filter
29
+ *
30
+ * @var int
31
+ */
32
+ protected $_websiteId;
33
+
34
+
35
+ /**
36
+ * Define grid properties
37
+ *
38
+ * @return void
39
+ */
40
+ public function __construct()
41
+ {
42
+ parent::__construct();
43
+ $this->setId('zitec_dpd_shippingTablerateGrid');
44
+ $this->_exportPageSize = 10000;
45
+ }
46
+
47
+
48
+ /**
49
+ * Set current website
50
+ *
51
+ * @param int $websiteId
52
+ *
53
+ * @return Mage_Adminhtml_Block_Shipping_Carrier_Tablerate_Grid
54
+ */
55
+ public function setWebsiteId($websiteId)
56
+ {
57
+ $this->_websiteId = Mage::app()->getWebsite($websiteId)->getId();
58
+
59
+ return $this;
60
+ }
61
+
62
+ /**
63
+ * Retrieve current website id
64
+ *
65
+ * @return int
66
+ */
67
+ public function getWebsiteId()
68
+ {
69
+ if (is_null($this->_websiteId)) {
70
+ $this->_websiteId = Mage::app()->getWebsite()->getId();
71
+ }
72
+
73
+ return $this->_websiteId;
74
+ }
75
+
76
+ /**
77
+ * Prepare shipping table rate collection
78
+ *
79
+ * @return Mage_Adminhtml_Block_Shipping_Carrier_Tablerate_Grid
80
+ */
81
+ protected function _prepareCollection()
82
+ {
83
+ /** @var $collection Mage_Shipping_Model_Mysql4_Carrier_Tablerate_Collection */
84
+ $collection = Mage::getResourceModel('zitec_dpd/carrier_tablerate_collection');
85
+ $collection->setWebsiteFilter($this->getWebsiteId());
86
+
87
+ $this->setCollection($collection);
88
+
89
+ return parent::_prepareCollection();
90
+ }
91
+
92
+ /**
93
+ * Prepare table columns
94
+ *
95
+ * @return Mage_Adminhtml_Block_Widget_Grid
96
+ */
97
+ protected function _prepareColumns()
98
+ {
99
+
100
+ // 'website_id', 'dest_country_id', 'dest_region_id', 'dest_zip', 'weight', 'price', 'method'
101
+ $this->addColumn('dest_country', array(
102
+ 'header' => Mage::helper('adminhtml')->__('Country'),
103
+ 'index' => 'dest_country',
104
+ 'default' => '*',
105
+ ));
106
+
107
+ $this->addColumn('dest_region', array(
108
+ 'header' => Mage::helper('adminhtml')->__('Region/State'),
109
+ 'index' => 'dest_region',
110
+ 'default' => '*',
111
+ ));
112
+
113
+ $this->addColumn('dest_zip', array(
114
+ 'header' => Mage::helper('adminhtml')->__('Zip/Postal Code'),
115
+ 'index' => 'dest_zip',
116
+ 'default' => '*',
117
+ ));
118
+
119
+ $this->addColumn('weight', array(
120
+ 'header' => 'Weight / Price (and above)',
121
+ 'index' => 'weight',
122
+ ));
123
+
124
+ $this->addColumn('price', array(
125
+ 'header' => Mage::helper('adminhtml')->__('Shipping Price/Percentage/Addition'),
126
+ 'index' => 'shipping_price',
127
+ ));
128
+
129
+ $this->addColumn('Method', array(
130
+ 'header' => 'Method',
131
+ 'index' => 'method',
132
+ ));
133
+
134
+ $this->addColumn('cashondelivery_surcharge', array(
135
+ 'header' => 'Cash On Delivery Surcharge',
136
+ 'index' => 'cashondelivery_surcharge',
137
+ 'default' => ''
138
+ ));
139
+
140
+ $this->addColumn('cod_min_surcharge', array(
141
+ 'header' => 'Minimum COD Surcharge',
142
+ 'index' => 'cod_min_surcharge',
143
+ 'default' => ''
144
+ ));
145
+
146
+ $this->addColumn('price_vs_dest', array(
147
+ 'header' => 'Price vs Dest',
148
+ 'index' => 'price_vs_dest',
149
+ 'default' => '0'
150
+ ));
151
+
152
+
153
+ return parent::_prepareColumns();
154
+ }
155
+ }
app/code/community/Zitec/Dpd/Block/Checkout/Onepage/Addresslength.php CHANGED
@@ -1,37 +1,37 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Block_Checkout_Onepage_Addresslength extends Zitec_Dpd_Block_Addresslength
25
- {
26
-
27
- /**
28
- *
29
- * @return array
30
- */
31
- public function getFieldNames()
32
- {
33
- return array("shipping:street1", "shipping:street2", "shipping:street3", "shipping:street4");
34
- }
35
- }
36
-
37
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Block_Checkout_Onepage_Addresslength extends Zitec_Dpd_Block_Addresslength
25
+ {
26
+
27
+ /**
28
+ *
29
+ * @return array
30
+ */
31
+ public function getFieldNames()
32
+ {
33
+ return array("shipping:street1", "shipping:street2", "shipping:street3", "shipping:street4");
34
+ }
35
+ }
36
+
37
+
app/code/community/Zitec/Dpd/Block/Customer/Address/Edit/Addresslength.php CHANGED
@@ -1,37 +1,37 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Block_Customer_Address_Edit_Addresslength extends Zitec_Dpd_Block_Addresslength
25
- {
26
-
27
- /**
28
- *
29
- * @return array
30
- */
31
- public function getFieldNames()
32
- {
33
- return array("street_1", "street_2", "street_3", "street_4");
34
- }
35
- }
36
-
37
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Block_Customer_Address_Edit_Addresslength extends Zitec_Dpd_Block_Addresslength
25
+ {
26
+
27
+ /**
28
+ *
29
+ * @return array
30
+ */
31
+ public function getFieldNames()
32
+ {
33
+ return array("street_1", "street_2", "street_3", "street_4");
34
+ }
35
+ }
36
+
37
+
app/code/community/Zitec/Dpd/Block/Order/Creditmemo/Totals/Cashondeliverysurcharge.php CHANGED
@@ -1,72 +1,72 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Block_Order_Creditmemo_Totals_Cashondeliverysurcharge extends Zitec_Dpd_Block_Order_Totals_Cashondeliverysurchage
25
- {
26
- /**
27
- *
28
- * @return float
29
- */
30
- protected function _getAmount()
31
- {
32
- return $this->_getCreditmemo()->getData('zitec_dpd_cashondelivery_surcharge');
33
- }
34
-
35
- /**
36
- *
37
- * @return float
38
- */
39
- protected function _getBaseAmount()
40
- {
41
- return $this->_getCreditmemo()->getData('base_zitec_dpd_cashondelivery_surcharge');
42
- }
43
-
44
- /**
45
- *
46
- * @return type
47
- */
48
- protected function _getCreditmemo()
49
- {
50
- return $this->getParentBlock()->getCreditmemo();
51
- }
52
-
53
- /**
54
- *
55
- * @return float
56
- */
57
- protected function _getBaseTax()
58
- {
59
- return $this->_getCreditmemo()->getData('base_zitec_dpd_cashondelivery_surcharge_tax');
60
- }
61
-
62
- /**
63
- *
64
- * @return float
65
- */
66
- protected function _getTax()
67
- {
68
- return $this->_getCreditmemo()->getData('zitec_dpd_cashondelivery_surcharge_tax');
69
- }
70
- }
71
-
72
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Block_Order_Creditmemo_Totals_Cashondeliverysurcharge extends Zitec_Dpd_Block_Order_Totals_Cashondeliverysurchage
25
+ {
26
+ /**
27
+ *
28
+ * @return float
29
+ */
30
+ protected function _getAmount()
31
+ {
32
+ return $this->_getCreditmemo()->getData('zitec_dpd_cashondelivery_surcharge');
33
+ }
34
+
35
+ /**
36
+ *
37
+ * @return float
38
+ */
39
+ protected function _getBaseAmount()
40
+ {
41
+ return $this->_getCreditmemo()->getData('base_zitec_dpd_cashondelivery_surcharge');
42
+ }
43
+
44
+ /**
45
+ *
46
+ * @return type
47
+ */
48
+ protected function _getCreditmemo()
49
+ {
50
+ return $this->getParentBlock()->getCreditmemo();
51
+ }
52
+
53
+ /**
54
+ *
55
+ * @return float
56
+ */
57
+ protected function _getBaseTax()
58
+ {
59
+ return $this->_getCreditmemo()->getData('base_zitec_dpd_cashondelivery_surcharge_tax');
60
+ }
61
+
62
+ /**
63
+ *
64
+ * @return float
65
+ */
66
+ protected function _getTax()
67
+ {
68
+ return $this->_getCreditmemo()->getData('zitec_dpd_cashondelivery_surcharge_tax');
69
+ }
70
+ }
71
+
72
+
app/code/community/Zitec/Dpd/Block/Order/Invoice/Totals/Cashondeliverysurcharge.php CHANGED
@@ -1,72 +1,72 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Block_Order_Invoice_Totals_Cashondeliverysurcharge extends Zitec_Dpd_Block_Order_Totals_Cashondeliverysurchage
25
- {
26
- /**
27
- *
28
- * @return float
29
- */
30
- protected function _getAmount()
31
- {
32
- return $this->_getInvoice()->getData('zitec_dpd_cashondelivery_surcharge');
33
- }
34
-
35
- /**
36
- *
37
- * @return float
38
- */
39
- protected function _getBaseAmount()
40
- {
41
- return $this->_getInvoice()->getData('base_zitec_dpd_cashondelivery_surcharge');
42
- }
43
-
44
- /**
45
- *
46
- * @return type
47
- */
48
- protected function _getInvoice()
49
- {
50
- return $this->getParentBlock()->getInvoice();
51
- }
52
-
53
- /**
54
- *
55
- * @return float
56
- */
57
- protected function _getTax()
58
- {
59
- return $this->_getInvoice()->getData('zitec_dpd_cashondelivery_surcharge_tax');
60
- }
61
-
62
- /**
63
- *
64
- * @return float
65
- */
66
- protected function _getBaseTax()
67
- {
68
- return $this->_getInvoice()->getData('base_zitec_dpd_cashondelivery_surcharge_tax');
69
- }
70
- }
71
-
72
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Block_Order_Invoice_Totals_Cashondeliverysurcharge extends Zitec_Dpd_Block_Order_Totals_Cashondeliverysurchage
25
+ {
26
+ /**
27
+ *
28
+ * @return float
29
+ */
30
+ protected function _getAmount()
31
+ {
32
+ return $this->_getInvoice()->getData('zitec_dpd_cashondelivery_surcharge');
33
+ }
34
+
35
+ /**
36
+ *
37
+ * @return float
38
+ */
39
+ protected function _getBaseAmount()
40
+ {
41
+ return $this->_getInvoice()->getData('base_zitec_dpd_cashondelivery_surcharge');
42
+ }
43
+
44
+ /**
45
+ *
46
+ * @return type
47
+ */
48
+ protected function _getInvoice()
49
+ {
50
+ return $this->getParentBlock()->getInvoice();
51
+ }
52
+
53
+ /**
54
+ *
55
+ * @return float
56
+ */
57
+ protected function _getTax()
58
+ {
59
+ return $this->_getInvoice()->getData('zitec_dpd_cashondelivery_surcharge_tax');
60
+ }
61
+
62
+ /**
63
+ *
64
+ * @return float
65
+ */
66
+ protected function _getBaseTax()
67
+ {
68
+ return $this->_getInvoice()->getData('base_zitec_dpd_cashondelivery_surcharge_tax');
69
+ }
70
+ }
71
+
72
+
app/code/community/Zitec/Dpd/Block/Order/Totals/Cashondeliverysurchage.php CHANGED
@@ -1,161 +1,161 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Block_Order_Totals_Cashondeliverysurchage extends Mage_Sales_Block_Order_Totals
25
- {
26
-
27
- public function initTotals()
28
- {
29
- $title = Mage::getStoreConfig('payment/zitec_dpd_cashondelivery/total_title', $this->_getOrder()->getStoreId());
30
-
31
- if (!round($this->_getAmount(), 2)) {
32
- return;
33
- }
34
-
35
- $includingAfter = $this->_getAfter();
36
- if ($this->_displayBoth() || $this->_displayExcludingTax()) {
37
- $this->getParentBlock()->addTotal(new Varien_Object(array(
38
- 'code' => 'zitec_dpd_cashondelivery_surcharge',
39
- 'value' => $this->_getAmount(),
40
- 'base_value' => $this->_getBaseAmount(),
41
- 'label' => $title . ($this->_displayBoth() ? ' ' . $this->_getHelper()->__('(Excl.Tax)') : ''),
42
- )), $this->_getAfter());
43
- $includingAfter = 'zitec_dpd_cashondelivery_surcharge';
44
- }
45
-
46
- if ($this->_displayIncludingTax() || $this->_displayBoth()) {
47
- $this->getParentBlock()->addTotal(new Varien_Object(array(
48
- 'code' => 'zitec_dpd_cashondelivery_surcharge_incl_tax',
49
- 'value' => $this->_getAmount() + $this->_getTax(),
50
- 'base_value' => $this->_getBaseAmount() + $this->_getBaseTax(),
51
- 'label' => $title . ($this->_displayBoth() ? ' ' . $this->_getHelper()->__('(Incl.Tax)') : ''),
52
- )), $includingAfter);
53
- }
54
- }
55
-
56
- /**
57
- *
58
- * @return Mage_Sales_Model_Order
59
- */
60
- protected function _getOrder()
61
- {
62
- return $this->getParentBlock()->getOrder();
63
- }
64
-
65
- protected function _getStore()
66
- {
67
- return $this->_getOrder()->getStore();
68
- }
69
-
70
- /**
71
- *
72
- * @return string
73
- */
74
- protected function _getAfter()
75
- {
76
- return $this->_displayBoth() ? 'shipping_incl' : 'shipping';
77
- }
78
-
79
-
80
- /**
81
- *
82
- * @return float
83
- */
84
- protected function _getAmount()
85
- {
86
- return $this->_getOrder()->getData('zitec_dpd_cashondelivery_surcharge');
87
- }
88
-
89
- /**
90
- *
91
- * @return float
92
- */
93
- protected function _getBaseAmount()
94
- {
95
- return $this->_getOrder()->getData('base_zitec_dpd_cashondelivery_surcharge');
96
- }
97
-
98
- /**
99
- *
100
- * @return float
101
- */
102
- protected function _getTax()
103
- {
104
- return $this->_getOrder()->getData('zitec_dpd_cashondelivery_surcharge_tax');
105
- }
106
-
107
- /**
108
- *
109
- * @return float
110
- */
111
- protected function _getBaseTax()
112
- {
113
- return $this->_getOrder()->getData('base_zitec_dpd_cashondelivery_surcharge_tax');
114
- }
115
-
116
- /**
117
- *
118
- * @return boolean
119
- */
120
- protected function _displayBoth()
121
- {
122
- return $this->_getConfig()->displaySalesShippingBoth($this->_getStore());
123
- }
124
-
125
- /**
126
- *
127
- * @return boolean
128
- */
129
- protected function _displayIncludingTax()
130
- {
131
- return $this->_getConfig()->displaySalesShippingInclTax($this->_getStore());
132
- }
133
-
134
- /**
135
- *
136
- * @return boolean
137
- */
138
- protected function _displayExcludingTax()
139
- {
140
- return $this->_getConfig()->displaySalesShippingExclTax($this->_getStore());
141
- }
142
-
143
- /**
144
- *
145
- * @return Mage_Tax_Model_Config
146
- */
147
- protected function _getConfig()
148
- {
149
- return Mage::getSingleton('tax/config');
150
- }
151
-
152
- /**
153
- *
154
- * @return Zitec_Dpd_Helper_Data
155
- */
156
- protected function _getHelper()
157
- {
158
- return Mage::helper('zitec_dpd');
159
- }
160
-
161
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Block_Order_Totals_Cashondeliverysurchage extends Mage_Sales_Block_Order_Totals
25
+ {
26
+
27
+ public function initTotals()
28
+ {
29
+ $title = Mage::getStoreConfig('payment/zitec_dpd_cashondelivery/total_title', $this->_getOrder()->getStoreId());
30
+
31
+ if (!round($this->_getAmount(), 2)) {
32
+ return;
33
+ }
34
+
35
+ $includingAfter = $this->_getAfter();
36
+ if ($this->_displayBoth() || $this->_displayExcludingTax()) {
37
+ $this->getParentBlock()->addTotal(new Varien_Object(array(
38
+ 'code' => 'zitec_dpd_cashondelivery_surcharge',
39
+ 'value' => $this->_getAmount(),
40
+ 'base_value' => $this->_getBaseAmount(),
41
+ 'label' => $title . ($this->_displayBoth() ? ' ' . $this->_getHelper()->__('(Excl.Tax)') : ''),
42
+ )), $this->_getAfter());
43
+ $includingAfter = 'zitec_dpd_cashondelivery_surcharge';
44
+ }
45
+
46
+ if ($this->_displayIncludingTax() || $this->_displayBoth()) {
47
+ $this->getParentBlock()->addTotal(new Varien_Object(array(
48
+ 'code' => 'zitec_dpd_cashondelivery_surcharge_incl_tax',
49
+ 'value' => $this->_getAmount() + $this->_getTax(),
50
+ 'base_value' => $this->_getBaseAmount() + $this->_getBaseTax(),
51
+ 'label' => $title . ($this->_displayBoth() ? ' ' . $this->_getHelper()->__('(Incl.Tax)') : ''),
52
+ )), $includingAfter);
53
+ }
54
+ }
55
+
56
+ /**
57
+ *
58
+ * @return Mage_Sales_Model_Order
59
+ */
60
+ protected function _getOrder()
61
+ {
62
+ return $this->getParentBlock()->getOrder();
63
+ }
64
+
65
+ protected function _getStore()
66
+ {
67
+ return $this->_getOrder()->getStore();
68
+ }
69
+
70
+ /**
71
+ *
72
+ * @return string
73
+ */
74
+ protected function _getAfter()
75
+ {
76
+ return $this->_displayBoth() ? 'shipping_incl' : 'shipping';
77
+ }
78
+
79
+
80
+ /**
81
+ *
82
+ * @return float
83
+ */
84
+ protected function _getAmount()
85
+ {
86
+ return $this->_getOrder()->getData('zitec_dpd_cashondelivery_surcharge');
87
+ }
88
+
89
+ /**
90
+ *
91
+ * @return float
92
+ */
93
+ protected function _getBaseAmount()
94
+ {
95
+ return $this->_getOrder()->getData('base_zitec_dpd_cashondelivery_surcharge');
96
+ }
97
+
98
+ /**
99
+ *
100
+ * @return float
101
+ */
102
+ protected function _getTax()
103
+ {
104
+ return $this->_getOrder()->getData('zitec_dpd_cashondelivery_surcharge_tax');
105
+ }
106
+
107
+ /**
108
+ *
109
+ * @return float
110
+ */
111
+ protected function _getBaseTax()
112
+ {
113
+ return $this->_getOrder()->getData('base_zitec_dpd_cashondelivery_surcharge_tax');
114
+ }
115
+
116
+ /**
117
+ *
118
+ * @return boolean
119
+ */
120
+ protected function _displayBoth()
121
+ {
122
+ return $this->_getConfig()->displaySalesShippingBoth($this->_getStore());
123
+ }
124
+
125
+ /**
126
+ *
127
+ * @return boolean
128
+ */
129
+ protected function _displayIncludingTax()
130
+ {
131
+ return $this->_getConfig()->displaySalesShippingInclTax($this->_getStore());
132
+ }
133
+
134
+ /**
135
+ *
136
+ * @return boolean
137
+ */
138
+ protected function _displayExcludingTax()
139
+ {
140
+ return $this->_getConfig()->displaySalesShippingExclTax($this->_getStore());
141
+ }
142
+
143
+ /**
144
+ *
145
+ * @return Mage_Tax_Model_Config
146
+ */
147
+ protected function _getConfig()
148
+ {
149
+ return Mage::getSingleton('tax/config');
150
+ }
151
+
152
+ /**
153
+ *
154
+ * @return Zitec_Dpd_Helper_Data
155
+ */
156
+ protected function _getHelper()
157
+ {
158
+ return Mage::helper('zitec_dpd');
159
+ }
160
+
161
  }
app/code/community/Zitec/Dpd/Block/Tax/Checkout/Cashondeliverysurchage.php CHANGED
@@ -1,126 +1,126 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Block_Tax_Checkout_Cashondeliverysurchage extends Mage_Checkout_Block_Total_Default
25
- {
26
-
27
- protected $_template = 'zitec_dpd/tax/checkout/cashondeliverysurchage.phtml';
28
-
29
- /**
30
- *
31
- * @return float
32
- */
33
- protected function _getCashOnDeliverySurcharge()
34
- {
35
- return $this->getTotal()->getAddress()->getData('zitec_dpd_cashondelivery_surcharge');
36
- }
37
-
38
- /**
39
- *
40
- * @return float
41
- */
42
- protected function _getCashOnDeliverySurchargeTax()
43
- {
44
- return $this->getTotal()->getAddress()->getData('zitec_dpd_cashondelivery_surcharge_tax');
45
- }
46
-
47
-
48
- /**
49
- * Check if we need display shipping include and exclude tax
50
- *
51
- * @return bool
52
- */
53
- public function displayBoth()
54
- {
55
- return Mage::getSingleton('tax/config')->displayCartShippingBoth($this->getStore());
56
- }
57
-
58
- /**
59
- * Check if we need display shipping include tax
60
- *
61
- * @return bool
62
- */
63
- public function displayIncludeTax()
64
- {
65
- return Mage::getSingleton('tax/config')->displayCartShippingInclTax($this->getStore());
66
- }
67
-
68
-
69
- /**
70
- * Get label for cash on delivery surcharge including tax
71
- *
72
- * @return float
73
- */
74
- public function getIncludeTaxLabel()
75
- {
76
- return $this->_getTitle() . $this->_getHelper()->__(' Incl. tax');
77
- }
78
-
79
- /**
80
- * Get label for cash on delivery surcharge excluding tax
81
- *
82
- * @return float
83
- */
84
- public function getExcludeTaxLabel()
85
- {
86
- return $this->_getTitle() . $this->_getHelper()->__(' Excl. tax');
87
- }
88
-
89
- /**
90
- *
91
- * @return float
92
- */
93
- public function getCashOnDeliverySurchargeExcludeTax()
94
- {
95
- return $this->_getCashOnDeliverySurcharge();
96
- }
97
-
98
- /**
99
- *
100
- * @return float
101
- */
102
- public function getCashOnDeliverySurchargeIncludeTax()
103
- {
104
- return $this->_getCashOnDeliverySurcharge() + $this->_getCashOnDeliverySurchargeTax();
105
- }
106
-
107
- /**
108
- *
109
- * @return Zitec_Dpd_Helper_Data
110
- */
111
- protected function _getHelper()
112
- {
113
- return Mage::helper('zitec_dpd');
114
- }
115
-
116
- /**
117
- *
118
- * @return string
119
- */
120
- protected function _getTitle()
121
- {
122
- return $this->getTotal()->getTitle();
123
- }
124
-
125
-
126
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Block_Tax_Checkout_Cashondeliverysurchage extends Mage_Checkout_Block_Total_Default
25
+ {
26
+
27
+ protected $_template = 'zitec_dpd/tax/checkout/cashondeliverysurchage.phtml';
28
+
29
+ /**
30
+ *
31
+ * @return float
32
+ */
33
+ protected function _getCashOnDeliverySurcharge()
34
+ {
35
+ return $this->getTotal()->getAddress()->getData('zitec_dpd_cashondelivery_surcharge');
36
+ }
37
+
38
+ /**
39
+ *
40
+ * @return float
41
+ */
42
+ protected function _getCashOnDeliverySurchargeTax()
43
+ {
44
+ return $this->getTotal()->getAddress()->getData('zitec_dpd_cashondelivery_surcharge_tax');
45
+ }
46
+
47
+
48
+ /**
49
+ * Check if we need display shipping include and exclude tax
50
+ *
51
+ * @return bool
52
+ */
53
+ public function displayBoth()
54
+ {
55
+ return Mage::getSingleton('tax/config')->displayCartShippingBoth($this->getStore());
56
+ }
57
+
58
+ /**
59
+ * Check if we need display shipping include tax
60
+ *
61
+ * @return bool
62
+ */
63
+ public function displayIncludeTax()
64
+ {
65
+ return Mage::getSingleton('tax/config')->displayCartShippingInclTax($this->getStore());
66
+ }
67
+
68
+
69
+ /**
70
+ * Get label for cash on delivery surcharge including tax
71
+ *
72
+ * @return float
73
+ */
74
+ public function getIncludeTaxLabel()
75
+ {
76
+ return $this->_getTitle() . $this->_getHelper()->__(' Incl. tax');
77
+ }
78
+
79
+ /**
80
+ * Get label for cash on delivery surcharge excluding tax
81
+ *
82
+ * @return float
83
+ */
84
+ public function getExcludeTaxLabel()
85
+ {
86
+ return $this->_getTitle() . $this->_getHelper()->__(' Excl. tax');
87
+ }
88
+
89
+ /**
90
+ *
91
+ * @return float
92
+ */
93
+ public function getCashOnDeliverySurchargeExcludeTax()
94
+ {
95
+ return $this->_getCashOnDeliverySurcharge();
96
+ }
97
+
98
+ /**
99
+ *
100
+ * @return float
101
+ */
102
+ public function getCashOnDeliverySurchargeIncludeTax()
103
+ {
104
+ return $this->_getCashOnDeliverySurcharge() + $this->_getCashOnDeliverySurchargeTax();
105
+ }
106
+
107
+ /**
108
+ *
109
+ * @return Zitec_Dpd_Helper_Data
110
+ */
111
+ protected function _getHelper()
112
+ {
113
+ return Mage::helper('zitec_dpd');
114
+ }
115
+
116
+ /**
117
+ *
118
+ * @return string
119
+ */
120
+ protected function _getTitle()
121
+ {
122
+ return $this->getTotal()->getTitle();
123
+ }
124
+
125
+
126
  }
app/code/community/Zitec/Dpd/Helper/Compatibility.php CHANGED
@@ -1,77 +1,77 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * this class is used for
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Helper_Compatibility extends Mage_Core_Helper_Abstract
25
- {
26
-
27
-
28
- /**
29
- * Checks the possibility of creating shipping label by current carrier
30
- *
31
- * compatibility with magento less then 1.6.2
32
- * @param $shipment
33
- */
34
- public function canCreateShippingLabel($shipment){
35
- $shippingCarrier = $this->getOrder($shipment)->getShippingCarrier();
36
- return $shippingCarrier && $shippingCarrier->isShippingLabelsAvailable();
37
- }
38
-
39
-
40
- /**
41
- * checko compatibility for print shipping label pdf in Mage_Adminhtml_Sales_Order_ShipmentController
42
- * compatibility with magento less then 1.6.2
43
- *
44
- * @return bool
45
- */
46
- public function checkMassPrintShippingLabelExists(){
47
- if($this->versionIsAtLeast16()){
48
- return true;
49
- }
50
-
51
- return false;
52
- }
53
-
54
-
55
- public function versionIsAtLeast16()
56
- {
57
- $versionInfo = Mage::getVersionInfo();
58
- if ($versionInfo['major'] >= 1) {
59
- if ($versionInfo['minor'] >= 6) {
60
- return true;
61
- }
62
- }
63
-
64
- return false;
65
- }
66
-
67
- /**
68
- * Retrieve invoice order
69
- *
70
- * @return Mage_Sales_Model_Order
71
- */
72
- public function getOrder($shipment)
73
- {
74
- return $shipment->getOrder();
75
- }
76
-
77
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * this class is used for
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Helper_Compatibility extends Mage_Core_Helper_Abstract
25
+ {
26
+
27
+
28
+ /**
29
+ * Checks the possibility of creating shipping label by current carrier
30
+ *
31
+ * compatibility with magento less then 1.6.2
32
+ * @param $shipment
33
+ */
34
+ public function canCreateShippingLabel($shipment){
35
+ $shippingCarrier = $this->getOrder($shipment)->getShippingCarrier();
36
+ return $shippingCarrier && $shippingCarrier->isShippingLabelsAvailable();
37
+ }
38
+
39
+
40
+ /**
41
+ * checko compatibility for print shipping label pdf in Mage_Adminhtml_Sales_Order_ShipmentController
42
+ * compatibility with magento less then 1.6.2
43
+ *
44
+ * @return bool
45
+ */
46
+ public function checkMassPrintShippingLabelExists(){
47
+ if($this->versionIsAtLeast16()){
48
+ return true;
49
+ }
50
+
51
+ return false;
52
+ }
53
+
54
+
55
+ public function versionIsAtLeast16()
56
+ {
57
+ $versionInfo = Mage::getVersionInfo();
58
+ if ($versionInfo['major'] >= 1) {
59
+ if ($versionInfo['minor'] >= 6) {
60
+ return true;
61
+ }
62
+ }
63
+
64
+ return false;
65
+ }
66
+
67
+ /**
68
+ * Retrieve invoice order
69
+ *
70
+ * @return Mage_Sales_Model_Order
71
+ */
72
+ public function getOrder($shipment)
73
+ {
74
+ return $shipment->getOrder();
75
+ }
76
+
77
  }
app/code/community/Zitec/Dpd/Helper/Data.php CHANGED
@@ -1,595 +1,595 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * this class is used for
20
- *
21
- * @category Zitec
22
- * @package Zitec_Dpd
23
- * @author Zitec COM <magento@zitec.ro>
24
- */
25
- class Zitec_Dpd_Helper_Data extends Mage_Core_Helper_Abstract
26
- {
27
-
28
-
29
- /**
30
- * is used in checkout to extract the value of products
31
- * and the names
32
- *
33
- * @param $request
34
- *
35
- * @return array
36
- */
37
- public function extractInsuranceValuesByRequest($request)
38
- {
39
- $allItems = $request->getAllItems();
40
- $description = '';
41
- $value = 0;
42
- if (count($allItems)) {
43
- foreach ($allItems as $item) {
44
- if ($item->getParentItemId()) {
45
- continue;
46
- }
47
- $description .= ' | '.$item->getName();
48
-
49
- $value += $item->getRowTotalInclTax();
50
- }
51
- }
52
- $currencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
53
-
54
- return array(
55
- 'goodsValue' => $value,
56
- 'currency' => $currencyCode,
57
- 'content' => $description
58
- );
59
-
60
-
61
- }
62
-
63
- /**
64
- * it is used in admin panel to process the products values and
65
- * products description
66
- *
67
- * @param $request
68
- *
69
- * @return array
70
- */
71
- public function extractInsuranceValuesByOrder($order)
72
- {
73
- $allItems = $order->getAllItems();
74
- $description = '';
75
- $value = 0;
76
- if (count($allItems)) {
77
- foreach ($allItems as $item) {
78
- if ($item->getParentItemId()) {
79
- continue;
80
- }
81
- $description .= ' | '.$item->getName();
82
-
83
- $value += $item->getRowTotalInclTax();
84
- }
85
- }
86
- $currencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
87
-
88
- return array(
89
- 'goodsValue' => $value,
90
- 'currency' => $currencyCode,
91
- 'content' => $description
92
- );
93
-
94
-
95
- }
96
-
97
- /**
98
- * @param $message
99
- * @param string $function
100
- * @param string $class
101
- * @param string $line
102
- *
103
- * @return $this
104
- */
105
- public function log($message, $function = '', $class = '', $line = '')
106
- {
107
- $location = ($class ? "$class::" : "") . $function . ($line ? " on line $line" : "");
108
- Mage::log($message . ($location ? " at $location" : ''), null, "zitec_dpd.log");
109
-
110
- return $this;
111
- }
112
-
113
- /**
114
- *
115
- * @param string $field
116
- * @param mixed $store
117
- *
118
- * @return mixed
119
- */
120
- public function getConfigData($field, $store = null)
121
- {
122
- if (!$store) {
123
- $store = Mage::app()->getStore();
124
- }
125
-
126
- $carrierCode = $this->getDpdCarrierCode();
127
-
128
- return Mage::getStoreConfig("carriers/$carrierCode/$field", $store);
129
- }
130
-
131
- /**
132
- *
133
- * @param mixed $store
134
- *
135
- * @return string
136
- */
137
- public function getCarrierName($store = null)
138
- {
139
- return $this->getConfigData("title", $store);
140
- }
141
-
142
- /**
143
- *
144
- * @param mixed $store
145
- *
146
- * @return boolean
147
- */
148
- public function moduleIsActive($store = null)
149
- {
150
- return $this->getConfigData("active", $store) ? true : false;
151
- }
152
-
153
-
154
- /**
155
- *
156
- * @param Mage_Shipping_Model_Carrier_Abstract $carrier
157
- *
158
- * @return boolean
159
- */
160
- public function isCarrierDpd(Mage_Shipping_Model_Carrier_Abstract $carrier)
161
- {
162
- return $carrier instanceof Zitec_Dpd_Model_Shipping_Carrier_Dpd;
163
- }
164
-
165
- /**
166
- * test if a order was submited using dpd shipping carrier
167
- *
168
- * @param $order
169
- *
170
- * @return bool
171
- */
172
- public function isDpdCarrierByOrder($order)
173
- {
174
- if (!is_object($order)) {
175
- return false;
176
- }
177
- $carrier = $order->getShippingCarrier();
178
-
179
- return $this->isCarrierDpd($carrier);
180
- }
181
-
182
- /**
183
- * check if the postcode was marked as a valid postcode or not
184
- *
185
- * @param $order
186
- */
187
- public function isValidAutoPostcode($order)
188
- {
189
- if (!is_object($order)) {
190
- return false;
191
- }
192
- if (!$this->isEnabledPostcodeAutocompleteByOrder($order)) {
193
- //it should be valid
194
- return 1;
195
- }
196
- if (!$this->isDpdCarrierByOrder($order)) {
197
- //it should be valid
198
- return 1;
199
- }
200
- $_shippingAddress = $order->getShippingAddress();
201
- $isValid = $_shippingAddress->getValidAutoPostcode();
202
-
203
- return $isValid;
204
-
205
- }
206
-
207
-
208
- public function isEnabledPostcodeAutocompleteByOrder($order)
209
- {
210
- if (!is_object($order)) {
211
- return false;
212
- }
213
- $_shippingAddress = $order->getShippingAddress();
214
- $address = $_shippingAddress->getData();
215
- if (!empty($address['country_id'])) {
216
- $countryName = Mage::getModel('directory/country')->loadByCode($address['country_id'])->getName();
217
- $address['country'] = $countryName;
218
- } else {
219
- return false;
220
- }
221
-
222
- return (Mage::helper('zitec_dpd/postcode_search')->isEnabledAutocompleteForPostcode($countryName));
223
- }
224
-
225
- /**
226
- * chceck the address length to be less then DPD API requirements
227
- *
228
- * @param $shippingAddress
229
- *
230
- * @return bool
231
- */
232
- public function checkAddressStreetLength($shippingAddress)
233
- {
234
-
235
- $shippingAddressStreetArray = $shippingAddress->getStreet();
236
- if (is_array($shippingAddressStreetArray)) {
237
- $shippingAddressStreet = '';
238
- foreach ($shippingAddressStreetArray as $street) {
239
- $shippingAddressStreet .= '' . $street;
240
- }
241
- $shippingAddressStreet = trim($shippingAddressStreet);
242
- } else {
243
- $shippingAddressStreet = $shippingAddressStreetArray;
244
- }
245
-
246
- return (strlen($shippingAddressStreet) <= Zitec_Dpd_Api_Configs::SHIPMENT_LIST_RECEIVER_STREET_MAX_LENGTH);
247
- }
248
-
249
-
250
- /**
251
- *
252
- * @param string|Mage_Sales_Model_Order_Shipment|Mage_Sales_Model_Order $shippingMethod
253
- *
254
- * @return boolean
255
- */
256
- public function isShippingMethodDpd($shippingMethod)
257
- {
258
- if ($shippingMethod instanceof Mage_Sales_Model_Order_Shipment) {
259
- $shippingMethod = $shippingMethod->getOrder()->getShippingMethod();
260
- } elseif ($shippingMethod instanceof Mage_Sales_Model_Order) {
261
- $shippingMethod = $shippingMethod->getShippingMethod();
262
- }
263
-
264
- return is_string($shippingMethod) && (strpos($shippingMethod, $this->getDpdCarrierCode()) !== false);
265
- }
266
-
267
-
268
- /**
269
- * Returns true if the magento version is greater or equal to the version passed.
270
- *
271
- * @param int $major
272
- * @param int $minor
273
- * @param int $revision
274
- * @param int $patch
275
- *
276
- * @return boolean
277
- */
278
- public function isMagentoVersionGreaterOrEqualTo($major, $minor, $revision, $patch)
279
- {
280
- $versionInfo = Mage::getVersionInfo();
281
- if ((int)$major > (int)$versionInfo['major']) {
282
- return false;
283
- } elseif ((int)$minor > (int)$versionInfo['minor']) {
284
- return false;
285
- } elseif ((int)$revision > (int)$versionInfo['revision']) {
286
- return false;
287
- } elseif ((int)$patch > (int)$versionInfo['patch']) {
288
- return false;
289
- } else {
290
- return true;
291
- }
292
- }
293
-
294
- /**
295
- *
296
- * @param string $message
297
- */
298
- public function addNotice($message)
299
- {
300
- Mage::getSingleton('core/session')->addNotice($message);
301
- }
302
-
303
- /**
304
- *
305
- * @param string $message
306
- */
307
- public function addError($message)
308
- {
309
- Mage::getSingleton('core/session')->addError($message);
310
- }
311
-
312
- /**
313
- *
314
- * @param string $message
315
- */
316
- public function addSuccess($message)
317
- {
318
- Mage::getSingleton('core/session')->addSuccess($message);
319
- }
320
-
321
- /**
322
- *
323
- * @param boolean $success
324
- * @param string $message
325
- *
326
- * @return \Zitec_Dpd_Helper_Data
327
- */
328
- public function addSuccessError($success, $message)
329
- {
330
- if ($success) {
331
- $this->addSuccess($message);
332
- } else {
333
- $this->addError($message);
334
- }
335
-
336
- return $this;
337
- }
338
-
339
- /**
340
- *
341
- * @return boolean
342
- */
343
- public function isAdmin()
344
- {
345
- return Mage::app()->getStore()->isAdmin();
346
- }
347
-
348
- /**
349
- *
350
- * @param string $shipmentId
351
- *
352
- * @return boolean
353
- * @deprecated
354
- */
355
- public function isManifestClosed($shipmentId)
356
- {
357
- $shipsCollection = Mage::getResourceModel('zitec_dpd/dpd_ship_collection');
358
- /* @var $shipsCollection Zitec_Dpd_Model_Mysql4_Dpd_Ship_Collection */
359
- $ships = $shipsCollection->getByShipmentId($shipmentId);
360
-
361
- /* @var $ships Zitec_Dpd_Model_Dpd_Ship */
362
-
363
- return $ships->getManifest() ? true : false;
364
-
365
- }
366
-
367
- /**
368
- *
369
- * @param Mage_Sales_Model_Order_Shipment_Track $track
370
- *
371
- * @return boolean
372
- */
373
- public function isDpdTrack(Mage_Sales_Model_Order_Shipment_Track $track)
374
- {
375
- return strpos($track->getCarrierCode(), $this->getDpdCarrierCode()) !== false;
376
- }
377
-
378
- /**
379
- *
380
- * @param Mage_Sales_Model_Order_Shipment $shipment
381
- *
382
- * @return boolean
383
- */
384
- public function isCancelledWithDpd(Mage_Sales_Model_Order_Shipment $shipment)
385
- {
386
- return $this->isShippingMethodDpd($shipment->getOrder()->getShippingMethod()) && !$shipment->getShippingLabel();
387
- }
388
-
389
-
390
- /**
391
- *
392
- * @param string $shippingMethod
393
- *
394
- * @return string|boolean
395
- */
396
- public function getDPDServiceCode($shippingMethod)
397
- {
398
- $parts = explode('_', $shippingMethod);
399
- if (count($parts) == 2) {
400
- return $parts[1];
401
- } else {
402
- return false;
403
- }
404
- }
405
-
406
- /**
407
- *
408
- * @param Mage_Sales_Model_Order $order
409
- *
410
- * @return boolean
411
- */
412
- public function isOrderCashOnDelivery(Mage_Sales_Model_Order $order)
413
- {
414
- return $order->getPayment()->getMethod() == Mage::helper('zitec_dpd')->getDpdPaymentCode() ? true : false;
415
- }
416
-
417
- /**
418
- * return default surcharge in checkout if no table rates defined
419
- *
420
- * @param Mage_Sales_Model_Quote $quote
421
- * @param $shippingAmount
422
- *
423
- * @return mixed
424
- */
425
- public function returnDefaultBaseCashOnDeliverySurcharge(Mage_Sales_Model_Quote $quote)
426
- {
427
- $amountType = Mage::getStoreConfig('payment/zitec_dpd_cashondelivery/payment_amount_type', $quote->getStoreId());
428
- $amount = Mage::getStoreConfig('payment/zitec_dpd_cashondelivery/payment_amount', $quote->getStoreId());
429
- if ($amountType == Zitec_Dpd_Api_Configs::PAYMENT_AMOUNT_TYPE_FIXED) {
430
- return $amount;
431
- } else {
432
- $address = $quote->getShippingAddress();
433
- $taxConfig = Mage::getSingleton('tax/config');
434
- /* @var $taxConfig Mage_Tax_Model_Config */
435
-
436
- $amount = $amount / 100;
437
-
438
- return $amount * ($this->getBaseValueOfShippableGoods($quote));
439
- }
440
-
441
- }
442
-
443
- /**
444
- * here is calculated the price of the quote payment method: cash on delivery using DPD
445
- *
446
- * @param Mage_Sales_Model_Quote $quote
447
- * @param string $surcharge
448
- *
449
- * @return float
450
- */
451
- public function calculateQuoteBaseCashOnDeliverySurcharge(Mage_Sales_Model_Quote $quote, $surcharge)
452
- {
453
- $address = $quote->getShippingAddress();
454
- $taxConfig = Mage::getSingleton('tax/config');
455
- /* @var $taxConfig Mage_Tax_Model_Config */
456
-
457
- if (!$surcharge || !is_array($surcharge) || !isset($surcharge['cashondelivery_surcharge'])) {
458
- return 0;
459
- }
460
- $baseCashondeliverySurchargePercent = $this->parsePercentageValueAsFraction($surcharge['cashondelivery_surcharge']);
461
- if ($baseCashondeliverySurchargePercent !== false) {
462
-
463
- $baseCashondeliverySurcharge = $baseCashondeliverySurchargePercent * ($this->getBaseValueOfShippableGoods($quote));
464
- if (isset($surcharge['cod_min_surcharge'])) {
465
- $baseCashondeliverySurcharge = max(array((float)$surcharge['cod_min_surcharge'], $baseCashondeliverySurcharge));
466
- }
467
- } else {
468
- $baseCashondeliverySurcharge = (float)$surcharge['cashondelivery_surcharge'];
469
- }
470
-
471
- return $baseCashondeliverySurcharge;
472
- }
473
-
474
- /**
475
- * Parse a string of the form nn.nn% and returns the percent as a fraction.
476
- * It returns false if the string does not have the correct form.
477
- *
478
- * @param type $value
479
- *
480
- * @return boolean
481
- */
482
- public function parsePercentageValueAsFraction($value)
483
- {
484
- if (!is_string($value)) {
485
- return false;
486
- }
487
- $value = trim($value);
488
- if (strlen($value) < 2 || substr($value, -1) != '%') {
489
- return false;
490
- }
491
- $percentage = $this->parseDecimalValue(substr($value, 0, strlen($value) - 1));
492
- if ($percentage === false) {
493
- return false;
494
- }
495
-
496
- return $percentage / 100;
497
- }
498
-
499
-
500
- /**
501
- * Parse and validate positive decimal value
502
- * Return false if value is not decimal or is not positive
503
- *
504
- * @param string $value
505
- *
506
- * @return bool|float
507
- */
508
- public function parseDecimalValue($value)
509
- {
510
- if (!is_numeric($value)) {
511
- return false;
512
- }
513
- $value = (float)sprintf('%.4F', $value);
514
- if ($value < 0.0000) {
515
- return false;
516
- }
517
-
518
- return $value;
519
- }
520
-
521
-
522
- /**
523
- *
524
- * @param Mage_Sales_Model_Quote $quote
525
- *
526
- * @return float
527
- */
528
- public function getBaseValueOfShippableGoods(Mage_Sales_Model_Quote $quote)
529
- {
530
- $baseTotalPrice = 0.0;
531
- $taxConfig = Mage::getSingleton('tax/config');
532
- /* @var $taxConfig Mage_Tax_Model_Config */
533
- if ($quote->getAllItems()) {
534
- foreach ($quote->getAllItems() as $item) {
535
- /* @var $item Mage_Sales_Model_Quote_Item */
536
-
537
- if ($item->getProduct()->isVirtual() || $item->getParentItemId()) {
538
- continue;
539
- }
540
-
541
- $baseTotalPrice += $taxConfig->shippingPriceIncludesTax($quote->getStore()) ? $item->getBaseRowTotalInclTax() : $item->getBaseRowTotal();
542
- }
543
- }
544
-
545
- return $baseTotalPrice;
546
- }
547
-
548
-
549
- /**
550
- *
551
- * @param Mage_Sales_Model_Order $order
552
- *
553
- * @return string
554
- */
555
- public function getCodPaymentType(Mage_Sales_Model_Order $order)
556
- {
557
- return $order->getPayment()->getMethodInstance()->getConfigData("cod_payment_type", $order->getStoreId());
558
- }
559
-
560
-
561
- /**
562
- *
563
- * @param int $manifestId
564
- *
565
- * @return string
566
- */
567
- public function getDownloadManifestUrl($manifestId)
568
- {
569
- $helper = Mage::helper('adminhtml');
570
-
571
- /* @var $helper Mage_Adminhtml_Helper_Data */
572
-
573
- return $helper->getUrl("zitec_dpd/adminhtml_shipment/downloadmanifest", array("manifest_id" => $manifestId));
574
- }
575
-
576
-
577
- /**
578
- * @return string
579
- */
580
- public function getDpdCarrierCode()
581
- {
582
- return Zitec_Dpd_Model_Shipping_Carrier_Dpd::CARRIER_CODE;
583
- }
584
-
585
-
586
- /**
587
- * @return string
588
- */
589
- public function getDpdPaymentCode()
590
- {
591
- return Zitec_Dpd_Model_Payment_Cashondelivery::CODE;
592
- }
593
-
594
-
595
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * this class is used for
20
+ *
21
+ * @category Zitec
22
+ * @package Zitec_Dpd
23
+ * @author Zitec COM <magento@zitec.ro>
24
+ */
25
+ class Zitec_Dpd_Helper_Data extends Mage_Core_Helper_Abstract
26
+ {
27
+
28
+
29
+ /**
30
+ * is used in checkout to extract the value of products
31
+ * and the names
32
+ *
33
+ * @param $request
34
+ *
35
+ * @return array
36
+ */
37
+ public function extractInsuranceValuesByRequest($request)
38
+ {
39
+ $allItems = $request->getAllItems();
40
+ $description = '';
41
+ $value = 0;
42
+ if (count($allItems)) {
43
+ foreach ($allItems as $item) {
44
+ if ($item->getParentItemId()) {
45
+ continue;
46
+ }
47
+ $description .= ' | '.$item->getName();
48
+
49
+ $value += $item->getRowTotalInclTax();
50
+ }
51
+ }
52
+ $currencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
53
+
54
+ return array(
55
+ 'goodsValue' => $value,
56
+ 'currency' => $currencyCode,
57
+ 'content' => $description
58
+ );
59
+
60
+
61
+ }
62
+
63
+ /**
64
+ * it is used in admin panel to process the products values and
65
+ * products description
66
+ *
67
+ * @param $request
68
+ *
69
+ * @return array
70
+ */
71
+ public function extractInsuranceValuesByOrder($order)
72
+ {
73
+ $allItems = $order->getAllItems();
74
+ $description = '';
75
+ $value = 0;
76
+ if (count($allItems)) {
77
+ foreach ($allItems as $item) {
78
+ if ($item->getParentItemId()) {
79
+ continue;
80
+ }
81
+ $description .= ' | '.$item->getName();
82
+
83
+ $value += $item->getRowTotalInclTax();
84
+ }
85
+ }
86
+ $currencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
87
+
88
+ return array(
89
+ 'goodsValue' => $value,
90
+ 'currency' => $currencyCode,
91
+ 'content' => $description
92
+ );
93
+
94
+
95
+ }
96
+
97
+ /**
98
+ * @param $message
99
+ * @param string $function
100
+ * @param string $class
101
+ * @param string $line
102
+ *
103
+ * @return $this
104
+ */
105
+ public function log($message, $function = '', $class = '', $line = '')
106
+ {
107
+ $location = ($class ? "$class::" : "") . $function . ($line ? " on line $line" : "");
108
+ Mage::log($message . ($location ? " at $location" : ''), null, "zitec_dpd.log");
109
+
110
+ return $this;
111
+ }
112
+
113
+ /**
114
+ *
115
+ * @param string $field
116
+ * @param mixed $store
117
+ *
118
+ * @return mixed
119
+ */
120
+ public function getConfigData($field, $store = null)
121
+ {
122
+ if (!$store) {
123
+ $store = Mage::app()->getStore();
124
+ }
125
+
126
+ $carrierCode = $this->getDpdCarrierCode();
127
+
128
+ return Mage::getStoreConfig("carriers/$carrierCode/$field", $store);
129
+ }
130
+
131
+ /**
132
+ *
133
+ * @param mixed $store
134
+ *
135
+ * @return string
136
+ */
137
+ public function getCarrierName($store = null)
138
+ {
139
+ return $this->getConfigData("title", $store);
140
+ }
141
+
142
+ /**
143
+ *
144
+ * @param mixed $store
145
+ *
146
+ * @return boolean
147
+ */
148
+ public function moduleIsActive($store = null)
149
+ {
150
+ return $this->getConfigData("active", $store) ? true : false;
151
+ }
152
+
153
+
154
+ /**
155
+ *
156
+ * @param Mage_Shipping_Model_Carrier_Abstract $carrier
157
+ *
158
+ * @return boolean
159
+ */
160
+ public function isCarrierDpd(Mage_Shipping_Model_Carrier_Abstract $carrier)
161
+ {
162
+ return $carrier instanceof Zitec_Dpd_Model_Shipping_Carrier_Dpd;
163
+ }
164
+
165
+ /**
166
+ * test if a order was submited using dpd shipping carrier
167
+ *
168
+ * @param $order
169
+ *
170
+ * @return bool
171
+ */
172
+ public function isDpdCarrierByOrder($order)
173
+ {
174
+ if (!is_object($order)) {
175
+ return false;
176
+ }
177
+ $carrier = $order->getShippingCarrier();
178
+
179
+ return $this->isCarrierDpd($carrier);
180
+ }
181
+
182
+ /**
183
+ * check if the postcode was marked as a valid postcode or not
184
+ *
185
+ * @param $order
186
+ */
187
+ public function isValidAutoPostcode($order)
188
+ {
189
+ if (!is_object($order)) {
190
+ return false;
191
+ }
192
+ if (!$this->isEnabledPostcodeAutocompleteByOrder($order)) {
193
+ //it should be valid
194
+ return 1;
195
+ }
196
+ if (!$this->isDpdCarrierByOrder($order)) {
197
+ //it should be valid
198
+ return 1;
199
+ }
200
+ $_shippingAddress = $order->getShippingAddress();
201
+ $isValid = $_shippingAddress->getValidAutoPostcode();
202
+
203
+ return $isValid;
204
+
205
+ }
206
+
207
+
208
+ public function isEnabledPostcodeAutocompleteByOrder($order)
209
+ {
210
+ if (!is_object($order)) {
211
+ return false;
212
+ }
213
+ $_shippingAddress = $order->getShippingAddress();
214
+ $address = $_shippingAddress->getData();
215
+ if (!empty($address['country_id'])) {
216
+ $countryName = Mage::getModel('directory/country')->loadByCode($address['country_id'])->getName();
217
+ $address['country'] = $countryName;
218
+ } else {
219
+ return false;
220
+ }
221
+
222
+ return (Mage::helper('zitec_dpd/postcode_search')->isEnabledAutocompleteForPostcode($countryName));
223
+ }
224
+
225
+ /**
226
+ * chceck the address length to be less then DPD API requirements
227
+ *
228
+ * @param $shippingAddress
229
+ *
230
+ * @return bool
231
+ */
232
+ public function checkAddressStreetLength($shippingAddress)
233
+ {
234
+
235
+ $shippingAddressStreetArray = $shippingAddress->getStreet();
236
+ if (is_array($shippingAddressStreetArray)) {
237
+ $shippingAddressStreet = '';
238
+ foreach ($shippingAddressStreetArray as $street) {
239
+ $shippingAddressStreet .= '' . $street;
240
+ }
241
+ $shippingAddressStreet = trim($shippingAddressStreet);
242
+ } else {
243
+ $shippingAddressStreet = $shippingAddressStreetArray;
244
+ }
245
+
246
+ return (strlen($shippingAddressStreet) <= Zitec_Dpd_Api_Configs::SHIPMENT_LIST_RECEIVER_STREET_MAX_LENGTH);
247
+ }
248
+
249
+
250
+ /**
251
+ *
252
+ * @param string|Mage_Sales_Model_Order_Shipment|Mage_Sales_Model_Order $shippingMethod
253
+ *
254
+ * @return boolean
255
+ */
256
+ public function isShippingMethodDpd($shippingMethod)
257
+ {
258
+ if ($shippingMethod instanceof Mage_Sales_Model_Order_Shipment) {
259
+ $shippingMethod = $shippingMethod->getOrder()->getShippingMethod();
260
+ } elseif ($shippingMethod instanceof Mage_Sales_Model_Order) {
261
+ $shippingMethod = $shippingMethod->getShippingMethod();
262
+ }
263
+
264
+ return is_string($shippingMethod) && (strpos($shippingMethod, $this->getDpdCarrierCode()) !== false);
265
+ }
266
+
267
+
268
+ /**
269
+ * Returns true if the magento version is greater or equal to the version passed.
270
+ *
271
+ * @param int $major
272
+ * @param int $minor
273
+ * @param int $revision
274
+ * @param int $patch
275
+ *
276
+ * @return boolean
277
+ */
278
+ public function isMagentoVersionGreaterOrEqualTo($major, $minor, $revision, $patch)
279
+ {
280
+ $versionInfo = Mage::getVersionInfo();
281
+ if ((int)$major > (int)$versionInfo['major']) {
282
+ return false;
283
+ } elseif ((int)$minor > (int)$versionInfo['minor']) {
284
+ return false;
285
+ } elseif ((int)$revision > (int)$versionInfo['revision']) {
286
+ return false;
287
+ } elseif ((int)$patch > (int)$versionInfo['patch']) {
288
+ return false;
289
+ } else {
290
+ return true;
291
+ }
292
+ }
293
+
294
+ /**
295
+ *
296
+ * @param string $message
297
+ */
298
+ public function addNotice($message)
299
+ {
300
+ Mage::getSingleton('core/session')->addNotice($message);
301
+ }
302
+
303
+ /**
304
+ *
305
+ * @param string $message
306
+ */
307
+ public function addError($message)
308
+ {
309
+ Mage::getSingleton('core/session')->addError($message);
310
+ }
311
+
312
+ /**
313
+ *
314
+ * @param string $message
315
+ */
316
+ public function addSuccess($message)
317
+ {
318
+ Mage::getSingleton('core/session')->addSuccess($message);
319
+ }
320
+
321
+ /**
322
+ *
323
+ * @param boolean $success
324
+ * @param string $message
325
+ *
326
+ * @return \Zitec_Dpd_Helper_Data
327
+ */
328
+ public function addSuccessError($success, $message)
329
+ {
330
+ if ($success) {
331
+ $this->addSuccess($message);
332
+ } else {
333
+ $this->addError($message);
334
+ }
335
+
336
+ return $this;
337
+ }
338
+
339
+ /**
340
+ *
341
+ * @return boolean
342
+ */
343
+ public function isAdmin()
344
+ {
345
+ return Mage::app()->getStore()->isAdmin();
346
+ }
347
+
348
+ /**
349
+ *
350
+ * @param string $shipmentId
351
+ *
352
+ * @return boolean
353
+ * @deprecated
354
+ */
355
+ public function isManifestClosed($shipmentId)
356
+ {
357
+ $shipsCollection = Mage::getResourceModel('zitec_dpd/dpd_ship_collection');
358
+ /* @var $shipsCollection Zitec_Dpd_Model_Mysql4_Dpd_Ship_Collection */
359
+ $ships = $shipsCollection->getByShipmentId($shipmentId);
360
+
361
+ /* @var $ships Zitec_Dpd_Model_Dpd_Ship */
362
+
363
+ return $ships->getManifest() ? true : false;
364
+
365
+ }
366
+
367
+ /**
368
+ *
369
+ * @param Mage_Sales_Model_Order_Shipment_Track $track
370
+ *
371
+ * @return boolean
372
+ */
373
+ public function isDpdTrack(Mage_Sales_Model_Order_Shipment_Track $track)
374
+ {
375
+ return strpos($track->getCarrierCode(), $this->getDpdCarrierCode()) !== false;
376
+ }
377
+
378
+ /**
379
+ *
380
+ * @param Mage_Sales_Model_Order_Shipment $shipment
381
+ *
382
+ * @return boolean
383
+ */
384
+ public function isCancelledWithDpd(Mage_Sales_Model_Order_Shipment $shipment)
385
+ {
386
+ return $this->isShippingMethodDpd($shipment->getOrder()->getShippingMethod()) && !$shipment->getShippingLabel();
387
+ }
388
+
389
+
390
+ /**
391
+ *
392
+ * @param string $shippingMethod
393
+ *
394
+ * @return string|boolean
395
+ */
396
+ public function getDPDServiceCode($shippingMethod)
397
+ {
398
+ $parts = explode('_', $shippingMethod);
399
+ if (count($parts) == 2) {
400
+ return $parts[1];
401
+ } else {
402
+ return false;
403
+ }
404
+ }
405
+
406
+ /**
407
+ *
408
+ * @param Mage_Sales_Model_Order $order
409
+ *
410
+ * @return boolean
411
+ */
412
+ public function isOrderCashOnDelivery(Mage_Sales_Model_Order $order)
413
+ {
414
+ return $order->getPayment()->getMethod() == Mage::helper('zitec_dpd')->getDpdPaymentCode() ? true : false;
415
+ }
416
+
417
+ /**
418
+ * return default surcharge in checkout if no table rates defined
419
+ *
420
+ * @param Mage_Sales_Model_Quote $quote
421
+ * @param $shippingAmount
422
+ *
423
+ * @return mixed
424
+ */
425
+ public function returnDefaultBaseCashOnDeliverySurcharge(Mage_Sales_Model_Quote $quote)
426
+ {
427
+ $amountType = Mage::getStoreConfig('payment/zitec_dpd_cashondelivery/payment_amount_type', $quote->getStoreId());
428
+ $amount = Mage::getStoreConfig('payment/zitec_dpd_cashondelivery/payment_amount', $quote->getStoreId());
429
+ if ($amountType == Zitec_Dpd_Api_Configs::PAYMENT_AMOUNT_TYPE_FIXED) {
430
+ return $amount;
431
+ } else {
432
+ $address = $quote->getShippingAddress();
433
+ $taxConfig = Mage::getSingleton('tax/config');
434
+ /* @var $taxConfig Mage_Tax_Model_Config */
435
+
436
+ $amount = $amount / 100;
437
+
438
+ return $amount * ($this->getBaseValueOfShippableGoods($quote));
439
+ }
440
+
441
+ }
442
+
443
+ /**
444
+ * here is calculated the price of the quote payment method: cash on delivery using DPD
445
+ *
446
+ * @param Mage_Sales_Model_Quote $quote
447
+ * @param string $surcharge
448
+ *
449
+ * @return float
450
+ */
451
+ public function calculateQuoteBaseCashOnDeliverySurcharge(Mage_Sales_Model_Quote $quote, $surcharge)
452
+ {
453
+ $address = $quote->getShippingAddress();
454
+ $taxConfig = Mage::getSingleton('tax/config');
455
+ /* @var $taxConfig Mage_Tax_Model_Config */
456
+
457
+ if (!$surcharge || !is_array($surcharge) || !isset($surcharge['cashondelivery_surcharge'])) {
458
+ return 0;
459
+ }
460
+ $baseCashondeliverySurchargePercent = $this->parsePercentageValueAsFraction($surcharge['cashondelivery_surcharge']);
461
+ if ($baseCashondeliverySurchargePercent !== false) {
462
+
463
+ $baseCashondeliverySurcharge = $baseCashondeliverySurchargePercent * ($this->getBaseValueOfShippableGoods($quote));
464
+ if (isset($surcharge['cod_min_surcharge'])) {
465
+ $baseCashondeliverySurcharge = max(array((float)$surcharge['cod_min_surcharge'], $baseCashondeliverySurcharge));
466
+ }
467
+ } else {
468
+ $baseCashondeliverySurcharge = (float)$surcharge['cashondelivery_surcharge'];
469
+ }
470
+
471
+ return $baseCashondeliverySurcharge;
472
+ }
473
+
474
+ /**
475
+ * Parse a string of the form nn.nn% and returns the percent as a fraction.
476
+ * It returns false if the string does not have the correct form.
477
+ *
478
+ * @param type $value
479
+ *
480
+ * @return boolean
481
+ */
482
+ public function parsePercentageValueAsFraction($value)
483
+ {
484
+ if (!is_string($value)) {
485
+ return false;
486
+ }
487
+ $value = trim($value);
488
+ if (strlen($value) < 2 || substr($value, -1) != '%') {
489
+ return false;
490
+ }
491
+ $percentage = $this->parseDecimalValue(substr($value, 0, strlen($value) - 1));
492
+ if ($percentage === false) {
493
+ return false;
494
+ }
495
+
496
+ return $percentage / 100;
497
+ }
498
+
499
+
500
+ /**
501
+ * Parse and validate positive decimal value
502
+ * Return false if value is not decimal or is not positive
503
+ *
504
+ * @param string $value
505
+ *
506
+ * @return bool|float
507
+ */
508
+ public function parseDecimalValue($value)
509
+ {
510
+ if (!is_numeric($value)) {
511
+ return false;
512
+ }
513
+ $value = (float)sprintf('%.4F', $value);
514
+ if ($value < 0.0000) {
515
+ return false;
516
+ }
517
+
518
+ return $value;
519
+ }
520
+
521
+
522
+ /**
523
+ *
524
+ * @param Mage_Sales_Model_Quote $quote
525
+ *
526
+ * @return float
527
+ */
528
+ public function getBaseValueOfShippableGoods(Mage_Sales_Model_Quote $quote)
529
+ {
530
+ $baseTotalPrice = 0.0;
531
+ $taxConfig = Mage::getSingleton('tax/config');
532
+ /* @var $taxConfig Mage_Tax_Model_Config */
533
+ if ($quote->getAllItems()) {
534
+ foreach ($quote->getAllItems() as $item) {
535
+ /* @var $item Mage_Sales_Model_Quote_Item */
536
+
537
+ if ($item->getProduct()->isVirtual() || $item->getParentItemId()) {
538
+ continue;
539
+ }
540
+
541
+ $baseTotalPrice += $taxConfig->shippingPriceIncludesTax($quote->getStore()) ? $item->getBaseRowTotalInclTax() : $item->getBaseRowTotal();
542
+ }
543
+ }
544
+
545
+ return $baseTotalPrice;
546
+ }
547
+
548
+
549
+ /**
550
+ *
551
+ * @param Mage_Sales_Model_Order $order
552
+ *
553
+ * @return string
554
+ */
555
+ public function getCodPaymentType(Mage_Sales_Model_Order $order)
556
+ {
557
+ return $order->getPayment()->getMethodInstance()->getConfigData("cod_payment_type", $order->getStoreId());
558
+ }
559
+
560
+
561
+ /**
562
+ *
563
+ * @param int $manifestId
564
+ *
565
+ * @return string
566
+ */
567
+ public function getDownloadManifestUrl($manifestId)
568
+ {
569
+ $helper = Mage::helper('adminhtml');
570
+
571
+ /* @var $helper Mage_Adminhtml_Helper_Data */
572
+
573
+ return $helper->getUrl("zitec_dpd/adminhtml_shipment/downloadmanifest", array("manifest_id" => $manifestId));
574
+ }
575
+
576
+
577
+ /**
578
+ * @return string
579
+ */
580
+ public function getDpdCarrierCode()
581
+ {
582
+ return Zitec_Dpd_Model_Shipping_Carrier_Dpd::CARRIER_CODE;
583
+ }
584
+
585
+
586
+ /**
587
+ * @return string
588
+ */
589
+ public function getDpdPaymentCode()
590
+ {
591
+ return Zitec_Dpd_Model_Payment_Cashondelivery::CODE;
592
+ }
593
+
594
+
595
  }
app/code/community/Zitec/Dpd/Helper/Layout.php CHANGED
@@ -1,107 +1,107 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Helper_Layout extends Mage_Core_Helper_Abstract
25
- {
26
-
27
- const DEFAULT_TRACKING_TEMPLATE = 'sales/order/shipment/view/tracking.phtml';
28
- const DEFAULT_SHIPPING_TRACKING_POPUP_TEMPLATE = "shipping/tracking/popup.phtml";
29
-
30
- /**
31
- *
32
- * @return string
33
- */
34
- public function getAdminhtmlTrackingTemplate()
35
- {
36
- if (!$this->_getHelper()->moduleIsActive()) {
37
- return self::DEFAULT_TRACKING_TEMPLATE;
38
- }
39
-
40
- $shipmentId = $this->_getRequest()->getParam('shipment_id');
41
- if (!$shipmentId) {
42
- return self::DEFAULT_TRACKING_TEMPLATE;
43
- }
44
-
45
- $shipment = Mage::getModel('sales/order_shipment')/* @var $shipment Mage_Sales_Model_Order_Shipment */
46
- ->load($shipmentId);
47
- if (!$this->_getHelper()->isShippingMethodDpd($shipment->getOrder()->getShippingMethod())) {
48
- return self::DEFAULT_TRACKING_TEMPLATE;
49
- }
50
-
51
- if ($this->_getHelper()->isMagentoVersionGreaterOrEqualTo('1', '7', '0', '0')) {
52
- return 'zitec_dpd/sales/order/shipment/view/tracking_17.phtml';
53
- } else {
54
- return 'zitec_dpd/sales/order/shipment/view/tracking.phtml';
55
- }
56
- }
57
-
58
- /**
59
- *
60
- * @return string
61
- */
62
- public function changeShippingTrackingPopupTemplate()
63
- {
64
- if (!$this->_getHelper()->moduleIsActive()) {
65
- return self::DEFAULT_SHIPPING_TRACKING_POPUP_TEMPLATE;
66
- }
67
-
68
- $shippingInfo = Mage::registry("current_shipping_info");
69
- /* @var $shippingInfo Mage_Shipping_Model_Info */
70
- if (!$shippingInfo instanceof Mage_Shipping_Model_Info) {
71
- return self::DEFAULT_SHIPPING_TRACKING_POPUP_TEMPLATE;
72
- }
73
-
74
-
75
- if ($shippingInfo->getOrderId()) {
76
- $orderId = $shippingInfo->getOrderId();
77
- } elseif ($shippingInfo->getShipId()) {
78
- $orderId = Mage::getModel('sales/order_shipment')->load($shippingInfo->getShipId())->getOrderId();
79
- } elseif ($shippingInfo->getTrackId()) {
80
- $orderId = Mage::getModel('sales/order_shipment_track')->load($shippingInfo->getTrackId())->getOrderId();
81
- } else {
82
- return self::DEFAULT_SHIPPING_TRACKING_POPUP_TEMPLATE;
83
- }
84
-
85
- if (!$orderId) {
86
- return self::DEFAULT_SHIPPING_TRACKING_POPUP_TEMPLATE;
87
- }
88
-
89
- $shippingMethod = Mage::getModel('sales/order')->load($orderId)->getShippingMethod();
90
- if (!$this->_getHelper()->isShippingMethodDpd($shippingMethod)) {
91
- return self::DEFAULT_SHIPPING_TRACKING_POPUP_TEMPLATE;
92
- }
93
-
94
- return 'zitec_dpd/shipping/tracking/popup.phtml';
95
- }
96
-
97
- /**
98
- *
99
- * @return Zitec_Dpd_Helper_Data
100
- */
101
- protected function _getHelper()
102
- {
103
- return Mage::helper('zitec_dpd');
104
- }
105
- }
106
-
107
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Helper_Layout extends Mage_Core_Helper_Abstract
25
+ {
26
+
27
+ const DEFAULT_TRACKING_TEMPLATE = 'sales/order/shipment/view/tracking.phtml';
28
+ const DEFAULT_SHIPPING_TRACKING_POPUP_TEMPLATE = "shipping/tracking/popup.phtml";
29
+
30
+ /**
31
+ *
32
+ * @return string
33
+ */
34
+ public function getAdminhtmlTrackingTemplate()
35
+ {
36
+ if (!$this->_getHelper()->moduleIsActive()) {
37
+ return self::DEFAULT_TRACKING_TEMPLATE;
38
+ }
39
+
40
+ $shipmentId = $this->_getRequest()->getParam('shipment_id');
41
+ if (!$shipmentId) {
42
+ return self::DEFAULT_TRACKING_TEMPLATE;
43
+ }
44
+
45
+ $shipment = Mage::getModel('sales/order_shipment')/* @var $shipment Mage_Sales_Model_Order_Shipment */
46
+ ->load($shipmentId);
47
+ if (!$this->_getHelper()->isShippingMethodDpd($shipment->getOrder()->getShippingMethod())) {
48
+ return self::DEFAULT_TRACKING_TEMPLATE;
49
+ }
50
+
51
+ if ($this->_getHelper()->isMagentoVersionGreaterOrEqualTo('1', '7', '0', '0')) {
52
+ return 'zitec_dpd/sales/order/shipment/view/tracking_17.phtml';
53
+ } else {
54
+ return 'zitec_dpd/sales/order/shipment/view/tracking.phtml';
55
+ }
56
+ }
57
+
58
+ /**
59
+ *
60
+ * @return string
61
+ */
62
+ public function changeShippingTrackingPopupTemplate()
63
+ {
64
+ if (!$this->_getHelper()->moduleIsActive()) {
65
+ return self::DEFAULT_SHIPPING_TRACKING_POPUP_TEMPLATE;
66
+ }
67
+
68
+ $shippingInfo = Mage::registry("current_shipping_info");
69
+ /* @var $shippingInfo Mage_Shipping_Model_Info */
70
+ if (!$shippingInfo instanceof Mage_Shipping_Model_Info) {
71
+ return self::DEFAULT_SHIPPING_TRACKING_POPUP_TEMPLATE;
72
+ }
73
+
74
+
75
+ if ($shippingInfo->getOrderId()) {
76
+ $orderId = $shippingInfo->getOrderId();
77
+ } elseif ($shippingInfo->getShipId()) {
78
+ $orderId = Mage::getModel('sales/order_shipment')->load($shippingInfo->getShipId())->getOrderId();
79
+ } elseif ($shippingInfo->getTrackId()) {
80
+ $orderId = Mage::getModel('sales/order_shipment_track')->load($shippingInfo->getTrackId())->getOrderId();
81
+ } else {
82
+ return self::DEFAULT_SHIPPING_TRACKING_POPUP_TEMPLATE;
83
+ }
84
+
85
+ if (!$orderId) {
86
+ return self::DEFAULT_SHIPPING_TRACKING_POPUP_TEMPLATE;
87
+ }
88
+
89
+ $shippingMethod = Mage::getModel('sales/order')->load($orderId)->getShippingMethod();
90
+ if (!$this->_getHelper()->isShippingMethodDpd($shippingMethod)) {
91
+ return self::DEFAULT_SHIPPING_TRACKING_POPUP_TEMPLATE;
92
+ }
93
+
94
+ return 'zitec_dpd/shipping/tracking/popup.phtml';
95
+ }
96
+
97
+ /**
98
+ *
99
+ * @return Zitec_Dpd_Helper_Data
100
+ */
101
+ protected function _getHelper()
102
+ {
103
+ return Mage::helper('zitec_dpd');
104
+ }
105
+ }
106
+
107
+
app/code/community/Zitec/Dpd/Helper/Payment.php CHANGED
@@ -1,57 +1,57 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * this class is used for
20
- *
21
- * @category Zitec
22
- * @package Zitec_Dpd
23
- * @author Zitec COM <magento@zitec.ro>
24
- */
25
- class Zitec_Dpd_Helper_Payment extends Mage_Core_Helper_Abstract
26
- {
27
-
28
-
29
- public function getWebsiteId()
30
- {
31
- if (Mage::app()->getStore()->isAdmin()) {
32
- $sessionQuote = Mage::getSingleton('adminhtml/session_quote');
33
- $store = $sessionQuote->getStore();
34
- if (empty($store)) {
35
- return 0;
36
- }
37
- $webSiteId = $store->getWebsiteId();
38
-
39
- return $webSiteId;
40
- }
41
-
42
- $webSiteId = Mage::app()->getStore()->getWebsiteId();
43
-
44
- return $webSiteId;
45
- }
46
-
47
-
48
-
49
- public function getQuote(){
50
- if (Mage::app()->getStore()->isAdmin()) {
51
- return Mage::getSingleton('adminhtml/session_quote')->getQuote();
52
- } else {
53
- return Mage::getSingleton('checkout/session')->getQuote();
54
- }
55
- }
56
-
57
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * this class is used for
20
+ *
21
+ * @category Zitec
22
+ * @package Zitec_Dpd
23
+ * @author Zitec COM <magento@zitec.ro>
24
+ */
25
+ class Zitec_Dpd_Helper_Payment extends Mage_Core_Helper_Abstract
26
+ {
27
+
28
+
29
+ public function getWebsiteId()
30
+ {
31
+ if (Mage::app()->getStore()->isAdmin()) {
32
+ $sessionQuote = Mage::getSingleton('adminhtml/session_quote');
33
+ $store = $sessionQuote->getStore();
34
+ if (empty($store)) {
35
+ return 0;
36
+ }
37
+ $webSiteId = $store->getWebsiteId();
38
+
39
+ return $webSiteId;
40
+ }
41
+
42
+ $webSiteId = Mage::app()->getStore()->getWebsiteId();
43
+
44
+ return $webSiteId;
45
+ }
46
+
47
+
48
+
49
+ public function getQuote(){
50
+ if (Mage::app()->getStore()->isAdmin()) {
51
+ return Mage::getSingleton('adminhtml/session_quote')->getQuote();
52
+ } else {
53
+ return Mage::getSingleton('checkout/session')->getQuote();
54
+ }
55
+ }
56
+
57
  }
app/code/community/Zitec/Dpd/Helper/Postcode/Search.php CHANGED
@@ -1,182 +1,212 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * this class is used for
20
- *
21
- * @category Zitec
22
- * @package Zitec_Dpd
23
- * @author Zitec COM <magento@zitec.ro>
24
- */
25
- class Zitec_Dpd_Helper_Postcode_Search extends Mage_Core_Helper_Abstract
26
- {
27
-
28
- public function extractPostCodeForShippingRequest($request)
29
- {
30
- $countryName = Mage::getModel('directory/country')->loadByCode($request->getDestCountryId())->getName();
31
-
32
- if ($this->isEnabledAutocompleteForPostcode($countryName)) {
33
- if($request->getDestRegionId()) {
34
- $regionName = Mage::getModel('directory/region')->load($request->getDestRegionId())->getName();
35
- }
36
-
37
- $address = array(
38
- 'country' => $countryName,
39
- 'region' => $regionName,
40
- 'city' => $request->getDestCity(),
41
- 'address' => $request->getDestStreet(),
42
- 'postcode' => $request->getDestPostcode(),
43
- );
44
-
45
- $postcodeRelevance = new stdClass();
46
- $postCode = $this->search($address, $postcodeRelevance);
47
-
48
- $checkout = Mage::getSingleton('checkout/session')->getQuote();
49
- $shipAddress = $checkout->getShippingAddress();
50
- $shipAddress->setData('auto_postcode', $postCode);
51
- $shipAddress->setData('valid_auto_postcode', $this->isValid($postCode, $postcodeRelevance));
52
- if ($this->isValid($postCode, $postcodeRelevance)){
53
- $shipAddress->setPostcode($postCode);
54
- }
55
- } else {
56
- $postCode = $request->getDestPostcode();
57
- }
58
-
59
- return $postCode;
60
- }
61
-
62
-
63
-
64
- /**
65
- * it is used to create a list of relevant addresses for given address.
66
- * used in admin panel to validate the postcode
67
- *
68
- * @param array $address The content will be the edit form for address from admin
69
- * $address contain next keys
70
- * MANDATORY
71
- * country
72
- * city
73
- *
74
- * OPTIONAL
75
- * region
76
- * address
77
- * street
78
- */
79
- public function findAllSimilarAddressesForAddress($address){
80
- if(!empty($address['country_id'])){
81
- $countryName = Mage::getModel('directory/country')->loadByCode($address['country_id'])->getName();
82
- $address['country'] = $countryName;
83
- }
84
-
85
- if ($this->isEnabledAutocompleteForPostcode($countryName)) {
86
- if ($address['region_id']) {
87
- $regionName = Mage::getModel('directory/region')->load($address['region_id'])->getName();
88
- $address['region'] = $regionName;
89
- }
90
-
91
- $foundAddresses = $this->getSearchPostcodeModel()->searchSimilarAddresses($address);
92
- return $foundAddresses;
93
- }
94
-
95
- return false;
96
- }
97
-
98
-
99
-
100
- /**
101
- * @param array $address
102
- * $address contain next keys
103
- * MANDATORY
104
- * country
105
- * city
106
- *
107
- * OPTIONAL
108
- * region
109
- * address
110
- * street
111
- *
112
- * @param null $postcodeRelevance
113
- *
114
- * @return string
115
- */
116
- public function search($address, $postcodeRelevance = null)
117
- {
118
- $foundPostCode = $this->getSearchPostcodeModel()->search($address, $postcodeRelevance);
119
- if (isset($address['postcode']) && strlen($address['postcode']) > 4) {
120
- if ($foundPostCode == $address['postcode']) {
121
- return $foundPostCode;
122
- } elseif (!empty($foundPostCode)) {
123
- //mark the response as not exactly the same
124
- return $foundPostCode;
125
- }
126
-
127
- return $address['postcode'];
128
- }
129
-
130
- return $foundPostCode;
131
- }
132
-
133
- /**
134
- * test if found postcode relevance is enough for considering the postcode useful in the rest of checkout process
135
- *
136
- * @param $postCode
137
- * @param stdClass $relevance
138
- *
139
- * @return int
140
- */
141
- public function isValid($postCode, stdClass $relevance = null)
142
- {
143
- if (empty($relevance)) {
144
- return 0;
145
- }
146
- if (!empty($relevance->percent) && $relevance->percent > Zitec_Dpd_Postcode_Search::SEARCH_RESULT_RELEVANCE_THRESHOLD_FOR_VALIDATION) {
147
- return 1;
148
- }
149
-
150
- return 0;
151
- }
152
-
153
-
154
- public function isEnabledAutocompleteForPostcode($countryName)
155
- {
156
- $isValid = $this->getSearchPostcodeModel()->isEnabled($countryName);
157
- if(empty($isValid)){
158
- return false;
159
- }
160
-
161
- $value = Mage::getStoreConfig('carriers/zitecDpd/postcode_autocomplete_checkout');
162
-
163
- return !empty($value);
164
- }
165
-
166
-
167
- public function getSearchPostcodeModel()
168
- {
169
- $getSearchPostcodeModel = Mage::registry('getSearchPostcodeModel');
170
-
171
- if (empty($getSearchPostcodeModel)) {
172
- $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
173
- $libInstance = new Zitec_Dpd_Postcode_Search(Zitec_Dpd_Postcode_Search::MYSQL_ADAPTER, $connection);
174
- Mage::register('getSearchPostcodeModel', $libInstance);
175
- $getSearchPostcodeModel = $libInstance;
176
- }
177
-
178
- return $getSearchPostcodeModel;
179
- }
180
-
181
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * this class is used for
20
+ *
21
+ * @category Zitec
22
+ * @package Zitec_Dpd
23
+ * @author Zitec COM <magento@zitec.ro>
24
+ */
25
+ class Zitec_Dpd_Helper_Postcode_Search extends Mage_Core_Helper_Abstract
26
+ {
27
+
28
+
29
+ public function extractPostCodeForShippingRequest($request)
30
+ {
31
+ $countryName = Mage::getModel('directory/country')->loadByCode($request->getDestCountryId())->getName();
32
+
33
+ if ($this->isEnabledAutocompleteForPostcode($countryName)) {
34
+ if($request->getDestRegionId()) {
35
+ $regionName = Mage::getModel('directory/region')->load($request->getDestRegionId())->getName();
36
+ }
37
+
38
+ $address = array(
39
+ 'country' => $countryName,
40
+ 'region' => $regionName,
41
+ 'city' => $request->getDestCity(),
42
+ 'address' => $request->getDestStreet(),
43
+ 'postcode' => $request->getDestPostcode(),
44
+ );
45
+
46
+ $postcodeRelevance = new stdClass();
47
+ $postCode = $this->search($address, $postcodeRelevance);
48
+
49
+ $checkout = Mage::getSingleton('checkout/session')->getQuote();
50
+ $shipAddress = $checkout->getShippingAddress();
51
+ $shipAddress->setData('auto_postcode', $postCode);
52
+ $shipAddress->setData('valid_auto_postcode', $this->isValid($postCode, $postcodeRelevance));
53
+ if ($this->isValid($postCode, $postcodeRelevance)){
54
+ $shipAddress->setPostcode($postCode);
55
+ }
56
+ } else {
57
+ $postCode = $request->getDestPostcode();
58
+ }
59
+
60
+ return $postCode;
61
+ }
62
+
63
+
64
+
65
+ /**
66
+ * it is used to create a list of relevant addresses for given address.
67
+ * used in admin panel to validate the postcode
68
+ *
69
+ * @param array $address The content will be the edit form for address from admin
70
+ * $address contain next keys
71
+ * MANDATORY
72
+ * country
73
+ * city
74
+ *
75
+ * OPTIONAL
76
+ * region
77
+ * address
78
+ * street
79
+ */
80
+ public function findAllSimilarAddressesForAddress($address){
81
+ if(!empty($address['country_id'])){
82
+ $countryName = Mage::getModel('directory/country')->loadByCode($address['country_id'])->getName();
83
+ $address['country'] = $countryName;
84
+ }
85
+
86
+ if ($this->isEnabledAutocompleteForPostcode($countryName)) {
87
+ if ($address['region_id']) {
88
+ $regionName = Mage::getModel('directory/region')->load($address['region_id'])->getName();
89
+ $address['region'] = $regionName;
90
+ }
91
+
92
+ $foundAddresses = $this->getSearchPostcodeModel()->searchSimilarAddresses($address);
93
+ return $foundAddresses;
94
+ }
95
+
96
+ return false;
97
+ }
98
+
99
+
100
+
101
+ /**
102
+ * @param array $address
103
+ * $address contain next keys
104
+ * MANDATORY
105
+ * country
106
+ * city
107
+ *
108
+ * OPTIONAL
109
+ * region
110
+ * address
111
+ * street
112
+ *
113
+ * @param null $postcodeRelevance
114
+ *
115
+ * @return string
116
+ */
117
+ public function search($address, $postcodeRelevance = null)
118
+ {
119
+ $foundPostCode = $this->getSearchPostcodeModel()->search($address, $postcodeRelevance);
120
+ if (isset($address['postcode']) && strlen($address['postcode']) > 4) {
121
+ if ($foundPostCode == $address['postcode']) {
122
+ return $foundPostCode;
123
+ } elseif (!empty($foundPostCode)) {
124
+ //mark the response as not exactly the same
125
+ return $foundPostCode;
126
+ }
127
+
128
+ return $address['postcode'];
129
+ }
130
+
131
+ return $foundPostCode;
132
+ }
133
+
134
+ /**
135
+ * test if found postcode relevance is enough for considering the postcode useful in the rest of checkout process
136
+ *
137
+ * @param $postCode
138
+ * @param stdClass $relevance
139
+ *
140
+ * @return int
141
+ */
142
+ public function isValid($postCode, stdClass $relevance = null)
143
+ {
144
+ if (empty($relevance)) {
145
+ return 0;
146
+ }
147
+ if (!empty($relevance->percent) && $relevance->percent > Zitec_Dpd_Postcode_Search::SEARCH_RESULT_RELEVANCE_THRESHOLD_FOR_VALIDATION) {
148
+ return 1;
149
+ }
150
+
151
+ return 0;
152
+ }
153
+
154
+
155
+ public function isEnabledAutocompleteForPostcode($countryName)
156
+ {
157
+ $isValid = $this->getSearchPostcodeModel()->isEnabled($countryName);
158
+ if(empty($isValid)){
159
+ return false;
160
+ }
161
+
162
+ $value = Mage::getStoreConfig('carriers/zitecDpd/postcode_autocomplete_checkout');
163
+
164
+ return !empty($value);
165
+ }
166
+
167
+
168
+ public function getSearchPostcodeModel()
169
+ {
170
+ $getSearchPostcodeModel = Mage::registry('getSearchPostcodeModel');
171
+
172
+ if (empty($getSearchPostcodeModel)) {
173
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
174
+ $libInstance = new Zitec_Dpd_Postcode_Search(Zitec_Dpd_Postcode_Search::MYSQL_ADAPTER, $connection);
175
+ Mage::register('getSearchPostcodeModel', $libInstance);
176
+ $getSearchPostcodeModel = $libInstance;
177
+ }
178
+
179
+ return $getSearchPostcodeModel;
180
+ }
181
+
182
+
183
+ /**
184
+ * return the path do database files CSV
185
+ *
186
+ * @return string
187
+ */
188
+ public function getPathToDatabaseUpgradeFiles(){
189
+ return Mage::getBaseDir('media').DS.'dpd'.DS . 'postcode_updates'. DS;
190
+ }
191
+
192
+
193
+ /**
194
+ *
195
+ * call the library function for postcode update
196
+ *
197
+ * @param $fileName
198
+ *
199
+ * @return bool
200
+ * @throws Exception
201
+ */
202
+ public function updateDatabase($fileName){
203
+ $result = $this->getSearchPostcodeModel()->updateDatabase($fileName);
204
+ if(empty($result)){
205
+ throw new Exception(Mage::helper('core')->__('An error occurred while updating postcode database. Please run again the import script. (A database backup is always created in zitec_dpd_postcodes_backup table.)'));
206
+ }
207
+ return true;
208
+ }
209
+
210
+
211
+
212
  }
app/code/community/Zitec/Dpd/Helper/Ws.php CHANGED
@@ -1,396 +1,396 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * this helper is used for calling the api methods implemented further in the Zitec_Dpd_Api library
20
- *
21
- * @category Zitec
22
- * @package Zitec_Dpd
23
- * @author Zitec COM <magento@zitec.ro>
24
- */
25
- class Zitec_Dpd_Helper_Ws extends Mage_Core_Helper_Abstract
26
- {
27
- protected $_store = null;
28
-
29
- /**
30
- * create shipping label and create the pdf content
31
- *
32
- * @param int $dpdShipmentId
33
- * @param string $dpdShipmentReferenceNumber
34
- *
35
- * @return string
36
- * @throws Exception
37
- */
38
- public function getNewPdfShipmentLabelsStr($dpdShipmentId, $dpdShipmentReferenceNumber)
39
- {
40
- $apiParams = $this->getShipmentParams();
41
- $apiParams['method'] = Zitec_Dpd_Api_Configs::METHOD_SHIPMENT_GET_LABEL;
42
- $dpdApi = new Zitec_Dpd_Api($apiParams);
43
- $dpdLabel = $dpdApi->getApiMethodObject();
44
-
45
- $dpdLabel->setShipment($dpdShipmentId, $dpdShipmentReferenceNumber);
46
- try {
47
- $dpdLabel->execute();
48
- } catch (Exception $e) {
49
- throw $e;
50
- }
51
- $labelResponse = $dpdLabel->getResponse();
52
- /* @var $labelResponse Zitec_Dpd_Api_Shipment_GetLabel_Response */
53
- if ($labelResponse->hasError()) {
54
- throw new Exception($labelResponse->getErrorText());
55
- }
56
-
57
- return $labelResponse->getPdfFile();
58
- }
59
-
60
-
61
-
62
- /**
63
- * this method is used for tracking the order shipment
64
- * in the response of this method will be a url on dpd website
65
- *
66
- * @param $saveShipmentResponse
67
- *
68
- * @return mixed
69
- */
70
- public function getShipmentStatus($saveShipmentResponse){
71
-
72
- $apiParams = $this->getShipmentParams();
73
- $apiParams['method'] = Zitec_Dpd_Api_Configs::METHOD_SHIPMENT_GET_SHIPMENT_STATUS;
74
-
75
-
76
- $dpdApi = new Zitec_Dpd_Api($apiParams);
77
- $getShipmentStatus = $dpdApi->getApiMethodObject();
78
-
79
- $getShipmentStatus->setShipment($saveShipmentResponse->getDpdShipmentId(), $saveShipmentResponse->getDpdShipmentReferenceNumber());
80
-
81
-
82
- $getShipmentStatus->execute();
83
- $statusResponse = $getShipmentStatus->getShipmentStatusResponse();
84
-
85
- return $statusResponse;
86
- }
87
-
88
-
89
- /**
90
- * remove the shipment tracking code form DPD system
91
- * after this action pdf content will be set to null
92
- * but the shipment will still exist in magento admin interface
93
- *
94
- * @param $shipment
95
- * @param $saveShipmentResponse
96
- *
97
- * @return mixed
98
- */
99
- public function deleteWsShipment($shipment, $saveShipmentResponse){
100
-
101
- $apiParams = $this->getShipmentParams($shipment->getStore());
102
- $apiParams['method'] = Zitec_Dpd_Api_Configs::METHOD_SHIPMENT_DELETE;
103
-
104
-
105
- $dpdApi = new Zitec_Dpd_Api($apiParams);
106
- $deleteShipment = $dpdApi->getApiMethodObject();
107
-
108
- $deleteShipment->addShipmentReference($saveShipmentResponse->getDpdShipmentId(), $saveShipmentResponse->getDpdShipmentReferenceNumber());
109
-
110
-
111
- $deleteShipment->execute();
112
- $wsResult = $deleteShipment->getDeleteShipmentResponse();
113
-
114
- return $wsResult;
115
- }
116
-
117
-
118
-
119
- /**
120
- *
121
- * @param mixed $store
122
- *
123
- * @return array
124
- */
125
- public function getShipmentParams($store = null)
126
- {
127
- $params = $this->_getConnectionParams($store);
128
- $params[Zitec_Dpd_Api_Configs::URL] = $this->_getUrlShipment();
129
-
130
- return $params;
131
- }
132
-
133
- /**
134
- *
135
- * @param mixed $store
136
- *
137
- * @return array
138
- */
139
- public function getManifestParams($store = null)
140
- {
141
- $params = $this->_getConnectionParams($store);
142
- $params[Zitec_Dpd_Api_Configs::URL] = $this->_getUrlManifest();
143
-
144
- return $params;
145
- }
146
-
147
- /**
148
- *
149
- * @param mixed $store
150
- *
151
- * @return array
152
- */
153
- public function getPickupParams($store = null)
154
- {
155
- $params = $this->_getConnectionParams($store);
156
- $params[Zitec_Dpd_Api_Configs::URL] = $this->_getUrlPickup();
157
-
158
- return $params;
159
- }
160
-
161
- /**
162
- *
163
- * @param mixed $store
164
- *
165
- * @return array
166
- */
167
- protected function _getConnectionParams($store = null)
168
- {
169
- $this->_store = $store;
170
-
171
- return array(
172
- Zitec_Dpd_Api_Configs::CONNECTION_TIMEOUT => $this->_getConnectionTimeout(),
173
- Zitec_Dpd_Api_Configs::WS_USER_NAME => $this->_getWsUserName(),
174
- Zitec_Dpd_Api_Configs::WS_PASSWORD => $this->_getWsPassword(),
175
- Zitec_Dpd_Api_Configs::SENDER_ADDRESS_ID => $this->_getSenderAddressId(),
176
- Zitec_Dpd_Api_Configs::PAYER_ID => $this->_getPayerId()
177
- );
178
- }
179
-
180
- /**
181
- *
182
- * @return int
183
- */
184
- protected function _getConnectionTimeout()
185
- {
186
- return $this->_getConfigData("connectionTimeout");
187
- }
188
-
189
- /**
190
- *
191
- * @return type
192
- */
193
- protected function _getWsUserName()
194
- {
195
- return $this->_getConfigData("username");
196
- }
197
-
198
- /**
199
- *
200
- * @return string
201
- */
202
- protected function _getWsPassword()
203
- {
204
- return $this->_getConfigData("password");
205
- }
206
-
207
- /**
208
- *
209
- * @return string
210
- */
211
- protected function _getSenderAddressId()
212
- {
213
- return $this->_getConfigData("senderAddressId");
214
- }
215
-
216
- /**
217
- *
218
- * @return string
219
- */
220
- protected function _getPayerId()
221
- {
222
- return $this->_getConfigData("payerId");
223
- }
224
-
225
- /**
226
- *
227
- * @return string
228
- */
229
- protected function _getUrlShipment()
230
- {
231
- return $this->_getWsUrl("shipmentUrl");
232
- }
233
-
234
- /**
235
- *
236
- * @return string
237
- */
238
- protected function _getUrlManifest()
239
- {
240
- return $this->_getWsUrl("manifestUrl");
241
- }
242
-
243
- /**
244
- *
245
- * @return string
246
- */
247
- protected function _getUrlPickup()
248
- {
249
- return $this->_getWsUrl("pickupUrl");
250
- }
251
-
252
- /**
253
- *
254
- * @param string $field
255
- *
256
- * @return mixed
257
- */
258
- protected function _getConfigData($field)
259
- {
260
- return $this->_getHelper()->getConfigData($field, $this->_store);
261
- }
262
-
263
- /**
264
- *
265
- * @return Zitec_Dpd_Helper_Data
266
- */
267
- protected function _getHelper()
268
- {
269
- return Mage::helper('zitec_dpd');
270
- }
271
-
272
- /**
273
- *
274
- * @param string $dateStr
275
- *
276
- * @return string|boolean
277
- */
278
- public function convertDPDDate($dateStr)
279
- {
280
- if (!is_string($dateStr) || strlen($dateStr) != 8) {
281
- return false;
282
- }
283
-
284
- return substr($dateStr, 0, 4) . '-' . substr($dateStr, 4, 2) . '-' . substr($dateStr, -2);
285
- }
286
-
287
- /**
288
- *
289
- * @param string $timeStr
290
- *
291
- * @return string|boolean
292
- */
293
- public function convertDPDTime($timeStr)
294
- {
295
- if (!is_string($timeStr) || strlen($timeStr) != 6) {
296
- return false;
297
- }
298
-
299
- return substr($timeStr, 0, 2) . ':' . substr($timeStr, 2, 2) . ':' . substr($timeStr, -2);
300
- }
301
-
302
-
303
- /**
304
- *
305
- * @return array|boolean
306
- */
307
- public function getPickupAddress()
308
- {
309
- $address = array();
310
- $address[Zitec_Dpd_Api_Pickup_Create::NAME] = $this->_getPickupAddressConfig("name");
311
- $address[Zitec_Dpd_Api_Pickup_Create::ADDITIONAL_NAME] = $this->_getPickupAddressConfig("additionalname", false);
312
- $address[Zitec_Dpd_Api_Pickup_Create::COUNTRY_CODE] = $this->_getPickupAddressConfig("country");
313
- $address[Zitec_Dpd_Api_Pickup_Create::CITY] = $this->_getPickupAddressConfig("city");
314
- $address[Zitec_Dpd_Api_Pickup_Create::STREET] = $this->_getPickupAddressConfig("street");
315
- $address[Zitec_Dpd_Api_Pickup_Create::POSTCODE] = $this->_getPickupAddressConfig("postcode");
316
- $address[Zitec_Dpd_Api_Pickup_Create::PHONE] = $this->_getPickupAddressConfig("phone");
317
- $address[Zitec_Dpd_Api_Pickup_Create::EMAIL] = $this->_getPickupAddressConfig("email");
318
-
319
- return !in_array(false, $address, true) ? $address : false;
320
- }
321
-
322
- /**
323
- *
324
- * @param string $field
325
- * @param boolean $mandatory
326
- *
327
- * @return string|false
328
- */
329
-
330
- protected function _getPickupAddressConfig($field, $mandatory = true)
331
- {
332
- $value = Mage::getStoreConfig("shipping/zitec_pickupaddress/$field");
333
-
334
- return $value || !$mandatory ? $value : false;
335
- }
336
-
337
- /**
338
- * @param $urlType
339
- *
340
- * @return mixed|string
341
- */
342
- protected function _getWsUrl($urlType)
343
- {
344
- $wsCountry = $this->_getConfigData("wscountry");
345
- $mode = $this->_getHelper()->getConfigData("mode") ? "production" : "test";
346
- if ($wsCountry && $wsCountry != "zOther") {
347
- $url = $this->_getConfigData("countryurls/$wsCountry/$mode");
348
- } elseif ($wsCountry == "zOther") {
349
- $url = $this->_getConfigData("wsurl$mode");
350
- $url = ($url && substr($url, -1) != '/') ? "$url/" : $url;
351
- } else {
352
- return "";
353
- }
354
- if (!$url) {
355
- return "";
356
- }
357
-
358
- $urlServicePart = $this->_getConfigData("{$urlType}Part");
359
- $url = $url . $urlServicePart;
360
-
361
- return $url;
362
- }
363
-
364
- /**
365
- *
366
- * @param string $countryId
367
- *
368
- * @return boolean
369
- */
370
- public function hasWsUrls($countryId)
371
- {
372
- return $this->hasWsProductionUrl($countryId) || $this->hasWsTestUrl($countryId);
373
- }
374
-
375
- /**
376
- *
377
- * @param string $countryId
378
- *
379
- * @return boolean
380
- */
381
- public function hasWsTestUrl($countryId)
382
- {
383
- return $this->_getConfigData("countryurls/$countryId/test") ? true : false;
384
- }
385
-
386
- /**
387
- *
388
- * @param string $countryId
389
- *
390
- * @return boolean
391
- */
392
- public function hasWsProductionUrl($countryId)
393
- {
394
- return $this->_getConfigData("countryurls/$countryId/production") ? true : false;
395
- }
396
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * this helper is used for calling the api methods implemented further in the Zitec_Dpd_Api library
20
+ *
21
+ * @category Zitec
22
+ * @package Zitec_Dpd
23
+ * @author Zitec COM <magento@zitec.ro>
24
+ */
25
+ class Zitec_Dpd_Helper_Ws extends Mage_Core_Helper_Abstract
26
+ {
27
+ protected $_store = null;
28
+
29
+ /**
30
+ * create shipping label and create the pdf content
31
+ *
32
+ * @param int $dpdShipmentId
33
+ * @param string $dpdShipmentReferenceNumber
34
+ *
35
+ * @return string
36
+ * @throws Exception
37
+ */
38
+ public function getNewPdfShipmentLabelsStr($dpdShipmentId, $dpdShipmentReferenceNumber)
39
+ {
40
+ $apiParams = $this->getShipmentParams();
41
+ $apiParams['method'] = Zitec_Dpd_Api_Configs::METHOD_SHIPMENT_GET_LABEL;
42
+ $dpdApi = new Zitec_Dpd_Api($apiParams);
43
+ $dpdLabel = $dpdApi->getApiMethodObject();
44
+
45
+ $dpdLabel->setShipment($dpdShipmentId, $dpdShipmentReferenceNumber);
46
+ try {
47
+ $dpdLabel->execute();
48
+ } catch (Exception $e) {
49
+ throw $e;
50
+ }
51
+ $labelResponse = $dpdLabel->getResponse();
52
+ /* @var $labelResponse Zitec_Dpd_Api_Shipment_GetLabel_Response */
53
+ if ($labelResponse->hasError()) {
54
+ throw new Exception($labelResponse->getErrorText());
55
+ }
56
+
57
+ return $labelResponse->getPdfFile();
58
+ }
59
+
60
+
61
+
62
+ /**
63
+ * this method is used for tracking the order shipment
64
+ * in the response of this method will be a url on dpd website
65
+ *
66
+ * @param $saveShipmentResponse
67
+ *
68
+ * @return mixed
69
+ */
70
+ public function getShipmentStatus($saveShipmentResponse){
71
+
72
+ $apiParams = $this->getShipmentParams();
73
+ $apiParams['method'] = Zitec_Dpd_Api_Configs::METHOD_SHIPMENT_GET_SHIPMENT_STATUS;
74
+
75
+
76
+ $dpdApi = new Zitec_Dpd_Api($apiParams);
77
+ $getShipmentStatus = $dpdApi->getApiMethodObject();
78
+
79
+ $getShipmentStatus->setShipment($saveShipmentResponse->getDpdShipmentId(), $saveShipmentResponse->getDpdShipmentReferenceNumber());
80
+
81
+
82
+ $getShipmentStatus->execute();
83
+ $statusResponse = $getShipmentStatus->getShipmentStatusResponse();
84
+
85
+ return $statusResponse;
86
+ }
87
+
88
+
89
+ /**
90
+ * remove the shipment tracking code form DPD system
91
+ * after this action pdf content will be set to null
92
+ * but the shipment will still exist in magento admin interface
93
+ *
94
+ * @param $shipment
95
+ * @param $saveShipmentResponse
96
+ *
97
+ * @return mixed
98
+ */
99
+ public function deleteWsShipment($shipment, $saveShipmentResponse){
100
+
101
+ $apiParams = $this->getShipmentParams($shipment->getStore());
102
+ $apiParams['method'] = Zitec_Dpd_Api_Configs::METHOD_SHIPMENT_DELETE;
103
+
104
+
105
+ $dpdApi = new Zitec_Dpd_Api($apiParams);
106
+ $deleteShipment = $dpdApi->getApiMethodObject();
107
+
108
+ $deleteShipment->addShipmentReference($saveShipmentResponse->getDpdShipmentId(), $saveShipmentResponse->getDpdShipmentReferenceNumber());
109
+
110
+
111
+ $deleteShipment->execute();
112
+ $wsResult = $deleteShipment->getDeleteShipmentResponse();
113
+
114
+ return $wsResult;
115
+ }
116
+
117
+
118
+
119
+ /**
120
+ *
121
+ * @param mixed $store
122
+ *
123
+ * @return array
124
+ */
125
+ public function getShipmentParams($store = null)
126
+ {
127
+ $params = $this->_getConnectionParams($store);
128
+ $params[Zitec_Dpd_Api_Configs::URL] = $this->_getUrlShipment();
129
+
130
+ return $params;
131
+ }
132
+
133
+ /**
134
+ *
135
+ * @param mixed $store
136
+ *
137
+ * @return array
138
+ */
139
+ public function getManifestParams($store = null)
140
+ {
141
+ $params = $this->_getConnectionParams($store);
142
+ $params[Zitec_Dpd_Api_Configs::URL] = $this->_getUrlManifest();
143
+
144
+ return $params;
145
+ }
146
+
147
+ /**
148
+ *
149
+ * @param mixed $store
150
+ *
151
+ * @return array
152
+ */
153
+ public function getPickupParams($store = null)
154
+ {
155
+ $params = $this->_getConnectionParams($store);
156
+ $params[Zitec_Dpd_Api_Configs::URL] = $this->_getUrlPickup();
157
+
158
+ return $params;
159
+ }
160
+
161
+ /**
162
+ *
163
+ * @param mixed $store
164
+ *
165
+ * @return array
166
+ */
167
+ protected function _getConnectionParams($store = null)
168
+ {
169
+ $this->_store = $store;
170
+
171
+ return array(
172
+ Zitec_Dpd_Api_Configs::CONNECTION_TIMEOUT => $this->_getConnectionTimeout(),
173
+ Zitec_Dpd_Api_Configs::WS_USER_NAME => $this->_getWsUserName(),
174
+ Zitec_Dpd_Api_Configs::WS_PASSWORD => $this->_getWsPassword(),
175
+ Zitec_Dpd_Api_Configs::SENDER_ADDRESS_ID => $this->_getSenderAddressId(),
176
+ Zitec_Dpd_Api_Configs::PAYER_ID => $this->_getPayerId()
177
+ );
178
+ }
179
+
180
+ /**
181
+ *
182
+ * @return int
183
+ */
184
+ protected function _getConnectionTimeout()
185
+ {
186
+ return $this->_getConfigData("connectionTimeout");
187
+ }
188
+
189
+ /**
190
+ *
191
+ * @return type
192
+ */
193
+ protected function _getWsUserName()
194
+ {
195
+ return $this->_getConfigData("username");
196
+ }
197
+
198
+ /**
199
+ *
200
+ * @return string
201
+ */
202
+ protected function _getWsPassword()
203
+ {
204
+ return $this->_getConfigData("password");
205
+ }
206
+
207
+ /**
208
+ *
209
+ * @return string
210
+ */
211
+ protected function _getSenderAddressId()
212
+ {
213
+ return $this->_getConfigData("senderAddressId");
214
+ }
215
+
216
+ /**
217
+ *
218
+ * @return string
219
+ */
220
+ protected function _getPayerId()
221
+ {
222
+ return $this->_getConfigData("payerId");
223
+ }
224
+
225
+ /**
226
+ *
227
+ * @return string
228
+ */
229
+ protected function _getUrlShipment()
230
+ {
231
+ return $this->_getWsUrl("shipmentUrl");
232
+ }
233
+
234
+ /**
235
+ *
236
+ * @return string
237
+ */
238
+ protected function _getUrlManifest()
239
+ {
240
+ return $this->_getWsUrl("manifestUrl");
241
+ }
242
+
243
+ /**
244
+ *
245
+ * @return string
246
+ */
247
+ protected function _getUrlPickup()
248
+ {
249
+ return $this->_getWsUrl("pickupUrl");
250
+ }
251
+
252
+ /**
253
+ *
254
+ * @param string $field
255
+ *
256
+ * @return mixed
257
+ */
258
+ protected function _getConfigData($field)
259
+ {
260
+ return $this->_getHelper()->getConfigData($field, $this->_store);
261
+ }
262
+
263
+ /**
264
+ *
265
+ * @return Zitec_Dpd_Helper_Data
266
+ */
267
+ protected function _getHelper()
268
+ {
269
+ return Mage::helper('zitec_dpd');
270
+ }
271
+
272
+ /**
273
+ *
274
+ * @param string $dateStr
275
+ *
276
+ * @return string|boolean
277
+ */
278
+ public function convertDPDDate($dateStr)
279
+ {
280
+ if (!is_string($dateStr) || strlen($dateStr) != 8) {
281
+ return false;
282
+ }
283
+
284
+ return substr($dateStr, 0, 4) . '-' . substr($dateStr, 4, 2) . '-' . substr($dateStr, -2);
285
+ }
286
+
287
+ /**
288
+ *
289
+ * @param string $timeStr
290
+ *
291
+ * @return string|boolean
292
+ */
293
+ public function convertDPDTime($timeStr)
294
+ {
295
+ if (!is_string($timeStr) || strlen($timeStr) != 6) {
296
+ return false;
297
+ }
298
+
299
+ return substr($timeStr, 0, 2) . ':' . substr($timeStr, 2, 2) . ':' . substr($timeStr, -2);
300
+ }
301
+
302
+
303
+ /**
304
+ *
305
+ * @return array|boolean
306
+ */
307
+ public function getPickupAddress()
308
+ {
309
+ $address = array();
310
+ $address[Zitec_Dpd_Api_Pickup_Create::NAME] = $this->_getPickupAddressConfig("name");
311
+ $address[Zitec_Dpd_Api_Pickup_Create::ADDITIONAL_NAME] = $this->_getPickupAddressConfig("additionalname", false);
312
+ $address[Zitec_Dpd_Api_Pickup_Create::COUNTRY_CODE] = $this->_getPickupAddressConfig("country");
313
+ $address[Zitec_Dpd_Api_Pickup_Create::CITY] = $this->_getPickupAddressConfig("city");
314
+ $address[Zitec_Dpd_Api_Pickup_Create::STREET] = $this->_getPickupAddressConfig("street");
315
+ $address[Zitec_Dpd_Api_Pickup_Create::POSTCODE] = $this->_getPickupAddressConfig("postcode");
316
+ $address[Zitec_Dpd_Api_Pickup_Create::PHONE] = $this->_getPickupAddressConfig("phone");
317
+ $address[Zitec_Dpd_Api_Pickup_Create::EMAIL] = $this->_getPickupAddressConfig("email");
318
+
319
+ return !in_array(false, $address, true) ? $address : false;
320
+ }
321
+
322
+ /**
323
+ *
324
+ * @param string $field
325
+ * @param boolean $mandatory
326
+ *
327
+ * @return string|false
328
+ */
329
+
330
+ protected function _getPickupAddressConfig($field, $mandatory = true)
331
+ {
332
+ $value = Mage::getStoreConfig("shipping/zitec_pickupaddress/$field");
333
+
334
+ return $value || !$mandatory ? $value : false;
335
+ }
336
+
337
+ /**
338
+ * @param $urlType
339
+ *
340
+ * @return mixed|string
341
+ */
342
+ protected function _getWsUrl($urlType)
343
+ {
344
+ $wsCountry = $this->_getConfigData("wscountry");
345
+ $mode = $this->_getHelper()->getConfigData("mode") ? "production" : "test";
346
+ if ($wsCountry && $wsCountry != "zOther") {
347
+ $url = $this->_getConfigData("countryurls/$wsCountry/$mode");
348
+ } elseif ($wsCountry == "zOther") {
349
+ $url = $this->_getConfigData("wsurl$mode");
350
+ $url = ($url && substr($url, -1) != '/') ? "$url/" : $url;
351
+ } else {
352
+ return "";
353
+ }
354
+ if (!$url) {
355
+ return "";
356
+ }
357
+
358
+ $urlServicePart = $this->_getConfigData("{$urlType}Part");
359
+ $url = $url . $urlServicePart;
360
+
361
+ return $url;
362
+ }
363
+
364
+ /**
365
+ *
366
+ * @param string $countryId
367
+ *
368
+ * @return boolean
369
+ */
370
+ public function hasWsUrls($countryId)
371
+ {
372
+ return $this->hasWsProductionUrl($countryId) || $this->hasWsTestUrl($countryId);
373
+ }
374
+
375
+ /**
376
+ *
377
+ * @param string $countryId
378
+ *
379
+ * @return boolean
380
+ */
381
+ public function hasWsTestUrl($countryId)
382
+ {
383
+ return $this->_getConfigData("countryurls/$countryId/test") ? true : false;
384
+ }
385
+
386
+ /**
387
+ *
388
+ * @param string $countryId
389
+ *
390
+ * @return boolean
391
+ */
392
+ public function hasWsProductionUrl($countryId)
393
+ {
394
+ return $this->_getConfigData("countryurls/$countryId/production") ? true : false;
395
+ }
396
  }
app/code/community/Zitec/Dpd/Model/Config/Data/Abstract.php CHANGED
@@ -1,75 +1,75 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Config_Data_Abstract extends Mage_Core_Model_Config_Data
25
- {
26
- /**
27
- *
28
- * @return boolean
29
- */
30
- protected function _isActive()
31
- {
32
- $isActive = $this->_getConfigValue('active');
33
-
34
- return $isActive ? true : false;
35
- }
36
-
37
- /**
38
- *
39
- * @param string $field
40
- * @param string $group
41
- *
42
- * @return string|null
43
- */
44
- protected function _getConfigValue($field, $group = 'zitec_dpd')
45
- {
46
- $configValueData = $this->getData("groups/{$group}/fields/{$field}");
47
- if (is_array($configValueData) && array_key_exists('value', $configValueData)) {
48
- $configValue = $configValueData['value'];
49
-
50
- return $configValue;
51
- }
52
-
53
- return null;
54
- }
55
-
56
- /**
57
- *
58
- * @return Zitec_Dpd_Helper_Data
59
- */
60
- protected function _getHelper()
61
- {
62
- return Mage::helper('zitec_dpd');
63
- }
64
-
65
- /**
66
- *
67
- * @return Zitec_Dpd_Helper_Ws
68
- */
69
- protected function _getWsHelper()
70
- {
71
- return Mage::helper('zitec_dpd/ws');
72
- }
73
- }
74
-
75
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Config_Data_Abstract extends Mage_Core_Model_Config_Data
25
+ {
26
+ /**
27
+ *
28
+ * @return boolean
29
+ */
30
+ protected function _isActive()
31
+ {
32
+ $isActive = $this->_getConfigValue('active');
33
+
34
+ return $isActive ? true : false;
35
+ }
36
+
37
+ /**
38
+ *
39
+ * @param string $field
40
+ * @param string $group
41
+ *
42
+ * @return string|null
43
+ */
44
+ protected function _getConfigValue($field, $group = 'zitec_dpd')
45
+ {
46
+ $configValueData = $this->getData("groups/{$group}/fields/{$field}");
47
+ if (is_array($configValueData) && array_key_exists('value', $configValueData)) {
48
+ $configValue = $configValueData['value'];
49
+
50
+ return $configValue;
51
+ }
52
+
53
+ return null;
54
+ }
55
+
56
+ /**
57
+ *
58
+ * @return Zitec_Dpd_Helper_Data
59
+ */
60
+ protected function _getHelper()
61
+ {
62
+ return Mage::helper('zitec_dpd');
63
+ }
64
+
65
+ /**
66
+ *
67
+ * @return Zitec_Dpd_Helper_Ws
68
+ */
69
+ protected function _getWsHelper()
70
+ {
71
+ return Mage::helper('zitec_dpd/ws');
72
+ }
73
+ }
74
+
75
+
app/code/community/Zitec/Dpd/Model/Config/Data/Mode.php CHANGED
@@ -1,66 +1,66 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Config_Data_Mode extends Zitec_Dpd_Model_Config_Data_Abstract
25
- {
26
-
27
-
28
- /**
29
- * Validates that the country selected has a WS Url for the mode (production or test)
30
- *
31
- * @return void
32
- */
33
- protected function _afterSave()
34
- {
35
- if (!$this->_isActive()) {
36
- return;
37
- }
38
-
39
- $countryId = $this->_getCountryId();
40
- if (!$countryId || $countryId == Zitec_Dpd_Model_Config_Source_Wscountry::WS_COUNTRY_OTHER) {
41
- return;
42
- }
43
-
44
- if ($this->getValue()) { // Production mode
45
- if (!$this->_getWsHelper()->hasWsProductionUrl($countryId)) {
46
- Mage::throwException($this->_getHelper()->__("The country you have selected does not have a web service URL for production mode. Please ensure you have selected the correct country, or select 'Other (enter web service URLs manually)' to enter a specific URL."));
47
- }
48
- } else { // Test mode
49
- if (!$this->_getWsHelper()->hasWsTestUrl($countryId)) {
50
- Mage::throwException($this->_getHelper()->__("The country you have selected does not have a web service URL for test mode. Please ensure you have selected the correct country, or select 'Other (enter web service URLs manually)' to enter a specific URL."));
51
- }
52
- }
53
- }
54
-
55
- /**
56
- *
57
- * @return string
58
- */
59
- protected function _getCountryId()
60
- {
61
- return $this->_getConfigValue('wscountry');
62
- }
63
-
64
-
65
- }
66
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Config_Data_Mode extends Zitec_Dpd_Model_Config_Data_Abstract
25
+ {
26
+
27
+
28
+ /**
29
+ * Validates that the country selected has a WS Url for the mode (production or test)
30
+ *
31
+ * @return void
32
+ */
33
+ protected function _afterSave()
34
+ {
35
+ if (!$this->_isActive()) {
36
+ return;
37
+ }
38
+
39
+ $countryId = $this->_getCountryId();
40
+ if (!$countryId || $countryId == Zitec_Dpd_Model_Config_Source_Wscountry::WS_COUNTRY_OTHER) {
41
+ return;
42
+ }
43
+
44
+ if ($this->getValue()) { // Production mode
45
+ if (!$this->_getWsHelper()->hasWsProductionUrl($countryId)) {
46
+ Mage::throwException($this->_getHelper()->__("The country you have selected does not have a web service URL for production mode. Please ensure you have selected the correct country, or select 'Other (enter web service URLs manually)' to enter a specific URL."));
47
+ }
48
+ } else { // Test mode
49
+ if (!$this->_getWsHelper()->hasWsTestUrl($countryId)) {
50
+ Mage::throwException($this->_getHelper()->__("The country you have selected does not have a web service URL for test mode. Please ensure you have selected the correct country, or select 'Other (enter web service URLs manually)' to enter a specific URL."));
51
+ }
52
+ }
53
+ }
54
+
55
+ /**
56
+ *
57
+ * @return string
58
+ */
59
+ protected function _getCountryId()
60
+ {
61
+ return $this->_getConfigValue('wscountry');
62
+ }
63
+
64
+
65
+ }
66
+
app/code/community/Zitec/Dpd/Model/Config/Data/Tablerate.php CHANGED
@@ -1,47 +1,47 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Config_Data_Tablerate extends Mage_Core_Model_Config_Data
25
- {
26
-
27
- public function _afterSave()
28
- {
29
- try {
30
- Mage::getResourceModel('zitec_dpd/carrier_tablerate')->uploadAndImport($this);
31
- } catch (Exception $e) {
32
- $this->_getHelper()->addError(implode("<br />", explode("\n", $e->getMessage())));
33
- }
34
- }
35
-
36
- /**
37
- *
38
- * @return Zitec_Dpd_Helper_Data
39
- */
40
- protected function _getHelper()
41
- {
42
- return Mage::helper('zitec_dpd');
43
- }
44
-
45
- }
46
-
47
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Config_Data_Tablerate extends Mage_Core_Model_Config_Data
25
+ {
26
+
27
+ public function _afterSave()
28
+ {
29
+ try {
30
+ Mage::getResourceModel('zitec_dpd/carrier_tablerate')->uploadAndImport($this);
31
+ } catch (Exception $e) {
32
+ $this->_getHelper()->addError(implode("<br />", explode("\n", $e->getMessage())));
33
+ }
34
+ }
35
+
36
+ /**
37
+ *
38
+ * @return Zitec_Dpd_Helper_Data
39
+ */
40
+ protected function _getHelper()
41
+ {
42
+ return Mage::helper('zitec_dpd');
43
+ }
44
+
45
+ }
46
+
47
+
app/code/community/Zitec/Dpd/Model/Config/Source/Abstract.php CHANGED
@@ -1,58 +1,58 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Config_Source_Abstract
25
- {
26
-
27
-
28
- /**
29
- *
30
- * @return Zitec_Dpd_Helper_Data
31
- */
32
- protected function _getHelper()
33
- {
34
- return Mage::helper('zitec_dpd');
35
- }
36
-
37
- /**
38
- *
39
- * @return Zitec_Dpd_Helper_Ws
40
- */
41
- protected function _getWsHelper()
42
- {
43
- return Mage::helper('zitec_dpd/ws');
44
- }
45
-
46
- /**
47
- *
48
- * @param string $translateStr
49
- *
50
- * @return string
51
- */
52
- protected function __($translateStr)
53
- {
54
- return $this->_getHelper()->__($translateStr);
55
- }
56
- }
57
-
58
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Config_Source_Abstract
25
+ {
26
+
27
+
28
+ /**
29
+ *
30
+ * @return Zitec_Dpd_Helper_Data
31
+ */
32
+ protected function _getHelper()
33
+ {
34
+ return Mage::helper('zitec_dpd');
35
+ }
36
+
37
+ /**
38
+ *
39
+ * @return Zitec_Dpd_Helper_Ws
40
+ */
41
+ protected function _getWsHelper()
42
+ {
43
+ return Mage::helper('zitec_dpd/ws');
44
+ }
45
+
46
+ /**
47
+ *
48
+ * @param string $translateStr
49
+ *
50
+ * @return string
51
+ */
52
+ protected function __($translateStr)
53
+ {
54
+ return $this->_getHelper()->__($translateStr);
55
+ }
56
+ }
57
+
58
+
app/code/community/Zitec/Dpd/Model/Config/Source/Order/Status/Pendingpayment.php CHANGED
@@ -1,30 +1,30 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Config_Source_Order_Status_Pendingpayment extends Mage_Adminhtml_Model_System_Config_Source_Order_Status
25
- {
26
- protected $_stateStatuses = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT;
27
- }
28
-
29
-
30
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Config_Source_Order_Status_Pendingpayment extends Mage_Adminhtml_Model_System_Config_Source_Order_Status
25
+ {
26
+ protected $_stateStatuses = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT;
27
+ }
28
+
29
+
30
+
app/code/community/Zitec/Dpd/Model/Config/Source/Service.php CHANGED
@@ -1,113 +1,113 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Config_Source_Service extends Zitec_Dpd_Model_Config_Source_Abstract
25
- {
26
-
27
- public function toOptionArray($isMultiselect = false)
28
- {
29
-
30
- $services = array(
31
- '1' => $this->__('DPD Classic'),
32
- '10' => $this->__('DPD 10:00'),
33
- '9' => $this->__('DPD 12:00'),
34
- '109' => $this->__('DPD B2C'),
35
- '27' => $this->__('DPD Same Day'),
36
- '40033' => $this->__('DPD Classic International'),
37
- '40107' => $this->__('DPD Classic Bulgaria')
38
- );
39
-
40
- if ($isMultiselect) {
41
- $options = array();
42
- foreach ($services as $k => $v) {
43
- $options[] = array('label' => $k . ' - ' . $v, 'value' => $k);
44
- }
45
-
46
- return $options;
47
- } else {
48
- return $services;
49
- }
50
- }
51
-
52
- /**
53
- * return default values for all shipping service of dpd carrier to force using
54
- * api response amount for enabled services
55
- *
56
- * @return array
57
- */
58
- public function getDefaultShipingRates()
59
- {
60
- $rates = array();
61
- foreach ($this->toOptionArray() as $key => $value) {
62
- $rates[] = array(
63
- //'pk'=>14,
64
- 'website_id' => null,//1
65
- 'dest_country_id' => 0,
66
- 'dest_region_id' => 0,
67
- 'dest_zip' => '',
68
- 'weight' => 0,
69
- 'price' => 0,
70
- 'method' => $key,
71
- 'markup_type' => 1,
72
- 'cod_option' => 3,
73
- 'cashondelivery_surcharge' => "0%",
74
- 'cod_min_surcharge' => null,
75
- 'price_vs_dest' => 0,
76
- );
77
- }
78
-
79
- return $rates;
80
-
81
- }
82
-
83
-
84
- /**
85
- * return the payment rate with default values
86
- * it will return an array forcing the payment to be calculated as a percentage
87
- *
88
- * @return array
89
- */
90
- public function getDefaultPaymentRate()
91
- {
92
- $rate = array(
93
- 'website_id' => null,
94
- 'dest_country_id' => 0,
95
- 'dest_region_id' => 0,
96
- 'dest_zip' => '',
97
- 'weight' => 0,
98
- 'price' => 0,
99
- 'markup_type' => 1,
100
- 'cod_option' => 3,
101
- 'cashondelivery_surcharge' => "0%",
102
- 'cod_min_surcharge' => null,
103
- 'price_vs_dest' => 0,
104
- );
105
-
106
- return $rate;
107
-
108
- }
109
-
110
-
111
- }
112
-
113
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Config_Source_Service extends Zitec_Dpd_Model_Config_Source_Abstract
25
+ {
26
+
27
+ public function toOptionArray($isMultiselect = false)
28
+ {
29
+
30
+ $services = array(
31
+ '1' => $this->__('DPD Classic'),
32
+ '10' => $this->__('DPD 10:00'),
33
+ '9' => $this->__('DPD 12:00'),
34
+ '109' => $this->__('DPD B2C'),
35
+ '27' => $this->__('DPD Same Day'),
36
+ '40033' => $this->__('DPD Classic International'),
37
+ '40107' => $this->__('DPD Classic Bulgaria')
38
+ );
39
+
40
+ if ($isMultiselect) {
41
+ $options = array();
42
+ foreach ($services as $k => $v) {
43
+ $options[] = array('label' => $k . ' - ' . $v, 'value' => $k);
44
+ }
45
+
46
+ return $options;
47
+ } else {
48
+ return $services;
49
+ }
50
+ }
51
+
52
+ /**
53
+ * return default values for all shipping service of dpd carrier to force using
54
+ * api response amount for enabled services
55
+ *
56
+ * @return array
57
+ */
58
+ public function getDefaultShipingRates()
59
+ {
60
+ $rates = array();
61
+ foreach ($this->toOptionArray() as $key => $value) {
62
+ $rates[] = array(
63
+ //'pk'=>14,
64
+ 'website_id' => null,//1
65
+ 'dest_country_id' => 0,
66
+ 'dest_region_id' => 0,
67
+ 'dest_zip' => '',
68
+ 'weight' => 0,
69
+ 'price' => 0,
70
+ 'method' => $key,
71
+ 'markup_type' => 1,
72
+ 'cod_option' => 3,
73
+ 'cashondelivery_surcharge' => "0%",
74
+ 'cod_min_surcharge' => null,
75
+ 'price_vs_dest' => 0,
76
+ );
77
+ }
78
+
79
+ return $rates;
80
+
81
+ }
82
+
83
+
84
+ /**
85
+ * return the payment rate with default values
86
+ * it will return an array forcing the payment to be calculated as a percentage
87
+ *
88
+ * @return array
89
+ */
90
+ public function getDefaultPaymentRate()
91
+ {
92
+ $rate = array(
93
+ 'website_id' => null,
94
+ 'dest_country_id' => 0,
95
+ 'dest_region_id' => 0,
96
+ 'dest_zip' => '',
97
+ 'weight' => 0,
98
+ 'price' => 0,
99
+ 'markup_type' => 1,
100
+ 'cod_option' => 3,
101
+ 'cashondelivery_surcharge' => "0%",
102
+ 'cod_min_surcharge' => null,
103
+ 'price_vs_dest' => 0,
104
+ );
105
+
106
+ return $rate;
107
+
108
+ }
109
+
110
+
111
+ }
112
+
113
+
app/code/community/Zitec/Dpd/Model/Config/Source/Wscountry.php CHANGED
@@ -1,57 +1,57 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Config_Source_Wscountry extends Zitec_Dpd_Model_Config_Source_Abstract
25
- {
26
-
27
- const WS_COUNTRY_OTHER = 'zOther';
28
-
29
- public function toOptionArray()
30
- {
31
- $countryCollection = Mage::getResourceModel('directory/country_collection');
32
- /* @var $countryCollection Mage_Directory_Model_Resource_Country_Collection */
33
- $countryOptions = $countryCollection->toOptionArray();
34
-
35
-
36
- $countries = array();
37
- $countries[0] = array('value' => 0, 'label' => $this->__('-- Please select an option --'));
38
- foreach ($countryOptions as $option) {
39
- if(!empty($option['label']) && !empty($option['value'])) {
40
- $countries[$option['value']] = array('value' => $option['value'], 'label' => $option['label']);
41
- }
42
- }
43
- $countries[self::WS_COUNTRY_OTHER] = array('value' => self::WS_COUNTRY_OTHER, 'label' => $this->__('Other (enter web service URLs manually)'));
44
-
45
- // Only include the countries that have web service URLs defined.
46
- $countryIds = array_keys($countries);
47
- foreach ($countryIds as $countryId) {
48
- if ($countryId && $countryId != 'zOther' && !$this->_getWsHelper()->hasWsUrls($countryId)) {
49
- unset($countries[$countryId]);
50
- }
51
- }
52
-
53
- return $countries;
54
- }
55
- }
56
-
57
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Config_Source_Wscountry extends Zitec_Dpd_Model_Config_Source_Abstract
25
+ {
26
+
27
+ const WS_COUNTRY_OTHER = 'zOther';
28
+
29
+ public function toOptionArray()
30
+ {
31
+ $countryCollection = Mage::getResourceModel('directory/country_collection');
32
+ /* @var $countryCollection Mage_Directory_Model_Resource_Country_Collection */
33
+ $countryOptions = $countryCollection->toOptionArray();
34
+
35
+
36
+ $countries = array();
37
+ $countries[0] = array('value' => 0, 'label' => $this->__('-- Please select an option --'));
38
+ foreach ($countryOptions as $option) {
39
+ if(!empty($option['label']) && !empty($option['value'])) {
40
+ $countries[$option['value']] = array('value' => $option['value'], 'label' => $option['label']);
41
+ }
42
+ }
43
+ $countries[self::WS_COUNTRY_OTHER] = array('value' => self::WS_COUNTRY_OTHER, 'label' => $this->__('Other (enter web service URLs manually)'));
44
+
45
+ // Only include the countries that have web service URLs defined.
46
+ $countryIds = array_keys($countries);
47
+ foreach ($countryIds as $countryId) {
48
+ if ($countryId && $countryId != 'zOther' && !$this->_getWsHelper()->hasWsUrls($countryId)) {
49
+ unset($countries[$countryId]);
50
+ }
51
+ }
52
+
53
+ return $countries;
54
+ }
55
+ }
56
+
57
+
app/code/community/Zitec/Dpd/Model/Dpd/Manifest.php CHANGED
@@ -1,297 +1,297 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Dpd_Manifest extends Mage_Core_Model_Abstract
25
- {
26
-
27
- /**
28
- *
29
- * @var array
30
- */
31
- protected $_notifications = array();
32
-
33
- protected $_shipsForManifest = array();
34
-
35
-
36
- public function _construct()
37
- {
38
- $this->_init('zitec_dpd/dpd_manifest');
39
- }
40
-
41
- /**
42
- *
43
- * @param array|int|null $shipmentIds
44
- *
45
- * @return boolean
46
- */
47
- public function createManifestForShipments($shipmentIds)
48
- {
49
- $this->_clearNotifications();
50
-
51
- if ($shipmentIds && is_numeric($shipmentIds)) {
52
- $shipmentIds = array($shipmentIds);
53
- }
54
-
55
- if (!$shipmentIds || !is_array($shipmentIds)) {
56
- $message = $this->_getHelper()->__("Please select the shipments to include in the closed manifest.");
57
- $this->_addNotification($message);
58
-
59
- return false;
60
- }
61
-
62
-
63
- $shipments = Mage::getResourceModel('sales/order_shipment_collection');
64
- /* @var $shipments Mage_Sales_Model_Resource_Order_Shipment_Collection */
65
- $shipments->addFieldToFilter('entity_id', array("in" => $shipmentIds));
66
-
67
- $ships = Mage::getResourceModel('zitec_dpd/dpd_ship_collection');
68
- /* @var $ships Zitec_Dpd_Model_Mysql4_Dpd_Ship_Collection */
69
- $ships->filterByShipmentIds($shipmentIds);
70
-
71
- $shipmentsForManifest = array();
72
- $shipsForManifest = array();
73
- $manifestParams = null;
74
- foreach ($shipments as $shipment) {
75
- /* @var $shipment Mage_Sales_Model_Order_Shipment */
76
- if (!$this->_getHelper()->isShippingMethodDpd($shipment->getOrder()->getShippingMethod())) {
77
- $message = "Could not include shipment %s in the manifest because it is not a DPD shipment.";
78
- $this->_addNotification($this->_getHelper()->__($message, $shipment->getIncrementId()), true);
79
- continue;
80
- }
81
-
82
- $ship = $ships->findByShipmentId($shipment->getId());
83
- /* @var $ship Zitec_Dpd_Model_Dpd_Ship */
84
- if (!$ship) {
85
- $message = "Could not include shipment %s in the manifest because it was not communicated to DPD.";
86
- $this->_addNotification($this->_getHelper()->__($message, $shipment->getIncrementId()), true);
87
- continue;
88
- }
89
-
90
- if ($this->_getHelper()->isCancelledWithDpd($shipment)) {
91
- $message = "Could not include shipment %s in the manifest because it was cancelled with DPD.";
92
- $this->_addNotification($this->_getHelper()->__($message, $shipment->getIncrementId()), true);
93
- continue;
94
- }
95
-
96
- if ($ship->getManifestId()) {
97
- $message = "Could not include shipment %s in the manifest because it is already in a manifest.";
98
- $this->_addNotification($this->_getHelper()->__($message, $shipment->getIncrementId()), true);
99
- continue;
100
- }
101
-
102
- $storeManifestParams = $this->_getWsHelper()->getManifestParams($shipment->getOrder()->getStore());
103
- if (isset($manifestParams) && $storeManifestParams != $manifestParams) {
104
- $this->_clearNotifications();
105
- $message = "The shipments you selected come from different stores which have different DPD connection parameters. Please select shipments which belong " .
106
- "to stores that use the same DPD connection parameters.";
107
- $this->_addNotification($this->_getHelper()->__($message));
108
-
109
- return false;
110
- } else {
111
- $manifestParams = $storeManifestParams;
112
- }
113
-
114
- $this->_addNotification($this->_getHelper()->__('Shipment %s was added to the manifest.', $shipment->getIncrementId()));
115
-
116
- $shipmentsForManifest[] = $shipment;
117
- $shipsForManifest[] = $ship;
118
- }
119
-
120
- if (count($shipmentsForManifest) == 0) {
121
- $this->_clearNotificationErrorStyles();
122
- $this->_addNotification("None of the shipments selected could be included in a manifest.");
123
-
124
- return false;
125
- }
126
-
127
- $manifestParams['method'] = Zitec_Dpd_Api_Configs::METHOD_MANIFEST_CLOSE;
128
- $dpdApi = new Zitec_Dpd_Api($manifestParams);
129
- $closeManifest = $dpdApi->getApiMethodObject();
130
-
131
- foreach ($shipmentsForManifest as $index => $shipment) {
132
- /* @var $shipment Mage_Sales_Model_Order_Shipment */
133
- $ship = $shipsForManifest[$index];
134
- /* @var $ship Zitec_Dpd_Model_Dpd_Ship */
135
- $shipResponse = unserialize($ship->getSaveShipmentResponse());
136
- /* @var $response Zitec_Dpd_Api_Shipment_Save_Response */
137
- $closeManifest->addShipment($shipResponse->getDpdShipmentId(), $shipResponse->getDpdShipmentReferenceNumber());
138
- if ($index == 0) {
139
- $closeManifest->setManifestReferenceNumber($shipResponse->getDpdShipmentReferenceNumber());
140
- }
141
- }
142
-
143
- try {
144
- $closeManifest->execute();
145
- } catch (Exception $e) {
146
- $this->_clearNotifications();
147
- $this->_addNotification($this->_getHelper()->__("An error occurred whilst requesting the manifest from DPD: %s", $e->getMessage()));
148
-
149
- return false;
150
- }
151
-
152
- $response = $closeManifest->getCloseManifestResponse();
153
- if ($response->hasError()) {
154
- $this->_clearNotifications();
155
- $this->_addNotification($this->_getHelper()->__('An error occurred whilst communicating the manifest details to DPD. DPD says: "%s"', $response->getErrorText()));
156
-
157
- return false;
158
- }
159
-
160
- $this->setManifestRef($response->getManifestReferenceNumber());
161
- $this->setManifestDpdId($response->getManifestId());
162
- $this->setManifestDpdName($response->getManifestName());
163
- $this->setPdf(base64_encode($response->getPdfFile()));
164
- $this->setShipsForManifest($shipsForManifest);
165
-
166
- try {
167
- $this->save();
168
-
169
- } catch (Exception $e) {
170
- $this->_clearNotificationErrorStyles();
171
- $message = "The manifest was communicated successfully to DPD, but an error occurred whilst saving the manifest details in Magento. <br />" .
172
- "Please make a capture of this screen so that you have a record of the shipments included in the manifest. <br />" .
173
-
174
- "For you reference when communicating with DPD, the manifest details are: <br /> " .
175
- "Manifest Reference: %s <br />" .
176
- "Manifest Name: %s <br />" .
177
- "Manifest internal DPD ID: %s <br />" .
178
- "The error message returned was: %s";
179
-
180
- $this->_addNotification($this->_getHelper()->__($message, $this->getManifestRef(), $this->getManifestDpdId(), $this->getManifestDpdName(), $e->getMessage()));
181
- $this->_getHelper()->log(sprintf($message, $this->getManifestRef(), $this->getManifestDpdId(), $this->getManifestDpdName(), $e->getMessage()));
182
-
183
- return false;
184
-
185
- }
186
-
187
- return true;
188
- }
189
-
190
-
191
- /**
192
- *
193
- * @return \Zitec_Dpd_Model_Dpd_Manifest
194
- */
195
- protected function _clearNotifications()
196
- {
197
- $this->_notifications = array();
198
-
199
- return $this;
200
- }
201
-
202
- /**
203
- *
204
- * @param string $message
205
- *
206
- * @return \Zitec_Dpd_Model_Dpd_Manifest
207
- */
208
- protected function _addNotification($message, $error = false)
209
- {
210
- $this->_notifications[] = $this->_setNotificationErrorStyle($message, $error);
211
-
212
- return $this;
213
- }
214
-
215
- /**
216
- *
217
- * @return \Zitec_Dpd_Model_Dpd_Manifest
218
- */
219
- protected function _clearNotificationErrorStyles()
220
- {
221
- foreach ($this->_notifications as $index => $notification) {
222
- $this->_notifications[$index] = $this->_setNotificationErrorStyle($notification, false);
223
- }
224
-
225
- return $this;
226
- }
227
-
228
- /**
229
- *
230
- * @param string $message
231
- * @param boolean $on
232
- *
233
- * @return string
234
- */
235
- protected function _setNotificationErrorStyle($message, $on)
236
- {
237
- $openTag = '<span class="error-msg">';
238
- $closeTag = '</span>';
239
- $message = str_replace($openTag, '', $message);
240
- $message = str_replace($closeTag, '', $message);
241
- if ($on) {
242
- $message = $openTag . $message . $closeTag;
243
- }
244
-
245
- return $message;
246
- }
247
-
248
- /**
249
- *
250
- * @param array $shipsForManifest
251
- *
252
- * @return \Zitec_Dpd_Model_Dpd_Manifest
253
- */
254
- public function setShipsForManifest(array $shipsForManifest)
255
- {
256
- $this->_shipsForManifest = $shipsForManifest;
257
-
258
- return $this;
259
- }
260
-
261
- /**
262
- *
263
- * @return array
264
- */
265
- public function getShipsForManifest()
266
- {
267
- return $this->_shipsForManifest;
268
- }
269
-
270
- /**
271
- *
272
- * @return array
273
- */
274
- public function getNotifications()
275
- {
276
- return $this->_notifications;
277
- }
278
-
279
- /**
280
- *
281
- * @return Zitec_Dpd_Helper_Data
282
- */
283
- protected function _getHelper()
284
- {
285
- return Mage::helper('zitec_dpd');
286
- }
287
-
288
- /**
289
- *
290
- * @return Zitec_Dpd_Helper_Ws
291
- */
292
- protected function _getWsHelper()
293
- {
294
- return Mage::helper('zitec_dpd/ws');
295
- }
296
-
297
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Dpd_Manifest extends Mage_Core_Model_Abstract
25
+ {
26
+
27
+ /**
28
+ *
29
+ * @var array
30
+ */
31
+ protected $_notifications = array();
32
+
33
+ protected $_shipsForManifest = array();
34
+
35
+
36
+ public function _construct()
37
+ {
38
+ $this->_init('zitec_dpd/dpd_manifest');
39
+ }
40
+
41
+ /**
42
+ *
43
+ * @param array|int|null $shipmentIds
44
+ *
45
+ * @return boolean
46
+ */
47
+ public function createManifestForShipments($shipmentIds)
48
+ {
49
+ $this->_clearNotifications();
50
+
51
+ if ($shipmentIds && is_numeric($shipmentIds)) {
52
+ $shipmentIds = array($shipmentIds);
53
+ }
54
+
55
+ if (!$shipmentIds || !is_array($shipmentIds)) {
56
+ $message = $this->_getHelper()->__("Please select the shipments to include in the closed manifest.");
57
+ $this->_addNotification($message);
58
+
59
+ return false;
60
+ }
61
+
62
+
63
+ $shipments = Mage::getResourceModel('sales/order_shipment_collection');
64
+ /* @var $shipments Mage_Sales_Model_Resource_Order_Shipment_Collection */
65
+ $shipments->addFieldToFilter('entity_id', array("in" => $shipmentIds));
66
+
67
+ $ships = Mage::getResourceModel('zitec_dpd/dpd_ship_collection');
68
+ /* @var $ships Zitec_Dpd_Model_Mysql4_Dpd_Ship_Collection */
69
+ $ships->filterByShipmentIds($shipmentIds);
70
+
71
+ $shipmentsForManifest = array();
72
+ $shipsForManifest = array();
73
+ $manifestParams = null;
74
+ foreach ($shipments as $shipment) {
75
+ /* @var $shipment Mage_Sales_Model_Order_Shipment */
76
+ if (!$this->_getHelper()->isShippingMethodDpd($shipment->getOrder()->getShippingMethod())) {
77
+ $message = "Could not include shipment %s in the manifest because it is not a DPD shipment.";
78
+ $this->_addNotification($this->_getHelper()->__($message, $shipment->getIncrementId()), true);
79
+ continue;
80
+ }
81
+
82
+ $ship = $ships->findByShipmentId($shipment->getId());
83
+ /* @var $ship Zitec_Dpd_Model_Dpd_Ship */
84
+ if (!$ship) {
85
+ $message = "Could not include shipment %s in the manifest because it was not communicated to DPD.";
86
+ $this->_addNotification($this->_getHelper()->__($message, $shipment->getIncrementId()), true);
87
+ continue;
88
+ }
89
+
90
+ if ($this->_getHelper()->isCancelledWithDpd($shipment)) {
91
+ $message = "Could not include shipment %s in the manifest because it was cancelled with DPD.";
92
+ $this->_addNotification($this->_getHelper()->__($message, $shipment->getIncrementId()), true);
93
+ continue;
94
+ }
95
+
96
+ if ($ship->getManifestId()) {
97
+ $message = "Could not include shipment %s in the manifest because it is already in a manifest.";
98
+ $this->_addNotification($this->_getHelper()->__($message, $shipment->getIncrementId()), true);
99
+ continue;
100
+ }
101
+
102
+ $storeManifestParams = $this->_getWsHelper()->getManifestParams($shipment->getOrder()->getStore());
103
+ if (isset($manifestParams) && $storeManifestParams != $manifestParams) {
104
+ $this->_clearNotifications();
105
+ $message = "The shipments you selected come from different stores which have different DPD connection parameters. Please select shipments which belong " .
106
+ "to stores that use the same DPD connection parameters.";
107
+ $this->_addNotification($this->_getHelper()->__($message));
108
+
109
+ return false;
110
+ } else {
111
+ $manifestParams = $storeManifestParams;
112
+ }
113
+
114
+ $this->_addNotification($this->_getHelper()->__('Shipment %s was added to the manifest.', $shipment->getIncrementId()));
115
+
116
+ $shipmentsForManifest[] = $shipment;
117
+ $shipsForManifest[] = $ship;
118
+ }
119
+
120
+ if (count($shipmentsForManifest) == 0) {
121
+ $this->_clearNotificationErrorStyles();
122
+ $this->_addNotification("None of the shipments selected could be included in a manifest.");
123
+
124
+ return false;
125
+ }
126
+
127
+ $manifestParams['method'] = Zitec_Dpd_Api_Configs::METHOD_MANIFEST_CLOSE;
128
+ $dpdApi = new Zitec_Dpd_Api($manifestParams);
129
+ $closeManifest = $dpdApi->getApiMethodObject();
130
+
131
+ foreach ($shipmentsForManifest as $index => $shipment) {
132
+ /* @var $shipment Mage_Sales_Model_Order_Shipment */
133
+ $ship = $shipsForManifest[$index];
134
+ /* @var $ship Zitec_Dpd_Model_Dpd_Ship */
135
+ $shipResponse = unserialize($ship->getSaveShipmentResponse());
136
+ /* @var $response Zitec_Dpd_Api_Shipment_Save_Response */
137
+ $closeManifest->addShipment($shipResponse->getDpdShipmentId(), $shipResponse->getDpdShipmentReferenceNumber());
138
+ if ($index == 0) {
139
+ $closeManifest->setManifestReferenceNumber($shipResponse->getDpdShipmentReferenceNumber());
140
+ }
141
+ }
142
+
143
+ try {
144
+ $closeManifest->execute();
145
+ } catch (Exception $e) {
146
+ $this->_clearNotifications();
147
+ $this->_addNotification($this->_getHelper()->__("An error occurred whilst requesting the manifest from DPD: %s", $e->getMessage()));
148
+
149
+ return false;
150
+ }
151
+
152
+ $response = $closeManifest->getCloseManifestResponse();
153
+ if ($response->hasError()) {
154
+ $this->_clearNotifications();
155
+ $this->_addNotification($this->_getHelper()->__('An error occurred whilst communicating the manifest details to DPD. DPD says: "%s"', $response->getErrorText()));
156
+
157
+ return false;
158
+ }
159
+
160
+ $this->setManifestRef($response->getManifestReferenceNumber());
161
+ $this->setManifestDpdId($response->getManifestId());
162
+ $this->setManifestDpdName($response->getManifestName());
163
+ $this->setPdf(base64_encode($response->getPdfFile()));
164
+ $this->setShipsForManifest($shipsForManifest);
165
+
166
+ try {
167
+ $this->save();
168
+
169
+ } catch (Exception $e) {
170
+ $this->_clearNotificationErrorStyles();
171
+ $message = "The manifest was communicated successfully to DPD, but an error occurred whilst saving the manifest details in Magento. <br />" .
172
+ "Please make a capture of this screen so that you have a record of the shipments included in the manifest. <br />" .
173
+
174
+ "For you reference when communicating with DPD, the manifest details are: <br /> " .
175
+ "Manifest Reference: %s <br />" .
176
+ "Manifest Name: %s <br />" .
177
+ "Manifest internal DPD ID: %s <br />" .
178
+ "The error message returned was: %s";
179
+
180
+ $this->_addNotification($this->_getHelper()->__($message, $this->getManifestRef(), $this->getManifestDpdId(), $this->getManifestDpdName(), $e->getMessage()));
181
+ $this->_getHelper()->log(sprintf($message, $this->getManifestRef(), $this->getManifestDpdId(), $this->getManifestDpdName(), $e->getMessage()));
182
+
183
+ return false;
184
+
185
+ }
186
+
187
+ return true;
188
+ }
189
+
190
+
191
+ /**
192
+ *
193
+ * @return \Zitec_Dpd_Model_Dpd_Manifest
194
+ */
195
+ protected function _clearNotifications()
196
+ {
197
+ $this->_notifications = array();
198
+
199
+ return $this;
200
+ }
201
+
202
+ /**
203
+ *
204
+ * @param string $message
205
+ *
206
+ * @return \Zitec_Dpd_Model_Dpd_Manifest
207
+ */
208
+ protected function _addNotification($message, $error = false)
209
+ {
210
+ $this->_notifications[] = $this->_setNotificationErrorStyle($message, $error);
211
+
212
+ return $this;
213
+ }
214
+
215
+ /**
216
+ *
217
+ * @return \Zitec_Dpd_Model_Dpd_Manifest
218
+ */
219
+ protected function _clearNotificationErrorStyles()
220
+ {
221
+ foreach ($this->_notifications as $index => $notification) {
222
+ $this->_notifications[$index] = $this->_setNotificationErrorStyle($notification, false);
223
+ }
224
+
225
+ return $this;
226
+ }
227
+
228
+ /**
229
+ *
230
+ * @param string $message
231
+ * @param boolean $on
232
+ *
233
+ * @return string
234
+ */
235
+ protected function _setNotificationErrorStyle($message, $on)
236
+ {
237
+ $openTag = '<span class="error-msg">';
238
+ $closeTag = '</span>';
239
+ $message = str_replace($openTag, '', $message);
240
+ $message = str_replace($closeTag, '', $message);
241
+ if ($on) {
242
+ $message = $openTag . $message . $closeTag;
243
+ }
244
+
245
+ return $message;
246
+ }
247
+
248
+ /**
249
+ *
250
+ * @param array $shipsForManifest
251
+ *
252
+ * @return \Zitec_Dpd_Model_Dpd_Manifest
253
+ */
254
+ public function setShipsForManifest(array $shipsForManifest)
255
+ {
256
+ $this->_shipsForManifest = $shipsForManifest;
257
+
258
+ return $this;
259
+ }
260
+
261
+ /**
262
+ *
263
+ * @return array
264
+ */
265
+ public function getShipsForManifest()
266
+ {
267
+ return $this->_shipsForManifest;
268
+ }
269
+
270
+ /**
271
+ *
272
+ * @return array
273
+ */
274
+ public function getNotifications()
275
+ {
276
+ return $this->_notifications;
277
+ }
278
+
279
+ /**
280
+ *
281
+ * @return Zitec_Dpd_Helper_Data
282
+ */
283
+ protected function _getHelper()
284
+ {
285
+ return Mage::helper('zitec_dpd');
286
+ }
287
+
288
+ /**
289
+ *
290
+ * @return Zitec_Dpd_Helper_Ws
291
+ */
292
+ protected function _getWsHelper()
293
+ {
294
+ return Mage::helper('zitec_dpd/ws');
295
+ }
296
+
297
  }
app/code/community/Zitec/Dpd/Model/Dpd/Pickup.php CHANGED
@@ -1,41 +1,41 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- /**
25
- * @method Zitec_Dpd_Model_Dpd_Pickup setReference($reference)
26
- * @method Zitec_Dpd_Model_Dpd_Pickup setDpdId($dpdId)
27
- * @method Zitec_Dpd_Model_Dpd_Pickup setPickupDate($pickupDate)
28
- * @method Zitec_Dpd_Model_Dpd_Pickup setPickupTimeFrom($from)
29
- * @method Zitec_Dpd_Model_Dpd_Pickup setPickupTimeTo($to)
30
- * @method Zitec_Dpd_Model_Dpd_Pickup setCallData($callData)
31
- * @method Zitec_Dpd_Model_Dpd_Pickup setResponseData($responseData)
32
- */
33
- class Zitec_Dpd_Model_Dpd_Pickup extends Mage_Core_Model_Abstract
34
- {
35
- public function _construct()
36
- {
37
- $this->_init('zitec_dpd/dpd_pickup');
38
- }
39
- }
40
-
41
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ /**
25
+ * @method Zitec_Dpd_Model_Dpd_Pickup setReference($reference)
26
+ * @method Zitec_Dpd_Model_Dpd_Pickup setDpdId($dpdId)
27
+ * @method Zitec_Dpd_Model_Dpd_Pickup setPickupDate($pickupDate)
28
+ * @method Zitec_Dpd_Model_Dpd_Pickup setPickupTimeFrom($from)
29
+ * @method Zitec_Dpd_Model_Dpd_Pickup setPickupTimeTo($to)
30
+ * @method Zitec_Dpd_Model_Dpd_Pickup setCallData($callData)
31
+ * @method Zitec_Dpd_Model_Dpd_Pickup setResponseData($responseData)
32
+ */
33
+ class Zitec_Dpd_Model_Dpd_Pickup extends Mage_Core_Model_Abstract
34
+ {
35
+ public function _construct()
36
+ {
37
+ $this->_init('zitec_dpd/dpd_pickup');
38
+ }
39
+ }
40
+
41
+
app/code/community/Zitec/Dpd/Model/Dpd/Ship.php CHANGED
@@ -1,40 +1,40 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- /**
25
- * @method string getSaveShipmentCall()
26
- * @method string getSaveShipmentResponse()
27
- * @method string getShippingLabels()
28
- * @method string getManifest()
29
- */
30
- class Zitec_Dpd_Model_Dpd_Ship extends Mage_Core_Model_Abstract
31
- {
32
-
33
- public function _construct()
34
- {
35
- $this->_init('zitec_dpd/dpd_ship');
36
- }
37
-
38
- }
39
-
40
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ /**
25
+ * @method string getSaveShipmentCall()
26
+ * @method string getSaveShipmentResponse()
27
+ * @method string getShippingLabels()
28
+ * @method string getManifest()
29
+ */
30
+ class Zitec_Dpd_Model_Dpd_Ship extends Mage_Core_Model_Abstract
31
+ {
32
+
33
+ public function _construct()
34
+ {
35
+ $this->_init('zitec_dpd/dpd_ship');
36
+ }
37
+
38
+ }
39
+
40
+
app/code/community/Zitec/Dpd/Model/Mysql4/Carrier/Tablerate.php CHANGED
@@ -1,735 +1,735 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Mysql4_Carrier_Tablerate extends Mage_Core_Model_Mysql4_Abstract
25
- {
26
-
27
- const CSV_COL_IDX_COUNTRY_ID = 0;
28
- const CSV_COL_IDX_REGION = 1;
29
- const CSV_COL_IDX_ZIP = 2;
30
- const CSV_COL_IDX_WEIGHT = 3;
31
- const CSV_COL_IDX_PRICE = 4;
32
- const CSV_COL_IDX_METHOD = 5;
33
- const CSV_COL_IDX_COD_SURCHARGE = 6;
34
- const CSV_COL_IDX_COD_MIN_SURCHARGE = 7;
35
- const CSV_COL_IDX_COD_PRICE_VS_DEST = 8;
36
-
37
-
38
- const CSV_COL_COUNT = 9;
39
-
40
-
41
- /**
42
- * Import table rates website ID
43
- *
44
- * @var int
45
- */
46
- protected $_importWebsiteId = 0;
47
-
48
- /**
49
- * Errors in import process
50
- *
51
- * @var array
52
- */
53
- protected $_importErrors = array();
54
-
55
- /**
56
- * Count of imported table rates
57
- *
58
- * @var int
59
- */
60
- protected $_importedRows = 0;
61
-
62
- /**
63
- * Array of unique table rate keys to protect from duplicates
64
- *
65
- * @var array
66
- */
67
- protected $_importUniqueHash = array();
68
-
69
- /**
70
- * Array of countries keyed by iso2 code
71
- *
72
- * @var array
73
- */
74
- protected $_importIso2Countries;
75
-
76
- /**
77
- * Array of countries keyed by iso3 code
78
- *
79
- * @var array
80
- */
81
- protected $_importIso3Countries;
82
-
83
- /**
84
- * Associative array of countries and regions
85
- * [country_id][region_code] = region_id
86
- * [country_id][default_name] = region_id
87
- *
88
- * @var array
89
- */
90
- protected $_importRegions;
91
-
92
-
93
- /**
94
- * Import Table Rate condition name
95
- *
96
- * @var string
97
- */
98
- protected $_importConditionName;
99
-
100
- /**
101
- * Array of condition full names
102
- *
103
- * @var array
104
- */
105
- protected $_conditionFullNames = array();
106
-
107
- /**
108
- * List of valid method codes
109
- *
110
- * @var array
111
- */
112
- protected $_validMethods = null;
113
-
114
- /**
115
- * Define main table and id field name
116
- *
117
- * @return void
118
- */
119
- protected function _construct()
120
- {
121
- $this->_init('zitec_dpd/carrier_tablerate', 'pk');
122
- }
123
-
124
- /**
125
- * Return table rate array or false by rate request
126
- *
127
- * @param Mage_Shipping_Model_Rate_Request $request
128
- *
129
- * @return array|false
130
- */
131
- public function getRate(Mage_Shipping_Model_Rate_Request $request)
132
- {
133
- $adapter = $this->_getReadAdapter();
134
- $bind = array(
135
- ':website_id' => (int)$request->getWebsiteId(),
136
- ':country_id' => $request->getDestCountryId(),
137
- ':region_id' => $request->getDestRegionId(),
138
- ':postcode' => $request->getDestPostcode(),
139
- ':weight' => (float)$request->getPackageWeight(),
140
- ':price' => (float)$request->getData('zitec_table_price')
141
- );
142
- $select = $adapter->select()
143
- ->from($this->getMainTable())
144
- ->where('website_id=:website_id')
145
- ->order(array('dest_country_id DESC', 'dest_region_id DESC', 'dest_zip DESC', 'method DESC', 'price_vs_dest DESC', 'weight DESC'));
146
-
147
-
148
- // render destination condition
149
- $orWhere = '(' . implode(') OR (', array(
150
- "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = :postcode",
151
- "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = ''",
152
- "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = ''",
153
- "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = :postcode",
154
- "dest_country_id = '0' AND dest_region_id = 0 AND dest_zip = ''",
155
- )) . ')';
156
- $select->where($orWhere);
157
- $select->where('((weight <= :weight and price_vs_dest = 0) or (weight <= :price and price_vs_dest = 1))');
158
- $rates = $adapter->fetchAll($select, $bind);
159
-
160
- if (empty($rates)) {
161
- $rates = Mage::getModel('zitec_dpd/config_source_service')->getDefaultShipingRates();
162
- }
163
-
164
- return $rates;
165
- }
166
-
167
- /**
168
- * Upload table rate file and import data from it
169
- *
170
- * @param Varien_Object $object
171
- *
172
- * @throws Mage_Core_Exception
173
- * @return Mage_Shipping_Model_Mysql4_Carrier_Tablerate
174
- */
175
- public function uploadAndImport(Varien_Object $object, $csvFile = null)
176
- {
177
- $this->_log(__METHOD__);
178
-
179
- if (!$csvFile && !empty($_FILES['groups']['tmp_name']['zitec_dpd']['fields']['import']['value'])) {
180
- $csvFile = $_FILES['groups']['tmp_name']['zitec_dpd']['fields']['import']['value'];
181
- }
182
- if (!$csvFile) {
183
- return $this;
184
- }
185
-
186
-
187
- $website = Mage::app()->getWebsite($object->getScopeId());
188
-
189
- $this->_importWebsiteId = (int)$website->getId();
190
- $this->_importUniqueHash = array();
191
- $this->_importErrors = array();
192
- $this->_importedRows = 0;
193
-
194
- $io = new Varien_Io_File();
195
- $info = pathinfo($csvFile);
196
- $io->open(array('path' => $info['dirname']));
197
- $io->streamOpen($info['basename'], 'r');
198
-
199
- // check and skip headers
200
- $headers = $io->streamReadCsv();
201
- if ($headers === false || count($headers) < self::CSV_COL_COUNT) {
202
- $io->streamClose();
203
- Mage::throwException($this->_getHelper()->__('Invalid Table Rates File Format'));
204
- }
205
-
206
-
207
- $adapter = $this->_getWriteAdapter();
208
- $adapter->beginTransaction();
209
-
210
- try {
211
- $rowNumber = 1;
212
- $importData = array();
213
-
214
- $this->_loadDirectoryCountries();
215
- $this->_loadDirectoryRegions();
216
-
217
- // delete old data by website and condition name
218
- $condition = array(
219
- 'website_id = ?' => $this->_importWebsiteId,
220
- );
221
- $adapter->delete($this->getMainTable(), $condition);
222
-
223
- while (false !== ($csvLine = $io->streamReadCsv())) {
224
- $rowNumber++;
225
- if (is_array($csvLine)) {
226
- foreach ($csvLine as &$cell) {
227
- $cell = filter_var($cell, FILTER_SANITIZE_STRING);
228
- }
229
- }
230
-
231
- if (empty($csvLine)) {
232
- continue;
233
- }
234
-
235
- $row = $this->_getImportRow($csvLine, $rowNumber);
236
- if ($row !== false) {
237
- $importData[] = $row;
238
- }
239
-
240
- if (count($importData) == 5000) {
241
- $this->_saveImportData($importData);
242
- $importData = array();
243
- }
244
- }
245
- $this->_saveImportData($importData);
246
- $io->streamClose();
247
- } catch (Mage_Core_Exception $e) {
248
- $adapter->rollback();
249
- $io->streamClose();
250
- Mage::throwException($e->getMessage());
251
- } catch (Exception $e) {
252
- $adapter->rollback();
253
- $io->streamClose();
254
- $this->_log($e->getMessage());
255
- Mage::throwException($this->_getHelper()->__('An error occurred while import table rates.'));
256
- }
257
-
258
- $adapter->commit();
259
-
260
- if ($this->_importErrors) {
261
- array_unshift($this->_importErrors, "");
262
- $error = $this->_getHelper()->__('%1$d records have been imported. See the following list of errors for each record that has not been imported: %2$s', $this->_importedRows, implode(" \n", $this->_importErrors));
263
- Mage::throwException($error);
264
- }
265
-
266
- return $this;
267
- }
268
-
269
- /**
270
- * Load directory countries
271
- *
272
- * @return Mage_Shipping_Model_Mysql4_Carrier_Tablerate
273
- */
274
- protected function _loadDirectoryCountries()
275
- {
276
- if (!is_null($this->_importIso2Countries) && !is_null($this->_importIso3Countries)) {
277
- return $this;
278
- }
279
-
280
- $this->_importIso2Countries = array();
281
- $this->_importIso3Countries = array();
282
-
283
- /** @var $collection Mage_Directory_Model_Mysql4_Country_Collection */
284
- $collection = Mage::getResourceModel('directory/country_collection');
285
- foreach ($collection->getData() as $row) {
286
- $this->_importIso2Countries[$row['iso2_code']] = $row['country_id'];
287
- $this->_importIso3Countries[$row['iso3_code']] = $row['country_id'];
288
- }
289
-
290
- return $this;
291
- }
292
-
293
- /**
294
- * Load directory regions
295
- *
296
- * @return Mage_Shipping_Model_Mysql4_Carrier_Tablerate
297
- */
298
- protected function _loadDirectoryRegions()
299
- {
300
- if (!is_null($this->_importRegions)) {
301
- return $this;
302
- }
303
-
304
- $this->_importRegions = array();
305
-
306
- /** @var $collection Mage_Directory_Model_Mysql4_Region_Collection */
307
- $collection = Mage::getResourceModel('directory/region_collection');
308
- foreach ($collection->getData() as $row) {
309
- $this->_importRegions[$row['country_id']][$row['code']] = (int)$row['region_id'];
310
- $this->_importRegions[$row['country_id']][$row['default_name']] = (int)$row['region_id'];
311
- }
312
-
313
- return $this;
314
- }
315
-
316
- /**
317
- * Return import condition full name by condition name code
318
- *
319
- * @return string
320
- */
321
- protected function _getConditionFullName($conditionName)
322
- {
323
- if (!isset($this->_conditionFullNames[$conditionName])) {
324
- $name = Mage::getSingleton('shipping/carrier_tablerate')->getCode('condition_name_short', $conditionName);
325
- $this->_conditionFullNames[$conditionName] = $name;
326
- }
327
-
328
- return $this->_conditionFullNames[$conditionName];
329
- }
330
-
331
- /**
332
- * Validate row for import and return table rate array or false
333
- * Error will be add to _importErrors array
334
- *
335
- * @param array $row
336
- * @param int $rowNumber
337
- *
338
- * @return array|false
339
- */
340
- protected function _getImportRow($row, $rowNumber = 0)
341
- {
342
- // validate row
343
- if (count($row) < self::CSV_COL_COUNT) {
344
- $this->_importErrors[] = $this->_getHelper()->__('Invalid Table Rates format in the Row #%s', $rowNumber);
345
-
346
- return false;
347
- }
348
- // validate country
349
- if (isset($this->_importIso2Countries[$row[self::CSV_COL_IDX_COUNTRY_ID]])) {
350
- $countryId = $this->_importIso2Countries[$row[self::CSV_COL_IDX_COUNTRY_ID]];
351
- } else if (isset($this->_importIso3Countries[$row[self::CSV_COL_IDX_COUNTRY_ID]])) {
352
- $countryId = $this->_importIso3Countries[$row[self::CSV_COL_IDX_COUNTRY_ID]];
353
- } else if ($row[self::CSV_COL_IDX_COUNTRY_ID] == '*' || $row[self::CSV_COL_IDX_COUNTRY_ID] == '') {
354
- $countryId = '0';
355
- } else {
356
- $this->_importErrors[] = $this->_getHelper()->__('Invalid Country "%s" in the Row #%s.', $row[self::CSV_COL_IDX_COUNTRY_ID], $rowNumber);
357
-
358
- return false;
359
- }
360
-
361
- // validate region
362
- if ($countryId != '0' && isset($this->_importRegions[$countryId][$row[self::CSV_COL_IDX_REGION]])) {
363
- $regionId = $this->_importRegions[$countryId][$row[self::CSV_COL_IDX_REGION]];
364
- } else if ($row[self::CSV_COL_IDX_REGION] == '*' || $row[self::CSV_COL_IDX_REGION] == '') {
365
- $regionId = 0;
366
- } else {
367
- $this->_importErrors[] = $this->_getHelper()->__('Invalid Region/State "%s" in the Row #%s.', $row[self::CSV_COL_IDX_REGION], $rowNumber);
368
-
369
- return false;
370
- }
371
-
372
- // detect zip code
373
- if ($row[self::CSV_COL_IDX_ZIP] == '*' || $row[self::CSV_COL_IDX_ZIP] == '') {
374
- $zipCode = '';
375
- } else {
376
- $zipCode = $row[self::CSV_COL_IDX_ZIP];
377
- }
378
-
379
- // Validar el peso/precio
380
- $weight = $this->_parseDecimalValue($row[self::CSV_COL_IDX_WEIGHT]);
381
- if ($weight === false || $weight < 0) {
382
- $this->_importErrors[] = $this->_getHelper()->__('Invalid weight/price "%s" in the Row #%s.', $weight, $rowNumber);
383
-
384
- return false;
385
- }
386
-
387
- // validate price
388
- $price = null;
389
- $markupType = null;
390
- $priceInput = $row[self::CSV_COL_IDX_PRICE];
391
- if (!$this->_parsePricePercentage($priceInput, $price, $markupType)) {
392
- $this->_importErrors[] = $this->_getHelper()->__('Invalid price/percentage/addition "%s" in the Row #%s.', $priceInput, $rowNumber);
393
-
394
- return false;
395
- }
396
-
397
- $method = trim($row[self::CSV_COL_IDX_METHOD]);
398
- if (!$this->_validateMethod($method)) {
399
- $this->_importErrors[] = $this->_getHelper()->__('Invalid service "%s" in the Row #%s.', $method, $rowNumber);
400
-
401
- return false;
402
- }
403
-
404
- $cashondelivery_surcharge = $this->_parseCashOnDeliverySurcharge($row[self::CSV_COL_IDX_COD_SURCHARGE]);
405
- if ($cashondelivery_surcharge === false) {
406
- $this->_importErrors[] = $this->_getHelper()->__('Invalid COD Surcharge "%s" in the Row #%s.', $row[self::CSV_COL_IDX_COD_SURCHARGE], $rowNumber);
407
-
408
- return false;
409
- }
410
-
411
- // Validar el sobrecargo contrareembolso mínimo.
412
- $minCodSurcharge = $this->_parseMinCodSurcharge($row[self::CSV_COL_IDX_COD_MIN_SURCHARGE], $cashondelivery_surcharge);
413
- if ($minCodSurcharge === false) {
414
- $this->_importErrors[] = $this->_getHelper()->__('Invalid Minimum COD Surcharge "%s" in the Row #%s. The minimum COD surcharge must be greater or equal to zero, and can only be used where the Cash On Delivery Surcharge is specified as a percentage.', $row[self::CSV_COL_IDX_COD_SURCHARGE], $rowNumber);
415
-
416
- return false;
417
- }
418
-
419
- $priceVsDest = $row[self::CSV_COL_IDX_COD_PRICE_VS_DEST] ? $row[self::CSV_COL_IDX_COD_PRICE_VS_DEST] : '0';
420
- if (array_search($priceVsDest, array('0', '1')) === false) {
421
- $this->_importErrors[] = $this->_getHelper()->__('Invalid value Price vs Dest value "%s" in the Row #%s. The value should be 0 (Weight vs Dest) or 1 (Price vs Dest).', $row[self::CSV_COL_IDX_COD_SURCHARGE], $rowNumber);
422
-
423
- return false;
424
- }
425
-
426
- $this->_log("[$countryId] [$regionId] [$zipCode] [$weight] [$priceInput] [$method] [$cashondelivery_surcharge] [$minCodSurcharge] [$priceVsDest]");
427
-
428
- // protect from duplicate
429
- $hash = sprintf("%s-%d-%s-%F-%d-%d", $countryId, $regionId, $zipCode, $weight, $method, $priceVsDest);
430
- if (isset($this->_importUniqueHash[$hash])) {
431
- $this->_importErrors[] = $this->_getHelper()->__('Duplicate Row #%s (Country "%s", Region/State "%s", Zip "%s", Weight/Price "%s", Method "%s", Price vs Dest "%s").', $rowNumber, $row[self::CSV_COL_IDX_COUNTRY_ID], $row[self::CSV_COL_IDX_REGION], $zipCode, $weight, $method);
432
-
433
- return false;
434
- }
435
- $this->_importUniqueHash[$hash] = true;
436
-
437
-
438
- return array(
439
- $this->_importWebsiteId, // website_id
440
- $countryId, // dest_country_id
441
- $regionId, // dest_region_id,
442
- $zipCode, // dest_zip
443
- $weight, // weight
444
- $price, // price - percentage, addition, or fixed
445
- $method, // method
446
- $markupType,// markup_type,
447
- $cashondelivery_surcharge,
448
- $minCodSurcharge,
449
- $priceVsDest
450
- );
451
- }
452
-
453
-
454
- /**
455
- *
456
- * @param type $value
457
- * @param string $value
458
- * @param string $cashondelivery_surcharge
459
- *
460
- * @return boolean
461
- */
462
- protected function _parseMinCodSurcharge($value, $cashondelivery_surcharge)
463
- {
464
- if (empty($value)) {
465
- return null;
466
- }
467
-
468
- $minCodSurcharge = $this->_parseDecimalValue($value, 2);
469
- if ($minCodSurcharge === false || $minCodSurcharge < 0) {
470
- return false;
471
- }
472
-
473
- if ($this->_getHelper()->parsePercentageValueAsFraction($cashondelivery_surcharge) === false) {
474
- return false;
475
- }
476
-
477
- return $minCodSurcharge;
478
- }
479
-
480
-
481
- /**
482
- * Save import data batch
483
- *
484
- * @param array $data
485
- *
486
- * @return Mage_Shipping_Model_Mysql4_Carrier_Tablerate
487
- */
488
- protected function _saveImportData(array $data)
489
- {
490
- if (!empty($data)) {
491
- $columns = array('website_id', 'dest_country_id', 'dest_region_id', 'dest_zip',
492
- 'weight', 'price', 'method', "markup_type", "cashondelivery_surcharge", "cod_min_surcharge", "price_vs_dest");
493
- $this->_getWriteAdapter()->insertArray($this->getMainTable(), $columns, $data);
494
- $this->_importedRows += count($data);
495
- }
496
-
497
- return $this;
498
- }
499
-
500
- /**
501
- * Parse and validate decimal value
502
- * Return false if value is not decimal
503
- *
504
- * @param string $value
505
- *
506
- * @return bool|float
507
- */
508
- protected function _parseDecimalValue($value, $precision = 4)
509
- {
510
- $value = trim($value);
511
- if (!is_numeric($value)) {
512
- return false;
513
- }
514
- $value = (float)sprintf("%.{$precision}F", $value);
515
-
516
- return $value;
517
- }
518
-
519
- /**
520
- * Parse the price/percentage column into a decimal value and a flag
521
- * which indicates whether the value is a percentage.
522
- *
523
- * @param string $value
524
- * @param float &$decimalPart
525
- * @param boolean $markupType
526
- *
527
- * @return float|boolean
528
- */
529
- protected function _parsePricePercentage($value, &$decimalPart, &$markupType)
530
- {
531
- $value = trim($value);
532
- if ($value === '') {
533
- return false;
534
- }
535
- $identifier = '';
536
- switch (substr($value, -1)) {
537
- case '#': {
538
- $markupType = 0;
539
- $identifier = '#';
540
- break;
541
- }
542
- case '%': {
543
- $markupType = 1;
544
- $identifier = '%';
545
- break;
546
- }
547
- case '+': {
548
- $markupType = 2;
549
- $identifier = '+';
550
- break;
551
- }
552
- default: {
553
- if (is_numeric(substr($value, -1)) && is_numeric($value)) {
554
- $markupType = 0;
555
- $identifier = '';
556
-
557
- break;
558
- }
559
-
560
- return false;
561
- }
562
- }
563
-
564
- if ($value == '#') {
565
- $decimalPart = 0;
566
- $markupType = 0;
567
-
568
- return true;
569
- }
570
- if (strlen($identifier) == 0) {
571
- $decimalPart = $value;
572
- } else {
573
- $decimalPart = substr($value, 0, strlen($value) - 1);
574
- }
575
- $decimalPart = $this->_parseDecimalValue($decimalPart);
576
- if ($decimalPart === false) {
577
- return false;
578
- }
579
- if (!$markupType && $decimalPart < 0) {
580
- return false;
581
- }
582
-
583
- return true;
584
- }
585
-
586
- /**
587
- * Returns true if the method code specified is valid
588
- *
589
- * @param string $method
590
- *
591
- * @return boolean
592
- */
593
- protected function _validateMethod($method)
594
- {
595
- if (!is_array($this->_validMethods)) {
596
- $this->_validMethods = array_keys(Mage::getModel('zitec_dpd/config_source_service')->toOptionArray());
597
- }
598
-
599
- return in_array($method, $this->_validMethods);
600
- }
601
-
602
- /**
603
- * Return CashOnDelivery Surcharge Value
604
- *
605
- * @param Varien_Object
606
- *
607
- * @return float
608
- */
609
- public function getCashOnDeliverySurcharge(Varien_Object $request)
610
- {
611
- $adapter = $this->_getReadAdapter();
612
- $bind = array(
613
- ':website_id' => (int)$request->getWebsiteId(),
614
- ':country_id' => $request->getDestCountryId(),
615
- ':region_id' => $request->getDestRegionId(),
616
- ':postcode' => $request->getDestPostcode(),
617
- ':weight' => (float)$request->getPackageWeight(),
618
- ':price' => (float)$request->getData('zitec_table_price'),
619
- ':method' => $request->getMethod()
620
- );
621
-
622
- $select = $adapter->select()
623
- ->from($this->getMainTable(), array('cashondelivery_surcharge', 'cod_min_surcharge'))
624
- ->where('website_id=:website_id')
625
- ->order(array('dest_country_id DESC', 'dest_region_id DESC', 'dest_zip DESC', 'method DESC', 'price_vs_dest DESC', 'weight DESC'));
626
-
627
-
628
- // render destination condition
629
- $orWhere = '(' . implode(') OR (', array(
630
- "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = :postcode",
631
- "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = ''",
632
- "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = ''",
633
- "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = :postcode",
634
- "dest_country_id = '0' AND dest_region_id = 0 AND dest_zip = ''",
635
- )) . ')';
636
-
637
- $select->where($orWhere);
638
-
639
-
640
- $select->where('((weight <= :weight and price_vs_dest = 0) or (weight <= :price and price_vs_dest = 1))');
641
- $select->where('method = :method');
642
-
643
- $rate = $adapter->fetchRow($select, $bind);
644
-
645
- if (empty($rate) && $this->isRateDefinedForMethod($request)) {
646
- $rate = null;
647
- }
648
-
649
- return $rate;
650
- }
651
-
652
-
653
- /**
654
- * find if there is a rate defined for method in the table rate
655
- *
656
- * @param $request
657
- *
658
- * @return bool
659
- */
660
- public function isRateDefinedForMethod($request)
661
- {
662
- $adapter = $this->_getReadAdapter();
663
- $bind = array(
664
- ':method' => $request->getMethod()
665
- );
666
-
667
- $select = $adapter->select()
668
- ->from($this->getMainTable(), array('count(*)'));
669
-
670
- $select->where('method = :method');
671
-
672
- $rate = $adapter->fetchOne($select, $bind);
673
- if ($rate) {
674
- return true;
675
- }
676
-
677
- return false;
678
- }
679
-
680
-
681
- /**
682
- * obtain the cash on delivery tax amounth
683
- *
684
- * @param mixed $value
685
- *
686
- * @return string|null|boolean
687
- */
688
- protected function _parseCashOnDeliverySurcharge($value)
689
- {
690
- if (!isset($value)) {
691
- return null;
692
- }
693
- $value = trim(strval($value));
694
- if ($value === "") {
695
- return null;
696
- }
697
-
698
- $asDecimal = $this->_parseDecimalValue($value);
699
- if ($asDecimal !== false) {
700
- if ($asDecimal >= 0) {
701
- return $value;
702
- } else {
703
- return false;
704
- }
705
- }
706
-
707
- if ($this->_getHelper()->parsePercentageValueAsFraction($value) !== false) {
708
- return $value;
709
- } else {
710
- return false;
711
- }
712
- }
713
-
714
- /**
715
- *
716
- * @return Zitec_Dpd_Helper_Data
717
- */
718
- protected function _getHelper()
719
- {
720
- return Mage::helper('zitec_dpd');
721
- }
722
-
723
- /**
724
- *
725
- * @param string $message
726
- *
727
- * @return Zitec_Dpd_Helper_Data
728
- */
729
- protected function _log($message)
730
- {
731
- return $this->_getHelper()->log($message);
732
- }
733
-
734
-
735
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Mysql4_Carrier_Tablerate extends Mage_Core_Model_Mysql4_Abstract
25
+ {
26
+
27
+ const CSV_COL_IDX_COUNTRY_ID = 0;
28
+ const CSV_COL_IDX_REGION = 1;
29
+ const CSV_COL_IDX_ZIP = 2;
30
+ const CSV_COL_IDX_WEIGHT = 3;
31
+ const CSV_COL_IDX_PRICE = 4;
32
+ const CSV_COL_IDX_METHOD = 5;
33
+ const CSV_COL_IDX_COD_SURCHARGE = 6;
34
+ const CSV_COL_IDX_COD_MIN_SURCHARGE = 7;
35
+ const CSV_COL_IDX_COD_PRICE_VS_DEST = 8;
36
+
37
+
38
+ const CSV_COL_COUNT = 9;
39
+
40
+
41
+ /**
42
+ * Import table rates website ID
43
+ *
44
+ * @var int
45
+ */
46
+ protected $_importWebsiteId = 0;
47
+
48
+ /**
49
+ * Errors in import process
50
+ *
51
+ * @var array
52
+ */
53
+ protected $_importErrors = array();
54
+
55
+ /**
56
+ * Count of imported table rates
57
+ *
58
+ * @var int
59
+ */
60
+ protected $_importedRows = 0;
61
+
62
+ /**
63
+ * Array of unique table rate keys to protect from duplicates
64
+ *
65
+ * @var array
66
+ */
67
+ protected $_importUniqueHash = array();
68
+
69
+ /**
70
+ * Array of countries keyed by iso2 code
71
+ *
72
+ * @var array
73
+ */
74
+ protected $_importIso2Countries;
75
+
76
+ /**
77
+ * Array of countries keyed by iso3 code
78
+ *
79
+ * @var array
80
+ */
81
+ protected $_importIso3Countries;
82
+
83
+ /**
84
+ * Associative array of countries and regions
85
+ * [country_id][region_code] = region_id
86
+ * [country_id][default_name] = region_id
87
+ *
88
+ * @var array
89
+ */
90
+ protected $_importRegions;
91
+
92
+
93
+ /**
94
+ * Import Table Rate condition name
95
+ *
96
+ * @var string
97
+ */
98
+ protected $_importConditionName;
99
+
100
+ /**
101
+ * Array of condition full names
102
+ *
103
+ * @var array
104
+ */
105
+ protected $_conditionFullNames = array();
106
+
107
+ /**
108
+ * List of valid method codes
109
+ *
110
+ * @var array
111
+ */
112
+ protected $_validMethods = null;
113
+
114
+ /**
115
+ * Define main table and id field name
116
+ *
117
+ * @return void
118
+ */
119
+ protected function _construct()
120
+ {
121
+ $this->_init('zitec_dpd/carrier_tablerate', 'pk');
122
+ }
123
+
124
+ /**
125
+ * Return table rate array or false by rate request
126
+ *
127
+ * @param Mage_Shipping_Model_Rate_Request $request
128
+ *
129
+ * @return array|false
130
+ */
131
+ public function getRate(Mage_Shipping_Model_Rate_Request $request)
132
+ {
133
+ $adapter = $this->_getReadAdapter();
134
+ $bind = array(
135
+ ':website_id' => (int)$request->getWebsiteId(),
136
+ ':country_id' => $request->getDestCountryId(),
137
+ ':region_id' => $request->getDestRegionId(),
138
+ ':postcode' => $request->getDestPostcode(),
139
+ ':weight' => (float)$request->getPackageWeight(),
140
+ ':price' => (float)$request->getData('zitec_table_price')
141
+ );
142
+ $select = $adapter->select()
143
+ ->from($this->getMainTable())
144
+ ->where('website_id=:website_id')
145
+ ->order(array('dest_country_id DESC', 'dest_region_id DESC', 'dest_zip DESC', 'method DESC', 'price_vs_dest DESC', 'weight DESC'));
146
+
147
+
148
+ // render destination condition
149
+ $orWhere = '(' . implode(') OR (', array(
150
+ "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = :postcode",
151
+ "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = ''",
152
+ "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = ''",
153
+ "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = :postcode",
154
+ "dest_country_id = '0' AND dest_region_id = 0 AND dest_zip = ''",
155
+ )) . ')';
156
+ $select->where($orWhere);
157
+ $select->where('((weight <= :weight and price_vs_dest = 0) or (weight <= :price and price_vs_dest = 1))');
158
+ $rates = $adapter->fetchAll($select, $bind);
159
+
160
+ if (empty($rates)) {
161
+ $rates = Mage::getModel('zitec_dpd/config_source_service')->getDefaultShipingRates();
162
+ }
163
+
164
+ return $rates;
165
+ }
166
+
167
+ /**
168
+ * Upload table rate file and import data from it
169
+ *
170
+ * @param Varien_Object $object
171
+ *
172
+ * @throws Mage_Core_Exception
173
+ * @return Mage_Shipping_Model_Mysql4_Carrier_Tablerate
174
+ */
175
+ public function uploadAndImport(Varien_Object $object, $csvFile = null)
176
+ {
177
+ $this->_log(__METHOD__);
178
+
179
+ if (!$csvFile && !empty($_FILES['groups']['tmp_name']['zitec_dpd']['fields']['import']['value'])) {
180
+ $csvFile = $_FILES['groups']['tmp_name']['zitec_dpd']['fields']['import']['value'];
181
+ }
182
+ if (!$csvFile) {
183
+ return $this;
184
+ }
185
+
186
+
187
+ $website = Mage::app()->getWebsite($object->getScopeId());
188
+
189
+ $this->_importWebsiteId = (int)$website->getId();
190
+ $this->_importUniqueHash = array();
191
+ $this->_importErrors = array();
192
+ $this->_importedRows = 0;
193
+
194
+ $io = new Varien_Io_File();
195
+ $info = pathinfo($csvFile);
196
+ $io->open(array('path' => $info['dirname']));
197
+ $io->streamOpen($info['basename'], 'r');
198
+
199
+ // check and skip headers
200
+ $headers = $io->streamReadCsv();
201
+ if ($headers === false || count($headers) < self::CSV_COL_COUNT) {
202
+ $io->streamClose();
203
+ Mage::throwException($this->_getHelper()->__('Invalid Table Rates File Format'));
204
+ }
205
+
206
+
207
+ $adapter = $this->_getWriteAdapter();
208
+ $adapter->beginTransaction();
209
+
210
+ try {
211
+ $rowNumber = 1;
212
+ $importData = array();
213
+
214
+ $this->_loadDirectoryCountries();
215
+ $this->_loadDirectoryRegions();
216
+
217
+ // delete old data by website and condition name
218
+ $condition = array(
219
+ 'website_id = ?' => $this->_importWebsiteId,
220
+ );
221
+ $adapter->delete($this->getMainTable(), $condition);
222
+
223
+ while (false !== ($csvLine = $io->streamReadCsv())) {
224
+ $rowNumber++;
225
+ if (is_array($csvLine)) {
226
+ foreach ($csvLine as &$cell) {
227
+ $cell = filter_var($cell, FILTER_SANITIZE_STRING);
228
+ }
229
+ }
230
+
231
+ if (empty($csvLine)) {
232
+ continue;
233
+ }
234
+
235
+ $row = $this->_getImportRow($csvLine, $rowNumber);
236
+ if ($row !== false) {
237
+ $importData[] = $row;
238
+ }
239
+
240
+ if (count($importData) == 5000) {
241
+ $this->_saveImportData($importData);
242
+ $importData = array();
243
+ }
244
+ }
245
+ $this->_saveImportData($importData);
246
+ $io->streamClose();
247
+ } catch (Mage_Core_Exception $e) {
248
+ $adapter->rollback();
249
+ $io->streamClose();
250
+ Mage::throwException($e->getMessage());
251
+ } catch (Exception $e) {
252
+ $adapter->rollback();
253
+ $io->streamClose();
254
+ $this->_log($e->getMessage());
255
+ Mage::throwException($this->_getHelper()->__('An error occurred while import table rates.'));
256
+ }
257
+
258
+ $adapter->commit();
259
+
260
+ if ($this->_importErrors) {
261
+ array_unshift($this->_importErrors, "");
262
+ $error = $this->_getHelper()->__('%1$d records have been imported. See the following list of errors for each record that has not been imported: %2$s', $this->_importedRows, implode(" \n", $this->_importErrors));
263
+ Mage::throwException($error);
264
+ }
265
+
266
+ return $this;
267
+ }
268
+
269
+ /**
270
+ * Load directory countries
271
+ *
272
+ * @return Mage_Shipping_Model_Mysql4_Carrier_Tablerate
273
+ */
274
+ protected function _loadDirectoryCountries()
275
+ {
276
+ if (!is_null($this->_importIso2Countries) && !is_null($this->_importIso3Countries)) {
277
+ return $this;
278
+ }
279
+
280
+ $this->_importIso2Countries = array();
281
+ $this->_importIso3Countries = array();
282
+
283
+ /** @var $collection Mage_Directory_Model_Mysql4_Country_Collection */
284
+ $collection = Mage::getResourceModel('directory/country_collection');
285
+ foreach ($collection->getData() as $row) {
286
+ $this->_importIso2Countries[$row['iso2_code']] = $row['country_id'];
287
+ $this->_importIso3Countries[$row['iso3_code']] = $row['country_id'];
288
+ }
289
+
290
+ return $this;
291
+ }
292
+
293
+ /**
294
+ * Load directory regions
295
+ *
296
+ * @return Mage_Shipping_Model_Mysql4_Carrier_Tablerate
297
+ */
298
+ protected function _loadDirectoryRegions()
299
+ {
300
+ if (!is_null($this->_importRegions)) {
301
+ return $this;
302
+ }
303
+
304
+ $this->_importRegions = array();
305
+
306
+ /** @var $collection Mage_Directory_Model_Mysql4_Region_Collection */
307
+ $collection = Mage::getResourceModel('directory/region_collection');
308
+ foreach ($collection->getData() as $row) {
309
+ $this->_importRegions[$row['country_id']][$row['code']] = (int)$row['region_id'];
310
+ $this->_importRegions[$row['country_id']][$row['default_name']] = (int)$row['region_id'];
311
+ }
312
+
313
+ return $this;
314
+ }
315
+
316
+ /**
317
+ * Return import condition full name by condition name code
318
+ *
319
+ * @return string
320
+ */
321
+ protected function _getConditionFullName($conditionName)
322
+ {
323
+ if (!isset($this->_conditionFullNames[$conditionName])) {
324
+ $name = Mage::getSingleton('shipping/carrier_tablerate')->getCode('condition_name_short', $conditionName);
325
+ $this->_conditionFullNames[$conditionName] = $name;
326
+ }
327
+
328
+ return $this->_conditionFullNames[$conditionName];
329
+ }
330
+
331
+ /**
332
+ * Validate row for import and return table rate array or false
333
+ * Error will be add to _importErrors array
334
+ *
335
+ * @param array $row
336
+ * @param int $rowNumber
337
+ *
338
+ * @return array|false
339
+ */
340
+ protected function _getImportRow($row, $rowNumber = 0)
341
+ {
342
+ // validate row
343
+ if (count($row) < self::CSV_COL_COUNT) {
344
+ $this->_importErrors[] = $this->_getHelper()->__('Invalid Table Rates format in the Row #%s', $rowNumber);
345
+
346
+ return false;
347
+ }
348
+ // validate country
349
+ if (isset($this->_importIso2Countries[$row[self::CSV_COL_IDX_COUNTRY_ID]])) {
350
+ $countryId = $this->_importIso2Countries[$row[self::CSV_COL_IDX_COUNTRY_ID]];
351
+ } else if (isset($this->_importIso3Countries[$row[self::CSV_COL_IDX_COUNTRY_ID]])) {
352
+ $countryId = $this->_importIso3Countries[$row[self::CSV_COL_IDX_COUNTRY_ID]];
353
+ } else if ($row[self::CSV_COL_IDX_COUNTRY_ID] == '*' || $row[self::CSV_COL_IDX_COUNTRY_ID] == '') {
354
+ $countryId = '0';
355
+ } else {
356
+ $this->_importErrors[] = $this->_getHelper()->__('Invalid Country "%s" in the Row #%s.', $row[self::CSV_COL_IDX_COUNTRY_ID], $rowNumber);
357
+
358
+ return false;
359
+ }
360
+
361
+ // validate region
362
+ if ($countryId != '0' && isset($this->_importRegions[$countryId][$row[self::CSV_COL_IDX_REGION]])) {
363
+ $regionId = $this->_importRegions[$countryId][$row[self::CSV_COL_IDX_REGION]];
364
+ } else if ($row[self::CSV_COL_IDX_REGION] == '*' || $row[self::CSV_COL_IDX_REGION] == '') {
365
+ $regionId = 0;
366
+ } else {
367
+ $this->_importErrors[] = $this->_getHelper()->__('Invalid Region/State "%s" in the Row #%s.', $row[self::CSV_COL_IDX_REGION], $rowNumber);
368
+
369
+ return false;
370
+ }
371
+
372
+ // detect zip code
373
+ if ($row[self::CSV_COL_IDX_ZIP] == '*' || $row[self::CSV_COL_IDX_ZIP] == '') {
374
+ $zipCode = '';
375
+ } else {
376
+ $zipCode = $row[self::CSV_COL_IDX_ZIP];
377
+ }
378
+
379
+ // Validar el peso/precio
380
+ $weight = $this->_parseDecimalValue($row[self::CSV_COL_IDX_WEIGHT]);
381
+ if ($weight === false || $weight < 0) {
382
+ $this->_importErrors[] = $this->_getHelper()->__('Invalid weight/price "%s" in the Row #%s.', $weight, $rowNumber);
383
+
384
+ return false;
385
+ }
386
+
387
+ // validate price
388
+ $price = null;
389
+ $markupType = null;
390
+ $priceInput = $row[self::CSV_COL_IDX_PRICE];
391
+ if (!$this->_parsePricePercentage($priceInput, $price, $markupType)) {
392
+ $this->_importErrors[] = $this->_getHelper()->__('Invalid price/percentage/addition "%s" in the Row #%s.', $priceInput, $rowNumber);
393
+
394
+ return false;
395
+ }
396
+
397
+ $method = trim($row[self::CSV_COL_IDX_METHOD]);
398
+ if (!$this->_validateMethod($method)) {
399
+ $this->_importErrors[] = $this->_getHelper()->__('Invalid service "%s" in the Row #%s.', $method, $rowNumber);
400
+
401
+ return false;
402
+ }
403
+
404
+ $cashondelivery_surcharge = $this->_parseCashOnDeliverySurcharge($row[self::CSV_COL_IDX_COD_SURCHARGE]);
405
+ if ($cashondelivery_surcharge === false) {
406
+ $this->_importErrors[] = $this->_getHelper()->__('Invalid COD Surcharge "%s" in the Row #%s.', $row[self::CSV_COL_IDX_COD_SURCHARGE], $rowNumber);
407
+
408
+ return false;
409
+ }
410
+
411
+ // Validar el sobrecargo contrareembolso mínimo.
412
+ $minCodSurcharge = $this->_parseMinCodSurcharge($row[self::CSV_COL_IDX_COD_MIN_SURCHARGE], $cashondelivery_surcharge);
413
+ if ($minCodSurcharge === false) {
414
+ $this->_importErrors[] = $this->_getHelper()->__('Invalid Minimum COD Surcharge "%s" in the Row #%s. The minimum COD surcharge must be greater or equal to zero, and can only be used where the Cash On Delivery Surcharge is specified as a percentage.', $row[self::CSV_COL_IDX_COD_SURCHARGE], $rowNumber);
415
+
416
+ return false;
417
+ }
418
+
419
+ $priceVsDest = $row[self::CSV_COL_IDX_COD_PRICE_VS_DEST] ? $row[self::CSV_COL_IDX_COD_PRICE_VS_DEST] : '0';
420
+ if (array_search($priceVsDest, array('0', '1')) === false) {
421
+ $this->_importErrors[] = $this->_getHelper()->__('Invalid value Price vs Dest value "%s" in the Row #%s. The value should be 0 (Weight vs Dest) or 1 (Price vs Dest).', $row[self::CSV_COL_IDX_COD_SURCHARGE], $rowNumber);
422
+
423
+ return false;
424
+ }
425
+
426
+ $this->_log("[$countryId] [$regionId] [$zipCode] [$weight] [$priceInput] [$method] [$cashondelivery_surcharge] [$minCodSurcharge] [$priceVsDest]");
427
+
428
+ // protect from duplicate
429
+ $hash = sprintf("%s-%d-%s-%F-%d-%d", $countryId, $regionId, $zipCode, $weight, $method, $priceVsDest);
430
+ if (isset($this->_importUniqueHash[$hash])) {
431
+ $this->_importErrors[] = $this->_getHelper()->__('Duplicate Row #%s (Country "%s", Region/State "%s", Zip "%s", Weight/Price "%s", Method "%s", Price vs Dest "%s").', $rowNumber, $row[self::CSV_COL_IDX_COUNTRY_ID], $row[self::CSV_COL_IDX_REGION], $zipCode, $weight, $method);
432
+
433
+ return false;
434
+ }
435
+ $this->_importUniqueHash[$hash] = true;
436
+
437
+
438
+ return array(
439
+ $this->_importWebsiteId, // website_id
440
+ $countryId, // dest_country_id
441
+ $regionId, // dest_region_id,
442
+ $zipCode, // dest_zip
443
+ $weight, // weight
444
+ $price, // price - percentage, addition, or fixed
445
+ $method, // method
446
+ $markupType,// markup_type,
447
+ $cashondelivery_surcharge,
448
+ $minCodSurcharge,
449
+ $priceVsDest
450
+ );
451
+ }
452
+
453
+
454
+ /**
455
+ *
456
+ * @param type $value
457
+ * @param string $value
458
+ * @param string $cashondelivery_surcharge
459
+ *
460
+ * @return boolean
461
+ */
462
+ protected function _parseMinCodSurcharge($value, $cashondelivery_surcharge)
463
+ {
464
+ if (empty($value)) {
465
+ return null;
466
+ }
467
+
468
+ $minCodSurcharge = $this->_parseDecimalValue($value, 2);
469
+ if ($minCodSurcharge === false || $minCodSurcharge < 0) {
470
+ return false;
471
+ }
472
+
473
+ if ($this->_getHelper()->parsePercentageValueAsFraction($cashondelivery_surcharge) === false) {
474
+ return false;
475
+ }
476
+
477
+ return $minCodSurcharge;
478
+ }
479
+
480
+
481
+ /**
482
+ * Save import data batch
483
+ *
484
+ * @param array $data
485
+ *
486
+ * @return Mage_Shipping_Model_Mysql4_Carrier_Tablerate
487
+ */
488
+ protected function _saveImportData(array $data)
489
+ {
490
+ if (!empty($data)) {
491
+ $columns = array('website_id', 'dest_country_id', 'dest_region_id', 'dest_zip',
492
+ 'weight', 'price', 'method', "markup_type", "cashondelivery_surcharge", "cod_min_surcharge", "price_vs_dest");
493
+ $this->_getWriteAdapter()->insertArray($this->getMainTable(), $columns, $data);
494
+ $this->_importedRows += count($data);
495
+ }
496
+
497
+ return $this;
498
+ }
499
+
500
+ /**
501
+ * Parse and validate decimal value
502
+ * Return false if value is not decimal
503
+ *
504
+ * @param string $value
505
+ *
506
+ * @return bool|float
507
+ */
508
+ protected function _parseDecimalValue($value, $precision = 4)
509
+ {
510
+ $value = trim($value);
511
+ if (!is_numeric($value)) {
512
+ return false;
513
+ }
514
+ $value = (float)sprintf("%.{$precision}F", $value);
515
+
516
+ return $value;
517
+ }
518
+
519
+ /**
520
+ * Parse the price/percentage column into a decimal value and a flag
521
+ * which indicates whether the value is a percentage.
522
+ *
523
+ * @param string $value
524
+ * @param float &$decimalPart
525
+ * @param boolean $markupType
526
+ *
527
+ * @return float|boolean
528
+ */
529
+ protected function _parsePricePercentage($value, &$decimalPart, &$markupType)
530
+ {
531
+ $value = trim($value);
532
+ if ($value === '') {
533
+ return false;
534
+ }
535
+ $identifier = '';
536
+ switch (substr($value, -1)) {
537
+ case '#': {
538
+ $markupType = 0;
539
+ $identifier = '#';
540
+ break;
541
+ }
542
+ case '%': {
543
+ $markupType = 1;
544
+ $identifier = '%';
545
+ break;
546
+ }
547
+ case '+': {
548
+ $markupType = 2;
549
+ $identifier = '+';
550
+ break;
551
+ }
552
+ default: {
553
+ if (is_numeric(substr($value, -1)) && is_numeric($value)) {
554
+ $markupType = 0;
555
+ $identifier = '';
556
+
557
+ break;
558
+ }
559
+
560
+ return false;
561
+ }
562
+ }
563
+
564
+ if ($value == '#') {
565
+ $decimalPart = 0;
566
+ $markupType = 0;
567
+
568
+ return true;
569
+ }
570
+ if (strlen($identifier) == 0) {
571
+ $decimalPart = $value;
572
+ } else {
573
+ $decimalPart = substr($value, 0, strlen($value) - 1);
574
+ }
575
+ $decimalPart = $this->_parseDecimalValue($decimalPart);
576
+ if ($decimalPart === false) {
577
+ return false;
578
+ }
579
+ if (!$markupType && $decimalPart < 0) {
580
+ return false;
581
+ }
582
+
583
+ return true;
584
+ }
585
+
586
+ /**
587
+ * Returns true if the method code specified is valid
588
+ *
589
+ * @param string $method
590
+ *
591
+ * @return boolean
592
+ */
593
+ protected function _validateMethod($method)
594
+ {
595
+ if (!is_array($this->_validMethods)) {
596
+ $this->_validMethods = array_keys(Mage::getModel('zitec_dpd/config_source_service')->toOptionArray());
597
+ }
598
+
599
+ return in_array($method, $this->_validMethods);
600
+ }
601
+
602
+ /**
603
+ * Return CashOnDelivery Surcharge Value
604
+ *
605
+ * @param Varien_Object
606
+ *
607
+ * @return float
608
+ */
609
+ public function getCashOnDeliverySurcharge(Varien_Object $request)
610
+ {
611
+ $adapter = $this->_getReadAdapter();
612
+ $bind = array(
613
+ ':website_id' => (int)$request->getWebsiteId(),
614
+ ':country_id' => $request->getDestCountryId(),
615
+ ':region_id' => $request->getDestRegionId(),
616
+ ':postcode' => $request->getDestPostcode(),
617
+ ':weight' => (float)$request->getPackageWeight(),
618
+ ':price' => (float)$request->getData('zitec_table_price'),
619
+ ':method' => $request->getMethod()
620
+ );
621
+
622
+ $select = $adapter->select()
623
+ ->from($this->getMainTable(), array('cashondelivery_surcharge', 'cod_min_surcharge'))
624
+ ->where('website_id=:website_id')
625
+ ->order(array('dest_country_id DESC', 'dest_region_id DESC', 'dest_zip DESC', 'method DESC', 'price_vs_dest DESC', 'weight DESC'));
626
+
627
+
628
+ // render destination condition
629
+ $orWhere = '(' . implode(') OR (', array(
630
+ "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = :postcode",
631
+ "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = ''",
632
+ "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = ''",
633
+ "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = :postcode",
634
+ "dest_country_id = '0' AND dest_region_id = 0 AND dest_zip = ''",
635
+ )) . ')';
636
+
637
+ $select->where($orWhere);
638
+
639
+
640
+ $select->where('((weight <= :weight and price_vs_dest = 0) or (weight <= :price and price_vs_dest = 1))');
641
+ $select->where('method = :method');
642
+
643
+ $rate = $adapter->fetchRow($select, $bind);
644
+
645
+ if (empty($rate) && $this->isRateDefinedForMethod($request)) {
646
+ $rate = null;
647
+ }
648
+
649
+ return $rate;
650
+ }
651
+
652
+
653
+ /**
654
+ * find if there is a rate defined for method in the table rate
655
+ *
656
+ * @param $request
657
+ *
658
+ * @return bool
659
+ */
660
+ public function isRateDefinedForMethod($request)
661
+ {
662
+ $adapter = $this->_getReadAdapter();
663
+ $bind = array(
664
+ ':method' => $request->getMethod()
665
+ );
666
+
667
+ $select = $adapter->select()
668
+ ->from($this->getMainTable(), array('count(*)'));
669
+
670
+ $select->where('method = :method');
671
+
672
+ $rate = $adapter->fetchOne($select, $bind);
673
+ if ($rate) {
674
+ return true;
675
+ }
676
+
677
+ return false;
678
+ }
679
+
680
+
681
+ /**
682
+ * obtain the cash on delivery tax amounth
683
+ *
684
+ * @param mixed $value
685
+ *
686
+ * @return string|null|boolean
687
+ */
688
+ protected function _parseCashOnDeliverySurcharge($value)
689
+ {
690
+ if (!isset($value)) {
691
+ return null;
692
+ }
693
+ $value = trim(strval($value));
694
+ if ($value === "") {
695
+ return null;
696
+ }
697
+
698
+ $asDecimal = $this->_parseDecimalValue($value);
699
+ if ($asDecimal !== false) {
700
+ if ($asDecimal >= 0) {
701
+ return $value;
702
+ } else {
703
+ return false;
704
+ }
705
+ }
706
+
707
+ if ($this->_getHelper()->parsePercentageValueAsFraction($value) !== false) {
708
+ return $value;
709
+ } else {
710
+ return false;
711
+ }
712
+ }
713
+
714
+ /**
715
+ *
716
+ * @return Zitec_Dpd_Helper_Data
717
+ */
718
+ protected function _getHelper()
719
+ {
720
+ return Mage::helper('zitec_dpd');
721
+ }
722
+
723
+ /**
724
+ *
725
+ * @param string $message
726
+ *
727
+ * @return Zitec_Dpd_Helper_Data
728
+ */
729
+ protected function _log($message)
730
+ {
731
+ return $this->_getHelper()->log($message);
732
+ }
733
+
734
+
735
  }
app/code/community/Zitec/Dpd/Model/Mysql4/Carrier/Tablerate/Collection.php CHANGED
@@ -1,109 +1,109 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Mysql4_Carrier_Tablerate_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
25
- {
26
-
27
- /**
28
- * directory/country table name
29
- *
30
- * @var string
31
- */
32
- protected $_countryTable;
33
-
34
- /**
35
- * directory/country_region table name
36
- *
37
- * @var string
38
- */
39
- protected $_regionTable;
40
-
41
- /**
42
- * Define resource model and item
43
- *
44
- */
45
- protected function _construct()
46
- {
47
- $this->_init('zitec_dpd/shipping_carrier_dpd', 'zitec_dpd/carrier_tablerate');
48
- $this->_countryTable = $this->getTable('directory/country');
49
- $this->_regionTable = $this->getTable('directory/country_region');
50
- }
51
-
52
- /**
53
- * Initialize select, add country iso3 code and region name
54
- *
55
- * @return void
56
- */
57
- public function _initSelect()
58
- {
59
- parent::_initSelect();
60
-
61
- $this->_select
62
- ->columns(array('shipping_price' => new Zend_Db_Expr("IF(main_table.markup_type = '1' OR main_table.markup_type = '2', IF(main_table.markup_type = '1',CONCAT(main_table.price, '%'), CONCAT(main_table.price,'+')), CONCAT(main_table.price,'#'))")))
63
- ->joinLeft(
64
- array('country_table' => $this->_countryTable), 'country_table.country_id = main_table.dest_country_id', array('dest_country' => 'iso3_code'))
65
- ->joinLeft(
66
- array('region_table' => $this->_regionTable), 'region_table.region_id = main_table.dest_region_id', array('dest_region' => 'code'));
67
-
68
- $this->addOrder('dest_country', self::SORT_ORDER_ASC);
69
- $this->addOrder('dest_region', self::SORT_ORDER_ASC);
70
- $this->addOrder('dest_zip', self::SORT_ORDER_ASC);
71
- }
72
-
73
- /**
74
- * Add website filter to collection
75
- *
76
- * @param int $websiteId
77
- *
78
- * @return Mage_Shipping_Model_Mysql4_Carrier_Tablerate_Collection
79
- */
80
- public function setWebsiteFilter($websiteId)
81
- {
82
- return $this->addFieldToFilter('website_id', $websiteId);
83
- }
84
-
85
- /**
86
- * Add condition name (code) filter to collection
87
- *
88
- * @param string $conditionName
89
- *
90
- * @return Mage_Shipping_Model_Mysql4_Carrier_Tablerate_Collection
91
- */
92
- public function setConditionFilter($conditionName)
93
- {
94
- return $this->addFieldToFilter('condition_name', $conditionName);
95
- }
96
-
97
- /**
98
- * Add country filter to collection
99
- *
100
- * @param string $countryId
101
- *
102
- * @return Mage_Shipping_Model_Mysql4_Carrier_Tablerate_Collection
103
- */
104
- public function setCountryFilter($countryId)
105
- {
106
- return $this->addFieldToFilter('dest_country_id', $countryId);
107
- }
108
-
109
- }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Mysql4_Carrier_Tablerate_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
25
+ {
26
+
27
+ /**
28
+ * directory/country table name
29
+ *
30
+ * @var string
31
+ */
32
+ protected $_countryTable;
33
+
34
+ /**
35
+ * directory/country_region table name
36
+ *
37
+ * @var string
38
+ */
39
+ protected $_regionTable;
40
+
41
+ /**
42
+ * Define resource model and item
43
+ *
44
+ */
45
+ protected function _construct()
46
+ {
47
+ $this->_init('zitec_dpd/shipping_carrier_dpd', 'zitec_dpd/carrier_tablerate');
48
+ $this->_countryTable = $this->getTable('directory/country');
49
+ $this->_regionTable = $this->getTable('directory/country_region');
50
+ }
51
+
52
+ /**
53
+ * Initialize select, add country iso3 code and region name
54
+ *
55
+ * @return void
56
+ */
57
+ public function _initSelect()
58
+ {
59
+ parent::_initSelect();
60
+
61
+ $this->_select
62
+ ->columns(array('shipping_price' => new Zend_Db_Expr("IF(main_table.markup_type = '1' OR main_table.markup_type = '2', IF(main_table.markup_type = '1',CONCAT(main_table.price, '%'), CONCAT(main_table.price,'+')), CONCAT(main_table.price,'#'))")))
63
+ ->joinLeft(
64
+ array('country_table' => $this->_countryTable), 'country_table.country_id = main_table.dest_country_id', array('dest_country' => 'iso3_code'))
65
+ ->joinLeft(
66
+ array('region_table' => $this->_regionTable), 'region_table.region_id = main_table.dest_region_id', array('dest_region' => 'code'));
67
+
68
+ $this->addOrder('dest_country', self::SORT_ORDER_ASC);
69
+ $this->addOrder('dest_region', self::SORT_ORDER_ASC);
70
+ $this->addOrder('dest_zip', self::SORT_ORDER_ASC);
71
+ }
72
+
73
+ /**
74
+ * Add website filter to collection
75
+ *
76
+ * @param int $websiteId
77
+ *
78
+ * @return Mage_Shipping_Model_Mysql4_Carrier_Tablerate_Collection
79
+ */
80
+ public function setWebsiteFilter($websiteId)
81
+ {
82
+ return $this->addFieldToFilter('website_id', $websiteId);
83
+ }
84
+
85
+ /**
86
+ * Add condition name (code) filter to collection
87
+ *
88
+ * @param string $conditionName
89
+ *
90
+ * @return Mage_Shipping_Model_Mysql4_Carrier_Tablerate_Collection
91
+ */
92
+ public function setConditionFilter($conditionName)
93
+ {
94
+ return $this->addFieldToFilter('condition_name', $conditionName);
95
+ }
96
+
97
+ /**
98
+ * Add country filter to collection
99
+ *
100
+ * @param string $countryId
101
+ *
102
+ * @return Mage_Shipping_Model_Mysql4_Carrier_Tablerate_Collection
103
+ */
104
+ public function setCountryFilter($countryId)
105
+ {
106
+ return $this->addFieldToFilter('dest_country_id', $countryId);
107
+ }
108
+
109
+ }
app/code/community/Zitec/Dpd/Model/Mysql4/Dpd/Manifest.php CHANGED
@@ -1,57 +1,57 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Mysql4_Dpd_Manifest extends Mage_Core_Model_Mysql4_Abstract
25
- {
26
-
27
-
28
- protected function _construct()
29
- {
30
- $this->_init('zitec_dpd/zitec_dpd_manifest', 'manifest_id');
31
- }
32
-
33
- /**
34
- *
35
- * @param Mage_Core_Model_Abstract $object
36
- *
37
- * @return Zitec_Dpd_Model_Mysql4_Dpd_Manifest
38
- */
39
- protected function _afterSave(Mage_Core_Model_Abstract $object)
40
- {
41
- $result = parent::_afterSave($object);
42
-
43
- $manifest = $object;
44
- /* @var $manifest Zitec_Dpd_Model_Dpd_Manifest */
45
- foreach ($manifest->getShipsForManifest() as $ship) {
46
- /* @var $ship Zitec_Dpd_Model_Dpd_Ship */
47
- $ship->setManifestId($manifest->getId());
48
- $ship->save();
49
- }
50
-
51
- return $result;
52
- }
53
-
54
-
55
- }
56
-
57
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Mysql4_Dpd_Manifest extends Mage_Core_Model_Mysql4_Abstract
25
+ {
26
+
27
+
28
+ protected function _construct()
29
+ {
30
+ $this->_init('zitec_dpd/zitec_dpd_manifest', 'manifest_id');
31
+ }
32
+
33
+ /**
34
+ *
35
+ * @param Mage_Core_Model_Abstract $object
36
+ *
37
+ * @return Zitec_Dpd_Model_Mysql4_Dpd_Manifest
38
+ */
39
+ protected function _afterSave(Mage_Core_Model_Abstract $object)
40
+ {
41
+ $result = parent::_afterSave($object);
42
+
43
+ $manifest = $object;
44
+ /* @var $manifest Zitec_Dpd_Model_Dpd_Manifest */
45
+ foreach ($manifest->getShipsForManifest() as $ship) {
46
+ /* @var $ship Zitec_Dpd_Model_Dpd_Ship */
47
+ $ship->setManifestId($manifest->getId());
48
+ $ship->save();
49
+ }
50
+
51
+ return $result;
52
+ }
53
+
54
+
55
+ }
56
+
57
+
app/code/community/Zitec/Dpd/Model/Mysql4/Dpd/Pickup.php CHANGED
@@ -1,34 +1,34 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Mysql4_Dpd_Pickup extends Mage_Core_Model_Mysql4_Abstract
25
- {
26
- //put your code here
27
- protected function _construct()
28
- {
29
- $this->_init('zitec_dpd/zitec_dpd_pickup_order', 'entity_id');
30
-
31
- }
32
- }
33
-
34
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Mysql4_Dpd_Pickup extends Mage_Core_Model_Mysql4_Abstract
25
+ {
26
+ //put your code here
27
+ protected function _construct()
28
+ {
29
+ $this->_init('zitec_dpd/zitec_dpd_pickup_order', 'entity_id');
30
+
31
+ }
32
+ }
33
+
34
+
app/code/community/Zitec/Dpd/Model/Mysql4/Dpd/Ship.php CHANGED
@@ -1,41 +1,41 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- /**
25
- * @method int getShipmentId()
26
- * @method int getOrderId()
27
- * @method string getSaveShipmentCall()
28
- * @method string getSaveShipmentResponse()
29
- * @method string getShippingLabels()
30
- * @method string getManifest()
31
- * @method int getManifestId()
32
- */
33
- class Zitec_Dpd_Model_Mysql4_Dpd_Ship extends Mage_Core_Model_Mysql4_Abstract
34
- {
35
-
36
- protected function _construct()
37
- {
38
- $this->_init('zitec_dpd/zitec_dpd_ship', 'id');
39
- }
40
-
41
- }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ /**
25
+ * @method int getShipmentId()
26
+ * @method int getOrderId()
27
+ * @method string getSaveShipmentCall()
28
+ * @method string getSaveShipmentResponse()
29
+ * @method string getShippingLabels()
30
+ * @method string getManifest()
31
+ * @method int getManifestId()
32
+ */
33
+ class Zitec_Dpd_Model_Mysql4_Dpd_Ship extends Mage_Core_Model_Mysql4_Abstract
34
+ {
35
+
36
+ protected function _construct()
37
+ {
38
+ $this->_init('zitec_dpd/zitec_dpd_ship', 'id');
39
+ }
40
+
41
+ }
app/code/community/Zitec/Dpd/Model/Mysql4/Dpd/Ship/Collection.php CHANGED
@@ -1,92 +1,92 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Mysql4_Dpd_Ship_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
25
- {
26
-
27
- protected function _construct()
28
- {
29
- $this->_init('zitec_dpd/dpd_ship');
30
- }
31
-
32
-
33
- /**
34
- *
35
- * @param int $shipmentId
36
- *
37
- * @return Zitec_Dpd_Model_Dpd_Ship
38
- */
39
- public function setOrderFilter($orderId)
40
- {
41
- $this->addFieldToFilter('order_id', $orderId);
42
- }
43
-
44
- /**
45
- *
46
- * @param int $shipmentId
47
- *
48
- * @return Zitec_Dpd_Model_Dpd_Ship
49
- */
50
- public function getByShipmentId($shipmentId)
51
- {
52
- $this->addFieldToFilter('shipment_id', $shipmentId);
53
- if ($this->count() == 0) {
54
- return false;
55
- }
56
-
57
- return $this->getFirstItem();
58
- }
59
-
60
- /**
61
- *
62
- * @param array $shipmentIds
63
- *
64
- * @return \Zitec_Dpd_Model_Mysql4_Dpd_Ship_Collection
65
- */
66
- public function filterByShipmentIds(array $shipmentIds)
67
- {
68
- $this->addFieldToFilter("shipment_id", array("in" => $shipmentIds));
69
-
70
- return $this;
71
- }
72
-
73
- /**
74
- *
75
- * @param type $shipmentId
76
- *
77
- * @return Zitec_Dpd_Model_Dpd_Ship|boolean
78
- */
79
- public function findByShipmentId($shipmentId)
80
- {
81
- foreach ($this as $ship) {
82
- /* @var $ship Zitec_Dpd_Model_Dpd_Ship */
83
- if ($ship->getShipmentId() == $shipmentId) {
84
- return $ship;
85
- }
86
- }
87
-
88
- return false;
89
- }
90
-
91
- }
92
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Mysql4_Dpd_Ship_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
25
+ {
26
+
27
+ protected function _construct()
28
+ {
29
+ $this->_init('zitec_dpd/dpd_ship');
30
+ }
31
+
32
+
33
+ /**
34
+ *
35
+ * @param int $shipmentId
36
+ *
37
+ * @return Zitec_Dpd_Model_Dpd_Ship
38
+ */
39
+ public function setOrderFilter($orderId)
40
+ {
41
+ $this->addFieldToFilter('order_id', $orderId);
42
+ }
43
+
44
+ /**
45
+ *
46
+ * @param int $shipmentId
47
+ *
48
+ * @return Zitec_Dpd_Model_Dpd_Ship
49
+ */
50
+ public function getByShipmentId($shipmentId)
51
+ {
52
+ $this->addFieldToFilter('shipment_id', $shipmentId);
53
+ if ($this->count() == 0) {
54
+ return false;
55
+ }
56
+
57
+ return $this->getFirstItem();
58
+ }
59
+
60
+ /**
61
+ *
62
+ * @param array $shipmentIds
63
+ *
64
+ * @return \Zitec_Dpd_Model_Mysql4_Dpd_Ship_Collection
65
+ */
66
+ public function filterByShipmentIds(array $shipmentIds)
67
+ {
68
+ $this->addFieldToFilter("shipment_id", array("in" => $shipmentIds));
69
+
70
+ return $this;
71
+ }
72
+
73
+ /**
74
+ *
75
+ * @param type $shipmentId
76
+ *
77
+ * @return Zitec_Dpd_Model_Dpd_Ship|boolean
78
+ */
79
+ public function findByShipmentId($shipmentId)
80
+ {
81
+ foreach ($this as $ship) {
82
+ /* @var $ship Zitec_Dpd_Model_Dpd_Ship */
83
+ if ($ship->getShipmentId() == $shipmentId) {
84
+ return $ship;
85
+ }
86
+ }
87
+
88
+ return false;
89
+ }
90
+
91
+ }
92
+
app/code/community/Zitec/Dpd/Model/Observer/Address.php CHANGED
@@ -1,179 +1,179 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Observer_Address
25
- {
26
-
27
- /**
28
- * Communicate the updated address to DPD.
29
- */
30
- public function salesOrderAddressAfterSave(Varien_Event_Observer $observer)
31
- {
32
- if (!$this->_getHelper()->isAdmin()) {
33
- return;
34
- }
35
-
36
-
37
- $address = $observer->getEvent()->getAddress();
38
- /* @var $address Mage_Sales_Model_Order_Address */
39
- if ($address->getAddressType() != 'shipping') {
40
- return;
41
- }
42
-
43
- $order = $address->getOrder();
44
- /* @var $order Mage_Sales_Model_Order */
45
- if (!$this->_getHelper()->moduleIsActive($order->getStore())) {
46
- return;
47
- }
48
-
49
- if (!$this->_getHelper()->isShippingMethodDpd($order->getShippingMethod())) {
50
- return;
51
- }
52
-
53
- if (!$this->_communicateAddresUpdateToDpd($address)) {
54
- return;
55
- }
56
-
57
- $this->_getHelper()->addNotice($this->__("The new shipping address for shipments associated with this order have been communicated successfully to DPD."));
58
-
59
- }
60
-
61
- /**
62
- * change the status of postcode validation
63
- *
64
- */
65
- public function salesOrderAddressBeforeSave(Varien_Event_Observer $observer)
66
- {
67
- if (!$this->_getHelper()->isAdmin()) {
68
- return;
69
- }
70
-
71
-
72
- $address = $observer->getEvent()->getAddress();
73
- /* @var $address Mage_Sales_Model_Order_Address */
74
- if ($address->getAddressType() != 'shipping') {
75
- return;
76
- }
77
-
78
- $order = $address->getOrder();
79
- /* @var $order Mage_Sales_Model_Order */
80
- if (!$this->_getHelper()->moduleIsActive($order->getStore())) {
81
- return;
82
- }
83
-
84
- if (!$this->_getHelper()->isShippingMethodDpd($order->getShippingMethod())) {
85
- return;
86
- }
87
-
88
- $origPostcode = $address->getOrigData('postcode');
89
- $newPostcode = $address->getPostcode();
90
- if ($origPostcode != $newPostcode){
91
- $address->setValidAutoPostcode(1);
92
- }
93
-
94
-
95
- }
96
-
97
-
98
- /**
99
- *
100
- * @param Mage_Sales_Model_Order_Address $address
101
- *
102
- * @return boolean
103
- */
104
- protected function _communicateAddresUpdateToDpd(Mage_Sales_Model_Order_Address $address)
105
- {
106
-
107
- $shipsCollectionForOrder = Mage::getResourceModel('zitec_dpd/dpd_ship_collection');
108
- /* @var $shipsCollectionForOrder Zitec_Dpd_Model_Mysql4_Dpd_Ship_Collection */
109
- $shipsCollectionForOrder->setOrderFilter($address->getParentId());
110
- if (!$shipsCollectionForOrder->count()) {
111
- return false;
112
- }
113
- foreach ($shipsCollectionForOrder as $ship) {
114
- /* @var $ship Zitec_Dpd_Model_Dpd_Ship */
115
- $dpdShipment = unserialize($ship->getSaveShipmentCall());
116
- /* @var $dpdShipmnent Zitec_Dpd_Api_Shipment_Save */
117
- try {
118
- $response = $dpdShipment->setReceiverAddress($address)
119
- ->execute();
120
- /* @var $response Zitec_Dpd_Api_Shipment_Save_Response */
121
- } catch (Exception $e) {
122
- Mage::throwException(sprintf($this->__('An error occurred updating the shipping address details with DPD: <br /> "%s"', $e->getMessage())));
123
- }
124
- if ($response->hasError()) {
125
- Mage::throwException(sprintf($this->__('DPD could not update the shipment address. The following error was returned: <br /> "%s: %s"'), $response->getErrorCode(), $response->getErrorText()));
126
- }
127
-
128
- try {
129
- $labelPdfStr = $this->_getWsHelper()->getNewPdfShipmentLabelsStr($response->getDpdShipmentId(), $response->getDpdShipmentReferenceNumber());
130
- } catch (Exception $e) {
131
- Mage::throwException(sprintf($this->__('An error occurred retrieving the updated shipping labels from DPD. <br />"s%"'), $e->getMessage()));
132
- }
133
-
134
- $ship->setSaveShipmentCall(serialize($dpdShipment))
135
- ->setSaveShipmentResponse(serialize($response))
136
- ->setShippingLabels(base64_encode($labelPdfStr))
137
- ->save();
138
-
139
- Mage::getModel('sales/order_shipment')
140
- ->load($ship->getShipmentId())
141
- ->setShippingLabel($labelPdfStr)
142
- ->save();
143
- }
144
-
145
- return true;
146
- }
147
-
148
-
149
- /**
150
- *
151
- * @return Zitec_Dpd_Helper_Data
152
- */
153
- protected function _getHelper()
154
- {
155
- return Mage::helper('zitec_dpd');
156
- }
157
-
158
- /**
159
- *
160
- * @param string $translateStr
161
- *
162
- * @return string
163
- */
164
- protected function __($translateStr)
165
- {
166
- return $this->_getHelper()->__($translateStr);
167
- }
168
-
169
- /**
170
- *
171
- * @return Zitec_Dpd_Helper_Ws
172
- */
173
- protected function _getWsHelper()
174
- {
175
- return Mage::helper('zitec_dpd/ws');
176
- }
177
- }
178
-
179
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Observer_Address
25
+ {
26
+
27
+ /**
28
+ * Communicate the updated address to DPD.
29
+ */
30
+ public function salesOrderAddressAfterSave(Varien_Event_Observer $observer)
31
+ {
32
+ if (!$this->_getHelper()->isAdmin()) {
33
+ return;
34
+ }
35
+
36
+
37
+ $address = $observer->getEvent()->getAddress();
38
+ /* @var $address Mage_Sales_Model_Order_Address */
39
+ if ($address->getAddressType() != 'shipping') {
40
+ return;
41
+ }
42
+
43
+ $order = $address->getOrder();
44
+ /* @var $order Mage_Sales_Model_Order */
45
+ if (!$this->_getHelper()->moduleIsActive($order->getStore())) {
46
+ return;
47
+ }
48
+
49
+ if (!$this->_getHelper()->isShippingMethodDpd($order->getShippingMethod())) {
50
+ return;
51
+ }
52
+
53
+ if (!$this->_communicateAddresUpdateToDpd($address)) {
54
+ return;
55
+ }
56
+
57
+ $this->_getHelper()->addNotice($this->__("The new shipping address for shipments associated with this order have been communicated successfully to DPD."));
58
+
59
+ }
60
+
61
+ /**
62
+ * change the status of postcode validation
63
+ *
64
+ */
65
+ public function salesOrderAddressBeforeSave(Varien_Event_Observer $observer)
66
+ {
67
+ if (!$this->_getHelper()->isAdmin()) {
68
+ return;
69
+ }
70
+
71
+
72
+ $address = $observer->getEvent()->getAddress();
73
+ /* @var $address Mage_Sales_Model_Order_Address */
74
+ if ($address->getAddressType() != 'shipping') {
75
+ return;
76
+ }
77
+
78
+ $order = $address->getOrder();
79
+ /* @var $order Mage_Sales_Model_Order */
80
+ if (!$this->_getHelper()->moduleIsActive($order->getStore())) {
81
+ return;
82
+ }
83
+
84
+ if (!$this->_getHelper()->isShippingMethodDpd($order->getShippingMethod())) {
85
+ return;
86
+ }
87
+
88
+ $origPostcode = $address->getOrigData('postcode');
89
+ $newPostcode = $address->getPostcode();
90
+ if ($origPostcode != $newPostcode){
91
+ $address->setValidAutoPostcode(1);
92
+ }
93
+
94
+
95
+ }
96
+
97
+
98
+ /**
99
+ *
100
+ * @param Mage_Sales_Model_Order_Address $address
101
+ *
102
+ * @return boolean
103
+ */
104
+ protected function _communicateAddresUpdateToDpd(Mage_Sales_Model_Order_Address $address)
105
+ {
106
+
107
+ $shipsCollectionForOrder = Mage::getResourceModel('zitec_dpd/dpd_ship_collection');
108
+ /* @var $shipsCollectionForOrder Zitec_Dpd_Model_Mysql4_Dpd_Ship_Collection */
109
+ $shipsCollectionForOrder->setOrderFilter($address->getParentId());
110
+ if (!$shipsCollectionForOrder->count()) {
111
+ return false;
112
+ }
113
+ foreach ($shipsCollectionForOrder as $ship) {
114
+ /* @var $ship Zitec_Dpd_Model_Dpd_Ship */
115
+ $dpdShipment = unserialize($ship->getSaveShipmentCall());
116
+ /* @var $dpdShipmnent Zitec_Dpd_Api_Shipment_Save */
117
+ try {
118
+ $response = $dpdShipment->setReceiverAddress($address)
119
+ ->execute();
120
+ /* @var $response Zitec_Dpd_Api_Shipment_Save_Response */
121
+ } catch (Exception $e) {
122
+ Mage::throwException(sprintf($this->__('An error occurred updating the shipping address details with DPD: <br /> "%s"', $e->getMessage())));
123
+ }
124
+ if ($response->hasError()) {
125
+ Mage::throwException(sprintf($this->__('DPD could not update the shipment address. The following error was returned: <br /> "%s: %s"'), $response->getErrorCode(), $response->getErrorText()));
126
+ }
127
+
128
+ try {
129
+ $labelPdfStr = $this->_getWsHelper()->getNewPdfShipmentLabelsStr($response->getDpdShipmentId(), $response->getDpdShipmentReferenceNumber());
130
+ } catch (Exception $e) {
131
+ Mage::throwException(sprintf($this->__('An error occurred retrieving the updated shipping labels from DPD. <br />"s%"'), $e->getMessage()));
132
+ }
133
+
134
+ $ship->setSaveShipmentCall(serialize($dpdShipment))
135
+ ->setSaveShipmentResponse(serialize($response))
136
+ ->setShippingLabels(base64_encode($labelPdfStr))
137
+ ->save();
138
+
139
+ Mage::getModel('sales/order_shipment')
140
+ ->load($ship->getShipmentId())
141
+ ->setShippingLabel($labelPdfStr)
142
+ ->save();
143
+ }
144
+
145
+ return true;
146
+ }
147
+
148
+
149
+ /**
150
+ *
151
+ * @return Zitec_Dpd_Helper_Data
152
+ */
153
+ protected function _getHelper()
154
+ {
155
+ return Mage::helper('zitec_dpd');
156
+ }
157
+
158
+ /**
159
+ *
160
+ * @param string $translateStr
161
+ *
162
+ * @return string
163
+ */
164
+ protected function __($translateStr)
165
+ {
166
+ return $this->_getHelper()->__($translateStr);
167
+ }
168
+
169
+ /**
170
+ *
171
+ * @return Zitec_Dpd_Helper_Ws
172
+ */
173
+ protected function _getWsHelper()
174
+ {
175
+ return Mage::helper('zitec_dpd/ws');
176
+ }
177
+ }
178
+
179
+
app/code/community/Zitec/Dpd/Model/Observer/Manifest.php CHANGED
@@ -1,54 +1,54 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Observer_Manifest
25
- {
26
-
27
- public function addManifestMassAction(Varien_Event_Observer $observer)
28
- {
29
- if (!$this->_getHelper()->moduleIsActive()) {
30
- return;
31
- }
32
- $block = $observer->getEvent()->getBlock();
33
- if ($block instanceof Mage_Adminhtml_Block_Widget_Grid_Massaction
34
- && (($block->getRequest()->getControllerName() == 'sales_shipment'))
35
- ) {
36
- $block->addItem('print_dpd_manifest', array(
37
- 'label' => $this->_getHelper()->__('Close DPD Manifest'),
38
- 'url' => Mage::helper("adminhtml")->getUrl('zitec_dpd/adminhtml_shipment/manifest'),
39
- 'confirm' => $this->_getHelper()->__('Once the manifest is closed for the selected shipments, you will not be able to make further changes to their shipping addresses. Do you want to continue?')
40
- ));
41
- }
42
- }
43
-
44
- /**
45
- *
46
- * @return Zitec_Dpd_Helper_Data
47
- */
48
- protected function _getHelper()
49
- {
50
- return Mage::helper('zitec_dpd');
51
- }
52
- }
53
-
54
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Observer_Manifest
25
+ {
26
+
27
+ public function addManifestMassAction(Varien_Event_Observer $observer)
28
+ {
29
+ if (!$this->_getHelper()->moduleIsActive()) {
30
+ return;
31
+ }
32
+ $block = $observer->getEvent()->getBlock();
33
+ if ($block instanceof Mage_Adminhtml_Block_Widget_Grid_Massaction
34
+ && (($block->getRequest()->getControllerName() == 'sales_shipment'))
35
+ ) {
36
+ $block->addItem('print_dpd_manifest', array(
37
+ 'label' => $this->_getHelper()->__('Close DPD Manifest'),
38
+ 'url' => Mage::helper("adminhtml")->getUrl('zitec_dpd/adminhtml_shipment/manifest'),
39
+ 'confirm' => $this->_getHelper()->__('Once the manifest is closed for the selected shipments, you will not be able to make further changes to their shipping addresses. Do you want to continue?')
40
+ ));
41
+ }
42
+ }
43
+
44
+ /**
45
+ *
46
+ * @return Zitec_Dpd_Helper_Data
47
+ */
48
+ protected function _getHelper()
49
+ {
50
+ return Mage::helper('zitec_dpd');
51
+ }
52
+ }
53
+
54
+
app/code/community/Zitec/Dpd/Model/Observer/Payment.php CHANGED
@@ -1,60 +1,60 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Observer_Payment
25
- {
26
-
27
-
28
- /**
29
- * force collect totals on checkout if the payment method is DPD
30
- *
31
- * @param Varien_Event_Observer $observer
32
- */
33
- public function setTotalsCollectedFlag(Varien_Event_Observer $observer)
34
- {
35
- $input = $observer->getEvent()->getInput();
36
- if ($input->getMethod() == Mage::helper('zitec_dpd')->getDpdPaymentCode()) {
37
- Mage::getModel('checkout/cart')->getQuote()->setTotalsCollectedFlag(false);
38
- }
39
- }
40
-
41
- /**
42
- * force collect html for review order in admin order create
43
- *
44
- * @param Varien_Event_Observer $observer
45
- */
46
- public function refreshTotalsInAdminOrderCreate(Varien_Event_Observer $observer)
47
- {
48
- $request = $observer->getEvent()->getRequestModel();
49
- $payment = $request->getParam('payment');
50
- if (!empty($payment)) {
51
- $block = $request->getParam('block');
52
- $blocks = explode(',', $block);
53
- if (!in_array('totals', $blocks)) {
54
- $request->setParam('block', $request->getParam('block') . ',totals');
55
- }
56
- }
57
- }
58
-
59
-
60
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Observer_Payment
25
+ {
26
+
27
+
28
+ /**
29
+ * force collect totals on checkout if the payment method is DPD
30
+ *
31
+ * @param Varien_Event_Observer $observer
32
+ */
33
+ public function setTotalsCollectedFlag(Varien_Event_Observer $observer)
34
+ {
35
+ $input = $observer->getEvent()->getInput();
36
+ if ($input->getMethod() == Mage::helper('zitec_dpd')->getDpdPaymentCode()) {
37
+ Mage::getModel('checkout/cart')->getQuote()->setTotalsCollectedFlag(false);
38
+ }
39
+ }
40
+
41
+ /**
42
+ * force collect html for review order in admin order create
43
+ *
44
+ * @param Varien_Event_Observer $observer
45
+ */
46
+ public function refreshTotalsInAdminOrderCreate(Varien_Event_Observer $observer)
47
+ {
48
+ $request = $observer->getEvent()->getRequestModel();
49
+ $payment = $request->getParam('payment');
50
+ if (!empty($payment)) {
51
+ $block = $request->getParam('block');
52
+ $blocks = explode(',', $block);
53
+ if (!in_array('totals', $blocks)) {
54
+ $request->setParam('block', $request->getParam('block') . ',totals');
55
+ }
56
+ }
57
+ }
58
+
59
+
60
  }
app/code/community/Zitec/Dpd/Model/Observer/Pickup.php CHANGED
@@ -1,80 +1,80 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Observer_Pickup
25
- {
26
-
27
- public function createPickupAction(Varien_Event_Observer $observer)
28
- {
29
- return;
30
- if (!$this->_getHelper()->moduleIsActive()) {
31
- return;
32
- }
33
- $block = $observer->getEvent()->getBlock();
34
- if ($block instanceof Mage_Adminhtml_Block_Widget_Grid_Massaction
35
- && (($block->getRequest()->getControllerName() == 'sales_shipment'))
36
- ) {
37
- $block->addItem('create_dpd_pickup', array(
38
- 'label' => $this->_getHelper()->__('Arrange DPD Pickup'),
39
- 'url' => Mage::helper("adminhtml")->getUrl('zitec_dpd/adminhtml_shipment/createpickup'),
40
- 'additional' => array(
41
- 'zitec_dpd_pickup_date' => array(
42
- 'name' => 'zitec_dpd_pickup_date',
43
- 'type' => 'text',
44
- 'class' => 'required-entry',
45
- 'label' => Mage::helper('index')->__('Date (DD/MM/YYYY)')
46
- ),
47
- 'zitec_dpd_pickup_from' => array(
48
- 'name' => 'zitec_dpd_pickup_from',
49
- 'type' => 'time',
50
- 'class' => 'required-entry',
51
- 'label' => Mage::helper('index')->__('Between')
52
- ),
53
- 'zitec_dpd_pickup_to' => array(
54
- 'name' => 'zitec_dpd_pickup_to',
55
- 'type' => 'time',
56
- 'class' => 'required-entry',
57
- 'label' => Mage::helper('index')->__('and')
58
- ),
59
- 'zitec_dpd_pickup_instruction' => array(
60
- 'name' => 'zitec_dpd_pickup_instruction',
61
- 'type' => 'text',
62
- 'label' => Mage::helper('index')->__('Instructions')
63
- ),
64
- )
65
- ));
66
- }
67
- }
68
-
69
- /**
70
- *
71
- * @return Zitec_Dpd_Helper_Data
72
- */
73
- protected function _getHelper()
74
- {
75
- return Mage::helper('zitec_dpd');
76
- }
77
-
78
- }
79
-
80
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Observer_Pickup
25
+ {
26
+
27
+ public function createPickupAction(Varien_Event_Observer $observer)
28
+ {
29
+ return;
30
+ if (!$this->_getHelper()->moduleIsActive()) {
31
+ return;
32
+ }
33
+ $block = $observer->getEvent()->getBlock();
34
+ if ($block instanceof Mage_Adminhtml_Block_Widget_Grid_Massaction
35
+ && (($block->getRequest()->getControllerName() == 'sales_shipment'))
36
+ ) {
37
+ $block->addItem('create_dpd_pickup', array(
38
+ 'label' => $this->_getHelper()->__('Arrange DPD Pickup'),
39
+ 'url' => Mage::helper("adminhtml")->getUrl('zitec_dpd/adminhtml_shipment/createpickup'),
40
+ 'additional' => array(
41
+ 'zitec_dpd_pickup_date' => array(
42
+ 'name' => 'zitec_dpd_pickup_date',
43
+ 'type' => 'text',
44
+ 'class' => 'required-entry',
45
+ 'label' => Mage::helper('index')->__('Date (DD/MM/YYYY)')
46
+ ),
47
+ 'zitec_dpd_pickup_from' => array(
48
+ 'name' => 'zitec_dpd_pickup_from',
49
+ 'type' => 'time',
50
+ 'class' => 'required-entry',
51
+ 'label' => Mage::helper('index')->__('Between')
52
+ ),
53
+ 'zitec_dpd_pickup_to' => array(
54
+ 'name' => 'zitec_dpd_pickup_to',
55
+ 'type' => 'time',
56
+ 'class' => 'required-entry',
57
+ 'label' => Mage::helper('index')->__('and')
58
+ ),
59
+ 'zitec_dpd_pickup_instruction' => array(
60
+ 'name' => 'zitec_dpd_pickup_instruction',
61
+ 'type' => 'text',
62
+ 'label' => Mage::helper('index')->__('Instructions')
63
+ ),
64
+ )
65
+ ));
66
+ }
67
+ }
68
+
69
+ /**
70
+ *
71
+ * @return Zitec_Dpd_Helper_Data
72
+ */
73
+ protected function _getHelper()
74
+ {
75
+ return Mage::helper('zitec_dpd');
76
+ }
77
+
78
+ }
79
+
80
+
app/code/community/Zitec/Dpd/Model/Observer/Shipment.php CHANGED
@@ -1,455 +1,455 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Observer_Shipment
25
- {
26
-
27
- /**
28
- *
29
- * @var boolean
30
- */
31
- protected $_isProcessed = false;
32
-
33
- /**
34
- *
35
- * @var Mage_Sales_Model_Order_Address
36
- */
37
- protected $_shippingAddress = null;
38
-
39
- /**
40
- *
41
- * @var Mage_Sales_Model_Order
42
- */
43
- protected $_order = null;
44
-
45
- /**
46
- *
47
- * @var Zitec_Dpd_Api_Shipment_Save_Response
48
- */
49
- protected $_response = null;
50
-
51
- /**
52
- *
53
- * @var Zitec_Dpd_Api_Shipment_Save
54
- */
55
- protected $_call = null;
56
-
57
- /**
58
- *
59
- * @var string
60
- */
61
- protected $_labelPdfStr = null;
62
-
63
-
64
- /**
65
- *
66
- * @var Mage_Sales_Model_Order_Shipment
67
- */
68
- protected $_shipment = null;
69
-
70
- /**
71
- *
72
- */
73
- protected $_isOrderShipmentNew = false;
74
-
75
- /**
76
- * @param Varien_Event_Observer $observer
77
- */
78
- public function salesOrderShipmentSaveBefore(Varien_Event_Observer $observer)
79
- {
80
- $shipment = $observer->getEvent()->getShipment();
81
- if (is_null($shipment->getId())) {
82
- $this->_isOrderShipmentNew = true;
83
- }
84
- }
85
-
86
- /**
87
- * Saves the DPD shipment when the shipment is created.
88
- *
89
- * @param void
90
- */
91
- public function salesOrderShipmentSaveAfter(Varien_Event_Observer $observer)
92
- {
93
- /**
94
- * @var Mage_Sales_Model_Order_Shipment $shipment
95
- */
96
- $shipment = $observer->getEvent()->getShipment();
97
- if (!$this->_canSaveDpdShipment($shipment)) {
98
- return;
99
- }
100
-
101
- $this->_isProcessed = true;
102
-
103
- $this->_setShipment($observer->getEvent()->getShipment());
104
- $this->_setOrder($this->_getShipment()->getOrder());
105
-
106
- $packedShipment = new Zitec_PackedShipment_Model_PackedShipment($this->_getShipment(), Mage::app()->getRequest()->getParam('packages'));
107
- if (!$packedShipment->getPackages()) {
108
- return $observer;
109
- }
110
-
111
-
112
- $this->_createShipment($packedShipment);
113
-
114
- $this->_getLabels();
115
-
116
-
117
- $successNotice = $this->__('Your new shipment was successfully communicated to DPD.');
118
- if ($this->_getDPDMessage()) {
119
- $successNotice .= '<br />' . sprintf($this->__('DPD says, "%s"'), $this->_getDPDMessage());
120
- }
121
- $this->_getHelper()->addNotice($successNotice);
122
- }
123
-
124
- /**
125
- * @param Zitec_PackedShipment_Model_PackedShipment $packedShipment
126
- *
127
- * @return bool
128
- * @throws Mage_Core_Exception
129
- */
130
- protected function _createShipment(Zitec_PackedShipment_Model_PackedShipment $packedShipment)
131
- {
132
- $dpdApi = new Zitec_Dpd_Api($this->_getShipmentParams());
133
- $dpdShipment = $dpdApi->getApiMethodObject();
134
-
135
- $serviceCode = $this->_getHelper()->getDPDServiceCode($this->_getOrder()->getShippingMethod());
136
- if (!$serviceCode) {
137
- Mage::throwException(sprintf($this->__("An error occurred communicating the shipment to DPD. The shipping method '%s' is invalid"), $this->_getOrder()->getShippingMethod()));
138
- }
139
- $dpdShipment->setReceiverAddress($this->_getShippingAddress())
140
- ->setShipmentReferenceNumber($this->_getShipment()->getIncrementId())
141
- ->setShipmentServiceCode($serviceCode);
142
-
143
-
144
- foreach ($packedShipment->getPackages() as $packageIdx => $package) {
145
- $dpdShipment->addParcel($packageIdx + 1, $package->getPackageWeight(), $package->getRef());
146
- }
147
-
148
- if ($this->_getHelper()->isOrderCashOnDelivery($this->_getOrder())) {
149
- $paymentType = $this->_getHelper()->getCodPaymentType($this->_getOrder());
150
- $dpdShipment->setCashOnDelivery(round($this->_getOrder()->getBaseGrandTotal(), 2), $this->_getOrder()->getBaseCurrencyCode(), $paymentType);
151
- }
152
- $order = $this->_getOrder();
153
- $insurance = Mage::helper('zitec_dpd')->extractInsuranceValuesByOrder($order);
154
- $dpdShipment->setAdditionalHighInsurance($insurance['goodsValue'], $insurance['currency'], $insurance['content']);
155
-
156
- try {
157
- $response = $dpdShipment->execute();
158
- } catch (Zitec_Dpd_Api_Shipment_Save_Exception_ReceiverAddressTooLong $e) {
159
- $message = "The shipment could not be communicated to DPD because the shipping street the maximum permitted length of %s characters. <br />Please edit the shipping address to reduce the length of the street in the shipping address.";
160
- Mage::throwException(sprintf($this->__($message), $e->getMaxLength()));
161
- } catch (Exception $e) {
162
- Mage::throwException(sprintf($this->__("An error occurred communicating the shipment to DPD at %s:<br /> '%s'"), $dpdShipment->getUrl(), $e->getMessage()));
163
- }
164
-
165
- if ($response->hasError()) {
166
- $message = sprintf($this->__('DPD could not process the new shipment. The following error was returned: <br /> "%s: %s"'), $response->getErrorCode(), $response->getErrorText());
167
- Mage::throwException($message);
168
- }
169
-
170
- $this->_response = $response;
171
- $this->_call = $dpdShipment;
172
-
173
- $this->_saveShipmentResponse($response, $dpdShipment);
174
-
175
- return true;
176
- }
177
-
178
- /**
179
- *
180
- * @return string|boolean
181
- */
182
- protected function _getDPDMessage()
183
- {
184
- if ($this->_response instanceof Zitec_Dpd_Api_Shipment_Save_Response) {
185
- return $this->_response->getMessage();
186
- } else {
187
- return false;
188
- }
189
- }
190
-
191
- /**
192
- *
193
- * @return array
194
- */
195
- protected function _getShipmentParams()
196
- {
197
- $apiParams = $this->_getWsHelper()->getShipmentParams($this->_getOrder()->getStoreId());
198
- $apiParams['method'] = Zitec_Dpd_Api_Configs::METHOD_CREATE_SHIPMENT;
199
-
200
- return $apiParams;
201
- }
202
-
203
- /**
204
- * @param Zitec_Dpd_Api_Shipment_Save_Response $response
205
- *
206
- * @return bool
207
- * @throws Exception
208
- */
209
- protected function _saveTracking($response)
210
- {
211
- $trackNumber = $response->getDpdShipmentReferenceNumber();
212
- $carrier = Mage::helper('zitec_dpd')->getDpdCarrierCode();
213
- $shipment = $this->_getShipment();
214
- $carrierName = $this->_getHelper()->getCarrierName($this->_getStore());
215
- $track = Mage::getModel('sales/order_shipment_track')
216
- ->setNumber($trackNumber)
217
- ->setTrackNumber($trackNumber)
218
- ->setCarrierCode($carrier)
219
- ->setTitle($carrierName);
220
- $shipment->addTrack($track);
221
- $shipment->save();
222
-
223
- return true;
224
- }
225
-
226
- /**
227
- *
228
- * @return boolean
229
- */
230
- protected function _getLabels()
231
- {
232
- try {
233
- $this->_labelPdfStr = $this->_getWsHelper()->getNewPdfShipmentLabelsStr($this->_response->getDpdShipmentId(), $this->_response->getDpdShipmentReferenceNumber());
234
- $this->_getShipment()->setShippingLabel($this->_labelPdfStr)->save();
235
-
236
- } catch (Exception $e) {
237
- Mage::throwException(sprintf('An error occurred whilst retreiving the shipping labels from DPD for the new shipment. <br /> "%s"'));
238
- }
239
-
240
- return true;
241
- }
242
-
243
- /**
244
- *
245
- * @param Zitec_Dpd_Api_Shipment_Save_Response $response
246
- *
247
- * @return boolean
248
- */
249
- protected function _saveShipmentResponse($response, $call)
250
- {
251
- $ship = Mage::getModel('zitec_dpd/dpd_ship');
252
- $ship->setShipmentId($this->_getShipment()->getId())
253
- ->setOrderId($this->_getOrder()->getId())
254
- ->setSaveShipmentCall(serialize($call))
255
- ->setShippingLabels(base64_encode($this->_labelPdfStr))
256
- ->setSaveShipmentResponse(serialize($response))
257
- ->save();
258
-
259
- $this->_saveTracking($response);
260
-
261
- $this->_getShipment()->setShippingLabel($this->_labelPdfStr)->save();
262
-
263
- return true;
264
- }
265
-
266
- /**
267
- * is not used anymore - to copy the file we use config.xml
268
- *
269
- * @param Varien_Object $observer
270
- *
271
- * @return
272
- */
273
- public function postcodeAddressConvertToOrder($observer)
274
- {
275
- if ($observer->getEvent()->getAddress()->getValidPostcode()) {
276
- $observer->getEvent()->getOrder()
277
- ->setValidPostcode($observer->getEvent()->getAddress()->getValidPostcode());
278
- }
279
- if ($observer->getEvent()->getAddress()->getAutoPostcode()) {
280
- $observer->getEvent()->getOrder()
281
- ->setAutoPostcode($observer->getEvent()->getAddress()->getAutoPostcode());
282
- }
283
-
284
- return $this;
285
- }
286
-
287
- /**
288
- * add some blocks used for postcode validation
289
- *
290
- * @param Varien_Object $observer
291
- *
292
- * @return
293
- */
294
- public function adminAddPostcodeAutocompleteBlock($observer)
295
- {
296
- $transport = $observer->getEvent()->getTransport();
297
- $block = $observer->getEvent()->getBlock();
298
- if ($block instanceof Mage_Adminhtml_Block_Sales_Order_Address) {
299
- $content = $transport->getHtml();
300
-
301
- $content .= Mage::app()->getLayout()
302
- ->createBlock('core/template')
303
- ->setTemplate('zitec_dpd/sales/order/address/postcode/validate.phtml')->toHtml();
304
-
305
- $transport->setHtml($content);
306
- }
307
-
308
- if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View_Info) {
309
- $isDpdCarrier = Mage::helper('zitec_dpd')->isDpdCarrierByOrder($block->getOrder());
310
- $isPCAutocompleterEnabled = Mage::helper('zitec_dpd')->isEnabledPostcodeAutocompleteByOrder($block->getOrder());
311
- if ($isDpdCarrier) {
312
- $content = $transport->getHtml();
313
- if ($isPCAutocompleterEnabled) {
314
-
315
- $content .= Mage::app()->getLayout()
316
- ->createBlock('core/template')
317
- ->setOrder($block->getOrder())
318
- ->setTemplate('zitec_dpd/sales/order/address/postcode/alert-problem.phtml')->toHtml();
319
- }
320
-
321
- $content .= Mage::app()->getLayout()
322
- ->createBlock('core/template')
323
- ->setOrder($block->getOrder())
324
- ->setTemplate('zitec_dpd/sales/order/address/street/alert-problem.phtml')->toHtml();
325
-
326
- $transport->setHtml($content);
327
- }
328
- }
329
-
330
-
331
- return $this;
332
- }
333
-
334
-
335
- /**
336
- * @param Mage_Sales_Model_Order_Shipment $shipment
337
- *
338
- * @return bool
339
- */
340
- protected function _canSaveDpdShipment(Mage_Sales_Model_Order_Shipment $shipment)
341
- {
342
- if (!$this->_isOrderShipmentNew || $this->_isProcessed) {
343
- return false;
344
- }
345
-
346
- if (!$this->_getHelper()->moduleIsActive($shipment->getOrder()->getStore())) {
347
- return false;
348
- }
349
-
350
- if (!$this->_getHelper()->isShippingMethodDpd($shipment->getOrder()->getShippingMethod())) {
351
- return false;
352
- }
353
-
354
- return true;
355
- }
356
-
357
- /**
358
- *
359
- * @param Mage_Sales_Model_Order $order
360
- *
361
- * @return \Zitec_Dpd_Model_Observer_Shipment
362
- */
363
- protected function _setOrder(Mage_Sales_Model_Order $order)
364
- {
365
- $this->_order = $order;
366
-
367
- return $this;
368
- }
369
-
370
- /**
371
- *
372
- * @return Mage_Sales_Model_Order
373
- */
374
- protected function _getOrder()
375
- {
376
- return $this->_order;
377
- }
378
-
379
- /**
380
- *
381
- * @param Mage_Sales_Model_Order_Shipment $shipment
382
- *
383
- * @return \Zitec_Dpd_Model_Observer_Shipment
384
- */
385
- protected function _setShipment(Mage_Sales_Model_Order_Shipment $shipment)
386
- {
387
- $this->_shipment = $shipment;
388
-
389
- return $this;
390
- }
391
-
392
- /**
393
- *
394
- * @return Mage_Sales_Model_Order_Shipment
395
- */
396
- protected function _getShipment()
397
- {
398
- return $this->_shipment;
399
- }
400
-
401
- /**
402
- *
403
- * @return Mage_Core_Model_Store
404
- */
405
- protected function _getStore()
406
- {
407
- return $this->_getOrder()->getStore();
408
- }
409
-
410
- /**
411
- * Important: Here we load the shipping address from the database rather than
412
- * using the one accessible from the order. This is intentional. using the one on the order
413
- * appears to cause a crash with some versions of PHP.
414
- *
415
- * @return Mage_Sales_Model_Order_Address
416
- */
417
- protected function _getShippingAddress()
418
- {
419
- if (!$this->_shippingAddress) {
420
- $this->_shippingAddress = Mage::getModel('sales/order_address')->load($this->_getOrder()->getShippingAddressId());
421
- }
422
-
423
- return $this->_shippingAddress;
424
- }
425
-
426
- /**
427
- *
428
- * @return Zitec_Dpd_Helper_Ws
429
- */
430
- protected function _getWsHelper()
431
- {
432
- return Mage::helper('zitec_dpd/ws');
433
- }
434
-
435
- /**
436
- *
437
- * @return Zitec_Dpd_Helper_Data
438
- */
439
- protected function _getHelper()
440
- {
441
- return Mage::helper('zitec_dpd');
442
- }
443
-
444
- /**
445
- *
446
- * @param string $translateStr
447
- *
448
- * @return string
449
- */
450
- protected function __($translateStr)
451
- {
452
- return $this->_getHelper()->__($translateStr);
453
- }
454
-
455
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Observer_Shipment
25
+ {
26
+
27
+ /**
28
+ *
29
+ * @var boolean
30
+ */
31
+ protected $_isProcessed = false;
32
+
33
+ /**
34
+ *
35
+ * @var Mage_Sales_Model_Order_Address
36
+ */
37
+ protected $_shippingAddress = null;
38
+
39
+ /**
40
+ *
41
+ * @var Mage_Sales_Model_Order
42
+ */
43
+ protected $_order = null;
44
+
45
+ /**
46
+ *
47
+ * @var Zitec_Dpd_Api_Shipment_Save_Response
48
+ */
49
+ protected $_response = null;
50
+
51
+ /**
52
+ *
53
+ * @var Zitec_Dpd_Api_Shipment_Save
54
+ */
55
+ protected $_call = null;
56
+
57
+ /**
58
+ *
59
+ * @var string
60
+ */
61
+ protected $_labelPdfStr = null;
62
+
63
+
64
+ /**
65
+ *
66
+ * @var Mage_Sales_Model_Order_Shipment
67
+ */
68
+ protected $_shipment = null;
69
+
70
+ /**
71
+ *
72
+ */
73
+ protected $_isOrderShipmentNew = false;
74
+
75
+ /**
76
+ * @param Varien_Event_Observer $observer
77
+ */
78
+ public function salesOrderShipmentSaveBefore(Varien_Event_Observer $observer)
79
+ {
80
+ $shipment = $observer->getEvent()->getShipment();
81
+ if (is_null($shipment->getId())) {
82
+ $this->_isOrderShipmentNew = true;
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Saves the DPD shipment when the shipment is created.
88
+ *
89
+ * @param void
90
+ */
91
+ public function salesOrderShipmentSaveAfter(Varien_Event_Observer $observer)
92
+ {
93
+ /**
94
+ * @var Mage_Sales_Model_Order_Shipment $shipment
95
+ */
96
+ $shipment = $observer->getEvent()->getShipment();
97
+ if (!$this->_canSaveDpdShipment($shipment)) {
98
+ return;
99
+ }
100
+
101
+ $this->_isProcessed = true;
102
+
103
+ $this->_setShipment($observer->getEvent()->getShipment());
104
+ $this->_setOrder($this->_getShipment()->getOrder());
105
+
106
+ $packedShipment = new Zitec_PackedShipment_Model_PackedShipment($this->_getShipment(), Mage::app()->getRequest()->getParam('packages'));
107
+ if (!$packedShipment->getPackages()) {
108
+ return $observer;
109
+ }
110
+
111
+
112
+ $this->_createShipment($packedShipment);
113
+
114
+ $this->_getLabels();
115
+
116
+
117
+ $successNotice = $this->__('Your new shipment was successfully communicated to DPD.');
118
+ if ($this->_getDPDMessage()) {
119
+ $successNotice .= '<br />' . sprintf($this->__('DPD says, "%s"'), $this->_getDPDMessage());
120
+ }
121
+ $this->_getHelper()->addNotice($successNotice);
122
+ }
123
+
124
+ /**
125
+ * @param Zitec_PackedShipment_Model_PackedShipment $packedShipment
126
+ *
127
+ * @return bool
128
+ * @throws Mage_Core_Exception
129
+ */
130
+ protected function _createShipment(Zitec_PackedShipment_Model_PackedShipment $packedShipment)
131
+ {
132
+ $dpdApi = new Zitec_Dpd_Api($this->_getShipmentParams());
133
+ $dpdShipment = $dpdApi->getApiMethodObject();
134
+
135
+ $serviceCode = $this->_getHelper()->getDPDServiceCode($this->_getOrder()->getShippingMethod());
136
+ if (!$serviceCode) {
137
+ Mage::throwException(sprintf($this->__("An error occurred communicating the shipment to DPD. The shipping method '%s' is invalid"), $this->_getOrder()->getShippingMethod()));
138
+ }
139
+ $dpdShipment->setReceiverAddress($this->_getShippingAddress())
140
+ ->setShipmentReferenceNumber($this->_getShipment()->getIncrementId())
141
+ ->setShipmentServiceCode($serviceCode);
142
+
143
+
144
+ foreach ($packedShipment->getPackages() as $packageIdx => $package) {
145
+ $dpdShipment->addParcel($packageIdx + 1, $package->getPackageWeight(), $package->getRef());
146
+ }
147
+
148
+ if ($this->_getHelper()->isOrderCashOnDelivery($this->_getOrder())) {
149
+ $paymentType = $this->_getHelper()->getCodPaymentType($this->_getOrder());
150
+ $dpdShipment->setCashOnDelivery(round($this->_getOrder()->getBaseGrandTotal(), 2), $this->_getOrder()->getBaseCurrencyCode(), $paymentType);
151
+ }
152
+ $order = $this->_getOrder();
153
+ $insurance = Mage::helper('zitec_dpd')->extractInsuranceValuesByOrder($order);
154
+ $dpdShipment->setAdditionalHighInsurance($insurance['goodsValue'], $insurance['currency'], $insurance['content']);
155
+
156
+ try {
157
+ $response = $dpdShipment->execute();
158
+ } catch (Zitec_Dpd_Api_Shipment_Save_Exception_ReceiverAddressTooLong $e) {
159
+ $message = "The shipment could not be communicated to DPD because the shipping street the maximum permitted length of %s characters. <br />Please edit the shipping address to reduce the length of the street in the shipping address.";
160
+ Mage::throwException(sprintf($this->__($message), $e->getMaxLength()));
161
+ } catch (Exception $e) {
162
+ Mage::throwException(sprintf($this->__("An error occurred communicating the shipment to DPD at %s:<br /> '%s'"), $dpdShipment->getUrl(), $e->getMessage()));
163
+ }
164
+
165
+ if ($response->hasError()) {
166
+ $message = sprintf($this->__('DPD could not process the new shipment. The following error was returned: <br /> "%s: %s"'), $response->getErrorCode(), $response->getErrorText());
167
+ Mage::throwException($message);
168
+ }
169
+
170
+ $this->_response = $response;
171
+ $this->_call = $dpdShipment;
172
+
173
+ $this->_saveShipmentResponse($response, $dpdShipment);
174
+
175
+ return true;
176
+ }
177
+
178
+ /**
179
+ *
180
+ * @return string|boolean
181
+ */
182
+ protected function _getDPDMessage()
183
+ {
184
+ if ($this->_response instanceof Zitec_Dpd_Api_Shipment_Save_Response) {
185
+ return $this->_response->getMessage();
186
+ } else {
187
+ return false;
188
+ }
189
+ }
190
+
191
+ /**
192
+ *
193
+ * @return array
194
+ */
195
+ protected function _getShipmentParams()
196
+ {
197
+ $apiParams = $this->_getWsHelper()->getShipmentParams($this->_getOrder()->getStoreId());
198
+ $apiParams['method'] = Zitec_Dpd_Api_Configs::METHOD_CREATE_SHIPMENT;
199
+
200
+ return $apiParams;
201
+ }
202
+
203
+ /**
204
+ * @param Zitec_Dpd_Api_Shipment_Save_Response $response
205
+ *
206
+ * @return bool
207
+ * @throws Exception
208
+ */
209
+ protected function _saveTracking($response)
210
+ {
211
+ $trackNumber = $response->getDpdShipmentReferenceNumber();
212
+ $carrier = Mage::helper('zitec_dpd')->getDpdCarrierCode();
213
+ $shipment = $this->_getShipment();
214
+ $carrierName = $this->_getHelper()->getCarrierName($this->_getStore());
215
+ $track = Mage::getModel('sales/order_shipment_track')
216
+ ->setNumber($trackNumber)
217
+ ->setTrackNumber($trackNumber)
218
+ ->setCarrierCode($carrier)
219
+ ->setTitle($carrierName);
220
+ $shipment->addTrack($track);
221
+ $shipment->save();
222
+
223
+ return true;
224
+ }
225
+
226
+ /**
227
+ *
228
+ * @return boolean
229
+ */
230
+ protected function _getLabels()
231
+ {
232
+ try {
233
+ $this->_labelPdfStr = $this->_getWsHelper()->getNewPdfShipmentLabelsStr($this->_response->getDpdShipmentId(), $this->_response->getDpdShipmentReferenceNumber());
234
+ $this->_getShipment()->setShippingLabel($this->_labelPdfStr)->save();
235
+
236
+ } catch (Exception $e) {
237
+ Mage::throwException(sprintf('An error occurred whilst retreiving the shipping labels from DPD for the new shipment. <br /> "%s"'));
238
+ }
239
+
240
+ return true;
241
+ }
242
+
243
+ /**
244
+ *
245
+ * @param Zitec_Dpd_Api_Shipment_Save_Response $response
246
+ *
247
+ * @return boolean
248
+ */
249
+ protected function _saveShipmentResponse($response, $call)
250
+ {
251
+ $ship = Mage::getModel('zitec_dpd/dpd_ship');
252
+ $ship->setShipmentId($this->_getShipment()->getId())
253
+ ->setOrderId($this->_getOrder()->getId())
254
+ ->setSaveShipmentCall(serialize($call))
255
+ ->setShippingLabels(base64_encode($this->_labelPdfStr))
256
+ ->setSaveShipmentResponse(serialize($response))
257
+ ->save();
258
+
259
+ $this->_saveTracking($response);
260
+
261
+ $this->_getShipment()->setShippingLabel($this->_labelPdfStr)->save();
262
+
263
+ return true;
264
+ }
265
+
266
+ /**
267
+ * is not used anymore - to copy the file we use config.xml
268
+ *
269
+ * @param Varien_Object $observer
270
+ *
271
+ * @return
272
+ */
273
+ public function postcodeAddressConvertToOrder($observer)
274
+ {
275
+ if ($observer->getEvent()->getAddress()->getValidPostcode()) {
276
+ $observer->getEvent()->getOrder()
277
+ ->setValidPostcode($observer->getEvent()->getAddress()->getValidPostcode());
278
+ }
279
+ if ($observer->getEvent()->getAddress()->getAutoPostcode()) {
280
+ $observer->getEvent()->getOrder()
281
+ ->setAutoPostcode($observer->getEvent()->getAddress()->getAutoPostcode());
282
+ }
283
+
284
+ return $this;
285
+ }
286
+
287
+ /**
288
+ * add some blocks used for postcode validation
289
+ *
290
+ * @param Varien_Object $observer
291
+ *
292
+ * @return
293
+ */
294
+ public function adminAddPostcodeAutocompleteBlock($observer)
295
+ {
296
+ $transport = $observer->getEvent()->getTransport();
297
+ $block = $observer->getEvent()->getBlock();
298
+ if ($block instanceof Mage_Adminhtml_Block_Sales_Order_Address) {
299
+ $content = $transport->getHtml();
300
+
301
+ $content .= Mage::app()->getLayout()
302
+ ->createBlock('core/template')
303
+ ->setTemplate('zitec_dpd/sales/order/address/postcode/validate.phtml')->toHtml();
304
+
305
+ $transport->setHtml($content);
306
+ }
307
+
308
+ if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View_Info) {
309
+ $isDpdCarrier = Mage::helper('zitec_dpd')->isDpdCarrierByOrder($block->getOrder());
310
+ $isPCAutocompleterEnabled = Mage::helper('zitec_dpd')->isEnabledPostcodeAutocompleteByOrder($block->getOrder());
311
+ if ($isDpdCarrier) {
312
+ $content = $transport->getHtml();
313
+ if ($isPCAutocompleterEnabled) {
314
+
315
+ $content .= Mage::app()->getLayout()
316
+ ->createBlock('core/template')
317
+ ->setOrder($block->getOrder())
318
+ ->setTemplate('zitec_dpd/sales/order/address/postcode/alert-problem.phtml')->toHtml();
319
+ }
320
+
321
+ $content .= Mage::app()->getLayout()
322
+ ->createBlock('core/template')
323
+ ->setOrder($block->getOrder())
324
+ ->setTemplate('zitec_dpd/sales/order/address/street/alert-problem.phtml')->toHtml();
325
+
326
+ $transport->setHtml($content);
327
+ }
328
+ }
329
+
330
+
331
+ return $this;
332
+ }
333
+
334
+
335
+ /**
336
+ * @param Mage_Sales_Model_Order_Shipment $shipment
337
+ *
338
+ * @return bool
339
+ */
340
+ protected function _canSaveDpdShipment(Mage_Sales_Model_Order_Shipment $shipment)
341
+ {
342
+ if (!$this->_isOrderShipmentNew || $this->_isProcessed) {
343
+ return false;
344
+ }
345
+
346
+ if (!$this->_getHelper()->moduleIsActive($shipment->getOrder()->getStore())) {
347
+ return false;
348
+ }
349
+
350
+ if (!$this->_getHelper()->isShippingMethodDpd($shipment->getOrder()->getShippingMethod())) {
351
+ return false;
352
+ }
353
+
354
+ return true;
355
+ }
356
+
357
+ /**
358
+ *
359
+ * @param Mage_Sales_Model_Order $order
360
+ *
361
+ * @return \Zitec_Dpd_Model_Observer_Shipment
362
+ */
363
+ protected function _setOrder(Mage_Sales_Model_Order $order)
364
+ {
365
+ $this->_order = $order;
366
+
367
+ return $this;
368
+ }
369
+
370
+ /**
371
+ *
372
+ * @return Mage_Sales_Model_Order
373
+ */
374
+ protected function _getOrder()
375
+ {
376
+ return $this->_order;
377
+ }
378
+
379
+ /**
380
+ *
381
+ * @param Mage_Sales_Model_Order_Shipment $shipment
382
+ *
383
+ * @return \Zitec_Dpd_Model_Observer_Shipment
384
+ */
385
+ protected function _setShipment(Mage_Sales_Model_Order_Shipment $shipment)
386
+ {
387
+ $this->_shipment = $shipment;
388
+
389
+ return $this;
390
+ }
391
+
392
+ /**
393
+ *
394
+ * @return Mage_Sales_Model_Order_Shipment
395
+ */
396
+ protected function _getShipment()
397
+ {
398
+ return $this->_shipment;
399
+ }
400
+
401
+ /**
402
+ *
403
+ * @return Mage_Core_Model_Store
404
+ */
405
+ protected function _getStore()
406
+ {
407
+ return $this->_getOrder()->getStore();
408
+ }
409
+
410
+ /**
411
+ * Important: Here we load the shipping address from the database rather than
412
+ * using the one accessible from the order. This is intentional. using the one on the order
413
+ * appears to cause a crash with some versions of PHP.
414
+ *
415
+ * @return Mage_Sales_Model_Order_Address
416
+ */
417
+ protected function _getShippingAddress()
418
+ {
419
+ if (!$this->_shippingAddress) {
420
+ $this->_shippingAddress = Mage::getModel('sales/order_address')->load($this->_getOrder()->getShippingAddressId());
421
+ }
422
+
423
+ return $this->_shippingAddress;
424
+ }
425
+
426
+ /**
427
+ *
428
+ * @return Zitec_Dpd_Helper_Ws
429
+ */
430
+ protected function _getWsHelper()
431
+ {
432
+ return Mage::helper('zitec_dpd/ws');
433
+ }
434
+
435
+ /**
436
+ *
437
+ * @return Zitec_Dpd_Helper_Data
438
+ */
439
+ protected function _getHelper()
440
+ {
441
+ return Mage::helper('zitec_dpd');
442
+ }
443
+
444
+ /**
445
+ *
446
+ * @param string $translateStr
447
+ *
448
+ * @return string
449
+ */
450
+ protected function __($translateStr)
451
+ {
452
+ return $this->_getHelper()->__($translateStr);
453
+ }
454
+
455
  }
app/code/community/Zitec/Dpd/Model/Payment/Cashondelivery.php CHANGED
@@ -1,213 +1,213 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Payment_Cashondelivery extends Mage_Payment_Model_Method_Abstract
25
- {
26
-
27
- const CODE = 'zitec_dpd_cashondelivery';
28
-
29
- protected $_code = 'zitec_dpd_cashondelivery';
30
- protected $_isInitializeNeeded = true;
31
- protected $_canUseInternal = true;
32
- protected $_canUseForMultishipping = false;
33
- protected $_surcharge = null;
34
- protected $_order = null;
35
-
36
- /**
37
- * Retrieve payment method title
38
- *
39
- * @return string
40
- */
41
- public function getTitle()
42
- {
43
- $order = $this->fetchOrder();
44
- $title = '';
45
- $store = null;
46
- if ($order) {
47
- $title = $this->getConfigData('title', $order->getStoreId());
48
- $store = $order->getStoreId();
49
- } else {
50
- $quote = Mage::getSingleton('checkout/session')->getQuote();
51
- if ($quote) {
52
- $title = $this->getConfigData('title', $quote->getStoreId());
53
- $store = $quote->getStoreId();
54
- }
55
- }
56
- $surcharge = $this->getSurchage();
57
- if ($surcharge > 0) {
58
- $title = $title . ' (+ ' . Mage::helper('core')->formatCurrency($surcharge, false);
59
- $taxConfig = Mage::getSingleton('tax/config');
60
- /* @var $taxConfig Mage_Tax_Model_Config */
61
- if ($taxConfig->shippingPriceIncludesTax($store)) {
62
- $title .= $this->_getHelper()->__(' incl. tax');
63
- } else {
64
- $title .= $this->_getHelper()->__(' excl. tax');
65
- }
66
- $title .= ') ';
67
- }
68
-
69
- return $title;
70
- }
71
-
72
- /**
73
- * Check whether payment method can be used
74
- *
75
- * TODO: payment method instance is not supposed to know about quote
76
- *
77
- * @param Mage_Sales_Model_Quote|null $quote
78
- *
79
- * @return bool
80
- */
81
- public function isAvailable($quote = null)
82
- {
83
- $checkResult = new StdClass;
84
- $isActive = (bool)(int)$this->getConfigData('active', $quote ? $quote->getStoreId() : null);
85
- $shippingMethodRaw = $quote->getShippingAddress()->getShippingMethod();
86
- $product = $this->_getHelper()->getDPDServiceCode($shippingMethodRaw);
87
-
88
- if (!$isActive ||
89
- !$quote ||
90
- !$this->_getHelper()->isShippingMethodDpd($shippingMethodRaw) ||
91
- !in_array($product, explode(',', $this->getConfigData('specificproducto', $quote->getStoreId()))) ||
92
- is_null($this->getSurchage())
93
- ) {
94
- $isActive = false;
95
- }
96
-
97
- $checkResult->isAvailable = $isActive;
98
- $checkResult->isDeniedInConfig = !$isActive; // for future use in observers
99
- Mage::dispatchEvent('payment_method_is_active', array(
100
- 'result' => $checkResult,
101
- 'method_instance' => $this,
102
- 'quote' => $quote,
103
- ));
104
-
105
- // disable method if it cannot implement recurring profiles management and there are recurring items in quote
106
- if ($checkResult->isAvailable) {
107
- $implementsRecurring = $this->canManageRecurringProfiles();
108
- // the $quote->hasRecurringItems() causes big performance impact, thus it has to be called last
109
- if ($quote && !$implementsRecurring && $quote->hasRecurringItems()) {
110
- $checkResult->isAvailable = false;
111
- }
112
- }
113
-
114
- return $checkResult->isAvailable;
115
- }
116
-
117
- public function getSurchage()
118
- {
119
- if ($this->_surcharge === null) {
120
- $order = $this->fetchOrder();
121
- if ($order) {
122
- $this->_surcharge = $order->getData('base_zitec_dpd_cashondelivery_surcharge');
123
- } else {
124
- $quote = Mage::helper('zitec_dpd/payment')->getQuote();
125
- /* @var $quote Mage_Sales_Model_Quote */
126
- if ($quote) {
127
- $shippingAddress = $quote->getShippingAddress();
128
-
129
- $request = new Varien_Object();
130
-
131
- $request->setWebsiteId(Mage::helper('zitec_dpd/payment')->getWebsiteId());
132
- $request->setDestCountryId($shippingAddress->getCountryId());
133
- $request->setDestRegionId($shippingAddress->getRegionId());
134
- $request->setDestPostcode($shippingAddress->getPostcode());
135
- $request->setPackageWeight($shippingAddress->getWeight());
136
- if ($this->_getTaxHelper()->shippingPriceIncludesTax($quote->getStoreId())) {
137
- $request->setData('zitec_table_price', $shippingAddress->getBaseSubtotalInclTax());
138
- } else {
139
- $request->setData('zitec_table_price', $shippingAddress->getBaseSubtotal());
140
- }
141
- $request->setMethod(str_replace(Mage::helper('zitec_dpd')->getDPDCarrierCode() . '_', '', $shippingAddress->getShippingMethod()));
142
- $tablerateSurcharge = Mage::getResourceModel('zitec_dpd/carrier_tablerate')->getCashOnDeliverySurcharge($request);
143
-
144
- if (is_null($tablerateSurcharge) || (is_array($tablerateSurcharge)&& is_null($tablerateSurcharge['cashondelivery_surcharge']))) {
145
- return null;
146
- } elseif (!empty($tablerateSurcharge)) {
147
- $this->_surcharge = $this->_getHelper()->calculateQuoteBaseCashOnDeliverySurcharge($quote, $tablerateSurcharge);
148
- } else {
149
- $this->_surcharge = $this->_getHelper()->returnDefaultBaseCashOnDeliverySurcharge($quote);
150
- }
151
- }
152
- }
153
- }
154
-
155
- return $this->_surcharge;
156
- }
157
-
158
- /**
159
- *
160
- * @return Mage_Tax_Helper_Data
161
- */
162
- protected function _getTaxHelper()
163
- {
164
- return Mage::helper('tax');
165
- }
166
-
167
- /**
168
- * @return Mage_Core_Model_Abstract|mixed|null
169
- */
170
- public function fetchOrder()
171
- {
172
- if (is_null($this->_order)) {
173
- if (Mage::app()->getStore()->isAdmin()) {
174
- $this->_order = Mage::registry('current_order');
175
- if (!$this->_order && Mage::app()->getRequest()->getParam('order_id')) {
176
- $this->_order = Mage::getModel('sales/order')->load(Mage::app()->getRequest()->getParam('order_id'));
177
- }
178
- } else {
179
- $order_id = Mage::app()->getRequest()->getParam('order_id');
180
- if ($order_id) {
181
- $this->_order = Mage::getModel('sales/order')->load(Mage::app()->getRequest()->getParam('order_id'));
182
- }
183
- }
184
- }
185
-
186
- return $this->_order;
187
- }
188
-
189
- /**
190
- * To check billing country is allowed for the payment method
191
- *
192
- * @return bool
193
- */
194
- public function canUseForCountry($country)
195
- {
196
- $allowedCountries = Zitec_Dpd_Model_Payment_Cashondelivery_Source_Country::getAllAllowedCountries();
197
- $canUseForCountry = parent::canUseForCountry($country) && (!$allowedCountries || in_array($country, $allowedCountries));
198
-
199
- return $canUseForCountry ? true : false;
200
- }
201
-
202
- /**
203
- *
204
- * @return Zitec_Dpd_Helper_Data
205
- */
206
- protected function _getHelper()
207
- {
208
- return Mage::helper('zitec_dpd');
209
- }
210
-
211
-
212
- }
213
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Payment_Cashondelivery extends Mage_Payment_Model_Method_Abstract
25
+ {
26
+
27
+ const CODE = 'zitec_dpd_cashondelivery';
28
+
29
+ protected $_code = 'zitec_dpd_cashondelivery';
30
+ protected $_isInitializeNeeded = true;
31
+ protected $_canUseInternal = true;
32
+ protected $_canUseForMultishipping = false;
33
+ protected $_surcharge = null;
34
+ protected $_order = null;
35
+
36
+ /**
37
+ * Retrieve payment method title
38
+ *
39
+ * @return string
40
+ */
41
+ public function getTitle()
42
+ {
43
+ $order = $this->fetchOrder();
44
+ $title = '';
45
+ $store = null;
46
+ if ($order) {
47
+ $title = $this->getConfigData('title', $order->getStoreId());
48
+ $store = $order->getStoreId();
49
+ } else {
50
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
51
+ if ($quote) {
52
+ $title = $this->getConfigData('title', $quote->getStoreId());
53
+ $store = $quote->getStoreId();
54
+ }
55
+ }
56
+ $surcharge = $this->getSurchage();
57
+ if ($surcharge > 0) {
58
+ $title = $title . ' (+ ' . Mage::helper('core')->formatCurrency($surcharge, false);
59
+ $taxConfig = Mage::getSingleton('tax/config');
60
+ /* @var $taxConfig Mage_Tax_Model_Config */
61
+ if ($taxConfig->shippingPriceIncludesTax($store)) {
62
+ $title .= $this->_getHelper()->__(' incl. tax');
63
+ } else {
64
+ $title .= $this->_getHelper()->__(' excl. tax');
65
+ }
66
+ $title .= ') ';
67
+ }
68
+
69
+ return $title;
70
+ }
71
+
72
+ /**
73
+ * Check whether payment method can be used
74
+ *
75
+ * TODO: payment method instance is not supposed to know about quote
76
+ *
77
+ * @param Mage_Sales_Model_Quote|null $quote
78
+ *
79
+ * @return bool
80
+ */
81
+ public function isAvailable($quote = null)
82
+ {
83
+ $checkResult = new StdClass;
84
+ $isActive = (bool)(int)$this->getConfigData('active', $quote ? $quote->getStoreId() : null);
85
+ $shippingMethodRaw = $quote->getShippingAddress()->getShippingMethod();
86
+ $product = $this->_getHelper()->getDPDServiceCode($shippingMethodRaw);
87
+
88
+ if (!$isActive ||
89
+ !$quote ||
90
+ !$this->_getHelper()->isShippingMethodDpd($shippingMethodRaw) ||
91
+ !in_array($product, explode(',', $this->getConfigData('specificproducto', $quote->getStoreId()))) ||
92
+ is_null($this->getSurchage())
93
+ ) {
94
+ $isActive = false;
95
+ }
96
+
97
+ $checkResult->isAvailable = $isActive;
98
+ $checkResult->isDeniedInConfig = !$isActive; // for future use in observers
99
+ Mage::dispatchEvent('payment_method_is_active', array(
100
+ 'result' => $checkResult,
101
+ 'method_instance' => $this,
102
+ 'quote' => $quote,
103
+ ));
104
+
105
+ // disable method if it cannot implement recurring profiles management and there are recurring items in quote
106
+ if ($checkResult->isAvailable) {
107
+ $implementsRecurring = $this->canManageRecurringProfiles();
108
+ // the $quote->hasRecurringItems() causes big performance impact, thus it has to be called last
109
+ if ($quote && !$implementsRecurring && $quote->hasRecurringItems()) {
110
+ $checkResult->isAvailable = false;
111
+ }
112
+ }
113
+
114
+ return $checkResult->isAvailable;
115
+ }
116
+
117
+ public function getSurchage()
118
+ {
119
+ if ($this->_surcharge === null) {
120
+ $order = $this->fetchOrder();
121
+ if ($order) {
122
+ $this->_surcharge = $order->getData('base_zitec_dpd_cashondelivery_surcharge');
123
+ } else {
124
+ $quote = Mage::helper('zitec_dpd/payment')->getQuote();
125
+ /* @var $quote Mage_Sales_Model_Quote */
126
+ if ($quote) {
127
+ $shippingAddress = $quote->getShippingAddress();
128
+
129
+ $request = new Varien_Object();
130
+
131
+ $request->setWebsiteId(Mage::helper('zitec_dpd/payment')->getWebsiteId());
132
+ $request->setDestCountryId($shippingAddress->getCountryId());
133
+ $request->setDestRegionId($shippingAddress->getRegionId());
134
+ $request->setDestPostcode($shippingAddress->getPostcode());
135
+ $request->setPackageWeight($shippingAddress->getWeight());
136
+ if ($this->_getTaxHelper()->shippingPriceIncludesTax($quote->getStoreId())) {
137
+ $request->setData('zitec_table_price', $shippingAddress->getBaseSubtotalInclTax());
138
+ } else {
139
+ $request->setData('zitec_table_price', $shippingAddress->getBaseSubtotal());
140
+ }
141
+ $request->setMethod(str_replace(Mage::helper('zitec_dpd')->getDPDCarrierCode() . '_', '', $shippingAddress->getShippingMethod()));
142
+ $tablerateSurcharge = Mage::getResourceModel('zitec_dpd/carrier_tablerate')->getCashOnDeliverySurcharge($request);
143
+
144
+ if (is_null($tablerateSurcharge) || (is_array($tablerateSurcharge)&& is_null($tablerateSurcharge['cashondelivery_surcharge']))) {
145
+ return null;
146
+ } elseif (!empty($tablerateSurcharge)) {
147
+ $this->_surcharge = $this->_getHelper()->calculateQuoteBaseCashOnDeliverySurcharge($quote, $tablerateSurcharge);
148
+ } else {
149
+ $this->_surcharge = $this->_getHelper()->returnDefaultBaseCashOnDeliverySurcharge($quote);
150
+ }
151
+ }
152
+ }
153
+ }
154
+
155
+ return $this->_surcharge;
156
+ }
157
+
158
+ /**
159
+ *
160
+ * @return Mage_Tax_Helper_Data
161
+ */
162
+ protected function _getTaxHelper()
163
+ {
164
+ return Mage::helper('tax');
165
+ }
166
+
167
+ /**
168
+ * @return Mage_Core_Model_Abstract|mixed|null
169
+ */
170
+ public function fetchOrder()
171
+ {
172
+ if (is_null($this->_order)) {
173
+ if (Mage::app()->getStore()->isAdmin()) {
174
+ $this->_order = Mage::registry('current_order');
175
+ if (!$this->_order && Mage::app()->getRequest()->getParam('order_id')) {
176
+ $this->_order = Mage::getModel('sales/order')->load(Mage::app()->getRequest()->getParam('order_id'));
177
+ }
178
+ } else {
179
+ $order_id = Mage::app()->getRequest()->getParam('order_id');
180
+ if ($order_id) {
181
+ $this->_order = Mage::getModel('sales/order')->load(Mage::app()->getRequest()->getParam('order_id'));
182
+ }
183
+ }
184
+ }
185
+
186
+ return $this->_order;
187
+ }
188
+
189
+ /**
190
+ * To check billing country is allowed for the payment method
191
+ *
192
+ * @return bool
193
+ */
194
+ public function canUseForCountry($country)
195
+ {
196
+ $allowedCountries = Zitec_Dpd_Model_Payment_Cashondelivery_Source_Country::getAllAllowedCountries();
197
+ $canUseForCountry = parent::canUseForCountry($country) && (!$allowedCountries || in_array($country, $allowedCountries));
198
+
199
+ return $canUseForCountry ? true : false;
200
+ }
201
+
202
+ /**
203
+ *
204
+ * @return Zitec_Dpd_Helper_Data
205
+ */
206
+ protected function _getHelper()
207
+ {
208
+ return Mage::helper('zitec_dpd');
209
+ }
210
+
211
+
212
+ }
213
+
app/code/community/Zitec/Dpd/Model/Payment/Cashondelivery/Source/AmountType.php CHANGED
@@ -1,41 +1,41 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Payment_Cashondelivery_Source_AmountType extends Zitec_Dpd_Model_Config_Source_Abstract
25
- {
26
-
27
- public function toOptionArray()
28
- {
29
-
30
- $codPaymentTypes = array(
31
- Zitec_Dpd_Api_Configs::PAYMENT_AMOUNT_TYPE_FIXED => $this->__('Fixed amount'),
32
- Zitec_Dpd_Api_Configs::PAYMENT_AMOUNT_TYPE_PERCENTAGE => $this->__('Percentage of entire order'),
33
- );
34
-
35
- return $codPaymentTypes;
36
- }
37
-
38
-
39
- }
40
-
41
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Payment_Cashondelivery_Source_AmountType extends Zitec_Dpd_Model_Config_Source_Abstract
25
+ {
26
+
27
+ public function toOptionArray()
28
+ {
29
+
30
+ $codPaymentTypes = array(
31
+ Zitec_Dpd_Api_Configs::PAYMENT_AMOUNT_TYPE_FIXED => $this->__('Fixed amount'),
32
+ Zitec_Dpd_Api_Configs::PAYMENT_AMOUNT_TYPE_PERCENTAGE => $this->__('Percentage of entire order'),
33
+ );
34
+
35
+ return $codPaymentTypes;
36
+ }
37
+
38
+
39
+ }
40
+
41
+
app/code/community/Zitec/Dpd/Model/Payment/Cashondelivery/Source/Codpaymenttype.php CHANGED
@@ -1,42 +1,42 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Payment_Cashondelivery_Source_Codpaymenttype extends Zitec_Dpd_Model_Config_Source_Abstract
25
- {
26
-
27
- public function toOptionArray()
28
- {
29
-
30
- $codPaymentTypes = array(
31
- Zitec_Dpd_Api_Configs::PAYMENT_TYPE_CASH => $this->__('Cash'),
32
- Zitec_Dpd_Api_Configs::PAYMENT_TYPE_CREDIT_CARD => $this->__('Credit Card'),
33
- Zitec_Dpd_Api_Configs::PAYMENT_TYPE_CROSSED_CHECK => $this->__('Crossed Check')
34
- );
35
-
36
- return $codPaymentTypes;
37
- }
38
-
39
-
40
- }
41
-
42
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Payment_Cashondelivery_Source_Codpaymenttype extends Zitec_Dpd_Model_Config_Source_Abstract
25
+ {
26
+
27
+ public function toOptionArray()
28
+ {
29
+
30
+ $codPaymentTypes = array(
31
+ Zitec_Dpd_Api_Configs::PAYMENT_TYPE_CASH => $this->__('Cash'),
32
+ Zitec_Dpd_Api_Configs::PAYMENT_TYPE_CREDIT_CARD => $this->__('Credit Card'),
33
+ Zitec_Dpd_Api_Configs::PAYMENT_TYPE_CROSSED_CHECK => $this->__('Crossed Check')
34
+ );
35
+
36
+ return $codPaymentTypes;
37
+ }
38
+
39
+
40
+ }
41
+
42
+
app/code/community/Zitec/Dpd/Model/Payment/Cashondelivery/Source/Country.php CHANGED
@@ -1,64 +1,64 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Payment_Cashondelivery_Source_Country extends Mage_Adminhtml_Model_System_Config_Source_Country
25
- {
26
-
27
- protected static $_allAllowedCountries = null;
28
-
29
- public function toOptionArray($isMultiselect = false)
30
- {
31
- $options = parent::toOptionArray($isMultiselect);
32
- if (self::getAllAllowedCountries()) {
33
- foreach ($options as $key => $option) {
34
- if ($option['value'] && !in_array($option['value'], self::getAllAllowedCountries())) {
35
- unset($options[$key]);
36
- }
37
- }
38
- }
39
-
40
- return $options;
41
- }
42
-
43
- /**
44
- *
45
- * @return array
46
- */
47
- public static function getAllAllowedCountries()
48
- {
49
- if (!is_array(self::$_allAllowedCountries)) {
50
- $allAllowedCountries = trim(Mage::getStoreConfig("payment/zitec_dpd_cashondelivery/all_allowed_countries"));
51
- if ($allAllowedCountries) {
52
- self::$_allAllowedCountries = explode(",", Mage::getStoreConfig("payment/zitec_dpd_cashondelivery/all_allowed_countries"));
53
- } else {
54
- self::$_allAllowedCountries = array();
55
- }
56
- }
57
-
58
- return self::$_allAllowedCountries;
59
- }
60
-
61
-
62
- }
63
-
64
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Payment_Cashondelivery_Source_Country extends Mage_Adminhtml_Model_System_Config_Source_Country
25
+ {
26
+
27
+ protected static $_allAllowedCountries = null;
28
+
29
+ public function toOptionArray($isMultiselect = false)
30
+ {
31
+ $options = parent::toOptionArray($isMultiselect);
32
+ if (self::getAllAllowedCountries()) {
33
+ foreach ($options as $key => $option) {
34
+ if ($option['value'] && !in_array($option['value'], self::getAllAllowedCountries())) {
35
+ unset($options[$key]);
36
+ }
37
+ }
38
+ }
39
+
40
+ return $options;
41
+ }
42
+
43
+ /**
44
+ *
45
+ * @return array
46
+ */
47
+ public static function getAllAllowedCountries()
48
+ {
49
+ if (!is_array(self::$_allAllowedCountries)) {
50
+ $allAllowedCountries = trim(Mage::getStoreConfig("payment/zitec_dpd_cashondelivery/all_allowed_countries"));
51
+ if ($allAllowedCountries) {
52
+ self::$_allAllowedCountries = explode(",", Mage::getStoreConfig("payment/zitec_dpd_cashondelivery/all_allowed_countries"));
53
+ } else {
54
+ self::$_allAllowedCountries = array();
55
+ }
56
+ }
57
+
58
+ return self::$_allAllowedCountries;
59
+ }
60
+
61
+
62
+ }
63
+
64
+
app/code/community/Zitec/Dpd/Model/Payment/Cashondelivery/Source/Service.php CHANGED
@@ -1,66 +1,66 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Payment_Cashondelivery_Source_Service
25
- {
26
- protected $_allowedServices = null;
27
-
28
- /**
29
- *
30
- * @param boolean $isMultiselect
31
- *
32
- * @return array
33
- */
34
- public function toOptionArray($isMultiselect = false)
35
- {
36
- $servicesSource = Mage::getModel('zitec_dpd/config_source_service');
37
- /* @var $services Zitec_Dpd_Model_Config_Source_Service */
38
- $services = $servicesSource->toOptionArray($isMultiselect);
39
- foreach ($services as $key => $service) {
40
- $serviceCode = $isMultiselect ? $service['value'] : $key;
41
- if (!in_array($serviceCode, $this->_getAllowedServices())) {
42
- unset($services[$key]);
43
- }
44
- }
45
-
46
- return $services;
47
- }
48
-
49
- /**
50
- *
51
- * @return array
52
- */
53
- protected function _getAllowedServices()
54
- {
55
- if (!is_array($this->_allowedServices)) {
56
- $this->_allowedServices = explode(",", Mage::getStoreConfig("payment/zitec_dpd_cashondelivery/services"));
57
- }
58
-
59
- return $this->_allowedServices;
60
- }
61
-
62
-
63
- }
64
-
65
-
66
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Payment_Cashondelivery_Source_Service
25
+ {
26
+ protected $_allowedServices = null;
27
+
28
+ /**
29
+ *
30
+ * @param boolean $isMultiselect
31
+ *
32
+ * @return array
33
+ */
34
+ public function toOptionArray($isMultiselect = false)
35
+ {
36
+ $servicesSource = Mage::getModel('zitec_dpd/config_source_service');
37
+ /* @var $services Zitec_Dpd_Model_Config_Source_Service */
38
+ $services = $servicesSource->toOptionArray($isMultiselect);
39
+ foreach ($services as $key => $service) {
40
+ $serviceCode = $isMultiselect ? $service['value'] : $key;
41
+ if (!in_array($serviceCode, $this->_getAllowedServices())) {
42
+ unset($services[$key]);
43
+ }
44
+ }
45
+
46
+ return $services;
47
+ }
48
+
49
+ /**
50
+ *
51
+ * @return array
52
+ */
53
+ protected function _getAllowedServices()
54
+ {
55
+ if (!is_array($this->_allowedServices)) {
56
+ $this->_allowedServices = explode(",", Mage::getStoreConfig("payment/zitec_dpd_cashondelivery/services"));
57
+ }
58
+
59
+ return $this->_allowedServices;
60
+ }
61
+
62
+
63
+ }
64
+
65
+
66
+
app/code/community/Zitec/Dpd/Model/Sales/Order/Creditmemo/Total/Cashondeliverysurchage.php CHANGED
@@ -1,62 +1,62 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Sales_Order_Creditmemo_Total_Cashondeliverysurchage extends Mage_Sales_Model_Order_Creditmemo_Total_Abstract
25
- {
26
-
27
- public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
28
- {
29
-
30
-
31
- $creditmemo->setData('zitec_dpd_cashondelivery_surcharge', 0);
32
- $creditmemo->setData('base_zitec_dpd_cashondelivery_surcharge', 0);
33
-
34
- $order = $creditmemo->getOrder();
35
-
36
-
37
- //Check creditmemo before to see if we have already returned
38
- $amount = $order->getData('zitec_dpd_cashondelivery_surcharge');
39
- if ($amount) {
40
- foreach ($order->getCreditmemosCollection() as $previousCreditMemo) {
41
- /* @var $previousCreditMemo Mage_Sales_Model_Order_Creditmemo */
42
- if ($previousCreditMemo->getData("base_zitec_dpd_cashondelivery_surcharge")) {
43
- return $this;
44
- }
45
- }
46
-
47
- // NB. Here we add one to the total tax base. Taxes
48
- // are added in Zitec_Dpd_Model_Sales_Order_Creditmemo_Total_Tax
49
- $creditmemo->setData('zitec_dpd_cashondelivery_surcharge', $amount);
50
-
51
- $baseAmount = $order->getData('base_zitec_dpd_cashondelivery_surcharge');
52
- $creditmemo->setData('base_zitec_dpd_cashondelivery_surcharge', $baseAmount);
53
-
54
- $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $amount);
55
- $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseAmount);
56
-
57
- }
58
-
59
- return $this;
60
- }
61
-
62
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Sales_Order_Creditmemo_Total_Cashondeliverysurchage extends Mage_Sales_Model_Order_Creditmemo_Total_Abstract
25
+ {
26
+
27
+ public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
28
+ {
29
+
30
+
31
+ $creditmemo->setData('zitec_dpd_cashondelivery_surcharge', 0);
32
+ $creditmemo->setData('base_zitec_dpd_cashondelivery_surcharge', 0);
33
+
34
+ $order = $creditmemo->getOrder();
35
+
36
+
37
+ //Check creditmemo before to see if we have already returned
38
+ $amount = $order->getData('zitec_dpd_cashondelivery_surcharge');
39
+ if ($amount) {
40
+ foreach ($order->getCreditmemosCollection() as $previousCreditMemo) {
41
+ /* @var $previousCreditMemo Mage_Sales_Model_Order_Creditmemo */
42
+ if ($previousCreditMemo->getData("base_zitec_dpd_cashondelivery_surcharge")) {
43
+ return $this;
44
+ }
45
+ }
46
+
47
+ // NB. Here we add one to the total tax base. Taxes
48
+ // are added in Zitec_Dpd_Model_Sales_Order_Creditmemo_Total_Tax
49
+ $creditmemo->setData('zitec_dpd_cashondelivery_surcharge', $amount);
50
+
51
+ $baseAmount = $order->getData('base_zitec_dpd_cashondelivery_surcharge');
52
+ $creditmemo->setData('base_zitec_dpd_cashondelivery_surcharge', $baseAmount);
53
+
54
+ $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $amount);
55
+ $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseAmount);
56
+
57
+ }
58
+
59
+ return $this;
60
+ }
61
+
62
  }
app/code/community/Zitec/Dpd/Model/Sales/Order/Creditmemo/Total/Tax.php CHANGED
@@ -1,50 +1,50 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Sales_Order_Creditmemo_Total_Tax extends Mage_Sales_Model_Order_Creditmemo_Total_Tax
25
- {
26
- public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
27
- {
28
-
29
- $result = parent::collect($creditmemo);
30
-
31
- // We added taxes on delivery surcharge
32
- $creditmemo->setData("zitec_dpd_cashondelivery_surcharge_tax", 0);
33
- $creditmemo->setData("base_zitec_dpd_cashondelivery_surcharge_tax", 0);
34
- if ($creditmemo->getData("zitec_dpd_cashondelivery_surcharge")) {
35
- $baseTax = $creditmemo->getOrder()->getData("base_zitec_dpd_cashondelivery_surcharge_tax");
36
- $creditmemo->setData("base_zitec_dpd_cashondelivery_surcharge_tax", $baseTax);
37
- $creditmemo->setBaseTaxAmount($creditmemo->getBaseTaxAmount() + $baseTax);
38
- $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseTax);
39
-
40
- $tax = $creditmemo->getOrder()->getData("zitec_dpd_cashondelivery_surcharge_tax");
41
- $creditmemo->setData("zitec_dpd_cashondelivery_surcharge_tax", $tax);
42
- $creditmemo->setTaxAmount($creditmemo->getTaxAmount() + $tax);
43
- $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $tax);
44
- }
45
-
46
- return $result;
47
- }
48
- }
49
-
50
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Sales_Order_Creditmemo_Total_Tax extends Mage_Sales_Model_Order_Creditmemo_Total_Tax
25
+ {
26
+ public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
27
+ {
28
+
29
+ $result = parent::collect($creditmemo);
30
+
31
+ // We added taxes on delivery surcharge
32
+ $creditmemo->setData("zitec_dpd_cashondelivery_surcharge_tax", 0);
33
+ $creditmemo->setData("base_zitec_dpd_cashondelivery_surcharge_tax", 0);
34
+ if ($creditmemo->getData("zitec_dpd_cashondelivery_surcharge")) {
35
+ $baseTax = $creditmemo->getOrder()->getData("base_zitec_dpd_cashondelivery_surcharge_tax");
36
+ $creditmemo->setData("base_zitec_dpd_cashondelivery_surcharge_tax", $baseTax);
37
+ $creditmemo->setBaseTaxAmount($creditmemo->getBaseTaxAmount() + $baseTax);
38
+ $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseTax);
39
+
40
+ $tax = $creditmemo->getOrder()->getData("zitec_dpd_cashondelivery_surcharge_tax");
41
+ $creditmemo->setData("zitec_dpd_cashondelivery_surcharge_tax", $tax);
42
+ $creditmemo->setTaxAmount($creditmemo->getTaxAmount() + $tax);
43
+ $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $tax);
44
+ }
45
+
46
+ return $result;
47
+ }
48
+ }
49
+
50
+
app/code/community/Zitec/Dpd/Model/Sales/Order/Invoice/Total/Cashondeliverysurchage.php CHANGED
@@ -1,61 +1,61 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Sales_Order_Invoice_Total_Cashondeliverysurchage extends Mage_Sales_Model_Order_Invoice_Total_Abstract
25
- {
26
-
27
- public function collect(Mage_Sales_Model_Order_Invoice $invoice)
28
- {
29
- $invoice->setData('zitec_dpd_cashondelivery_surcharge', 0);
30
- $invoice->setData('base_zitec_dpd_cashondelivery_surcharge', 0);
31
- $invoice->setData('zitec_dpd_cashondelivery_surcharge_tax', 0);
32
- $invoice->setData('base_zitec_dpd_cashondelivery_surcharge_tax', 0);
33
-
34
- $order = $invoice->getOrder();
35
- $amount = $order->getData('zitec_dpd_cashondelivery_surcharge');
36
- if ($amount) {
37
- // We look at the bills to see if it has already claimed the COD surcharge.
38
- foreach ($order->getInvoiceCollection() as $previousInvoice) {
39
- /* @var $previousInvoice Mage_Sales_Model_Order_Invoice */
40
- if (!$previousInvoice->isCanceled() && $previousInvoice->getData('base_zitec_dpd_cashondelivery_surcharge')) {
41
- return $this;
42
- }
43
- }
44
- $invoice->setData('zitec_dpd_cashondelivery_surcharge', $amount);
45
-
46
- $baseAmount = $order->getData('base_zitec_dpd_cashondelivery_surcharge');
47
- $invoice->setData('base_zitec_dpd_cashondelivery_surcharge', $baseAmount);
48
-
49
-
50
- $invoice->setGrandTotal($invoice->getGrandTotal() + $amount);
51
- $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $amount);
52
-
53
- // NB. We do not add taxes grand total here.
54
- // Are added Zitec_Dpd_Model_Sales_Order_Invoice_Total_Tax.
55
-
56
- }
57
-
58
- return $this;
59
- }
60
-
61
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Sales_Order_Invoice_Total_Cashondeliverysurchage extends Mage_Sales_Model_Order_Invoice_Total_Abstract
25
+ {
26
+
27
+ public function collect(Mage_Sales_Model_Order_Invoice $invoice)
28
+ {
29
+ $invoice->setData('zitec_dpd_cashondelivery_surcharge', 0);
30
+ $invoice->setData('base_zitec_dpd_cashondelivery_surcharge', 0);
31
+ $invoice->setData('zitec_dpd_cashondelivery_surcharge_tax', 0);
32
+ $invoice->setData('base_zitec_dpd_cashondelivery_surcharge_tax', 0);
33
+
34
+ $order = $invoice->getOrder();
35
+ $amount = $order->getData('zitec_dpd_cashondelivery_surcharge');
36
+ if ($amount) {
37
+ // We look at the bills to see if it has already claimed the COD surcharge.
38
+ foreach ($order->getInvoiceCollection() as $previousInvoice) {
39
+ /* @var $previousInvoice Mage_Sales_Model_Order_Invoice */
40
+ if (!$previousInvoice->isCanceled() && $previousInvoice->getData('base_zitec_dpd_cashondelivery_surcharge')) {
41
+ return $this;
42
+ }
43
+ }
44
+ $invoice->setData('zitec_dpd_cashondelivery_surcharge', $amount);
45
+
46
+ $baseAmount = $order->getData('base_zitec_dpd_cashondelivery_surcharge');
47
+ $invoice->setData('base_zitec_dpd_cashondelivery_surcharge', $baseAmount);
48
+
49
+
50
+ $invoice->setGrandTotal($invoice->getGrandTotal() + $amount);
51
+ $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $amount);
52
+
53
+ // NB. We do not add taxes grand total here.
54
+ // Are added Zitec_Dpd_Model_Sales_Order_Invoice_Total_Tax.
55
+
56
+ }
57
+
58
+ return $this;
59
+ }
60
+
61
  }
app/code/community/Zitec/Dpd/Model/Sales/Order/Invoice/Total/Tax.php CHANGED
@@ -1,60 +1,60 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Sales_Order_Invoice_Total_Tax extends Mage_Sales_Model_Order_Invoice_Total_Tax
25
- {
26
-
27
- public function collect(Mage_Sales_Model_Order_Invoice $invoice)
28
- {
29
- $result = parent::collect($invoice);
30
- // We added taxes on delivery surcharge
31
-
32
- $invoice->setData("zitec_dpd_cashondelivery_surcharge_tax", 0);
33
- $invoice->setData("base_zitec_dpd_cashondelivery_surcharge_tax", 0);
34
- if ($invoice->getData("zitec_dpd_cashondelivery_surcharge")) {
35
- $baseTax = $invoice->getOrder()->getData("base_zitec_dpd_cashondelivery_surcharge_tax");
36
- $invoice->setData("base_zitec_dpd_cashondelivery_surcharge_tax", $baseTax);
37
-
38
- $tax = $invoice->getOrder()->getData("zitec_dpd_cashondelivery_surcharge_tax");
39
- $invoice->setData("zitec_dpd_cashondelivery_surcharge_tax", $tax);
40
-
41
- // According to the calculations carried out in the parent class, if returned
42
- // True for "isLast" we will already added taxes
43
- // (Including the COD to the total tax and the grand total
44
- // Order). So just in case you return false from
45
- // The call to "isLast" add COD taxes to total.
46
- if (!$invoice->isLast()) {
47
- $invoice->setBaseTaxAmount($invoice->getBaseTaxAmount() + $baseTax);
48
- $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseTax);
49
-
50
- $invoice->setTaxAmount($invoice->getTaxAmount() + $tax);
51
- $invoice->setGrandTotal($invoice->getGrandTotal() + $tax);
52
- }
53
- }
54
-
55
- return $result;
56
-
57
- }
58
- }
59
-
60
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Sales_Order_Invoice_Total_Tax extends Mage_Sales_Model_Order_Invoice_Total_Tax
25
+ {
26
+
27
+ public function collect(Mage_Sales_Model_Order_Invoice $invoice)
28
+ {
29
+ $result = parent::collect($invoice);
30
+ // We added taxes on delivery surcharge
31
+
32
+ $invoice->setData("zitec_dpd_cashondelivery_surcharge_tax", 0);
33
+ $invoice->setData("base_zitec_dpd_cashondelivery_surcharge_tax", 0);
34
+ if ($invoice->getData("zitec_dpd_cashondelivery_surcharge")) {
35
+ $baseTax = $invoice->getOrder()->getData("base_zitec_dpd_cashondelivery_surcharge_tax");
36
+ $invoice->setData("base_zitec_dpd_cashondelivery_surcharge_tax", $baseTax);
37
+
38
+ $tax = $invoice->getOrder()->getData("zitec_dpd_cashondelivery_surcharge_tax");
39
+ $invoice->setData("zitec_dpd_cashondelivery_surcharge_tax", $tax);
40
+
41
+ // According to the calculations carried out in the parent class, if returned
42
+ // True for "isLast" we will already added taxes
43
+ // (Including the COD to the total tax and the grand total
44
+ // Order). So just in case you return false from
45
+ // The call to "isLast" add COD taxes to total.
46
+ if (!$invoice->isLast()) {
47
+ $invoice->setBaseTaxAmount($invoice->getBaseTaxAmount() + $baseTax);
48
+ $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseTax);
49
+
50
+ $invoice->setTaxAmount($invoice->getTaxAmount() + $tax);
51
+ $invoice->setGrandTotal($invoice->getGrandTotal() + $tax);
52
+ }
53
+ }
54
+
55
+ return $result;
56
+
57
+ }
58
+ }
59
+
60
+
app/code/community/Zitec/Dpd/Model/Sales/Order/Pdf/Total/Cashondeliverysurchage.php CHANGED
@@ -1,114 +1,114 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Sales_Order_Pdf_Total_Cashondeliverysurchage extends Mage_Sales_Model_Order_Pdf_Total_Default
25
- {
26
-
27
- public function getTotalsForDisplay()
28
- {
29
- $amount = $this->getOrder()->getData('zitec_dpd_cashondelivery_surcharge');
30
- if (floatval($amount)) {
31
- if ($this->getAmountPrefix()) {
32
- $discount = $this->getAmountPrefix() . $discount;
33
- }
34
-
35
- $title = Mage::getStoreConfig('payment/zitec_dpd_cashondelivery/total_title', $this->getOrder()->getStoreId());
36
- $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
37
-
38
- $totals = array();
39
- if ($this->_displayBoth() || $this->_displayExcludingTax()) {
40
- $totals[] = array(
41
- 'label' => $title . ($this->_displayBoth() ? $this->_getHelper()->__(' (Excl. Tax)') : '') . ':',
42
- 'amount' => $this->getOrder()->formatPriceTxt($amount),
43
- 'font_size' => $fontSize,
44
- );
45
- }
46
-
47
- if ($this->_displayBoth() || $this->_displayIncludingTax()) {
48
- $amount += $this->getOrder()->getData('zitec_dpd_cashondelivery_surcharge_tax');
49
- $totals[] = array(
50
- 'label' => $title . ($this->_displayBoth() ? $this->_getHelper()->__(' (Incl. Tax)') : '') . ':',
51
- 'amount' => $this->getOrder()->formatPriceTxt($amount),
52
- 'font_size' => $fontSize,
53
- );
54
- }
55
-
56
- return $totals;
57
- }
58
- }
59
-
60
- /**
61
- *
62
- * @return boolean
63
- */
64
- protected function _displayBoth()
65
- {
66
- return $this->_getConfig()->displaySalesShippingBoth($this->_getStore());
67
- }
68
-
69
- /**
70
- *
71
- * @return boolean
72
- */
73
- protected function _displayIncludingTax()
74
- {
75
- return $this->_getConfig()->displaySalesShippingInclTax($this->_getStore());
76
- }
77
-
78
- /**
79
- *
80
- * @return boolean
81
- */
82
- protected function _displayExcludingTax()
83
- {
84
- return $this->_getConfig()->displaySalesShippingExclTax($this->_getStore());
85
- }
86
-
87
- /**
88
- *
89
- * @return Mage_Tax_Model_Config
90
- */
91
- protected function _getConfig()
92
- {
93
- return Mage::getSingleton('tax/config');
94
- }
95
-
96
- /**
97
- *
98
- * @return Zitec_Dpd_Helper_Data
99
- */
100
- protected function _getHelper()
101
- {
102
- return Mage::helper('zitec_dpd');
103
- }
104
-
105
- /**
106
- *
107
- * @return Mage_Core_Model_Store
108
- */
109
- protected function _getStore()
110
- {
111
- return $this->getOrder()->getStore();
112
- }
113
-
114
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Sales_Order_Pdf_Total_Cashondeliverysurchage extends Mage_Sales_Model_Order_Pdf_Total_Default
25
+ {
26
+
27
+ public function getTotalsForDisplay()
28
+ {
29
+ $amount = $this->getOrder()->getData('zitec_dpd_cashondelivery_surcharge');
30
+ if (floatval($amount)) {
31
+ if ($this->getAmountPrefix()) {
32
+ $discount = $this->getAmountPrefix() . $discount;
33
+ }
34
+
35
+ $title = Mage::getStoreConfig('payment/zitec_dpd_cashondelivery/total_title', $this->getOrder()->getStoreId());
36
+ $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
37
+
38
+ $totals = array();
39
+ if ($this->_displayBoth() || $this->_displayExcludingTax()) {
40
+ $totals[] = array(
41
+ 'label' => $title . ($this->_displayBoth() ? $this->_getHelper()->__(' (Excl. Tax)') : '') . ':',
42
+ 'amount' => $this->getOrder()->formatPriceTxt($amount),
43
+ 'font_size' => $fontSize,
44
+ );
45
+ }
46
+
47
+ if ($this->_displayBoth() || $this->_displayIncludingTax()) {
48
+ $amount += $this->getOrder()->getData('zitec_dpd_cashondelivery_surcharge_tax');
49
+ $totals[] = array(
50
+ 'label' => $title . ($this->_displayBoth() ? $this->_getHelper()->__(' (Incl. Tax)') : '') . ':',
51
+ 'amount' => $this->getOrder()->formatPriceTxt($amount),
52
+ 'font_size' => $fontSize,
53
+ );
54
+ }
55
+
56
+ return $totals;
57
+ }
58
+ }
59
+
60
+ /**
61
+ *
62
+ * @return boolean
63
+ */
64
+ protected function _displayBoth()
65
+ {
66
+ return $this->_getConfig()->displaySalesShippingBoth($this->_getStore());
67
+ }
68
+
69
+ /**
70
+ *
71
+ * @return boolean
72
+ */
73
+ protected function _displayIncludingTax()
74
+ {
75
+ return $this->_getConfig()->displaySalesShippingInclTax($this->_getStore());
76
+ }
77
+
78
+ /**
79
+ *
80
+ * @return boolean
81
+ */
82
+ protected function _displayExcludingTax()
83
+ {
84
+ return $this->_getConfig()->displaySalesShippingExclTax($this->_getStore());
85
+ }
86
+
87
+ /**
88
+ *
89
+ * @return Mage_Tax_Model_Config
90
+ */
91
+ protected function _getConfig()
92
+ {
93
+ return Mage::getSingleton('tax/config');
94
+ }
95
+
96
+ /**
97
+ *
98
+ * @return Zitec_Dpd_Helper_Data
99
+ */
100
+ protected function _getHelper()
101
+ {
102
+ return Mage::helper('zitec_dpd');
103
+ }
104
+
105
+ /**
106
+ *
107
+ * @return Mage_Core_Model_Store
108
+ */
109
+ protected function _getStore()
110
+ {
111
+ return $this->getOrder()->getStore();
112
+ }
113
+
114
  }
app/code/community/Zitec/Dpd/Model/Sales/Order/Total/Cashondeliverysurchage.php CHANGED
@@ -1,42 +1,42 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Sales_Order_Total_Cashondeliverysurchage extends Mage_Sales_Model_Order_Total_Abstract
25
- {
26
- public function collect(Mage_Sales_Model_Order $order)
27
- {
28
- $order->setData('zitec_dpd_cashondelivery_surcharge', 0);
29
- $order->setData('base_zitec_dpd_cashondelivery_surcharge', 0);
30
-
31
- $amount = $order->getOrder()->getData('zitec_dpd_cashondelivery_surcharge');
32
- $order->setData('zitec_dpd_cashondelivery_surcharge', $amount);
33
-
34
- $amount = $order->getOrder()->getData('base_zitec_dpd_cashondelivery_surcharge');
35
- $order->setData('base_zitec_dpd_cashondelivery_surcharge', $amount);
36
-
37
- $order->setGrandTotal($order->getGrandTotal() + $order->getData('zitec_dpd_cashondelivery_surcharge'));
38
- $order->setBaseGrandTotal($order->getBaseGrandTotal() + $order->getData('base_zitec_dpd_cashondelivery_surcharge'));
39
-
40
- return $this;
41
- }
42
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Sales_Order_Total_Cashondeliverysurchage extends Mage_Sales_Model_Order_Total_Abstract
25
+ {
26
+ public function collect(Mage_Sales_Model_Order $order)
27
+ {
28
+ $order->setData('zitec_dpd_cashondelivery_surcharge', 0);
29
+ $order->setData('base_zitec_dpd_cashondelivery_surcharge', 0);
30
+
31
+ $amount = $order->getOrder()->getData('zitec_dpd_cashondelivery_surcharge');
32
+ $order->setData('zitec_dpd_cashondelivery_surcharge', $amount);
33
+
34
+ $amount = $order->getOrder()->getData('base_zitec_dpd_cashondelivery_surcharge');
35
+ $order->setData('base_zitec_dpd_cashondelivery_surcharge', $amount);
36
+
37
+ $order->setGrandTotal($order->getGrandTotal() + $order->getData('zitec_dpd_cashondelivery_surcharge'));
38
+ $order->setBaseGrandTotal($order->getBaseGrandTotal() + $order->getData('base_zitec_dpd_cashondelivery_surcharge'));
39
+
40
+ return $this;
41
+ }
42
  }
app/code/community/Zitec/Dpd/Model/Sales/Quote/Address/Total/Cashondeliverysurchage.php CHANGED
@@ -1,183 +1,183 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Sales_Quote_Address_Total_Cashondeliverysurchage extends Mage_Sales_Model_Quote_Address_Total_Abstract
25
- {
26
- public function __construct()
27
- {
28
- $this->setCode('zitec_dpd_cashondelivery_surcharge');
29
- }
30
-
31
- public function collect(Mage_Sales_Model_Quote_Address $address)
32
- {
33
- $address->setData('zitec_dpd_cashondelivery_surcharge', 0);
34
- $address->setData('base_zitec_dpd_cashondelivery_surcharge', 0);
35
- $address->setData('zitec_dpd_cashondelivery_surcharge_tax', 0);
36
- $address->setData('base_zitec_dpd_cashondelivery_surcharge_tax', 0);
37
-
38
- $paymentMethod = $address->getQuote()->getPayment()->getMethod();
39
-
40
- if ($paymentMethod == Mage::helper('zitec_dpd')->getDpdPaymentCode() && $address->getAddressType() == 'shipping') {
41
- $quote = $address->getQuote();
42
- /* @var $quote Mage_Sales_Model_Quote */
43
- $shippingAddress = $quote->getShippingAddress();
44
-
45
- $request = new Varien_Object();
46
- $request->setWebsiteId(Mage::helper('zitec_dpd/payment')->getWebsiteId());
47
- $request->setDestCountryId($shippingAddress->getCountryId());
48
- $request->setDestRegionId($shippingAddress->getRegionId());
49
- $request->setDestPostcode($shippingAddress->getPostcode());
50
- $request->setPackageWeight($shippingAddress->getWeight());
51
- if ($this->_getTaxHelper()->shippingPriceIncludesTax($address->getQuote()->getStoreId())) {
52
- $request->setData('zitec_table_price', $shippingAddress->getBaseSubtotalInclTax());
53
- } else {
54
- $request->setData('zitec_table_price', $shippingAddress->getBaseSubtotal());
55
- }
56
- $request->setMethod(str_replace(Mage::helper('zitec_dpd')->getDPDCarrierCode() . '_', '', $shippingAddress->getShippingMethod()));
57
- $tablerateSurcharge = Mage::getResourceModel('zitec_dpd/carrier_tablerate')->getCashOnDeliverySurcharge($request);
58
-
59
- if (is_null($tablerateSurcharge)) {
60
- return $this;
61
- } elseif (!empty($tablerateSurcharge)) {
62
- $baseCashondeliverySurcharge = $this->_getHelper()->calculateQuoteBaseCashOnDeliverySurcharge($quote, $tablerateSurcharge);
63
- } else {
64
- $baseCashondeliverySurcharge = $this->_getHelper()->returnDefaultBaseCashOnDeliverySurcharge($quote);
65
- }
66
-
67
- if (!isset($baseCashondeliverySurcharge)) {
68
- return $this;
69
- }
70
-
71
- $baseCurrencyCode = $quote->getStore()->getBaseCurrencyCode();
72
- $currentCurrencyCode = $quote->getStore()->getCurrentCurrencyCode();
73
- $cashondeliverySurcharge = Mage::helper('directory')->currencyConvert($baseCashondeliverySurcharge, $baseCurrencyCode, $currentCurrencyCode);
74
- $address->setData('zitec_dpd_cashondelivery_surcharge', $cashondeliverySurcharge);
75
- $address->setData('base_zitec_dpd_cashondelivery_surcharge', $baseCashondeliverySurcharge);
76
- $this->_calculateSurchargeSalesTax($address);
77
- $quote->save();
78
- }
79
-
80
- $address->setGrandTotal($address->getGrandTotal() + $address->getData('zitec_dpd_cashondelivery_surcharge'));
81
- $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getData('base_zitec_dpd_cashondelivery_surcharge'));
82
-
83
- return $this;
84
- }
85
-
86
- /**
87
- *
88
- * @param Mage_Sales_Model_Quote_Address $address
89
- *
90
- * @return \Zitec_Dpd_Model_Sales_Quote_Address_Total_Cashondeliverysurchage
91
- */
92
- protected function _calculateSurchargeSalesTax(Mage_Sales_Model_Quote_Address $address)
93
- {
94
-
95
- $taxCalculator = Mage::getSingleton('tax/calculation');
96
- /* @var $taxCalculator Mage_Tax_Model_Calculation */
97
- $customer = $address->getQuote()->getCustomer();
98
- if ($customer) {
99
- $taxCalculator->setCustomer($customer);
100
- }
101
-
102
- $store = $address->getQuote()->getStore();
103
- $request = $taxCalculator->getRateRequest(
104
- $address,
105
- $address->getQuote()->getBillingAddress(),
106
- $address->getQuote()->getCustomerTaxClassId(),
107
- $store
108
- );
109
- $taxConfig = Mage::getSingleton('tax/config');
110
- /* @var $taxConfig Mage_Tax_Model_Config */
111
- $request->setProductClassId($taxConfig->getShippingTaxClass($store));
112
-
113
- $rate = $taxCalculator->getRate($request);
114
- $inclTax = $taxConfig->shippingPriceIncludesTax($store);
115
- $surcharge = $address->getData('zitec_dpd_cashondelivery_surcharge');
116
- $baseSurcharge = $address->getData('base_zitec_dpd_cashondelivery_surcharge');
117
-
118
- // NOTA: Mira el comentario de 25 abr 2013 10:45 en #43 de collab.
119
- $surchargeTax = $taxCalculator->calcTaxAmount($surcharge, $rate, $inclTax, true);
120
- $baseSurchargeTax = $taxCalculator->calcTaxAmount($baseSurcharge, $rate, $inclTax, true);
121
-
122
- $address->setExtraTaxAmount($address->getExtraTaxAmount() + $surchargeTax);
123
- $address->setBaseExtraTaxAmount($address->getBaseExtraTaxAmount() + $baseSurchargeTax);
124
-
125
- $address->setData('zitec_dpd_cashondelivery_surcharge_tax', $surchargeTax);
126
- $address->setData('base_zitec_dpd_cashondelivery_surcharge_tax', $baseSurchargeTax);
127
-
128
- if ($inclTax) {
129
- $address->setData('zitec_dpd_cashondelivery_surcharge', $surcharge - $surchargeTax);
130
- $address->setData('base_zitec_dpd_cashondelivery_surcharge', $baseSurcharge - $baseSurchargeTax);
131
- }
132
-
133
- return $this;
134
- }
135
-
136
- /**
137
- *
138
- * @return Mage_Tax_Helper_Data
139
- */
140
- protected function _getTaxHelper()
141
- {
142
- return Mage::helper('tax');
143
- }
144
-
145
- public function fetch(Mage_Sales_Model_Quote_Address $address)
146
- {
147
- $amount = $address->getData('zitec_dpd_cashondelivery_surcharge');
148
-
149
- if ($amount != 0 && $address->getAddressType() == 'shipping') {
150
- $title = Mage::getStoreConfig('payment/zitec_dpd_cashondelivery/total_title', $address->getQuote()->getStore());
151
-
152
- $address->addTotal(array(
153
- 'code' => $this->getCode(),
154
- 'title' => $title,
155
- 'value' => $amount
156
- ));
157
- }
158
-
159
- return $this;
160
- }
161
-
162
- /**
163
- * Get label
164
- *
165
- * @return string
166
- */
167
- public function getLabel()
168
- {
169
- $title = Mage::getStoreConfig('payment/zitec_dpd_cashondelivery/total_title');
170
-
171
- return $title;
172
- }
173
-
174
- /**
175
- *
176
- * @return Zitec_Dpd_Helper_Data
177
- */
178
- protected function _getHelper()
179
- {
180
- return Mage::helper('zitec_dpd');
181
- }
182
-
183
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Sales_Quote_Address_Total_Cashondeliverysurchage extends Mage_Sales_Model_Quote_Address_Total_Abstract
25
+ {
26
+ public function __construct()
27
+ {
28
+ $this->setCode('zitec_dpd_cashondelivery_surcharge');
29
+ }
30
+
31
+ public function collect(Mage_Sales_Model_Quote_Address $address)
32
+ {
33
+ $address->setData('zitec_dpd_cashondelivery_surcharge', 0);
34
+ $address->setData('base_zitec_dpd_cashondelivery_surcharge', 0);
35
+ $address->setData('zitec_dpd_cashondelivery_surcharge_tax', 0);
36
+ $address->setData('base_zitec_dpd_cashondelivery_surcharge_tax', 0);
37
+
38
+ $paymentMethod = $address->getQuote()->getPayment()->getMethod();
39
+
40
+ if ($paymentMethod == Mage::helper('zitec_dpd')->getDpdPaymentCode() && $address->getAddressType() == 'shipping') {
41
+ $quote = $address->getQuote();
42
+ /* @var $quote Mage_Sales_Model_Quote */
43
+ $shippingAddress = $quote->getShippingAddress();
44
+
45
+ $request = new Varien_Object();
46
+ $request->setWebsiteId(Mage::helper('zitec_dpd/payment')->getWebsiteId());
47
+ $request->setDestCountryId($shippingAddress->getCountryId());
48
+ $request->setDestRegionId($shippingAddress->getRegionId());
49
+ $request->setDestPostcode($shippingAddress->getPostcode());
50
+ $request->setPackageWeight($shippingAddress->getWeight());
51
+ if ($this->_getTaxHelper()->shippingPriceIncludesTax($address->getQuote()->getStoreId())) {
52
+ $request->setData('zitec_table_price', $shippingAddress->getBaseSubtotalInclTax());
53
+ } else {
54
+ $request->setData('zitec_table_price', $shippingAddress->getBaseSubtotal());
55
+ }
56
+ $request->setMethod(str_replace(Mage::helper('zitec_dpd')->getDPDCarrierCode() . '_', '', $shippingAddress->getShippingMethod()));
57
+ $tablerateSurcharge = Mage::getResourceModel('zitec_dpd/carrier_tablerate')->getCashOnDeliverySurcharge($request);
58
+
59
+ if (is_null($tablerateSurcharge)) {
60
+ return $this;
61
+ } elseif (!empty($tablerateSurcharge)) {
62
+ $baseCashondeliverySurcharge = $this->_getHelper()->calculateQuoteBaseCashOnDeliverySurcharge($quote, $tablerateSurcharge);
63
+ } else {
64
+ $baseCashondeliverySurcharge = $this->_getHelper()->returnDefaultBaseCashOnDeliverySurcharge($quote);
65
+ }
66
+
67
+ if (!isset($baseCashondeliverySurcharge)) {
68
+ return $this;
69
+ }
70
+
71
+ $baseCurrencyCode = $quote->getStore()->getBaseCurrencyCode();
72
+ $currentCurrencyCode = $quote->getStore()->getCurrentCurrencyCode();
73
+ $cashondeliverySurcharge = Mage::helper('directory')->currencyConvert($baseCashondeliverySurcharge, $baseCurrencyCode, $currentCurrencyCode);
74
+ $address->setData('zitec_dpd_cashondelivery_surcharge', $cashondeliverySurcharge);
75
+ $address->setData('base_zitec_dpd_cashondelivery_surcharge', $baseCashondeliverySurcharge);
76
+ $this->_calculateSurchargeSalesTax($address);
77
+ $quote->save();
78
+ }
79
+
80
+ $address->setGrandTotal($address->getGrandTotal() + $address->getData('zitec_dpd_cashondelivery_surcharge'));
81
+ $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getData('base_zitec_dpd_cashondelivery_surcharge'));
82
+
83
+ return $this;
84
+ }
85
+
86
+ /**
87
+ *
88
+ * @param Mage_Sales_Model_Quote_Address $address
89
+ *
90
+ * @return \Zitec_Dpd_Model_Sales_Quote_Address_Total_Cashondeliverysurchage
91
+ */
92
+ protected function _calculateSurchargeSalesTax(Mage_Sales_Model_Quote_Address $address)
93
+ {
94
+
95
+ $taxCalculator = Mage::getSingleton('tax/calculation');
96
+ /* @var $taxCalculator Mage_Tax_Model_Calculation */
97
+ $customer = $address->getQuote()->getCustomer();
98
+ if ($customer) {
99
+ $taxCalculator->setCustomer($customer);
100
+ }
101
+
102
+ $store = $address->getQuote()->getStore();
103
+ $request = $taxCalculator->getRateRequest(
104
+ $address,
105
+ $address->getQuote()->getBillingAddress(),
106
+ $address->getQuote()->getCustomerTaxClassId(),
107
+ $store
108
+ );
109
+ $taxConfig = Mage::getSingleton('tax/config');
110
+ /* @var $taxConfig Mage_Tax_Model_Config */
111
+ $request->setProductClassId($taxConfig->getShippingTaxClass($store));
112
+
113
+ $rate = $taxCalculator->getRate($request);
114
+ $inclTax = $taxConfig->shippingPriceIncludesTax($store);
115
+ $surcharge = $address->getData('zitec_dpd_cashondelivery_surcharge');
116
+ $baseSurcharge = $address->getData('base_zitec_dpd_cashondelivery_surcharge');
117
+
118
+ // NOTA: Mira el comentario de 25 abr 2013 10:45 en #43 de collab.
119
+ $surchargeTax = $taxCalculator->calcTaxAmount($surcharge, $rate, $inclTax, true);
120
+ $baseSurchargeTax = $taxCalculator->calcTaxAmount($baseSurcharge, $rate, $inclTax, true);
121
+
122
+ $address->setExtraTaxAmount($address->getExtraTaxAmount() + $surchargeTax);
123
+ $address->setBaseExtraTaxAmount($address->getBaseExtraTaxAmount() + $baseSurchargeTax);
124
+
125
+ $address->setData('zitec_dpd_cashondelivery_surcharge_tax', $surchargeTax);
126
+ $address->setData('base_zitec_dpd_cashondelivery_surcharge_tax', $baseSurchargeTax);
127
+
128
+ if ($inclTax) {
129
+ $address->setData('zitec_dpd_cashondelivery_surcharge', $surcharge - $surchargeTax);
130
+ $address->setData('base_zitec_dpd_cashondelivery_surcharge', $baseSurcharge - $baseSurchargeTax);
131
+ }
132
+
133
+ return $this;
134
+ }
135
+
136
+ /**
137
+ *
138
+ * @return Mage_Tax_Helper_Data
139
+ */
140
+ protected function _getTaxHelper()
141
+ {
142
+ return Mage::helper('tax');
143
+ }
144
+
145
+ public function fetch(Mage_Sales_Model_Quote_Address $address)
146
+ {
147
+ $amount = $address->getData('zitec_dpd_cashondelivery_surcharge');
148
+
149
+ if ($amount != 0 && $address->getAddressType() == 'shipping') {
150
+ $title = Mage::getStoreConfig('payment/zitec_dpd_cashondelivery/total_title', $address->getQuote()->getStore());
151
+
152
+ $address->addTotal(array(
153
+ 'code' => $this->getCode(),
154
+ 'title' => $title,
155
+ 'value' => $amount
156
+ ));
157
+ }
158
+
159
+ return $this;
160
+ }
161
+
162
+ /**
163
+ * Get label
164
+ *
165
+ * @return string
166
+ */
167
+ public function getLabel()
168
+ {
169
+ $title = Mage::getStoreConfig('payment/zitec_dpd_cashondelivery/total_title');
170
+
171
+ return $title;
172
+ }
173
+
174
+ /**
175
+ *
176
+ * @return Zitec_Dpd_Helper_Data
177
+ */
178
+ protected function _getHelper()
179
+ {
180
+ return Mage::helper('zitec_dpd');
181
+ }
182
+
183
  }
app/code/community/Zitec/Dpd/Model/Shipping/Carrier/Abstract.php CHANGED
@@ -1,88 +1,88 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- abstract class Zitec_Dpd_Model_Shipping_Carrier_Abstract extends Mage_Shipping_Model_Carrier_Abstract
25
- {
26
- protected $_numBoxes = 1;
27
-
28
-
29
- /**
30
- * Check if carrier has shipping label option available
31
- *
32
- * @return boolean
33
- */
34
- public function isShippingLabelsAvailable()
35
- {
36
- return true;
37
- }
38
-
39
-
40
- public function isTrackingAvailable()
41
- {
42
- return true;
43
- }
44
-
45
- public function isCityRequired()
46
- {
47
- return true;
48
- }
49
-
50
- public function isZipCodeRequired($countryId = null)
51
- {
52
- return true;
53
- }
54
-
55
- public function getTotalNumOfBoxes($weight)
56
- {
57
- /*
58
- reset num box first before retrieve again
59
- */
60
- $this->_numBoxes = 1;
61
- //$weight = $this->convertWeightToLbs($weight);
62
- $maxPackageWeight = $this->getConfigData('max_package_weight');
63
- if ($weight > $maxPackageWeight && $maxPackageWeight != 0) {
64
- $this->_numBoxes = ceil($weight / $maxPackageWeight);
65
- $weight = $weight / $this->_numBoxes;
66
- }
67
-
68
- return $weight;
69
- }
70
-
71
- /**
72
- *
73
- * @return Zitec_Dpd_Helper_Data
74
- */
75
- protected function _getHelper()
76
- {
77
- return Mage::helper('zitec_dpd');
78
- }
79
-
80
- /**
81
- *
82
- * @return Zitec_Dpd_Helper_Ws
83
- */
84
- protected function _getWsHelper()
85
- {
86
- return Mage::helper('zitec_dpd/ws');
87
- }
88
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ abstract class Zitec_Dpd_Model_Shipping_Carrier_Abstract extends Mage_Shipping_Model_Carrier_Abstract
25
+ {
26
+ protected $_numBoxes = 1;
27
+
28
+
29
+ /**
30
+ * Check if carrier has shipping label option available
31
+ *
32
+ * @return boolean
33
+ */
34
+ public function isShippingLabelsAvailable()
35
+ {
36
+ return true;
37
+ }
38
+
39
+
40
+ public function isTrackingAvailable()
41
+ {
42
+ return true;
43
+ }
44
+
45
+ public function isCityRequired()
46
+ {
47
+ return true;
48
+ }
49
+
50
+ public function isZipCodeRequired($countryId = null)
51
+ {
52
+ return true;
53
+ }
54
+
55
+ public function getTotalNumOfBoxes($weight)
56
+ {
57
+ /*
58
+ reset num box first before retrieve again
59
+ */
60
+ $this->_numBoxes = 1;
61
+ //$weight = $this->convertWeightToLbs($weight);
62
+ $maxPackageWeight = $this->getConfigData('max_package_weight');
63
+ if ($weight > $maxPackageWeight && $maxPackageWeight != 0) {
64
+ $this->_numBoxes = ceil($weight / $maxPackageWeight);
65
+ $weight = $weight / $this->_numBoxes;
66
+ }
67
+
68
+ return $weight;
69
+ }
70
+
71
+ /**
72
+ *
73
+ * @return Zitec_Dpd_Helper_Data
74
+ */
75
+ protected function _getHelper()
76
+ {
77
+ return Mage::helper('zitec_dpd');
78
+ }
79
+
80
+ /**
81
+ *
82
+ * @return Zitec_Dpd_Helper_Ws
83
+ */
84
+ protected function _getWsHelper()
85
+ {
86
+ return Mage::helper('zitec_dpd/ws');
87
+ }
88
  }
app/code/community/Zitec/Dpd/Model/Shipping/Carrier/Dpd.php CHANGED
@@ -1,542 +1,542 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Model_Shipping_Carrier_Dpd extends Zitec_Dpd_Model_Shipping_Carrier_Abstract implements Zitec_PackedShipment_Model_Carrier_Interface
25
- {
26
- const CARRIER_CODE = 'zitecDpd';
27
- protected $_code = 'zitecDpd';
28
-
29
- public function getAllowedMethods()
30
- {
31
- $optionsMethods = Mage::getSingleton('zitec_dpd/config_source_service')->toOptionArray(true);
32
-
33
- $result = array();
34
- foreach ($optionsMethods as $method) {
35
- $result[$method['value']] = $method['label'];
36
- }
37
-
38
- return $result;
39
- }
40
-
41
- /**
42
- * Collect and get rates
43
- *
44
- * @param Mage_Shipping_Model_Rate_Request $request
45
- *
46
- * @return Mage_Shipping_Model_Rate_Result|bool|null
47
- */
48
- public function collectRates(Mage_Shipping_Model_Rate_Request $request)
49
- {
50
- if (!$this->_canCollectRates($request)) {
51
- return false;
52
- }
53
-
54
- // Recalculate the package value excluding any virtual products.
55
- if (!$this->getConfigFlag('include_virtual_price')) {
56
- $request->setPackageValue($request->getPackagePhysicalValue());
57
- }
58
-
59
- // Free shipping by qty
60
- $freeQty = 0;
61
- $totalPriceInclTax = 0;
62
- $totalPriceExclTax = 0;
63
- foreach ($request->getAllItems() as $item) {
64
- $totalPriceInclTax += $item->getBaseRowTotalInclTax();
65
- $totalPriceExclTax += $item->getBaseRowTotal();
66
-
67
- if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
68
- continue;
69
- }
70
-
71
- if ($item->getHasChildren() && $item->isShipSeparately()) {
72
- foreach ($item->getChildren() as $child) {
73
- if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
74
- $freeQty += $item->getQty() * ($child->getQty() - (is_numeric($child->getFreeShipping()) ? $child->getFreeShipping() : 0));
75
- }
76
- }
77
- } elseif ($item->getFreeShipping()) {
78
- $freeQty += ($item->getQty() - (is_numeric($item->getFreeShipping()) ? $item->getFreeShipping() : 0));
79
- }
80
- }
81
-
82
- // Package weight and qty free shipping
83
- $oldWeight = $request->getPackageWeight();
84
- $oldQty = $request->getPackageQty();
85
- $oldPrice = $request->getPackageValue();
86
-
87
- $request->setPackageWeight($request->getFreeMethodWeight());
88
- $request->setPackageQty($oldQty - $freeQty);
89
- $request->setPackageValue($totalPriceInclTax);
90
-
91
- $this->_updateFreeMethodQuote($request);
92
-
93
- // The shipping price calculations for price vs destination is included.
94
- if ($this->_getTaxHelper()->shippingPriceIncludesTax($request->getStoreId())) {
95
- $request->setData('zitec_table_price', $totalPriceInclTax);
96
- } else {
97
- $request->setData('zitec_table_price', $totalPriceExclTax);
98
- }
99
-
100
- $rate = $this->getRate($request);
101
-
102
- $request->setPackageWeight($oldWeight);
103
- $request->setPackageQty($oldQty);
104
- $request->setPackageValue($oldPrice);
105
-
106
- $isFree = false;
107
- $freeShippingPrice = ($this->getConfigFlag('free_shipping_subtotal_tax_incl')) ? $totalPriceInclTax : $oldPrice;
108
- $freeShippingSubtotal = $this->getConfigData('free_shipping_subtotal');
109
- $freeShippingEnabled = $this->getConfigFlag('free_shipping_enable');
110
- $freeShipping = ($freeShippingEnabled && $freeShippingPrice >= $freeShippingSubtotal) ? true : false;
111
- if ($request->getFreeShipping() === true || $freeShipping) {
112
- $isFree = true;
113
- }
114
-
115
- $result = Mage::getModel('shipping/rate_result');
116
- /* @var $result Mage_Shipping_Model_Rate_Result */
117
-
118
- if (count($rate) == 0) {
119
- return false;
120
- }
121
-
122
- $methods = array();
123
- foreach ($rate as $r) {
124
- // Before adding the rate, we check that it is active in the admin configuration.
125
- if (!$this->_isRateAllowedByAdminConfiguration($r)) {
126
- continue;
127
- }
128
-
129
- //There can be multiple rate the same method, but is first applicable.
130
- //If we have already considered a rate of this method, we again evaluate
131
- //(the other will be for weights / lower prices) or for more general conditions.
132
-
133
- $dpdMethod = $r['method'];
134
- if (in_array($dpdMethod, $methods)) {
135
- continue;
136
- }
137
- $methods[] = $dpdMethod;
138
-
139
- $method = Mage::getModel('shipping/rate_result_method');
140
-
141
- $method->setCarrier($this->_code);
142
- $method->setCarrierTitle($this->getConfigData('title'));
143
- $price = $this->_calculateDPDPrice($r, $request);
144
- if ($price === false) {
145
- continue;
146
- }
147
- $method->setPrice($price);
148
- $method->setCost($price);
149
- $method->setMethod($dpdMethod);
150
- $methodDescriptions = Mage::getSingleton('zitec_dpd/config_source_service')->toOptionArray();
151
- $methodTitle = $methodDescriptions[$dpdMethod];
152
- $method->setMethodTitle($methodTitle);
153
-
154
- $result->append($method);
155
- }
156
-
157
- if ($isFree) {
158
- $cheapest = $result->getCheapestRate();
159
- if (!empty($cheapest)) {
160
- $cheapest->setPrice('0.00');
161
- $title = $cheapest->getMethodTitle() . ' (' . Mage::helper('shipping')->__('Free') . ')';
162
- $cheapest->setMethodTitle($title);
163
- $result->reset();
164
- $result->append($cheapest);
165
- }
166
- }
167
-
168
- return $result;
169
- }
170
-
171
- /**
172
- * @param Mage_Shipping_Model_Rate_Request $request
173
- *
174
- * @return bool
175
- */
176
- protected function _canCollectRates(Mage_Shipping_Model_Rate_Request $request)
177
- {
178
- if (!$this->getConfigFlag('active')) {
179
- return false;
180
- }
181
-
182
- // Exclude empty carts
183
- if (!$request->getAllItems()) {
184
- return false;
185
- }
186
-
187
- // Exclude carts containing products with no defined weight or where the
188
- // total weight of the cart is zero (virtual products only).
189
- if ($this->_cartContainsProductsOfZeroWeightOrWeighsNothing($request->getAllItems())) {
190
- return false;
191
- }
192
-
193
- return true;
194
- }
195
-
196
- /**
197
- *
198
- * @return Mage_Tax_Helper_Data
199
- */
200
- protected function _getTaxHelper()
201
- {
202
- return Mage::helper('tax');
203
- }
204
-
205
- /**
206
- * Returns true if the cart contains items with no defined weight or the
207
- * whole cart weighs nothing.
208
- *
209
- * @param array $itemsInCart
210
- *
211
- * @return boolean
212
- */
213
- protected function _cartContainsProductsOfZeroWeightOrWeighsNothing($itemsInCart)
214
- {
215
-
216
- if (!$itemsInCart) {
217
- return true;
218
- }
219
-
220
- $cartContainsNonVirtualItems = false;
221
-
222
- foreach ($itemsInCart as $item) {
223
- if ($item->getParentItem()) {
224
- continue;
225
- }
226
-
227
-
228
- if ($item->getHasChildren() && $item->isShipSeparately()) {
229
- foreach ($item->getChildren() as $child) {
230
- if (!$child->getProduct()->isVirtual()) {
231
- if (!$child->getWeight() || ($child->getWeight() == 0)) {
232
- return true;
233
- }
234
- $cartContainsNonVirtualItems = true;
235
- }
236
- }
237
- } elseif (!$item->getProduct()->isVirtual()) {
238
- if (!$item->getWeight() || ($item->getWeight() == 0)) {
239
- return true;
240
- }
241
- $cartContainsNonVirtualItems = true;
242
- }
243
- }
244
-
245
- if ($cartContainsNonVirtualItems) {
246
- return false;
247
- } else {
248
- return true; // All items in cart are virtual
249
- }
250
- }
251
-
252
- /**
253
- *
254
- * @param Mage_Shipping_Model_Rate_Request $request
255
- *
256
- * @return array
257
- */
258
- public function getRate(Mage_Shipping_Model_Rate_Request $request)
259
- {
260
- $rates = Mage::getResourceModel('zitec_dpd/carrier_tablerate')->getRate($request);
261
-
262
- return $rates;
263
- }
264
-
265
- /**
266
- *
267
- * @param array $shippingRate
268
- *
269
- * @return boolean
270
- */
271
- protected function _isRateAllowedByAdminConfiguration($shippingRate)
272
- {
273
-
274
- $availableMethods = explode(',', $this->getconfigData('services'));
275
-
276
- return in_array($shippingRate['method'], $availableMethods);
277
- }
278
-
279
- /**
280
- * We calculate the shipping price based on the price / rate mentioned in
281
- * the rates table. If a "markup_type" (percent) indicated we travel to DPD WS
282
- * to calculate the final price based on the shipping cost with
283
- * his ws. If the price / percentage is less than zero indicates that the rate is not available.
284
- *
285
- * @param array $rate
286
- * @param Mage_Shipping_Model_Rate_Request $request
287
- *
288
- * @return array|boolean
289
- */
290
- protected function _calculateDPDPrice(array $rate, Mage_Shipping_Model_Rate_Request $request)
291
- {
292
-
293
- if (!$rate['markup_type']) {
294
- if ($rate['price'] >= 0) {
295
- return $rate['price'];
296
- } else {
297
- return false;
298
- }
299
- }
300
-
301
- $apiParams = $this->_getWsHelper()->getShipmentParams($request->getStoreId());
302
- $apiParams['method'] = Zitec_Dpd_Api_Configs::METHOD_SHIPMENT_CALCULATE_PRICE;
303
-
304
- try {
305
- $dpdApi = new Zitec_Dpd_Api($apiParams);
306
- $calculatePrice = $dpdApi->getApiMethodObject();
307
-
308
- $postCode = Mage::helper('zitec_dpd/postcode_search')->extractPostCodeForShippingRequest($request);
309
-
310
- $calculatePrice->setReceiverAddress($request->getDestStreet(), $request->getDestCity(), $postCode, $request->getDestCountryId())
311
- ->addParcel($request->getPackageWeight())
312
- ->setShipmentServiceCode($rate['method']);
313
-
314
- $insurance = Mage::helper('zitec_dpd')->extractInsuranceValuesByRequest($request);
315
- $calculatePrice = $calculatePrice->setAdditionalHighInsurance($insurance['goodsValue'], $insurance['currency'], $insurance['content']);
316
-
317
- $calculatePrice->execute();
318
- } catch (Exception $e) {
319
- $this->_getHelper()->log("An error occurred whilst calculating the DPD price for the shipment {$e->getMessage()}");
320
-
321
- return false;
322
- }
323
-
324
- $response = $calculatePrice->getCalculatePriceResponse();
325
- if ($response->hasError()) {
326
- $this->_getHelper()->log("DPD returned the following error whilst attempting to calculate the price of a shipment: {$response->getErrorText()}");
327
-
328
- return false;
329
- }
330
-
331
-
332
- if ($request->getBaseCurrency()->getCode() == $response->getCurrency()) {
333
- $dpdPrice = $response->getAmount();
334
- } else if ($request->getBaseCurrency()->getCode() == $response->getCurrencyLocal()) {
335
- $dpdPrice = $response->getAmountLocal();
336
- } else {
337
- $this->_getHelper()->log("An error occurred whilst calculating the price of a shipment. The currency of the shipment ({$request->getBaseCurrency()->getCode()}) does not correspond to the currency ({$response->getCurrency()}) or the local currency ({$response->getCurrencyLocal()}) used by DPD. ");
338
-
339
- return false;
340
- }
341
- if ($rate['markup_type'] == 1) {
342
- return $dpdPrice * (1 + ($rate['price'] / 100));
343
- } else {
344
- return $dpdPrice + round(floatval($rate['price']), 2);
345
- }
346
- }
347
-
348
- public function getCitiesForPostcode($postcode, &$errorMsg)
349
- {
350
-
351
- }
352
-
353
- public function getPostcodesForCity($city, &$errorMsg)
354
- {
355
-
356
- }
357
-
358
- /**
359
- *
360
- * @param Mage_Sales_Model_Order $order
361
- * @param string $city
362
- * @param string $postcode
363
- * @param array $weightsPackages
364
- * @param string $errorStr
365
- *
366
- * @return double
367
- */
368
- public function getShippingCost(Mage_Sales_Model_Order $order, $city, $postcode, $weightsPackages, &$errorStr)
369
- {
370
- $shippingAddress = $order->getShippingAddress();
371
- $city = $city ? $city : $shippingAddress->getCity();
372
- $postcode = $postcode ? $postcode : $shippingAddress->getPostcode();
373
- $serviceCode = $this->_getHelper()->getDPDServiceCode($order->getShippingMethod());
374
- $street = is_array($shippingAddress->getStreetFull()) ? implode("\n", $shippingAddress->getStreetFull()) : $shippingAddress->getStreetFull();
375
-
376
- $apiParams = $this->_getWsHelper()->getShipmentParams($order->getStore());
377
- $apiParams['method'] = Zitec_Dpd_Api_Configs::METHOD_SHIPMENT_CALCULATE_PRICE;
378
-
379
-
380
- try {
381
- $dpdApi = new Zitec_Dpd_Api($apiParams);
382
- $calculatePrice = $dpdApi->getApiMethodObject();
383
-
384
-
385
- $calculatePrice->setReceiverAddress($street, $city, $postcode, $shippingAddress->getCountryId())
386
- ->setShipmentServiceCode($serviceCode);
387
-
388
- foreach ($weightsPackages as $parcelWeight) {
389
- $calculatePrice->addParcel($parcelWeight);
390
- }
391
-
392
- $insurance = Mage::helper('zitec_dpd')->extractInsuranceValuesByOrder($order);
393
- $calculatePrice = $calculatePrice->setAdditionalHighInsurance($insurance['goodsValue'], $insurance['currency'], $insurance['content']);
394
-
395
- $calculatePrice->execute();
396
- } catch (Exception $e) {
397
- $errorStr = $this->_getHelper()->__("Error obtaining shipping price: %s", $e->getMessage());
398
- $this->_getHelper()->log("An error occurred whilst calculating the DPD price for the shipment {$e->getMessage()}");
399
-
400
- return 0;
401
- }
402
-
403
- $response = $calculatePrice->getCalculatePriceResponse();
404
- if ($response->hasError()) {
405
- $errorStr = $this->_getHelper()->__("DPD error: %s", $response->getErrorText());
406
- $this->_getHelper()->log("DPD returned the following error whilst attempting to calculate the price of a shipment: {$response->getErrorText()}");
407
-
408
- return 0;
409
- }
410
-
411
-
412
- if ($order->getBaseCurrencyCode() == $response->getCurrency()) {
413
- return $response->getAmount();
414
- } else if ($order->getBaseCurrencyCode() == $response->getCurrencyLocal()) {
415
- return $response->getAmountLocal();
416
- } else {
417
- $errorStr = $this->_getHelper()->__("Shipping price not available in order currency");
418
- $this->_getHelper()->log("An error occurred whilst calculating the price of a shipment. The base currency of the shipment ({$order->getBaseCurrencyCode()}) does not correspond to the currency ({$response->getCurrency()}) or the local currency ({$response->getCurrencyLocal()}) used by DPD.");
419
-
420
- return 0;
421
- }
422
- }
423
-
424
- /**
425
- *
426
- * @return boolean
427
- */
428
- public function supportsCalculationOfShippingCosts()
429
- {
430
- return true;
431
- }
432
-
433
- public function getTrackingInfo($trackingNumber)
434
- {
435
-
436
-
437
- $trackingCollection = Mage::getResourceModel('sales/order_shipment_track_collection');
438
- /* @var $trackingCollection Mage_Sales_Model_Mysql4_Order_Shipment_Track_Collection */
439
- $trackingCollection->addFieldToFilter('track_number', $trackingNumber);
440
- $track = $trackingCollection->getFirstItem();
441
- /* @var $track Mage_Sales_Model_Order_Shipment_Track */
442
- if (!$track->getId()) {
443
- $result = array("title" => $this->getConfigData("title"), "number" => $trackingNumber);
444
-
445
- return $result;
446
- }
447
-
448
- $shipment = Mage::getModel('sales/order_shipment')/* @var $shipment Mage_Sales_Model_Order_Shipment */
449
- ->load($track->getParentId());
450
- $carrierTitle = $this->getConfigData("title", $shipment->getStore());
451
-
452
- $ships = Mage::getResourceModel('zitec_dpd/dpd_ship_collection');
453
- /* @var $ships Zitec_Dpd_Model_Mysql4_Dpd_Ship_Collection */
454
- $ship = $ships->getByShipmentId($track->getParentId());
455
- /* @var $ship Zitec_Dpd_Model_Dpd_Ship */
456
- if (!$ship) {
457
- $errorMessage = $this->_getHelper()->__("Could not load the stored tracking information for track %s", $trackingNumber);
458
- $this->_getHelper()->log($errorMessage);
459
- $result = $this->_getTrackingInfoObject($trackingNumber, $carrierTitle, $errorMessage);
460
-
461
- return $result;
462
- }
463
-
464
- $response = @unserialize($ship->getSaveShipmentResponse());
465
- /* @var $response Zitec_Dpd_Api_Shipment_Save_Response */
466
- if (!$response) {
467
- $errorMessage = $this->_getHelper()->__("Error loading stored tracking information for track %s", $trackingNumber);
468
- $this->_getHelper()->log($errorMessage);
469
- $result = $this->_getTrackingInfoObject($trackingNumber, $carrierTitle, $errorMessage);
470
-
471
- return $result;
472
- }
473
-
474
- try {
475
-
476
- $statusResponse = $this->_getWsHelper()->getShipmentStatus($response);
477
-
478
- } catch (Exception $e) {
479
- $errorMessage = $this->_getHelper()->__("Error calling DPD for track %s", $trackingNumber);
480
- $this->_getHelper()->log($errorMessage);
481
- $this->_getHelper()->log($e->getMessage());
482
- $result = $this->_getTrackingInfoObject($trackingNumber, $carrierTitle, $errorMessage);
483
-
484
- return $result;
485
- }
486
-
487
- if ($statusResponse->hasError()) {
488
- $errorMessage = $this->_getHelper()->__('Error calling DPD for track %s: %s ', $trackingNumber, $statusResponse->getErrorText());
489
- $this->_getHelper()->log($errorMessage);
490
- $result = $this->_getTrackingInfoObject($trackingNumber, $carrierTitle, $errorMessage);
491
-
492
- return $result;
493
- }
494
-
495
- $result = $this->_getTrackingInfoObject($trackingNumber, $carrierTitle, "", $statusResponse);
496
-
497
- return $result;
498
- }
499
-
500
- /**
501
- *
502
- * @param string $trackingNumber
503
- * @param string $carrierTitle
504
- * @param string $errorMessage
505
- * @param Zitec_Dpd_Api_Shipment_GetShipmentStatus_Response $response
506
- *
507
- * @return \Varien_Object
508
- */
509
- protected function _getTrackingInfoObject($trackingNumber, $carrierTitle, $errorMessage, Zitec_Dpd_Api_Shipment_GetShipmentStatus_Response $response = null)
510
- {
511
- $result = $result = new Varien_Object();
512
- $result->setTracking($trackingNumber);
513
- $result->setCarrierTitle($carrierTitle);
514
- $result->setErrorMessage($errorMessage);
515
- if ($response) {
516
- $result->setUrl($response->getTrackingUrl());
517
- $result->setDeliverydate($response->getDeliveryDate());
518
- $result->setDeliverytime($response->getDeliveryTime());
519
- $result->setShippedDate($response->getShipDate());
520
- $result->setService($response->getServiceDescription());
521
- $result->setWeight($response->getWeight());
522
- }
523
-
524
- return $result;
525
- }
526
-
527
- public function isValidCityPostcode($city, $postcode, &$errorMsg)
528
- {
529
-
530
- }
531
-
532
- public function shippingMethodRequiresShipmentsOfOnlyOneParcel($shippingMethod)
533
- {
534
-
535
- }
536
-
537
- public function supportsAddressValidation($countryId)
538
- {
539
-
540
- }
541
-
542
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Model_Shipping_Carrier_Dpd extends Zitec_Dpd_Model_Shipping_Carrier_Abstract implements Zitec_PackedShipment_Model_Carrier_Interface
25
+ {
26
+ const CARRIER_CODE = 'zitecDpd';
27
+ protected $_code = 'zitecDpd';
28
+
29
+ public function getAllowedMethods()
30
+ {
31
+ $optionsMethods = Mage::getSingleton('zitec_dpd/config_source_service')->toOptionArray(true);
32
+
33
+ $result = array();
34
+ foreach ($optionsMethods as $method) {
35
+ $result[$method['value']] = $method['label'];
36
+ }
37
+
38
+ return $result;
39
+ }
40
+
41
+ /**
42
+ * Collect and get rates
43
+ *
44
+ * @param Mage_Shipping_Model_Rate_Request $request
45
+ *
46
+ * @return Mage_Shipping_Model_Rate_Result|bool|null
47
+ */
48
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request)
49
+ {
50
+ if (!$this->_canCollectRates($request)) {
51
+ return false;
52
+ }
53
+
54
+ // Recalculate the package value excluding any virtual products.
55
+ if (!$this->getConfigFlag('include_virtual_price')) {
56
+ $request->setPackageValue($request->getPackagePhysicalValue());
57
+ }
58
+
59
+ // Free shipping by qty
60
+ $freeQty = 0;
61
+ $totalPriceInclTax = 0;
62
+ $totalPriceExclTax = 0;
63
+ foreach ($request->getAllItems() as $item) {
64
+ $totalPriceInclTax += $item->getBaseRowTotalInclTax();
65
+ $totalPriceExclTax += $item->getBaseRowTotal();
66
+
67
+ if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
68
+ continue;
69
+ }
70
+
71
+ if ($item->getHasChildren() && $item->isShipSeparately()) {
72
+ foreach ($item->getChildren() as $child) {
73
+ if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
74
+ $freeQty += $item->getQty() * ($child->getQty() - (is_numeric($child->getFreeShipping()) ? $child->getFreeShipping() : 0));
75
+ }
76
+ }
77
+ } elseif ($item->getFreeShipping()) {
78
+ $freeQty += ($item->getQty() - (is_numeric($item->getFreeShipping()) ? $item->getFreeShipping() : 0));
79
+ }
80
+ }
81
+
82
+ // Package weight and qty free shipping
83
+ $oldWeight = $request->getPackageWeight();
84
+ $oldQty = $request->getPackageQty();
85
+ $oldPrice = $request->getPackageValue();
86
+
87
+ $request->setPackageWeight($request->getFreeMethodWeight());
88
+ $request->setPackageQty($oldQty - $freeQty);
89
+ $request->setPackageValue($totalPriceInclTax);
90
+
91
+ $this->_updateFreeMethodQuote($request);
92
+
93
+ // The shipping price calculations for price vs destination is included.
94
+ if ($this->_getTaxHelper()->shippingPriceIncludesTax($request->getStoreId())) {
95
+ $request->setData('zitec_table_price', $totalPriceInclTax);
96
+ } else {
97
+ $request->setData('zitec_table_price', $totalPriceExclTax);
98
+ }
99
+
100
+ $rate = $this->getRate($request);
101
+
102
+ $request->setPackageWeight($oldWeight);
103
+ $request->setPackageQty($oldQty);
104
+ $request->setPackageValue($oldPrice);
105
+
106
+ $isFree = false;
107
+ $freeShippingPrice = ($this->getConfigFlag('free_shipping_subtotal_tax_incl')) ? $totalPriceInclTax : $oldPrice;
108
+ $freeShippingSubtotal = $this->getConfigData('free_shipping_subtotal');
109
+ $freeShippingEnabled = $this->getConfigFlag('free_shipping_enable');
110
+ $freeShipping = ($freeShippingEnabled && $freeShippingPrice >= $freeShippingSubtotal) ? true : false;
111
+ if ($request->getFreeShipping() === true || $freeShipping) {
112
+ $isFree = true;
113
+ }
114
+
115
+ $result = Mage::getModel('shipping/rate_result');
116
+ /* @var $result Mage_Shipping_Model_Rate_Result */
117
+
118
+ if (count($rate) == 0) {
119
+ return false;
120
+ }
121
+
122
+ $methods = array();
123
+ foreach ($rate as $r) {
124
+ // Before adding the rate, we check that it is active in the admin configuration.
125
+ if (!$this->_isRateAllowedByAdminConfiguration($r)) {
126
+ continue;
127
+ }
128
+
129
+ //There can be multiple rate the same method, but is first applicable.
130
+ //If we have already considered a rate of this method, we again evaluate
131
+ //(the other will be for weights / lower prices) or for more general conditions.
132
+
133
+ $dpdMethod = $r['method'];
134
+ if (in_array($dpdMethod, $methods)) {
135
+ continue;
136
+ }
137
+ $methods[] = $dpdMethod;
138
+
139
+ $method = Mage::getModel('shipping/rate_result_method');
140
+
141
+ $method->setCarrier($this->_code);
142
+ $method->setCarrierTitle($this->getConfigData('title'));
143
+ $price = $this->_calculateDPDPrice($r, $request);
144
+ if ($price === false) {
145
+ continue;
146
+ }
147
+ $method->setPrice($price);
148
+ $method->setCost($price);
149
+ $method->setMethod($dpdMethod);
150
+ $methodDescriptions = Mage::getSingleton('zitec_dpd/config_source_service')->toOptionArray();
151
+ $methodTitle = $methodDescriptions[$dpdMethod];
152
+ $method->setMethodTitle($methodTitle);
153
+
154
+ $result->append($method);
155
+ }
156
+
157
+ if ($isFree) {
158
+ $cheapest = $result->getCheapestRate();
159
+ if (!empty($cheapest)) {
160
+ $cheapest->setPrice('0.00');
161
+ $title = $cheapest->getMethodTitle() . ' (' . Mage::helper('shipping')->__('Free') . ')';
162
+ $cheapest->setMethodTitle($title);
163
+ $result->reset();
164
+ $result->append($cheapest);
165
+ }
166
+ }
167
+
168
+ return $result;
169
+ }
170
+
171
+ /**
172
+ * @param Mage_Shipping_Model_Rate_Request $request
173
+ *
174
+ * @return bool
175
+ */
176
+ protected function _canCollectRates(Mage_Shipping_Model_Rate_Request $request)
177
+ {
178
+ if (!$this->getConfigFlag('active')) {
179
+ return false;
180
+ }
181
+
182
+ // Exclude empty carts
183
+ if (!$request->getAllItems()) {
184
+ return false;
185
+ }
186
+
187
+ // Exclude carts containing products with no defined weight or where the
188
+ // total weight of the cart is zero (virtual products only).
189
+ if ($this->_cartContainsProductsOfZeroWeightOrWeighsNothing($request->getAllItems())) {
190
+ return false;
191
+ }
192
+
193
+ return true;
194
+ }
195
+
196
+ /**
197
+ *
198
+ * @return Mage_Tax_Helper_Data
199
+ */
200
+ protected function _getTaxHelper()
201
+ {
202
+ return Mage::helper('tax');
203
+ }
204
+
205
+ /**
206
+ * Returns true if the cart contains items with no defined weight or the
207
+ * whole cart weighs nothing.
208
+ *
209
+ * @param array $itemsInCart
210
+ *
211
+ * @return boolean
212
+ */
213
+ protected function _cartContainsProductsOfZeroWeightOrWeighsNothing($itemsInCart)
214
+ {
215
+
216
+ if (!$itemsInCart) {
217
+ return true;
218
+ }
219
+
220
+ $cartContainsNonVirtualItems = false;
221
+
222
+ foreach ($itemsInCart as $item) {
223
+ if ($item->getParentItem()) {
224
+ continue;
225
+ }
226
+
227
+
228
+ if ($item->getHasChildren() && $item->isShipSeparately()) {
229
+ foreach ($item->getChildren() as $child) {
230
+ if (!$child->getProduct()->isVirtual()) {
231
+ if (!$child->getWeight() || ($child->getWeight() == 0)) {
232
+ return true;
233
+ }
234
+ $cartContainsNonVirtualItems = true;
235
+ }
236
+ }
237
+ } elseif (!$item->getProduct()->isVirtual()) {
238
+ if (!$item->getWeight() || ($item->getWeight() == 0)) {
239
+ return true;
240
+ }
241
+ $cartContainsNonVirtualItems = true;
242
+ }
243
+ }
244
+
245
+ if ($cartContainsNonVirtualItems) {
246
+ return false;
247
+ } else {
248
+ return true; // All items in cart are virtual
249
+ }
250
+ }
251
+
252
+ /**
253
+ *
254
+ * @param Mage_Shipping_Model_Rate_Request $request
255
+ *
256
+ * @return array
257
+ */
258
+ public function getRate(Mage_Shipping_Model_Rate_Request $request)
259
+ {
260
+ $rates = Mage::getResourceModel('zitec_dpd/carrier_tablerate')->getRate($request);
261
+
262
+ return $rates;
263
+ }
264
+
265
+ /**
266
+ *
267
+ * @param array $shippingRate
268
+ *
269
+ * @return boolean
270
+ */
271
+ protected function _isRateAllowedByAdminConfiguration($shippingRate)
272
+ {
273
+
274
+ $availableMethods = explode(',', $this->getconfigData('services'));
275
+
276
+ return in_array($shippingRate['method'], $availableMethods);
277
+ }
278
+
279
+ /**
280
+ * We calculate the shipping price based on the price / rate mentioned in
281
+ * the rates table. If a "markup_type" (percent) indicated we travel to DPD WS
282
+ * to calculate the final price based on the shipping cost with
283
+ * his ws. If the price / percentage is less than zero indicates that the rate is not available.
284
+ *
285
+ * @param array $rate
286
+ * @param Mage_Shipping_Model_Rate_Request $request
287
+ *
288
+ * @return array|boolean
289
+ */
290
+ protected function _calculateDPDPrice(array $rate, Mage_Shipping_Model_Rate_Request $request)
291
+ {
292
+
293
+ if (!$rate['markup_type']) {
294
+ if ($rate['price'] >= 0) {
295
+ return $rate['price'];
296
+ } else {
297
+ return false;
298
+ }
299
+ }
300
+
301
+ $apiParams = $this->_getWsHelper()->getShipmentParams($request->getStoreId());
302
+ $apiParams['method'] = Zitec_Dpd_Api_Configs::METHOD_SHIPMENT_CALCULATE_PRICE;
303
+
304
+ try {
305
+ $dpdApi = new Zitec_Dpd_Api($apiParams);
306
+ $calculatePrice = $dpdApi->getApiMethodObject();
307
+
308
+ $postCode = Mage::helper('zitec_dpd/postcode_search')->extractPostCodeForShippingRequest($request);
309
+
310
+ $calculatePrice->setReceiverAddress($request->getDestStreet(), $request->getDestCity(), $postCode, $request->getDestCountryId())
311
+ ->addParcel($request->getPackageWeight())
312
+ ->setShipmentServiceCode($rate['method']);
313
+
314
+ $insurance = Mage::helper('zitec_dpd')->extractInsuranceValuesByRequest($request);
315
+ $calculatePrice = $calculatePrice->setAdditionalHighInsurance($insurance['goodsValue'], $insurance['currency'], $insurance['content']);
316
+
317
+ $calculatePrice->execute();
318
+ } catch (Exception $e) {
319
+ $this->_getHelper()->log("An error occurred whilst calculating the DPD price for the shipment {$e->getMessage()}");
320
+
321
+ return false;
322
+ }
323
+
324
+ $response = $calculatePrice->getCalculatePriceResponse();
325
+ if ($response->hasError()) {
326
+ $this->_getHelper()->log("DPD returned the following error whilst attempting to calculate the price of a shipment: {$response->getErrorText()}");
327
+
328
+ return false;
329
+ }
330
+
331
+
332
+ if ($request->getBaseCurrency()->getCode() == $response->getCurrency()) {
333
+ $dpdPrice = $response->getAmount();
334
+ } else if ($request->getBaseCurrency()->getCode() == $response->getCurrencyLocal()) {
335
+ $dpdPrice = $response->getAmountLocal();
336
+ } else {
337
+ $this->_getHelper()->log("An error occurred whilst calculating the price of a shipment. The currency of the shipment ({$request->getBaseCurrency()->getCode()}) does not correspond to the currency ({$response->getCurrency()}) or the local currency ({$response->getCurrencyLocal()}) used by DPD. ");
338
+
339
+ return false;
340
+ }
341
+ if ($rate['markup_type'] == 1) {
342
+ return $dpdPrice * (1 + ($rate['price'] / 100));
343
+ } else {
344
+ return $dpdPrice + round(floatval($rate['price']), 2);
345
+ }
346
+ }
347
+
348
+ public function getCitiesForPostcode($postcode, &$errorMsg)
349
+ {
350
+
351
+ }
352
+
353
+ public function getPostcodesForCity($city, &$errorMsg)
354
+ {
355
+
356
+ }
357
+
358
+ /**
359
+ *
360
+ * @param Mage_Sales_Model_Order $order
361
+ * @param string $city
362
+ * @param string $postcode
363
+ * @param array $weightsPackages
364
+ * @param string $errorStr
365
+ *
366
+ * @return double
367
+ */
368
+ public function getShippingCost(Mage_Sales_Model_Order $order, $city, $postcode, $weightsPackages, &$errorStr)
369
+ {
370
+ $shippingAddress = $order->getShippingAddress();
371
+ $city = $city ? $city : $shippingAddress->getCity();
372
+ $postcode = $postcode ? $postcode : $shippingAddress->getPostcode();
373
+ $serviceCode = $this->_getHelper()->getDPDServiceCode($order->getShippingMethod());
374
+ $street = is_array($shippingAddress->getStreetFull()) ? implode("\n", $shippingAddress->getStreetFull()) : $shippingAddress->getStreetFull();
375
+
376
+ $apiParams = $this->_getWsHelper()->getShipmentParams($order->getStore());
377
+ $apiParams['method'] = Zitec_Dpd_Api_Configs::METHOD_SHIPMENT_CALCULATE_PRICE;
378
+
379
+
380
+ try {
381
+ $dpdApi = new Zitec_Dpd_Api($apiParams);
382
+ $calculatePrice = $dpdApi->getApiMethodObject();
383
+
384
+
385
+ $calculatePrice->setReceiverAddress($street, $city, $postcode, $shippingAddress->getCountryId())
386
+ ->setShipmentServiceCode($serviceCode);
387
+
388
+ foreach ($weightsPackages as $parcelWeight) {
389
+ $calculatePrice->addParcel($parcelWeight);
390
+ }
391
+
392
+ $insurance = Mage::helper('zitec_dpd')->extractInsuranceValuesByOrder($order);
393
+ $calculatePrice = $calculatePrice->setAdditionalHighInsurance($insurance['goodsValue'], $insurance['currency'], $insurance['content']);
394
+
395
+ $calculatePrice->execute();
396
+ } catch (Exception $e) {
397
+ $errorStr = $this->_getHelper()->__("Error obtaining shipping price: %s", $e->getMessage());
398
+ $this->_getHelper()->log("An error occurred whilst calculating the DPD price for the shipment {$e->getMessage()}");
399
+
400
+ return 0;
401
+ }
402
+
403
+ $response = $calculatePrice->getCalculatePriceResponse();
404
+ if ($response->hasError()) {
405
+ $errorStr = $this->_getHelper()->__("DPD error: %s", $response->getErrorText());
406
+ $this->_getHelper()->log("DPD returned the following error whilst attempting to calculate the price of a shipment: {$response->getErrorText()}");
407
+
408
+ return 0;
409
+ }
410
+
411
+
412
+ if ($order->getBaseCurrencyCode() == $response->getCurrency()) {
413
+ return $response->getAmount();
414
+ } else if ($order->getBaseCurrencyCode() == $response->getCurrencyLocal()) {
415
+ return $response->getAmountLocal();
416
+ } else {
417
+ $errorStr = $this->_getHelper()->__("Shipping price not available in order currency");
418
+ $this->_getHelper()->log("An error occurred whilst calculating the price of a shipment. The base currency of the shipment ({$order->getBaseCurrencyCode()}) does not correspond to the currency ({$response->getCurrency()}) or the local currency ({$response->getCurrencyLocal()}) used by DPD.");
419
+
420
+ return 0;
421
+ }
422
+ }
423
+
424
+ /**
425
+ *
426
+ * @return boolean
427
+ */
428
+ public function supportsCalculationOfShippingCosts()
429
+ {
430
+ return true;
431
+ }
432
+
433
+ public function getTrackingInfo($trackingNumber)
434
+ {
435
+
436
+
437
+ $trackingCollection = Mage::getResourceModel('sales/order_shipment_track_collection');
438
+ /* @var $trackingCollection Mage_Sales_Model_Mysql4_Order_Shipment_Track_Collection */
439
+ $trackingCollection->addFieldToFilter('track_number', $trackingNumber);
440
+ $track = $trackingCollection->getFirstItem();
441
+ /* @var $track Mage_Sales_Model_Order_Shipment_Track */
442
+ if (!$track->getId()) {
443
+ $result = array("title" => $this->getConfigData("title"), "number" => $trackingNumber);
444
+
445
+ return $result;
446
+ }
447
+
448
+ $shipment = Mage::getModel('sales/order_shipment')/* @var $shipment Mage_Sales_Model_Order_Shipment */
449
+ ->load($track->getParentId());
450
+ $carrierTitle = $this->getConfigData("title", $shipment->getStore());
451
+
452
+ $ships = Mage::getResourceModel('zitec_dpd/dpd_ship_collection');
453
+ /* @var $ships Zitec_Dpd_Model_Mysql4_Dpd_Ship_Collection */
454
+ $ship = $ships->getByShipmentId($track->getParentId());
455
+ /* @var $ship Zitec_Dpd_Model_Dpd_Ship */
456
+ if (!$ship) {
457
+ $errorMessage = $this->_getHelper()->__("Could not load the stored tracking information for track %s", $trackingNumber);
458
+ $this->_getHelper()->log($errorMessage);
459
+ $result = $this->_getTrackingInfoObject($trackingNumber, $carrierTitle, $errorMessage);
460
+
461
+ return $result;
462
+ }
463
+
464
+ $response = @unserialize($ship->getSaveShipmentResponse());
465
+ /* @var $response Zitec_Dpd_Api_Shipment_Save_Response */
466
+ if (!$response) {
467
+ $errorMessage = $this->_getHelper()->__("Error loading stored tracking information for track %s", $trackingNumber);
468
+ $this->_getHelper()->log($errorMessage);
469
+ $result = $this->_getTrackingInfoObject($trackingNumber, $carrierTitle, $errorMessage);
470
+
471
+ return $result;
472
+ }
473
+
474
+ try {
475
+
476
+ $statusResponse = $this->_getWsHelper()->getShipmentStatus($response);
477
+
478
+ } catch (Exception $e) {
479
+ $errorMessage = $this->_getHelper()->__("Error calling DPD for track %s", $trackingNumber);
480
+ $this->_getHelper()->log($errorMessage);
481
+ $this->_getHelper()->log($e->getMessage());
482
+ $result = $this->_getTrackingInfoObject($trackingNumber, $carrierTitle, $errorMessage);
483
+
484
+ return $result;
485
+ }
486
+
487
+ if ($statusResponse->hasError()) {
488
+ $errorMessage = $this->_getHelper()->__('Error calling DPD for track %s: %s ', $trackingNumber, $statusResponse->getErrorText());
489
+ $this->_getHelper()->log($errorMessage);
490
+ $result = $this->_getTrackingInfoObject($trackingNumber, $carrierTitle, $errorMessage);
491
+
492
+ return $result;
493
+ }
494
+
495
+ $result = $this->_getTrackingInfoObject($trackingNumber, $carrierTitle, "", $statusResponse);
496
+
497
+ return $result;
498
+ }
499
+
500
+ /**
501
+ *
502
+ * @param string $trackingNumber
503
+ * @param string $carrierTitle
504
+ * @param string $errorMessage
505
+ * @param Zitec_Dpd_Api_Shipment_GetShipmentStatus_Response $response
506
+ *
507
+ * @return \Varien_Object
508
+ */
509
+ protected function _getTrackingInfoObject($trackingNumber, $carrierTitle, $errorMessage, Zitec_Dpd_Api_Shipment_GetShipmentStatus_Response $response = null)
510
+ {
511
+ $result = $result = new Varien_Object();
512
+ $result->setTracking($trackingNumber);
513
+ $result->setCarrierTitle($carrierTitle);
514
+ $result->setErrorMessage($errorMessage);
515
+ if ($response) {
516
+ $result->setUrl($response->getTrackingUrl());
517
+ $result->setDeliverydate($response->getDeliveryDate());
518
+ $result->setDeliverytime($response->getDeliveryTime());
519
+ $result->setShippedDate($response->getShipDate());
520
+ $result->setService($response->getServiceDescription());
521
+ $result->setWeight($response->getWeight());
522
+ }
523
+
524
+ return $result;
525
+ }
526
+
527
+ public function isValidCityPostcode($city, $postcode, &$errorMsg)
528
+ {
529
+
530
+ }
531
+
532
+ public function shippingMethodRequiresShipmentsOfOnlyOneParcel($shippingMethod)
533
+ {
534
+
535
+ }
536
+
537
+ public function supportsAddressValidation($countryId)
538
+ {
539
+
540
+ }
541
+
542
  }
app/code/community/Zitec/Dpd/controllers/Adminhtml/ConfigController.php CHANGED
@@ -1,39 +1,39 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Adminhtml_ConfigController extends Mage_Adminhtml_Controller_Action
25
- {
26
-
27
- public function exportTableratesAction()
28
- {
29
- $fileName = 'dpd_tablerates.csv';
30
- $gridBlock = $this->getLayout()->createBlock('zitec_dpd/adminhtml_tablerate_grid');
31
- $website = Mage::app()->getWebsite($this->getRequest()->getParam('website'));
32
- $gridBlock->setWebsiteId($website->getId());
33
- $content = $gridBlock->getCsvFile();
34
- $this->_prepareDownloadResponse($fileName, $content);
35
- }
36
-
37
- }
38
-
39
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Adminhtml_ConfigController extends Mage_Adminhtml_Controller_Action
25
+ {
26
+
27
+ public function exportTableratesAction()
28
+ {
29
+ $fileName = 'dpd_tablerates.csv';
30
+ $gridBlock = $this->getLayout()->createBlock('zitec_dpd/adminhtml_tablerate_grid');
31
+ $website = Mage::app()->getWebsite($this->getRequest()->getParam('website'));
32
+ $gridBlock->setWebsiteId($website->getId());
33
+ $content = $gridBlock->getCsvFile();
34
+ $this->_prepareDownloadResponse($fileName, $content);
35
+ }
36
+
37
+ }
38
+
39
+
app/code/community/Zitec/Dpd/controllers/Adminhtml/PostcodeController.php ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Adminhtml_PostcodeController extends Mage_Adminhtml_Controller_Action
25
+ {
26
+
27
+
28
+ /**
29
+ * print the form to the user
30
+ *
31
+ */
32
+ public function updateFormAction()
33
+ {
34
+ // if an error occurred in the past because of php upload size limit, then trigger an error message
35
+ // while the setting is not modified
36
+ $fileSizeError = Mage::getSingleton('core/session')->getDpdMaxFileUploadError();
37
+ $currentSettings = ini_get('upload_max_filesize');
38
+ if (!empty($fileSizeError) && $fileSizeError == $currentSettings) {
39
+ Mage::getSingleton('core/session')->addError(
40
+ Mage::helper('core')->__('Your PHP settings for upload_max_filesize is too low (%s). Please increase this limit or upload the file manually into media/dpd/postcode', $fileSizeError)
41
+ );
42
+ }
43
+
44
+
45
+ $this->loadLayout();
46
+ $this->_setActiveMenu("zitec_dpd");
47
+
48
+ // create the form container + form and the left panel
49
+ $this->_addContent($this->getLayout()->createBlock('zitec_dpd/adminhtml_postcode_formContainer'));
50
+ $this->_addContent($this->getLayout()->createBlock('zitec_dpd/adminhtml_postcode_update_files'));
51
+
52
+ $this->renderLayout();
53
+
54
+ }
55
+
56
+ /**
57
+ * upload the file and run the import script on it
58
+ * if a file was already uploaded and the name
59
+ * of the file is sent in the post request then run the import on this file
60
+ */
61
+ public function importAction()
62
+ {
63
+ $baseFileName = '';
64
+ try {
65
+
66
+ //process the upload logic for the csv file
67
+ if (isset($_FILES['csv']['name']) && $_FILES['csv']['name'] != '') {
68
+ if (isset($_FILES['csv']['error']) && !empty($_FILES['csv']['error'])) {
69
+ $message = $this->getUploadCodeMessage($_FILES['csv']['error']);
70
+ throw new Exception($message, $_FILES['csv']['error']);
71
+ }
72
+ $uploader = new Varien_File_Uploader('csv');
73
+ $uploader->setAllowedExtensions(array('csv'));
74
+ $uploader->setAllowRenameFiles(true);
75
+ $uploader->setFilesDispersion(false);
76
+ $path = Mage::helper('zitec_dpd/postcode_search')->getPathToDatabaseUpgradeFiles();
77
+ //$path .= date('Y-m-d').DS;
78
+ if (!is_dir($path)) {
79
+ mkdir($path, 0777, true);
80
+ }
81
+ $uploader->save($path, $_FILES['csv']['contacts']);
82
+ $newUpdateFilename = $path . $uploader->getUploadedFileName();
83
+ $baseFileName = $uploader->getUploadedFileName();
84
+ }
85
+
86
+ // if the no uploads made then check if the path_to_csv field was filed
87
+ if (empty($newUpdateFilename)) {
88
+ $baseFileName = $this->getRequest()->getPost('path_to_csv');
89
+ if (empty($baseFileName)) {
90
+ throw new Exception(
91
+ Mage::helper('core')->__('Nothing to do!! Please upload a file or select an uploaded file.')
92
+ );
93
+ }
94
+ if (isset($baseFileName)) {
95
+ $path = Mage::helper('zitec_dpd/postcode_search')->getPathToDatabaseUpgradeFiles();
96
+ $updateFilename = $path . $baseFileName;
97
+ if (!is_file($updateFilename)) {
98
+ throw new Exception(
99
+ Mage::helper('core')->__('File %s was not found in path media/dpd/postcode_updates', $baseFileName)
100
+ );
101
+ }
102
+
103
+ $newUpdateFilename = $updateFilename;
104
+ }
105
+ }
106
+
107
+ if (!is_file($newUpdateFilename)) {
108
+ throw new Exception(
109
+ Mage::helper('core')->__('File %s was not found in path media/dpd/postcode_updates', $baseFileName)
110
+ );
111
+ }
112
+
113
+
114
+ } catch (Exception $e) {
115
+ Mage::getSingleton('core/session')->addError($e->getMessage());
116
+ $this->_redirect("zitec_dpd/adminhtml_postcode/updateForm");
117
+
118
+ return;
119
+ }
120
+
121
+ // with the filename found, we need to run the database update script
122
+ // by calling the updateDatabase function of the postcode library
123
+ try {
124
+ Mage::helper('zitec_dpd/postcode_search')->updateDatabase($newUpdateFilename);
125
+ Mage::getSingleton('core/session')->addSuccess(
126
+ Mage::helper('core')->__('Last updates found on file %s, were installed successfully.', $baseFileName)
127
+ );
128
+ } catch (Exception $e) {
129
+ Mage::getSingleton('core/session')->addError($e->getMessage());
130
+ }
131
+ $this->_redirect("zitec_dpd/adminhtml_postcode/updateForm");
132
+ }
133
+
134
+
135
+ /**
136
+ *
137
+ * @param $code
138
+ *
139
+ * @return string
140
+ */
141
+ private function getUploadCodeMessage($code)
142
+ {
143
+ switch ($code) {
144
+ case UPLOAD_ERR_INI_SIZE:
145
+ $message = "The uploaded file exceeds the upload_max_filesize directive in php.ini";
146
+ Mage::getSingleton('core/session')->setDpdMaxFileUploadError(ini_get('upload_max_filesize'));
147
+ break;
148
+ case UPLOAD_ERR_FORM_SIZE:
149
+ $message = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form";
150
+ break;
151
+ case UPLOAD_ERR_PARTIAL:
152
+ $message = "The uploaded file was only partially uploaded";
153
+ break;
154
+ case UPLOAD_ERR_NO_FILE:
155
+ $message = "No file was uploaded";
156
+ break;
157
+ case UPLOAD_ERR_NO_TMP_DIR:
158
+ $message = "Missing a temporary folder";
159
+ break;
160
+ case UPLOAD_ERR_CANT_WRITE:
161
+ $message = "Failed to write file to disk";
162
+ break;
163
+ case UPLOAD_ERR_EXTENSION:
164
+ $message = "File upload stopped by extension";
165
+ break;
166
+
167
+ default:
168
+ $message = "Unknown upload error";
169
+ break;
170
+ }
171
+
172
+ return $message;
173
+ }
174
+
175
+ /**
176
+ *
177
+ * @return Zitec_TableRates_Helper_Data
178
+ */
179
+ protected function _getTableRateHelper()
180
+ {
181
+ return Mage::helper('zitec_tablerates');
182
+ }
183
+
184
+
185
+ }
app/code/community/Zitec/Dpd/controllers/Adminhtml/ShipmentController.php CHANGED
@@ -1,463 +1,463 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_Dpd_Adminhtml_ShipmentController extends Mage_Adminhtml_Controller_Action
25
- {
26
-
27
-
28
- /**
29
- * this action is used to validate manually the address postcode
30
- */
31
- public function validatePostcodeAction(){
32
- $params = $this->getRequest()->getParams();
33
- $address = '';
34
- foreach($params['street'] as $street){
35
- $address .= ' '.$street;
36
- }
37
- $address = trim($address);
38
- $params['address'] = $address;
39
- $foundAddresses = Mage::helper('zitec_dpd/postcode_search')->findAllSimilarAddressesForAddress($params);
40
- $content = $this->getLayout()
41
- ->createBlock('zitec_dpd/adminhtml_shipment_postcode_autocompleter')
42
- ->setData('found_addresses',$foundAddresses)
43
- ->setTemplate('zitec_dpd/sales/order/shipment/postcode/autocompleter.phtml')->toHtml();
44
-
45
- $this->getResponse()->setBody($content);
46
-
47
- }
48
-
49
-
50
- /**
51
- * download the pdf containg labels for each parcel
52
- *
53
- * @return Mage_Core_Controller_Varien_Action
54
- */
55
- public function getLabelPdfAction()
56
- {
57
- $shipmentId = $this->getRequest()->getParam('shipmentid');
58
- if (!$shipmentId) {
59
-
60
- }
61
- $shipment = Mage::getModel('sales/order_shipment')->load($shipmentId);
62
- /* @var $shipment Mage_Sales_Model_Order_Shipment */
63
- $shipmentLabel = $shipment->getShippingLabel();
64
- $pdf = Zend_Pdf::parse($shipmentLabel);
65
-
66
- return $this->_prepareDownloadResponse($shipment->getIncrementId().'_dpd_'.$shipment->getCreatedAt().'.pdf', $pdf->render(), 'application/pdf');
67
- }
68
-
69
- /**
70
- * create the manifest and generate the download link for pdf
71
- */
72
- public function manifestAction()
73
- {
74
- $shipmentIds = $this->getRequest()->getParam('shipment_ids');
75
-
76
- $manifest = Mage::getModel('zitec_dpd/dpd_manifest');
77
- /* @var $manifest Zitec_Dpd_Model_Dpd_Manifest */
78
- try {
79
- $success = $manifest->createManifestForShipments($shipmentIds);
80
- $notifications = $manifest->getNotifications();
81
- if ($success) {
82
- $downloadLinkMessage = "Successfully closed manifest %s for the following shipments. <a href='%s'>Download the manifest</a>.";
83
- array_unshift($notifications, $this->_getHelper()->__($downloadLinkMessage, $manifest->getManifestRef(), $this->_getDownloadManifestUrl($manifest->getManifestId())));
84
- }
85
- $message = implode("<br />", $notifications);
86
- $this->_getHelper()->addSuccessError($success, $message);
87
- } catch (Exception $e) {
88
- $this->_getHelper()->addError($this->_getHelper()->__("An error occurred whilst closing the manifest: %s", $e->getMessage()));
89
- $this->_getHelper()->log($e->getMessage(), __FUNCTION__, __CLASS__, __LINE__);
90
- }
91
-
92
- $this->_redirect("adminhtml/sales_shipment/index");
93
- }
94
-
95
-
96
- /**
97
- * @param int $manifestId
98
- *
99
- * @return string
100
- */
101
- protected function _getDownloadManifestUrl($manifestId)
102
- {
103
- return $this->_getHelper()->getDownloadManifestUrl($manifestId);
104
- }
105
-
106
-
107
- /**
108
- * create the pdf and download it
109
- */
110
- public function downloadManifestAction()
111
- {
112
- $manifestId = $this->getRequest()->getParam("manifest_id");
113
- try {
114
- if (!$manifestId) {
115
- $message = $this->_getHelper()->__("A problem occurred whilst attempting to download a manifest. No manifest was specified in the request.");
116
- Mage::throwException($message);
117
- }
118
-
119
- $manifest = Mage::getModel('zitec_dpd/dpd_manifest');
120
- /* @var $manifest Zitec_Dpd_Model_Dpd_Manifest */
121
- try {
122
- $manifest->load($manifestId);
123
- } catch (Exception $e) {
124
- $message = $this->_getHelper()->__("A problem occurred whilst attempting to download the manifest id %s: %s", $manifestId, $e->getMessage());
125
- Mage::throwException($message);
126
- }
127
- if ($manifest->getManifestId() != $manifestId) {
128
- $message = $this->_getHelper()->__("A problem occurred whilst attempting to download the manifest %s. The manifest no longer exists.", $manifestId);
129
- Mage::throwException($message);
130
- }
131
- $pdfFile = base64_decode($manifest->getPdf());
132
- $pdf = Zend_Pdf::parse($pdfFile);
133
-
134
- return $this->_prepareDownloadResponse("{$manifest->getManifestRef()}_dpd_manifest.pdf", $pdf->render(), 'application/pdf');
135
- } catch (Mage_Core_Exception $e) {
136
- $this->_getHelper()->addError($e->getMessage());
137
- $this->_getHelper()->log($e->getMessage(), __FUNCTION__, __CLASS__, __LINE__);
138
- } catch (Exception $e) {
139
- $message = $this->_getHelper()->__("An unexpected problem occurred whilst attempting to download the manifest %s. %s", $manifestId, $e->getMessage());
140
- $this->_getHelper()->addError($message);
141
- $this->_getHelper()->log($message, __FUNCTION__, __CLASS__, __LINE__);
142
- }
143
- $this->_redirect("adminhtml/sales_shipment/index");
144
-
145
- }
146
-
147
-
148
- /**
149
- * merge more labels into on pdf and return the Zend_Pdf object
150
- *
151
- * @param array $labelsContent
152
- *
153
- * @return Zend_Pdf
154
- */
155
- protected function _combineLabelsPdf(array $labelsContent)
156
- {
157
- $outputPdf = new Zend_Pdf();
158
- foreach ($labelsContent as $content) {
159
- if (stripos($content, '%PDF-') !== false) {
160
- $pdfLabel = Zend_Pdf::parse($content);
161
- foreach ($pdfLabel->pages as $page) {
162
- $outputPdf->pages[] = clone $page;
163
- }
164
- } else {
165
- $page = $this->_createPdfPageFromImageString($content);
166
- if ($page) {
167
- $outputPdf->pages[] = $page;
168
- }
169
- }
170
- }
171
-
172
- return $outputPdf;
173
- }
174
-
175
-
176
- protected function _createPdfPageFromImageString($imageString)
177
- {
178
- $image = imagecreatefromstring($imageString);
179
- if (!$image) {
180
- return false;
181
- }
182
-
183
- $xSize = imagesx($image);
184
- $ySize = imagesy($image);
185
- $page = new Zend_Pdf_Page($xSize, $ySize);
186
-
187
- imageinterlace($image, 0);
188
- $tmpFileName = sys_get_temp_dir() . DS . 'shipping_labels_'
189
- . uniqid(mt_rand()) . time() . '.png';
190
- imagepng($image, $tmpFileName);
191
- $pdfImage = Zend_Pdf_Image::imageWithPath($tmpFileName);
192
- $page->drawImage($pdfImage, 0, 0, $xSize, $ySize);
193
- unlink($tmpFileName);
194
-
195
- return $page;
196
- }
197
-
198
- /**
199
- * Delete shipment if the manifest was not closed before
200
- */
201
- public function deleteAction()
202
- {
203
- $shipmentId = $this->getRequest()->getParam('shipment_id');
204
- if (!$shipmentId) {
205
- $this->_setDeleteResponse("No shipment was specified", $shipmentId);
206
-
207
- return;
208
- }
209
- $shipment = Mage::getModel('sales/order_shipment');
210
- /* @var $shipment Mage_Sales_Model_Order_Shipment */
211
- $shipment->load($shipmentId);
212
-
213
- $ships = Mage::getResourceModel('zitec_dpd/dpd_ship_collection');
214
- /* @var $ships Zitec_Dpd_Model_Mysql4_Dpd_Ship_Collection */
215
- $ship = $ships->getByShipmentId($shipmentId);
216
- /* @var $ship Zitec_Dpd_Model_Dpd_Ship */
217
- if (!$ship) {
218
- $this->_setDeleteResponse("Could not find any DPD shipment information for this shipment.", $shipment);
219
-
220
- return;
221
- }
222
-
223
- if ($ship->getManifestId()) {
224
- $this->_setDeleteResponse("You cannot cancel this shipment with DPD because the manifest is already closed.", $shipment);
225
-
226
- return;
227
- }
228
- $response = @unserialize($ship->getSaveShipmentResponse());
229
- /* @var $response Zitec_Dpd_Api_Shipment_Save_Response */
230
- if (!$response) {
231
- $this->_setDeleteResponse("Unable to load shipment information for this shipment.", $shipment);
232
-
233
- return;
234
- }
235
-
236
-
237
- try {
238
- $wsResult = $this->_getWsHelper()->deleteWsShipment($shipment,$response);
239
- } catch (Exception $e) {
240
- $this->_setDeleteResponse('An error occurred whilst attempting to delete the shipment information with DPD. <br /> "%s"', $shipment, $e->getMessage());
241
-
242
- return;
243
- }
244
-
245
- if ($wsResult->hasError()) {
246
- $this->_setDeleteResponse('An error occurred whilst attempting to delete the shipment information with DPD. <br /> "%s"', $shipment, $wsResult->getErrorText());
247
-
248
- return;
249
- }
250
-
251
- $shipment->setShippingLabel(null)->save();
252
- $ship->setShippingLabels(null)->save();
253
-
254
- $this->_forward("removeTrack", "sales_order_shipment", "admin");
255
- }
256
-
257
-
258
-
259
- protected function _setDeleteResponse($message, $shipment, $additional = '', $isError = true)
260
- {
261
- $response = array(
262
- 'error' => $isError,
263
- 'message' => $this->__($message, $additional),
264
- );
265
- $response = Mage::helper('core')->jsonEncode($response);
266
- $this->getResponse()->setBody($response);
267
- if ($isError) {
268
- $isShipmentLoaded = $shipment instanceof Mage_Sales_Model_Order_Shipment;
269
- $incrementId = $isShipmentLoaded ? $shipment->getIncrementId() : "Unknown";
270
- $shipmentId = $isShipmentLoaded ? $shipment->getId() : $shipment;
271
- $this->_getHelper()->log(sprintf("Error deleting shipment, id: %s, reference: %s", $shipmentId, $incrementId));
272
- $this->_getHelper()->log(sprintf("Message: %s", $message));
273
- if ($additional) {
274
- $this->_getHelper()->log(sprintf("Additional: %s", $additional));
275
- }
276
- }
277
-
278
- return $isError;
279
- }
280
-
281
-
282
- /**
283
- *
284
- * Create a pickup request in the future
285
- * sender address have to be configures
286
- * shipment should be already generated
287
- * the manifest can be closed or not
288
- */
289
- public function createPickupAction()
290
- {
291
- $shipmentIds = $this->getRequest()->getParam("shipment_ids");
292
- if (!$shipmentIds) {
293
- $this->_createPickupRedirect($this->__('Please select the shipments for which you wish to arrange a pickup.'));
294
-
295
- return;
296
- }
297
-
298
- list($day, $month, $year) = explode("/", $this->getRequest()->getParam("zitec_dpd_pickup_date"));
299
- if (!checkdate($month, $day, $year)) {
300
- $this->_createPickupRedirect($this->__('Please enter a pickup date in the format DD/MM/YYYY.'));
301
-
302
- return;
303
- }
304
- $year = isset($year) && strlen($year) == 2 ? "20$year" : $year;
305
- $month = isset($month) && strlen($month) < 2 ? str_pad($month, 2, "0") : $month;
306
- $day = isset($day) && strlen($day) < 2 ? str_pad($day, 2, "0") : $day;
307
- $pickupDate = "$year$month$day";
308
-
309
- $pickupFromParts = $this->getRequest()->getParam("zitec_dpd_pickup_from");
310
- if (!is_array($pickupFromParts) || count($pickupFromParts) != 3) {
311
- $this->_createPickupRedirect($this->__('Please select a from and to time for the pickup.'));
312
-
313
- return;
314
- }
315
- $pickupFrom = implode("", $pickupFromParts);
316
-
317
- $pickupToParts = $this->getRequest()->getParam("zitec_dpd_pickup_to");
318
- if (!is_array($pickupToParts) || count($pickupToParts) != 3) {
319
- $this->_getHelper()->addError($this->__('Please select a from and to time for the pickup.'));
320
- $this->_redirect("adminhtml/sales_shipment/index");
321
-
322
- return;
323
- }
324
- $pickupTo = implode("", $pickupToParts);
325
-
326
- $instruction = $this->getRequest()->getParam("zitec_dpd_pickup_instruction");
327
-
328
- $pickupAddress = $this->_getWsHelper()->getPickupAddress();
329
- if (!is_array($pickupAddress)) {
330
- $this->_getHelper()->addError($this->__('You cannot create a pickup because you have not fully specified your pickup address. <br />Please set your pickup address in System->Configuration->Sales->Shipping Settings->DPD GeoPost Pickup Address.'));
331
- $this->_redirect("adminhtml/sales_shipment/index");
332
-
333
- return;
334
- }
335
-
336
- $apiParams = $this->_getWsHelper()->getPickupParams();
337
- $apiParams['method'] = Zitec_Dpd_Api_Configs::METHOD_PICKUP_CREATE;
338
-
339
- $dpdApi = new Zitec_Dpd_Api($apiParams);
340
- $createPickup = $dpdApi->getApiMethodObject();
341
-
342
- $createPickup->setPickupTime($pickupDate, $pickupFrom, $pickupTo);
343
- $createPickup->setSpecialInstruction($instruction);
344
- $createPickup->setPickupAddress($pickupAddress);
345
-
346
- $shipments = Mage::getResourceModel('sales/order_shipment_collection');
347
- /* @var $shipments Mage_Sales_Model_Resource_Order_Shipment_Collection */
348
- $shipments->addFieldToFilter('entity_id', array("in" => $shipmentIds));
349
-
350
- $ships = Mage::getResourceModel('zitec_dpd/dpd_ship_collection');
351
- /* @var $ships Zitec_Dpd_Model_Mysql4_Dpd_Ship_Collection */
352
- $ships->filterByShipmentIds($shipmentIds);
353
-
354
-
355
- $includedShipments = array();
356
- foreach ($shipments as $shipment) {
357
- /* @var $shipment Mage_Sales_Model_Order_Shipment */
358
- $ship = $ships->findByShipmentId($shipment->getId());
359
- /* @var $ship Zitec_Dpd_Model_Dpd_Ship */
360
- if (!$ship || !$this->_getHelper()->isShippingMethodDpd($shipment) || $this->_getHelper()->isCancelledWithDpd($shipment)) {
361
- continue;
362
- }
363
- $includedShipments[] = $shipment;
364
-
365
- $call = @unserialize($ship->getSaveShipmentCall());
366
- /* @var $call Zitec_Dpd_Api_Shipment_Save */
367
- if (!$call) {
368
- $message = $this->__("Unable to load shipment information for this shipment %s.", $shipment);
369
- $this->_createPickupRedirect($message);
370
-
371
- return;
372
- }
373
- $createPickup->addPieces($call->getShipmentServiceCode(), $call->getParcelCount(), $call->getTotalWeight(), $call->getReceiverCountryCode());
374
- }
375
- if (!$includedShipments) {
376
- $message = $this->__("Your list did not contain any DPD shipments for which to arrange a pickup.", $shipment);
377
- $this->_createPickupRedirect($message);
378
-
379
- return;
380
- }
381
-
382
- try {
383
- $createPickup->execute();
384
- } catch (Exception $e) {
385
- $message = $this->__('A problem occurred whilst communicating your shipment to DPD. <br />"%s"', $e->getMessage());
386
- $this->_getHelper()->log($message);
387
- $this->_createPickupRedirect($message);
388
-
389
- return;
390
- }
391
- $response = $createPickup->getCreatePickupResponse();
392
- if ($response->hasError()) {
393
- $message = $this->__('DPD reported an error whilst attempting to arrange your pickup. <br />DPD says, "%s"', $response->getErrorText());
394
- $this->_getHelper()->log($message);
395
- $this->_createPickupRedirect($message);
396
-
397
- return;
398
- }
399
-
400
- $pickup = Mage::getModel('zitec_dpd/dpd_pickup');
401
- /* @var $pickup Zitec_Dpd_Model_Dpd_Pickup */
402
-
403
- $pickup->setReference($response->getReferenceNumber())
404
- ->setDpdId($response->getDpdId())
405
- ->setPickupDate("$year-$month-$day")
406
- ->setPickupTimeFrom("$year-$month-$day " . implode(":", $pickupFromParts))
407
- ->setPickupTimeTo("$year-$month-$day " . implode(":", $pickupToParts))
408
- ->setCallData(serialize($createPickup))
409
- ->setResponseData(serialize($response))
410
- ->save();
411
-
412
- foreach ($includedShipments as $includedShipment) {
413
- $includedShipment->setData('zitec_dpd_pickup_time', "$year-$month-$day " . implode(":", $pickupFromParts));
414
- $includedShipment->setData('zitec_dpd_pickup_id', $pickup->getEntityId());
415
- $includedShipment->save();
416
- }
417
-
418
- $this->_getHelper()->addNotice("Your pickup was created successfully");
419
- $this->_redirect("adminhtml/sales_shipment/index");
420
- }
421
-
422
-
423
-
424
- /**
425
- *
426
- * @param string $message
427
- * @param boolean $isError
428
- */
429
- protected function _createPickupRedirect($message, $isError = true)
430
- {
431
- if ($isError) {
432
- $this->_getHelper()->addError($message);
433
- } else {
434
- $this->_getHelper()->addNotice($message);
435
- }
436
- $this->_redirect("adminhtml/sales_shipment/index");
437
- }
438
-
439
-
440
-
441
-
442
-
443
-
444
- /**
445
- *
446
- * @return Zitec_Dpd_Helper_Ws
447
- */
448
- protected function _getWsHelper()
449
- {
450
- return Mage::helper('zitec_dpd/ws');
451
- }
452
-
453
- /**
454
- *
455
- * @return Zitec_Dpd_Helper_Data
456
- */
457
- protected function _getHelper()
458
- {
459
- return Mage::helper('zitec_dpd');
460
- }
461
-
462
-
463
- }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_Dpd_Adminhtml_ShipmentController extends Mage_Adminhtml_Controller_Action
25
+ {
26
+
27
+
28
+ /**
29
+ * this action is used to validate manually the address postcode
30
+ */
31
+ public function validatePostcodeAction(){
32
+ $params = $this->getRequest()->getParams();
33
+ $address = '';
34
+ foreach($params['street'] as $street){
35
+ $address .= ' '.$street;
36
+ }
37
+ $address = trim($address);
38
+ $params['address'] = $address;
39
+ $foundAddresses = Mage::helper('zitec_dpd/postcode_search')->findAllSimilarAddressesForAddress($params);
40
+ $content = $this->getLayout()
41
+ ->createBlock('zitec_dpd/adminhtml_shipment_postcode_autocompleter')
42
+ ->setData('found_addresses',$foundAddresses)
43
+ ->setTemplate('zitec_dpd/sales/order/shipment/postcode/autocompleter.phtml')->toHtml();
44
+
45
+ $this->getResponse()->setBody($content);
46
+
47
+ }
48
+
49
+
50
+ /**
51
+ * download the pdf containg labels for each parcel
52
+ *
53
+ * @return Mage_Core_Controller_Varien_Action
54
+ */
55
+ public function getLabelPdfAction()
56
+ {
57
+ $shipmentId = $this->getRequest()->getParam('shipmentid');
58
+ if (!$shipmentId) {
59
+
60
+ }
61
+ $shipment = Mage::getModel('sales/order_shipment')->load($shipmentId);
62
+ /* @var $shipment Mage_Sales_Model_Order_Shipment */
63
+ $shipmentLabel = $shipment->getShippingLabel();
64
+ $pdf = Zend_Pdf::parse($shipmentLabel);
65
+
66
+ return $this->_prepareDownloadResponse($shipment->getIncrementId().'_dpd_'.$shipment->getCreatedAt().'.pdf', $pdf->render(), 'application/pdf');
67
+ }
68
+
69
+ /**
70
+ * create the manifest and generate the download link for pdf
71
+ */
72
+ public function manifestAction()
73
+ {
74
+ $shipmentIds = $this->getRequest()->getParam('shipment_ids');
75
+
76
+ $manifest = Mage::getModel('zitec_dpd/dpd_manifest');
77
+ /* @var $manifest Zitec_Dpd_Model_Dpd_Manifest */
78
+ try {
79
+ $success = $manifest->createManifestForShipments($shipmentIds);
80
+ $notifications = $manifest->getNotifications();
81
+ if ($success) {
82
+ $downloadLinkMessage = "Successfully closed manifest %s for the following shipments. <a href='%s'>Download the manifest</a>.";
83
+ array_unshift($notifications, $this->_getHelper()->__($downloadLinkMessage, $manifest->getManifestRef(), $this->_getDownloadManifestUrl($manifest->getManifestId())));
84
+ }
85
+ $message = implode("<br />", $notifications);
86
+ $this->_getHelper()->addSuccessError($success, $message);
87
+ } catch (Exception $e) {
88
+ $this->_getHelper()->addError($this->_getHelper()->__("An error occurred whilst closing the manifest: %s", $e->getMessage()));
89
+ $this->_getHelper()->log($e->getMessage(), __FUNCTION__, __CLASS__, __LINE__);
90
+ }
91
+
92
+ $this->_redirect("adminhtml/sales_shipment/index");
93
+ }
94
+
95
+
96
+ /**
97
+ * @param int $manifestId
98
+ *
99
+ * @return string
100
+ */
101
+ protected function _getDownloadManifestUrl($manifestId)
102
+ {
103
+ return $this->_getHelper()->getDownloadManifestUrl($manifestId);
104
+ }
105
+
106
+
107
+ /**
108
+ * create the pdf and download it
109
+ */
110
+ public function downloadManifestAction()
111
+ {
112
+ $manifestId = $this->getRequest()->getParam("manifest_id");
113
+ try {
114
+ if (!$manifestId) {
115
+ $message = $this->_getHelper()->__("A problem occurred whilst attempting to download a manifest. No manifest was specified in the request.");
116
+ Mage::throwException($message);
117
+ }
118
+
119
+ $manifest = Mage::getModel('zitec_dpd/dpd_manifest');
120
+ /* @var $manifest Zitec_Dpd_Model_Dpd_Manifest */
121
+ try {
122
+ $manifest->load($manifestId);
123
+ } catch (Exception $e) {
124
+ $message = $this->_getHelper()->__("A problem occurred whilst attempting to download the manifest id %s: %s", $manifestId, $e->getMessage());
125
+ Mage::throwException($message);
126
+ }
127
+ if ($manifest->getManifestId() != $manifestId) {
128
+ $message = $this->_getHelper()->__("A problem occurred whilst attempting to download the manifest %s. The manifest no longer exists.", $manifestId);
129
+ Mage::throwException($message);
130
+ }
131
+ $pdfFile = base64_decode($manifest->getPdf());
132
+ $pdf = Zend_Pdf::parse($pdfFile);
133
+
134
+ return $this->_prepareDownloadResponse("{$manifest->getManifestRef()}_dpd_manifest.pdf", $pdf->render(), 'application/pdf');
135
+ } catch (Mage_Core_Exception $e) {
136
+ $this->_getHelper()->addError($e->getMessage());
137
+ $this->_getHelper()->log($e->getMessage(), __FUNCTION__, __CLASS__, __LINE__);
138
+ } catch (Exception $e) {
139
+ $message = $this->_getHelper()->__("An unexpected problem occurred whilst attempting to download the manifest %s. %s", $manifestId, $e->getMessage());
140
+ $this->_getHelper()->addError($message);
141
+ $this->_getHelper()->log($message, __FUNCTION__, __CLASS__, __LINE__);
142
+ }
143
+ $this->_redirect("adminhtml/sales_shipment/index");
144
+
145
+ }
146
+
147
+
148
+ /**
149
+ * merge more labels into on pdf and return the Zend_Pdf object
150
+ *
151
+ * @param array $labelsContent
152
+ *
153
+ * @return Zend_Pdf
154
+ */
155
+ protected function _combineLabelsPdf(array $labelsContent)
156
+ {
157
+ $outputPdf = new Zend_Pdf();
158
+ foreach ($labelsContent as $content) {
159
+ if (stripos($content, '%PDF-') !== false) {
160
+ $pdfLabel = Zend_Pdf::parse($content);
161
+ foreach ($pdfLabel->pages as $page) {
162
+ $outputPdf->pages[] = clone $page;
163
+ }
164
+ } else {
165
+ $page = $this->_createPdfPageFromImageString($content);
166
+ if ($page) {
167
+ $outputPdf->pages[] = $page;
168
+ }
169
+ }
170
+ }
171
+
172
+ return $outputPdf;
173
+ }
174
+
175
+
176
+ protected function _createPdfPageFromImageString($imageString)
177
+ {
178
+ $image = imagecreatefromstring($imageString);
179
+ if (!$image) {
180
+ return false;
181
+ }
182
+
183
+ $xSize = imagesx($image);
184
+ $ySize = imagesy($image);
185
+ $page = new Zend_Pdf_Page($xSize, $ySize);
186
+
187
+ imageinterlace($image, 0);
188
+ $tmpFileName = sys_get_temp_dir() . DS . 'shipping_labels_'
189
+ . uniqid(mt_rand()) . time() . '.png';
190
+ imagepng($image, $tmpFileName);
191
+ $pdfImage = Zend_Pdf_Image::imageWithPath($tmpFileName);
192
+ $page->drawImage($pdfImage, 0, 0, $xSize, $ySize);
193
+ unlink($tmpFileName);
194
+
195
+ return $page;
196
+ }
197
+
198
+ /**
199
+ * Delete shipment if the manifest was not closed before
200
+ */
201
+ public function deleteAction()
202
+ {
203
+ $shipmentId = $this->getRequest()->getParam('shipment_id');
204
+ if (!$shipmentId) {
205
+ $this->_setDeleteResponse("No shipment was specified", $shipmentId);
206
+
207
+ return;
208
+ }
209
+ $shipment = Mage::getModel('sales/order_shipment');
210
+ /* @var $shipment Mage_Sales_Model_Order_Shipment */
211
+ $shipment->load($shipmentId);
212
+
213
+ $ships = Mage::getResourceModel('zitec_dpd/dpd_ship_collection');
214
+ /* @var $ships Zitec_Dpd_Model_Mysql4_Dpd_Ship_Collection */
215
+ $ship = $ships->getByShipmentId($shipmentId);
216
+ /* @var $ship Zitec_Dpd_Model_Dpd_Ship */
217
+ if (!$ship) {
218
+ $this->_setDeleteResponse("Could not find any DPD shipment information for this shipment.", $shipment);
219
+
220
+ return;
221
+ }
222
+
223
+ if ($ship->getManifestId()) {
224
+ $this->_setDeleteResponse("You cannot cancel this shipment with DPD because the manifest is already closed.", $shipment);
225
+
226
+ return;
227
+ }
228
+ $response = @unserialize($ship->getSaveShipmentResponse());
229
+ /* @var $response Zitec_Dpd_Api_Shipment_Save_Response */
230
+ if (!$response) {
231
+ $this->_setDeleteResponse("Unable to load shipment information for this shipment.", $shipment);
232
+
233
+ return;
234
+ }
235
+
236
+
237
+ try {
238
+ $wsResult = $this->_getWsHelper()->deleteWsShipment($shipment,$response);
239
+ } catch (Exception $e) {
240
+ $this->_setDeleteResponse('An error occurred whilst attempting to delete the shipment information with DPD. <br /> "%s"', $shipment, $e->getMessage());
241
+
242
+ return;
243
+ }
244
+
245
+ if ($wsResult->hasError()) {
246
+ $this->_setDeleteResponse('An error occurred whilst attempting to delete the shipment information with DPD. <br /> "%s"', $shipment, $wsResult->getErrorText());
247
+
248
+ return;
249
+ }
250
+
251
+ $shipment->setShippingLabel(null)->save();
252
+ $ship->setShippingLabels(null)->save();
253
+
254
+ $this->_forward("removeTrack", "sales_order_shipment", "admin");
255
+ }
256
+
257
+
258
+
259
+ protected function _setDeleteResponse($message, $shipment, $additional = '', $isError = true)
260
+ {
261
+ $response = array(
262
+ 'error' => $isError,
263
+ 'message' => $this->__($message, $additional),
264
+ );
265
+ $response = Mage::helper('core')->jsonEncode($response);
266
+ $this->getResponse()->setBody($response);
267
+ if ($isError) {
268
+ $isShipmentLoaded = $shipment instanceof Mage_Sales_Model_Order_Shipment;
269
+ $incrementId = $isShipmentLoaded ? $shipment->getIncrementId() : "Unknown";
270
+ $shipmentId = $isShipmentLoaded ? $shipment->getId() : $shipment;
271
+ $this->_getHelper()->log(sprintf("Error deleting shipment, id: %s, reference: %s", $shipmentId, $incrementId));
272
+ $this->_getHelper()->log(sprintf("Message: %s", $message));
273
+ if ($additional) {
274
+ $this->_getHelper()->log(sprintf("Additional: %s", $additional));
275
+ }
276
+ }
277
+
278
+ return $isError;
279
+ }
280
+
281
+
282
+ /**
283
+ *
284
+ * Create a pickup request in the future
285
+ * sender address have to be configures
286
+ * shipment should be already generated
287
+ * the manifest can be closed or not
288
+ */
289
+ public function createPickupAction()
290
+ {
291
+ $shipmentIds = $this->getRequest()->getParam("shipment_ids");
292
+ if (!$shipmentIds) {
293
+ $this->_createPickupRedirect($this->__('Please select the shipments for which you wish to arrange a pickup.'));
294
+
295
+ return;
296
+ }
297
+
298
+ list($day, $month, $year) = explode("/", $this->getRequest()->getParam("zitec_dpd_pickup_date"));
299
+ if (!checkdate($month, $day, $year)) {
300
+ $this->_createPickupRedirect($this->__('Please enter a pickup date in the format DD/MM/YYYY.'));
301
+
302
+ return;
303
+ }
304
+ $year = isset($year) && strlen($year) == 2 ? "20$year" : $year;
305
+ $month = isset($month) && strlen($month) < 2 ? str_pad($month, 2, "0") : $month;
306
+ $day = isset($day) && strlen($day) < 2 ? str_pad($day, 2, "0") : $day;
307
+ $pickupDate = "$year$month$day";
308
+
309
+ $pickupFromParts = $this->getRequest()->getParam("zitec_dpd_pickup_from");
310
+ if (!is_array($pickupFromParts) || count($pickupFromParts) != 3) {
311
+ $this->_createPickupRedirect($this->__('Please select a from and to time for the pickup.'));
312
+
313
+ return;
314
+ }
315
+ $pickupFrom = implode("", $pickupFromParts);
316
+
317
+ $pickupToParts = $this->getRequest()->getParam("zitec_dpd_pickup_to");
318
+ if (!is_array($pickupToParts) || count($pickupToParts) != 3) {
319
+ $this->_getHelper()->addError($this->__('Please select a from and to time for the pickup.'));
320
+ $this->_redirect("adminhtml/sales_shipment/index");
321
+
322
+ return;
323
+ }
324
+ $pickupTo = implode("", $pickupToParts);
325
+
326
+ $instruction = $this->getRequest()->getParam("zitec_dpd_pickup_instruction");
327
+
328
+ $pickupAddress = $this->_getWsHelper()->getPickupAddress();
329
+ if (!is_array($pickupAddress)) {
330
+ $this->_getHelper()->addError($this->__('You cannot create a pickup because you have not fully specified your pickup address. <br />Please set your pickup address in System->Configuration->Sales->Shipping Settings->DPD GeoPost Pickup Address.'));
331
+ $this->_redirect("adminhtml/sales_shipment/index");
332
+
333
+ return;
334
+ }
335
+
336
+ $apiParams = $this->_getWsHelper()->getPickupParams();
337
+ $apiParams['method'] = Zitec_Dpd_Api_Configs::METHOD_PICKUP_CREATE;
338
+
339
+ $dpdApi = new Zitec_Dpd_Api($apiParams);
340
+ $createPickup = $dpdApi->getApiMethodObject();
341
+
342
+ $createPickup->setPickupTime($pickupDate, $pickupFrom, $pickupTo);
343
+ $createPickup->setSpecialInstruction($instruction);
344
+ $createPickup->setPickupAddress($pickupAddress);
345
+
346
+ $shipments = Mage::getResourceModel('sales/order_shipment_collection');
347
+ /* @var $shipments Mage_Sales_Model_Resource_Order_Shipment_Collection */
348
+ $shipments->addFieldToFilter('entity_id', array("in" => $shipmentIds));
349
+
350
+ $ships = Mage::getResourceModel('zitec_dpd/dpd_ship_collection');
351
+ /* @var $ships Zitec_Dpd_Model_Mysql4_Dpd_Ship_Collection */
352
+ $ships->filterByShipmentIds($shipmentIds);
353
+
354
+
355
+ $includedShipments = array();
356
+ foreach ($shipments as $shipment) {
357
+ /* @var $shipment Mage_Sales_Model_Order_Shipment */
358
+ $ship = $ships->findByShipmentId($shipment->getId());
359
+ /* @var $ship Zitec_Dpd_Model_Dpd_Ship */
360
+ if (!$ship || !$this->_getHelper()->isShippingMethodDpd($shipment) || $this->_getHelper()->isCancelledWithDpd($shipment)) {
361
+ continue;
362
+ }
363
+ $includedShipments[] = $shipment;
364
+
365
+ $call = @unserialize($ship->getSaveShipmentCall());
366
+ /* @var $call Zitec_Dpd_Api_Shipment_Save */
367
+ if (!$call) {
368
+ $message = $this->__("Unable to load shipment information for this shipment %s.", $shipment);
369
+ $this->_createPickupRedirect($message);
370
+
371
+ return;
372
+ }
373
+ $createPickup->addPieces($call->getShipmentServiceCode(), $call->getParcelCount(), $call->getTotalWeight(), $call->getReceiverCountryCode());
374
+ }
375
+ if (!$includedShipments) {
376
+ $message = $this->__("Your list did not contain any DPD shipments for which to arrange a pickup.", $shipment);
377
+ $this->_createPickupRedirect($message);
378
+
379
+ return;
380
+ }
381
+
382
+ try {
383
+ $createPickup->execute();
384
+ } catch (Exception $e) {
385
+ $message = $this->__('A problem occurred whilst communicating your shipment to DPD. <br />"%s"', $e->getMessage());
386
+ $this->_getHelper()->log($message);
387
+ $this->_createPickupRedirect($message);
388
+
389
+ return;
390
+ }
391
+ $response = $createPickup->getCreatePickupResponse();
392
+ if ($response->hasError()) {
393
+ $message = $this->__('DPD reported an error whilst attempting to arrange your pickup. <br />DPD says, "%s"', $response->getErrorText());
394
+ $this->_getHelper()->log($message);
395
+ $this->_createPickupRedirect($message);
396
+
397
+ return;
398
+ }
399
+
400
+ $pickup = Mage::getModel('zitec_dpd/dpd_pickup');
401
+ /* @var $pickup Zitec_Dpd_Model_Dpd_Pickup */
402
+
403
+ $pickup->setReference($response->getReferenceNumber())
404
+ ->setDpdId($response->getDpdId())
405
+ ->setPickupDate("$year-$month-$day")
406
+ ->setPickupTimeFrom("$year-$month-$day " . implode(":", $pickupFromParts))
407
+ ->setPickupTimeTo("$year-$month-$day " . implode(":", $pickupToParts))
408
+ ->setCallData(serialize($createPickup))
409
+ ->setResponseData(serialize($response))
410
+ ->save();
411
+
412
+ foreach ($includedShipments as $includedShipment) {
413
+ $includedShipment->setData('zitec_dpd_pickup_time', "$year-$month-$day " . implode(":", $pickupFromParts));
414
+ $includedShipment->setData('zitec_dpd_pickup_id', $pickup->getEntityId());
415
+ $includedShipment->save();
416
+ }
417
+
418
+ $this->_getHelper()->addNotice("Your pickup was created successfully");
419
+ $this->_redirect("adminhtml/sales_shipment/index");
420
+ }
421
+
422
+
423
+
424
+ /**
425
+ *
426
+ * @param string $message
427
+ * @param boolean $isError
428
+ */
429
+ protected function _createPickupRedirect($message, $isError = true)
430
+ {
431
+ if ($isError) {
432
+ $this->_getHelper()->addError($message);
433
+ } else {
434
+ $this->_getHelper()->addNotice($message);
435
+ }
436
+ $this->_redirect("adminhtml/sales_shipment/index");
437
+ }
438
+
439
+
440
+
441
+
442
+
443
+
444
+ /**
445
+ *
446
+ * @return Zitec_Dpd_Helper_Ws
447
+ */
448
+ protected function _getWsHelper()
449
+ {
450
+ return Mage::helper('zitec_dpd/ws');
451
+ }
452
+
453
+ /**
454
+ *
455
+ * @return Zitec_Dpd_Helper_Data
456
+ */
457
+ protected function _getHelper()
458
+ {
459
+ return Mage::helper('zitec_dpd');
460
+ }
461
+
462
+
463
+ }
app/code/community/Zitec/Dpd/etc/adminhtml.xml CHANGED
@@ -1,75 +1,80 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <menu>
4
- <zitec_dpd>
5
- <title>DPD carrier</title>
6
- <sort_order>99999</sort_order>
7
- <action>zitec_shippingreports/adminhtml_reports_profitability/index</action>
8
- <children>
9
- <zitec_dpd translate="title" module="zitec_dpd">
10
- <title>Table Rates</title>
11
- <sort_order>20</sort_order>
12
- <action>zitec_tablerates/adminhtml_index/index/carrier/zitecDpd</action>
13
- </zitec_dpd>
14
- <zitec_dpd_shipment_settings translate="title" module="zitec_dpd">
15
- <title>Shipping settings</title>
16
- <sort_order>10</sort_order>
17
- <action>adminhtml/system_config/edit/section/carriers</action>
18
- </zitec_dpd_shipment_settings>
19
- <zitec_dpd_shipment_sender_settings translate="title" module="zitec_dpd">
20
- <title>Sender settings</title>
21
- <sort_order>12</sort_order>
22
- <action>adminhtml/system_config/edit/section/shipping/</action>
23
- </zitec_dpd_shipment_sender_settings>
24
- <zitec_dpd_payment_settings translate="title" module="zitec_dpd">
25
- <title>Payment settings</title>
26
- <sort_order>14</sort_order>
27
- <action>adminhtml/system_config/edit/section/payment</action>
28
- </zitec_dpd_payment_settings>
29
- <reports>
30
- <title>Report price vs cost</title>
31
- <sort_order>40</sort_order>
32
- <action>zitec_shippingreports/adminhtml_reports_profitability</action>
33
- </reports>
34
- </children>
35
- </zitec_dpd>
36
- </menu>
37
-
38
- <acl>
39
- <resources>
40
- <all>
41
- <title>Allow Everything</title>
42
- </all>
43
- <admin>
44
- <children>
45
- <zitec_dpd>
46
- <title>DPD GeoPost</title>
47
- <sort_order>0</sort_order>
48
- <children>
49
- <zitec_dpd translate="title" module="zitec_dpd">
50
- <title>DPD GeoPost - Table Rates</title>
51
- <sort_order>500</sort_order>
52
- </zitec_dpd>
53
- <zitec_dpd_shipment_settings translate="title" module="zitec_dpd">
54
- <title>DPD GeoPost - Shipping settings</title>
55
- <sort_order>500</sort_order>
56
- </zitec_dpd_shipment_settings>
57
- <zitec_dpd_shipment_sender_settings translate="title" module="zitec_dpd">
58
- <title>Sender settings</title>
59
- <sort_order>500</sort_order>
60
- </zitec_dpd_shipment_sender_settings>
61
- <zitec_dpd_payment_settings translate="title" module="zitec_dpd">
62
- <title>Payment settings</title>
63
- <sort_order>500</sort_order>
64
- </zitec_dpd_payment_settings>
65
- <reports translate="title" module="zitec_dpd">
66
- <title>DPD GeoPost</title>
67
- <sort_order>500</sort_order>
68
- </reports>
69
- </children>
70
- </zitec_dpd>
71
- </children>
72
- </admin>
73
- </resources>
74
- </acl>
 
 
 
 
 
75
  </config>
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <menu>
4
+ <zitec_dpd>
5
+ <title>DPD carrier</title>
6
+ <sort_order>99999</sort_order>
7
+ <action>zitec_shippingreports/adminhtml_reports_profitability/index</action>
8
+ <children>
9
+ <zitec_dpd translate="title" module="zitec_dpd">
10
+ <title>Table Rates</title>
11
+ <sort_order>20</sort_order>
12
+ <action>zitec_tablerates/adminhtml_index/index/carrier/zitecDpd</action>
13
+ </zitec_dpd>
14
+ <zitec_dpd_shipment_settings translate="title" module="zitec_dpd">
15
+ <title>Shipping settings</title>
16
+ <sort_order>10</sort_order>
17
+ <action>adminhtml/system_config/edit/section/carriers</action>
18
+ </zitec_dpd_shipment_settings>
19
+ <zitec_dpd_shipment_sender_settings translate="title" module="zitec_dpd">
20
+ <title>Sender settings</title>
21
+ <sort_order>12</sort_order>
22
+ <action>adminhtml/system_config/edit/section/shipping/</action>
23
+ </zitec_dpd_shipment_sender_settings>
24
+ <zitec_dpd_payment_settings translate="title" module="zitec_dpd">
25
+ <title>Payment settings</title>
26
+ <sort_order>14</sort_order>
27
+ <action>adminhtml/system_config/edit/section/payment</action>
28
+ </zitec_dpd_payment_settings>
29
+ <postcode_updater>
30
+ <title>Postcode update manager</title>
31
+ <sort_order>16</sort_order>
32
+ <action>zitec_dpd/adminhtml_postcode/updateForm</action>
33
+ </postcode_updater>
34
+ <reports>
35
+ <title>Report price vs cost</title>
36
+ <sort_order>40</sort_order>
37
+ <action>zitec_shippingreports/adminhtml_reports_profitability</action>
38
+ </reports>
39
+ </children>
40
+ </zitec_dpd>
41
+ </menu>
42
+
43
+ <acl>
44
+ <resources>
45
+ <all>
46
+ <title>Allow Everything</title>
47
+ </all>
48
+ <admin>
49
+ <children>
50
+ <zitec_dpd>
51
+ <title>DPD GeoPost</title>
52
+ <sort_order>0</sort_order>
53
+ <children>
54
+ <zitec_dpd translate="title" module="zitec_dpd">
55
+ <title>DPD GeoPost - Table Rates</title>
56
+ <sort_order>500</sort_order>
57
+ </zitec_dpd>
58
+ <zitec_dpd_shipment_settings translate="title" module="zitec_dpd">
59
+ <title>DPD GeoPost - Shipping settings</title>
60
+ <sort_order>500</sort_order>
61
+ </zitec_dpd_shipment_settings>
62
+ <zitec_dpd_shipment_sender_settings translate="title" module="zitec_dpd">
63
+ <title>Sender settings</title>
64
+ <sort_order>500</sort_order>
65
+ </zitec_dpd_shipment_sender_settings>
66
+ <zitec_dpd_payment_settings translate="title" module="zitec_dpd">
67
+ <title>Payment settings</title>
68
+ <sort_order>500</sort_order>
69
+ </zitec_dpd_payment_settings>
70
+ <reports translate="title" module="zitec_dpd">
71
+ <title>DPD GeoPost</title>
72
+ <sort_order>500</sort_order>
73
+ </reports>
74
+ </children>
75
+ </zitec_dpd>
76
+ </children>
77
+ </admin>
78
+ </resources>
79
+ </acl>
80
  </config>
app/code/community/Zitec/Dpd/etc/config.xml CHANGED
@@ -1,398 +1,398 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Zitec_Dpd>
5
- <version>1.0.3</version>
6
- </Zitec_Dpd>
7
- </modules>
8
- <global>
9
- <models>
10
- <zitec_dpd>
11
- <class>Zitec_Dpd_Model</class>
12
- <resourceModel>zitec_dpd_mysql4</resourceModel>
13
- </zitec_dpd>
14
- <zitec_dpd_mysql4>
15
- <class>Zitec_Dpd_Model_Mysql4</class>
16
- <entities>
17
- <zitec_dpd_ship>
18
- <table>zitec_dpd_ships</table>
19
- </zitec_dpd_ship>
20
- <carrier_tablerate>
21
- <table>zitec_dpd_tablerate</table>
22
- </carrier_tablerate>
23
- <zitec_dpd_pickup_order>
24
- <table>zitec_dpd_pickup_order</table>
25
- </zitec_dpd_pickup_order>
26
- <zitec_dpd_manifest>
27
- <table>zitec_dpd_manifest</table>
28
- </zitec_dpd_manifest>
29
- </entities>
30
- </zitec_dpd_mysql4>
31
- <sales>
32
- <rewrite>
33
- <order_creditmemo_total_tax>Zitec_Dpd_Model_Sales_Order_Creditmemo_Total_Tax</order_creditmemo_total_tax>
34
- <order_invoice_total_tax>Zitec_Dpd_Model_Sales_Order_Invoice_Total_Tax</order_invoice_total_tax>
35
- </rewrite>
36
- </sales>
37
- </models>
38
- <resources>
39
- <zitec_dpd_setup>
40
- <setup>
41
- <module>Zitec_Dpd</module>
42
- </setup>
43
- <connection>
44
- <use>core_setup</use>
45
- </connection>
46
- </zitec_dpd_setup>
47
- <zitec_dpd_write>
48
- <connection>
49
- <use>core_write</use>
50
- </connection>
51
- </zitec_dpd_write>
52
- <zitec_dpd_read>
53
- <connection>
54
- <use>core_read</use>
55
- </connection>
56
- </zitec_dpd_read>
57
- </resources>
58
- <blocks>
59
- <zitec_dpd>
60
- <class>Zitec_Dpd_Block</class>
61
- </zitec_dpd>
62
- <adminhtml>
63
- <rewrite>
64
- <sales_order_shipment_view_tracking>Zitec_Dpd_Block_Adminhtml_Sales_Order_Shipment_View_Tracking</sales_order_shipment_view_tracking>
65
- <!-- <sales_order_shipment_view>Zitec_Dpd_Block_Adminhtml_Sales_Order_Shipment_View</sales_order_shipment_view> -->
66
- <sales_shipment_grid>Zitec_Dpd_Block_Adminhtml_Sales_Shipment_Grid</sales_shipment_grid>
67
- </rewrite>
68
- </adminhtml>
69
- </blocks>
70
- <helpers>
71
- <zitec_dpd>
72
- <class>Zitec_Dpd_Helper</class>
73
- </zitec_dpd>
74
- </helpers>
75
- <resources>
76
- <zitec_dpd_setup>
77
- <setup>
78
- <module>Zitec_Dpd</module>
79
- </setup>
80
- </zitec_dpd_setup>
81
- </resources>
82
- <events>
83
- <core_block_abstract_to_html_after>
84
- <observers>
85
- <zitec_dpd>
86
- <type>singleton</type>
87
- <class>zitec_dpd/observer_shipment</class>
88
- <method>adminAddPostcodeAutocompleteBlock</method>
89
- </zitec_dpd>
90
- </observers>
91
- </core_block_abstract_to_html_after>
92
- <sales_order_shipment_save_before>
93
- <observers>
94
- <zitec_dpd>
95
- <type>singleton</type>
96
- <class>zitec_dpd/observer_shipment</class>
97
- <method>salesOrderShipmentSaveBefore</method>
98
- </zitec_dpd>
99
- </observers>
100
- </sales_order_shipment_save_before>
101
- <sales_order_shipment_save_after>
102
- <observers>
103
- <zitec_dpd>
104
- <type>singleton</type>
105
- <class>zitec_dpd/observer_shipment</class>
106
- <method>salesOrderShipmentSaveAfter</method>
107
- </zitec_dpd>
108
- </observers>
109
- </sales_order_shipment_save_after>
110
- <sales_order_address_save_after>
111
- <observers>
112
- <zitec_dpd>
113
- <type>singleton</type>
114
- <class>zitec_dpd/observer_address</class>
115
- <method>salesOrderAddressAfterSave</method>
116
- </zitec_dpd>
117
- </observers>
118
- </sales_order_address_save_after>
119
-
120
- <core_block_abstract_prepare_layout_before>
121
- <observers>
122
- <zitec_dpd_print_manifest>
123
- <class>zitec_dpd/observer_manifest</class>
124
- <method>addManifestMassAction</method>
125
- </zitec_dpd_print_manifest>
126
- <zitec_dpd_create_pickup>
127
- <class>zitec_dpd/observer_pickup</class>
128
- <method>createPickupAction</method>
129
- </zitec_dpd_create_pickup>
130
- </observers>
131
- </core_block_abstract_prepare_layout_before>
132
- <sales_quote_payment_import_data_before>
133
- <observers>
134
- <zitec_dpd_force_recolect_totals_checkout>
135
- <class>zitec_dpd/observer_payment</class>
136
- <method>setTotalsCollectedFlag</method>
137
- </zitec_dpd_force_recolect_totals_checkout>
138
- </observers>
139
- </sales_quote_payment_import_data_before>
140
- <adminhtml_sales_order_create_process_data_before>
141
- <observers>
142
- <zitec_dpd_force_refresh_totals_admin_order_create>
143
- <class>zitec_dpd/observer_payment</class>
144
- <method>refreshTotalsInAdminOrderCreate</method>
145
- </zitec_dpd_force_refresh_totals_admin_order_create>
146
- </observers>
147
- </adminhtml_sales_order_create_process_data_before>
148
- <sales_order_address_save_before>
149
- <observers>
150
- <zitec_dpd_sales_order_address_save_before>
151
- <type>singleton</type>
152
- <class>zitec_dpd/observer_address</class>
153
- <method>salesOrderAddressBeforeSave</method>
154
- </zitec_dpd_sales_order_address_save_before>
155
- </observers>
156
- </sales_order_address_save_before>
157
-
158
- </events>
159
- <sales>
160
- <shipping>
161
- <carriers>
162
- <zitec_dpd>
163
- <class>Zitec_Dpd_Model_Shipping_Carrier_DPD</class>
164
- </zitec_dpd>
165
- </carriers>
166
- </shipping>
167
- <quote>
168
- <totals>
169
- <zitec_dpd_cashondelivery_surcharge>
170
- <class>zitec_dpd/sales_quote_address_total_cashondeliverysurchage</class>
171
- <after>shipping,tax_shipping</after>
172
- <before>tax,grand_total</before>
173
- <renderer>zitec_dpd/tax_checkout_cashondeliverysurchage</renderer>
174
- </zitec_dpd_cashondelivery_surcharge>
175
- <grand_total>
176
- <after>zitec_dpd_cashondelivery_surcharge,tax</after>
177
- <before>msrp</before>
178
- </grand_total>
179
- <tax>
180
- <before>grand_total</before>
181
- <after>zitec_dpd_cashondelivery_surcharge</after>
182
- </tax>
183
- <msrp>
184
- <after>grand_total</after>
185
- </msrp>
186
- </totals>
187
-
188
- </quote>
189
- <order_invoice>
190
- <totals>
191
- <zitec_dpd_cashondelivery_surcharge>
192
- <class>zitec_dpd/sales_order_invoice_total_cashondeliverysurchage</class>
193
- <after>shipping</after>
194
- <before>tax,grand_total</before>
195
- </zitec_dpd_cashondelivery_surcharge>
196
- </totals>
197
- </order_invoice>
198
- <order_creditmemo>
199
- <totals>
200
- <zitec_dpd_cashondelivery_surcharge>
201
- <class>zitec_dpd/sales_order_creditmemo_total_cashondeliverysurchage</class>
202
- <after>shipping</after>
203
- <before>tax,grand_total</before>
204
- </zitec_dpd_cashondelivery_surcharge>
205
- </totals>
206
- </order_creditmemo>
207
- </sales>
208
- <fieldsets>
209
- <sales_convert_quote_address>
210
- <zitec_dpd_cashondelivery_surcharge>
211
- <to_order>*</to_order>
212
- </zitec_dpd_cashondelivery_surcharge>
213
- <base_zitec_dpd_cashondelivery_surcharge>
214
- <to_order>*</to_order>
215
- </base_zitec_dpd_cashondelivery_surcharge>
216
- <zitec_dpd_cashondelivery_surcharge_tax>
217
- <to_order>*</to_order>
218
- </zitec_dpd_cashondelivery_surcharge_tax>
219
- <base_zitec_dpd_cashondelivery_surcharge_tax>
220
- <to_order>*</to_order>
221
- </base_zitec_dpd_cashondelivery_surcharge_tax>
222
- <valid_auto_postcode>
223
- <to_order_address>*</to_order_address>
224
- </valid_auto_postcode>
225
- <auto_postcode>
226
- <to_order_address>*</to_order_address>
227
- </auto_postcode>
228
- </sales_convert_quote_address>
229
- </fieldsets>
230
- <pdf>
231
- <totals>
232
- <zitec_dpd_cashondelivery_surcharge translate="title">
233
- <title>Recargo contrareembolso</title>
234
- <model>zitec_dpd/sales_order_pdf_total_cashondeliverysurchage</model>
235
- <source_field>zitec_dpd_cashondelivery_surcharge</source_field>
236
- <font_size>7</font_size>
237
- <display_zero>0</display_zero>
238
- <sort_order>410</sort_order>
239
- </zitec_dpd_cashondelivery_surcharge>
240
- </totals>
241
- </pdf>
242
- </global>
243
- <adminhtml>
244
- <translate>
245
- <modules>
246
- <Zitec_Dpd>
247
- <files>
248
- <default>Zitec_Dpd.csv</default>
249
- </files>
250
- </Zitec_Dpd>
251
- </modules>
252
- </translate>
253
-
254
- <layout>
255
- <updates>
256
- <zitec_dpd>
257
- <file>zitec_dpd.xml</file>
258
- </zitec_dpd>
259
- </updates>
260
- </layout>
261
-
262
- </adminhtml>
263
- <frontend>
264
- <layout>
265
- <updates>
266
- <zitec_dpd>
267
- <file>zitec_dpd.xml</file>
268
- </zitec_dpd>
269
- </updates>
270
- </layout>
271
- <translate>
272
- <modules>
273
- <Zitec_Dpd>
274
- <files>
275
- <default>Zitec_Dpd_frontend.csv</default>
276
- </files>
277
- </Zitec_Dpd>
278
- </modules>
279
- </translate>
280
- </frontend>
281
- <admin>
282
- <routers>
283
- <zitec_dpd>
284
- <use>admin</use>
285
- <args>
286
- <module>Zitec_Dpd</module>
287
- <frontName>zitec_dpd</frontName>
288
- </args>
289
- </zitec_dpd>
290
- </routers>
291
- </admin>
292
- <frontend>
293
- <routers>
294
- <zitec_dpd>
295
- <use>standard</use>
296
- <args>
297
- <module>Zitec_Dpd</module>
298
- <frontName>zitec_dpd</frontName>
299
- </args>
300
- </zitec_dpd>
301
- </routers>
302
- </frontend>
303
-
304
- <default>
305
- <carriers>
306
- <zitecDpd>
307
- <postcode_autocomplete_checkout>1</postcode_autocomplete_checkout>
308
- <connectionTimeout>10</connectionTimeout>
309
- <model>zitec_dpd/shipping_carrier_dpd</model>
310
- <countryurls>
311
- <CZ>
312
- <production>https://it4em.dpd.cz/IT4EMWebServices/eshop/</production>
313
- <test>http://it4emtest.dpd.cz:7777/IT4EMWebServices/eshop/</test>
314
- </CZ>
315
- <SK>
316
- <production>https://it4em.dpd.sk/IT4EMWebServices/eshop/</production>
317
- <test></test>
318
- </SK>
319
- <RO>
320
- <production>https://it4em.dpd.ro/IT4EMWebServices/eshop/</production>
321
- <test></test>
322
- </RO>
323
- <SI>
324
- <production>https://it4em.dpd.si/IT4EMWebServices/eshop/</production>
325
- <test></test>
326
- </SI>
327
- <HR>
328
- <production>https://it4em.dpd.hr/IT4EMWebServices/eshop/</production>
329
- <test></test>
330
- </HR>
331
- <LT>
332
- <production>https://integration.dpd.lt:8443/IT4EMWebServices/eshop/</production>
333
- <test>https://integrationtest.dpd.lt:8183/IT4EMWebServices/eshop/</test>
334
- </LT>
335
- <LV>
336
- <production>https://integration.dpd.lv:8443/IT4EMWebServices/eshop/</production>
337
- <test>https://integrationtest.dpd.lv:8183/IT4EMWebServices/eshop/</test>
338
- </LV>
339
- <EE>
340
- <production>https://integration.dpd.ee:8443/IT4EMWebServices/eshop/</production>
341
- <test>https://integrationtest.dpd.ee:8183/IT4EMWebServices/eshop/</test>
342
- </EE>
343
- </countryurls>
344
- <shipmentUrlPart>ShipmentServiceImpl?wsdl</shipmentUrlPart>
345
- <manifestUrlPart>ManifestServiceImpl?wsdl</manifestUrlPart>
346
- <pickupUrlPart>PickupOrderServiceImpl?wsdl</pickupUrlPart>
347
- <zitec_tablerates>
348
- <grid_title>DPD Table Rates</grid_title>
349
- <tablerates_db_table>zitec_dpd/carrier_tablerate</tablerates_db_table>
350
- <features>
351
- <markup_type>1</markup_type>
352
- <price_vs_dest>1</price_vs_dest>
353
- <cash_on_delivery>1</cash_on_delivery>
354
- <cod_min_surcharge>1</cod_min_surcharge>
355
- </features>
356
- <db_table_field_names>
357
- <weight_price>weight</weight_price>
358
- </db_table_field_names>
359
- <method_source>zitec_dpd/config_source_service</method_source>
360
- <export_action>zitec_dpd/adminhtml_config/exportTablerates</export_action>
361
- <import>
362
- <resource_class>zitec_dpd/carrier_tablerate</resource_class>
363
- <method>uploadAndImport</method>
364
- </import>
365
- </zitec_tablerates>
366
- </zitecDpd>
367
- </carriers>
368
- <payment>
369
- <zitec_dpd_cashondelivery>
370
- <active>1</active>
371
- <title>Cash On Delivery</title>
372
- <total_title>Cash On Delivery Surcharge</total_title>
373
- <order_status>zitec_dpd_pending_cashondelivery</order_status>
374
- <model>zitec_dpd/payment_cashondelivery</model>
375
- <services>1,9,10,27,109,40033,40107</services>
376
- <specificproducto>1,9,10,27,109,40033,40107</specificproducto>
377
- <cod_payment_type>Cash</cod_payment_type>
378
- <payment_amount_type>1</payment_amount_type>
379
- <payment_amount>0</payment_amount>
380
- </zitec_dpd_cashondelivery>
381
- </payment>
382
- <sales>
383
- <totals_sort>
384
- <zitec_dpd_cashondelivery_surcharge>35</zitec_dpd_cashondelivery_surcharge>
385
- </totals_sort>
386
- </sales>
387
- <zitec_fieldlengths>
388
- <checkout_onepage_index>
389
- <street_address>
390
- <idStartsWith>shipping:street</idStartsWith>
391
- <maxLength>70</maxLength>
392
- </street_address>
393
- </checkout_onepage_index>
394
- </zitec_fieldlengths>
395
-
396
- </default>
397
-
398
  </config>
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Zitec_Dpd>
5
+ <version>1.0.6</version>
6
+ </Zitec_Dpd>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <zitec_dpd>
11
+ <class>Zitec_Dpd_Model</class>
12
+ <resourceModel>zitec_dpd_mysql4</resourceModel>
13
+ </zitec_dpd>
14
+ <zitec_dpd_mysql4>
15
+ <class>Zitec_Dpd_Model_Mysql4</class>
16
+ <entities>
17
+ <zitec_dpd_ship>
18
+ <table>zitec_dpd_ships</table>
19
+ </zitec_dpd_ship>
20
+ <carrier_tablerate>
21
+ <table>zitec_dpd_tablerate</table>
22
+ </carrier_tablerate>
23
+ <zitec_dpd_pickup_order>
24
+ <table>zitec_dpd_pickup_order</table>
25
+ </zitec_dpd_pickup_order>
26
+ <zitec_dpd_manifest>
27
+ <table>zitec_dpd_manifest</table>
28
+ </zitec_dpd_manifest>
29
+ </entities>
30
+ </zitec_dpd_mysql4>
31
+ <sales>
32
+ <rewrite>
33
+ <order_creditmemo_total_tax>Zitec_Dpd_Model_Sales_Order_Creditmemo_Total_Tax</order_creditmemo_total_tax>
34
+ <order_invoice_total_tax>Zitec_Dpd_Model_Sales_Order_Invoice_Total_Tax</order_invoice_total_tax>
35
+ </rewrite>
36
+ </sales>
37
+ </models>
38
+ <resources>
39
+ <zitec_dpd_setup>
40
+ <setup>
41
+ <module>Zitec_Dpd</module>
42
+ </setup>
43
+ <connection>
44
+ <use>core_setup</use>
45
+ </connection>
46
+ </zitec_dpd_setup>
47
+ <zitec_dpd_write>
48
+ <connection>
49
+ <use>core_write</use>
50
+ </connection>
51
+ </zitec_dpd_write>
52
+ <zitec_dpd_read>
53
+ <connection>
54
+ <use>core_read</use>
55
+ </connection>
56
+ </zitec_dpd_read>
57
+ </resources>
58
+ <blocks>
59
+ <zitec_dpd>
60
+ <class>Zitec_Dpd_Block</class>
61
+ </zitec_dpd>
62
+ <adminhtml>
63
+ <rewrite>
64
+ <sales_order_shipment_view_tracking>Zitec_Dpd_Block_Adminhtml_Sales_Order_Shipment_View_Tracking</sales_order_shipment_view_tracking>
65
+ <!-- <sales_order_shipment_view>Zitec_Dpd_Block_Adminhtml_Sales_Order_Shipment_View</sales_order_shipment_view> -->
66
+ <sales_shipment_grid>Zitec_Dpd_Block_Adminhtml_Sales_Shipment_Grid</sales_shipment_grid>
67
+ </rewrite>
68
+ </adminhtml>
69
+ </blocks>
70
+ <helpers>
71
+ <zitec_dpd>
72
+ <class>Zitec_Dpd_Helper</class>
73
+ </zitec_dpd>
74
+ </helpers>
75
+ <resources>
76
+ <zitec_dpd_setup>
77
+ <setup>
78
+ <module>Zitec_Dpd</module>
79
+ </setup>
80
+ </zitec_dpd_setup>
81
+ </resources>
82
+ <events>
83
+ <core_block_abstract_to_html_after>
84
+ <observers>
85
+ <zitec_dpd>
86
+ <type>singleton</type>
87
+ <class>zitec_dpd/observer_shipment</class>
88
+ <method>adminAddPostcodeAutocompleteBlock</method>
89
+ </zitec_dpd>
90
+ </observers>
91
+ </core_block_abstract_to_html_after>
92
+ <sales_order_shipment_save_before>
93
+ <observers>
94
+ <zitec_dpd>
95
+ <type>singleton</type>
96
+ <class>zitec_dpd/observer_shipment</class>
97
+ <method>salesOrderShipmentSaveBefore</method>
98
+ </zitec_dpd>
99
+ </observers>
100
+ </sales_order_shipment_save_before>
101
+ <sales_order_shipment_save_after>
102
+ <observers>
103
+ <zitec_dpd>
104
+ <type>singleton</type>
105
+ <class>zitec_dpd/observer_shipment</class>
106
+ <method>salesOrderShipmentSaveAfter</method>
107
+ </zitec_dpd>
108
+ </observers>
109
+ </sales_order_shipment_save_after>
110
+ <sales_order_address_save_after>
111
+ <observers>
112
+ <zitec_dpd>
113
+ <type>singleton</type>
114
+ <class>zitec_dpd/observer_address</class>
115
+ <method>salesOrderAddressAfterSave</method>
116
+ </zitec_dpd>
117
+ </observers>
118
+ </sales_order_address_save_after>
119
+
120
+ <core_block_abstract_prepare_layout_before>
121
+ <observers>
122
+ <zitec_dpd_print_manifest>
123
+ <class>zitec_dpd/observer_manifest</class>
124
+ <method>addManifestMassAction</method>
125
+ </zitec_dpd_print_manifest>
126
+ <zitec_dpd_create_pickup>
127
+ <class>zitec_dpd/observer_pickup</class>
128
+ <method>createPickupAction</method>
129
+ </zitec_dpd_create_pickup>
130
+ </observers>
131
+ </core_block_abstract_prepare_layout_before>
132
+ <sales_quote_payment_import_data_before>
133
+ <observers>
134
+ <zitec_dpd_force_recolect_totals_checkout>
135
+ <class>zitec_dpd/observer_payment</class>
136
+ <method>setTotalsCollectedFlag</method>
137
+ </zitec_dpd_force_recolect_totals_checkout>
138
+ </observers>
139
+ </sales_quote_payment_import_data_before>
140
+ <adminhtml_sales_order_create_process_data_before>
141
+ <observers>
142
+ <zitec_dpd_force_refresh_totals_admin_order_create>
143
+ <class>zitec_dpd/observer_payment</class>
144
+ <method>refreshTotalsInAdminOrderCreate</method>
145
+ </zitec_dpd_force_refresh_totals_admin_order_create>
146
+ </observers>
147
+ </adminhtml_sales_order_create_process_data_before>
148
+ <sales_order_address_save_before>
149
+ <observers>
150
+ <zitec_dpd_sales_order_address_save_before>
151
+ <type>singleton</type>
152
+ <class>zitec_dpd/observer_address</class>
153
+ <method>salesOrderAddressBeforeSave</method>
154
+ </zitec_dpd_sales_order_address_save_before>
155
+ </observers>
156
+ </sales_order_address_save_before>
157
+
158
+ </events>
159
+ <sales>
160
+ <shipping>
161
+ <carriers>
162
+ <zitec_dpd>
163
+ <class>Zitec_Dpd_Model_Shipping_Carrier_DPD</class>
164
+ </zitec_dpd>
165
+ </carriers>
166
+ </shipping>
167
+ <quote>
168
+ <totals>
169
+ <zitec_dpd_cashondelivery_surcharge>
170
+ <class>zitec_dpd/sales_quote_address_total_cashondeliverysurchage</class>
171
+ <after>shipping,tax_shipping</after>
172
+ <before>tax,grand_total</before>
173
+ <renderer>zitec_dpd/tax_checkout_cashondeliverysurchage</renderer>
174
+ </zitec_dpd_cashondelivery_surcharge>
175
+ <grand_total>
176
+ <after>zitec_dpd_cashondelivery_surcharge,tax</after>
177
+ <before>msrp</before>
178
+ </grand_total>
179
+ <tax>
180
+ <before>grand_total</before>
181
+ <after>zitec_dpd_cashondelivery_surcharge</after>
182
+ </tax>
183
+ <msrp>
184
+ <after>grand_total</after>
185
+ </msrp>
186
+ </totals>
187
+
188
+ </quote>
189
+ <order_invoice>
190
+ <totals>
191
+ <zitec_dpd_cashondelivery_surcharge>
192
+ <class>zitec_dpd/sales_order_invoice_total_cashondeliverysurchage</class>
193
+ <after>shipping</after>
194
+ <before>tax,grand_total</before>
195
+ </zitec_dpd_cashondelivery_surcharge>
196
+ </totals>
197
+ </order_invoice>
198
+ <order_creditmemo>
199
+ <totals>
200
+ <zitec_dpd_cashondelivery_surcharge>
201
+ <class>zitec_dpd/sales_order_creditmemo_total_cashondeliverysurchage</class>
202
+ <after>shipping</after>
203
+ <before>tax,grand_total</before>
204
+ </zitec_dpd_cashondelivery_surcharge>
205
+ </totals>
206
+ </order_creditmemo>
207
+ </sales>
208
+ <fieldsets>
209
+ <sales_convert_quote_address>
210
+ <zitec_dpd_cashondelivery_surcharge>
211
+ <to_order>*</to_order>
212
+ </zitec_dpd_cashondelivery_surcharge>
213
+ <base_zitec_dpd_cashondelivery_surcharge>
214
+ <to_order>*</to_order>
215
+ </base_zitec_dpd_cashondelivery_surcharge>
216
+ <zitec_dpd_cashondelivery_surcharge_tax>
217
+ <to_order>*</to_order>
218
+ </zitec_dpd_cashondelivery_surcharge_tax>
219
+ <base_zitec_dpd_cashondelivery_surcharge_tax>
220
+ <to_order>*</to_order>
221
+ </base_zitec_dpd_cashondelivery_surcharge_tax>
222
+ <valid_auto_postcode>
223
+ <to_order_address>*</to_order_address>
224
+ </valid_auto_postcode>
225
+ <auto_postcode>
226
+ <to_order_address>*</to_order_address>
227
+ </auto_postcode>
228
+ </sales_convert_quote_address>
229
+ </fieldsets>
230
+ <pdf>
231
+ <totals>
232
+ <zitec_dpd_cashondelivery_surcharge translate="title">
233
+ <title>Recargo contrareembolso</title>
234
+ <model>zitec_dpd/sales_order_pdf_total_cashondeliverysurchage</model>
235
+ <source_field>zitec_dpd_cashondelivery_surcharge</source_field>
236
+ <font_size>7</font_size>
237
+ <display_zero>0</display_zero>
238
+ <sort_order>410</sort_order>
239
+ </zitec_dpd_cashondelivery_surcharge>
240
+ </totals>
241
+ </pdf>
242
+ </global>
243
+ <adminhtml>
244
+ <translate>
245
+ <modules>
246
+ <Zitec_Dpd>
247
+ <files>
248
+ <default>Zitec_Dpd.csv</default>
249
+ </files>
250
+ </Zitec_Dpd>
251
+ </modules>
252
+ </translate>
253
+
254
+ <layout>
255
+ <updates>
256
+ <zitec_dpd>
257
+ <file>zitec_dpd.xml</file>
258
+ </zitec_dpd>
259
+ </updates>
260
+ </layout>
261
+
262
+ </adminhtml>
263
+ <frontend>
264
+ <layout>
265
+ <updates>
266
+ <zitec_dpd>
267
+ <file>zitec_dpd.xml</file>
268
+ </zitec_dpd>
269
+ </updates>
270
+ </layout>
271
+ <translate>
272
+ <modules>
273
+ <Zitec_Dpd>
274
+ <files>
275
+ <default>Zitec_Dpd_frontend.csv</default>
276
+ </files>
277
+ </Zitec_Dpd>
278
+ </modules>
279
+ </translate>
280
+ </frontend>
281
+ <admin>
282
+ <routers>
283
+ <zitec_dpd>
284
+ <use>admin</use>
285
+ <args>
286
+ <module>Zitec_Dpd</module>
287
+ <frontName>zitec_dpd</frontName>
288
+ </args>
289
+ </zitec_dpd>
290
+ </routers>
291
+ </admin>
292
+ <frontend>
293
+ <routers>
294
+ <zitec_dpd>
295
+ <use>standard</use>
296
+ <args>
297
+ <module>Zitec_Dpd</module>
298
+ <frontName>zitec_dpd</frontName>
299
+ </args>
300
+ </zitec_dpd>
301
+ </routers>
302
+ </frontend>
303
+
304
+ <default>
305
+ <carriers>
306
+ <zitecDpd>
307
+ <postcode_autocomplete_checkout>1</postcode_autocomplete_checkout>
308
+ <connectionTimeout>10</connectionTimeout>
309
+ <model>zitec_dpd/shipping_carrier_dpd</model>
310
+ <countryurls>
311
+ <CZ>
312
+ <production>https://it4em.dpd.cz/IT4EMWebServices/eshop/</production>
313
+ <test>http://it4emtest.dpd.cz:7777/IT4EMWebServices/eshop/</test>
314
+ </CZ>
315
+ <SK>
316
+ <production>https://it4em.dpd.sk/IT4EMWebServices/eshop/</production>
317
+ <test></test>
318
+ </SK>
319
+ <RO>
320
+ <production>https://it4em.dpd.ro/IT4EMWebServices/eshop/</production>
321
+ <test></test>
322
+ </RO>
323
+ <SI>
324
+ <production>https://it4em.dpd.si/IT4EMWebServices/eshop/</production>
325
+ <test></test>
326
+ </SI>
327
+ <HR>
328
+ <production>https://it4em.dpd.hr/IT4EMWebServices/eshop/</production>
329
+ <test></test>
330
+ </HR>
331
+ <LT>
332
+ <production>https://integration.dpd.lt:8443/IT4EMWebServices/eshop/</production>
333
+ <test>https://integrationtest.dpd.lt:8183/IT4EMWebServices/eshop/</test>
334
+ </LT>
335
+ <LV>
336
+ <production>https://integration.dpd.lv:8443/IT4EMWebServices/eshop/</production>
337
+ <test>https://integrationtest.dpd.lv:8183/IT4EMWebServices/eshop/</test>
338
+ </LV>
339
+ <EE>
340
+ <production>https://integration.dpd.ee:8443/IT4EMWebServices/eshop/</production>
341
+ <test>https://integrationtest.dpd.ee:8183/IT4EMWebServices/eshop/</test>
342
+ </EE>
343
+ </countryurls>
344
+ <shipmentUrlPart>ShipmentServiceImpl?wsdl</shipmentUrlPart>
345
+ <manifestUrlPart>ManifestServiceImpl?wsdl</manifestUrlPart>
346
+ <pickupUrlPart>PickupOrderServiceImpl?wsdl</pickupUrlPart>
347
+ <zitec_tablerates>
348
+ <grid_title>DPD Table Rates</grid_title>
349
+ <tablerates_db_table>zitec_dpd/carrier_tablerate</tablerates_db_table>
350
+ <features>
351
+ <markup_type>1</markup_type>
352
+ <price_vs_dest>1</price_vs_dest>
353
+ <cash_on_delivery>1</cash_on_delivery>
354
+ <cod_min_surcharge>1</cod_min_surcharge>
355
+ </features>
356
+ <db_table_field_names>
357
+ <weight_price>weight</weight_price>
358
+ </db_table_field_names>
359
+ <method_source>zitec_dpd/config_source_service</method_source>
360
+ <export_action>zitec_dpd/adminhtml_config/exportTablerates</export_action>
361
+ <import>
362
+ <resource_class>zitec_dpd/carrier_tablerate</resource_class>
363
+ <method>uploadAndImport</method>
364
+ </import>
365
+ </zitec_tablerates>
366
+ </zitecDpd>
367
+ </carriers>
368
+ <payment>
369
+ <zitec_dpd_cashondelivery>
370
+ <active>1</active>
371
+ <title>Cash On Delivery</title>
372
+ <total_title>Cash On Delivery Surcharge</total_title>
373
+ <order_status>zitec_dpd_pending_cashondelivery</order_status>
374
+ <model>zitec_dpd/payment_cashondelivery</model>
375
+ <services>1,9,10,27,109,40033,40107</services>
376
+ <specificproducto>1,9,10,27,109,40033,40107</specificproducto>
377
+ <cod_payment_type>Cash</cod_payment_type>
378
+ <payment_amount_type>1</payment_amount_type>
379
+ <payment_amount>0</payment_amount>
380
+ </zitec_dpd_cashondelivery>
381
+ </payment>
382
+ <sales>
383
+ <totals_sort>
384
+ <zitec_dpd_cashondelivery_surcharge>35</zitec_dpd_cashondelivery_surcharge>
385
+ </totals_sort>
386
+ </sales>
387
+ <zitec_fieldlengths>
388
+ <checkout_onepage_index>
389
+ <street_address>
390
+ <idStartsWith>shipping:street</idStartsWith>
391
+ <maxLength>70</maxLength>
392
+ </street_address>
393
+ </checkout_onepage_index>
394
+ </zitec_fieldlengths>
395
+
396
+ </default>
397
+
398
  </config>
app/code/community/Zitec/Dpd/etc/system.xml CHANGED
@@ -1,380 +1,380 @@
1
- <config>
2
- <sections>
3
- <carriers>
4
- <groups>
5
- <zitecDpd>
6
- <label>DPD GeoPost By Zitec</label>
7
- <comment><![CDATA[
8
- <div class="custom-options">
9
- <div style="margin-bottom:20px;">
10
- <strong style="color:#EA7601;">DPD GeoPost v1.0
11
- <br />
12
- </div>
13
- </div>
14
- ]]>
15
- </comment>
16
-
17
- <frontend_type>text</frontend_type>
18
- <sort_order>20</sort_order>
19
- <show_in_default>1</show_in_default>
20
- <show_in_website>1</show_in_website>
21
- <show_in_store>1</show_in_store>
22
- <fields>
23
- <active translate="label">
24
- <label>Enabled</label>
25
- <frontend_type>select</frontend_type>
26
- <source_model>adminhtml/system_config_source_yesno</source_model>
27
- <sort_order>10</sort_order>
28
- <show_in_default>1</show_in_default>
29
- <show_in_website>1</show_in_website>
30
- <show_in_store>0</show_in_store>
31
- </active>
32
- <wscountry translate="label">
33
- <label>DPD Country Select</label>
34
- <frontend_type>select</frontend_type>
35
- <source_model>zitec_dpd/config_source_wscountry</source_model>
36
- <sort_order>15</sort_order>
37
- <show_in_default>1</show_in_default>
38
- <show_in_website>1</show_in_website>
39
- <show_in_store>0</show_in_store>
40
- </wscountry>
41
- <mode translate="label">
42
- <label>Production Mode</label>
43
- <frontend_type>select</frontend_type>
44
- <source_model>adminhtml/system_config_source_yesno</source_model>
45
- <backend_model>zitec_dpd/config_data_mode</backend_model>
46
- <sort_order>30</sort_order>
47
- <show_in_default>1</show_in_default>
48
- <show_in_website>1</show_in_website>
49
- <show_in_store>0</show_in_store>
50
- </mode>
51
- <wsurlproduction translate="label comment">
52
- <label>Production WS URL</label>
53
- <frontend_type>text</frontend_type>
54
- <sort_order>33</sort_order>
55
- <show_in_default>1</show_in_default>
56
- <show_in_website>1</show_in_website>
57
- <show_in_store>0</show_in_store>
58
- <depends>
59
- <wscountry>zOther</wscountry>
60
- </depends>
61
- <comment><![CDATA[E.g. http://egproduction.dpd.com/IT4EMWebServices/eshop/]]></comment>
62
- </wsurlproduction>
63
- <wsurltest translate="label comment">
64
- <label>Test WS URL</label>
65
- <frontend_type>text</frontend_type>
66
- <sort_order>34</sort_order>
67
- <show_in_default>1</show_in_default>
68
- <show_in_website>1</show_in_website>
69
- <show_in_store>0</show_in_store>
70
- <depends>
71
- <wscountry>zOther</wscountry>
72
- </depends>
73
- <comment><![CDATA[E.g. http://egtest.dpd.com/IT4EMWebServices/eshop/]]></comment>
74
- </wsurltest>
75
- <title translate="label">
76
- <label>Method Title</label>
77
- <frontend_type>text</frontend_type>
78
- <sort_order>38</sort_order>
79
- <show_in_default>1</show_in_default>
80
- <show_in_website>1</show_in_website>
81
- <show_in_store>1</show_in_store>
82
- </title>
83
- <name translate="label">
84
- <label>Method Name</label>
85
- <frontend_type>text</frontend_type>
86
- <sort_order>40</sort_order>
87
- <show_in_default>1</show_in_default>
88
- <show_in_website>1</show_in_website>
89
- <show_in_store>1</show_in_store>
90
- </name>
91
- <username translate="label">
92
- <label>Web Service Username</label>
93
- <frontend_type>text</frontend_type>
94
- <sort_order>50</sort_order>
95
- <show_in_default>1</show_in_default>
96
- <show_in_website>1</show_in_website>
97
- <show_in_store>0</show_in_store>
98
- </username>
99
- <password translate="label">
100
- <label>Web Service Password</label>
101
- <frontend_type>text</frontend_type>
102
- <sort_order>60</sort_order>
103
- <show_in_default>1</show_in_default>
104
- <show_in_website>1</show_in_website>
105
- <show_in_store>0</show_in_store>
106
- </password>
107
- <connectionTimeout translate="label comment">
108
- <label>Web Service Connection Timeout</label>
109
- <frontend_type>text</frontend_type>
110
- <sort_order>65</sort_order>
111
- <show_in_default>1</show_in_default>
112
- <show_in_website>1</show_in_website>
113
- <show_in_store>0</show_in_store>
114
- <comment>
115
- <![CDATA[Set a timeout for connecting to the DPD web service in seconds.]]></comment>
116
- </connectionTimeout>
117
- <senderAddressId translate="label">
118
- <label>Sender Address Id</label>
119
- <frontend_type>text</frontend_type>
120
- <sort_order>70</sort_order>
121
- <show_in_default>1</show_in_default>
122
- <show_in_website>1</show_in_website>
123
- <show_in_store>0</show_in_store>
124
- </senderAddressId>
125
- <payerId translate="label">
126
- <label>Payer Id</label>
127
- <frontend_type>text</frontend_type>
128
- <sort_order>80</sort_order>
129
- <show_in_default>1</show_in_default>
130
- <show_in_website>1</show_in_website>
131
- <show_in_store>0</show_in_store>
132
- </payerId>
133
- <services translate="label comment">
134
- <label>Service</label>
135
- <frontend_type>multiselect</frontend_type>
136
- <source_model>zitec_dpd/config_source_service</source_model>
137
- <sort_order>90</sort_order>
138
- <show_in_default>1</show_in_default>
139
- <show_in_website>1</show_in_website>
140
- <show_in_store>0</show_in_store>
141
- <comment>Select the services that you want to enable. Note that you must also define the shipping prices for these services in your shipping table rates (see below).</comment>
142
- </services>
143
- <export translate="label">
144
- <label>Export Shipping Table Rates</label>
145
- <frontend_type>button</frontend_type>
146
- <frontend_model>zitec_dpd/adminhtml_system_config_button_export</frontend_model>
147
- <sort_order>100</sort_order>
148
- <show_in_default>0</show_in_default>
149
- <show_in_website>1</show_in_website>
150
- <show_in_store>0</show_in_store>
151
- </export>
152
- <import translate="label">
153
- <label>Import Shipping Table Rates</label>
154
- <frontend_type>import</frontend_type>
155
- <backend_model>zitec_dpd/config_data_tablerate</backend_model>
156
- <sort_order>110</sort_order>
157
- <show_in_default>0</show_in_default>
158
- <show_in_website>1</show_in_website>
159
- <show_in_store>0</show_in_store>
160
- </import>
161
- <postcode_autocomplete_checkout translate="label">
162
- <label>Auto-correct the user postcode in checkout</label>
163
- <frontend_type>select</frontend_type>
164
- <source_model>adminhtml/system_config_source_yesno</source_model>
165
- <sort_order>10</sort_order>
166
- <show_in_default>1</show_in_default>
167
- <show_in_website>1</show_in_website>
168
- <show_in_store>0</show_in_store>
169
- <comment>Use this option to allow DPD shipment method even if the postcode is not valid. The post code will be automatically generated considering the city, region and street. In some cases the administrator will have to manually validate the postcode.</comment>
170
- </postcode_autocomplete_checkout>
171
-
172
- </fields>
173
- </zitecDpd>
174
-
175
-
176
- </groups>
177
- </carriers>
178
- <shipping>
179
- <groups>
180
- <zitec_pickupaddress traslate="label">
181
- <label>DPD GeoPost Pickup Address</label>
182
- <sort_order>10</sort_order>
183
- <show_in_default>1</show_in_default>
184
- <show_in_website>0</show_in_website>
185
- <show_in_store>0</show_in_store>
186
- <fields>
187
- <name translate="label">
188
- <label>Name</label>
189
- <frontend_type>text</frontend_type>
190
- <sort_order>10</sort_order>
191
- <show_in_default>1</show_in_default>
192
- <show_in_website>1</show_in_website>
193
- <show_in_store>0</show_in_store>
194
- </name>
195
- <additionalname translate="label">
196
- <label>Additional Name</label>
197
- <frontend_type>text</frontend_type>
198
- <sort_order>15</sort_order>
199
- <show_in_default>1</show_in_default>
200
- <show_in_website>1</show_in_website>
201
- <show_in_store>0</show_in_store>
202
- </additionalname>
203
- <street translate="label">
204
- <label>Street</label>
205
- <frontend_type>text</frontend_type>
206
- <sort_order>20</sort_order>
207
- <show_in_default>1</show_in_default>
208
- <show_in_website>1</show_in_website>
209
- <show_in_store>0</show_in_store>
210
- </street>
211
- <city translate="label">
212
- <label>City</label>
213
- <frontend_type>text</frontend_type>
214
- <sort_order>30</sort_order>
215
- <show_in_default>1</show_in_default>
216
- <show_in_website>1</show_in_website>
217
- <show_in_store>0</show_in_store>
218
- </city>
219
- <postcode translate="label">
220
- <label>Postcode</label>
221
- <frontend_type>text</frontend_type>
222
- <sort_order>40</sort_order>
223
- <show_in_default>1</show_in_default>
224
- <show_in_website>1</show_in_website>
225
- <show_in_store>0</show_in_store>
226
- </postcode>
227
- <country translate="label">
228
- <label>Country</label>
229
- <frontend_type>select</frontend_type>
230
- <sort_order>50</sort_order>
231
- <source_model>adminhtml/system_config_source_country</source_model>
232
- <show_in_default>1</show_in_default>
233
- <show_in_website>1</show_in_website>
234
- <show_in_store>0</show_in_store>
235
- </country>
236
- <phone translate="label">
237
- <label>Telephone</label>
238
- <frontend_type>text</frontend_type>
239
- <sort_order>55</sort_order>
240
- <show_in_default>1</show_in_default>
241
- <show_in_website>1</show_in_website>
242
- <show_in_store>0</show_in_store>
243
- </phone>
244
- <email translate="label">
245
- <label>Email Address</label>
246
- <frontend_type>text</frontend_type>
247
- <sort_order>60</sort_order>
248
- <show_in_default>1</show_in_default>
249
- <show_in_website>1</show_in_website>
250
- <show_in_store>0</show_in_store>
251
- </email>
252
- </fields>
253
- </zitec_pickupaddress>
254
- </groups>
255
- </shipping>
256
- <payment>
257
- <groups>
258
- <zitec_dpd_cashondelivery translate="label" module="payment">
259
- <label>Cash On Delivery for DPD GeoPost</label>
260
- <comment><![CDATA[<div class="custom-options">
261
- <div style="margin-bottom:20px;">
262
- <span style="color:#EA7601;">Important:</span> This payment method will only be available if you have activated the shipping method 'DPD GeoPost' and have specified values in the 'CashOnDelivery Surcharge' column of your table rates file.
263
- <br />
264
- <strong style="color:#EA7601;">Cash on Delivery for DPD GeoPost v1.0</strong>
265
- <br />
266
- </div>
267
- </div>
268
- ]]></comment>
269
- <sort_order>670</sort_order>
270
- <show_in_default>1</show_in_default>
271
- <show_in_website>1</show_in_website>
272
- <show_in_store>1</show_in_store>
273
- <fields>
274
- <active translate="label">
275
- <label>Enabled</label>
276
- <frontend_type>select</frontend_type>
277
- <source_model>adminhtml/system_config_source_yesno</source_model>
278
- <sort_order>1</sort_order>
279
- <show_in_default>1</show_in_default>
280
- <show_in_website>1</show_in_website>
281
- <show_in_store>0</show_in_store>
282
- </active>
283
- <title translate="label">
284
- <label>Title</label>
285
- <frontend_type>text</frontend_type>
286
- <sort_order>2</sort_order>
287
- <show_in_default>1</show_in_default>
288
- <show_in_website>1</show_in_website>
289
- <show_in_store>1</show_in_store>
290
- </title>
291
- <description translate="label">
292
- <label>Description</label>
293
- <frontend_type>textarea</frontend_type>
294
- <sort_order>3</sort_order>
295
- <show_in_default>1</show_in_default>
296
- <show_in_website>1</show_in_website>
297
- <show_in_store>1</show_in_store>
298
- </description>
299
- <total_title translate="label">
300
- <label>Surcharge Name</label>
301
- <frontend_type>text</frontend_type>
302
- <sort_order>4</sort_order>
303
- <show_in_default>1</show_in_default>
304
- <show_in_website>1</show_in_website>
305
- <show_in_store>1</show_in_store>
306
- </total_title>
307
- <order_status translate="label">
308
- <label>New order status</label>
309
- <frontend_type>select</frontend_type>
310
- <source_model>zitec_dpd/config_source_order_status_pendingpayment</source_model>
311
- <sort_order>10</sort_order>
312
- <show_in_default>1</show_in_default>
313
- <show_in_website>1</show_in_website>
314
- <show_in_store>0</show_in_store>
315
- </order_status>
316
- <specificproducto translate="label">
317
- <label>Service</label>
318
- <frontend_type>multiselect</frontend_type>
319
- <source_model>zitec_dpd/payment_cashondelivery_source_service</source_model>
320
- <sort_order>50</sort_order>
321
- <show_in_default>1</show_in_default>
322
- <show_in_website>1</show_in_website>
323
- <show_in_store>0</show_in_store>
324
- <can_be_empty>1</can_be_empty>
325
- </specificproducto>
326
- <cod_payment_type translate="label comment">
327
- <label>Payment Type</label>
328
- <frontend_type>select</frontend_type>
329
- <source_model>zitec_dpd/payment_cashondelivery_source_codpaymenttype</source_model>
330
- <sort_order>55</sort_order>
331
- <show_in_default>1</show_in_default>
332
- <show_in_website>1</show_in_website>
333
- <show_in_store>0</show_in_store>
334
- <comment>Select how customers will pay the courier.</comment>
335
- </cod_payment_type>
336
- <payment_amount_type translate="label comment">
337
- <label>Payment amount type</label>
338
- <frontend_type>select</frontend_type>
339
- <source_model>zitec_dpd/payment_cashondelivery_source_amountType</source_model>
340
- <sort_order>57</sort_order>
341
- <show_in_default>1</show_in_default>
342
- <show_in_website>1</show_in_website>
343
- <show_in_store>0</show_in_store>
344
- <comment>Choose the type of charge percentage of order amount or fixed price in case table rates is not defined for DPD shipping method.</comment>
345
- </payment_amount_type>
346
- <payment_amount translate="label comment">
347
- <label>Payment amount</label>
348
- <frontend_type>text</frontend_type>
349
- <sort_order>58</sort_order>
350
- <show_in_default>1</show_in_default>
351
- <show_in_website>1</show_in_website>
352
- <show_in_store>1</show_in_store>
353
- <comment>This amount will be used to charge the customer if no records is loaded into table rates</comment>
354
- </payment_amount>
355
-
356
- <allowspecific translate="label">
357
- <label>Payment from Applicable Countries</label>
358
- <frontend_type>allowspecific</frontend_type>
359
- <sort_order>60</sort_order>
360
- <source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model>
361
- <show_in_default>1</show_in_default>
362
- <show_in_website>1</show_in_website>
363
- <show_in_store>0</show_in_store>
364
- </allowspecific>
365
- <specificcountry translate="label">
366
- <label>Payment from Specific Countries</label>
367
- <frontend_type>multiselect</frontend_type>
368
- <sort_order>61</sort_order>
369
- <source_model>zitec_dpd/payment_cashondelivery_source_country</source_model>
370
- <show_in_default>1</show_in_default>
371
- <show_in_website>1</show_in_website>
372
- <show_in_store>0</show_in_store>
373
- <can_be_empty>1</can_be_empty>
374
- </specificcountry>
375
- </fields>
376
- </zitec_dpd_cashondelivery>
377
- </groups>
378
- </payment>
379
- </sections>
380
  </config>
1
+ <config>
2
+ <sections>
3
+ <carriers>
4
+ <groups>
5
+ <zitecDpd>
6
+ <label>DPD GeoPost By Zitec</label>
7
+ <comment><![CDATA[
8
+ <div class="custom-options">
9
+ <div style="margin-bottom:20px;">
10
+ <strong style="color:#EA7601;">DPD GeoPost v1.0
11
+ <br />
12
+ </div>
13
+ </div>
14
+ ]]>
15
+ </comment>
16
+
17
+ <frontend_type>text</frontend_type>
18
+ <sort_order>20</sort_order>
19
+ <show_in_default>1</show_in_default>
20
+ <show_in_website>1</show_in_website>
21
+ <show_in_store>1</show_in_store>
22
+ <fields>
23
+ <active translate="label">
24
+ <label>Enabled</label>
25
+ <frontend_type>select</frontend_type>
26
+ <source_model>adminhtml/system_config_source_yesno</source_model>
27
+ <sort_order>10</sort_order>
28
+ <show_in_default>1</show_in_default>
29
+ <show_in_website>1</show_in_website>
30
+ <show_in_store>0</show_in_store>
31
+ </active>
32
+ <wscountry translate="label">
33
+ <label>DPD Country Select</label>
34
+ <frontend_type>select</frontend_type>
35
+ <source_model>zitec_dpd/config_source_wscountry</source_model>
36
+ <sort_order>15</sort_order>
37
+ <show_in_default>1</show_in_default>
38
+ <show_in_website>1</show_in_website>
39
+ <show_in_store>0</show_in_store>
40
+ </wscountry>
41
+ <mode translate="label">
42
+ <label>Production Mode</label>
43
+ <frontend_type>select</frontend_type>
44
+ <source_model>adminhtml/system_config_source_yesno</source_model>
45
+ <backend_model>zitec_dpd/config_data_mode</backend_model>
46
+ <sort_order>30</sort_order>
47
+ <show_in_default>1</show_in_default>
48
+ <show_in_website>1</show_in_website>
49
+ <show_in_store>0</show_in_store>
50
+ </mode>
51
+ <wsurlproduction translate="label comment">
52
+ <label>Production WS URL</label>
53
+ <frontend_type>text</frontend_type>
54
+ <sort_order>33</sort_order>
55
+ <show_in_default>1</show_in_default>
56
+ <show_in_website>1</show_in_website>
57
+ <show_in_store>0</show_in_store>
58
+ <depends>
59
+ <wscountry>zOther</wscountry>
60
+ </depends>
61
+ <comment><![CDATA[E.g. http://egproduction.dpd.com/IT4EMWebServices/eshop/]]></comment>
62
+ </wsurlproduction>
63
+ <wsurltest translate="label comment">
64
+ <label>Test WS URL</label>
65
+ <frontend_type>text</frontend_type>
66
+ <sort_order>34</sort_order>
67
+ <show_in_default>1</show_in_default>
68
+ <show_in_website>1</show_in_website>
69
+ <show_in_store>0</show_in_store>
70
+ <depends>
71
+ <wscountry>zOther</wscountry>
72
+ </depends>
73
+ <comment><![CDATA[E.g. http://egtest.dpd.com/IT4EMWebServices/eshop/]]></comment>
74
+ </wsurltest>
75
+ <title translate="label">
76
+ <label>Method Title</label>
77
+ <frontend_type>text</frontend_type>
78
+ <sort_order>38</sort_order>
79
+ <show_in_default>1</show_in_default>
80
+ <show_in_website>1</show_in_website>
81
+ <show_in_store>1</show_in_store>
82
+ </title>
83
+ <name translate="label">
84
+ <label>Method Name</label>
85
+ <frontend_type>text</frontend_type>
86
+ <sort_order>40</sort_order>
87
+ <show_in_default>1</show_in_default>
88
+ <show_in_website>1</show_in_website>
89
+ <show_in_store>1</show_in_store>
90
+ </name>
91
+ <username translate="label">
92
+ <label>Web Service Username</label>
93
+ <frontend_type>text</frontend_type>
94
+ <sort_order>50</sort_order>
95
+ <show_in_default>1</show_in_default>
96
+ <show_in_website>1</show_in_website>
97
+ <show_in_store>0</show_in_store>
98
+ </username>
99
+ <password translate="label">
100
+ <label>Web Service Password</label>
101
+ <frontend_type>text</frontend_type>
102
+ <sort_order>60</sort_order>
103
+ <show_in_default>1</show_in_default>
104
+ <show_in_website>1</show_in_website>
105
+ <show_in_store>0</show_in_store>
106
+ </password>
107
+ <connectionTimeout translate="label comment">
108
+ <label>Web Service Connection Timeout</label>
109
+ <frontend_type>text</frontend_type>
110
+ <sort_order>65</sort_order>
111
+ <show_in_default>1</show_in_default>
112
+ <show_in_website>1</show_in_website>
113
+ <show_in_store>0</show_in_store>
114
+ <comment>
115
+ <![CDATA[Set a timeout for connecting to the DPD web service in seconds.]]></comment>
116
+ </connectionTimeout>
117
+ <senderAddressId translate="label">
118
+ <label>Sender Address Id</label>
119
+ <frontend_type>text</frontend_type>
120
+ <sort_order>70</sort_order>
121
+ <show_in_default>1</show_in_default>
122
+ <show_in_website>1</show_in_website>
123
+ <show_in_store>0</show_in_store>
124
+ </senderAddressId>
125
+ <payerId translate="label">
126
+ <label>Payer Id</label>
127
+ <frontend_type>text</frontend_type>
128
+ <sort_order>80</sort_order>
129
+ <show_in_default>1</show_in_default>
130
+ <show_in_website>1</show_in_website>
131
+ <show_in_store>0</show_in_store>
132
+ </payerId>
133
+ <services translate="label comment">
134
+ <label>Service</label>
135
+ <frontend_type>multiselect</frontend_type>
136
+ <source_model>zitec_dpd/config_source_service</source_model>
137
+ <sort_order>90</sort_order>
138
+ <show_in_default>1</show_in_default>
139
+ <show_in_website>1</show_in_website>
140
+ <show_in_store>0</show_in_store>
141
+ <comment>Select the services that you want to enable. Note that you must also define the shipping prices for these services in your shipping table rates (see below).</comment>
142
+ </services>
143
+ <export translate="label">
144
+ <label>Export Shipping Table Rates</label>
145
+ <frontend_type>button</frontend_type>
146
+ <frontend_model>zitec_dpd/adminhtml_system_config_button_export</frontend_model>
147
+ <sort_order>100</sort_order>
148
+ <show_in_default>0</show_in_default>
149
+ <show_in_website>1</show_in_website>
150
+ <show_in_store>0</show_in_store>
151
+ </export>
152
+ <import translate="label">
153
+ <label>Import Shipping Table Rates</label>
154
+ <frontend_type>import</frontend_type>
155
+ <backend_model>zitec_dpd/config_data_tablerate</backend_model>
156
+ <sort_order>110</sort_order>
157
+ <show_in_default>0</show_in_default>
158
+ <show_in_website>1</show_in_website>
159
+ <show_in_store>0</show_in_store>
160
+ </import>
161
+ <postcode_autocomplete_checkout translate="label">
162
+ <label>Auto-correct the user postcode in checkout</label>
163
+ <frontend_type>select</frontend_type>
164
+ <source_model>adminhtml/system_config_source_yesno</source_model>
165
+ <sort_order>10</sort_order>
166
+ <show_in_default>1</show_in_default>
167
+ <show_in_website>1</show_in_website>
168
+ <show_in_store>0</show_in_store>
169
+ <comment>Use this option to allow DPD shipment method even if the postcode is not valid. The post code will be automatically generated considering the city, region and street. In some cases the administrator will have to manually validate the postcode.</comment>
170
+ </postcode_autocomplete_checkout>
171
+
172
+ </fields>
173
+ </zitecDpd>
174
+
175
+
176
+ </groups>
177
+ </carriers>
178
+ <shipping>
179
+ <groups>
180
+ <zitec_pickupaddress traslate="label">
181
+ <label>DPD GeoPost Pickup Address</label>
182
+ <sort_order>10</sort_order>
183
+ <show_in_default>1</show_in_default>
184
+ <show_in_website>0</show_in_website>
185
+ <show_in_store>0</show_in_store>
186
+ <fields>
187
+ <name translate="label">
188
+ <label>Name</label>
189
+ <frontend_type>text</frontend_type>
190
+ <sort_order>10</sort_order>
191
+ <show_in_default>1</show_in_default>
192
+ <show_in_website>1</show_in_website>
193
+ <show_in_store>0</show_in_store>
194
+ </name>
195
+ <additionalname translate="label">
196
+ <label>Additional Name</label>
197
+ <frontend_type>text</frontend_type>
198
+ <sort_order>15</sort_order>
199
+ <show_in_default>1</show_in_default>
200
+ <show_in_website>1</show_in_website>
201
+ <show_in_store>0</show_in_store>
202
+ </additionalname>
203
+ <street translate="label">
204
+ <label>Street</label>
205
+ <frontend_type>text</frontend_type>
206
+ <sort_order>20</sort_order>
207
+ <show_in_default>1</show_in_default>
208
+ <show_in_website>1</show_in_website>
209
+ <show_in_store>0</show_in_store>
210
+ </street>
211
+ <city translate="label">
212
+ <label>City</label>
213
+ <frontend_type>text</frontend_type>
214
+ <sort_order>30</sort_order>
215
+ <show_in_default>1</show_in_default>
216
+ <show_in_website>1</show_in_website>
217
+ <show_in_store>0</show_in_store>
218
+ </city>
219
+ <postcode translate="label">
220
+ <label>Postcode</label>
221
+ <frontend_type>text</frontend_type>
222
+ <sort_order>40</sort_order>
223
+ <show_in_default>1</show_in_default>
224
+ <show_in_website>1</show_in_website>
225
+ <show_in_store>0</show_in_store>
226
+ </postcode>
227
+ <country translate="label">
228
+ <label>Country</label>
229
+ <frontend_type>select</frontend_type>
230
+ <sort_order>50</sort_order>
231
+ <source_model>adminhtml/system_config_source_country</source_model>
232
+ <show_in_default>1</show_in_default>
233
+ <show_in_website>1</show_in_website>
234
+ <show_in_store>0</show_in_store>
235
+ </country>
236
+ <phone translate="label">
237
+ <label>Telephone</label>
238
+ <frontend_type>text</frontend_type>
239
+ <sort_order>55</sort_order>
240
+ <show_in_default>1</show_in_default>
241
+ <show_in_website>1</show_in_website>
242
+ <show_in_store>0</show_in_store>
243
+ </phone>
244
+ <email translate="label">
245
+ <label>Email Address</label>
246
+ <frontend_type>text</frontend_type>
247
+ <sort_order>60</sort_order>
248
+ <show_in_default>1</show_in_default>
249
+ <show_in_website>1</show_in_website>
250
+ <show_in_store>0</show_in_store>
251
+ </email>
252
+ </fields>
253
+ </zitec_pickupaddress>
254
+ </groups>
255
+ </shipping>
256
+ <payment>
257
+ <groups>
258
+ <zitec_dpd_cashondelivery translate="label" module="payment">
259
+ <label>Cash On Delivery for DPD GeoPost</label>
260
+ <comment><![CDATA[<div class="custom-options">
261
+ <div style="margin-bottom:20px;">
262
+ <span style="color:#EA7601;">Important:</span> This payment method will only be available if you have activated the shipping method 'DPD GeoPost' and have specified values in the 'CashOnDelivery Surcharge' column of your table rates file.
263
+ <br />
264
+ <strong style="color:#EA7601;">Cash on Delivery for DPD GeoPost v1.0</strong>
265
+ <br />
266
+ </div>
267
+ </div>
268
+ ]]></comment>
269
+ <sort_order>670</sort_order>
270
+ <show_in_default>1</show_in_default>
271
+ <show_in_website>1</show_in_website>
272
+ <show_in_store>1</show_in_store>
273
+ <fields>
274
+ <active translate="label">
275
+ <label>Enabled</label>
276
+ <frontend_type>select</frontend_type>
277
+ <source_model>adminhtml/system_config_source_yesno</source_model>
278
+ <sort_order>1</sort_order>
279
+ <show_in_default>1</show_in_default>
280
+ <show_in_website>1</show_in_website>
281
+ <show_in_store>0</show_in_store>
282
+ </active>
283
+ <title translate="label">
284
+ <label>Title</label>
285
+ <frontend_type>text</frontend_type>
286
+ <sort_order>2</sort_order>
287
+ <show_in_default>1</show_in_default>
288
+ <show_in_website>1</show_in_website>
289
+ <show_in_store>1</show_in_store>
290
+ </title>
291
+ <description translate="label">
292
+ <label>Description</label>
293
+ <frontend_type>textarea</frontend_type>
294
+ <sort_order>3</sort_order>
295
+ <show_in_default>1</show_in_default>
296
+ <show_in_website>1</show_in_website>
297
+ <show_in_store>1</show_in_store>
298
+ </description>
299
+ <total_title translate="label">
300
+ <label>Surcharge Name</label>
301
+ <frontend_type>text</frontend_type>
302
+ <sort_order>4</sort_order>
303
+ <show_in_default>1</show_in_default>
304
+ <show_in_website>1</show_in_website>
305
+ <show_in_store>1</show_in_store>
306
+ </total_title>
307
+ <order_status translate="label">
308
+ <label>New order status</label>
309
+ <frontend_type>select</frontend_type>
310
+ <source_model>zitec_dpd/config_source_order_status_pendingpayment</source_model>
311
+ <sort_order>10</sort_order>
312
+ <show_in_default>1</show_in_default>
313
+ <show_in_website>1</show_in_website>
314
+ <show_in_store>0</show_in_store>
315
+ </order_status>
316
+ <specificproducto translate="label">
317
+ <label>Service</label>
318
+ <frontend_type>multiselect</frontend_type>
319
+ <source_model>zitec_dpd/payment_cashondelivery_source_service</source_model>
320
+ <sort_order>50</sort_order>
321
+ <show_in_default>1</show_in_default>
322
+ <show_in_website>1</show_in_website>
323
+ <show_in_store>0</show_in_store>
324
+ <can_be_empty>1</can_be_empty>
325
+ </specificproducto>
326
+ <cod_payment_type translate="label comment">
327
+ <label>Payment Type</label>
328
+ <frontend_type>select</frontend_type>
329
+ <source_model>zitec_dpd/payment_cashondelivery_source_codpaymenttype</source_model>
330
+ <sort_order>55</sort_order>
331
+ <show_in_default>1</show_in_default>
332
+ <show_in_website>1</show_in_website>
333
+ <show_in_store>0</show_in_store>
334
+ <comment>Select how customers will pay the courier.</comment>
335
+ </cod_payment_type>
336
+ <payment_amount_type translate="label comment">
337
+ <label>Payment amount type</label>
338
+ <frontend_type>select</frontend_type>
339
+ <source_model>zitec_dpd/payment_cashondelivery_source_amountType</source_model>
340
+ <sort_order>57</sort_order>
341
+ <show_in_default>1</show_in_default>
342
+ <show_in_website>1</show_in_website>
343
+ <show_in_store>0</show_in_store>
344
+ <comment>Choose the type of charge percentage of order amount or fixed price in case table rates is not defined for DPD shipping method.</comment>
345
+ </payment_amount_type>
346
+ <payment_amount translate="label comment">
347
+ <label>Payment amount</label>
348
+ <frontend_type>text</frontend_type>
349
+ <sort_order>58</sort_order>
350
+ <show_in_default>1</show_in_default>
351
+ <show_in_website>1</show_in_website>
352
+ <show_in_store>1</show_in_store>
353
+ <comment>This amount will be used to charge the customer if no records is loaded into table rates</comment>
354
+ </payment_amount>
355
+
356
+ <allowspecific translate="label">
357
+ <label>Payment from Applicable Countries</label>
358
+ <frontend_type>allowspecific</frontend_type>
359
+ <sort_order>60</sort_order>
360
+ <source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model>
361
+ <show_in_default>1</show_in_default>
362
+ <show_in_website>1</show_in_website>
363
+ <show_in_store>0</show_in_store>
364
+ </allowspecific>
365
+ <specificcountry translate="label">
366
+ <label>Payment from Specific Countries</label>
367
+ <frontend_type>multiselect</frontend_type>
368
+ <sort_order>61</sort_order>
369
+ <source_model>zitec_dpd/payment_cashondelivery_source_country</source_model>
370
+ <show_in_default>1</show_in_default>
371
+ <show_in_website>1</show_in_website>
372
+ <show_in_store>0</show_in_store>
373
+ <can_be_empty>1</can_be_empty>
374
+ </specificcountry>
375
+ </fields>
376
+ </zitec_dpd_cashondelivery>
377
+ </groups>
378
+ </payment>
379
+ </sections>
380
  </config>
app/code/community/Zitec/Dpd/sql/zitec_dpd_setup/mysql4-install-1.0.0.php CHANGED
@@ -1,209 +1,209 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
-
25
- /* @var $installer Mage_Core_Model_Resource_Setup */
26
- $installer = $this;
27
-
28
- $installer->startSetup();
29
-
30
- $installer->run("
31
- DROP TABLE IF EXISTS {$this->getTable('zitec_dpd_ships')};
32
- CREATE TABLE {$this->getTable('zitec_dpd_ships')} (
33
- `id` int(10) unsigned NOT NULL auto_increment,
34
- `shipment_id` int(10) unsigned DEFAULT NULL,
35
- `order_id` int(10) unsigned DEFAULT NULL,
36
- `save_shipment_call` mediumtext,
37
- `save_shipment_response` mediumtext,
38
- `shipping_labels` mediumtext,
39
- `manifest` mediumtext,
40
- PRIMARY KEY (`id`)
41
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
42
-
43
-
44
- DROP TABLE IF EXISTS {$this->getTable('zitec_dpd_tablerate')};
45
- CREATE TABLE {$this->getTable('zitec_dpd_tablerate')} (
46
- `pk` int(10) unsigned NOT NULL auto_increment,
47
- `website_id` int(11) NOT NULL default '0',
48
- `dest_country_id` varchar(4) NOT NULL default '0',
49
- `dest_region_id` int(10) NOT NULL default '0',
50
- `dest_zip` varchar(10) NOT NULL default '',
51
- `weight` decimal(12,4) NOT NULL default '0.0000',
52
- `price` varchar(10) NOT NULL default '0.0000',
53
- `method` varchar(6) NOT NULL default '0',
54
- `markup_type` varchar(5) NOT NULL default '0',
55
- PRIMARY KEY (`pk`),
56
- UNIQUE KEY `dest_country` (`website_id`,`dest_country_id`,`dest_region_id`,`dest_zip`,`weight`,`method`)
57
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
58
-
59
- ");
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
- $installer->run("
68
- DROP TABLE IF EXISTS {$this->getTable('zitec_dpd_pickup_order')};
69
-
70
- CREATE TABLE {$this->getTable('zitec_dpd_pickup_order')} (
71
- `entity_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
72
- `reference` VARCHAR( 255 ) NOT NULL ,
73
- `dpd_id` INT NOT NULL ,
74
- `pickup_date` DATETIME NOT NULL ,
75
- `pickup_time_from` DATETIME NOT NULL ,
76
- `pickup_time_to` DATETIME NOT NULL ,
77
- `call_data` MEDIUMTEXT NOT NULL ,
78
- `response_data` MEDIUMTEXT NOT NULL ,
79
- INDEX ( `pickup_date` , `pickup_time_from` , `pickup_time_to` ) ,
80
- UNIQUE (
81
- `reference`
82
- )
83
- ) ENGINE = INNODB DEFAULT CHARSET=utf8;
84
-
85
- ");
86
-
87
-
88
-
89
- $salesSetup = Mage::getModel('eav/entity_setup', 'sales_setup');
90
- /** @var $salesSetup Mage_Sales_Model_Resource_Setup */
91
- $salesSetup->addAttribute('shipment', 'zitec_dpd_pickup_id', array('type' => 'int'));
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
- $salesSetup = Mage::getModel('eav/entity_setup', 'sales_setup');
100
- /** @var $salesSetup Mage_Sales_Model_Resource_Setup */
101
- $salesSetup->addAttribute('shipment', 'zitec_dpd_pickup_time', array('type' => 'datetime', "grid" => true));
102
- $salesSetup->addAttribute('shipment', 'zitec_dpd_manifest_closed', array('type' => 'int', "grid" => true, "default" => 0));
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
- $installer->getConnection()->addColumn($this->getTable('zitec_dpd_tablerate'), 'cashondelivery_surcharge', "varchar(20) DEFAULT NULL");
113
-
114
- $salesSetup = new Mage_Sales_Model_Mysql4_Setup('sales_setup');
115
-
116
- $salesSetup->addAttribute('quote_address', 'zitec_dpd_cashondelivery_surcharge', array('type' => 'decimal'));
117
- $salesSetup->addAttribute('quote_address', 'base_zitec_dpd_cashondelivery_surcharge', array('type' => 'decimal'));
118
-
119
- $salesSetup->addAttribute('order', 'zitec_dpd_cashondelivery_surcharge', array('type' => 'decimal'));
120
- $salesSetup->addAttribute('order', 'base_zitec_dpd_cashondelivery_surcharge', array('type' => 'decimal'));
121
-
122
- $salesSetup->addAttribute('invoice', 'zitec_dpd_cashondelivery_surcharge', array('type' => 'decimal'));
123
- $salesSetup->addAttribute('invoice', 'base_zitec_dpd_cashondelivery_surcharge', array('type' => 'decimal'));
124
-
125
- $salesSetup->addAttribute('creditmemo', 'zitec_dpd_cashondelivery_surcharge', array('type' => 'decimal'));
126
- $salesSetup->addAttribute('creditmemo', 'base_zitec_dpd_cashondelivery_surcharge', array('type' => 'decimal'));
127
-
128
- $salesSetup->addAttribute('quote_address', 'zitec_dpd_cashondelivery_surcharge_tax', array('type' => 'decimal'));
129
- $salesSetup->addAttribute('quote_address', 'base_zitec_dpd_cashondelivery_surcharge_tax', array('type' => 'decimal'));
130
-
131
- $salesSetup->addAttribute('order', 'zitec_dpd_cashondelivery_surcharge_tax', array('type' => 'decimal'));
132
- $salesSetup->addAttribute('order', 'base_zitec_dpd_cashondelivery_surcharge_tax', array('type' => 'decimal'));
133
-
134
- $salesSetup->addAttribute('invoice', 'zitec_dpd_cashondelivery_surcharge_tax', array('type' => 'decimal'));
135
- $salesSetup->addAttribute('invoice', 'base_zitec_dpd_cashondelivery_surcharge_tax', array('type' => 'decimal'));
136
-
137
- $salesSetup->addAttribute('creditmemo', 'zitec_dpd_cashondelivery_surcharge_tax', array('type' => 'decimal'));
138
- $salesSetup->addAttribute('creditmemo', 'base_zitec_dpd_cashondelivery_surcharge_tax', array('type' => 'decimal'));
139
-
140
- $status = Mage::getModel('sales/order_status');
141
- $status->setStatus('zitec_dpd_pending_cashondelivery');
142
- $status->setLabel('DPD Pending Cash On Delivery');
143
- $status->assignState('pending_payment');
144
- $status->save();
145
-
146
-
147
-
148
-
149
-
150
-
151
- $installer->getConnection()->addColumn($this->getTable('zitec_dpd_tablerate'), 'price_vs_dest', "int(10) NOT NULL default '0'");
152
-
153
-
154
-
155
-
156
-
157
-
158
- $installer->getConnection()->addColumn($this->getTable('zitec_dpd_tablerate'), 'cod_min_surcharge', "decimal(12,4)");
159
-
160
-
161
-
162
-
163
-
164
-
165
- $installer->getConnection()->dropKey($this->getTable('zitec_dpd_tablerate'), "dest_country");
166
-
167
- $installer->getConnection()->addKey(
168
- $this->getTable('zitec_dpd_tablerate'),
169
- "dest_country",
170
- array('website_id', 'dest_country_id', 'dest_region_id', 'dest_zip', 'weight', 'method', 'price_vs_dest'),
171
- "unique");
172
-
173
-
174
-
175
-
176
-
177
-
178
-
179
- //$installer->getConnection()->dropColumn($this->getTable('zitec_dpd_ships'), 'manifest');
180
-
181
- $installer->getConnection()->addColumn($installer->getTable('zitec_dpd_ships'), 'manifest_id', "int");
182
-
183
- $installer->run("
184
-
185
- DROP TABLE IF EXISTS {$installer->getTable('zitec_dpd_manifest')};
186
-
187
-
188
- CREATE TABLE {$installer->getTable('zitec_dpd_manifest')} (
189
- `manifest_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
190
- `manifest_ref` VARCHAR( 30 ) NOT NULL ,
191
- `manifest_dpd_id` VARCHAR( 30 ) NULL ,
192
- `manifest_dpd_name` VARCHAR( 30 ) NULL ,
193
- `pdf` MEDIUMTEXT NOT NULL
194
- ) ENGINE = INNODB; ");
195
-
196
-
197
-
198
-
199
-
200
-
201
- $installer->getConnection()->dropColumn($this->getTable('zitec_dpd_ships'), 'manifest');
202
-
203
-
204
-
205
-
206
-
207
-
208
-
209
  $installer->endSetup();
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+
25
+ /* @var $installer Mage_Core_Model_Resource_Setup */
26
+ $installer = $this;
27
+
28
+ $installer->startSetup();
29
+
30
+ $installer->run("
31
+ DROP TABLE IF EXISTS {$this->getTable('zitec_dpd_ships')};
32
+ CREATE TABLE {$this->getTable('zitec_dpd_ships')} (
33
+ `id` int(10) unsigned NOT NULL auto_increment,
34
+ `shipment_id` int(10) unsigned DEFAULT NULL,
35
+ `order_id` int(10) unsigned DEFAULT NULL,
36
+ `save_shipment_call` mediumtext,
37
+ `save_shipment_response` mediumtext,
38
+ `shipping_labels` mediumtext,
39
+ `manifest` mediumtext,
40
+ PRIMARY KEY (`id`)
41
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
42
+
43
+
44
+ DROP TABLE IF EXISTS {$this->getTable('zitec_dpd_tablerate')};
45
+ CREATE TABLE {$this->getTable('zitec_dpd_tablerate')} (
46
+ `pk` int(10) unsigned NOT NULL auto_increment,
47
+ `website_id` int(11) NOT NULL default '0',
48
+ `dest_country_id` varchar(4) NOT NULL default '0',
49
+ `dest_region_id` int(10) NOT NULL default '0',
50
+ `dest_zip` varchar(10) NOT NULL default '',
51
+ `weight` decimal(12,4) NOT NULL default '0.0000',
52
+ `price` varchar(10) NOT NULL default '0.0000',
53
+ `method` varchar(6) NOT NULL default '0',
54
+ `markup_type` varchar(5) NOT NULL default '0',
55
+ PRIMARY KEY (`pk`),
56
+ UNIQUE KEY `dest_country` (`website_id`,`dest_country_id`,`dest_region_id`,`dest_zip`,`weight`,`method`)
57
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
58
+
59
+ ");
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+ $installer->run("
68
+ DROP TABLE IF EXISTS {$this->getTable('zitec_dpd_pickup_order')};
69
+
70
+ CREATE TABLE {$this->getTable('zitec_dpd_pickup_order')} (
71
+ `entity_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
72
+ `reference` VARCHAR( 255 ) NOT NULL ,
73
+ `dpd_id` INT NOT NULL ,
74
+ `pickup_date` DATETIME NOT NULL ,
75
+ `pickup_time_from` DATETIME NOT NULL ,
76
+ `pickup_time_to` DATETIME NOT NULL ,
77
+ `call_data` MEDIUMTEXT NOT NULL ,
78
+ `response_data` MEDIUMTEXT NOT NULL ,
79
+ INDEX ( `pickup_date` , `pickup_time_from` , `pickup_time_to` ) ,
80
+ UNIQUE (
81
+ `reference`
82
+ )
83
+ ) ENGINE = INNODB DEFAULT CHARSET=utf8;
84
+
85
+ ");
86
+
87
+
88
+
89
+ $salesSetup = Mage::getModel('eav/entity_setup', 'sales_setup');
90
+ /** @var $salesSetup Mage_Sales_Model_Resource_Setup */
91
+ $salesSetup->addAttribute('shipment', 'zitec_dpd_pickup_id', array('type' => 'int'));
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+ $salesSetup = Mage::getModel('eav/entity_setup', 'sales_setup');
100
+ /** @var $salesSetup Mage_Sales_Model_Resource_Setup */
101
+ $salesSetup->addAttribute('shipment', 'zitec_dpd_pickup_time', array('type' => 'datetime', "grid" => true));
102
+ $salesSetup->addAttribute('shipment', 'zitec_dpd_manifest_closed', array('type' => 'int', "grid" => true, "default" => 0));
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+ $installer->getConnection()->addColumn($this->getTable('zitec_dpd_tablerate'), 'cashondelivery_surcharge', "varchar(20) DEFAULT NULL");
113
+
114
+ $salesSetup = new Mage_Sales_Model_Mysql4_Setup('sales_setup');
115
+
116
+ $salesSetup->addAttribute('quote_address', 'zitec_dpd_cashondelivery_surcharge', array('type' => 'decimal'));
117
+ $salesSetup->addAttribute('quote_address', 'base_zitec_dpd_cashondelivery_surcharge', array('type' => 'decimal'));
118
+
119
+ $salesSetup->addAttribute('order', 'zitec_dpd_cashondelivery_surcharge', array('type' => 'decimal'));
120
+ $salesSetup->addAttribute('order', 'base_zitec_dpd_cashondelivery_surcharge', array('type' => 'decimal'));
121
+
122
+ $salesSetup->addAttribute('invoice', 'zitec_dpd_cashondelivery_surcharge', array('type' => 'decimal'));
123
+ $salesSetup->addAttribute('invoice', 'base_zitec_dpd_cashondelivery_surcharge', array('type' => 'decimal'));
124
+
125
+ $salesSetup->addAttribute('creditmemo', 'zitec_dpd_cashondelivery_surcharge', array('type' => 'decimal'));
126
+ $salesSetup->addAttribute('creditmemo', 'base_zitec_dpd_cashondelivery_surcharge', array('type' => 'decimal'));
127
+
128
+ $salesSetup->addAttribute('quote_address', 'zitec_dpd_cashondelivery_surcharge_tax', array('type' => 'decimal'));
129
+ $salesSetup->addAttribute('quote_address', 'base_zitec_dpd_cashondelivery_surcharge_tax', array('type' => 'decimal'));
130
+
131
+ $salesSetup->addAttribute('order', 'zitec_dpd_cashondelivery_surcharge_tax', array('type' => 'decimal'));
132
+ $salesSetup->addAttribute('order', 'base_zitec_dpd_cashondelivery_surcharge_tax', array('type' => 'decimal'));
133
+
134
+ $salesSetup->addAttribute('invoice', 'zitec_dpd_cashondelivery_surcharge_tax', array('type' => 'decimal'));
135
+ $salesSetup->addAttribute('invoice', 'base_zitec_dpd_cashondelivery_surcharge_tax', array('type' => 'decimal'));
136
+
137
+ $salesSetup->addAttribute('creditmemo', 'zitec_dpd_cashondelivery_surcharge_tax', array('type' => 'decimal'));
138
+ $salesSetup->addAttribute('creditmemo', 'base_zitec_dpd_cashondelivery_surcharge_tax', array('type' => 'decimal'));
139
+
140
+ $status = Mage::getModel('sales/order_status');
141
+ $status->setStatus('zitec_dpd_pending_cashondelivery');
142
+ $status->setLabel('DPD Pending Cash On Delivery');
143
+ $status->assignState('pending_payment');
144
+ $status->save();
145
+
146
+
147
+
148
+
149
+
150
+
151
+ $installer->getConnection()->addColumn($this->getTable('zitec_dpd_tablerate'), 'price_vs_dest', "int(10) NOT NULL default '0'");
152
+
153
+
154
+
155
+
156
+
157
+
158
+ $installer->getConnection()->addColumn($this->getTable('zitec_dpd_tablerate'), 'cod_min_surcharge', "decimal(12,4)");
159
+
160
+
161
+
162
+
163
+
164
+
165
+ $installer->getConnection()->dropKey($this->getTable('zitec_dpd_tablerate'), "dest_country");
166
+
167
+ $installer->getConnection()->addKey(
168
+ $this->getTable('zitec_dpd_tablerate'),
169
+ "dest_country",
170
+ array('website_id', 'dest_country_id', 'dest_region_id', 'dest_zip', 'weight', 'method', 'price_vs_dest'),
171
+ "unique");
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+ //$installer->getConnection()->dropColumn($this->getTable('zitec_dpd_ships'), 'manifest');
180
+
181
+ $installer->getConnection()->addColumn($installer->getTable('zitec_dpd_ships'), 'manifest_id', "int");
182
+
183
+ $installer->run("
184
+
185
+ DROP TABLE IF EXISTS {$installer->getTable('zitec_dpd_manifest')};
186
+
187
+
188
+ CREATE TABLE {$installer->getTable('zitec_dpd_manifest')} (
189
+ `manifest_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
190
+ `manifest_ref` VARCHAR( 30 ) NOT NULL ,
191
+ `manifest_dpd_id` VARCHAR( 30 ) NULL ,
192
+ `manifest_dpd_name` VARCHAR( 30 ) NULL ,
193
+ `pdf` MEDIUMTEXT NOT NULL
194
+ ) ENGINE = INNODB; ");
195
+
196
+
197
+
198
+
199
+
200
+
201
+ $installer->getConnection()->dropColumn($this->getTable('zitec_dpd_ships'), 'manifest');
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
  $installer->endSetup();
app/code/community/Zitec/Dpd/sql/zitec_dpd_setup/mysql4-upgrade-1.0.0-1.0.1.php CHANGED
@@ -1,44 +1,44 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
-
25
- /* @var $installer Mage_Core_Model_Resource_Setup */
26
- $installer = $this;
27
-
28
- $installer->startSetup();
29
-
30
- try {
31
- $installer->getConnection()->addColumn($installer->getTable('sales/shipment'), 'shipping_label', 'LONGBLOB');
32
- }catch (Exception $e){
33
- Mage::logException($e);
34
- }
35
-
36
- try {
37
- $installer->getConnection()->addColumn($installer->getTable('sales/shipment_track'), 'track_number', 'TEXT');
38
- }catch (Exception $e){
39
- Mage::logException($e);
40
- }
41
-
42
-
43
-
44
  $installer->endSetup();
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+
25
+ /* @var $installer Mage_Core_Model_Resource_Setup */
26
+ $installer = $this;
27
+
28
+ $installer->startSetup();
29
+
30
+ try {
31
+ $installer->getConnection()->addColumn($installer->getTable('sales/shipment'), 'shipping_label', 'LONGBLOB');
32
+ }catch (Exception $e){
33
+ Mage::logException($e);
34
+ }
35
+
36
+ try {
37
+ $installer->getConnection()->addColumn($installer->getTable('sales/shipment_track'), 'track_number', 'TEXT');
38
+ }catch (Exception $e){
39
+ Mage::logException($e);
40
+ }
41
+
42
+
43
+
44
  $installer->endSetup();
app/code/community/Zitec/Dpd/sql/zitec_dpd_setup/mysql4-upgrade-1.0.1-1.0.2.php CHANGED
@@ -1,37 +1,37 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
-
25
- /* @var $installer Mage_Core_Model_Resource_Setup */
26
- $installer = $this;
27
-
28
- $installer->startSetup();
29
-
30
- try {
31
- Mage::helper('zitec_dpd/postcode_search')->getSearchPostcodeModel()->installPostcodeDatabase();
32
- }catch (Exception $e){
33
- Mage::logException($e);
34
- }
35
-
36
-
37
  $installer->endSetup();
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+
25
+ /* @var $installer Mage_Core_Model_Resource_Setup */
26
+ $installer = $this;
27
+
28
+ $installer->startSetup();
29
+
30
+ try {
31
+ Mage::helper('zitec_dpd/postcode_search')->getSearchPostcodeModel()->installPostcodeDatabase();
32
+ }catch (Exception $e){
33
+ Mage::logException($e);
34
+ }
35
+
36
+
37
  $installer->endSetup();
app/code/community/Zitec/Dpd/sql/zitec_dpd_setup/mysql4-upgrade-1.0.2-1.0.3.php CHANGED
@@ -1,38 +1,38 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
-
25
- /* @var $installer Mage_Core_Model_Resource_Setup */
26
- $installer = $this;
27
-
28
- $installer->startSetup();
29
-
30
- $salesSetup = new Mage_Sales_Model_Mysql4_Setup('sales_setup');
31
-
32
- $salesSetup->addAttribute('quote_address', 'valid_auto_postcode', array('type' => 'smallint'));
33
- $salesSetup->addAttribute('order_address', 'valid_auto_postcode', array('type' => 'smallint'));
34
- $salesSetup->addAttribute('quote_address', 'auto_postcode', array('type' => 'varchar','length'=>10));
35
- $salesSetup->addAttribute('order_address', 'auto_postcode', array('type' => 'varchar','length'=>10));
36
-
37
-
38
  $installer->endSetup();
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+
25
+ /* @var $installer Mage_Core_Model_Resource_Setup */
26
+ $installer = $this;
27
+
28
+ $installer->startSetup();
29
+
30
+ $salesSetup = new Mage_Sales_Model_Mysql4_Setup('sales_setup');
31
+
32
+ $salesSetup->addAttribute('quote_address', 'valid_auto_postcode', array('type' => 'smallint'));
33
+ $salesSetup->addAttribute('order_address', 'valid_auto_postcode', array('type' => 'smallint'));
34
+ $salesSetup->addAttribute('quote_address', 'auto_postcode', array('type' => 'varchar','length'=>10));
35
+ $salesSetup->addAttribute('order_address', 'auto_postcode', array('type' => 'varchar','length'=>10));
36
+
37
+
38
  $installer->endSetup();
app/code/community/Zitec/PackedShipment/Block/Addressvalidationdialog.php CHANGED
@@ -1,105 +1,105 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_PackedShipment_Block_Addressvalidationdialog extends Mage_Adminhtml_Block_Template
25
- {
26
- /*
27
- * @see setOrder
28
- */
29
- protected $_order;
30
-
31
- protected $_postcode;
32
- protected $_city;
33
- protected $_countryId;
34
-
35
- /*
36
- * Se establece el pedido para el bloque
37
- * @param Mage_Sales_Model_Order $order
38
- */
39
- public function setOrder(Mage_Sales_Model_Order $order)
40
- {
41
- $this->_order = $order;
42
-
43
- return $this;
44
- }
45
-
46
- public function getOrder()
47
- {
48
- return $this->_order;
49
- }
50
-
51
- /*
52
- * @param string $postcode
53
- */
54
- public function setPostcode($postcode)
55
- {
56
- $this->_postcode = $postcode;
57
-
58
- return $this;
59
- }
60
-
61
- public function getPostcode()
62
- {
63
- return $this->_postcode;
64
- }
65
-
66
- /*
67
- * @param string $city
68
- */
69
- public function setCity($city)
70
- {
71
- $this->_city = $city;
72
-
73
- return $this;
74
- }
75
-
76
- public function getCity()
77
- {
78
- return $this->_city;
79
- }
80
-
81
- /**
82
- *
83
- * @param string $countryId
84
- *
85
- * @return \Zitec_PackedShipment_Block_Addressvalidationdialog
86
- */
87
- public function setCountryId($countryId)
88
- {
89
- $this->_countryId = $countryId;
90
-
91
- return $this;
92
- }
93
-
94
- /**
95
- *
96
- * @return string
97
- */
98
- public function getCountryId()
99
- {
100
- return $this->_countryId;
101
- }
102
-
103
-
104
- }
105
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_PackedShipment_Block_Addressvalidationdialog extends Mage_Adminhtml_Block_Template
25
+ {
26
+ /*
27
+ * @see setOrder
28
+ */
29
+ protected $_order;
30
+
31
+ protected $_postcode;
32
+ protected $_city;
33
+ protected $_countryId;
34
+
35
+ /*
36
+ * Se establece el pedido para el bloque
37
+ * @param Mage_Sales_Model_Order $order
38
+ */
39
+ public function setOrder(Mage_Sales_Model_Order $order)
40
+ {
41
+ $this->_order = $order;
42
+
43
+ return $this;
44
+ }
45
+
46
+ public function getOrder()
47
+ {
48
+ return $this->_order;
49
+ }
50
+
51
+ /*
52
+ * @param string $postcode
53
+ */
54
+ public function setPostcode($postcode)
55
+ {
56
+ $this->_postcode = $postcode;
57
+
58
+ return $this;
59
+ }
60
+
61
+ public function getPostcode()
62
+ {
63
+ return $this->_postcode;
64
+ }
65
+
66
+ /*
67
+ * @param string $city
68
+ */
69
+ public function setCity($city)
70
+ {
71
+ $this->_city = $city;
72
+
73
+ return $this;
74
+ }
75
+
76
+ public function getCity()
77
+ {
78
+ return $this->_city;
79
+ }
80
+
81
+ /**
82
+ *
83
+ * @param string $countryId
84
+ *
85
+ * @return \Zitec_PackedShipment_Block_Addressvalidationdialog
86
+ */
87
+ public function setCountryId($countryId)
88
+ {
89
+ $this->_countryId = $countryId;
90
+
91
+ return $this;
92
+ }
93
+
94
+ /**
95
+ *
96
+ * @return string
97
+ */
98
+ public function getCountryId()
99
+ {
100
+ return $this->_countryId;
101
+ }
102
+
103
+
104
+ }
105
+
app/code/community/Zitec/PackedShipment/Block/Addressvalidationinfojs.php CHANGED
@@ -1,130 +1,130 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_PackedShipment_Block_Addressvalidationinfojs extends Mage_Core_Block_Template
25
- {
26
- /*
27
- * @see _getOrder()
28
- */
29
- protected $_order;
30
-
31
- /*
32
- * The current order is returned.
33
- * @return Mage_Sales_Model_Order
34
- */
35
- protected function _getOrder()
36
- {
37
- // Since this block is shown on page 'new shipment'
38
- // know which is the id of the current order in the querystring parameter
39
- // order_id.
40
- if (!$this->_order) {
41
- $this->_order = Mage::getModel('sales/order');
42
- $orderId = $this->getRequest()->getParam('order_id');
43
- if ($orderId) {
44
- $this->_order->load($orderId);
45
- }
46
- }
47
-
48
- return $this->_order;
49
- }
50
-
51
-
52
- /*
53
- * 'True' is returned if the current order allows carrier validation
54
- * direcciones.
55
- * @param string $countryId
56
- * @return bool
57
- */
58
- public function isAddressValidationAvailable()
59
- {
60
- if ($this->_getOrder()->getId()) {
61
- $carrier = $this->_getOrder()->getShippingCarrier();
62
-
63
- return $this->helper('zitec_packedshipment')->carrierSupportsAddressValidation($carrier, $this->getShippingAddressCountryId());
64
- }
65
-
66
- return false;
67
- }
68
-
69
- /*
70
- * The city of the delivery address for the current order is returned.
71
- * @return string
72
- */
73
- public function getShippingAddressCity()
74
- {
75
- if ($this->_getOrder()->getId()) {
76
- return $this->_getOrder()->getShippingAddress()->getCity();
77
- }
78
-
79
- return '';
80
- }
81
-
82
- /*
83
- * Postal code of the shipping address for the current order is returned.
84
- * @return string
85
- */
86
- public function getShippingAddressPostcode()
87
- {
88
- if ($this->_getOrder()->getId()) {
89
- return $this->_getOrder()->getShippingAddress()->getPostcode();
90
- }
91
-
92
- return '';
93
- }
94
-
95
- /**
96
- * The country code of the delivery address for the current order is returned.
97
- *
98
- * @return string
99
- */
100
- public function getShippingAddressCountryId()
101
- {
102
- if ($this->_getOrder()->getId()) {
103
- return $this->_getOrder()->getShippingAddress()->getCountryId();
104
- }
105
-
106
- return '';
107
- }
108
-
109
- /*
110
- * current order id is returned.
111
- * @return int
112
- */
113
- public function getOrderId()
114
- {
115
- $orderId = $this->_getOrder()->getId();
116
-
117
- return $orderId ? $orderId : 0;
118
- }
119
-
120
- /*
121
- * @return string
122
- */
123
- public function getAddressValidationDialogHtmlActionUrl()
124
- {
125
- return $this->helper("adminhtml")->getUrl('zitec_packedshipment/adminhtml_index/addressvalidationdialoghtml');
126
- }
127
-
128
-
129
- }
130
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_PackedShipment_Block_Addressvalidationinfojs extends Mage_Core_Block_Template
25
+ {
26
+ /*
27
+ * @see _getOrder()
28
+ */
29
+ protected $_order;
30
+
31
+ /*
32
+ * The current order is returned.
33
+ * @return Mage_Sales_Model_Order
34
+ */
35
+ protected function _getOrder()
36
+ {
37
+ // Since this block is shown on page 'new shipment'
38
+ // know which is the id of the current order in the querystring parameter
39
+ // order_id.
40
+ if (!$this->_order) {
41
+ $this->_order = Mage::getModel('sales/order');
42
+ $orderId = $this->getRequest()->getParam('order_id');
43
+ if ($orderId) {
44
+ $this->_order->load($orderId);
45
+ }
46
+ }
47
+
48
+ return $this->_order;
49
+ }
50
+
51
+
52
+ /*
53
+ * 'True' is returned if the current order allows carrier validation
54
+ * direcciones.
55
+ * @param string $countryId
56
+ * @return bool
57
+ */
58
+ public function isAddressValidationAvailable()
59
+ {
60
+ if ($this->_getOrder()->getId()) {
61
+ $carrier = $this->_getOrder()->getShippingCarrier();
62
+
63
+ return $this->helper('zitec_packedshipment')->carrierSupportsAddressValidation($carrier, $this->getShippingAddressCountryId());
64
+ }
65
+
66
+ return false;
67
+ }
68
+
69
+ /*
70
+ * The city of the delivery address for the current order is returned.
71
+ * @return string
72
+ */
73
+ public function getShippingAddressCity()
74
+ {
75
+ if ($this->_getOrder()->getId()) {
76
+ return $this->_getOrder()->getShippingAddress()->getCity();
77
+ }
78
+
79
+ return '';
80
+ }
81
+
82
+ /*
83
+ * Postal code of the shipping address for the current order is returned.
84
+ * @return string
85
+ */
86
+ public function getShippingAddressPostcode()
87
+ {
88
+ if ($this->_getOrder()->getId()) {
89
+ return $this->_getOrder()->getShippingAddress()->getPostcode();
90
+ }
91
+
92
+ return '';
93
+ }
94
+
95
+ /**
96
+ * The country code of the delivery address for the current order is returned.
97
+ *
98
+ * @return string
99
+ */
100
+ public function getShippingAddressCountryId()
101
+ {
102
+ if ($this->_getOrder()->getId()) {
103
+ return $this->_getOrder()->getShippingAddress()->getCountryId();
104
+ }
105
+
106
+ return '';
107
+ }
108
+
109
+ /*
110
+ * current order id is returned.
111
+ * @return int
112
+ */
113
+ public function getOrderId()
114
+ {
115
+ $orderId = $this->_getOrder()->getId();
116
+
117
+ return $orderId ? $orderId : 0;
118
+ }
119
+
120
+ /*
121
+ * @return string
122
+ */
123
+ public function getAddressValidationDialogHtmlActionUrl()
124
+ {
125
+ return $this->helper("adminhtml")->getUrl('zitec_packedshipment/adminhtml_index/addressvalidationdialoghtml');
126
+ }
127
+
128
+
129
+ }
130
+
app/code/community/Zitec/PackedShipment/Helper/Data.php CHANGED
@@ -1,143 +1,143 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_PackedShipment_Helper_Data extends Mage_Core_Helper_Abstract
25
- {
26
- /*
27
- * The total weight of a shipment is returned.
28
- *
29
- * @param Mage_Sales_Model_Order_Shipment $shipment
30
- * @return float
31
- */
32
- public function getShipmentWeight(Mage_Sales_Model_Order_Shipment $shipment)
33
- {
34
- $shipmentWeight = 0;
35
- foreach ($shipment->getAllItems() as $item) {
36
- $shipmentWeight += $item->getWeight() * $item->getQty();
37
- }
38
-
39
- return $shipmentWeight;
40
- }
41
-
42
-
43
- /**
44
- * True is returned if we transport the shipment in a single package.
45
- *
46
- * @param Mage_Sales_Model_Order_Shipment $shipment
47
- *
48
- * @return boolean
49
- */
50
- public function mustShipInOneParcel(Mage_Sales_Model_Order_Shipment $shipment)
51
- {
52
- $carrier = $shipment->getOrder()->getShippingCarrier();
53
- if ($carrier instanceof Zitec_PackedShipment_Model_Carrier_Interface) {
54
- $shippingMethod = $shipment->getOrder()->getShippingMethod();
55
-
56
- return $carrier->shippingMethodRequiresShipmentsOfOnlyOneParcel($shippingMethod);
57
- }
58
-
59
- return true;
60
- }
61
-
62
- /**
63
- * True is returned if the carrier can calculate shipping costs.
64
- *
65
- * @param Mage_Shipping_Model_Carrier_Abstract $carrier
66
- *
67
- * @return boolean
68
- */
69
- public function carrierSupportsCalculationOfShippingCosts(Mage_Shipping_Model_Carrier_Abstract $carrier = null)
70
- {
71
- if ($carrier instanceof Zitec_PackedShipment_Model_Carrier_Interface) {
72
- return $carrier->supportsCalculationOfShippingCosts();
73
- }
74
-
75
- return false;
76
- }
77
-
78
- /**
79
- * True is returned if the carrier address validation support (postcode, town)
80
- *
81
- * @param Mage_Shipping_Model_Carrier_Abstract $carrier
82
- * @param string $countryId
83
- *
84
- * @return boolean
85
- */
86
- public function carrierSupportsAddressValidation(Mage_Shipping_Model_Carrier_Abstract $carrier = null, $countryId = 'ES')
87
- {
88
- if ($carrier instanceof Zitec_PackedShipment_Model_Carrier_Interface) {
89
- return $carrier->supportsAddressValidation($countryId);
90
- }
91
-
92
- return false;
93
- }
94
-
95
- /**
96
- * We replace the template package if the carrier supports it.
97
- *
98
- * @return string
99
- */
100
- public function changeOrderItemsTemplate()
101
- {
102
- $shipment = Mage::registry('current_shipment');
103
- /* @var $shipment Mage_Sales_Model_Order_Shipment */
104
- if ($shipment && ($this->carrierSupportsPackedShipment($shipment->getOrder()->getShippingCarrier()))) {
105
- return 'zitec_packedshipment/sales/order/shipment/create/items.phtml';
106
- } else {
107
- return Mage::app()->getLayout()->getBlock('order_items')->getTemplate();
108
- }
109
- }
110
-
111
- /**
112
- *
113
- * @param Mage_Shipping_Model_Carrier_Abstract $carrier
114
- *
115
- * @return boolean
116
- */
117
- public function carrierSupportsPackedShipment(Mage_Shipping_Model_Carrier_Abstract $carrier = null)
118
- {
119
- return $carrier instanceof Zitec_PackedShipment_Model_Carrier_Interface;
120
- }
121
-
122
-
123
- public function changeAddressValidationJsTemplate()
124
- {
125
- $shipment = Mage::registry('current_shipment');
126
- /* @var $shipment Mage_Sales_Model_Order_Shipment */
127
- if ($shipment && ($this->carrierSupportsPackedShipment($shipment->getOrder()->getShippingCarrier()))) {
128
- return 'zitec_packedshipment/sales/order/shipment/create/address_validation_info_js.phtml';
129
- } else {
130
- return '';
131
- }
132
- }
133
-
134
- /**
135
- * @return boolean
136
- */
137
- public function useDescriptionsInsteadOfReferences()
138
- {
139
- $useDescriptionsInsteadOfReferences = Mage::getStoreConfig("zitec_packedshipment/useDescriptionsInsteadOfReferences");
140
-
141
- return $useDescriptionsInsteadOfReferences ? true : false;
142
- }
143
- }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_PackedShipment_Helper_Data extends Mage_Core_Helper_Abstract
25
+ {
26
+ /*
27
+ * The total weight of a shipment is returned.
28
+ *
29
+ * @param Mage_Sales_Model_Order_Shipment $shipment
30
+ * @return float
31
+ */
32
+ public function getShipmentWeight(Mage_Sales_Model_Order_Shipment $shipment)
33
+ {
34
+ $shipmentWeight = 0;
35
+ foreach ($shipment->getAllItems() as $item) {
36
+ $shipmentWeight += $item->getWeight() * $item->getQty();
37
+ }
38
+
39
+ return $shipmentWeight;
40
+ }
41
+
42
+
43
+ /**
44
+ * True is returned if we transport the shipment in a single package.
45
+ *
46
+ * @param Mage_Sales_Model_Order_Shipment $shipment
47
+ *
48
+ * @return boolean
49
+ */
50
+ public function mustShipInOneParcel(Mage_Sales_Model_Order_Shipment $shipment)
51
+ {
52
+ $carrier = $shipment->getOrder()->getShippingCarrier();
53
+ if ($carrier instanceof Zitec_PackedShipment_Model_Carrier_Interface) {
54
+ $shippingMethod = $shipment->getOrder()->getShippingMethod();
55
+
56
+ return $carrier->shippingMethodRequiresShipmentsOfOnlyOneParcel($shippingMethod);
57
+ }
58
+
59
+ return true;
60
+ }
61
+
62
+ /**
63
+ * True is returned if the carrier can calculate shipping costs.
64
+ *
65
+ * @param Mage_Shipping_Model_Carrier_Abstract $carrier
66
+ *
67
+ * @return boolean
68
+ */
69
+ public function carrierSupportsCalculationOfShippingCosts(Mage_Shipping_Model_Carrier_Abstract $carrier = null)
70
+ {
71
+ if ($carrier instanceof Zitec_PackedShipment_Model_Carrier_Interface) {
72
+ return $carrier->supportsCalculationOfShippingCosts();
73
+ }
74
+
75
+ return false;
76
+ }
77
+
78
+ /**
79
+ * True is returned if the carrier address validation support (postcode, town)
80
+ *
81
+ * @param Mage_Shipping_Model_Carrier_Abstract $carrier
82
+ * @param string $countryId
83
+ *
84
+ * @return boolean
85
+ */
86
+ public function carrierSupportsAddressValidation(Mage_Shipping_Model_Carrier_Abstract $carrier = null, $countryId = 'ES')
87
+ {
88
+ if ($carrier instanceof Zitec_PackedShipment_Model_Carrier_Interface) {
89
+ return $carrier->supportsAddressValidation($countryId);
90
+ }
91
+
92
+ return false;
93
+ }
94
+
95
+ /**
96
+ * We replace the template package if the carrier supports it.
97
+ *
98
+ * @return string
99
+ */
100
+ public function changeOrderItemsTemplate()
101
+ {
102
+ $shipment = Mage::registry('current_shipment');
103
+ /* @var $shipment Mage_Sales_Model_Order_Shipment */
104
+ if ($shipment && ($this->carrierSupportsPackedShipment($shipment->getOrder()->getShippingCarrier()))) {
105
+ return 'zitec_packedshipment/sales/order/shipment/create/items.phtml';
106
+ } else {
107
+ return Mage::app()->getLayout()->getBlock('order_items')->getTemplate();
108
+ }
109
+ }
110
+
111
+ /**
112
+ *
113
+ * @param Mage_Shipping_Model_Carrier_Abstract $carrier
114
+ *
115
+ * @return boolean
116
+ */
117
+ public function carrierSupportsPackedShipment(Mage_Shipping_Model_Carrier_Abstract $carrier = null)
118
+ {
119
+ return $carrier instanceof Zitec_PackedShipment_Model_Carrier_Interface;
120
+ }
121
+
122
+
123
+ public function changeAddressValidationJsTemplate()
124
+ {
125
+ $shipment = Mage::registry('current_shipment');
126
+ /* @var $shipment Mage_Sales_Model_Order_Shipment */
127
+ if ($shipment && ($this->carrierSupportsPackedShipment($shipment->getOrder()->getShippingCarrier()))) {
128
+ return 'zitec_packedshipment/sales/order/shipment/create/address_validation_info_js.phtml';
129
+ } else {
130
+ return '';
131
+ }
132
+ }
133
+
134
+ /**
135
+ * @return boolean
136
+ */
137
+ public function useDescriptionsInsteadOfReferences()
138
+ {
139
+ $useDescriptionsInsteadOfReferences = Mage::getStoreConfig("zitec_packedshipment/useDescriptionsInsteadOfReferences");
140
+
141
+ return $useDescriptionsInsteadOfReferences ? true : false;
142
+ }
143
+ }
app/code/community/Zitec/PackedShipment/Model/Carrier/Interface.php CHANGED
@@ -1,97 +1,97 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Interface to follow any shipping carrier that supports packed Shipments .
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- interface Zitec_PackedShipment_Model_Carrier_Interface
25
- {
26
-
27
-
28
- /**
29
- * If the carrier soporate address validation returns true else
30
- * postcodes in the specified country.
31
- *
32
- * @param string $countryId
33
- *
34
- * @return bool
35
- */
36
- function supportsAddressValidation($countryId);
37
-
38
- /*
39
- * True is returned if the combination of city and zip code is valid.
40
- * @param string $city
41
- * @param string $postcode
42
- * @param string &$errorMsg - In the case of an error
43
- * @return bool
44
- */
45
- public function isValidCityPostcode($city, $postcode, &$errorMsg);
46
-
47
- /*
48
- * The list of zip codes that are valid is returned to
49
- * la población proporcionada.
50
- * @param string $city
51
- * @param string &$errorMsg - In the case of an error
52
- * @return array (of string)
53
- */
54
- public function getPostcodesForCity($city, &$errorMsg);
55
-
56
- /*
57
- * The list of cities that are valid is returned to
58
- * the zip code provided.
59
- * @param string $postcode
60
- * @param string &$errorMsg - In the case of an error *
61
- * @return array (of string)
62
- */
63
- public function getCitiesForPostcode($postcode, &$errorMsg);
64
-
65
-
66
- /*
67
- * True is returned if the carrier can provide information on the shipping costs
68
- *
69
- * @return bool
70
- */
71
- function supportsCalculationOfShippingCosts();
72
-
73
- /*
74
- * The cost of shipping is obtained.
75
- * We order the city and the zip code of the recipient
76
- * (if different than ordering) and the list of the weights of the packages we send.
77
- * @param Mage_Sales_Model_Order $order
78
- * @param string $city
79
- * @param string $postcode
80
- * @param array $weightsPackages
81
- * @param string &$errorStr -- error message returned.
82
- * @return double -- cost of shipping
83
- */
84
- function getShippingCost(
85
- Mage_Sales_Model_Order $order,
86
- $city,
87
- $postcode,
88
- $weightsPackages,
89
- &$errorStr);
90
-
91
- /**
92
- * @param string $shippingMethod
93
- *
94
- * @return int
95
- */
96
- function shippingMethodRequiresShipmentsOfOnlyOneParcel($shippingMethod);
97
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Interface to follow any shipping carrier that supports packed Shipments .
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ interface Zitec_PackedShipment_Model_Carrier_Interface
25
+ {
26
+
27
+
28
+ /**
29
+ * If the carrier soporate address validation returns true else
30
+ * postcodes in the specified country.
31
+ *
32
+ * @param string $countryId
33
+ *
34
+ * @return bool
35
+ */
36
+ function supportsAddressValidation($countryId);
37
+
38
+ /*
39
+ * True is returned if the combination of city and zip code is valid.
40
+ * @param string $city
41
+ * @param string $postcode
42
+ * @param string &$errorMsg - In the case of an error
43
+ * @return bool
44
+ */
45
+ public function isValidCityPostcode($city, $postcode, &$errorMsg);
46
+
47
+ /*
48
+ * The list of zip codes that are valid is returned to
49
+ * la población proporcionada.
50
+ * @param string $city
51
+ * @param string &$errorMsg - In the case of an error
52
+ * @return array (of string)
53
+ */
54
+ public function getPostcodesForCity($city, &$errorMsg);
55
+
56
+ /*
57
+ * The list of cities that are valid is returned to
58
+ * the zip code provided.
59
+ * @param string $postcode
60
+ * @param string &$errorMsg - In the case of an error *
61
+ * @return array (of string)
62
+ */
63
+ public function getCitiesForPostcode($postcode, &$errorMsg);
64
+
65
+
66
+ /*
67
+ * True is returned if the carrier can provide information on the shipping costs
68
+ *
69
+ * @return bool
70
+ */
71
+ function supportsCalculationOfShippingCosts();
72
+
73
+ /*
74
+ * The cost of shipping is obtained.
75
+ * We order the city and the zip code of the recipient
76
+ * (if different than ordering) and the list of the weights of the packages we send.
77
+ * @param Mage_Sales_Model_Order $order
78
+ * @param string $city
79
+ * @param string $postcode
80
+ * @param array $weightsPackages
81
+ * @param string &$errorStr -- error message returned.
82
+ * @return double -- cost of shipping
83
+ */
84
+ function getShippingCost(
85
+ Mage_Sales_Model_Order $order,
86
+ $city,
87
+ $postcode,
88
+ $weightsPackages,
89
+ &$errorStr);
90
+
91
+ /**
92
+ * @param string $shippingMethod
93
+ *
94
+ * @return int
95
+ */
96
+ function shippingMethodRequiresShipmentsOfOnlyOneParcel($shippingMethod);
97
  }
app/code/community/Zitec/PackedShipment/Model/Package.php CHANGED
@@ -1,272 +1,272 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_PackedShipment_Model_Package extends Mage_Core_Model_Abstract
25
- {
26
- /**
27
- * @var Mage_Sales_Model_Order_Shipment
28
- */
29
- protected $_shipment;
30
-
31
- /**
32
- * Ids of the items packed in this parcel
33
- *
34
- * @var array
35
- */
36
- protected $_packedItemsIds;
37
-
38
- /**
39
- * Array with items packaged in this parcel
40
- *
41
- * @var array
42
- */
43
- protected $_packedItems;
44
-
45
- /*
46
- * Array with the quantities of each item in the package array (id1 => qty1 ...)
47
- */
48
- protected $_packedItemsQtys;
49
-
50
- /**
51
- * reference used to generate the labels
52
- *
53
- * @var string
54
- */
55
- protected $_ref;
56
-
57
- /**
58
- * (sum of items that compose)
59
- *
60
- * @var float
61
- */
62
- protected $_weight;
63
-
64
- /**
65
- * Total number of items that are in this package
66
- *
67
- * @var unknown_type
68
- */
69
- protected $_totalItemsQty;
70
-
71
- /**
72
- * Total price of the package (sum of the prices of the items that comprise it)
73
- *
74
- * @var float
75
- */
76
- protected $_price;
77
-
78
-
79
- /**
80
- * We built a parcel, forcing get 2 mandatory parameters
81
- *
82
- * @param array $ids array with the ids of items that are packed in this parcel
83
- * @param Mage_Sales_Model_Order_Shipment $shipment
84
- * @param String $ref
85
- *
86
- * @throws Exception
87
- */
88
- public function __construct(Mage_Sales_Model_Order_Shipment $shipment, array $ids, $ref = null)
89
- {
90
-
91
- if (empty($ids))
92
- throw new Exception("__CLASS__ : One package has to have at least one item. Passed an array of empty itemsIds");
93
-
94
- $this
95
- ->setShipment($shipment)
96
- ->setPackedItemsIds($ids)
97
- ->setRef($ref);
98
- }
99
-
100
- /**
101
- * We set the ids of the items that are part of this package
102
- *
103
- * @param unknown_type $ids
104
- */
105
- public function setPackedItemsIds(array $ids)
106
- {
107
- $this->_packedItemsIds = $ids;
108
-
109
- return $this;
110
- }
111
-
112
-
113
- /**
114
- * Adds a collection of items in this bundle
115
- *
116
- * @param unknown_type $items
117
- */
118
- public function setShipment(Mage_Sales_Model_Order_Shipment $shipment)
119
- {
120
- $this->_shipment = $shipment;
121
-
122
- return $this;
123
- }
124
-
125
-
126
- /**
127
- * @param null $ref
128
- *
129
- * @return $this
130
- */
131
- public function setRef($ref = null)
132
- {
133
- $this->_ref = ($ref) ? $ref : $this->_autocalculateRef();
134
-
135
- return $this;
136
- }
137
-
138
- /**
139
- * calculate the reference ref using the sku of products in the package
140
- * @return string
141
- */
142
- protected function _autocalculateRef()
143
- {
144
- $items = $this->getPackedItems();
145
- $qtys = $this->_getPackedItemsQtys();
146
- $skus = array();
147
- foreach ($items as $itemId => $item) {
148
- $tmp = $item->getSku();
149
- if ($qtys[$itemId] > 1)
150
- $tmp .= '(' . $qtys[$itemId] . ' uds.)';
151
-
152
- $skus[] = $tmp;
153
- }
154
-
155
- return implode(', ', $skus);
156
- }
157
-
158
-
159
- /**
160
- *
161
- * Returns an array of the items in this bundle
162
- */
163
- public function getPackedItems()
164
- {
165
- if (!empty($this->_packedItems))
166
- return $this->_packedItems;
167
-
168
- $this->_packedItems = array();
169
- foreach ($this->_packedItemsIds as $id) {
170
- $this->_packedItems[$id] = $this->getItemByProductId($id);
171
- }
172
-
173
- return $this->_packedItems;
174
- }
175
-
176
- /*
177
- * Returns an array of the like array (<item id> => <qty> ...)
178
- * for all products in the package
179
- */
180
- protected function _getPackedItemsQtys()
181
- {
182
- if (!empty($this->_packedItemsQtys))
183
- return $this->_packedItemsQtys;
184
-
185
- $this->_packedItemsQtys = array();
186
- foreach ($this->_packedItemsIds as $id) {
187
- if (!array_key_exists($id, $this->_packedItemsQtys)) {
188
- $this->_packedItemsQtys[$id] = 1;
189
- } else {
190
- $this->_packedItemsQtys[$id]++;
191
- }
192
- }
193
-
194
- return $this->_packedItemsQtys;
195
- }
196
-
197
- /**
198
- * Returns array with the ids item of this package
199
- */
200
- public function getPackedItemsIds()
201
- {
202
- return $this->_packedItemsIds;
203
- }
204
-
205
-
206
- public function getItemByProductId($productId)
207
- {
208
- foreach ($this->_shipment->getItemsCollection() as $item) {
209
- if ($item->getProductId() == $productId) {
210
- return $item;
211
- }
212
- }
213
-
214
- return false;
215
- }
216
-
217
- /**
218
- * Returns the weight of the package. The first time is calculated by summing weights of items
219
- */
220
- public function getPackageWeight()
221
- {
222
- if (!empty($this->_weight))
223
- return $this->_weight;
224
-
225
- $this->_weight = (float)0;
226
- $qtys = $this->_getPackedItemsQtys();
227
- foreach ($this->getPackedItems() as $itemId => $item) {
228
- $this->_weight += ($item->getWeight() * $qtys[$itemId]);
229
- }
230
-
231
- return $this->_weight;
232
- }
233
-
234
- /**
235
- * @return float
236
- */
237
- public function getPackagePrice()
238
- {
239
- if (!empty($this->_price))
240
- return $this->_price;
241
-
242
- $this->_price = (float)0;
243
- $qtys = $this->_getPackedItemsQtys();
244
- foreach ($this->getPackedItems() as $itemId => $item) {
245
- $this->_price += ($item->getPrice() * $qtys[$itemId]);
246
- }
247
-
248
- return $this->_price;
249
- }
250
-
251
- /**
252
- * @return int|unknown_type
253
- */
254
- public function getTotalItemsQty()
255
- {
256
- if (!empty($this->_totalItemsQty))
257
- return $this->_totalItemsQty;
258
- $qtys = $this->_getPackedItemsQtys();
259
- $this->_totalItemsQty = 0;
260
- foreach ($qtys as $qty) {
261
- $this->_totalItemsQty += $qty;
262
- }
263
-
264
- return $this->_totalItemsQty;
265
- }
266
-
267
- public function getRef()
268
- {
269
- return $this->_ref;
270
- }
271
-
272
- }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_PackedShipment_Model_Package extends Mage_Core_Model_Abstract
25
+ {
26
+ /**
27
+ * @var Mage_Sales_Model_Order_Shipment
28
+ */
29
+ protected $_shipment;
30
+
31
+ /**
32
+ * Ids of the items packed in this parcel
33
+ *
34
+ * @var array
35
+ */
36
+ protected $_packedItemsIds;
37
+
38
+ /**
39
+ * Array with items packaged in this parcel
40
+ *
41
+ * @var array
42
+ */
43
+ protected $_packedItems;
44
+
45
+ /*
46
+ * Array with the quantities of each item in the package array (id1 => qty1 ...)
47
+ */
48
+ protected $_packedItemsQtys;
49
+
50
+ /**
51
+ * reference used to generate the labels
52
+ *
53
+ * @var string
54
+ */
55
+ protected $_ref;
56
+
57
+ /**
58
+ * (sum of items that compose)
59
+ *
60
+ * @var float
61
+ */
62
+ protected $_weight;
63
+
64
+ /**
65
+ * Total number of items that are in this package
66
+ *
67
+ * @var unknown_type
68
+ */
69
+ protected $_totalItemsQty;
70
+
71
+ /**
72
+ * Total price of the package (sum of the prices of the items that comprise it)
73
+ *
74
+ * @var float
75
+ */
76
+ protected $_price;
77
+
78
+
79
+ /**
80
+ * We built a parcel, forcing get 2 mandatory parameters
81
+ *
82
+ * @param array $ids array with the ids of items that are packed in this parcel
83
+ * @param Mage_Sales_Model_Order_Shipment $shipment
84
+ * @param String $ref
85
+ *
86
+ * @throws Exception
87
+ */
88
+ public function __construct(Mage_Sales_Model_Order_Shipment $shipment, array $ids, $ref = null)
89
+ {
90
+
91
+ if (empty($ids))
92
+ throw new Exception("__CLASS__ : One package has to have at least one item. Passed an array of empty itemsIds");
93
+
94
+ $this
95
+ ->setShipment($shipment)
96
+ ->setPackedItemsIds($ids)
97
+ ->setRef($ref);
98
+ }
99
+
100
+ /**
101
+ * We set the ids of the items that are part of this package
102
+ *
103
+ * @param unknown_type $ids
104
+ */
105
+ public function setPackedItemsIds(array $ids)
106
+ {
107
+ $this->_packedItemsIds = $ids;
108
+
109
+ return $this;
110
+ }
111
+
112
+
113
+ /**
114
+ * Adds a collection of items in this bundle
115
+ *
116
+ * @param unknown_type $items
117
+ */
118
+ public function setShipment(Mage_Sales_Model_Order_Shipment $shipment)
119
+ {
120
+ $this->_shipment = $shipment;
121
+
122
+ return $this;
123
+ }
124
+
125
+
126
+ /**
127
+ * @param null $ref
128
+ *
129
+ * @return $this
130
+ */
131
+ public function setRef($ref = null)
132
+ {
133
+ $this->_ref = ($ref) ? $ref : $this->_autocalculateRef();
134
+
135
+ return $this;
136
+ }
137
+
138
+ /**
139
+ * calculate the reference ref using the sku of products in the package
140
+ * @return string
141
+ */
142
+ protected function _autocalculateRef()
143
+ {
144
+ $items = $this->getPackedItems();
145
+ $qtys = $this->_getPackedItemsQtys();
146
+ $skus = array();
147
+ foreach ($items as $itemId => $item) {
148
+ $tmp = $item->getSku();
149
+ if ($qtys[$itemId] > 1)
150
+ $tmp .= '(' . $qtys[$itemId] . ' uds.)';
151
+
152
+ $skus[] = $tmp;
153
+ }
154
+
155
+ return implode(', ', $skus);
156
+ }
157
+
158
+
159
+ /**
160
+ *
161
+ * Returns an array of the items in this bundle
162
+ */
163
+ public function getPackedItems()
164
+ {
165
+ if (!empty($this->_packedItems))
166
+ return $this->_packedItems;
167
+
168
+ $this->_packedItems = array();
169
+ foreach ($this->_packedItemsIds as $id) {
170
+ $this->_packedItems[$id] = $this->getItemByProductId($id);
171
+ }
172
+
173
+ return $this->_packedItems;
174
+ }
175
+
176
+ /*
177
+ * Returns an array of the like array (<item id> => <qty> ...)
178
+ * for all products in the package
179
+ */
180
+ protected function _getPackedItemsQtys()
181
+ {
182
+ if (!empty($this->_packedItemsQtys))
183
+ return $this->_packedItemsQtys;
184
+
185
+ $this->_packedItemsQtys = array();
186
+ foreach ($this->_packedItemsIds as $id) {
187
+ if (!array_key_exists($id, $this->_packedItemsQtys)) {
188
+ $this->_packedItemsQtys[$id] = 1;
189
+ } else {
190
+ $this->_packedItemsQtys[$id]++;
191
+ }
192
+ }
193
+
194
+ return $this->_packedItemsQtys;
195
+ }
196
+
197
+ /**
198
+ * Returns array with the ids item of this package
199
+ */
200
+ public function getPackedItemsIds()
201
+ {
202
+ return $this->_packedItemsIds;
203
+ }
204
+
205
+
206
+ public function getItemByProductId($productId)
207
+ {
208
+ foreach ($this->_shipment->getItemsCollection() as $item) {
209
+ if ($item->getProductId() == $productId) {
210
+ return $item;
211
+ }
212
+ }
213
+
214
+ return false;
215
+ }
216
+
217
+ /**
218
+ * Returns the weight of the package. The first time is calculated by summing weights of items
219
+ */
220
+ public function getPackageWeight()
221
+ {
222
+ if (!empty($this->_weight))
223
+ return $this->_weight;
224
+
225
+ $this->_weight = (float)0;
226
+ $qtys = $this->_getPackedItemsQtys();
227
+ foreach ($this->getPackedItems() as $itemId => $item) {
228
+ $this->_weight += ($item->getWeight() * $qtys[$itemId]);
229
+ }
230
+
231
+ return $this->_weight;
232
+ }
233
+
234
+ /**
235
+ * @return float
236
+ */
237
+ public function getPackagePrice()
238
+ {
239
+ if (!empty($this->_price))
240
+ return $this->_price;
241
+
242
+ $this->_price = (float)0;
243
+ $qtys = $this->_getPackedItemsQtys();
244
+ foreach ($this->getPackedItems() as $itemId => $item) {
245
+ $this->_price += ($item->getPrice() * $qtys[$itemId]);
246
+ }
247
+
248
+ return $this->_price;
249
+ }
250
+
251
+ /**
252
+ * @return int|unknown_type
253
+ */
254
+ public function getTotalItemsQty()
255
+ {
256
+ if (!empty($this->_totalItemsQty))
257
+ return $this->_totalItemsQty;
258
+ $qtys = $this->_getPackedItemsQtys();
259
+ $this->_totalItemsQty = 0;
260
+ foreach ($qtys as $qty) {
261
+ $this->_totalItemsQty += $qty;
262
+ }
263
+
264
+ return $this->_totalItemsQty;
265
+ }
266
+
267
+ public function getRef()
268
+ {
269
+ return $this->_ref;
270
+ }
271
+
272
+ }
app/code/community/Zitec/PackedShipment/Model/PackedShipment.php CHANGED
@@ -1,51 +1,51 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_PackedShipment_Model_PackedShipment
25
- {
26
- protected $_packages = array();
27
-
28
- public function __construct(Mage_Sales_Model_Order_Shipment $shipment, $packages)
29
- {
30
- if (!is_array($packages)) {
31
- return;
32
- }
33
-
34
- foreach ($packages as $packageData) {
35
- //to avoid errors check that each package has products
36
- if (!empty($packageData['ids'])) {
37
- $package = new Zitec_PackedShipment_Model_Package($shipment, $packageData['ids'], $packageData['ref']);
38
- $this->_packages[] = $package;
39
- }
40
- };
41
- }
42
-
43
- /**
44
- *
45
- * @return array
46
- */
47
- public function getPackages()
48
- {
49
- return $this->_packages;
50
- }
51
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_PackedShipment_Model_PackedShipment
25
+ {
26
+ protected $_packages = array();
27
+
28
+ public function __construct(Mage_Sales_Model_Order_Shipment $shipment, $packages)
29
+ {
30
+ if (!is_array($packages)) {
31
+ return;
32
+ }
33
+
34
+ foreach ($packages as $packageData) {
35
+ //to avoid errors check that each package has products
36
+ if (!empty($packageData['ids'])) {
37
+ $package = new Zitec_PackedShipment_Model_Package($shipment, $packageData['ids'], $packageData['ref']);
38
+ $this->_packages[] = $package;
39
+ }
40
+ };
41
+ }
42
+
43
+ /**
44
+ *
45
+ * @return array
46
+ */
47
+ public function getPackages()
48
+ {
49
+ return $this->_packages;
50
+ }
51
  }
app/code/community/Zitec/PackedShipment/controllers/Adminhtml/IndexController.php CHANGED
@@ -1,119 +1,119 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Ajax calls dialog packed shipment are handled.
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_PackedShipment_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
25
- {
26
- /*
27
- * A block is loaded for dialogue address validation
28
- * or nothing, if the address is sent as valid or if there is nothing to do.
29
- */
30
- public function addressvalidationdialoghtmlAction()
31
- {
32
-
33
- $orderId = $this->getRequest()->getParam('order');
34
- $order = Mage::getModel('sales/order');
35
- if ($orderId) {
36
- $order->load($orderId);
37
- }
38
-
39
- $city = $this->getRequest()->getParam('city');
40
- $city = $city ? $city : '';
41
- $postcode = $this->getRequest()->getParam('postcode');
42
- $postcode = $postcode ? $postcode : '';
43
- $countryId = $this->getRequest()->getParam('countryid');
44
- $countryId = $countryId ? $countryId : '';
45
- $dontCorrectAddress = $this->getRequest()->getParam('dontcorrectaddress');
46
-
47
-
48
- if (!$dontCorrectAddress) {
49
- $layout = Mage::getSingleton('core/layout');
50
- $layout->createBlock('zitec_packedshipment/addressvalidationdialog', 'root')
51
- ->setTemplate('zitec_packedshipment/sales/order/shipment/create/address_validation_dialog.phtml')
52
- ->setOrder($order)
53
- ->setCity($city)
54
- ->setPostcode($postcode)
55
- ->setCountryId($countryId);
56
- $dialogHtml = $layout->addOutputBlock('root')
57
- ->setDirectOutput(false)
58
- ->getOutput();
59
- $data['dialogHtml'] = trim($dialogHtml);
60
- } else // User has indicated that it wants to make more changes to the address.
61
- {
62
- $data['dialogHtml'] = '';
63
- }
64
- $this->getResponse()->setHeader('Content-Type', 'application/json', true)->setBody(Mage::helper('core')->jsonEncode($data));
65
- }
66
-
67
- /*
68
- * The cost of transportation of packages shipping is returned.
69
- * this function receives the package weight, parcels, zip code of the desitnation
70
-
71
- * @return float
72
- */
73
- public function getshippingcostAction()
74
- {
75
- $orderId = $this->getRequest()->getParam('order');
76
- $order = Mage::getModel('sales/order')->load($orderId);
77
- $carrier = $order->getShippingCarrier();
78
- if (!Mage::helper('zitec_packedshipment')->carrierSupportsCalculationOfShippingCosts($carrier)) {
79
- $data = array();
80
- $data['error'] = Mage::helper('zitec_packedshipment')->__('An attempt to calculate the shipping cost, but the carrier does not support this operation.');
81
- $this->getResponse()->setHeader('Content-Type', 'application/json', true)->setBody(Mage::helper('core')->jsonEncode($data));
82
-
83
- }
84
-
85
- $weightsParcels = $this->getRequest()->getParam('weightsParcels');
86
-
87
- $shippingAddress = $order->getShippingAddress();
88
-
89
- $city = $this->getRequest()->getParam('city');
90
- $city = $city ? $city : $shippingAddress->getCity();
91
- $postcode = $this->getRequest()->getParam('postcode');
92
- $postcode = $postcode ? $postcode : $shippingAddress->getPostcode();
93
-
94
- $errorStr = '';
95
- $shippingCost = $carrier->getShippingCost(
96
- $order,
97
- $city,
98
- $postcode,
99
- $weightsParcels,
100
- $errorStr);
101
-
102
- $data = array();
103
- $data['shippingcost'] = Mage::helper('core')->currency($shippingCost, true, false);
104
-
105
- // Shipping cost is returned to store for reports
106
- // Shipping module Reports.
107
- $data['shippingreportsshippingcost'] = $shippingCost;
108
-
109
- $profit = $order->getBaseShippingAmount() - $shippingCost;
110
- $data['profit'] = Mage::helper('core')->currency($profit, true, false);
111
-
112
- $data['profitcolor'] = $profit >= 0 ? 'Black' : 'Red';
113
-
114
- $data['error'] = $errorStr;
115
-
116
- $this->getResponse()->setHeader('Content-Type', 'application/json', true)->setBody(Mage::helper('core')->jsonEncode($data));
117
- }
118
- }
119
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Ajax calls dialog packed shipment are handled.
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_PackedShipment_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
25
+ {
26
+ /*
27
+ * A block is loaded for dialogue address validation
28
+ * or nothing, if the address is sent as valid or if there is nothing to do.
29
+ */
30
+ public function addressvalidationdialoghtmlAction()
31
+ {
32
+
33
+ $orderId = $this->getRequest()->getParam('order');
34
+ $order = Mage::getModel('sales/order');
35
+ if ($orderId) {
36
+ $order->load($orderId);
37
+ }
38
+
39
+ $city = $this->getRequest()->getParam('city');
40
+ $city = $city ? $city : '';
41
+ $postcode = $this->getRequest()->getParam('postcode');
42
+ $postcode = $postcode ? $postcode : '';
43
+ $countryId = $this->getRequest()->getParam('countryid');
44
+ $countryId = $countryId ? $countryId : '';
45
+ $dontCorrectAddress = $this->getRequest()->getParam('dontcorrectaddress');
46
+
47
+
48
+ if (!$dontCorrectAddress) {
49
+ $layout = Mage::getSingleton('core/layout');
50
+ $layout->createBlock('zitec_packedshipment/addressvalidationdialog', 'root')
51
+ ->setTemplate('zitec_packedshipment/sales/order/shipment/create/address_validation_dialog.phtml')
52
+ ->setOrder($order)
53
+ ->setCity($city)
54
+ ->setPostcode($postcode)
55
+ ->setCountryId($countryId);
56
+ $dialogHtml = $layout->addOutputBlock('root')
57
+ ->setDirectOutput(false)
58
+ ->getOutput();
59
+ $data['dialogHtml'] = trim($dialogHtml);
60
+ } else // User has indicated that it wants to make more changes to the address.
61
+ {
62
+ $data['dialogHtml'] = '';
63
+ }
64
+ $this->getResponse()->setHeader('Content-Type', 'application/json', true)->setBody(Mage::helper('core')->jsonEncode($data));
65
+ }
66
+
67
+ /*
68
+ * The cost of transportation of packages shipping is returned.
69
+ * this function receives the package weight, parcels, zip code of the desitnation
70
+
71
+ * @return float
72
+ */
73
+ public function getshippingcostAction()
74
+ {
75
+ $orderId = $this->getRequest()->getParam('order');
76
+ $order = Mage::getModel('sales/order')->load($orderId);
77
+ $carrier = $order->getShippingCarrier();
78
+ if (!Mage::helper('zitec_packedshipment')->carrierSupportsCalculationOfShippingCosts($carrier)) {
79
+ $data = array();
80
+ $data['error'] = Mage::helper('zitec_packedshipment')->__('An attempt to calculate the shipping cost, but the carrier does not support this operation.');
81
+ $this->getResponse()->setHeader('Content-Type', 'application/json', true)->setBody(Mage::helper('core')->jsonEncode($data));
82
+
83
+ }
84
+
85
+ $weightsParcels = $this->getRequest()->getParam('weightsParcels');
86
+
87
+ $shippingAddress = $order->getShippingAddress();
88
+
89
+ $city = $this->getRequest()->getParam('city');
90
+ $city = $city ? $city : $shippingAddress->getCity();
91
+ $postcode = $this->getRequest()->getParam('postcode');
92
+ $postcode = $postcode ? $postcode : $shippingAddress->getPostcode();
93
+
94
+ $errorStr = '';
95
+ $shippingCost = $carrier->getShippingCost(
96
+ $order,
97
+ $city,
98
+ $postcode,
99
+ $weightsParcels,
100
+ $errorStr);
101
+
102
+ $data = array();
103
+ $data['shippingcost'] = Mage::helper('core')->currency($shippingCost, true, false);
104
+
105
+ // Shipping cost is returned to store for reports
106
+ // Shipping module Reports.
107
+ $data['shippingreportsshippingcost'] = $shippingCost;
108
+
109
+ $profit = $order->getBaseShippingAmount() - $shippingCost;
110
+ $data['profit'] = Mage::helper('core')->currency($profit, true, false);
111
+
112
+ $data['profitcolor'] = $profit >= 0 ? 'Black' : 'Red';
113
+
114
+ $data['error'] = $errorStr;
115
+
116
+ $this->getResponse()->setHeader('Content-Type', 'application/json', true)->setBody(Mage::helper('core')->jsonEncode($data));
117
+ }
118
+ }
119
+
app/code/community/Zitec/PackedShipment/etc/config.xml CHANGED
@@ -1,61 +1,61 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Zitec_PackedShipment>
5
- <version>1.0.0</version>
6
- </Zitec_PackedShipment>
7
- </modules>
8
- <global>
9
- <models>
10
- <zitec_packedshipment>
11
- <class>Zitec_PackedShipment_Model</class>
12
- </zitec_packedshipment>
13
- </models>
14
- <blocks>
15
- <zitec_packedshipment>
16
- <class>Zitec_PackedShipment_Block</class>
17
- </zitec_packedshipment>
18
- </blocks>
19
- <helpers>
20
- <zitec_packedshipment>
21
- <class>Zitec_PackedShipment_Helper</class>
22
- </zitec_packedshipment>
23
- </helpers>
24
- </global>
25
- <adminhtml>
26
- <translate>
27
- <modules>
28
- <Zitec_PackedShipment>
29
- <files>
30
- <default>Zitec_PackedShipment.csv</default>
31
- </files>
32
- </Zitec_PackedShipment>
33
- </modules>
34
- </translate>
35
- <layout>
36
- <updates>
37
- <zitec_packedshipment>
38
- <file>zitec_packedshipment.xml</file>
39
- </zitec_packedshipment>
40
- </updates>
41
- </layout>
42
- </adminhtml>
43
-
44
- <admin>
45
- <routers>
46
- <zitec_packedshipment>
47
- <use>admin</use>
48
- <args>
49
- <module>Zitec_PackedShipment</module>
50
- <frontName>zitec_packedshipment</frontName>
51
- </args>
52
- </zitec_packedshipment>
53
- </routers>
54
- </admin>
55
-
56
- <default>
57
- <zitec_packedshipment>
58
- <useDescriptionsInsteadOfReferences>1</useDescriptionsInsteadOfReferences>
59
- </zitec_packedshipment>
60
- </default>
61
- </config>
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Zitec_PackedShipment>
5
+ <version>1.0.0</version>
6
+ </Zitec_PackedShipment>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <zitec_packedshipment>
11
+ <class>Zitec_PackedShipment_Model</class>
12
+ </zitec_packedshipment>
13
+ </models>
14
+ <blocks>
15
+ <zitec_packedshipment>
16
+ <class>Zitec_PackedShipment_Block</class>
17
+ </zitec_packedshipment>
18
+ </blocks>
19
+ <helpers>
20
+ <zitec_packedshipment>
21
+ <class>Zitec_PackedShipment_Helper</class>
22
+ </zitec_packedshipment>
23
+ </helpers>
24
+ </global>
25
+ <adminhtml>
26
+ <translate>
27
+ <modules>
28
+ <Zitec_PackedShipment>
29
+ <files>
30
+ <default>Zitec_PackedShipment.csv</default>
31
+ </files>
32
+ </Zitec_PackedShipment>
33
+ </modules>
34
+ </translate>
35
+ <layout>
36
+ <updates>
37
+ <zitec_packedshipment>
38
+ <file>zitec_packedshipment.xml</file>
39
+ </zitec_packedshipment>
40
+ </updates>
41
+ </layout>
42
+ </adminhtml>
43
+
44
+ <admin>
45
+ <routers>
46
+ <zitec_packedshipment>
47
+ <use>admin</use>
48
+ <args>
49
+ <module>Zitec_PackedShipment</module>
50
+ <frontName>zitec_packedshipment</frontName>
51
+ </args>
52
+ </zitec_packedshipment>
53
+ </routers>
54
+ </admin>
55
+
56
+ <default>
57
+ <zitec_packedshipment>
58
+ <useDescriptionsInsteadOfReferences>1</useDescriptionsInsteadOfReferences>
59
+ </zitec_packedshipment>
60
+ </default>
61
+ </config>
app/code/community/Zitec/PrintShippingLabel/Block/Adminhtml/Sales/Order/Shipment/View.php CHANGED
@@ -1,64 +1,64 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_PrintShippingLabel_Block_Adminhtml_Sales_Order_Shipment_View extends Mage_Adminhtml_Block_Sales_Order_Shipment_View
25
- {
26
-
27
- public function __construct()
28
- {
29
- parent::__construct();
30
- if ($this->_hasPdfShippingLabel()) {
31
- $this->_addButton('zitec_print_shipping_label', array(
32
- 'label' => $this->_getHelper()->__('Print Shipping Labels'),
33
- 'onclick' => "setLocation('{$this->_getPrintShippingLabelsUrl()}')"
34
- ));
35
- }
36
- }
37
-
38
- /**
39
- * @return bool
40
- */
41
- protected function _hasPdfShippingLabel()
42
- {
43
- return $this->getShipment()->getShippingLabel() ? true : false;
44
- }
45
-
46
- /**
47
- *
48
- * @return string
49
- */
50
- protected function _getPrintShippingLabelsUrl()
51
- {
52
- return Mage::helper('adminhtml')->getUrl('zitec_printshippinglabel/adminhtml_index/printshippinglabels', array('shipment_id' => $this->getShipment()->getId()));
53
- }
54
-
55
- /**
56
- *
57
- * @return Zitec_PrintShippingLabel_Helper_Data
58
- */
59
- protected function _getHelper()
60
- {
61
- return Mage::helper('zitec_printshippinglabel');
62
- }
63
-
64
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_PrintShippingLabel_Block_Adminhtml_Sales_Order_Shipment_View extends Mage_Adminhtml_Block_Sales_Order_Shipment_View
25
+ {
26
+
27
+ public function __construct()
28
+ {
29
+ parent::__construct();
30
+ if ($this->_hasPdfShippingLabel()) {
31
+ $this->_addButton('zitec_print_shipping_label', array(
32
+ 'label' => $this->_getHelper()->__('Print Shipping Labels'),
33
+ 'onclick' => "setLocation('{$this->_getPrintShippingLabelsUrl()}')"
34
+ ));
35
+ }
36
+ }
37
+
38
+ /**
39
+ * @return bool
40
+ */
41
+ protected function _hasPdfShippingLabel()
42
+ {
43
+ return $this->getShipment()->getShippingLabel() ? true : false;
44
+ }
45
+
46
+ /**
47
+ *
48
+ * @return string
49
+ */
50
+ protected function _getPrintShippingLabelsUrl()
51
+ {
52
+ return Mage::helper('adminhtml')->getUrl('zitec_printshippinglabel/adminhtml_index/printshippinglabels', array('shipment_id' => $this->getShipment()->getId()));
53
+ }
54
+
55
+ /**
56
+ *
57
+ * @return Zitec_PrintShippingLabel_Helper_Data
58
+ */
59
+ protected function _getHelper()
60
+ {
61
+ return Mage::helper('zitec_printshippinglabel');
62
+ }
63
+
64
  }
app/code/community/Zitec/PrintShippingLabel/Block/Adminhtml/Sales/View.php CHANGED
@@ -1,69 +1,69 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_PrintShippingLabel_Block_Adminhtml_Sales_View extends Mage_Adminhtml_Block_Sales_Order_View
25
- {
26
-
27
- public function __construct()
28
- {
29
- parent::__construct();
30
- if ($this->_hasPdfShippingLabels()) {
31
- $this->_addButton('zitec_print_shipping_label', array(
32
- 'label' => $this->_getHelper()->__('Print Shipping Labels'),
33
- 'onclick' => "setLocation('{$this->_getPrintShippingLabelsUrl()}')"
34
- ));
35
- }
36
- }
37
-
38
- /**
39
- *
40
- * @return boolean
41
- */
42
- protected function _hasPdfShippingLabels()
43
- {
44
- $shipments = $this->getOrder()->getShipmentsCollection();
45
- /* @var $shipments Mage_Sales_Model_Resource_Order_Shipment_Collection */
46
- $shipments->addFieldToFilter('shipping_label', array("notnull" => true));
47
-
48
- return $shipments->getSize() > 0;
49
- }
50
-
51
- /**
52
- *
53
- * @return string
54
- */
55
- protected function _getPrintShippingLabelsUrl()
56
- {
57
- return Mage::helper('adminhtml')->getUrl('zitec_printshippinglabel/adminhtml_index/printshippinglabels', array('order_id' => $this->getOrder()->getId()));
58
- }
59
-
60
- /**
61
- *
62
- * @return Zitec_PrintShippingLabel_Helper_Data
63
- */
64
- protected function _getHelper()
65
- {
66
- return Mage::helper('zitec_printshippinglabel');
67
- }
68
-
69
- }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_PrintShippingLabel_Block_Adminhtml_Sales_View extends Mage_Adminhtml_Block_Sales_Order_View
25
+ {
26
+
27
+ public function __construct()
28
+ {
29
+ parent::__construct();
30
+ if ($this->_hasPdfShippingLabels()) {
31
+ $this->_addButton('zitec_print_shipping_label', array(
32
+ 'label' => $this->_getHelper()->__('Print Shipping Labels'),
33
+ 'onclick' => "setLocation('{$this->_getPrintShippingLabelsUrl()}')"
34
+ ));
35
+ }
36
+ }
37
+
38
+ /**
39
+ *
40
+ * @return boolean
41
+ */
42
+ protected function _hasPdfShippingLabels()
43
+ {
44
+ $shipments = $this->getOrder()->getShipmentsCollection();
45
+ /* @var $shipments Mage_Sales_Model_Resource_Order_Shipment_Collection */
46
+ $shipments->addFieldToFilter('shipping_label', array("notnull" => true));
47
+
48
+ return $shipments->getSize() > 0;
49
+ }
50
+
51
+ /**
52
+ *
53
+ * @return string
54
+ */
55
+ protected function _getPrintShippingLabelsUrl()
56
+ {
57
+ return Mage::helper('adminhtml')->getUrl('zitec_printshippinglabel/adminhtml_index/printshippinglabels', array('order_id' => $this->getOrder()->getId()));
58
+ }
59
+
60
+ /**
61
+ *
62
+ * @return Zitec_PrintShippingLabel_Helper_Data
63
+ */
64
+ protected function _getHelper()
65
+ {
66
+ return Mage::helper('zitec_printshippinglabel');
67
+ }
68
+
69
+ }
app/code/community/Zitec/PrintShippingLabel/Helper/Data.php CHANGED
@@ -1,29 +1,29 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_PrintShippingLabel_Helper_Data extends Mage_Core_Helper_Abstract
25
- {
26
-
27
-
28
- }
29
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_PrintShippingLabel_Helper_Data extends Mage_Core_Helper_Abstract
25
+ {
26
+
27
+
28
+ }
29
+
app/code/community/Zitec/PrintShippingLabel/controllers/Adminhtml/IndexController.php CHANGED
@@ -1,148 +1,148 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_PrintShippingLabel_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
25
- {
26
-
27
-
28
- public function printshippinglabelsAction()
29
- {
30
- if (Mage::helper('zitec_dpd/compatibility')->checkMassPrintShippingLabelExists()) {
31
- $module = (string)Mage::getConfig()->getNode('admin/routers/adminhtml/args/frontName');
32
- $controller = 'sales_order_shipment';
33
- $action = 'massPrintShippingLabel';
34
- } else {
35
- $module = 'zitec_printshippinglabel';
36
- $controller = 'adminhtml_index';
37
- $action = 'massPrintShippingLabel';
38
- }
39
-
40
- $orderId = $this->getRequest()->getParam('order_id');
41
- if ($orderId) {
42
- $this->getRequest()->setPost('order_ids', array($orderId));
43
- $this->getRequest()->setParam('massaction_prepare_key', 'order_ids');
44
- $this->_forward($action, $controller, $module);
45
-
46
- return;
47
- }
48
-
49
- $shipmentId = $this->getRequest()->getParam('shipment_id');
50
- if ($shipmentId) {
51
- $this->getRequest()->setPost('shipment_ids', array($shipmentId));
52
- $this->getRequest()->setParam('massaction_prepare_key', 'shipment_ids');
53
- $this->_forward($action, $controller, $module);
54
-
55
- return;
56
- }
57
- $this->_redirect('adminhtml/sales_order/index');
58
- }
59
-
60
-
61
- /**
62
- * Batch print shipping labels for whole shipments.
63
- * Push pdf document with shipping labels to user browser
64
- *
65
- * @return null
66
- */
67
- public function massPrintShippingLabelAction()
68
- {
69
- $request = $this->getRequest();
70
- $ids = $request->getParam('order_ids');
71
- $createdFromOrders = !empty($ids);
72
- $shipments = null;
73
- $labelsContent = array();
74
- switch ($request->getParam('massaction_prepare_key')) {
75
- case 'shipment_ids':
76
- $ids = $request->getParam('shipment_ids');
77
- array_filter($ids, 'intval');
78
- if (!empty($ids)) {
79
- $shipments = Mage::getResourceModel('sales/order_shipment_collection')
80
- ->addFieldToFilter('entity_id', array('in' => $ids));
81
- }
82
- break;
83
- case 'order_ids':
84
- $ids = $request->getParam('order_ids');
85
- array_filter($ids, 'intval');
86
- if (!empty($ids)) {
87
- $shipments = Mage::getResourceModel('sales/order_shipment_collection')
88
- ->setOrderFilter(array('in' => $ids));
89
- }
90
- break;
91
- }
92
-
93
- if ($shipments && $shipments->getSize()) {
94
- foreach ($shipments as $shipment) {
95
- $labelContent = $shipment->getShippingLabel();
96
- if ($labelContent) {
97
- $labelsContent[] = $labelContent;
98
- }
99
- }
100
- }
101
-
102
- if (!empty($labelsContent)) {
103
- $outputPdf = $this->_combineLabelsPdf($labelsContent);
104
- $this->_prepareDownloadResponse('ShippingLabels.pdf', $outputPdf->render(), 'application/pdf');
105
- return;
106
- }
107
-
108
- if ($createdFromOrders) {
109
- $this->_getSession()
110
- ->addError(Mage::helper('sales')->__('There are no shipping labels related to selected orders.'));
111
- $this->_redirect('*/sales_order/index');
112
- } else {
113
- $this->_getSession()
114
- ->addError(Mage::helper('sales')->__('There are no shipping labels related to selected shipments.'));
115
- $this->_redirect('*/sales_order_shipment/index');
116
- }
117
- }
118
-
119
-
120
- /**
121
- * Combine array of labels as instance PDF
122
- *
123
- * @param array $labelsContent
124
- * @return Zend_Pdf
125
- */
126
- protected function _combineLabelsPdf(array $labelsContent)
127
- {
128
- $outputPdf = new Zend_Pdf();
129
- foreach ($labelsContent as $content) {
130
- if (stripos($content, '%PDF-') !== false) {
131
- $pdfLabel = Zend_Pdf::parse($content);
132
- foreach ($pdfLabel->pages as $page) {
133
- $outputPdf->pages[] = clone $page;
134
- }
135
- } else {
136
- $page = $this->_createPdfPageFromImageString($content);
137
- if ($page) {
138
- $outputPdf->pages[] = $page;
139
- }
140
- }
141
- }
142
- return $outputPdf;
143
- }
144
-
145
-
146
-
147
- }
148
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_PrintShippingLabel_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
25
+ {
26
+
27
+
28
+ public function printshippinglabelsAction()
29
+ {
30
+ if (Mage::helper('zitec_dpd/compatibility')->checkMassPrintShippingLabelExists()) {
31
+ $module = (string)Mage::getConfig()->getNode('admin/routers/adminhtml/args/frontName');
32
+ $controller = 'sales_order_shipment';
33
+ $action = 'massPrintShippingLabel';
34
+ } else {
35
+ $module = 'zitec_printshippinglabel';
36
+ $controller = 'adminhtml_index';
37
+ $action = 'massPrintShippingLabel';
38
+ }
39
+
40
+ $orderId = $this->getRequest()->getParam('order_id');
41
+ if ($orderId) {
42
+ $this->getRequest()->setPost('order_ids', array($orderId));
43
+ $this->getRequest()->setParam('massaction_prepare_key', 'order_ids');
44
+ $this->_forward($action, $controller, $module);
45
+
46
+ return;
47
+ }
48
+
49
+ $shipmentId = $this->getRequest()->getParam('shipment_id');
50
+ if ($shipmentId) {
51
+ $this->getRequest()->setPost('shipment_ids', array($shipmentId));
52
+ $this->getRequest()->setParam('massaction_prepare_key', 'shipment_ids');
53
+ $this->_forward($action, $controller, $module);
54
+
55
+ return;
56
+ }
57
+ $this->_redirect('adminhtml/sales_order/index');
58
+ }
59
+
60
+
61
+ /**
62
+ * Batch print shipping labels for whole shipments.
63
+ * Push pdf document with shipping labels to user browser
64
+ *
65
+ * @return null
66
+ */
67
+ public function massPrintShippingLabelAction()
68
+ {
69
+ $request = $this->getRequest();
70
+ $ids = $request->getParam('order_ids');
71
+ $createdFromOrders = !empty($ids);
72
+ $shipments = null;
73
+ $labelsContent = array();
74
+ switch ($request->getParam('massaction_prepare_key')) {
75
+ case 'shipment_ids':
76
+ $ids = $request->getParam('shipment_ids');
77
+ array_filter($ids, 'intval');
78
+ if (!empty($ids)) {
79
+ $shipments = Mage::getResourceModel('sales/order_shipment_collection')
80
+ ->addFieldToFilter('entity_id', array('in' => $ids));
81
+ }
82
+ break;
83
+ case 'order_ids':
84
+ $ids = $request->getParam('order_ids');
85
+ array_filter($ids, 'intval');
86
+ if (!empty($ids)) {
87
+ $shipments = Mage::getResourceModel('sales/order_shipment_collection')
88
+ ->setOrderFilter(array('in' => $ids));
89
+ }
90
+ break;
91
+ }
92
+
93
+ if ($shipments && $shipments->getSize()) {
94
+ foreach ($shipments as $shipment) {
95
+ $labelContent = $shipment->getShippingLabel();
96
+ if ($labelContent) {
97
+ $labelsContent[] = $labelContent;
98
+ }
99
+ }
100
+ }
101
+
102
+ if (!empty($labelsContent)) {
103
+ $outputPdf = $this->_combineLabelsPdf($labelsContent);
104
+ $this->_prepareDownloadResponse('ShippingLabels.pdf', $outputPdf->render(), 'application/pdf');
105
+ return;
106
+ }
107
+
108
+ if ($createdFromOrders) {
109
+ $this->_getSession()
110
+ ->addError(Mage::helper('sales')->__('There are no shipping labels related to selected orders.'));
111
+ $this->_redirect('*/sales_order/index');
112
+ } else {
113
+ $this->_getSession()
114
+ ->addError(Mage::helper('sales')->__('There are no shipping labels related to selected shipments.'));
115
+ $this->_redirect('*/sales_order_shipment/index');
116
+ }
117
+ }
118
+
119
+
120
+ /**
121
+ * Combine array of labels as instance PDF
122
+ *
123
+ * @param array $labelsContent
124
+ * @return Zend_Pdf
125
+ */
126
+ protected function _combineLabelsPdf(array $labelsContent)
127
+ {
128
+ $outputPdf = new Zend_Pdf();
129
+ foreach ($labelsContent as $content) {
130
+ if (stripos($content, '%PDF-') !== false) {
131
+ $pdfLabel = Zend_Pdf::parse($content);
132
+ foreach ($pdfLabel->pages as $page) {
133
+ $outputPdf->pages[] = clone $page;
134
+ }
135
+ } else {
136
+ $page = $this->_createPdfPageFromImageString($content);
137
+ if ($page) {
138
+ $outputPdf->pages[] = $page;
139
+ }
140
+ }
141
+ }
142
+ return $outputPdf;
143
+ }
144
+
145
+
146
+
147
+ }
148
+
app/code/community/Zitec/PrintShippingLabel/etc/config.xml CHANGED
@@ -1,89 +1,89 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Zitec_PrintShippingLabel>
5
- <version>1.0.0</version>
6
- </Zitec_PrintShippingLabel>
7
- </modules>
8
- <global>
9
- <helpers>
10
- <zitec_printshippinglabel>
11
- <class>Zitec_PrintShippingLabel_Helper</class>
12
- </zitec_printshippinglabel>
13
- </helpers>
14
- <models>
15
- <zitec_printshippinglabel>
16
- <class>Zitec_PrintShippingLabel_Model</class>
17
- </zitec_printshippinglabel>
18
- </models>
19
- <blocks>
20
- <zitec_printshippinglabel>
21
- <class>Zitec_PrintShippingLabel_Block</class>
22
- </zitec_printshippinglabel>
23
- <adminhtml>
24
- <rewrite>
25
- <sales_order_view>Zitec_PrintShippingLabel_Block_Adminhtml_Sales_View</sales_order_view>
26
- <sales_order_shipment_view>Zitec_PrintShippingLabel_Block_Adminhtml_Sales_Order_Shipment_View</sales_order_shipment_view>
27
- </rewrite>
28
- </adminhtml>
29
- </blocks>
30
-
31
- </global>
32
- <frontend>
33
- <translate>
34
- <modules>
35
- <Zitec_PrintShippingLabel>
36
- <files>
37
- <default>Zitec_PrintShippingLabel_frontend.csv</default>
38
- </files>
39
- </Zitec_PrintShippingLabel>
40
- </modules>
41
- </translate>
42
- <layout>
43
- <updates>
44
- <zitec_printshippinglabel>
45
- <file>zitec_printshippinglabel.xml</file>
46
- </zitec_printshippinglabel>
47
- </updates>
48
- </layout>
49
- </frontend>
50
-
51
-
52
- <adminhtml>
53
- <layout>
54
- <updates>
55
- <zitec_printshippinglabel>
56
- <file>zitec_printshippinglabel.xml</file>
57
- </zitec_printshippinglabel>
58
- </updates>
59
- </layout>
60
- <translate>
61
- <modules>
62
- <zitec_printshippinglabel>
63
- <files>
64
- <default>Zitec_PrintShippingLabel.csv</default>
65
- </files>
66
- </zitec_printshippinglabel>
67
- </modules>
68
- </translate>
69
- </adminhtml>
70
- <admin>
71
- <routers>
72
- <zitec_printshippinglabel>
73
- <use>admin</use>
74
- <args>
75
- <module>Zitec_PrintShippingLabel</module>
76
- <frontName>zitec_printshippinglabel</frontName>
77
- </args>
78
- </zitec_printshippinglabel>
79
- </routers>
80
- </admin>
81
- <default>
82
- <zitec_printshippinglabel>
83
- <general>
84
-
85
- </general>
86
- </zitec_printshippinglabel>
87
- </default>
88
-
89
- </config>
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Zitec_PrintShippingLabel>
5
+ <version>1.0.0</version>
6
+ </Zitec_PrintShippingLabel>
7
+ </modules>
8
+ <global>
9
+ <helpers>
10
+ <zitec_printshippinglabel>
11
+ <class>Zitec_PrintShippingLabel_Helper</class>
12
+ </zitec_printshippinglabel>
13
+ </helpers>
14
+ <models>
15
+ <zitec_printshippinglabel>
16
+ <class>Zitec_PrintShippingLabel_Model</class>
17
+ </zitec_printshippinglabel>
18
+ </models>
19
+ <blocks>
20
+ <zitec_printshippinglabel>
21
+ <class>Zitec_PrintShippingLabel_Block</class>
22
+ </zitec_printshippinglabel>
23
+ <adminhtml>
24
+ <rewrite>
25
+ <sales_order_view>Zitec_PrintShippingLabel_Block_Adminhtml_Sales_View</sales_order_view>
26
+ <sales_order_shipment_view>Zitec_PrintShippingLabel_Block_Adminhtml_Sales_Order_Shipment_View</sales_order_shipment_view>
27
+ </rewrite>
28
+ </adminhtml>
29
+ </blocks>
30
+
31
+ </global>
32
+ <frontend>
33
+ <translate>
34
+ <modules>
35
+ <Zitec_PrintShippingLabel>
36
+ <files>
37
+ <default>Zitec_PrintShippingLabel_frontend.csv</default>
38
+ </files>
39
+ </Zitec_PrintShippingLabel>
40
+ </modules>
41
+ </translate>
42
+ <layout>
43
+ <updates>
44
+ <zitec_printshippinglabel>
45
+ <file>zitec_printshippinglabel.xml</file>
46
+ </zitec_printshippinglabel>
47
+ </updates>
48
+ </layout>
49
+ </frontend>
50
+
51
+
52
+ <adminhtml>
53
+ <layout>
54
+ <updates>
55
+ <zitec_printshippinglabel>
56
+ <file>zitec_printshippinglabel.xml</file>
57
+ </zitec_printshippinglabel>
58
+ </updates>
59
+ </layout>
60
+ <translate>
61
+ <modules>
62
+ <zitec_printshippinglabel>
63
+ <files>
64
+ <default>Zitec_PrintShippingLabel.csv</default>
65
+ </files>
66
+ </zitec_printshippinglabel>
67
+ </modules>
68
+ </translate>
69
+ </adminhtml>
70
+ <admin>
71
+ <routers>
72
+ <zitec_printshippinglabel>
73
+ <use>admin</use>
74
+ <args>
75
+ <module>Zitec_PrintShippingLabel</module>
76
+ <frontName>zitec_printshippinglabel</frontName>
77
+ </args>
78
+ </zitec_printshippinglabel>
79
+ </routers>
80
+ </admin>
81
+ <default>
82
+ <zitec_printshippinglabel>
83
+ <general>
84
+
85
+ </general>
86
+ </zitec_printshippinglabel>
87
+ </default>
88
+
89
+ </config>
app/code/community/Zitec/ReportsCommon/Block/RecordsReport/Grid.php CHANGED
@@ -1,631 +1,631 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Can be used as a class parent reports showing individual rows
20
- *   The DB (eg a report on individual orders).
21
- *   Is copied / modified Grid reports Magento.
22
- * @category Zitec
23
- * @package Zitec_Dpd
24
- * @author Zitec COM <magento@zitec.ro>
25
- */
26
- class Zitec_ReportsCommon_Block_RecordsReport_Grid extends Mage_Adminhtml_Block_Widget_Grid
27
- {
28
- protected $_from;
29
-
30
- protected $_to;
31
-
32
- protected $_storeSwitcherVisibility = true;
33
-
34
- protected $_dateFilterVisibility = true;
35
-
36
- protected $_exportVisibility = true;
37
-
38
- protected $_subtotalVisibility = false;
39
-
40
- protected $_filters = array();
41
-
42
- protected $_defaultFilters = array(
43
- 'report_from' => '',
44
- 'report_to' => ''
45
- );
46
-
47
- protected $_subReportSize = 5;
48
-
49
- protected $_grandTotals;
50
-
51
- protected $_errors = array();
52
-
53
- /**
54
- * stores current currency code
55
- */
56
- protected $_currentCurrencyCode = null;
57
-
58
- public function __construct()
59
- {
60
- parent::__construct();
61
- $this->setFilterVisibility(false);
62
- $this->setPagerVisibility(false);
63
- $this->setTemplate('zitec_reportscommon/records_report_grid.phtml');
64
- $this->setUseAjax(false);
65
- $this->setCountTotals(true);
66
- }
67
-
68
-
69
- protected function _prepareLayout()
70
- {
71
- $this->setChild('store_switcher',
72
- $this->getLayout()->createBlock('adminhtml/store_switcher')
73
- ->setUseConfirm(false)
74
- ->setSwitchUrl($this->getUrl('*/*/*', array('store' => null)))
75
- ->setTemplate('report/store/switcher.phtml')
76
- );
77
-
78
- $this->setChild('refresh_button',
79
- $this->getLayout()->createBlock('adminhtml/widget_button')
80
- ->setData(array(
81
- 'label' => Mage::helper('adminhtml')->__('Refresh'),
82
- 'onclick' => $this->getRefreshButtonCallback(),
83
- 'class' => 'task'
84
- ))
85
- );
86
- parent::_prepareLayout();
87
-
88
- return $this;
89
- }
90
-
91
- protected function _prepareColumns()
92
- {
93
- foreach ($this->_columns as $_column) {
94
- $_column->setSortable(false);
95
- }
96
-
97
- parent::_prepareColumns();
98
- }
99
-
100
- protected function _prepareCollection()
101
- {
102
- $filter = $this->getParam($this->getVarNameFilter(), null);
103
-
104
- if (is_null($filter)) {
105
- $filter = $this->_defaultFilter;
106
- }
107
-
108
- if (is_string($filter)) {
109
- $data = array();
110
- $filter = base64_decode($filter);
111
- parse_str(urldecode($filter), $data);
112
- $data['report_from'] = Mage::helper('core')->htmlEscape($data['report_from']);
113
- $data['report_to'] = Mage::helper('core')->htmlEscape($data['report_to']);
114
- if (!isset($data['report_from'])) {
115
- // getting all reports from 2001 year
116
- $date = new Zend_Date(mktime(0, 0, 0, 1, 1, 2001));
117
- $data['report_from'] = $date->toString($this->getLocale()->getDateFormat('short'));
118
- }
119
-
120
- if (!isset($data['report_to'])) {
121
- // getting all reports from 2001 year
122
- $date = new Zend_Date();
123
- $data['report_to'] = $date->toString($this->getLocale()->getDateFormat('short'));
124
- }
125
-
126
- $this->_setFilterValues($data);
127
- } else if ($filter && is_array($filter)) {
128
- $this->_setFilterValues($filter);
129
- } else if (0 !== sizeof($this->_defaultFilter)) {
130
- $this->_setFilterValues($this->_defaultFilter);
131
- }
132
-
133
- $collection = $this->getCollection();
134
-
135
- if ($this->getFilter('report_from') && $this->getFilter('report_to')) {
136
- /**
137
- * Validate from and to date
138
- */
139
- try {
140
- $from = $this->getLocale()->date($this->getFilter('report_from'), Zend_Date::DATE_SHORT, null, false);
141
- $to = $this->getLocale()->date($this->getFilter('report_to'), Zend_Date::DATE_SHORT, null, false);
142
- $to->set('23:59:59', Zend_Date::TIMES);
143
-
144
-
145
- $collection->setDateRange($from, $to)
146
- ->setPageSize(false)
147
- ->setStoreIds($this->getStoreIds());
148
- } catch (Exception $e) {
149
- $collection->getSelect()->where('FALSE');
150
- }
151
- } else {
152
- // No se muestra nada si no se han eligido las fechas.
153
- $collection->getSelect()->where('FALSE');
154
- }
155
-
156
- /**
157
- * Getting and saving store ids for website & group
158
- */
159
- $storeIds = array();
160
- if ($this->getRequest()->getParam('store')) {
161
- $storeIds = array($this->getParam('store'));
162
- } elseif ($this->getRequest()->getParam('website')) {
163
- $storeIds = Mage::app()->getWebsite($this->getRequest()->getParam('website'))->getStoreIds();
164
- } elseif ($this->getRequest()->getParam('group')) {
165
- $storeIds = Mage::app()->getGroup($this->getRequest()->getParam('group'))->getStoreIds();
166
- }
167
-
168
- if ($storeIds) {
169
- $collection->setStoreIds($storeIds);
170
- }
171
-
172
- if ($this->getSubReportSize() !== null) {
173
- $collection->setPageSize($this->getSubReportSize());
174
- }
175
-
176
- $debug = (string)$collection->getSelect();
177
- // echo ($debug);
178
-
179
- $this->setCollection($collection);
180
-
181
- $this->_computeTotals();
182
-
183
- Mage::dispatchEvent('adminhtml_widget_grid_filter_collection',
184
- array('collection' => $this->getCollection(), 'filter_values' => $this->_filterValues)
185
- );
186
- }
187
-
188
- protected function _setFilterValues($data)
189
- {
190
- foreach ($data as $name => $value) {
191
- //if (isset($data[$name])) {
192
- $this->setFilter($name, $data[$name]);
193
- //}
194
- }
195
-
196
- return $this;
197
- }
198
-
199
- /**
200
- * Set visibility of store switcher
201
- *
202
- * @param boolean $visible
203
- */
204
- public function setStoreSwitcherVisibility($visible = true)
205
- {
206
- $this->_storeSwitcherVisibility = $visible;
207
- }
208
-
209
- /**
210
- * Return visibility of store switcher
211
- *
212
- * @return boolean
213
- */
214
- public function getStoreSwitcherVisibility()
215
- {
216
- return $this->_storeSwitcherVisibility;
217
- }
218
-
219
- /**
220
- * Return store switcher html
221
- *
222
- * @return string
223
- */
224
- public function getStoreSwitcherHtml()
225
- {
226
- return $this->getChildHtml('store_switcher');
227
- }
228
-
229
- /**
230
- * Set visibility of date filter
231
- *
232
- * @param boolean $visible
233
- */
234
- public function setDateFilterVisibility($visible = true)
235
- {
236
- $this->_dateFilterVisibility = $visible;
237
- }
238
-
239
- /**
240
- * Return visibility of date filter
241
- *
242
- * @return boolean
243
- */
244
- public function getDateFilterVisibility()
245
- {
246
- return $this->_dateFilterVisibility;
247
- }
248
-
249
- /**
250
- * Set visibility of export action
251
- *
252
- * @param boolean $visible
253
- */
254
- public function setExportVisibility($visible = true)
255
- {
256
- $this->_exportVisibility = $visible;
257
- }
258
-
259
- /**
260
- * Return visibility of export action
261
- *
262
- * @return boolean
263
- */
264
- public function getExportVisibility()
265
- {
266
- return $this->_exportVisibility;
267
- }
268
-
269
- /**
270
- * Set visibility of subtotals
271
- *
272
- * @param boolean $visible
273
- */
274
- public function setSubtotalVisibility($visible = true)
275
- {
276
- $this->_subtotalVisibility = $visible;
277
- }
278
-
279
- /**
280
- * Return visibility of subtotals
281
- *
282
- * @return boolean
283
- */
284
- public function getSubtotalVisibility()
285
- {
286
- return $this->_subtotalVisibility;
287
- }
288
-
289
- public function getDateFormat()
290
- {
291
- return $this->getLocale()->getDateStrFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
292
- }
293
-
294
- /**
295
- * Return refresh button html
296
- */
297
- public function getRefreshButtonHtml()
298
- {
299
- return $this->getChildHtml('refresh_button');
300
- }
301
-
302
- public function setFilter($name, $value)
303
- {
304
- if ($name) {
305
- $this->_filters[$name] = $value;
306
- }
307
- }
308
-
309
- public function getFilter($name)
310
- {
311
- if (isset($this->_filters[$name])) {
312
- return $this->_filters[$name];
313
- } else {
314
- return ($this->getRequest()->getParam($name))
315
- ? htmlspecialchars($this->getRequest()->getParam($name)) : '';
316
- }
317
- }
318
-
319
- public function setSubReportSize($size)
320
- {
321
- $this->_subReportSize = $size;
322
- }
323
-
324
- public function getSubReportSize()
325
- {
326
- return $this->_subReportSize;
327
- }
328
-
329
- /**
330
- * Retrieve locale
331
- *
332
- * @return Mage_Core_Model_Locale
333
- */
334
- public function getLocale()
335
- {
336
- if (!$this->_locale) {
337
- $this->_locale = Mage::app()->getLocale();
338
- }
339
-
340
- return $this->_locale;
341
- }
342
-
343
- /**
344
- * Add new export type to grid
345
- *
346
- * @param string $url
347
- * @param string $label
348
- *
349
- * @return Mage_Adminhtml_Block_Widget_Grid
350
- */
351
- public function addExportType($url, $label)
352
- {
353
- $this->_exportTypes[] = new Varien_Object(
354
- array(
355
- 'url' => $this->getUrl($url,
356
- array(
357
- '_current' => true,
358
- 'filter' => $this->getParam($this->getVarNameFilter(), null)
359
- )
360
- ),
361
- 'label' => $label
362
- )
363
- );
364
-
365
- return $this;
366
- }
367
-
368
-
369
- public function getReport($from, $to)
370
- {
371
- if ($from == '') {
372
- $from = $this->getFilter('report_from');
373
- }
374
- if ($to == '') {
375
- $to = $this->getFilter('report_to');
376
- }
377
- $totalObj = Mage::getModel('reports/totals');
378
- $this->setTotals($totalObj->countTotals($this, $from, $to));
379
- $this->addGrandTotals($this->getTotals());
380
-
381
- return $this->getCollection()->setDateRange($from, $to)
382
- ->setPageSize(false)
383
- ->setStoreIds($this->getStoreIds());
384
- }
385
-
386
- public function addGrandTotals($total)
387
- {
388
- $totalData = $total->getData();
389
- foreach ($totalData as $key => $value) {
390
- $_column = $this->getColumn($key);
391
- if ($_column->getTotal() != '') {
392
- $this->getGrandTotals()->setData($key, $this->getGrandTotals()->getData($key) + $value);
393
- }
394
- }
395
- /*
396
- * recalc totals if we have average
397
- */
398
- foreach ($this->getColumns() as $key => $_column) {
399
- if (strpos($_column->getTotal(), '/') !== false) {
400
- list($t1, $t2) = explode('/', $_column->getTotal());
401
- if ($this->getGrandTotals()->getData($t2) != 0) {
402
- $this->getGrandTotals()->setData(
403
- $key,
404
- (float)$this->getGrandTotals()->getData($t1) / $this->getGrandTotals()->getData($t2)
405
- );
406
- }
407
- }
408
- }
409
- }
410
-
411
- public function getGrandTotals()
412
- {
413
- if (!$this->_grandTotals) {
414
- $this->_grandTotals = new Varien_Object();
415
- }
416
-
417
- return $this->_grandTotals;
418
- }
419
-
420
- /**
421
- * Retrieve grid as CSV
422
- *
423
- * @return unknown
424
- */
425
- public function getCsv()
426
- {
427
- $csv = '';
428
- $this->_isExport = true;
429
- $this->_prepareGrid();
430
- $this->getCollection()->getSelect()->limit();
431
- $this->getCollection()->setPageSize(0);
432
- $this->getCollection()->load();
433
- $this->_afterLoadCollection();
434
-
435
- $data = array();
436
- foreach ($this->_columns as $column) {
437
- if (!$column->getIsSystem()) {
438
- $data[] = '"' . $column->getExportHeader() . '"';
439
- }
440
- }
441
- $csv .= implode(',', $data) . "\n";
442
-
443
- foreach ($this->getCollection() as $item) {
444
- $data = array();
445
- foreach ($this->_columns as $column) {
446
- if (!$column->getIsSystem()) {
447
- $data[] = '"' . str_replace(array('"', '\\'), array('""', '\\\\'), $column->getRowFieldExport($item)) . '"';
448
- }
449
- }
450
- $csv .= implode(',', $data) . "\n";
451
- }
452
-
453
- if ($this->getCountTotals()) {
454
- $data = array();
455
- $j = 0;
456
- foreach ($this->_columns as $column) {
457
- if ($j == 0) {
458
- $data[] = '"' . $this->getTotalsText() . '"';
459
- } else {
460
- if (!$column->getIsSystem()) {
461
- //$data[] = '"'.str_replace('"', '""', $column->getRowField($this->getTotals())).'"';
462
- $data[] = '"' . str_replace(array('"', '\\'), array('""', '\\\\'), $column->getRowFieldExport($this->getTotals())) . '"';
463
- }
464
- }
465
- $j++;
466
- }
467
- $csv .= implode(',', $data) . "\n";
468
- }
469
-
470
- return $csv;
471
-
472
- }
473
-
474
- /**
475
- * Retrieve grid as Excel Xml
476
- *
477
- * @return unknown
478
- */
479
- public function getExcel($filename = '')
480
- {
481
-
482
- $this->_isExport = true;
483
- $this->_prepareGrid();
484
- $this->getCollection()->getSelect()->limit();
485
- $this->getCollection()->setPageSize(0);
486
- $this->getCollection()->load();
487
- $this->_afterLoadCollection();
488
- $headers = array();
489
- $data = array();
490
- foreach ($this->_columns as $column) {
491
- if (!$column->getIsSystem()) {
492
- $headers[] = $column->getHeader();
493
- }
494
- }
495
- $data[] = $headers;
496
-
497
- foreach ($this->getCollection() as $item) {
498
- $row = array();
499
- foreach ($this->_columns as $column) {
500
- if (!$column->getIsSystem()) {
501
- $row[] = $column->getRowField($item);
502
- }
503
- }
504
- $data[] = $row;
505
- }
506
-
507
- if ($this->getCountTotals()) {
508
-
509
- $j = 0;
510
- $row = array();
511
- foreach ($this->_columns as $column) {
512
- if ($j == 0) {
513
- $row[] = $this->__($this->getTotalText());
514
- } elseif (!$column->getIsSystem()) {
515
- $row[] = $column->getRowField($this->getTotals());
516
- }
517
- $j++;
518
- }
519
- $data[] = $row;
520
- }
521
-
522
- $xmlObj = new Varien_Convert_Parser_Xml_Excel();
523
- $xmlObj->setVar('single_sheet', $filename);
524
- $xmlObj->setData($data);
525
- $xmlObj->unparse();
526
-
527
- return $xmlObj->getData();
528
-
529
- }
530
-
531
- public function getSubtotalText()
532
- {
533
- return $this->__('Subtotal');
534
- }
535
-
536
- public function getTotalText()
537
- {
538
- return $this->__('Totals');
539
- }
540
-
541
- public function getEmptyText()
542
- {
543
- return $this->__('No records found for this period.');
544
- }
545
-
546
-
547
- /**
548
- * onlick event for refresh button to show alert if fields are empty
549
- *
550
- * @return string
551
- */
552
- public function getRefreshButtonCallback()
553
- {
554
- return "{$this->getJsObjectName()}.doFilter();";
555
-
556
- return "if ($('period_date_to').value == '' && $('period_date_from').value == '') {alert('" . $this->__('Please specify at least start or end date.') . "'); return false;}else {$this->getJsObjectName()}.doFilter();";
557
- }
558
-
559
- /**
560
- * Retrieve errors
561
- *
562
- * @return array
563
- */
564
- public function getErrors()
565
- {
566
- return $this->_errors;
567
- }
568
-
569
- /**
570
- * Retrieve correct currency code for select website, store, group
571
- *
572
- * @return string
573
- */
574
- public function getCurrentCurrencyCode()
575
- {
576
- if (is_null($this->_currentCurrencyCode)) {
577
- if ($this->getRequest()->getParam('store')) {
578
- $this->_currentCurrencyCode = Mage::app()->getStore($this->getRequest()->getParam('store'))->getBaseCurrencyCode();
579
- } else if ($this->getRequest()->getParam('website')) {
580
- $this->_currentCurrencyCode = Mage::app()->getWebsite($this->getRequest()->getParam('website'))->getBaseCurrencyCode();
581
- } else if ($this->getRequest()->getParam('group')) {
582
- $this->_currentCurrencyCode = Mage::app()->getGroup($this->getRequest()->getParam('group'))->getWebsite()->getBaseCurrencyCode();
583
- } else {
584
- $this->_currentCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
585
- }
586
- }
587
-
588
- return $this->_currentCurrencyCode;
589
- }
590
-
591
- protected function _computeTotals()
592
- {
593
- $totals = new Varien_Object();
594
-
595
- foreach ($this->getCollection() as $item) {
596
- foreach ($this->getColumns() as $col) {
597
- if ($col->getTotal()) {
598
- $fieldName = $col->getIndex();
599
- $subTotal = $totals->getData($fieldName);
600
- $subTotal = $subTotal ? $subTotal : 0;
601
- $subTotal += $item->getData($fieldName);
602
- $totals->setData($fieldName, $subTotal);
603
- }
604
- }
605
- }
606
-
607
- $collectionSize = $this->getCollection()->getSize();
608
- if ($collectionSize) {
609
- foreach ($this->getColumns() as $col) {
610
- $fieldName = $col->getIndex();
611
- if ($col->getTotal() == 'avg') {
612
- $avg = $totals->getData($fieldName) / $collectionSize;
613
- $totals->setData($fieldName, $avg);
614
- }
615
- if ($col->getType() == 'currency') {
616
- $total = Mage::helper('core')->currency($totals->getData($fieldName), true, false);
617
- $totals->setData($fieldName, $total);
618
- }
619
-
620
- }
621
- }
622
-
623
- $this->setTotals($totals);
624
-
625
- }
626
-
627
- public function getRowUrl($row)
628
- {
629
- return false;
630
- }
631
- }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Can be used as a class parent reports showing individual rows
20
+ *   The DB (eg a report on individual orders).
21
+ *   Is copied / modified Grid reports Magento.
22
+ * @category Zitec
23
+ * @package Zitec_Dpd
24
+ * @author Zitec COM <magento@zitec.ro>
25
+ */
26
+ class Zitec_ReportsCommon_Block_RecordsReport_Grid extends Mage_Adminhtml_Block_Widget_Grid
27
+ {
28
+ protected $_from;
29
+
30
+ protected $_to;
31
+
32
+ protected $_storeSwitcherVisibility = true;
33
+
34
+ protected $_dateFilterVisibility = true;
35
+
36
+ protected $_exportVisibility = true;
37
+
38
+ protected $_subtotalVisibility = false;
39
+
40
+ protected $_filters = array();
41
+
42
+ protected $_defaultFilters = array(
43
+ 'report_from' => '',
44
+ 'report_to' => ''
45
+ );
46
+
47
+ protected $_subReportSize = 5;
48
+
49
+ protected $_grandTotals;
50
+
51
+ protected $_errors = array();
52
+
53
+ /**
54
+ * stores current currency code
55
+ */
56
+ protected $_currentCurrencyCode = null;
57
+
58
+ public function __construct()
59
+ {
60
+ parent::__construct();
61
+ $this->setFilterVisibility(false);
62
+ $this->setPagerVisibility(false);
63
+ $this->setTemplate('zitec_reportscommon/records_report_grid.phtml');
64
+ $this->setUseAjax(false);
65
+ $this->setCountTotals(true);
66
+ }
67
+
68
+
69
+ protected function _prepareLayout()
70
+ {
71
+ $this->setChild('store_switcher',
72
+ $this->getLayout()->createBlock('adminhtml/store_switcher')
73
+ ->setUseConfirm(false)
74
+ ->setSwitchUrl($this->getUrl('*/*/*', array('store' => null)))
75
+ ->setTemplate('report/store/switcher.phtml')
76
+ );
77
+
78
+ $this->setChild('refresh_button',
79
+ $this->getLayout()->createBlock('adminhtml/widget_button')
80
+ ->setData(array(
81
+ 'label' => Mage::helper('adminhtml')->__('Refresh'),
82
+ 'onclick' => $this->getRefreshButtonCallback(),
83
+ 'class' => 'task'
84
+ ))
85
+ );
86
+ parent::_prepareLayout();
87
+
88
+ return $this;
89
+ }
90
+
91
+ protected function _prepareColumns()
92
+ {
93
+ foreach ($this->_columns as $_column) {
94
+ $_column->setSortable(false);
95
+ }
96
+
97
+ parent::_prepareColumns();
98
+ }
99
+
100
+ protected function _prepareCollection()
101
+ {
102
+ $filter = $this->getParam($this->getVarNameFilter(), null);
103
+
104
+ if (is_null($filter)) {
105
+ $filter = $this->_defaultFilter;
106
+ }
107
+
108
+ if (is_string($filter)) {
109
+ $data = array();
110
+ $filter = base64_decode($filter);
111
+ parse_str(urldecode($filter), $data);
112
+ $data['report_from'] = Mage::helper('core')->htmlEscape($data['report_from']);
113
+ $data['report_to'] = Mage::helper('core')->htmlEscape($data['report_to']);
114
+ if (!isset($data['report_from'])) {
115
+ // getting all reports from 2001 year
116
+ $date = new Zend_Date(mktime(0, 0, 0, 1, 1, 2001));
117
+ $data['report_from'] = $date->toString($this->getLocale()->getDateFormat('short'));
118
+ }
119
+
120
+ if (!isset($data['report_to'])) {
121
+ // getting all reports from 2001 year
122
+ $date = new Zend_Date();
123
+ $data['report_to'] = $date->toString($this->getLocale()->getDateFormat('short'));
124
+ }
125
+
126
+ $this->_setFilterValues($data);
127
+ } else if ($filter && is_array($filter)) {
128
+ $this->_setFilterValues($filter);
129
+ } else if (0 !== sizeof($this->_defaultFilter)) {
130
+ $this->_setFilterValues($this->_defaultFilter);
131
+ }
132
+
133
+ $collection = $this->getCollection();
134
+
135
+ if ($this->getFilter('report_from') && $this->getFilter('report_to')) {
136
+ /**
137
+ * Validate from and to date
138
+ */
139
+ try {
140
+ $from = $this->getLocale()->date($this->getFilter('report_from'), Zend_Date::DATE_SHORT, null, false);
141
+ $to = $this->getLocale()->date($this->getFilter('report_to'), Zend_Date::DATE_SHORT, null, false);
142
+ $to->set('23:59:59', Zend_Date::TIMES);
143
+
144
+
145
+ $collection->setDateRange($from, $to)
146
+ ->setPageSize(false)
147
+ ->setStoreIds($this->getStoreIds());
148
+ } catch (Exception $e) {
149
+ $collection->getSelect()->where('FALSE');
150
+ }
151
+ } else {
152
+ // No se muestra nada si no se han eligido las fechas.
153
+ $collection->getSelect()->where('FALSE');
154
+ }
155
+
156
+ /**
157
+ * Getting and saving store ids for website & group
158
+ */
159
+ $storeIds = array();
160
+ if ($this->getRequest()->getParam('store')) {
161
+ $storeIds = array($this->getParam('store'));
162
+ } elseif ($this->getRequest()->getParam('website')) {
163
+ $storeIds = Mage::app()->getWebsite($this->getRequest()->getParam('website'))->getStoreIds();
164
+ } elseif ($this->getRequest()->getParam('group')) {
165
+ $storeIds = Mage::app()->getGroup($this->getRequest()->getParam('group'))->getStoreIds();
166
+ }
167
+
168
+ if ($storeIds) {
169
+ $collection->setStoreIds($storeIds);
170
+ }
171
+
172
+ if ($this->getSubReportSize() !== null) {
173
+ $collection->setPageSize($this->getSubReportSize());
174
+ }
175
+
176
+ $debug = (string)$collection->getSelect();
177
+ // echo ($debug);
178
+
179
+ $this->setCollection($collection);
180
+
181
+ $this->_computeTotals();
182
+
183
+ Mage::dispatchEvent('adminhtml_widget_grid_filter_collection',
184
+ array('collection' => $this->getCollection(), 'filter_values' => $this->_filterValues)
185
+ );
186
+ }
187
+
188
+ protected function _setFilterValues($data)
189
+ {
190
+ foreach ($data as $name => $value) {
191
+ //if (isset($data[$name])) {
192
+ $this->setFilter($name, $data[$name]);
193
+ //}
194
+ }
195
+
196
+ return $this;
197
+ }
198
+
199
+ /**
200
+ * Set visibility of store switcher
201
+ *
202
+ * @param boolean $visible
203
+ */
204
+ public function setStoreSwitcherVisibility($visible = true)
205
+ {
206
+ $this->_storeSwitcherVisibility = $visible;
207
+ }
208
+
209
+ /**
210
+ * Return visibility of store switcher
211
+ *
212
+ * @return boolean
213
+ */
214
+ public function getStoreSwitcherVisibility()
215
+ {
216
+ return $this->_storeSwitcherVisibility;
217
+ }
218
+
219
+ /**
220
+ * Return store switcher html
221
+ *
222
+ * @return string
223
+ */
224
+ public function getStoreSwitcherHtml()
225
+ {
226
+ return $this->getChildHtml('store_switcher');
227
+ }
228
+
229
+ /**
230
+ * Set visibility of date filter
231
+ *
232
+ * @param boolean $visible
233
+ */
234
+ public function setDateFilterVisibility($visible = true)
235
+ {
236
+ $this->_dateFilterVisibility = $visible;
237
+ }
238
+
239
+ /**
240
+ * Return visibility of date filter
241
+ *
242
+ * @return boolean
243
+ */
244
+ public function getDateFilterVisibility()
245
+ {
246
+ return $this->_dateFilterVisibility;
247
+ }
248
+
249
+ /**
250
+ * Set visibility of export action
251
+ *
252
+ * @param boolean $visible
253
+ */
254
+ public function setExportVisibility($visible = true)
255
+ {
256
+ $this->_exportVisibility = $visible;
257
+ }
258
+
259
+ /**
260
+ * Return visibility of export action
261
+ *
262
+ * @return boolean
263
+ */
264
+ public function getExportVisibility()
265
+ {
266
+ return $this->_exportVisibility;
267
+ }
268
+
269
+ /**
270
+ * Set visibility of subtotals
271
+ *
272
+ * @param boolean $visible
273
+ */
274
+ public function setSubtotalVisibility($visible = true)
275
+ {
276
+ $this->_subtotalVisibility = $visible;
277
+ }
278
+
279
+ /**
280
+ * Return visibility of subtotals
281
+ *
282
+ * @return boolean
283
+ */
284
+ public function getSubtotalVisibility()
285
+ {
286
+ return $this->_subtotalVisibility;
287
+ }
288
+
289
+ public function getDateFormat()
290
+ {
291
+ return $this->getLocale()->getDateStrFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
292
+ }
293
+
294
+ /**
295
+ * Return refresh button html
296
+ */
297
+ public function getRefreshButtonHtml()
298
+ {
299
+ return $this->getChildHtml('refresh_button');
300
+ }
301
+
302
+ public function setFilter($name, $value)
303
+ {
304
+ if ($name) {
305
+ $this->_filters[$name] = $value;
306
+ }
307
+ }
308
+
309
+ public function getFilter($name)
310
+ {
311
+ if (isset($this->_filters[$name])) {
312
+ return $this->_filters[$name];
313
+ } else {
314
+ return ($this->getRequest()->getParam($name))
315
+ ? htmlspecialchars($this->getRequest()->getParam($name)) : '';
316
+ }
317
+ }
318
+
319
+ public function setSubReportSize($size)
320
+ {
321
+ $this->_subReportSize = $size;
322
+ }
323
+
324
+ public function getSubReportSize()
325
+ {
326
+ return $this->_subReportSize;
327
+ }
328
+
329
+ /**
330
+ * Retrieve locale
331
+ *
332
+ * @return Mage_Core_Model_Locale
333
+ */
334
+ public function getLocale()
335
+ {
336
+ if (!$this->_locale) {
337
+ $this->_locale = Mage::app()->getLocale();
338
+ }
339
+
340
+ return $this->_locale;
341
+ }
342
+
343
+ /**
344
+ * Add new export type to grid
345
+ *
346
+ * @param string $url
347
+ * @param string $label
348
+ *
349
+ * @return Mage_Adminhtml_Block_Widget_Grid
350
+ */
351
+ public function addExportType($url, $label)
352
+ {
353
+ $this->_exportTypes[] = new Varien_Object(
354
+ array(
355
+ 'url' => $this->getUrl($url,
356
+ array(
357
+ '_current' => true,
358
+ 'filter' => $this->getParam($this->getVarNameFilter(), null)
359
+ )
360
+ ),
361
+ 'label' => $label
362
+ )
363
+ );
364
+
365
+ return $this;
366
+ }
367
+
368
+
369
+ public function getReport($from, $to)
370
+ {
371
+ if ($from == '') {
372
+ $from = $this->getFilter('report_from');
373
+ }
374
+ if ($to == '') {
375
+ $to = $this->getFilter('report_to');
376
+ }
377
+ $totalObj = Mage::getModel('reports/totals');
378
+ $this->setTotals($totalObj->countTotals($this, $from, $to));
379
+ $this->addGrandTotals($this->getTotals());
380
+
381
+ return $this->getCollection()->setDateRange($from, $to)
382
+ ->setPageSize(false)
383
+ ->setStoreIds($this->getStoreIds());
384
+ }
385
+
386
+ public function addGrandTotals($total)
387
+ {
388
+ $totalData = $total->getData();
389
+ foreach ($totalData as $key => $value) {
390
+ $_column = $this->getColumn($key);
391
+ if ($_column->getTotal() != '') {
392
+ $this->getGrandTotals()->setData($key, $this->getGrandTotals()->getData($key) + $value);
393
+ }
394
+ }
395
+ /*
396
+ * recalc totals if we have average
397
+ */
398
+ foreach ($this->getColumns() as $key => $_column) {
399
+ if (strpos($_column->getTotal(), '/') !== false) {
400
+ list($t1, $t2) = explode('/', $_column->getTotal());
401
+ if ($this->getGrandTotals()->getData($t2) != 0) {
402
+ $this->getGrandTotals()->setData(
403
+ $key,
404
+ (float)$this->getGrandTotals()->getData($t1) / $this->getGrandTotals()->getData($t2)
405
+ );
406
+ }
407
+ }
408
+ }
409
+ }
410
+
411
+ public function getGrandTotals()
412
+ {
413
+ if (!$this->_grandTotals) {
414
+ $this->_grandTotals = new Varien_Object();
415
+ }
416
+
417
+ return $this->_grandTotals;
418
+ }
419
+
420
+ /**
421
+ * Retrieve grid as CSV
422
+ *
423
+ * @return unknown
424
+ */
425
+ public function getCsv()
426
+ {
427
+ $csv = '';
428
+ $this->_isExport = true;
429
+ $this->_prepareGrid();
430
+ $this->getCollection()->getSelect()->limit();
431
+ $this->getCollection()->setPageSize(0);
432
+ $this->getCollection()->load();
433
+ $this->_afterLoadCollection();
434
+
435
+ $data = array();
436
+ foreach ($this->_columns as $column) {
437
+ if (!$column->getIsSystem()) {
438
+ $data[] = '"' . $column->getExportHeader() . '"';
439
+ }
440
+ }
441
+ $csv .= implode(',', $data) . "\n";
442
+
443
+ foreach ($this->getCollection() as $item) {
444
+ $data = array();
445
+ foreach ($this->_columns as $column) {
446
+ if (!$column->getIsSystem()) {
447
+ $data[] = '"' . str_replace(array('"', '\\'), array('""', '\\\\'), $column->getRowFieldExport($item)) . '"';
448
+ }
449
+ }
450
+ $csv .= implode(',', $data) . "\n";
451
+ }
452
+
453
+ if ($this->getCountTotals()) {
454
+ $data = array();
455
+ $j = 0;
456
+ foreach ($this->_columns as $column) {
457
+ if ($j == 0) {
458
+ $data[] = '"' . $this->getTotalsText() . '"';
459
+ } else {
460
+ if (!$column->getIsSystem()) {
461
+ //$data[] = '"'.str_replace('"', '""', $column->getRowField($this->getTotals())).'"';
462
+ $data[] = '"' . str_replace(array('"', '\\'), array('""', '\\\\'), $column->getRowFieldExport($this->getTotals())) . '"';
463
+ }
464
+ }
465
+ $j++;
466
+ }
467
+ $csv .= implode(',', $data) . "\n";
468
+ }
469
+
470
+ return $csv;
471
+
472
+ }
473
+
474
+ /**
475
+ * Retrieve grid as Excel Xml
476
+ *
477
+ * @return unknown
478
+ */
479
+ public function getExcel($filename = '')
480
+ {
481
+
482
+ $this->_isExport = true;
483
+ $this->_prepareGrid();
484
+ $this->getCollection()->getSelect()->limit();
485
+ $this->getCollection()->setPageSize(0);
486
+ $this->getCollection()->load();
487
+ $this->_afterLoadCollection();
488
+ $headers = array();
489
+ $data = array();
490
+ foreach ($this->_columns as $column) {
491
+ if (!$column->getIsSystem()) {
492
+ $headers[] = $column->getHeader();
493
+ }
494
+ }
495
+ $data[] = $headers;
496
+
497
+ foreach ($this->getCollection() as $item) {
498
+ $row = array();
499
+ foreach ($this->_columns as $column) {
500
+ if (!$column->getIsSystem()) {
501
+ $row[] = $column->getRowField($item);
502
+ }
503
+ }
504
+ $data[] = $row;
505
+ }
506
+
507
+ if ($this->getCountTotals()) {
508
+
509
+ $j = 0;
510
+ $row = array();
511
+ foreach ($this->_columns as $column) {
512
+ if ($j == 0) {
513
+ $row[] = $this->__($this->getTotalText());
514
+ } elseif (!$column->getIsSystem()) {
515
+ $row[] = $column->getRowField($this->getTotals());
516
+ }
517
+ $j++;
518
+ }
519
+ $data[] = $row;
520
+ }
521
+
522
+ $xmlObj = new Varien_Convert_Parser_Xml_Excel();
523
+ $xmlObj->setVar('single_sheet', $filename);
524
+ $xmlObj->setData($data);
525
+ $xmlObj->unparse();
526
+
527
+ return $xmlObj->getData();
528
+
529
+ }
530
+
531
+ public function getSubtotalText()
532
+ {
533
+ return $this->__('Subtotal');
534
+ }
535
+
536
+ public function getTotalText()
537
+ {
538
+ return $this->__('Totals');
539
+ }
540
+
541
+ public function getEmptyText()
542
+ {
543
+ return $this->__('No records found for this period.');
544
+ }
545
+
546
+
547
+ /**
548
+ * onlick event for refresh button to show alert if fields are empty
549
+ *
550
+ * @return string
551
+ */
552
+ public function getRefreshButtonCallback()
553
+ {
554
+ return "{$this->getJsObjectName()}.doFilter();";
555
+
556
+ return "if ($('period_date_to').value == '' && $('period_date_from').value == '') {alert('" . $this->__('Please specify at least start or end date.') . "'); return false;}else {$this->getJsObjectName()}.doFilter();";
557
+ }
558
+
559
+ /**
560
+ * Retrieve errors
561
+ *
562
+ * @return array
563
+ */
564
+ public function getErrors()
565
+ {
566
+ return $this->_errors;
567
+ }
568
+
569
+ /**
570
+ * Retrieve correct currency code for select website, store, group
571
+ *
572
+ * @return string
573
+ */
574
+ public function getCurrentCurrencyCode()
575
+ {
576
+ if (is_null($this->_currentCurrencyCode)) {
577
+ if ($this->getRequest()->getParam('store')) {
578
+ $this->_currentCurrencyCode = Mage::app()->getStore($this->getRequest()->getParam('store'))->getBaseCurrencyCode();
579
+ } else if ($this->getRequest()->getParam('website')) {
580
+ $this->_currentCurrencyCode = Mage::app()->getWebsite($this->getRequest()->getParam('website'))->getBaseCurrencyCode();
581
+ } else if ($this->getRequest()->getParam('group')) {
582
+ $this->_currentCurrencyCode = Mage::app()->getGroup($this->getRequest()->getParam('group'))->getWebsite()->getBaseCurrencyCode();
583
+ } else {
584
+ $this->_currentCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
585
+ }
586
+ }
587
+
588
+ return $this->_currentCurrencyCode;
589
+ }
590
+
591
+ protected function _computeTotals()
592
+ {
593
+ $totals = new Varien_Object();
594
+
595
+ foreach ($this->getCollection() as $item) {
596
+ foreach ($this->getColumns() as $col) {
597
+ if ($col->getTotal()) {
598
+ $fieldName = $col->getIndex();
599
+ $subTotal = $totals->getData($fieldName);
600
+ $subTotal = $subTotal ? $subTotal : 0;
601
+ $subTotal += $item->getData($fieldName);
602
+ $totals->setData($fieldName, $subTotal);
603
+ }
604
+ }
605
+ }
606
+
607
+ $collectionSize = $this->getCollection()->getSize();
608
+ if ($collectionSize) {
609
+ foreach ($this->getColumns() as $col) {
610
+ $fieldName = $col->getIndex();
611
+ if ($col->getTotal() == 'avg') {
612
+ $avg = $totals->getData($fieldName) / $collectionSize;
613
+ $totals->setData($fieldName, $avg);
614
+ }
615
+ if ($col->getType() == 'currency') {
616
+ $total = Mage::helper('core')->currency($totals->getData($fieldName), true, false);
617
+ $totals->setData($fieldName, $total);
618
+ }
619
+
620
+ }
621
+ }
622
+
623
+ $this->setTotals($totals);
624
+
625
+ }
626
+
627
+ public function getRowUrl($row)
628
+ {
629
+ return false;
630
+ }
631
+ }
app/code/community/Zitec/ReportsCommon/Block/Renderer/Posnegcurrency.php CHANGED
@@ -1,43 +1,43 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * For columns of type 'currency'. Shown in green if it is positive, and red if negative.
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_ReportsCommon_Block_Renderer_Posnegcurrency extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
25
- {
26
- public function render(Varien_Object $row)
27
- {
28
- $value = $row->getData($this->getColumn()->getIndex());
29
- $formattedValue = Mage::helper('core')->currency($value, true, false);
30
- $html = '<span style="color: ' . ($value >= 0 ? 'green' : 'red') . '">' . $formattedValue . '</span>';
31
-
32
- return $html;
33
- }
34
-
35
- public function renderExport(Varien_Object $row)
36
- {
37
- $value = $row->getData($this->getColumn()->getIndex());
38
- $formattedValue = Mage::helper('core')->currency($value, true, false);
39
-
40
- return $formattedValue;
41
- }
42
- }
43
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * For columns of type 'currency'. Shown in green if it is positive, and red if negative.
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_ReportsCommon_Block_Renderer_Posnegcurrency extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
25
+ {
26
+ public function render(Varien_Object $row)
27
+ {
28
+ $value = $row->getData($this->getColumn()->getIndex());
29
+ $formattedValue = Mage::helper('core')->currency($value, true, false);
30
+ $html = '<span style="color: ' . ($value >= 0 ? 'green' : 'red') . '">' . $formattedValue . '</span>';
31
+
32
+ return $html;
33
+ }
34
+
35
+ public function renderExport(Varien_Object $row)
36
+ {
37
+ $value = $row->getData($this->getColumn()->getIndex());
38
+ $formattedValue = Mage::helper('core')->currency($value, true, false);
39
+
40
+ return $formattedValue;
41
+ }
42
+ }
43
+
app/code/community/Zitec/ReportsCommon/Controller/Adminhtml/RecordsreportController.php CHANGED
@@ -1,115 +1,115 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Parent class drivers reports "Record Report" (showing * rows - eg orders - individual).
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_ReportsCommon_Controller_Adminhtml_RecordsreportController extends Mage_Adminhtml_Controller_Action
25
- {
26
-
27
-
28
- protected $_exportFileName = 'Zitec_Report';
29
-
30
-
31
- protected $_gridBlock;
32
-
33
- /*
34
- * The maximum number of days between the date of permit beginning and end.
35
- * @var int
36
- */
37
- protected $_maxDaysInDateRange = 62;
38
-
39
-
40
- protected function _initAction()
41
- {
42
- $this->loadLayout();
43
-
44
- return $this;
45
- }
46
-
47
- public function indexAction()
48
- {
49
- $reportFrom = Mage::helper('core')->htmlEscape($this->getRequest()->getParam('report_from'));
50
- $reportTo = Mage::helper('core')->htmlEscape($this->getRequest()->getParam('report_to'));
51
-
52
- // We force the user to enter a range of dates when
53
- // click on 'Show Report'.
54
- if (!$reportFrom || !$reportTo) {
55
- if (!is_null($this->getRequest()->getParam('showReport'))) {
56
- Mage::getSingleton('core/session')->addError(Mage::helper('zitec_reportscommon')->__("Please select a 'from' and 'to' date."));
57
- }
58
- }
59
-
60
- /* We confirm that the dates are valid and do not break the established limits. */
61
- try {
62
- $from = Mage::app()->getLocale()->date($reportFrom, Zend_Date::DATE_SHORT, null, false);
63
- $to = Mage::app()->getLocale()->date($reportTo, Zend_Date::DATE_SHORT, null, false);
64
-
65
- $diff = $to->sub($from)->toValue();
66
- $days = ceil($diff / 60 / 60 / 24) + 1;
67
-
68
- if ($days > $this->_maxDaysInDateRange) {
69
- Mage::getSingleton('core/session')
70
- ->addError(Mage::helper('zitec_reportscommon')
71
- ->__(sprintf("The 'to' date must be at most %d days after the 'from' date.", $this->_maxDaysInDateRange)));
72
- }
73
- } catch (Exception $e) {
74
- Mage::getSingleton('core/session')->addError(Mage::helper('zitec_reportscommon')->__('Invalid date specified'));
75
- }
76
-
77
-
78
- $this->_initAction()->renderLayout();
79
- }
80
-
81
- public function exportCsvAction()
82
- {
83
- $fileName = $this->_exportFileName . '.csv';
84
- $content = $this->getLayout()->createBlock($this->_gridBlock)
85
- ->getCsv();
86
- $this->_sendUploadResponse($fileName, $content);
87
- }
88
-
89
- public function exportExcelAction()
90
- {
91
- $fileName = $this->_exportFileName . '.xml';
92
- $content = $this->getLayout()->createBlock($this->_gridBlock)
93
- ->getExcel($fileName);
94
- $this->_sendUploadResponse($fileName, $content);
95
- }
96
-
97
- protected function _sendUploadResponse($fileName, $content, $contentType = 'application/octet-stream')
98
- {
99
- $response = $this->getResponse();
100
- $response->setHeader('HTTP/1.1 200 OK', '');
101
- $response->setHeader('Pragma', 'public', true);
102
- $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
103
- $response->setHeader('Content-Disposition', 'attachment; filename=' . $fileName);
104
- $response->setHeader('Last-Modified', date('r'));
105
- $response->setHeader('Accept-Ranges', 'bytes');
106
- $response->setHeader('Content-Length', strlen($content));
107
- $response->setHeader('Content-type', $contentType);
108
- $response->setBody($content);
109
- $response->sendResponse();
110
- die;
111
- }
112
-
113
-
114
- }
115
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Parent class drivers reports "Record Report" (showing * rows - eg orders - individual).
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_ReportsCommon_Controller_Adminhtml_RecordsreportController extends Mage_Adminhtml_Controller_Action
25
+ {
26
+
27
+
28
+ protected $_exportFileName = 'Zitec_Report';
29
+
30
+
31
+ protected $_gridBlock;
32
+
33
+ /*
34
+ * The maximum number of days between the date of permit beginning and end.
35
+ * @var int
36
+ */
37
+ protected $_maxDaysInDateRange = 62;
38
+
39
+
40
+ protected function _initAction()
41
+ {
42
+ $this->loadLayout();
43
+
44
+ return $this;
45
+ }
46
+
47
+ public function indexAction()
48
+ {
49
+ $reportFrom = Mage::helper('core')->htmlEscape($this->getRequest()->getParam('report_from'));
50
+ $reportTo = Mage::helper('core')->htmlEscape($this->getRequest()->getParam('report_to'));
51
+
52
+ // We force the user to enter a range of dates when
53
+ // click on 'Show Report'.
54
+ if (!$reportFrom || !$reportTo) {
55
+ if (!is_null($this->getRequest()->getParam('showReport'))) {
56
+ Mage::getSingleton('core/session')->addError(Mage::helper('zitec_reportscommon')->__("Please select a 'from' and 'to' date."));
57
+ }
58
+ }
59
+
60
+ /* We confirm that the dates are valid and do not break the established limits. */
61
+ try {
62
+ $from = Mage::app()->getLocale()->date($reportFrom, Zend_Date::DATE_SHORT, null, false);
63
+ $to = Mage::app()->getLocale()->date($reportTo, Zend_Date::DATE_SHORT, null, false);
64
+
65
+ $diff = $to->sub($from)->toValue();
66
+ $days = ceil($diff / 60 / 60 / 24) + 1;
67
+
68
+ if ($days > $this->_maxDaysInDateRange) {
69
+ Mage::getSingleton('core/session')
70
+ ->addError(Mage::helper('zitec_reportscommon')
71
+ ->__(sprintf("The 'to' date must be at most %d days after the 'from' date.", $this->_maxDaysInDateRange)));
72
+ }
73
+ } catch (Exception $e) {
74
+ Mage::getSingleton('core/session')->addError(Mage::helper('zitec_reportscommon')->__('Invalid date specified'));
75
+ }
76
+
77
+
78
+ $this->_initAction()->renderLayout();
79
+ }
80
+
81
+ public function exportCsvAction()
82
+ {
83
+ $fileName = $this->_exportFileName . '.csv';
84
+ $content = $this->getLayout()->createBlock($this->_gridBlock)
85
+ ->getCsv();
86
+ $this->_sendUploadResponse($fileName, $content);
87
+ }
88
+
89
+ public function exportExcelAction()
90
+ {
91
+ $fileName = $this->_exportFileName . '.xml';
92
+ $content = $this->getLayout()->createBlock($this->_gridBlock)
93
+ ->getExcel($fileName);
94
+ $this->_sendUploadResponse($fileName, $content);
95
+ }
96
+
97
+ protected function _sendUploadResponse($fileName, $content, $contentType = 'application/octet-stream')
98
+ {
99
+ $response = $this->getResponse();
100
+ $response->setHeader('HTTP/1.1 200 OK', '');
101
+ $response->setHeader('Pragma', 'public', true);
102
+ $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
103
+ $response->setHeader('Content-Disposition', 'attachment; filename=' . $fileName);
104
+ $response->setHeader('Last-Modified', date('r'));
105
+ $response->setHeader('Accept-Ranges', 'bytes');
106
+ $response->setHeader('Content-Length', strlen($content));
107
+ $response->setHeader('Content-type', $contentType);
108
+ $response->setBody($content);
109
+ $response->sendResponse();
110
+ die;
111
+ }
112
+
113
+
114
+ }
115
+
app/code/community/Zitec/ReportsCommon/Helper/Data.php CHANGED
@@ -1,29 +1,29 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_ReportsCommon_Helper_Data extends Mage_Core_Helper_Abstract
25
- {
26
-
27
-
28
- }
29
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_ReportsCommon_Helper_Data extends Mage_Core_Helper_Abstract
25
+ {
26
+
27
+
28
+ }
29
+
app/code/community/Zitec/ReportsCommon/etc/adminhtml.xml CHANGED
@@ -1,32 +1,32 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <menu>
4
- <report>
5
- <children>
6
- <zitec_reportscommon translate="title">
7
- <title>DPD</title>
8
- <sort_order>9999</sort_order>
9
- </zitec_reportscommon>
10
- </children>
11
- </report>
12
- </menu>
13
- <acl>
14
- <resources>
15
- <all>
16
- <title>Allow Everything</title>
17
- </all>
18
- <admin>
19
- <children>
20
- <report>
21
- <children>
22
- <zitec_reportscommon translate="title">
23
- <title>DPD</title>
24
- <sort_order>9999</sort_order>
25
- </zitec_reportscommon>
26
- </children>
27
- </report>
28
- </children>
29
- </admin>
30
- </resources>
31
- </acl>
32
  </config>
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <menu>
4
+ <report>
5
+ <children>
6
+ <zitec_reportscommon translate="title">
7
+ <title>DPD</title>
8
+ <sort_order>9999</sort_order>
9
+ </zitec_reportscommon>
10
+ </children>
11
+ </report>
12
+ </menu>
13
+ <acl>
14
+ <resources>
15
+ <all>
16
+ <title>Allow Everything</title>
17
+ </all>
18
+ <admin>
19
+ <children>
20
+ <report>
21
+ <children>
22
+ <zitec_reportscommon translate="title">
23
+ <title>DPD</title>
24
+ <sort_order>9999</sort_order>
25
+ </zitec_reportscommon>
26
+ </children>
27
+ </report>
28
+ </children>
29
+ </admin>
30
+ </resources>
31
+ </acl>
32
  </config>
app/code/community/Zitec/ReportsCommon/etc/config.xml CHANGED
@@ -1,21 +1,21 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Zitec_ReportsCommon>
5
- <version>1.0.0</version>
6
- </Zitec_ReportsCommon>
7
- </modules>
8
- <global>
9
- <blocks>
10
- <zitec_reportscommon>
11
- <class>Zitec_ReportsCommon_Block</class>
12
- </zitec_reportscommon>
13
- </blocks>
14
- <helpers>
15
- <zitec_reportscommon>
16
- <class>Zitec_ReportsCommon_Helper</class>
17
- </zitec_reportscommon>
18
- </helpers>
19
- </global>
20
- </config>
21
-
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Zitec_ReportsCommon>
5
+ <version>1.0.0</version>
6
+ </Zitec_ReportsCommon>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <zitec_reportscommon>
11
+ <class>Zitec_ReportsCommon_Block</class>
12
+ </zitec_reportscommon>
13
+ </blocks>
14
+ <helpers>
15
+ <zitec_reportscommon>
16
+ <class>Zitec_ReportsCommon_Helper</class>
17
+ </zitec_reportscommon>
18
+ </helpers>
19
+ </global>
20
+ </config>
21
+
app/code/community/Zitec/ShippingReports/Block/Adminhtml/Profitability.php CHANGED
@@ -1,47 +1,47 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_ShippingReports_Block_Adminhtml_Profitability extends Mage_Adminhtml_Block_Widget_Grid_Container
25
- {
26
-
27
- public function __construct()
28
- {
29
- $this->_controller = 'adminhtml_profitability';
30
- $this->_blockGroup = 'zitec_shippingreports';
31
- $this->_headerText = Mage::helper('zitec_reportscommon')->__('Shipping Price vs Cost');
32
- parent::__construct();
33
- $this->setTemplate('zitec_reportscommon/records_report_container.phtml');
34
- $this->addButton('filter_form_submit', array(
35
- 'label' => Mage::helper('zitec_reportscommon')->__('Show Report'),
36
- 'onclick' => 'filterFormSubmit()'
37
- ));
38
- $this->_removeButton('add');
39
- }
40
-
41
- public function getFilterUrl()
42
- {
43
- $this->getRequest()->setParam('filter', null);
44
-
45
- return $this->getUrl('*/*/*', array('_current' => true));
46
- }
47
- }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_ShippingReports_Block_Adminhtml_Profitability extends Mage_Adminhtml_Block_Widget_Grid_Container
25
+ {
26
+
27
+ public function __construct()
28
+ {
29
+ $this->_controller = 'adminhtml_profitability';
30
+ $this->_blockGroup = 'zitec_shippingreports';
31
+ $this->_headerText = Mage::helper('zitec_reportscommon')->__('Shipping Price vs Cost');
32
+ parent::__construct();
33
+ $this->setTemplate('zitec_reportscommon/records_report_container.phtml');
34
+ $this->addButton('filter_form_submit', array(
35
+ 'label' => Mage::helper('zitec_reportscommon')->__('Show Report'),
36
+ 'onclick' => 'filterFormSubmit()'
37
+ ));
38
+ $this->_removeButton('add');
39
+ }
40
+
41
+ public function getFilterUrl()
42
+ {
43
+ $this->getRequest()->setParam('filter', null);
44
+
45
+ return $this->getUrl('*/*/*', array('_current' => true));
46
+ }
47
+ }
app/code/community/Zitec/ShippingReports/Block/Adminhtml/Profitability/Grid.php CHANGED
@@ -1,126 +1,126 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_ShippingReports_Block_Adminhtml_Profitability_Grid extends Zitec_ReportsCommon_Block_RecordsReport_Grid
25
- {
26
-
27
- public function __construct()
28
- {
29
- parent::__construct();
30
- $this->setId('zitec_ShippingReportsProfitabilityGrid');
31
- $this->setDefaultSort('created_at');
32
- $this->setDefaultDir('ASC');
33
- $this->setSaveParametersInSession(true);
34
- $this->setSubReportSize(false);
35
- }
36
-
37
- protected function _prepareCollection()
38
- {
39
- $collection = Mage::getResourceModel('zitec_shippingreports/profitability_collection');
40
- $collection->addReportFields();
41
- $this->setCollection($collection);
42
-
43
- parent::_prepareCollection();
44
-
45
- return $this;
46
- }
47
-
48
- protected function _prepareColumns()
49
- {
50
- $this->addColumn('order_ref', array(
51
- 'header' => Mage::helper('zitec_shippingreports')->__('Order #'),
52
- 'align' => 'right',
53
- 'index' => 'increment_id',
54
- 'renderer' => 'Zitec_ShippingReports_Block_Adminhtml_Profitability_Renderer_Orderref'
55
- ));
56
-
57
- $this->addColumn('created_at', array(
58
- 'header' => Mage::helper('zitec_shippingreports')->__('Purchased On'),
59
- 'index' => 'created_at',
60
- 'type' => 'datetime',
61
- ));
62
-
63
- $this->addColumn('shipping_name', array(
64
- 'header' => Mage::helper('zitec_shippingreports')->__('Ship to Name'),
65
- 'index' => 'zitec_shipping_name',
66
- ));
67
-
68
- $this->addColumn('shipping_postcode', array(
69
- 'header' => Mage::helper('zitec_shippingreports')->__('Postcode'),
70
- 'index' => 'zitec_shipping_postcode',
71
- ));
72
-
73
- $this->addColumn('shipping_region', array(
74
- 'header' => Mage::helper('zitec_shippingreports')->__('Region'),
75
- 'index' => 'zitec_shipping_region',
76
- ));
77
-
78
- $this->addColumn('zitec_shippingreports', array(
79
- 'header' => Mage::helper('zitec_shippingreports')->__('Country'),
80
- 'index' => 'zitec_shipping_country_id',
81
- 'type' => 'country'
82
- ));
83
-
84
- $this->addColumn('grand_total', array(
85
- 'header' => Mage::helper('zitec_shippingreports')->__('Order total'),
86
- 'index' => 'base_grand_total',
87
- 'type' => 'currency',
88
- 'total' => 'sum',
89
- 'currency' => 'base_currency_code',
90
-
91
- ));
92
-
93
-
94
- $this->addColumn('shipping_amount', array(
95
- 'header' => Mage::helper('zitec_shippingreports')->__('Shipping Price'),
96
- 'index' => 'base_shipping_amount',
97
- 'type' => 'currency',
98
- 'total' => 'sum',
99
- 'currency' => 'base_currency_code',
100
- ));
101
-
102
- $this->addColumn('total_shipping_cost', array(
103
- 'header' => Mage::helper('zitec_shippingreports')->__('Total Shipping Cost'),
104
- 'index' => 'zitec_total_shipping_cost',
105
- 'type' => 'currency',
106
- 'total' => 'sum',
107
- 'currency' => 'base_currency_code',
108
- ));
109
-
110
- $this->addColumn('shipping_profit', array(
111
- 'header' => Mage::helper('zitec_shippingreports')->__('Shipping Profit/Loss'),
112
- 'index' => 'zitec_shipping_profit',
113
- 'total' => 'sum',
114
- 'align' => 'right',
115
- 'renderer' => 'Zitec_ReportsCommon_Block_Renderer_Posnegcurrency',
116
- ));
117
-
118
- $this->addExportType('*/*/exportCsv', Mage::helper('zitec_shippingreports')->__('CSV'));
119
- $this->addExportType('*/*/exportExcel', Mage::helper('zitec_shippingreports')->__('Excel XML'));
120
-
121
- return parent::_prepareColumns();
122
- }
123
-
124
-
125
- }
126
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_ShippingReports_Block_Adminhtml_Profitability_Grid extends Zitec_ReportsCommon_Block_RecordsReport_Grid
25
+ {
26
+
27
+ public function __construct()
28
+ {
29
+ parent::__construct();
30
+ $this->setId('zitec_ShippingReportsProfitabilityGrid');
31
+ $this->setDefaultSort('created_at');
32
+ $this->setDefaultDir('ASC');
33
+ $this->setSaveParametersInSession(true);
34
+ $this->setSubReportSize(false);
35
+ }
36
+
37
+ protected function _prepareCollection()
38
+ {
39
+ $collection = Mage::getResourceModel('zitec_shippingreports/profitability_collection');
40
+ $collection->addReportFields();
41
+ $this->setCollection($collection);
42
+
43
+ parent::_prepareCollection();
44
+
45
+ return $this;
46
+ }
47
+
48
+ protected function _prepareColumns()
49
+ {
50
+ $this->addColumn('order_ref', array(
51
+ 'header' => Mage::helper('zitec_shippingreports')->__('Order #'),
52
+ 'align' => 'right',
53
+ 'index' => 'increment_id',
54
+ 'renderer' => 'Zitec_ShippingReports_Block_Adminhtml_Profitability_Renderer_Orderref'
55
+ ));
56
+
57
+ $this->addColumn('created_at', array(
58
+ 'header' => Mage::helper('zitec_shippingreports')->__('Purchased On'),
59
+ 'index' => 'created_at',
60
+ 'type' => 'datetime',
61
+ ));
62
+
63
+ $this->addColumn('shipping_name', array(
64
+ 'header' => Mage::helper('zitec_shippingreports')->__('Ship to Name'),
65
+ 'index' => 'zitec_shipping_name',
66
+ ));
67
+
68
+ $this->addColumn('shipping_postcode', array(
69
+ 'header' => Mage::helper('zitec_shippingreports')->__('Postcode'),
70
+ 'index' => 'zitec_shipping_postcode',
71
+ ));
72
+
73
+ $this->addColumn('shipping_region', array(
74
+ 'header' => Mage::helper('zitec_shippingreports')->__('Region'),
75
+ 'index' => 'zitec_shipping_region',
76
+ ));
77
+
78
+ $this->addColumn('zitec_shippingreports', array(
79
+ 'header' => Mage::helper('zitec_shippingreports')->__('Country'),
80
+ 'index' => 'zitec_shipping_country_id',
81
+ 'type' => 'country'
82
+ ));
83
+
84
+ $this->addColumn('grand_total', array(
85
+ 'header' => Mage::helper('zitec_shippingreports')->__('Order total'),
86
+ 'index' => 'base_grand_total',
87
+ 'type' => 'currency',
88
+ 'total' => 'sum',
89
+ 'currency' => 'base_currency_code',
90
+
91
+ ));
92
+
93
+
94
+ $this->addColumn('shipping_amount', array(
95
+ 'header' => Mage::helper('zitec_shippingreports')->__('Shipping Price'),
96
+ 'index' => 'base_shipping_amount',
97
+ 'type' => 'currency',
98
+ 'total' => 'sum',
99
+ 'currency' => 'base_currency_code',
100
+ ));
101
+
102
+ $this->addColumn('total_shipping_cost', array(
103
+ 'header' => Mage::helper('zitec_shippingreports')->__('Total Shipping Cost'),
104
+ 'index' => 'zitec_total_shipping_cost',
105
+ 'type' => 'currency',
106
+ 'total' => 'sum',
107
+ 'currency' => 'base_currency_code',
108
+ ));
109
+
110
+ $this->addColumn('shipping_profit', array(
111
+ 'header' => Mage::helper('zitec_shippingreports')->__('Shipping Profit/Loss'),
112
+ 'index' => 'zitec_shipping_profit',
113
+ 'total' => 'sum',
114
+ 'align' => 'right',
115
+ 'renderer' => 'Zitec_ReportsCommon_Block_Renderer_Posnegcurrency',
116
+ ));
117
+
118
+ $this->addExportType('*/*/exportCsv', Mage::helper('zitec_shippingreports')->__('CSV'));
119
+ $this->addExportType('*/*/exportExcel', Mage::helper('zitec_shippingreports')->__('Excel XML'));
120
+
121
+ return parent::_prepareColumns();
122
+ }
123
+
124
+
125
+ }
126
+
app/code/community/Zitec/ShippingReports/Block/Adminhtml/Profitability/Renderer/Orderref.php CHANGED
@@ -1,39 +1,39 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_ShippingReports_Block_Adminhtml_Profitability_Renderer_Orderref extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
25
- {
26
- public function render(Varien_Object $row)
27
- {
28
- $link = Mage::helper("adminhtml")->getUrl('adminhtml/sales_order/view', array('order_id' => $row->getEntityId()));
29
- $html = '<a href="' . $link . '">' . $row->getIncrementId() . '</a>';
30
-
31
- return $html;
32
- }
33
-
34
- public function renderExport(Varien_Object $row)
35
- {
36
- return $row->getIncrementId();
37
- }
38
- }
39
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_ShippingReports_Block_Adminhtml_Profitability_Renderer_Orderref extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
25
+ {
26
+ public function render(Varien_Object $row)
27
+ {
28
+ $link = Mage::helper("adminhtml")->getUrl('adminhtml/sales_order/view', array('order_id' => $row->getEntityId()));
29
+ $html = '<a href="' . $link . '">' . $row->getIncrementId() . '</a>';
30
+
31
+ return $html;
32
+ }
33
+
34
+ public function renderExport(Varien_Object $row)
35
+ {
36
+ return $row->getIncrementId();
37
+ }
38
+ }
39
+
app/code/community/Zitec/ShippingReports/Helper/Data.php CHANGED
@@ -1,28 +1,28 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_ShippingReports_Helper_Data extends Mage_Core_Helper_Abstract
25
- {
26
-
27
-
28
- }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_ShippingReports_Helper_Data extends Mage_Core_Helper_Abstract
25
+ {
26
+
27
+
28
+ }
app/code/community/Zitec/ShippingReports/Model/Mysql4/Profitability/Collection.php CHANGED
@@ -1,72 +1,72 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Report for price vs cost of shipping.
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_ShippingReports_Model_Mysql4_Profitability_Collection extends Mage_Sales_Model_Mysql4_Order_Collection
25
- {
26
-
27
-
28
- public function addReportFields()
29
- {
30
- $resource = Mage::getModel('core/resource');
31
- /* @var $resource Mage_Core_Model_Resource */
32
- $salesOrderAddressTable = $resource->getTableName('sales/order_address');
33
- $this->getSelect()
34
- ->columns(array('zitec_shipping_profit' => new Zend_Db_Expr("main_table.base_shipping_amount - main_table.zitec_total_shipping_cost")))
35
- ->joinLeft(array('zitec_shipping_address' => $salesOrderAddressTable),
36
- "main_table.entity_id = zitec_shipping_address.parent_id AND " .
37
- "zitec_shipping_address.address_type = 'shipping' ",
38
- array('zitec_shipping_name' => "CONCAT(zitec_shipping_address.lastname, ', ', zitec_shipping_address.firstname) ",
39
- 'zitec_shipping_postcode' => "zitec_shipping_address.postcode",
40
- 'zitec_shipping_region' => "zitec_shipping_address.region",
41
- 'zitec_shipping_country_id' => "zitec_shipping_address.country_id"
42
- ));
43
-
44
- return $this;
45
- }
46
-
47
- public function setStoreIds($storeIds)
48
- {
49
- if ($storeIds) {
50
- $this->addAttributeToFilter('store_id', array('in' => (array)$storeIds));
51
- }
52
-
53
- return $this;
54
- }
55
-
56
- /*
57
- * @param Zend_Date $from
58
- * @param Zend_Date $to
59
- */
60
-
61
- public function setDateRange($from, $to)
62
- {
63
- $fromDate = $from->toString('YYYY-MM-dd HH:mm:ss');
64
- $toDate = $to->toString('YYYY-MM-dd HH:mm:ss');
65
-
66
- $this->addAttributeToFilter('created_at', array('from' => $fromDate, 'to' => $toDate));
67
-
68
- return $this;
69
- }
70
-
71
- }
72
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Report for price vs cost of shipping.
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_ShippingReports_Model_Mysql4_Profitability_Collection extends Mage_Sales_Model_Mysql4_Order_Collection
25
+ {
26
+
27
+
28
+ public function addReportFields()
29
+ {
30
+ $resource = Mage::getModel('core/resource');
31
+ /* @var $resource Mage_Core_Model_Resource */
32
+ $salesOrderAddressTable = $resource->getTableName('sales/order_address');
33
+ $this->getSelect()
34
+ ->columns(array('zitec_shipping_profit' => new Zend_Db_Expr("main_table.base_shipping_amount - main_table.zitec_total_shipping_cost")))
35
+ ->joinLeft(array('zitec_shipping_address' => $salesOrderAddressTable),
36
+ "main_table.entity_id = zitec_shipping_address.parent_id AND " .
37
+ "zitec_shipping_address.address_type = 'shipping' ",
38
+ array('zitec_shipping_name' => "CONCAT(zitec_shipping_address.lastname, ', ', zitec_shipping_address.firstname) ",
39
+ 'zitec_shipping_postcode' => "zitec_shipping_address.postcode",
40
+ 'zitec_shipping_region' => "zitec_shipping_address.region",
41
+ 'zitec_shipping_country_id' => "zitec_shipping_address.country_id"
42
+ ));
43
+
44
+ return $this;
45
+ }
46
+
47
+ public function setStoreIds($storeIds)
48
+ {
49
+ if ($storeIds) {
50
+ $this->addAttributeToFilter('store_id', array('in' => (array)$storeIds));
51
+ }
52
+
53
+ return $this;
54
+ }
55
+
56
+ /*
57
+ * @param Zend_Date $from
58
+ * @param Zend_Date $to
59
+ */
60
+
61
+ public function setDateRange($from, $to)
62
+ {
63
+ $fromDate = $from->toString('YYYY-MM-dd HH:mm:ss');
64
+ $toDate = $to->toString('YYYY-MM-dd HH:mm:ss');
65
+
66
+ $this->addAttributeToFilter('created_at', array('from' => $fromDate, 'to' => $toDate));
67
+
68
+ return $this;
69
+ }
70
+
71
+ }
72
+
app/code/community/Zitec/ShippingReports/Model/Observer/Order.php CHANGED
@@ -1,58 +1,58 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_ShippingReports_Model_Observer_Order extends Mage_Core_Model_Abstract
25
- {
26
-
27
- /*
28
- * These marks are used to prevent the events are invoked twice.
29
- */
30
- protected $_beforeSaveAlreadyRun = false;
31
-
32
-
33
- /*
34
- * sales_order_shipment_save_before
35
- * @param Varien_Event_Observer $o
36
- * @return Varien_Event_Observer
37
- */
38
- public function beforeSave($o)
39
- {
40
- if ($this->_beforeSaveAlreadyRun) {
41
- return $o;
42
- }
43
-
44
- $order = $o->getEvent()->getOrder();
45
-
46
- // The total shipping costs for new orders is initialized.
47
- if (!$order->getId()) {
48
- $order->setData('zitec_total_shipping_cost', 0);
49
- }
50
- $this->_beforeSaveAlreadyRun = true;
51
-
52
- return $o;
53
- }
54
-
55
-
56
- }
57
-
58
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_ShippingReports_Model_Observer_Order extends Mage_Core_Model_Abstract
25
+ {
26
+
27
+ /*
28
+ * These marks are used to prevent the events are invoked twice.
29
+ */
30
+ protected $_beforeSaveAlreadyRun = false;
31
+
32
+
33
+ /*
34
+ * sales_order_shipment_save_before
35
+ * @param Varien_Event_Observer $o
36
+ * @return Varien_Event_Observer
37
+ */
38
+ public function beforeSave($o)
39
+ {
40
+ if ($this->_beforeSaveAlreadyRun) {
41
+ return $o;
42
+ }
43
+
44
+ $order = $o->getEvent()->getOrder();
45
+
46
+ // The total shipping costs for new orders is initialized.
47
+ if (!$order->getId()) {
48
+ $order->setData('zitec_total_shipping_cost', 0);
49
+ }
50
+ $this->_beforeSaveAlreadyRun = true;
51
+
52
+ return $o;
53
+ }
54
+
55
+
56
+ }
57
+
58
+
app/code/community/Zitec/ShippingReports/Model/Observer/Shipment.php CHANGED
@@ -1,89 +1,89 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_ShippingReports_Model_Observer_Shipment extends Mage_Core_Model_Abstract
25
- {
26
-
27
- /*
28
- * These marks are used to prevent the events are invoked twice.
29
- */
30
- protected $_beforeSaveAlreadyRun = false;
31
-
32
-
33
- /*
34
- * sales_order_shipment_save_before
35
- * If invoked from the page 'New Shipment' Magento Admin
36
- * look if present in the POST data shipping cost added by module PackedShipment.
37
- * If yes is present, update shipping and order with the cost reports.
38
- * @param Varien_Event_Observer $o
39
- * @return Varien_Event_Observer
40
- */
41
- public function beforeSave($o)
42
- {
43
- if ($this->_beforeSaveAlreadyRun) {
44
- return $o;
45
- }
46
-
47
- // For all new submissions, it is initialized
48
-
49
-
50
- $module = Mage::app()->getRequest()->getModuleName();
51
- $controller = Mage::app()->getRequest()->getControllerName();
52
- $action = Mage::app()->getRequest()->getActionName();
53
-
54
-
55
- $shippingCost = Mage::app()->getRequest()->getParam('zitecShippingResportsShippingCost');
56
- if (is_null($shippingCost) || strlen($shippingCost) == 0) {
57
- return $o;
58
- }
59
-
60
- $shipment = $o->getEvent()->getShipment();
61
-
62
-
63
- $oldShippingCost = $shipment->getData('zitec_shipping_cost', $shippingCost);
64
-
65
-
66
- $shipment->setData('zitec_shipping_cost', $shippingCost);
67
-
68
- // The order is updated with the total shipping cost.
69
- $order = $shipment->getOrder();
70
-
71
- $totalShippingCost = $order->getData('zitec_total_shipping_cost');
72
- $totalShippingCost = $totalShippingCost ? $totalShippingCost : 0.000;
73
-
74
- $totalShippingCost += $shippingCost;
75
-
76
- if ($oldShippingCost) {
77
- $totalShippingCost -= $oldShippingCost;
78
- }
79
-
80
- $order->setData('zitec_total_shipping_cost', (string)$totalShippingCost);
81
-
82
- $this->_beforeSaveAlreadyRun = true;
83
-
84
- return $o;
85
- }
86
-
87
-
88
- }
89
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_ShippingReports_Model_Observer_Shipment extends Mage_Core_Model_Abstract
25
+ {
26
+
27
+ /*
28
+ * These marks are used to prevent the events are invoked twice.
29
+ */
30
+ protected $_beforeSaveAlreadyRun = false;
31
+
32
+
33
+ /*
34
+ * sales_order_shipment_save_before
35
+ * If invoked from the page 'New Shipment' Magento Admin
36
+ * look if present in the POST data shipping cost added by module PackedShipment.
37
+ * If yes is present, update shipping and order with the cost reports.
38
+ * @param Varien_Event_Observer $o
39
+ * @return Varien_Event_Observer
40
+ */
41
+ public function beforeSave($o)
42
+ {
43
+ if ($this->_beforeSaveAlreadyRun) {
44
+ return $o;
45
+ }
46
+
47
+ // For all new submissions, it is initialized
48
+
49
+
50
+ $module = Mage::app()->getRequest()->getModuleName();
51
+ $controller = Mage::app()->getRequest()->getControllerName();
52
+ $action = Mage::app()->getRequest()->getActionName();
53
+
54
+
55
+ $shippingCost = Mage::app()->getRequest()->getParam('zitecShippingResportsShippingCost');
56
+ if (is_null($shippingCost) || strlen($shippingCost) == 0) {
57
+ return $o;
58
+ }
59
+
60
+ $shipment = $o->getEvent()->getShipment();
61
+
62
+
63
+ $oldShippingCost = $shipment->getData('zitec_shipping_cost', $shippingCost);
64
+
65
+
66
+ $shipment->setData('zitec_shipping_cost', $shippingCost);
67
+
68
+ // The order is updated with the total shipping cost.
69
+ $order = $shipment->getOrder();
70
+
71
+ $totalShippingCost = $order->getData('zitec_total_shipping_cost');
72
+ $totalShippingCost = $totalShippingCost ? $totalShippingCost : 0.000;
73
+
74
+ $totalShippingCost += $shippingCost;
75
+
76
+ if ($oldShippingCost) {
77
+ $totalShippingCost -= $oldShippingCost;
78
+ }
79
+
80
+ $order->setData('zitec_total_shipping_cost', (string)$totalShippingCost);
81
+
82
+ $this->_beforeSaveAlreadyRun = true;
83
+
84
+ return $o;
85
+ }
86
+
87
+
88
+ }
89
+
app/code/community/Zitec/ShippingReports/controllers/Adminhtml/Reports/ProfitabilityController.php CHANGED
@@ -1,35 +1,35 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_ShippingReports_Adminhtml_Reports_ProfitabilityController extends Zitec_ReportsCommon_Controller_Adminhtml_RecordsreportController
25
- {
26
-
27
- protected function _construct()
28
- {
29
- $this->_exportFileName = 'zitec_shippingreports_price_vs_cost';
30
- $this->_gridBlock = 'zitec_shippingreports/adminhtml_profitability_grid';
31
- }
32
-
33
-
34
- }
35
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_ShippingReports_Adminhtml_Reports_ProfitabilityController extends Zitec_ReportsCommon_Controller_Adminhtml_RecordsreportController
25
+ {
26
+
27
+ protected function _construct()
28
+ {
29
+ $this->_exportFileName = 'zitec_shippingreports_price_vs_cost';
30
+ $this->_gridBlock = 'zitec_shippingreports/adminhtml_profitability_grid';
31
+ }
32
+
33
+
34
+ }
35
+
app/code/community/Zitec/ShippingReports/etc/adminhtml.xml CHANGED
@@ -1,43 +1,43 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <menu>
4
- <report>
5
- <children>
6
-
7
- <zitec_reportscommon>
8
- <children>
9
- <zitec_shippingreports translate="title" module="zitec_shippingreports">
10
- <title>Shipping Price vs Cost</title>
11
- <action>zitec_shippingreports/adminhtml_reports_profitability</action>
12
- </zitec_shippingreports>
13
- </children>
14
- </zitec_reportscommon>
15
- </children>
16
- </report>
17
- </menu>
18
- <acl>
19
- <resources>
20
- <all>
21
- <title>Allow Everything</title>
22
- </all>
23
- <admin>
24
- <children>
25
- <report>
26
- <children>
27
- <zitec_reportscommon translate="title">
28
- <title>DPD reports</title>
29
- <sort_order>9999</sort_order>
30
- <children>
31
- <zitec_shippingreports translate="title" module="zitec_shippingreports">
32
- <title>Shipping Price vs Cost</title>
33
- <action>zitec_shippingreports/adminhtml_reports_profitability</action>
34
- </zitec_shippingreports>
35
- </children>
36
- </zitec_reportscommon>
37
- </children>
38
- </report>
39
- </children>
40
- </admin>
41
- </resources>
42
- </acl>
43
  </config>
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <menu>
4
+ <report>
5
+ <children>
6
+
7
+ <zitec_reportscommon>
8
+ <children>
9
+ <zitec_shippingreports translate="title" module="zitec_shippingreports">
10
+ <title>Shipping Price vs Cost</title>
11
+ <action>zitec_shippingreports/adminhtml_reports_profitability</action>
12
+ </zitec_shippingreports>
13
+ </children>
14
+ </zitec_reportscommon>
15
+ </children>
16
+ </report>
17
+ </menu>
18
+ <acl>
19
+ <resources>
20
+ <all>
21
+ <title>Allow Everything</title>
22
+ </all>
23
+ <admin>
24
+ <children>
25
+ <report>
26
+ <children>
27
+ <zitec_reportscommon translate="title">
28
+ <title>DPD reports</title>
29
+ <sort_order>9999</sort_order>
30
+ <children>
31
+ <zitec_shippingreports translate="title" module="zitec_shippingreports">
32
+ <title>Shipping Price vs Cost</title>
33
+ <action>zitec_shippingreports/adminhtml_reports_profitability</action>
34
+ </zitec_shippingreports>
35
+ </children>
36
+ </zitec_reportscommon>
37
+ </children>
38
+ </report>
39
+ </children>
40
+ </admin>
41
+ </resources>
42
+ </acl>
43
  </config>
app/code/community/Zitec/ShippingReports/etc/config.xml CHANGED
@@ -1,79 +1,79 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Zitec_ShippingReports>
5
- <version>1.0.0</version>
6
- </Zitec_ShippingReports>
7
- </modules>
8
- <admin>
9
- <routers>
10
- <zitec_shippingreports>
11
- <use>admin</use>
12
- <args>
13
- <module>Zitec_ShippingReports</module>
14
- <frontName>zitec_shippingreports</frontName>
15
- </args>
16
- </zitec_shippingreports>
17
- </routers>
18
- </admin>
19
- <adminhtml>
20
- <layout>
21
- <updates>
22
- <zitec_shippingreports>
23
- <file>zitec_shippingreports.xml</file>
24
- </zitec_shippingreports>
25
- </updates>
26
- </layout>
27
- </adminhtml>
28
- <global>
29
- <models>
30
- <zitec_shippingreports>
31
- <class>Zitec_ShippingReports_Model</class>
32
- <resourceModel>zitec_shippingreports_mysql4</resourceModel>
33
- </zitec_shippingreports>
34
- <zitec_shippingreports_mysql4>
35
- <class>Zitec_ShippingReports_Model_Mysql4</class>
36
- </zitec_shippingreports_mysql4>
37
- </models>
38
- <blocks>
39
- <zitec_shippingreports>
40
- <class>Zitec_ShippingReports_Block</class>
41
- </zitec_shippingreports>
42
- </blocks>
43
- <helpers>
44
- <zitec_shippingreports>
45
- <class>Zitec_ShippingReports_Helper</class>
46
- </zitec_shippingreports>
47
- </helpers>
48
- <resources>
49
- <zitec_shippingreports_setup>
50
- <setup>
51
- <module>Zitec_ShippingReports</module>
52
- <class>Mage_Sales_Model_Mysql4_Setup</class>
53
- </setup>
54
- <connection>
55
- <use>core_setup</use>
56
- </connection>
57
- </zitec_shippingreports_setup>
58
- </resources>
59
- <events>
60
- <sales_order_shipment_save_before>
61
- <observers>
62
- <zitec_shippingreports_shipment_before_save>
63
- <class>zitec_shippingreports/observer_shipment</class>
64
- <method>beforeSave</method>
65
- </zitec_shippingreports_shipment_before_save>
66
- </observers>
67
- </sales_order_shipment_save_before>
68
- <sales_order_save_before>
69
- <observers>
70
- <zitec_shippingreports_order_before_save>
71
- <class>zitec_shippingreports/observer_order</class>
72
- <method>beforeSave</method>
73
- </zitec_shippingreports_order_before_save>
74
- </observers>
75
- </sales_order_save_before>
76
- </events>
77
- </global>
78
- </config>
79
-
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Zitec_ShippingReports>
5
+ <version>1.0.0</version>
6
+ </Zitec_ShippingReports>
7
+ </modules>
8
+ <admin>
9
+ <routers>
10
+ <zitec_shippingreports>
11
+ <use>admin</use>
12
+ <args>
13
+ <module>Zitec_ShippingReports</module>
14
+ <frontName>zitec_shippingreports</frontName>
15
+ </args>
16
+ </zitec_shippingreports>
17
+ </routers>
18
+ </admin>
19
+ <adminhtml>
20
+ <layout>
21
+ <updates>
22
+ <zitec_shippingreports>
23
+ <file>zitec_shippingreports.xml</file>
24
+ </zitec_shippingreports>
25
+ </updates>
26
+ </layout>
27
+ </adminhtml>
28
+ <global>
29
+ <models>
30
+ <zitec_shippingreports>
31
+ <class>Zitec_ShippingReports_Model</class>
32
+ <resourceModel>zitec_shippingreports_mysql4</resourceModel>
33
+ </zitec_shippingreports>
34
+ <zitec_shippingreports_mysql4>
35
+ <class>Zitec_ShippingReports_Model_Mysql4</class>
36
+ </zitec_shippingreports_mysql4>
37
+ </models>
38
+ <blocks>
39
+ <zitec_shippingreports>
40
+ <class>Zitec_ShippingReports_Block</class>
41
+ </zitec_shippingreports>
42
+ </blocks>
43
+ <helpers>
44
+ <zitec_shippingreports>
45
+ <class>Zitec_ShippingReports_Helper</class>
46
+ </zitec_shippingreports>
47
+ </helpers>
48
+ <resources>
49
+ <zitec_shippingreports_setup>
50
+ <setup>
51
+ <module>Zitec_ShippingReports</module>
52
+ <class>Mage_Sales_Model_Mysql4_Setup</class>
53
+ </setup>
54
+ <connection>
55
+ <use>core_setup</use>
56
+ </connection>
57
+ </zitec_shippingreports_setup>
58
+ </resources>
59
+ <events>
60
+ <sales_order_shipment_save_before>
61
+ <observers>
62
+ <zitec_shippingreports_shipment_before_save>
63
+ <class>zitec_shippingreports/observer_shipment</class>
64
+ <method>beforeSave</method>
65
+ </zitec_shippingreports_shipment_before_save>
66
+ </observers>
67
+ </sales_order_shipment_save_before>
68
+ <sales_order_save_before>
69
+ <observers>
70
+ <zitec_shippingreports_order_before_save>
71
+ <class>zitec_shippingreports/observer_order</class>
72
+ <method>beforeSave</method>
73
+ </zitec_shippingreports_order_before_save>
74
+ </observers>
75
+ </sales_order_save_before>
76
+ </events>
77
+ </global>
78
+ </config>
79
+
app/code/community/Zitec/ShippingReports/sql/zitec_shippingreports_setup/mysql4-install-1.0.0.php CHANGED
@@ -1,41 +1,41 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
-
25
- $installer = $this;
26
- /* @var $this Mage_Core_Model_Resource_Setup */
27
- /* @var $installer Mage_Core_Model_Resource_Setup */
28
-
29
- $installer->startSetup();
30
-
31
- $installer->addAttribute('shipment', 'zitec_shipping_cost', array('type' => 'decimal', 'grid' => true));
32
-
33
- $installer->addAttribute('order', 'zitec_total_shipping_cost', array('type' => 'decimal', 'grid' => true));
34
-
35
- $installer->run("update {$installer->getTable('sales_flat_order')} set zitec_total_shipping_cost = 0 where zitec_total_shipping_cost is null");
36
-
37
- $installer->run("update {$installer->getTable('sales_flat_shipment')} set zitec_shipping_cost = 0 where zitec_shipping_cost is null");
38
-
39
- $installer->endSetup();
40
-
41
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+
25
+ $installer = $this;
26
+ /* @var $this Mage_Core_Model_Resource_Setup */
27
+ /* @var $installer Mage_Core_Model_Resource_Setup */
28
+
29
+ $installer->startSetup();
30
+
31
+ $installer->addAttribute('shipment', 'zitec_shipping_cost', array('type' => 'decimal', 'grid' => true));
32
+
33
+ $installer->addAttribute('order', 'zitec_total_shipping_cost', array('type' => 'decimal', 'grid' => true));
34
+
35
+ $installer->run("update {$installer->getTable('sales_flat_order')} set zitec_total_shipping_cost = 0 where zitec_total_shipping_cost is null");
36
+
37
+ $installer->run("update {$installer->getTable('sales_flat_shipment')} set zitec_shipping_cost = 0 where zitec_shipping_cost is null");
38
+
39
+ $installer->endSetup();
40
+
41
+
app/code/community/Zitec/TableRates/Block/Adminhtml/Tablerate.php CHANGED
@@ -1,75 +1,75 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_TableRates_Block_Adminhtml_Tablerate extends Mage_Adminhtml_Block_Widget_Grid_Container
25
- {
26
-
27
- public function __construct()
28
- {
29
- $this->_controller = 'adminhtml_tablerate';
30
- $this->_blockGroup = 'zitec_tablerates';
31
- $this->_headerText = $this->_getHelper()->getGridTitle();
32
- $this->_addButtonLabel = Mage::helper('zitec_tablerates')->__('Add Rate');
33
-
34
- $this->_addButton('zitec_import',
35
- array(
36
- 'label' => $this->_getHelper()->__('Import Rates'),
37
- 'onclick' => "setLocation('{$this->getImportUrl()}')"
38
- ));
39
-
40
- $this->_addButton('zitec_export',
41
- array(
42
- 'label' => $this->_getHelper()->__('Export Rates'),
43
- 'onclick' => "setLocation('{$this->getExportUrl()}')"
44
- ));
45
- parent::__construct();
46
-
47
-
48
- }
49
-
50
- /**
51
- *
52
- * @return Zitec_TableRates_Helper_Data
53
- */
54
- protected function _getHelper()
55
- {
56
- return Mage::helper('zitec_tablerates');
57
- }
58
-
59
- public function getCreateUrl()
60
- {
61
- return $this->getUrl('*/*/new', array("carrier" => $this->_getHelper()->getCarrierCode()));
62
- }
63
-
64
- public function getImportUrl()
65
- {
66
- return $this->getUrl('*/*/import', array("carrier" => $this->_getHelper()->getCarrierCode()));
67
- }
68
-
69
- public function getExportUrl()
70
- {
71
- return $this->getUrl('*/*/export', array("carrier" => $this->_getHelper()->getCarrierCode()));
72
- }
73
-
74
-
75
- }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_TableRates_Block_Adminhtml_Tablerate extends Mage_Adminhtml_Block_Widget_Grid_Container
25
+ {
26
+
27
+ public function __construct()
28
+ {
29
+ $this->_controller = 'adminhtml_tablerate';
30
+ $this->_blockGroup = 'zitec_tablerates';
31
+ $this->_headerText = $this->_getHelper()->getGridTitle();
32
+ $this->_addButtonLabel = Mage::helper('zitec_tablerates')->__('Add Rate');
33
+
34
+ $this->_addButton('zitec_import',
35
+ array(
36
+ 'label' => $this->_getHelper()->__('Import Rates'),
37
+ 'onclick' => "setLocation('{$this->getImportUrl()}')"
38
+ ));
39
+
40
+ $this->_addButton('zitec_export',
41
+ array(
42
+ 'label' => $this->_getHelper()->__('Export Rates'),
43
+ 'onclick' => "setLocation('{$this->getExportUrl()}')"
44
+ ));
45
+ parent::__construct();
46
+
47
+
48
+ }
49
+
50
+ /**
51
+ *
52
+ * @return Zitec_TableRates_Helper_Data
53
+ */
54
+ protected function _getHelper()
55
+ {
56
+ return Mage::helper('zitec_tablerates');
57
+ }
58
+
59
+ public function getCreateUrl()
60
+ {
61
+ return $this->getUrl('*/*/new', array("carrier" => $this->_getHelper()->getCarrierCode()));
62
+ }
63
+
64
+ public function getImportUrl()
65
+ {
66
+ return $this->getUrl('*/*/import', array("carrier" => $this->_getHelper()->getCarrierCode()));
67
+ }
68
+
69
+ public function getExportUrl()
70
+ {
71
+ return $this->getUrl('*/*/export', array("carrier" => $this->_getHelper()->getCarrierCode()));
72
+ }
73
+
74
+
75
+ }
app/code/community/Zitec/TableRates/Block/Adminhtml/Tablerate/Edit.php CHANGED
@@ -1,357 +1,357 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_TableRates_Block_Adminhtml_Tablerate_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
25
- {
26
-
27
- /**
28
- *
29
- * @var array
30
- */
31
- public function __construct()
32
- {
33
- $this->_objectId = 'tablerate_id';
34
- $this->_blockGroup = 'zitec_tablerates';
35
- $this->_controller = 'adminhtml_tablerate';
36
- $model = Mage::registry('tablerate_data');
37
- /* @var $model Zitec_TableRates_Model_Tablerate */
38
- parent::__construct();
39
-
40
- $this->_updateButton('save', 'label', Mage::helper('zitec_tablerates')->__('Save'));
41
- if ($model->getId()) {
42
- $this->_updateButton('delete', 'label', Mage::helper('zitec_tablerates')->__('Delete'));
43
-
44
- $this->_addButton('duplicate', array(
45
- 'label' => Mage::helper('zitec_tablerates')->__('Duplicate'),
46
- 'class' => 'add',
47
- 'onclick' => "zitecDpdDuplicate()",
48
-
49
- ));
50
- } else {
51
- $this->_removeButton('delete');
52
- }
53
-
54
- $json = Mage::helper('zitec_tablerates/directory')->getRegionJson2();
55
-
56
- $this->_formScripts[] = "function zitecDpdDuplicate() {
57
- if ($('tablerate_id') && $('edit_form')) {
58
- $('edit_form').action = $('edit_form').action + 'duplicate/1';
59
- editForm.submit();
60
- }
61
-
62
-
63
- }";
64
- $this->_formScripts[] = "var updater = new RegionUpdater('{$model->getMappedName('dest_country_id')}', 'none', '{$model->getMappedName('dest_region_id')}', $json, 'disable'); ";
65
- $this->_formScripts[] = "
66
- (function() {
67
- var WEIGHT_AND_ABOVE_LABEL = '{$this->_getHelper()->__("Weight (and above)")}';
68
- var PRICE_AND_ABOVE_LABEL = '{$this->_getHelper()->__("Price (and above)")}';
69
-
70
- var SHIPPING_PRICE_LABEL = '{$this->_getHelper()->__("Shipping Price")}';
71
- var SHIPPING_PERCENTAGE_LABEL = '{$this->_getHelper()->__("Shipping Percentage")}';
72
- var SHIPPING_FIXED_AMOUNT_LABEL = '{$this->_getHelper()->__("Add fixed amount to price")}';
73
-
74
- var COD_SURCHARGE_FIXED_LABEL = '{$this->_getHelper()->__("Fixed Cash On Delivery Surcharge Amount")}';
75
- var COD_SURCHARGE_PERCENTAGE_LABEL = '{$this->_getHelper()->__("Cash On Delivery Surcharge Percentage")}';
76
-
77
- var COD_MIN_SURCHARGE_LABEL = '{$this->_getHelper()->__("Minimum COD Surcharge")}';
78
-
79
- var PRICE_AND_ABOVE_NOTE = '{$this->_getHelper()->__("Enter the starting price for this rate in the base currency of website. This rate will apply to orders whose subtotal (excluding shipping) is greater or equal to this price. Only include the sales tax/VAT in this price if you have configured shipping prices to include it (see System->Configuration->Sales->Tax->Calulation Settings->Shipping Prices).")}';
80
- var WEIGHT_AND_ABOVE_NOTE = '{$this->_getHelper()->__("Enter the starting weight in kg for this rate.")}';
81
-
82
- var selectorEventHandlers = [];
83
-
84
- return {
85
-
86
-
87
- init: function() {
88
- document.observe('dom:loaded', function() {
89
- this.setLabelDependingOnSelect({
90
- selector: 'price_vs_dest',
91
- labelFor: 'weight_price',
92
- values: {
93
- '0': WEIGHT_AND_ABOVE_LABEL,
94
- '1': PRICE_AND_ABOVE_LABEL
95
- },
96
- notes: {
97
- '0': WEIGHT_AND_ABOVE_NOTE,
98
- '1': PRICE_AND_ABOVE_NOTE
99
- },
100
- isRequired: true,
101
- validation: ['validate-number']
102
- });
103
-
104
- this.setLabelDependingOnSelect({
105
- selector: 'markup_type',
106
- labelFor: 'price',
107
- values: {
108
- '0': SHIPPING_PRICE_LABEL,
109
- '1': SHIPPING_PERCENTAGE_LABEL,
110
- '2': SHIPPING_FIXED_AMOUNT_LABEL
111
- },
112
- isRequired: true,
113
- validation: ['validate-number']
114
- });
115
-
116
- this.setLabelDependingOnSelect({
117
- selector: 'cod_option',
118
- labelFor: 'cashondelivery_surcharge',
119
- values: {
120
- '0': null,
121
- '1': null,
122
- '2': COD_SURCHARGE_FIXED_LABEL,
123
- '3': COD_SURCHARGE_PERCENTAGE_LABEL
124
- },
125
- isRequired: true,
126
- validation: ['validate-number']
127
- });
128
-
129
- this.setLabelDependingOnSelect({
130
- selector: 'cod_option',
131
- labelFor: 'cod_min_surcharge',
132
- values: {
133
- '0': null,
134
- '1': null,
135
- '2': null,
136
- '3': COD_MIN_SURCHARGE_LABEL
137
- },
138
- isRequired: false,
139
- validation: ['validate-number']
140
- });
141
-
142
- this.hideFieldsDependingOnSelect('shipping_method_enabled',
143
- ['0'],
144
- [ { 'id': 'markup_type', 'isRequired' : true, validation: []},
145
- { 'id': 'price', 'isRequired' : true, validation: ['validate-number'], 'onShow': this.blankPricePercentage},
146
- { 'id': 'cod_option', 'isRequired' : true, validation: []},
147
- { 'id': 'cashondelivery_surcharge', 'isRequired' : true, validation: ['validate-number']},
148
- { 'id': 'cod_min_surcharge', 'isRequired' : false, validation: ['validate-number']}
149
-
150
- ]
151
-
152
- );
153
- }.bind(this));
154
-
155
- },
156
-
157
- blankPricePercentage: function() {
158
- var value = $('price').getValue();
159
- if (!isNaN(parseFloat(value)) && isFinite(value) && value < 0) {
160
- $('price').setValue('');
161
- }
162
- },
163
-
164
- setLabelDependingOnSelect: function(options) {
165
- var element = $(options.labelFor),
166
- elementRow = this.getElementRow(options.labelFor),
167
- label = this.getLabelForId(options.labelFor),
168
- select = $(options.selector),
169
- note = this.getNoteForId(options.labelFor),
170
- labelText = null,
171
- handler = null;
172
-
173
- if (!element || !label || !select) {
174
- return false;
175
- }
176
-
177
- handler = function() {
178
- var i = 0,
179
- validatorsCount = options.validation.length;
180
-
181
- labelText = options.values[select.getValue()];
182
- if (labelText) {
183
- if (options.isRequired) {
184
- labelText += ' <span class=\"required\">*</span>';
185
- element.addClassName('required-entry');
186
- }
187
- for (i = 0; i < validatorsCount; i += 1) {
188
- element.addClassName(options.validation[i]);
189
- }
190
- label.innerHTML = labelText;
191
- if (note && options.notes && options.notes[select.getValue()]) {
192
- note.innerHTML = options.notes[select.getValue()];
193
- }
194
- if (elementRow) {
195
- elementRow.show();
196
- }
197
- element.show();
198
- label.show();
199
- } else {
200
- if (elementRow) {
201
- elementRow.hide();
202
- }
203
- element.hide();
204
- label.hide();
205
- element.removeClassName('required-entry');
206
- for (i = 0; i < validatorsCount; i += 1) {
207
- element.removeClassName(options.validation[i]);
208
- }
209
- element.setValue('');
210
- }
211
-
212
- };
213
-
214
- selectorEventHandlers.push(handler);
215
-
216
- handler();
217
-
218
- select.observe('change', handler);
219
-
220
- return true;
221
- },
222
-
223
- hideFieldsDependingOnSelect: function(selectId, selectHideValues, hiddenFields) {
224
- var select = $(selectId),
225
- that = this,
226
- handler = null;
227
-
228
- if (!select) {
229
- return false;
230
- }
231
-
232
-
233
- handler = function() {
234
- var i = 0,
235
- j = 0,
236
- hiddenFieldsLength = hiddenFields.length,
237
- hide = false,
238
- field = null,
239
- fieldRow = null,
240
- validatorsCount = null;
241
-
242
- hide = selectHideValues.indexOf(select.getValue()) >= 0;
243
- for (i = 0; i < hiddenFieldsLength; i += 1) {
244
- field = $(hiddenFields[i].id);
245
- if (!field) {
246
- continue;
247
- }
248
-
249
- fieldRow = that.getElementRow(hiddenFields[i].id);
250
- if (!fieldRow) {
251
- continue;
252
- }
253
-
254
- if (hide) {
255
- fieldRow.hide();
256
- field.removeClassName('required-entry');
257
- for (j = 0, validatorsCount = hiddenFields[i].validation.length; j < validatorsCount; j += 1) {
258
- field.removeClassName(hiddenFields[i].validation[j]);
259
- }
260
- } else {
261
- fieldRow.show();
262
- if (hiddenFields[i].isRequired) {
263
- field.addClassName('required-entry');
264
- }
265
- for (j = 0, validatorsCount = hiddenFields[i].validation.length; j < validatorsCount; j += 1) {
266
- field.addClassName(hiddenFields[i].validation[j]);
267
- }
268
- if (hiddenFields[i].onShow) {
269
- hiddenFields[i].onShow();
270
- }
271
- that.executeSelectorEventHandlers();
272
- }
273
- }
274
-
275
- }
276
-
277
-
278
- handler();
279
-
280
- select.observe('change', handler);
281
-
282
- return true;
283
-
284
- },
285
-
286
- executeSelectorEventHandlers: function() {
287
- var i = 0,
288
- count = selectorEventHandlers.length;
289
- for (i = 0; i < count; i += 1) {
290
- selectorEventHandlers[i]();
291
- }
292
- },
293
-
294
- getLabelForId: function (id) {
295
- var labels = $$('label[for=\"' + id +'\"]');
296
- if (labels.length > 0) {
297
- return labels[0];
298
- } else {
299
- return false;
300
- }
301
- },
302
-
303
- getElementRow: function(id) {
304
- if ($(id)) {
305
- return $(id).up('tr');
306
- } else {
307
- return false;
308
- }
309
- },
310
-
311
- getNoteForId: function(id) {
312
- var row = this.getElementRow(id);
313
- if (!row) {
314
- return false;
315
- }
316
- note = row.down('p.note span');
317
- return note ? note : false;
318
- }
319
-
320
-
321
-
322
-
323
- }
324
- })().init();";
325
-
326
- }
327
-
328
- public function getHeaderText()
329
- {
330
- $tablerate = Mage::registry('tablerate_data');
331
- if ($tablerate && $tablerate->getId()) {
332
- return Mage::helper('zitec_tablerates')->__('Edit Rate');
333
- } else {
334
- return Mage::helper('zitec_tablerates')->__('New Rate');
335
- }
336
- }
337
-
338
- public function getBackUrl()
339
- {
340
- return $this->getUrl('*/*/', array("carrier" => $this->_getHelper()->getCarrierCode()));
341
- }
342
-
343
- public function getDeleteUrl()
344
- {
345
- return $this->getUrl('*/*/delete', array($this->_objectId => $this->getRequest()->getParam($this->_objectId), "carrier" => $this->_getHelper()->getCarrierCode()));
346
- }
347
-
348
- /**
349
- *
350
- * @return Zitec_TableRates_Helper_Data
351
- */
352
- protected function _getHelper()
353
- {
354
- return Mage::helper('zitec_tablerates');
355
- }
356
-
357
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_TableRates_Block_Adminhtml_Tablerate_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
25
+ {
26
+
27
+ /**
28
+ *
29
+ * @var array
30
+ */
31
+ public function __construct()
32
+ {
33
+ $this->_objectId = 'tablerate_id';
34
+ $this->_blockGroup = 'zitec_tablerates';
35
+ $this->_controller = 'adminhtml_tablerate';
36
+ $model = Mage::registry('tablerate_data');
37
+ /* @var $model Zitec_TableRates_Model_Tablerate */
38
+ parent::__construct();
39
+
40
+ $this->_updateButton('save', 'label', Mage::helper('zitec_tablerates')->__('Save'));
41
+ if ($model->getId()) {
42
+ $this->_updateButton('delete', 'label', Mage::helper('zitec_tablerates')->__('Delete'));
43
+
44
+ $this->_addButton('duplicate', array(
45
+ 'label' => Mage::helper('zitec_tablerates')->__('Duplicate'),
46
+ 'class' => 'add',
47
+ 'onclick' => "zitecDpdDuplicate()",
48
+
49
+ ));
50
+ } else {
51
+ $this->_removeButton('delete');
52
+ }
53
+
54
+ $json = Mage::helper('zitec_tablerates/directory')->getRegionJson2();
55
+
56
+ $this->_formScripts[] = "function zitecDpdDuplicate() {
57
+ if ($('tablerate_id') && $('edit_form')) {
58
+ $('edit_form').action = $('edit_form').action + 'duplicate/1';
59
+ editForm.submit();
60
+ }
61
+
62
+
63
+ }";
64
+ $this->_formScripts[] = "var updater = new RegionUpdater('{$model->getMappedName('dest_country_id')}', 'none', '{$model->getMappedName('dest_region_id')}', $json, 'disable'); ";
65
+ $this->_formScripts[] = "
66
+ (function() {
67
+ var WEIGHT_AND_ABOVE_LABEL = '{$this->_getHelper()->__("Weight (and above)")}';
68
+ var PRICE_AND_ABOVE_LABEL = '{$this->_getHelper()->__("Price (and above)")}';
69
+
70
+ var SHIPPING_PRICE_LABEL = '{$this->_getHelper()->__("Shipping Price")}';
71
+ var SHIPPING_PERCENTAGE_LABEL = '{$this->_getHelper()->__("Shipping Percentage")}';
72
+ var SHIPPING_FIXED_AMOUNT_LABEL = '{$this->_getHelper()->__("Add fixed amount to price")}';
73
+
74
+ var COD_SURCHARGE_FIXED_LABEL = '{$this->_getHelper()->__("Fixed Cash On Delivery Surcharge Amount")}';
75
+ var COD_SURCHARGE_PERCENTAGE_LABEL = '{$this->_getHelper()->__("Cash On Delivery Surcharge Percentage")}';
76
+
77
+ var COD_MIN_SURCHARGE_LABEL = '{$this->_getHelper()->__("Minimum COD Surcharge")}';
78
+
79
+ var PRICE_AND_ABOVE_NOTE = '{$this->_getHelper()->__("Enter the starting price for this rate in the base currency of website. This rate will apply to orders whose subtotal (excluding shipping) is greater or equal to this price. Only include the sales tax/VAT in this price if you have configured shipping prices to include it (see System->Configuration->Sales->Tax->Calulation Settings->Shipping Prices).")}';
80
+ var WEIGHT_AND_ABOVE_NOTE = '{$this->_getHelper()->__("Enter the starting weight in kg for this rate.")}';
81
+
82
+ var selectorEventHandlers = [];
83
+
84
+ return {
85
+
86
+
87
+ init: function() {
88
+ document.observe('dom:loaded', function() {
89
+ this.setLabelDependingOnSelect({
90
+ selector: 'price_vs_dest',
91
+ labelFor: 'weight_price',
92
+ values: {
93
+ '0': WEIGHT_AND_ABOVE_LABEL,
94
+ '1': PRICE_AND_ABOVE_LABEL
95
+ },
96
+ notes: {
97
+ '0': WEIGHT_AND_ABOVE_NOTE,
98
+ '1': PRICE_AND_ABOVE_NOTE
99
+ },
100
+ isRequired: true,
101
+ validation: ['validate-number']
102
+ });
103
+
104
+ this.setLabelDependingOnSelect({
105
+ selector: 'markup_type',
106
+ labelFor: 'price',
107
+ values: {
108
+ '0': SHIPPING_PRICE_LABEL,
109
+ '1': SHIPPING_PERCENTAGE_LABEL,
110
+ '2': SHIPPING_FIXED_AMOUNT_LABEL
111
+ },
112
+ isRequired: true,
113
+ validation: ['validate-number']
114
+ });
115
+
116
+ this.setLabelDependingOnSelect({
117
+ selector: 'cod_option',
118
+ labelFor: 'cashondelivery_surcharge',
119
+ values: {
120
+ '0': null,
121
+ '1': null,
122
+ '2': COD_SURCHARGE_FIXED_LABEL,
123
+ '3': COD_SURCHARGE_PERCENTAGE_LABEL
124
+ },
125
+ isRequired: true,
126
+ validation: ['validate-number']
127
+ });
128
+
129
+ this.setLabelDependingOnSelect({
130
+ selector: 'cod_option',
131
+ labelFor: 'cod_min_surcharge',
132
+ values: {
133
+ '0': null,
134
+ '1': null,
135
+ '2': null,
136
+ '3': COD_MIN_SURCHARGE_LABEL
137
+ },
138
+ isRequired: false,
139
+ validation: ['validate-number']
140
+ });
141
+
142
+ this.hideFieldsDependingOnSelect('shipping_method_enabled',
143
+ ['0'],
144
+ [ { 'id': 'markup_type', 'isRequired' : true, validation: []},
145
+ { 'id': 'price', 'isRequired' : true, validation: ['validate-number'], 'onShow': this.blankPricePercentage},
146
+ { 'id': 'cod_option', 'isRequired' : true, validation: []},
147
+ { 'id': 'cashondelivery_surcharge', 'isRequired' : true, validation: ['validate-number']},
148
+ { 'id': 'cod_min_surcharge', 'isRequired' : false, validation: ['validate-number']}
149
+
150
+ ]
151
+
152
+ );
153
+ }.bind(this));
154
+
155
+ },
156
+
157
+ blankPricePercentage: function() {
158
+ var value = $('price').getValue();
159
+ if (!isNaN(parseFloat(value)) && isFinite(value) && value < 0) {
160
+ $('price').setValue('');
161
+ }
162
+ },
163
+
164
+ setLabelDependingOnSelect: function(options) {
165
+ var element = $(options.labelFor),
166
+ elementRow = this.getElementRow(options.labelFor),
167
+ label = this.getLabelForId(options.labelFor),
168
+ select = $(options.selector),
169
+ note = this.getNoteForId(options.labelFor),
170
+ labelText = null,
171
+ handler = null;
172
+
173
+ if (!element || !label || !select) {
174
+ return false;
175
+ }
176
+
177
+ handler = function() {
178
+ var i = 0,
179
+ validatorsCount = options.validation.length;
180
+
181
+ labelText = options.values[select.getValue()];
182
+ if (labelText) {
183
+ if (options.isRequired) {
184
+ labelText += ' <span class=\"required\">*</span>';
185
+ element.addClassName('required-entry');
186
+ }
187
+ for (i = 0; i < validatorsCount; i += 1) {
188
+ element.addClassName(options.validation[i]);
189
+ }
190
+ label.innerHTML = labelText;
191
+ if (note && options.notes && options.notes[select.getValue()]) {
192
+ note.innerHTML = options.notes[select.getValue()];
193
+ }
194
+ if (elementRow) {
195
+ elementRow.show();
196
+ }
197
+ element.show();
198
+ label.show();
199
+ } else {
200
+ if (elementRow) {
201
+ elementRow.hide();
202
+ }
203
+ element.hide();
204
+ label.hide();
205
+ element.removeClassName('required-entry');
206
+ for (i = 0; i < validatorsCount; i += 1) {
207
+ element.removeClassName(options.validation[i]);
208
+ }
209
+ element.setValue('');
210
+ }
211
+
212
+ };
213
+
214
+ selectorEventHandlers.push(handler);
215
+
216
+ handler();
217
+
218
+ select.observe('change', handler);
219
+
220
+ return true;
221
+ },
222
+
223
+ hideFieldsDependingOnSelect: function(selectId, selectHideValues, hiddenFields) {
224
+ var select = $(selectId),
225
+ that = this,
226
+ handler = null;
227
+
228
+ if (!select) {
229
+ return false;
230
+ }
231
+
232
+
233
+ handler = function() {
234
+ var i = 0,
235
+ j = 0,
236
+ hiddenFieldsLength = hiddenFields.length,
237
+ hide = false,
238
+ field = null,
239
+ fieldRow = null,
240
+ validatorsCount = null;
241
+
242
+ hide = selectHideValues.indexOf(select.getValue()) >= 0;
243
+ for (i = 0; i < hiddenFieldsLength; i += 1) {
244
+ field = $(hiddenFields[i].id);
245
+ if (!field) {
246
+ continue;
247
+ }
248
+
249
+ fieldRow = that.getElementRow(hiddenFields[i].id);
250
+ if (!fieldRow) {
251
+ continue;
252
+ }
253
+
254
+ if (hide) {
255
+ fieldRow.hide();
256
+ field.removeClassName('required-entry');
257
+ for (j = 0, validatorsCount = hiddenFields[i].validation.length; j < validatorsCount; j += 1) {
258
+ field.removeClassName(hiddenFields[i].validation[j]);
259
+ }
260
+ } else {
261
+ fieldRow.show();
262
+ if (hiddenFields[i].isRequired) {
263
+ field.addClassName('required-entry');
264
+ }
265
+ for (j = 0, validatorsCount = hiddenFields[i].validation.length; j < validatorsCount; j += 1) {
266
+ field.addClassName(hiddenFields[i].validation[j]);
267
+ }
268
+ if (hiddenFields[i].onShow) {
269
+ hiddenFields[i].onShow();
270
+ }
271
+ that.executeSelectorEventHandlers();
272
+ }
273
+ }
274
+
275
+ }
276
+
277
+
278
+ handler();
279
+
280
+ select.observe('change', handler);
281
+
282
+ return true;
283
+
284
+ },
285
+
286
+ executeSelectorEventHandlers: function() {
287
+ var i = 0,
288
+ count = selectorEventHandlers.length;
289
+ for (i = 0; i < count; i += 1) {
290
+ selectorEventHandlers[i]();
291
+ }
292
+ },
293
+
294
+ getLabelForId: function (id) {
295
+ var labels = $$('label[for=\"' + id +'\"]');
296
+ if (labels.length > 0) {
297
+ return labels[0];
298
+ } else {
299
+ return false;
300
+ }
301
+ },
302
+
303
+ getElementRow: function(id) {
304
+ if ($(id)) {
305
+ return $(id).up('tr');
306
+ } else {
307
+ return false;
308
+ }
309
+ },
310
+
311
+ getNoteForId: function(id) {
312
+ var row = this.getElementRow(id);
313
+ if (!row) {
314
+ return false;
315
+ }
316
+ note = row.down('p.note span');
317
+ return note ? note : false;
318
+ }
319
+
320
+
321
+
322
+
323
+ }
324
+ })().init();";
325
+
326
+ }
327
+
328
+ public function getHeaderText()
329
+ {
330
+ $tablerate = Mage::registry('tablerate_data');
331
+ if ($tablerate && $tablerate->getId()) {
332
+ return Mage::helper('zitec_tablerates')->__('Edit Rate');
333
+ } else {
334
+ return Mage::helper('zitec_tablerates')->__('New Rate');
335
+ }
336
+ }
337
+
338
+ public function getBackUrl()
339
+ {
340
+ return $this->getUrl('*/*/', array("carrier" => $this->_getHelper()->getCarrierCode()));
341
+ }
342
+
343
+ public function getDeleteUrl()
344
+ {
345
+ return $this->getUrl('*/*/delete', array($this->_objectId => $this->getRequest()->getParam($this->_objectId), "carrier" => $this->_getHelper()->getCarrierCode()));
346
+ }
347
+
348
+ /**
349
+ *
350
+ * @return Zitec_TableRates_Helper_Data
351
+ */
352
+ protected function _getHelper()
353
+ {
354
+ return Mage::helper('zitec_tablerates');
355
+ }
356
+
357
  }
app/code/community/Zitec/TableRates/Block/Adminhtml/Tablerate/Edit/Form.php CHANGED
@@ -1,277 +1,277 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_TableRates_Block_Adminhtml_Tablerate_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
25
- {
26
-
27
- /**
28
- * @var array
29
- */
30
- public function __construct()
31
- {
32
- parent::__construct();
33
- }
34
-
35
- protected function _prepareForm()
36
- {
37
- $form = new Varien_Data_Form(array(
38
- 'id' => 'edit_form',
39
- 'action' => $this->getUrl('*/*/save', array('tablerate_id' => $this->getRequest()->getParam('tablerate_id'), 'carrier' => $this->_getHelper()->getCarrierCode())),
40
- 'method' => 'post',
41
- 'enctype' => 'multipart/form-data'
42
- ));
43
- $this->setForm($form);
44
- $model = Mage::registry('tablerate_data');
45
- /* @var $model Zitec_TableRates_Model_Tablerate */
46
-
47
- $fieldset = $form->addFieldset('base_fieldset', array());
48
-
49
- if ($model->getId()) {
50
- $fieldset->addField('tablerate_id', 'hidden', array(
51
- 'name' => 'pk',
52
- 'value' => $model->getMappedData('pk'),
53
- ));
54
- }
55
-
56
- $fieldset->addField('website_id', 'select', array(
57
- 'name' => 'website_id',
58
- 'label' => $this->_getHelper()->__('Website'),
59
- 'required' => true,
60
- 'value' => $model->getMappedData('website_id'),
61
- 'values' => Mage::getSingleton('zitec_tablerates/source_website')->toOptionArray()
62
- ));
63
-
64
- $destCountryId = $model->getMappedData('dest_country_id');
65
- $fieldset->addField('dest_country_id', 'select', array(
66
- 'name' => 'dest_country_id',
67
- 'label' => $this->_getHelper()->__('Dest Country'),
68
- 'required' => false,
69
- 'value' => $destCountryId,
70
- 'values' => $this->getCountryValues()
71
- ));
72
-
73
-
74
- $fieldset->addField('dest_zip', 'text', array(
75
- 'name' => 'dest_zip',
76
- 'label' => $this->_getHelper()->__('Dest Zip/Postal Code'),
77
- 'note' => $this->_getHelper()->__('* or blank - matches any'),
78
- 'required' => false,
79
- 'value' => $model->getMappedData('dest_zip')
80
- ));
81
-
82
- $fieldset->addField('method', 'select', array(
83
- 'name' => 'method',
84
- 'label' => $this->_getHelper()->__('Service'),
85
- 'required' => true,
86
- 'value' => $model->getMappedData('method'),
87
- 'values' => $this->_getHelper()->getMethodOptions(),
88
- 'note' => $this->_getHelper()->__('For rates with this service to be available, you must enable the service from the configuration panel of the shipping method in System->Configuration->Shipping Methods')
89
- ));
90
-
91
- if ($this->_getHelper()->supportsProduct()) {
92
- $fieldset->addField('product', 'select', array(
93
- 'name' => 'product',
94
- 'label' => $this->_getHelper()->__('Product'),
95
- 'required' => true,
96
- 'value' => $model->getMappedData('product'),
97
- 'values' => $this->_getHelper()->getProductOptions(),
98
- 'note' => $this->_getHelper()->__('For rates with this product to be available, you must enable the product from the configuration panel of the shipping method in System->Configuration->Shipping Methods')
99
- ));
100
- }
101
-
102
- if ($this->_getHelper()->supportsPriceVsDest()) {
103
- $fieldset->addField('price_vs_dest', 'select', array(
104
- 'name' => 'price_vs_dest',
105
- 'label' => $this->_getHelper()->__('Condition'),
106
- 'required' => true,
107
- 'value' => $model->getMappedData('price_vs_dest'),
108
- 'values' => array('0' => $this->_getHelper()->__("Weight vs. Destination"), '1' => $this->_getHelper()->__('Price vs. Destination')),
109
- ));
110
- }
111
-
112
-
113
- $fieldset->addField('weight_price', 'text', array(
114
- 'name' => 'weight_price',
115
- 'label' => $this->_getHelper()->__('Weight (and above)'),
116
- 'required' => true,
117
- 'class' => 'validate-number',
118
- 'value' => $model->getMappedData('weight_price'),
119
- 'note' => $this->_getHelper()->__("Enter the starting weight in kg for this rate.")
120
- ));
121
-
122
- $fieldset->addField('shipping_method_enabled', 'select', array(
123
- 'name' => 'shipping_method_enabled',
124
- 'label' => $this->_getHelper()->__('Enable Shipping Method'),
125
- 'required' => true,
126
- 'value' => ($model->getMappedData('price') >= 0 ? '1' : '0'),
127
- 'values' => array('0' => $this->_getHelper()->__('Disabled'), '1' => $this->_getHelper()->__('Enabled')),
128
- 'note' => $this->_getHelper()->__('Disable the shipping method if you would like it to be unavailable for orders whose price or weight is greater or equal to the value you have indicated.')
129
- ));
130
-
131
- if ($this->_getHelper()->supportsMarkup()) {
132
- $fieldset->addField('markup_type', 'select', array(
133
- 'name' => 'markup_type',
134
- 'label' => $this->_getHelper()->__('Shipping Price Calculation'),
135
- 'required' => true,
136
- 'value' => $model->getMappedData('markup_type'),
137
- 'values' => array('0' => $this->_getHelper()->__("Fixed Price"), '1' => $this->_getHelper()->__('Add Percentage'), '2' => $this->_getHelper()->__('Add Fixed amount')),
138
- 'note' => $this->_getHelper()->__("Use 'Add Percentage' if you want to calculate the shipping price by adding a percentage to price charged by the shipping carrier.")
139
- ));
140
- }
141
-
142
- $fieldset->addField('price', 'text', array(
143
- 'name' => 'price',
144
- 'label' => $this->_getHelper()->__('Shipping Price'),
145
- 'required' => true,
146
- 'value' => $model->getMappedData('price'),
147
- 'class' => 'validate-number'
148
- ));
149
-
150
- if ($this->_getHelper()->supportsCashOnDelivery()) {
151
- $codOption = $model->getCashOnDeliverySurchargeOption();
152
- $fieldset->addField('cod_option', 'select', array(
153
- 'name' => 'cod_option',
154
- 'label' => $this->_getHelper()->__('Cash On Delivery Surcharge Calculation'),
155
- 'required' => true,
156
- 'value' => $codOption,
157
- 'values' => array(
158
- Zitec_TableRates_Model_Tablerate::COD_NOT_AVAILABLE => $this->_getHelper()->__("Cash On Delivery Not Available"),
159
- Zitec_TableRates_Model_Tablerate::COD_SURCHARGE_ZERO => $this->_getHelper()->__("Zero Surcharge"),
160
- Zitec_TableRates_Model_Tablerate::COD_SURCHARGE_FIXED => $this->_getHelper()->__('Fixed Surcharge'),
161
- Zitec_TableRates_Model_Tablerate::COD_SURCHARGE_PERCENTAGE => $this->_getHelper()->__('Percentage Surcharge')
162
- ),
163
- ));
164
-
165
-
166
- $fieldset->addField('cashondelivery_surcharge', 'text', array(
167
- 'name' => 'cashondelivery_surcharge',
168
- 'label' => $this->_getHelper()->__('Fixed Cash On Delivery Surcharge'),
169
- 'required' => true,
170
- 'value' => $codOption == Zitec_TableRates_Model_Tablerate::COD_SURCHARGE_PERCENTAGE ? $model->getData('cod_surcharge_percentage') : $model->getData('cod_surcharge_price'),
171
- 'class' => 'validate-number',
172
- ));
173
-
174
- if ($this->_getHelper()->supportsCodMinSurcharge()) {
175
- $fieldset->addField('cod_min_surcharge', 'text', array(
176
- 'name' => 'cod_min_surcharge',
177
- 'label' => $this->_getHelper()->__('Minimum COD Surcharge'),
178
- 'required' => false,
179
- 'value' => $model->getMappedData('cod_min_surcharge'),
180
- 'class' => 'validate-number',
181
- 'note' => $this->_getHelper()->__('Optionally specify the minimum COD surcharge.')
182
- ));
183
- }
184
- }
185
-
186
-
187
- $sessionData = $this->_getSessionFormData();
188
- if (is_array($sessionData)) {
189
- $form->setValues($sessionData);
190
- $destRegionId = array_key_exists('dest_region_id', $sessionData) ? $sessionData['dest_region_id'] : null;
191
- $destCountryId = array_key_exists('dest_country_id', $sessionData) ? $sessionData['dest_country_id'] : null;
192
- $this->_clearSessionFormData();
193
- } else {
194
- $destRegionId = $model->getMappedData('dest_region_id');
195
- }
196
-
197
- $fieldset->addField('dest_region_id', 'select', array(
198
- 'name' => 'dest_region_id',
199
- 'label' => $this->_getHelper()->__('Dest Region/State'),
200
- 'required' => false,
201
- 'value' => $destRegionId,
202
- 'values' => $this->getRegionValues($destCountryId),
203
- ), 'dest_country_id');
204
-
205
- $form->setUseContainer(true);
206
-
207
- return parent::_prepareForm();
208
- }
209
-
210
- /**
211
- *
212
- * @return array
213
- */
214
- protected function _getSessionFormData()
215
- {
216
- return Mage::getSingleton('adminhtml/session')->getTablerateData();
217
- }
218
-
219
- /**
220
- *
221
- * @return \Zitec_TableRates_Block_Adminhtml_Tablerate_Edit_Form
222
- */
223
- protected function _clearSessionFormData()
224
- {
225
- Mage::getSingleton('adminhtml/session')->setTablerateData(null);
226
-
227
- return $this;
228
- }
229
-
230
- /**
231
- * Get country values
232
- *
233
- * @return array
234
- */
235
- protected function getCountryValues()
236
- {
237
- $countries = Mage::getModel('adminhtml/system_config_source_country')->toOptionArray(false);
238
- if (isset($countries[0])) {
239
- $countries[0] = array('label' => '*', 'value' => 0);
240
- }
241
-
242
- return $countries;
243
- }
244
-
245
- /**
246
- * Get region values
247
- *
248
- * @return array
249
- */
250
- protected function getRegionValues($destCountryId = null)
251
- {
252
- $regions = array(array('value' => '', 'label' => '*'));
253
- $model = Mage::registry('tablerate_data');
254
- $destCountryId = isset($destCountryId) ? $destCountryId : $model->getDestCountryId();
255
- if ($destCountryId) {
256
- $regionCollection = Mage::getModel('directory/region')
257
- ->getCollection()
258
- ->addCountryFilter($destCountryId);
259
- $regions = $regionCollection->toOptionArray();
260
- if (isset($regions[0])) {
261
- $regions[0]['label'] = '*';
262
- }
263
- }
264
-
265
- return $regions;
266
- }
267
-
268
- /**
269
- *
270
- * @return Zitec_TableRates_Helper_Data
271
- */
272
- protected function _getHelper()
273
- {
274
- return Mage::helper('zitec_tablerates');
275
- }
276
-
277
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_TableRates_Block_Adminhtml_Tablerate_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
25
+ {
26
+
27
+ /**
28
+ * @var array
29
+ */
30
+ public function __construct()
31
+ {
32
+ parent::__construct();
33
+ }
34
+
35
+ protected function _prepareForm()
36
+ {
37
+ $form = new Varien_Data_Form(array(
38
+ 'id' => 'edit_form',
39
+ 'action' => $this->getUrl('*/*/save', array('tablerate_id' => $this->getRequest()->getParam('tablerate_id'), 'carrier' => $this->_getHelper()->getCarrierCode())),
40
+ 'method' => 'post',
41
+ 'enctype' => 'multipart/form-data'
42
+ ));
43
+ $this->setForm($form);
44
+ $model = Mage::registry('tablerate_data');
45
+ /* @var $model Zitec_TableRates_Model_Tablerate */
46
+
47
+ $fieldset = $form->addFieldset('base_fieldset', array());
48
+
49
+ if ($model->getId()) {
50
+ $fieldset->addField('tablerate_id', 'hidden', array(
51
+ 'name' => 'pk',
52
+ 'value' => $model->getMappedData('pk'),
53
+ ));
54
+ }
55
+
56
+ $fieldset->addField('website_id', 'select', array(
57
+ 'name' => 'website_id',
58
+ 'label' => $this->_getHelper()->__('Website'),
59
+ 'required' => true,
60
+ 'value' => $model->getMappedData('website_id'),
61
+ 'values' => Mage::getSingleton('zitec_tablerates/source_website')->toOptionArray()
62
+ ));
63
+
64
+ $destCountryId = $model->getMappedData('dest_country_id');
65
+ $fieldset->addField('dest_country_id', 'select', array(
66
+ 'name' => 'dest_country_id',
67
+ 'label' => $this->_getHelper()->__('Dest Country'),
68
+ 'required' => false,
69
+ 'value' => $destCountryId,
70
+ 'values' => $this->getCountryValues()
71
+ ));
72
+
73
+
74
+ $fieldset->addField('dest_zip', 'text', array(
75
+ 'name' => 'dest_zip',
76
+ 'label' => $this->_getHelper()->__('Dest Zip/Postal Code'),
77
+ 'note' => $this->_getHelper()->__('* or blank - matches any'),
78
+ 'required' => false,
79
+ 'value' => $model->getMappedData('dest_zip')
80
+ ));
81
+
82
+ $fieldset->addField('method', 'select', array(
83
+ 'name' => 'method',
84
+ 'label' => $this->_getHelper()->__('Service'),
85
+ 'required' => true,
86
+ 'value' => $model->getMappedData('method'),
87
+ 'values' => $this->_getHelper()->getMethodOptions(),
88
+ 'note' => $this->_getHelper()->__('For rates with this service to be available, you must enable the service from the configuration panel of the shipping method in System->Configuration->Shipping Methods')
89
+ ));
90
+
91
+ if ($this->_getHelper()->supportsProduct()) {
92
+ $fieldset->addField('product', 'select', array(
93
+ 'name' => 'product',
94
+ 'label' => $this->_getHelper()->__('Product'),
95
+ 'required' => true,
96
+ 'value' => $model->getMappedData('product'),
97
+ 'values' => $this->_getHelper()->getProductOptions(),
98
+ 'note' => $this->_getHelper()->__('For rates with this product to be available, you must enable the product from the configuration panel of the shipping method in System->Configuration->Shipping Methods')
99
+ ));
100
+ }
101
+
102
+ if ($this->_getHelper()->supportsPriceVsDest()) {
103
+ $fieldset->addField('price_vs_dest', 'select', array(
104
+ 'name' => 'price_vs_dest',
105
+ 'label' => $this->_getHelper()->__('Condition'),
106
+ 'required' => true,
107
+ 'value' => $model->getMappedData('price_vs_dest'),
108
+ 'values' => array('0' => $this->_getHelper()->__("Weight vs. Destination"), '1' => $this->_getHelper()->__('Price vs. Destination')),
109
+ ));
110
+ }
111
+
112
+
113
+ $fieldset->addField('weight_price', 'text', array(
114
+ 'name' => 'weight_price',
115
+ 'label' => $this->_getHelper()->__('Weight (and above)'),
116
+ 'required' => true,
117
+ 'class' => 'validate-number',
118
+ 'value' => $model->getMappedData('weight_price'),
119
+ 'note' => $this->_getHelper()->__("Enter the starting weight in kg for this rate.")
120
+ ));
121
+
122
+ $fieldset->addField('shipping_method_enabled', 'select', array(
123
+ 'name' => 'shipping_method_enabled',
124
+ 'label' => $this->_getHelper()->__('Enable Shipping Method'),
125
+ 'required' => true,
126
+ 'value' => ($model->getMappedData('price') >= 0 ? '1' : '0'),
127
+ 'values' => array('0' => $this->_getHelper()->__('Disabled'), '1' => $this->_getHelper()->__('Enabled')),
128
+ 'note' => $this->_getHelper()->__('Disable the shipping method if you would like it to be unavailable for orders whose price or weight is greater or equal to the value you have indicated.')
129
+ ));
130
+
131
+ if ($this->_getHelper()->supportsMarkup()) {
132
+ $fieldset->addField('markup_type', 'select', array(
133
+ 'name' => 'markup_type',
134
+ 'label' => $this->_getHelper()->__('Shipping Price Calculation'),
135
+ 'required' => true,
136
+ 'value' => $model->getMappedData('markup_type'),
137
+ 'values' => array('0' => $this->_getHelper()->__("Fixed Price"), '1' => $this->_getHelper()->__('Add Percentage'), '2' => $this->_getHelper()->__('Add Fixed amount')),
138
+ 'note' => $this->_getHelper()->__("Use 'Add Percentage' if you want to calculate the shipping price by adding a percentage to price charged by the shipping carrier.")
139
+ ));
140
+ }
141
+
142
+ $fieldset->addField('price', 'text', array(
143
+ 'name' => 'price',
144
+ 'label' => $this->_getHelper()->__('Shipping Price'),
145
+ 'required' => true,
146
+ 'value' => $model->getMappedData('price'),
147
+ 'class' => 'validate-number'
148
+ ));
149
+
150
+ if ($this->_getHelper()->supportsCashOnDelivery()) {
151
+ $codOption = $model->getCashOnDeliverySurchargeOption();
152
+ $fieldset->addField('cod_option', 'select', array(
153
+ 'name' => 'cod_option',
154
+ 'label' => $this->_getHelper()->__('Cash On Delivery Surcharge Calculation'),
155
+ 'required' => true,
156
+ 'value' => $codOption,
157
+ 'values' => array(
158
+ Zitec_TableRates_Model_Tablerate::COD_NOT_AVAILABLE => $this->_getHelper()->__("Cash On Delivery Not Available"),
159
+ Zitec_TableRates_Model_Tablerate::COD_SURCHARGE_ZERO => $this->_getHelper()->__("Zero Surcharge"),
160
+ Zitec_TableRates_Model_Tablerate::COD_SURCHARGE_FIXED => $this->_getHelper()->__('Fixed Surcharge'),
161
+ Zitec_TableRates_Model_Tablerate::COD_SURCHARGE_PERCENTAGE => $this->_getHelper()->__('Percentage Surcharge')
162
+ ),
163
+ ));
164
+
165
+
166
+ $fieldset->addField('cashondelivery_surcharge', 'text', array(
167
+ 'name' => 'cashondelivery_surcharge',
168
+ 'label' => $this->_getHelper()->__('Fixed Cash On Delivery Surcharge'),
169
+ 'required' => true,
170
+ 'value' => $codOption == Zitec_TableRates_Model_Tablerate::COD_SURCHARGE_PERCENTAGE ? $model->getData('cod_surcharge_percentage') : $model->getData('cod_surcharge_price'),
171
+ 'class' => 'validate-number',
172
+ ));
173
+
174
+ if ($this->_getHelper()->supportsCodMinSurcharge()) {
175
+ $fieldset->addField('cod_min_surcharge', 'text', array(
176
+ 'name' => 'cod_min_surcharge',
177
+ 'label' => $this->_getHelper()->__('Minimum COD Surcharge'),
178
+ 'required' => false,
179
+ 'value' => $model->getMappedData('cod_min_surcharge'),
180
+ 'class' => 'validate-number',
181
+ 'note' => $this->_getHelper()->__('Optionally specify the minimum COD surcharge.')
182
+ ));
183
+ }
184
+ }
185
+
186
+
187
+ $sessionData = $this->_getSessionFormData();
188
+ if (is_array($sessionData)) {
189
+ $form->setValues($sessionData);
190
+ $destRegionId = array_key_exists('dest_region_id', $sessionData) ? $sessionData['dest_region_id'] : null;
191
+ $destCountryId = array_key_exists('dest_country_id', $sessionData) ? $sessionData['dest_country_id'] : null;
192
+ $this->_clearSessionFormData();
193
+ } else {
194
+ $destRegionId = $model->getMappedData('dest_region_id');
195
+ }
196
+
197
+ $fieldset->addField('dest_region_id', 'select', array(
198
+ 'name' => 'dest_region_id',
199
+ 'label' => $this->_getHelper()->__('Dest Region/State'),
200
+ 'required' => false,
201
+ 'value' => $destRegionId,
202
+ 'values' => $this->getRegionValues($destCountryId),
203
+ ), 'dest_country_id');
204
+
205
+ $form->setUseContainer(true);
206
+
207
+ return parent::_prepareForm();
208
+ }
209
+
210
+ /**
211
+ *
212
+ * @return array
213
+ */
214
+ protected function _getSessionFormData()
215
+ {
216
+ return Mage::getSingleton('adminhtml/session')->getTablerateData();
217
+ }
218
+
219
+ /**
220
+ *
221
+ * @return \Zitec_TableRates_Block_Adminhtml_Tablerate_Edit_Form
222
+ */
223
+ protected function _clearSessionFormData()
224
+ {
225
+ Mage::getSingleton('adminhtml/session')->setTablerateData(null);
226
+
227
+ return $this;
228
+ }
229
+
230
+ /**
231
+ * Get country values
232
+ *
233
+ * @return array
234
+ */
235
+ protected function getCountryValues()
236
+ {
237
+ $countries = Mage::getModel('adminhtml/system_config_source_country')->toOptionArray(false);
238
+ if (isset($countries[0])) {
239
+ $countries[0] = array('label' => '*', 'value' => 0);
240
+ }
241
+
242
+ return $countries;
243
+ }
244
+
245
+ /**
246
+ * Get region values
247
+ *
248
+ * @return array
249
+ */
250
+ protected function getRegionValues($destCountryId = null)
251
+ {
252
+ $regions = array(array('value' => '', 'label' => '*'));
253
+ $model = Mage::registry('tablerate_data');
254
+ $destCountryId = isset($destCountryId) ? $destCountryId : $model->getDestCountryId();
255
+ if ($destCountryId) {
256
+ $regionCollection = Mage::getModel('directory/region')
257
+ ->getCollection()
258
+ ->addCountryFilter($destCountryId);
259
+ $regions = $regionCollection->toOptionArray();
260
+ if (isset($regions[0])) {
261
+ $regions[0]['label'] = '*';
262
+ }
263
+ }
264
+
265
+ return $regions;
266
+ }
267
+
268
+ /**
269
+ *
270
+ * @return Zitec_TableRates_Helper_Data
271
+ */
272
+ protected function _getHelper()
273
+ {
274
+ return Mage::helper('zitec_tablerates');
275
+ }
276
+
277
  }
app/code/community/Zitec/TableRates/Block/Adminhtml/Tablerate/Export.php CHANGED
@@ -1,62 +1,62 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_TableRates_Block_Adminhtml_Tablerate_Export extends Mage_Adminhtml_Block_Widget_Form_Container
25
- {
26
-
27
- public function __construct()
28
- {
29
- $this->_objectId = 'tablerate_id';
30
- $this->_blockGroup = 'zitec_tablerates';
31
- $this->_controller = 'adminhtml_tablerate';
32
- $this->_mode = 'export';
33
- parent::__construct();
34
-
35
- $this->_updateButton('save', 'label', Mage::helper('zitec_tablerates')->__('Export'));
36
- $this->_removeButton('delete');
37
- $this->_removeButton('reset');
38
- }
39
-
40
- public function getHeaderText()
41
- {
42
- return $this->_getHelper()->__('Export') . ' ' . $this->_getHelper()->getGridTitle();
43
- }
44
-
45
- public function getBackUrl()
46
- {
47
- return $this->getUrl('*/*/', array("carrier" => $this->_getHelper()->getCarrierCode()));
48
- }
49
-
50
-
51
- /**
52
- *
53
- * @return Zitec_TableRates_Helper_Data
54
- */
55
- protected function _getHelper()
56
- {
57
- return Mage::helper('zitec_tablerates');
58
- }
59
-
60
-
61
- }
62
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_TableRates_Block_Adminhtml_Tablerate_Export extends Mage_Adminhtml_Block_Widget_Form_Container
25
+ {
26
+
27
+ public function __construct()
28
+ {
29
+ $this->_objectId = 'tablerate_id';
30
+ $this->_blockGroup = 'zitec_tablerates';
31
+ $this->_controller = 'adminhtml_tablerate';
32
+ $this->_mode = 'export';
33
+ parent::__construct();
34
+
35
+ $this->_updateButton('save', 'label', Mage::helper('zitec_tablerates')->__('Export'));
36
+ $this->_removeButton('delete');
37
+ $this->_removeButton('reset');
38
+ }
39
+
40
+ public function getHeaderText()
41
+ {
42
+ return $this->_getHelper()->__('Export') . ' ' . $this->_getHelper()->getGridTitle();
43
+ }
44
+
45
+ public function getBackUrl()
46
+ {
47
+ return $this->getUrl('*/*/', array("carrier" => $this->_getHelper()->getCarrierCode()));
48
+ }
49
+
50
+
51
+ /**
52
+ *
53
+ * @return Zitec_TableRates_Helper_Data
54
+ */
55
+ protected function _getHelper()
56
+ {
57
+ return Mage::helper('zitec_tablerates');
58
+ }
59
+
60
+
61
+ }
62
+
app/code/community/Zitec/TableRates/Block/Adminhtml/Tablerate/Export/Form.php CHANGED
@@ -1,75 +1,75 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_TableRates_Block_Adminhtml_Tablerate_Export_Form extends Mage_Adminhtml_Block_Widget_Form
25
- {
26
- /**
27
- * @var array
28
- */
29
- public function __construct()
30
- {
31
- parent::__construct();
32
- }
33
-
34
- protected function _prepareForm()
35
- {
36
- $form = new Varien_Data_Form(array(
37
- 'id' => 'edit_form',
38
- 'action' => $this->getUrl('*/*/exportrates', array('tablerate_id' => $this->getRequest()->getParam('tablerate_id'), 'carrier' => $this->_getHelper()->getCarrierCode())),
39
- 'method' => 'post',
40
- 'enctype' => 'multipart/form-data'
41
- ));
42
- $this->setForm($form);
43
-
44
-
45
- $fieldset = $form->addFieldset('base_fieldset', array());
46
-
47
- $fieldset->addField('website_id', 'select', array(
48
- 'name' => 'website_id',
49
- 'label' => $this->_getHelper()->__('Website'),
50
- 'values' => Mage::getSingleton('zitec_tablerates/source_website')->toOptionArray(),
51
- 'required' => true
52
- ));
53
-
54
-
55
- $form->setUseContainer(true);
56
-
57
- return parent::_prepareForm();
58
- }
59
-
60
- public function getExportUrl()
61
- {
62
- return $this->getUrl('*/*/exportrates', array("carrier" => $this->_getHelper()->getCarrierCode()));
63
- }
64
-
65
- /**
66
- *
67
- * @return Zitec_TableRates_Helper_Data
68
- */
69
- protected function _getHelper()
70
- {
71
- return Mage::helper('zitec_tablerates');
72
- }
73
-
74
- }
75
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_TableRates_Block_Adminhtml_Tablerate_Export_Form extends Mage_Adminhtml_Block_Widget_Form
25
+ {
26
+ /**
27
+ * @var array
28
+ */
29
+ public function __construct()
30
+ {
31
+ parent::__construct();
32
+ }
33
+
34
+ protected function _prepareForm()
35
+ {
36
+ $form = new Varien_Data_Form(array(
37
+ 'id' => 'edit_form',
38
+ 'action' => $this->getUrl('*/*/exportrates', array('tablerate_id' => $this->getRequest()->getParam('tablerate_id'), 'carrier' => $this->_getHelper()->getCarrierCode())),
39
+ 'method' => 'post',
40
+ 'enctype' => 'multipart/form-data'
41
+ ));
42
+ $this->setForm($form);
43
+
44
+
45
+ $fieldset = $form->addFieldset('base_fieldset', array());
46
+
47
+ $fieldset->addField('website_id', 'select', array(
48
+ 'name' => 'website_id',
49
+ 'label' => $this->_getHelper()->__('Website'),
50
+ 'values' => Mage::getSingleton('zitec_tablerates/source_website')->toOptionArray(),
51
+ 'required' => true
52
+ ));
53
+
54
+
55
+ $form->setUseContainer(true);
56
+
57
+ return parent::_prepareForm();
58
+ }
59
+
60
+ public function getExportUrl()
61
+ {
62
+ return $this->getUrl('*/*/exportrates', array("carrier" => $this->_getHelper()->getCarrierCode()));
63
+ }
64
+
65
+ /**
66
+ *
67
+ * @return Zitec_TableRates_Helper_Data
68
+ */
69
+ protected function _getHelper()
70
+ {
71
+ return Mage::helper('zitec_tablerates');
72
+ }
73
+
74
+ }
75
+
app/code/community/Zitec/TableRates/Block/Adminhtml/Tablerate/Grid.php CHANGED
@@ -1,351 +1,351 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_TableRates_Block_Adminhtml_Tablerate_Grid extends Mage_Adminhtml_Block_Widget_Grid
25
- {
26
-
27
- /**
28
- *
29
- * @var array
30
- */
31
- protected $_map = null;
32
-
33
- public function __construct()
34
- {
35
- parent::__construct();
36
- $this->_map = Zitec_TableRates_Model_Mysql4_Tablerate::getLogicalDbFieldNamesMap();
37
- $this->setId('zitec_tablerates_tablerateGrid');
38
- $this->setDefaultSort($this->_map['pk']);
39
- $this->setDefaultDir('DESC');
40
- $this->setSaveParametersInSession(true);
41
- $this->setUseAjax(true);
42
- }
43
-
44
- protected function _prepareCollection()
45
- {
46
- $collection = Mage::getModel('zitec_tablerates/tablerate')->getCollection();
47
- $this->setCollection($collection);
48
-
49
- return parent::_prepareCollection();
50
- }
51
-
52
- protected function _prepareColumns()
53
- {
54
-
55
- $store = $this->_getStore();
56
-
57
- $this->addColumn('tablerate_id', array(
58
- 'header' => $this->_getHelper()->__('ID'),
59
- 'align' => 'right',
60
- 'width' => '50px',
61
- 'index' => $this->_map['pk'],
62
- ));
63
-
64
-
65
- $this->addColumn('website', array(
66
- 'header' => $this->_getHelper()->__('Website'),
67
- 'index' => $this->_map['website_id'],
68
- 'default' => '',
69
- 'type' => 'options',
70
- 'options' => Mage::getSingleton('zitec_tablerates/source_website')->getWebsites(),
71
- 'filter_index' => "main_table.{$this->_map['website_id']}"
72
- ));
73
-
74
-
75
- $this->addColumn('dest_country_id', array(
76
- 'header' => $this->_getHelper()->__('Destination Country'),
77
- 'align' => 'left',
78
- 'index' => $this->_map['dest_country_id'],
79
- 'filter_index' => "main_table.{$this->_map['dest_country_id']}",
80
- 'type' => 'options',
81
- 'options' => $this->getCountryOptions(),
82
- ));
83
-
84
- $this->addColumn('dest_region', array(
85
- 'header' => $this->_getHelper()->__('Dest Region/State'),
86
- 'align' => 'left',
87
- 'index' => 'dest_region_name',
88
- 'filter_index' => 'region_table.default_name',
89
- 'filter' => 'zitec_tablerates/adminhtml_widget_grid_column_filter_region',
90
- 'default' => '*',
91
- ));
92
-
93
-
94
- $this->addColumn('dest_zip', array(
95
- 'header' => $this->_getHelper()->__('Destination Zip/Postal Code'),
96
- 'align' => 'left',
97
- 'index' => $this->_map['dest_zip'],
98
- 'default' => '*',
99
- ));
100
-
101
- $this->addColumn('method', array(
102
- 'header' => $this->_getHelper()->__('Service'),
103
- 'align' => 'left',
104
- 'index' => $this->_map['method'],
105
- 'filter_index' => "main_table.{$this->_map['method']}",
106
- 'type' => 'options',
107
- 'options' => $this->_getHelper()->getMethodOptions(),
108
- 'width' => 150,
109
- ));
110
-
111
- if ($this->_getHelper()->supportsProduct()) {
112
- $this->addColumn('product', array(
113
- 'header' => $this->_getHelper()->__('Product'),
114
- 'align' => 'left',
115
- 'index' => $this->_map['product'],
116
- 'filter_index' => "main_table.{$this->_map['product']}",
117
- 'type' => 'options',
118
- 'options' => $this->_getHelper()->getProductOptions(),
119
- 'width' => 150,
120
- ));
121
- }
122
-
123
-
124
- $this->addColumn('weight_and_above', array(
125
- 'header' => $this->_getHelper()->__('Weight (and above)'),
126
- 'index' => 'weight_and_above',
127
- 'filter_condition_callback' => array($this, '_weightAndAboveFilter'),
128
- 'default' => '*',
129
- 'type' => 'number'
130
- ));
131
-
132
- if ($this->_getHelper()->supportsPriceVsDest()) {
133
- $this->addColumn('price_and_above', array(
134
- 'header' => $this->_getHelper()->__('Price (and above)'),
135
- 'align' => 'left',
136
- 'index' => 'price_and_above',
137
- 'filter_condition_callback' => array($this, '_priceAndAboveFilter'),
138
- 'type' => 'price',
139
- 'currency_code' => $store->getBaseCurrency()->getCode(),
140
- 'default' => '*',
141
- ));
142
- }
143
-
144
- $this->addColumn('is_enabled', array(
145
- 'header' => $this->_getHelper()->__('Enabled'),
146
- 'align' => 'left',
147
- 'index' => 'is_enabled_grid',
148
- 'filter' => false,
149
- 'type' => 'options',
150
- 'options' => array(0 => $this->_getHelper()->__('No'), 1 => $this->_getHelper()->__('Yes')),
151
- ));
152
-
153
- $this->addColumn('shipping_price', array(
154
- 'header' => $this->_getHelper()->__('Shipping Price'),
155
- 'align' => 'left',
156
- 'index' => 'shipping_price_grid',
157
- 'filter_index' => "main_table.{$this->_map['price']}",
158
- 'type' => 'price',
159
- 'currency_code' => $store->getBaseCurrency()->getCode(),
160
- 'default' => '',
161
- ));
162
-
163
-
164
- if ($this->_getHelper()->supportsMarkup()) {
165
- $this->addColumn('shipping_percentage', array(
166
- 'header' => $this->_getHelper()->__('Shipping Price %'),
167
- 'align' => 'left',
168
- 'index' => 'shipping_percentage_grid',
169
- 'filter_index' => "main_table.{$this->_map['price']}",
170
- 'type' => 'number',
171
- 'default' => ''
172
- ));
173
-
174
- $this->addColumn('addition_amount', array(
175
- 'header' => $this->_getHelper()->__('Addition Price'),
176
- 'align' => 'left',
177
- 'index' => 'addition_amount_grid',
178
- 'filter_index' => "main_table.{$this->_map['price']}",
179
- 'type' => 'price',
180
- 'currency_code' => $store->getBaseCurrency()->getCode(),
181
- ));
182
-
183
- }
184
-
185
-
186
- if ($this->_getHelper()->supportsCashOnDelivery()) {
187
- $this->addColumn('cod_surcharge_price', array(
188
- 'header' => $this->_getHelper()->__('COD Surcharge'),
189
- 'align' => 'left',
190
- 'index' => 'cod_surcharge_price',
191
- 'filter_index' => "main_table.{$this->_map['cashondelivery_surcharge']}",
192
- 'type' => 'price',
193
- 'currency_code' => $store->getBaseCurrency()->getCode(),
194
- ));
195
-
196
- $this->addColumn('cod_surcharge_percentage', array(
197
- 'header' => $this->_getHelper()->__('COD Surcharge %'),
198
- 'index' => 'cod_surcharge_percentage',
199
- 'filter_index' => "main_table.{$this->_map['cashondelivery_surcharge']}",
200
- 'type' => 'number',
201
- ));
202
-
203
- if ($this->_getHelper()->supportsCodMinSurcharge()) {
204
- $this->addColumn('cod_min_surcharge', array(
205
- 'header' => $this->_getHelper()->__('COD Min. Surcharge'),
206
- 'index' => $this->_map['cod_min_surcharge'],
207
- 'filter_index' => "main_table.{$this->_map['cod_min_surcharge']}",
208
- 'type' => 'price',
209
- 'currency_code' => $store->getBaseCurrency()->getCode(),
210
- ));
211
- }
212
- }
213
-
214
-
215
- return parent::_prepareColumns();
216
- }
217
-
218
- protected function _prepareMassaction()
219
- {
220
- $this->setMassactionIdField($this->_map['pk']);
221
- $this->getMassactionBlock()->setFormFieldName('tablerates');
222
- $this->getMassactionBlock()->addItem('delete', array(
223
- 'label' => $this->_getHelper()->__('Delete'),
224
- 'url' => $this->getUrl('*/*/massDelete', array("carrier" => $this->_getHelper()->getCarrierCode())),
225
- 'confirm' => $this->_getHelper()->__('Are you sure?')
226
- ));
227
-
228
- return $this;
229
- }
230
-
231
- public function getGridUrl()
232
- {
233
- return $this->getUrl('*/*/grid', array('_current' => true, '_query' => array("carrier" => $this->_getHelper()->getCarrierCode())));
234
- }
235
-
236
- public function getRowUrl($row)
237
- {
238
- return $this->getUrl('*/*/edit', array('tablerate_id' => $row->getId(), "carrier" => $this->_getHelper()->getCarrierCode()));
239
- }
240
-
241
- /**
242
- * Get country options
243
- *
244
- * @return array
245
- */
246
- public function getCountryOptions()
247
- {
248
- $options = array();
249
- $countries = Mage::getModel('adminhtml/system_config_source_country')->toOptionArray(false);
250
- if (isset($countries[0])) {
251
- $countries[0] = array('value' => '0', 'label' => '*',);
252
- }
253
- foreach ($countries as $country) {
254
- $options[$country['value']] = $country['label'];
255
- }
256
-
257
- return $options;
258
- }
259
-
260
- /**
261
- *
262
- * @param Zitec_TableRates_Model_Mysql4_Tablerate_Collection $collection
263
- * @param type Mage_Adminhtml_Block_Widget_Grid_Column
264
- *
265
- * @return \Zitec_TableRates_Block_Adminhtml_Tablerate_Grid
266
- */
267
- protected function _weightAndAboveFilter($collection, $column)
268
- {
269
- return $this->_weightPriceAndAboveFilter($collection, $column, false);
270
- }
271
-
272
- /**
273
- *
274
- * @param Zitec_TableRates_Model_Mysql4_Tablerate_Collection $collection
275
- * @param type Mage_Adminhtml_Block_Widget_Grid_Column
276
- *
277
- * @return \Zitec_TableRates_Block_Adminhtml_Tablerate_Grid
278
- */
279
- protected function _priceAndAboveFilter($collection, $column)
280
- {
281
- return $this->_weightPriceAndAboveFilter($collection, $column, true);
282
- }
283
-
284
- /**
285
- *
286
- * @param Zitec_TableRates_Model_Mysql4_Tablerate_Collection $collection
287
- * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
288
- * @param boolean $priceVsDest
289
- *
290
- * @return \Zitec_TableRates_Block_Adminhtml_Tablerate_Grid
291
- */
292
- protected function _weightPriceAndAboveFilter(Zitec_TableRates_Model_Mysql4_Tablerate_Collection $collection, Mage_Adminhtml_Block_Widget_Grid_Column $column, $priceVsDest = false)
293
- {
294
-
295
- if ($priceVsDest && !$this->_getHelper()->supportsPriceVsDest()) {
296
- return $this;
297
- }
298
-
299
- $value = $column->getFilter()->getValue();
300
- if (!is_array($value)) {
301
- return $this;
302
- }
303
-
304
-
305
- $from = isset($value['from']) ? $value['from'] : false;
306
- $to = isset($value['to']) ? $value['to'] : false;
307
-
308
- if ($from === false && $to === false) {
309
- return $this;
310
- }
311
-
312
- $select = $collection->getSelect();
313
- if ($from !== false) {
314
- $select->where(" main_table.{$this->_map['weight_price']} >= ? ", $from);
315
- }
316
-
317
-
318
- if ($to !== false) {
319
- $select->where(" main_table.{$this->_map['weight_price']} <= ? ", $to);
320
- }
321
-
322
- $select->where(" main_table.{$this->_map['price_vs_dest']} = ? ", $priceVsDest ? 1 : 0);
323
-
324
- $selectStr = (string)$select;
325
- $this->_getHelper()->log($selectStr);
326
-
327
- return $this;
328
- }
329
-
330
- /**
331
- * Get store
332
- *
333
- * @return Mage_Core_Model_Store
334
- */
335
- protected function _getStore()
336
- {
337
- $storeId = (int)$this->getRequest()->getParam('store', 0);
338
-
339
- return Mage::app()->getStore($storeId);
340
- }
341
-
342
- /**
343
- *
344
- * @return Zitec_TableRates_Helper_Data
345
- */
346
- protected function _getHelper()
347
- {
348
- return Mage::helper('zitec_tablerates');
349
- }
350
-
351
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_TableRates_Block_Adminhtml_Tablerate_Grid extends Mage_Adminhtml_Block_Widget_Grid
25
+ {
26
+
27
+ /**
28
+ *
29
+ * @var array
30
+ */
31
+ protected $_map = null;
32
+
33
+ public function __construct()
34
+ {
35
+ parent::__construct();
36
+ $this->_map = Zitec_TableRates_Model_Mysql4_Tablerate::getLogicalDbFieldNamesMap();
37
+ $this->setId('zitec_tablerates_tablerateGrid');
38
+ $this->setDefaultSort($this->_map['pk']);
39
+ $this->setDefaultDir('DESC');
40
+ $this->setSaveParametersInSession(true);
41
+ $this->setUseAjax(true);
42
+ }
43
+
44
+ protected function _prepareCollection()
45
+ {
46
+ $collection = Mage::getModel('zitec_tablerates/tablerate')->getCollection();
47
+ $this->setCollection($collection);
48
+
49
+ return parent::_prepareCollection();
50
+ }
51
+
52
+ protected function _prepareColumns()
53
+ {
54
+
55
+ $store = $this->_getStore();
56
+
57
+ $this->addColumn('tablerate_id', array(
58
+ 'header' => $this->_getHelper()->__('ID'),
59
+ 'align' => 'right',
60
+ 'width' => '50px',
61
+ 'index' => $this->_map['pk'],
62
+ ));
63
+
64
+
65
+ $this->addColumn('website', array(
66
+ 'header' => $this->_getHelper()->__('Website'),
67
+ 'index' => $this->_map['website_id'],
68
+ 'default' => '',
69
+ 'type' => 'options',
70
+ 'options' => Mage::getSingleton('zitec_tablerates/source_website')->getWebsites(),
71
+ 'filter_index' => "main_table.{$this->_map['website_id']}"
72
+ ));
73
+
74
+
75
+ $this->addColumn('dest_country_id', array(
76
+ 'header' => $this->_getHelper()->__('Destination Country'),
77
+ 'align' => 'left',
78
+ 'index' => $this->_map['dest_country_id'],
79
+ 'filter_index' => "main_table.{$this->_map['dest_country_id']}",
80
+ 'type' => 'options',
81
+ 'options' => $this->getCountryOptions(),
82
+ ));
83
+
84
+ $this->addColumn('dest_region', array(
85
+ 'header' => $this->_getHelper()->__('Dest Region/State'),
86
+ 'align' => 'left',
87
+ 'index' => 'dest_region_name',
88
+ 'filter_index' => 'region_table.default_name',
89
+ 'filter' => 'zitec_tablerates/adminhtml_widget_grid_column_filter_region',
90
+ 'default' => '*',
91
+ ));
92
+
93
+
94
+ $this->addColumn('dest_zip', array(
95
+ 'header' => $this->_getHelper()->__('Destination Zip/Postal Code'),
96
+ 'align' => 'left',
97
+ 'index' => $this->_map['dest_zip'],
98
+ 'default' => '*',
99
+ ));
100
+
101
+ $this->addColumn('method', array(
102
+ 'header' => $this->_getHelper()->__('Service'),
103
+ 'align' => 'left',
104
+ 'index' => $this->_map['method'],
105
+ 'filter_index' => "main_table.{$this->_map['method']}",
106
+ 'type' => 'options',
107
+ 'options' => $this->_getHelper()->getMethodOptions(),
108
+ 'width' => 150,
109
+ ));
110
+
111
+ if ($this->_getHelper()->supportsProduct()) {
112
+ $this->addColumn('product', array(
113
+ 'header' => $this->_getHelper()->__('Product'),
114
+ 'align' => 'left',
115
+ 'index' => $this->_map['product'],
116
+ 'filter_index' => "main_table.{$this->_map['product']}",
117
+ 'type' => 'options',
118
+ 'options' => $this->_getHelper()->getProductOptions(),
119
+ 'width' => 150,
120
+ ));
121
+ }
122
+
123
+
124
+ $this->addColumn('weight_and_above', array(
125
+ 'header' => $this->_getHelper()->__('Weight (and above)'),
126
+ 'index' => 'weight_and_above',
127
+ 'filter_condition_callback' => array($this, '_weightAndAboveFilter'),
128
+ 'default' => '*',
129
+ 'type' => 'number'
130
+ ));
131
+
132
+ if ($this->_getHelper()->supportsPriceVsDest()) {
133
+ $this->addColumn('price_and_above', array(
134
+ 'header' => $this->_getHelper()->__('Price (and above)'),
135
+ 'align' => 'left',
136
+ 'index' => 'price_and_above',
137
+ 'filter_condition_callback' => array($this, '_priceAndAboveFilter'),
138
+ 'type' => 'price',
139
+ 'currency_code' => $store->getBaseCurrency()->getCode(),
140
+ 'default' => '*',
141
+ ));
142
+ }
143
+
144
+ $this->addColumn('is_enabled', array(
145
+ 'header' => $this->_getHelper()->__('Enabled'),
146
+ 'align' => 'left',
147
+ 'index' => 'is_enabled_grid',
148
+ 'filter' => false,
149
+ 'type' => 'options',
150
+ 'options' => array(0 => $this->_getHelper()->__('No'), 1 => $this->_getHelper()->__('Yes')),
151
+ ));
152
+
153
+ $this->addColumn('shipping_price', array(
154
+ 'header' => $this->_getHelper()->__('Shipping Price'),
155
+ 'align' => 'left',
156
+ 'index' => 'shipping_price_grid',
157
+ 'filter_index' => "main_table.{$this->_map['price']}",
158
+ 'type' => 'price',
159
+ 'currency_code' => $store->getBaseCurrency()->getCode(),
160
+ 'default' => '',
161
+ ));
162
+
163
+
164
+ if ($this->_getHelper()->supportsMarkup()) {
165
+ $this->addColumn('shipping_percentage', array(
166
+ 'header' => $this->_getHelper()->__('Shipping Price %'),
167
+ 'align' => 'left',
168
+ 'index' => 'shipping_percentage_grid',
169
+ 'filter_index' => "main_table.{$this->_map['price']}",
170
+ 'type' => 'number',
171
+ 'default' => ''
172
+ ));
173
+
174
+ $this->addColumn('addition_amount', array(
175
+ 'header' => $this->_getHelper()->__('Addition Price'),
176
+ 'align' => 'left',
177
+ 'index' => 'addition_amount_grid',
178
+ 'filter_index' => "main_table.{$this->_map['price']}",
179
+ 'type' => 'price',
180
+ 'currency_code' => $store->getBaseCurrency()->getCode(),
181
+ ));
182
+
183
+ }
184
+
185
+
186
+ if ($this->_getHelper()->supportsCashOnDelivery()) {
187
+ $this->addColumn('cod_surcharge_price', array(
188
+ 'header' => $this->_getHelper()->__('COD Surcharge'),
189
+ 'align' => 'left',
190
+ 'index' => 'cod_surcharge_price',
191
+ 'filter_index' => "main_table.{$this->_map['cashondelivery_surcharge']}",
192
+ 'type' => 'price',
193
+ 'currency_code' => $store->getBaseCurrency()->getCode(),
194
+ ));
195
+
196
+ $this->addColumn('cod_surcharge_percentage', array(
197
+ 'header' => $this->_getHelper()->__('COD Surcharge %'),
198
+ 'index' => 'cod_surcharge_percentage',
199
+ 'filter_index' => "main_table.{$this->_map['cashondelivery_surcharge']}",
200
+ 'type' => 'number',
201
+ ));
202
+
203
+ if ($this->_getHelper()->supportsCodMinSurcharge()) {
204
+ $this->addColumn('cod_min_surcharge', array(
205
+ 'header' => $this->_getHelper()->__('COD Min. Surcharge'),
206
+ 'index' => $this->_map['cod_min_surcharge'],
207
+ 'filter_index' => "main_table.{$this->_map['cod_min_surcharge']}",
208
+ 'type' => 'price',
209
+ 'currency_code' => $store->getBaseCurrency()->getCode(),
210
+ ));
211
+ }
212
+ }
213
+
214
+
215
+ return parent::_prepareColumns();
216
+ }
217
+
218
+ protected function _prepareMassaction()
219
+ {
220
+ $this->setMassactionIdField($this->_map['pk']);
221
+ $this->getMassactionBlock()->setFormFieldName('tablerates');
222
+ $this->getMassactionBlock()->addItem('delete', array(
223
+ 'label' => $this->_getHelper()->__('Delete'),
224
+ 'url' => $this->getUrl('*/*/massDelete', array("carrier" => $this->_getHelper()->getCarrierCode())),
225
+ 'confirm' => $this->_getHelper()->__('Are you sure?')
226
+ ));
227
+
228
+ return $this;
229
+ }
230
+
231
+ public function getGridUrl()
232
+ {
233
+ return $this->getUrl('*/*/grid', array('_current' => true, '_query' => array("carrier" => $this->_getHelper()->getCarrierCode())));
234
+ }
235
+
236
+ public function getRowUrl($row)
237
+ {
238
+ return $this->getUrl('*/*/edit', array('tablerate_id' => $row->getId(), "carrier" => $this->_getHelper()->getCarrierCode()));
239
+ }
240
+
241
+ /**
242
+ * Get country options
243
+ *
244
+ * @return array
245
+ */
246
+ public function getCountryOptions()
247
+ {
248
+ $options = array();
249
+ $countries = Mage::getModel('adminhtml/system_config_source_country')->toOptionArray(false);
250
+ if (isset($countries[0])) {
251
+ $countries[0] = array('value' => '0', 'label' => '*',);
252
+ }
253
+ foreach ($countries as $country) {
254
+ $options[$country['value']] = $country['label'];
255
+ }
256
+
257
+ return $options;
258
+ }
259
+
260
+ /**
261
+ *
262
+ * @param Zitec_TableRates_Model_Mysql4_Tablerate_Collection $collection
263
+ * @param type Mage_Adminhtml_Block_Widget_Grid_Column
264
+ *
265
+ * @return \Zitec_TableRates_Block_Adminhtml_Tablerate_Grid
266
+ */
267
+ protected function _weightAndAboveFilter($collection, $column)
268
+ {
269
+ return $this->_weightPriceAndAboveFilter($collection, $column, false);
270
+ }
271
+
272
+ /**
273
+ *
274
+ * @param Zitec_TableRates_Model_Mysql4_Tablerate_Collection $collection
275
+ * @param type Mage_Adminhtml_Block_Widget_Grid_Column
276
+ *
277
+ * @return \Zitec_TableRates_Block_Adminhtml_Tablerate_Grid
278
+ */
279
+ protected function _priceAndAboveFilter($collection, $column)
280
+ {
281
+ return $this->_weightPriceAndAboveFilter($collection, $column, true);
282
+ }
283
+
284
+ /**
285
+ *
286
+ * @param Zitec_TableRates_Model_Mysql4_Tablerate_Collection $collection
287
+ * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
288
+ * @param boolean $priceVsDest
289
+ *
290
+ * @return \Zitec_TableRates_Block_Adminhtml_Tablerate_Grid
291
+ */
292
+ protected function _weightPriceAndAboveFilter(Zitec_TableRates_Model_Mysql4_Tablerate_Collection $collection, Mage_Adminhtml_Block_Widget_Grid_Column $column, $priceVsDest = false)
293
+ {
294
+
295
+ if ($priceVsDest && !$this->_getHelper()->supportsPriceVsDest()) {
296
+ return $this;
297
+ }
298
+
299
+ $value = $column->getFilter()->getValue();
300
+ if (!is_array($value)) {
301
+ return $this;
302
+ }
303
+
304
+
305
+ $from = isset($value['from']) ? $value['from'] : false;
306
+ $to = isset($value['to']) ? $value['to'] : false;
307
+
308
+ if ($from === false && $to === false) {
309
+ return $this;
310
+ }
311
+
312
+ $select = $collection->getSelect();
313
+ if ($from !== false) {
314
+ $select->where(" main_table.{$this->_map['weight_price']} >= ? ", $from);
315
+ }
316
+
317
+
318
+ if ($to !== false) {
319
+ $select->where(" main_table.{$this->_map['weight_price']} <= ? ", $to);
320
+ }
321
+
322
+ $select->where(" main_table.{$this->_map['price_vs_dest']} = ? ", $priceVsDest ? 1 : 0);
323
+
324
+ $selectStr = (string)$select;
325
+ $this->_getHelper()->log($selectStr);
326
+
327
+ return $this;
328
+ }
329
+
330
+ /**
331
+ * Get store
332
+ *
333
+ * @return Mage_Core_Model_Store
334
+ */
335
+ protected function _getStore()
336
+ {
337
+ $storeId = (int)$this->getRequest()->getParam('store', 0);
338
+
339
+ return Mage::app()->getStore($storeId);
340
+ }
341
+
342
+ /**
343
+ *
344
+ * @return Zitec_TableRates_Helper_Data
345
+ */
346
+ protected function _getHelper()
347
+ {
348
+ return Mage::helper('zitec_tablerates');
349
+ }
350
+
351
  }
app/code/community/Zitec/TableRates/Block/Adminhtml/Tablerate/Grid/Renderer/Shippingpercentage.php CHANGED
@@ -1,38 +1,38 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_TableRates_Block_Adminhtml_Tablerate_Grid_Renderer_Shippingpercentage extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
25
- {
26
-
27
- public function render(Varien_Object $row)
28
- {
29
- $var = $row->getShippingPercentage();
30
- if (isset($var)) {
31
- return $row->getShippingPercentage() . '%';
32
- } else {
33
- return '';
34
- }
35
- }
36
-
37
- }
38
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_TableRates_Block_Adminhtml_Tablerate_Grid_Renderer_Shippingpercentage extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
25
+ {
26
+
27
+ public function render(Varien_Object $row)
28
+ {
29
+ $var = $row->getShippingPercentage();
30
+ if (isset($var)) {
31
+ return $row->getShippingPercentage() . '%';
32
+ } else {
33
+ return '';
34
+ }
35
+ }
36
+
37
+ }
38
+
app/code/community/Zitec/TableRates/Block/Adminhtml/Tablerate/Import.php CHANGED
@@ -1,61 +1,61 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_TableRates_Block_Adminhtml_Tablerate_Import extends Mage_Adminhtml_Block_Widget_Form_Container
25
- {
26
-
27
- public function __construct()
28
- {
29
- $this->_objectId = 'tablerate_id';
30
- $this->_blockGroup = 'zitec_tablerates';
31
- $this->_controller = 'adminhtml_tablerate';
32
- $this->_mode = 'import';
33
- parent::__construct();
34
-
35
- $this->_updateButton('save', 'label', Mage::helper('zitec_tablerates')->__('Import'));
36
- $this->_removeButton('delete');
37
- $this->_removeButton('reset');
38
- }
39
-
40
- public function getHeaderText()
41
- {
42
- return $this->_getHelper()->__('Import') . ' ' . $this->_getHelper()->getGridTitle();
43
- }
44
-
45
- public function getBackUrl()
46
- {
47
- return $this->getUrl('*/*/', array("carrier" => $this->_getHelper()->getCarrierCode()));
48
- }
49
-
50
- /**
51
- *
52
- * @return Zitec_TableRates_Helper_Data
53
- */
54
- protected function _getHelper()
55
- {
56
- return Mage::helper('zitec_tablerates');
57
- }
58
-
59
-
60
- }
61
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_TableRates_Block_Adminhtml_Tablerate_Import extends Mage_Adminhtml_Block_Widget_Form_Container
25
+ {
26
+
27
+ public function __construct()
28
+ {
29
+ $this->_objectId = 'tablerate_id';
30
+ $this->_blockGroup = 'zitec_tablerates';
31
+ $this->_controller = 'adminhtml_tablerate';
32
+ $this->_mode = 'import';
33
+ parent::__construct();
34
+
35
+ $this->_updateButton('save', 'label', Mage::helper('zitec_tablerates')->__('Import'));
36
+ $this->_removeButton('delete');
37
+ $this->_removeButton('reset');
38
+ }
39
+
40
+ public function getHeaderText()
41
+ {
42
+ return $this->_getHelper()->__('Import') . ' ' . $this->_getHelper()->getGridTitle();
43
+ }
44
+
45
+ public function getBackUrl()
46
+ {
47
+ return $this->getUrl('*/*/', array("carrier" => $this->_getHelper()->getCarrierCode()));
48
+ }
49
+
50
+ /**
51
+ *
52
+ * @return Zitec_TableRates_Helper_Data
53
+ */
54
+ protected function _getHelper()
55
+ {
56
+ return Mage::helper('zitec_tablerates');
57
+ }
58
+
59
+
60
+ }
61
+
app/code/community/Zitec/TableRates/Block/Adminhtml/Tablerate/Import/Form.php CHANGED
@@ -1,78 +1,78 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_TableRates_Block_Adminhtml_Tablerate_Import_Form extends Mage_Adminhtml_Block_Widget_Form
25
- {
26
- /**
27
- * @var array
28
- */
29
- public function __construct()
30
- {
31
- parent::__construct();
32
- }
33
-
34
- protected function _prepareForm()
35
- {
36
- $form = new Varien_Data_Form(array(
37
- 'id' => 'edit_form',
38
- 'action' => $this->getUrl('*/*/importrates', array('tablerate_id' => $this->getRequest()->getParam('tablerate_id'), 'carrier' => $this->_getHelper()->getCarrierCode())),
39
- 'method' => 'post',
40
- 'enctype' => 'multipart/form-data'
41
- ));
42
- $this->setForm($form);
43
-
44
-
45
- $fieldset = $form->addFieldset('base_fieldset', array());
46
-
47
- $fieldset->addField('website_id', 'select', array(
48
- 'name' => 'website_id',
49
- 'label' => $this->_getHelper()->__('Website'),
50
- 'values' => Mage::getSingleton('zitec_tablerates/source_website')->toOptionArray(),
51
- 'required' => true
52
- ));
53
-
54
- $fieldset->addField('import', 'file', array(
55
- 'name' => 'import',
56
- 'label' => $this->_getHelper()->__('Import Rates'),
57
- 'required' => true,
58
-
59
- ));
60
-
61
-
62
- $form->setUseContainer(true);
63
-
64
- return parent::_prepareForm();
65
- }
66
-
67
-
68
- /**
69
- *
70
- * @return Zitec_TableRates_Helper_Data
71
- */
72
- protected function _getHelper()
73
- {
74
- return Mage::helper('zitec_tablerates');
75
- }
76
-
77
- }
78
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_TableRates_Block_Adminhtml_Tablerate_Import_Form extends Mage_Adminhtml_Block_Widget_Form
25
+ {
26
+ /**
27
+ * @var array
28
+ */
29
+ public function __construct()
30
+ {
31
+ parent::__construct();
32
+ }
33
+
34
+ protected function _prepareForm()
35
+ {
36
+ $form = new Varien_Data_Form(array(
37
+ 'id' => 'edit_form',
38
+ 'action' => $this->getUrl('*/*/importrates', array('tablerate_id' => $this->getRequest()->getParam('tablerate_id'), 'carrier' => $this->_getHelper()->getCarrierCode())),
39
+ 'method' => 'post',
40
+ 'enctype' => 'multipart/form-data'
41
+ ));
42
+ $this->setForm($form);
43
+
44
+
45
+ $fieldset = $form->addFieldset('base_fieldset', array());
46
+
47
+ $fieldset->addField('website_id', 'select', array(
48
+ 'name' => 'website_id',
49
+ 'label' => $this->_getHelper()->__('Website'),
50
+ 'values' => Mage::getSingleton('zitec_tablerates/source_website')->toOptionArray(),
51
+ 'required' => true
52
+ ));
53
+
54
+ $fieldset->addField('import', 'file', array(
55
+ 'name' => 'import',
56
+ 'label' => $this->_getHelper()->__('Import Rates'),
57
+ 'required' => true,
58
+
59
+ ));
60
+
61
+
62
+ $form->setUseContainer(true);
63
+
64
+ return parent::_prepareForm();
65
+ }
66
+
67
+
68
+ /**
69
+ *
70
+ * @return Zitec_TableRates_Helper_Data
71
+ */
72
+ protected function _getHelper()
73
+ {
74
+ return Mage::helper('zitec_tablerates');
75
+ }
76
+
77
+ }
78
+
app/code/community/Zitec/TableRates/Block/Adminhtml/Widget/Grid/Column/Filter/Region.php CHANGED
@@ -1,41 +1,41 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_TableRates_Block_Adminhtml_Widget_Grid_Column_Filter_Region
25
- extends Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Text
26
- {
27
- /**
28
- * Get condition
29
- *
30
- * @return array
31
- */
32
- public function getCondition()
33
- {
34
- $value = trim($this->getValue());
35
- if ($value == '*') {
36
- return array('null' => true);
37
- } else {
38
- return array('like' => '%' . $this->_escapeValue($this->getValue()) . '%');
39
- }
40
- }
41
- }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_TableRates_Block_Adminhtml_Widget_Grid_Column_Filter_Region
25
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Text
26
+ {
27
+ /**
28
+ * Get condition
29
+ *
30
+ * @return array
31
+ */
32
+ public function getCondition()
33
+ {
34
+ $value = trim($this->getValue());
35
+ if ($value == '*') {
36
+ return array('null' => true);
37
+ } else {
38
+ return array('like' => '%' . $this->_escapeValue($this->getValue()) . '%');
39
+ }
40
+ }
41
+ }
app/code/community/Zitec/TableRates/Helper/Data.php CHANGED
@@ -1,267 +1,267 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_TableRates_Helper_Data extends Mage_Core_Helper_Abstract
25
- {
26
-
27
-
28
- /**
29
- *
30
- * @return string
31
- * @throws Exception
32
- */
33
- public function getCarrierCode()
34
- {
35
- $carrierCode = Mage::app()->getRequest()->getParam("carrier");
36
- if (!$carrierCode) {
37
- throw new Exception("Carrier code not found");
38
- }
39
-
40
- return $carrierCode;
41
- }
42
-
43
- /**
44
- *
45
- * @param string $field
46
- *
47
- * @return string
48
- */
49
- public function getCarrierConfig($field)
50
- {
51
- $path = "carriers/{$this->getCarrierCode()}/zitec_tablerates/$field";
52
- $value = Mage::getStoreConfig($path);
53
-
54
- return $value;
55
- }
56
-
57
- /**
58
- *
59
- * @param string $logicalName
60
- *
61
- * @return string
62
- */
63
- public function getCarrierConfigDbTableFieldName($logicalName)
64
- {
65
- return $this->getCarrierConfig("db_table_field_names/$logicalName");
66
- }
67
-
68
- /**
69
- *
70
- * @return boolean
71
- */
72
- public function supportsPriceVsDest()
73
- {
74
- return $this->supportsFeature("price_vs_dest");
75
- }
76
-
77
- /**
78
- *
79
- * @return boolean
80
- */
81
- public function supportsProduct()
82
- {
83
- return $this->_getProductSource() ? true : false;
84
- }
85
-
86
- /**
87
- *
88
- * @return string
89
- */
90
- protected function _getProductSource()
91
- {
92
- return $this->getCarrierConfig('product_source');
93
- }
94
-
95
- /**
96
- *
97
- * @return boolean
98
- */
99
- public function supportsMarkup()
100
- {
101
- return $this->supportsFeature("markup_type");
102
- }
103
-
104
- /**
105
- *
106
- * @return boolean
107
- */
108
- public function supportsCashOnDelivery()
109
- {
110
- return $this->supportsFeature('cash_on_delivery');
111
- }
112
-
113
- /**
114
- *
115
- * @return type
116
- */
117
- public function supportsCodMinSurcharge()
118
- {
119
- return $this->supportsCashOnDelivery() && $this->supportsFeature('cod_min_surcharge');
120
- }
121
-
122
- /**
123
- *
124
- * @param string $feature
125
- *
126
- * @return boolean
127
- */
128
- public function supportsFeature($feature)
129
- {
130
- return $this->getCarrierConfig("features/$feature") ? true : false;
131
- }
132
-
133
- /**
134
- *
135
- * @return string
136
- */
137
- public function getGridTitle()
138
- {
139
- $gridTitle = $this->getCarrierConfig("grid_title");
140
-
141
- return $gridTitle ? $this->getCarrierHelper()->__($gridTitle) : $this->__("Zitec Table Rates");
142
- }
143
-
144
- /**
145
- *
146
- * @return array
147
- */
148
- public function getMethodOptions()
149
- {
150
- return $this->_optionArrayToValueArray("method_source");
151
- }
152
-
153
- /**
154
- *
155
- * @return array
156
- */
157
- public function getProductOptions()
158
- {
159
- return $this->_optionArrayToValueArray("product_source");
160
- }
161
-
162
- /**
163
- *
164
- * @param string $sourceModel
165
- *
166
- * @return type
167
- */
168
- protected function _optionArrayToValueArray($sourceConfig)
169
- {
170
- $source = $this->getCarrierConfig($sourceConfig);
171
- if (!$source) {
172
- $message = __FUNCTION__ . ": $sourceConfig not in carrier's config.xml";
173
- $this->log($message);
174
- throw new Exception($message);
175
- }
176
- $optionArray = Mage::getModel($source)->toOptionArray(true);
177
- $options = array();
178
- foreach ($optionArray as $option) {
179
- $options[$option['value']] = $option['label'];
180
- }
181
-
182
- return $options;
183
- }
184
-
185
- /**
186
- *
187
- * @return string
188
- */
189
- public function getTableratesDbTable()
190
- {
191
- return $this->getCarrierConfig("tablerates_db_table");
192
- }
193
-
194
- /**
195
- *
196
- * @param string &$module
197
- * @param string &$controller
198
- * @param string &$action
199
- *
200
- * @return type
201
- */
202
- public function getExportAction(&$module, &$controller, &$action)
203
- {
204
- $exportAction = $this->getCarrierConfig('export_action');
205
- list($module, $controller, $action) = explode("/", $exportAction);
206
-
207
- return $exportAction;
208
- }
209
-
210
- /**
211
- *
212
- * @return boolean
213
- */
214
- public function isExportUsingRedirect()
215
- {
216
- return $this->getCarrierConfig("export_use_redirect") ? true : false;
217
- }
218
-
219
- /**
220
- *
221
- * @param string &$resourceClass
222
- * @param string &$method
223
- *
224
- * @return boolean
225
- */
226
- public function getImportAction(&$resourceClass, &$method)
227
- {
228
- $resourceClass = $this->getCarrierConfig("import/resource_class");
229
- $method = $this->getCarrierConfig("import/method");
230
-
231
- return true;
232
- }
233
-
234
- /**
235
- *
236
- * @return type
237
- */
238
- public function getCarrierHelper()
239
- {
240
- return Mage::helper('zitec_dpd');
241
- }
242
-
243
- /**
244
- *
245
- * @param string $message
246
- *
247
- * @return \Zitec_TableRates_Helper_Data
248
- */
249
- public function log($message)
250
- {
251
- Mage::log($message, null, "zitec_tablerates.log");
252
-
253
- return $this;
254
- }
255
-
256
- /**
257
- *
258
- * @param string $errorMessage
259
- *
260
- * @return boolean
261
- */
262
- public function isMySqlDuplicateKeyErrorMessage($errorMessage)
263
- {
264
- return strpos($errorMessage, "SQLSTATE[23000]") !== false;
265
- }
266
- }
267
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_TableRates_Helper_Data extends Mage_Core_Helper_Abstract
25
+ {
26
+
27
+
28
+ /**
29
+ *
30
+ * @return string
31
+ * @throws Exception
32
+ */
33
+ public function getCarrierCode()
34
+ {
35
+ $carrierCode = Mage::app()->getRequest()->getParam("carrier");
36
+ if (!$carrierCode) {
37
+ throw new Exception("Carrier code not found");
38
+ }
39
+
40
+ return $carrierCode;
41
+ }
42
+
43
+ /**
44
+ *
45
+ * @param string $field
46
+ *
47
+ * @return string
48
+ */
49
+ public function getCarrierConfig($field)
50
+ {
51
+ $path = "carriers/{$this->getCarrierCode()}/zitec_tablerates/$field";
52
+ $value = Mage::getStoreConfig($path);
53
+
54
+ return $value;
55
+ }
56
+
57
+ /**
58
+ *
59
+ * @param string $logicalName
60
+ *
61
+ * @return string
62
+ */
63
+ public function getCarrierConfigDbTableFieldName($logicalName)
64
+ {
65
+ return $this->getCarrierConfig("db_table_field_names/$logicalName");
66
+ }
67
+
68
+ /**
69
+ *
70
+ * @return boolean
71
+ */
72
+ public function supportsPriceVsDest()
73
+ {
74
+ return $this->supportsFeature("price_vs_dest");
75
+ }
76
+
77
+ /**
78
+ *
79
+ * @return boolean
80
+ */
81
+ public function supportsProduct()
82
+ {
83
+ return $this->_getProductSource() ? true : false;
84
+ }
85
+
86
+ /**
87
+ *
88
+ * @return string
89
+ */
90
+ protected function _getProductSource()
91
+ {
92
+ return $this->getCarrierConfig('product_source');
93
+ }
94
+
95
+ /**
96
+ *
97
+ * @return boolean
98
+ */
99
+ public function supportsMarkup()
100
+ {
101
+ return $this->supportsFeature("markup_type");
102
+ }
103
+
104
+ /**
105
+ *
106
+ * @return boolean
107
+ */
108
+ public function supportsCashOnDelivery()
109
+ {
110
+ return $this->supportsFeature('cash_on_delivery');
111
+ }
112
+
113
+ /**
114
+ *
115
+ * @return type
116
+ */
117
+ public function supportsCodMinSurcharge()
118
+ {
119
+ return $this->supportsCashOnDelivery() && $this->supportsFeature('cod_min_surcharge');
120
+ }
121
+
122
+ /**
123
+ *
124
+ * @param string $feature
125
+ *
126
+ * @return boolean
127
+ */
128
+ public function supportsFeature($feature)
129
+ {
130
+ return $this->getCarrierConfig("features/$feature") ? true : false;
131
+ }
132
+
133
+ /**
134
+ *
135
+ * @return string
136
+ */
137
+ public function getGridTitle()
138
+ {
139
+ $gridTitle = $this->getCarrierConfig("grid_title");
140
+
141
+ return $gridTitle ? $this->getCarrierHelper()->__($gridTitle) : $this->__("Zitec Table Rates");
142
+ }
143
+
144
+ /**
145
+ *
146
+ * @return array
147
+ */
148
+ public function getMethodOptions()
149
+ {
150
+ return $this->_optionArrayToValueArray("method_source");
151
+ }
152
+
153
+ /**
154
+ *
155
+ * @return array
156
+ */
157
+ public function getProductOptions()
158
+ {
159
+ return $this->_optionArrayToValueArray("product_source");
160
+ }
161
+
162
+ /**
163
+ *
164
+ * @param string $sourceModel
165
+ *
166
+ * @return type
167
+ */
168
+ protected function _optionArrayToValueArray($sourceConfig)
169
+ {
170
+ $source = $this->getCarrierConfig($sourceConfig);
171
+ if (!$source) {
172
+ $message = __FUNCTION__ . ": $sourceConfig not in carrier's config.xml";
173
+ $this->log($message);
174
+ throw new Exception($message);
175
+ }
176
+ $optionArray = Mage::getModel($source)->toOptionArray(true);
177
+ $options = array();
178
+ foreach ($optionArray as $option) {
179
+ $options[$option['value']] = $option['label'];
180
+ }
181
+
182
+ return $options;
183
+ }
184
+
185
+ /**
186
+ *
187
+ * @return string
188
+ */
189
+ public function getTableratesDbTable()
190
+ {
191
+ return $this->getCarrierConfig("tablerates_db_table");
192
+ }
193
+
194
+ /**
195
+ *
196
+ * @param string &$module
197
+ * @param string &$controller
198
+ * @param string &$action
199
+ *
200
+ * @return type
201
+ */
202
+ public function getExportAction(&$module, &$controller, &$action)
203
+ {
204
+ $exportAction = $this->getCarrierConfig('export_action');
205
+ list($module, $controller, $action) = explode("/", $exportAction);
206
+
207
+ return $exportAction;
208
+ }
209
+
210
+ /**
211
+ *
212
+ * @return boolean
213
+ */
214
+ public function isExportUsingRedirect()
215
+ {
216
+ return $this->getCarrierConfig("export_use_redirect") ? true : false;
217
+ }
218
+
219
+ /**
220
+ *
221
+ * @param string &$resourceClass
222
+ * @param string &$method
223
+ *
224
+ * @return boolean
225
+ */
226
+ public function getImportAction(&$resourceClass, &$method)
227
+ {
228
+ $resourceClass = $this->getCarrierConfig("import/resource_class");
229
+ $method = $this->getCarrierConfig("import/method");
230
+
231
+ return true;
232
+ }
233
+
234
+ /**
235
+ *
236
+ * @return type
237
+ */
238
+ public function getCarrierHelper()
239
+ {
240
+ return Mage::helper('zitec_dpd');
241
+ }
242
+
243
+ /**
244
+ *
245
+ * @param string $message
246
+ *
247
+ * @return \Zitec_TableRates_Helper_Data
248
+ */
249
+ public function log($message)
250
+ {
251
+ Mage::log($message, null, "zitec_tablerates.log");
252
+
253
+ return $this;
254
+ }
255
+
256
+ /**
257
+ *
258
+ * @param string $errorMessage
259
+ *
260
+ * @return boolean
261
+ */
262
+ public function isMySqlDuplicateKeyErrorMessage($errorMessage)
263
+ {
264
+ return strpos($errorMessage, "SQLSTATE[23000]") !== false;
265
+ }
266
+ }
267
+
app/code/community/Zitec/TableRates/Helper/Directory.php CHANGED
@@ -1,76 +1,76 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_TableRates_Helper_Directory extends Mage_Directory_Helper_Data
25
- {
26
-
27
- /**
28
- * Json representation of regions data
29
- *
30
- * @var string
31
- */
32
- protected $_regionJson2;
33
-
34
- public function getRegionJson2()
35
- {
36
- if (!$this->_regionJson2) {
37
- $cacheKey = 'CORE_DIRECTORY_REGIONS_JSON2_STORE' . Mage::app()->getStore()->getId();
38
- if (Mage::app()->useCache('config')) {
39
- $json = Mage::app()->loadCache($cacheKey);
40
- }
41
- if (empty($json)) {
42
- $countryIds = array();
43
- foreach ($this->getCountryCollection() as $country) {
44
- $countryIds[] = $country->getCountryId();
45
- }
46
- $collection = Mage::getModel('directory/region')->getResourceCollection()
47
- ->addCountryFilter($countryIds)
48
- ->load();
49
-
50
- $regions = array(
51
- 'config' => array(
52
- 'show_all_regions' => true,
53
- 'regions_required' => Mage::helper('core')->jsonEncode(array()),
54
- )
55
- );
56
-
57
- foreach ($collection as $region) {
58
- if (!$region->getRegionId()) {
59
- continue;
60
- }
61
- $regions[$region->getCountryId()][$region->getRegionId()] = array(
62
- 'code' => $region->getCode(),
63
- 'name' => $this->__($region->getName())
64
- );
65
- }
66
- $json = Mage::helper('core')->jsonEncode($regions);
67
- if (Mage::app()->useCache('config')) {
68
- Mage::app()->saveCache($json, $cacheKey, array('config'));
69
- }
70
- }
71
- $this->_regionJson2 = $json;
72
- }
73
-
74
- return $this->_regionJson2;
75
- }
76
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_TableRates_Helper_Directory extends Mage_Directory_Helper_Data
25
+ {
26
+
27
+ /**
28
+ * Json representation of regions data
29
+ *
30
+ * @var string
31
+ */
32
+ protected $_regionJson2;
33
+
34
+ public function getRegionJson2()
35
+ {
36
+ if (!$this->_regionJson2) {
37
+ $cacheKey = 'CORE_DIRECTORY_REGIONS_JSON2_STORE' . Mage::app()->getStore()->getId();
38
+ if (Mage::app()->useCache('config')) {
39
+ $json = Mage::app()->loadCache($cacheKey);
40
+ }
41
+ if (empty($json)) {
42
+ $countryIds = array();
43
+ foreach ($this->getCountryCollection() as $country) {
44
+ $countryIds[] = $country->getCountryId();
45
+ }
46
+ $collection = Mage::getModel('directory/region')->getResourceCollection()
47
+ ->addCountryFilter($countryIds)
48
+ ->load();
49
+
50
+ $regions = array(
51
+ 'config' => array(
52
+ 'show_all_regions' => true,
53
+ 'regions_required' => Mage::helper('core')->jsonEncode(array()),
54
+ )
55
+ );
56
+
57
+ foreach ($collection as $region) {
58
+ if (!$region->getRegionId()) {
59
+ continue;
60
+ }
61
+ $regions[$region->getCountryId()][$region->getRegionId()] = array(
62
+ 'code' => $region->getCode(),
63
+ 'name' => $this->__($region->getName())
64
+ );
65
+ }
66
+ $json = Mage::helper('core')->jsonEncode($regions);
67
+ if (Mage::app()->useCache('config')) {
68
+ Mage::app()->saveCache($json, $cacheKey, array('config'));
69
+ }
70
+ }
71
+ $this->_regionJson2 = $json;
72
+ }
73
+
74
+ return $this->_regionJson2;
75
+ }
76
  }
app/code/community/Zitec/TableRates/Model/Mysql4/Tablerate.php CHANGED
@@ -1,181 +1,181 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_TableRates_Model_Mysql4_Tablerate extends Mage_Core_Model_Mysql4_Abstract
25
- {
26
-
27
- /**
28
- * Initialize resource model
29
- *
30
- */
31
- protected function _construct()
32
- {
33
- $this->_init(self::_getHelper()->getTableratesDbTable(), self::getDbTableIdField());
34
- }
35
-
36
- /**
37
- *
38
- * @param string $field
39
- * @param mixed $value
40
- * @param Mage_Core_Model_Abstract $object
41
- *
42
- * @return Zend_Db_Select
43
- */
44
- protected function _getLoadSelect($field, $value, $object)
45
- {
46
- $select = parent::_getLoadSelect($field, $value, $object);
47
- self::prepareSelectColumns($select, $this->getTable(self::_getHelper()->getTableratesDbTable()));
48
- $selectStr = (string)$select;
49
- $this->_getHelper()->log($selectStr);
50
-
51
- return $select;
52
- }
53
-
54
- /**
55
- *
56
- * @return string
57
- */
58
- public static function getDbTableIdField()
59
- {
60
- $map = self::getLogicalDbFieldNamesMap();
61
-
62
- return self::getDbTableFieldName($map['pk']);
63
- }
64
-
65
- /**
66
- * You may tablerates table for shipping method has a column whose name is distanto than normal for extensions.
67
- * Must set up the columns and in the config shipping method.
68
- * Eg the id column is usually called 'pk' but if something else (eg "entity_id"
69
- * will in the config module shipping method this:
70
- * carriers / carrier_code / zitec_tablerates / db_table_field_names / pk / entity_id
71
- *
72
- *
73
- * @param string $logicalName
74
- *
75
- * @return string
76
- */
77
- public static function getDbTableFieldName($logicalName)
78
- {
79
- $mappedFieldName = self::_getHelper()->getCarrierConfigDbTableFieldName($logicalName);
80
-
81
- return $mappedFieldName ? $mappedFieldName : $logicalName;
82
- }
83
-
84
- /**
85
- *
86
- * @return array
87
- */
88
- public static function getLogicalDbFieldNames()
89
- {
90
- return array(
91
- 'pk',
92
- 'website_id',
93
- 'dest_country_id',
94
- 'dest_region_id',
95
- 'dest_zip',
96
- 'weight_price',
97
- 'price_vs_dest',
98
- 'price',
99
- 'method',
100
- 'product',
101
- 'markup_type',
102
- 'cashondelivery_surcharge',
103
- 'cod_min_surcharge'
104
- );
105
- }
106
-
107
- /**
108
- *
109
- * @return array
110
- */
111
- public static function getLogicalDbFieldNamesMap()
112
- {
113
- $map = array();
114
- foreach (self::getLogicalDbFieldNames() as $logicalName) {
115
- $map[$logicalName] = self::getDbTableFieldName($logicalName);
116
- }
117
-
118
- return $map;
119
- }
120
-
121
- /**
122
- *
123
- * @param Zend_Db_Select $select
124
- *
125
- * @return \Zend_Db_Select
126
- */
127
- public static function prepareSelectColumns(Zend_Db_Select $select, $table = 'main_table')
128
- {
129
- $map = self::getLogicalDbFieldNamesMap();
130
-
131
- $pricePercentageColName = $map['price'];
132
- if (self::_getHelper()->supportsMarkup()) {
133
- $markupColumnName = $map['markup_type'];
134
- $select->columns(array('shipping_price' => new Zend_Db_Expr("IF ({$table}.{$markupColumnName} = '0', {$table}.{$pricePercentageColName}, NULL)")));
135
- $select->columns(array('shipping_percentage' => new Zend_Db_Expr("IF ({$table}.{$markupColumnName} = '1', {$table}.{$pricePercentageColName}, NULL)")));
136
- $select->columns(array('shipping_price_grid' => new Zend_Db_Expr("IF ({$table}.{$markupColumnName} = '0' and {$table}.{$pricePercentageColName} >= 0, {$table}.{$pricePercentageColName}, NULL)")));
137
- $select->columns(array('shipping_percentage_grid' => new Zend_Db_Expr("IF ({$table}.{$markupColumnName} = '1' and {$table}.{$pricePercentageColName} >= 0, {$table}.{$pricePercentageColName}, NULL)")));
138
- $select->columns(array('addition_amount_grid' => new Zend_Db_Expr("IF ({$table}.{$markupColumnName} = '2' and {$table}.{$pricePercentageColName} >= 0, {$table}.{$pricePercentageColName}, NULL)")));
139
- } else {
140
-
141
- $select->columns(array('shipping_price' => "{$table}.{$pricePercentageColName}"));
142
- $select->columns(array('shipping_percentage' => null));
143
- $select->columns(array('shipping_price_grid' => new Zend_Db_Expr("IF({$table}.{$pricePercentageColName} >= 0, {$table}.{$pricePercentageColName}, NULL)")));
144
- $select->columns(array('shipping_percentage_grid' => null));
145
- $select->columns(array('addition_amount_grid' => null));
146
-
147
- }
148
-
149
- $select->columns(array('is_enabled_grid' => new Zend_Db_Expr("IF ({$table}.{$pricePercentageColName} >= 0, 1, 0)")));
150
-
151
- $weightPriceColName = $map['weight_price'];
152
- if (self::_getHelper()->supportsPriceVsDest()) {
153
- $priceVsDestColName = $map['price_vs_dest'];
154
- $select->columns(array('weight_and_above' => new Zend_Db_Expr("IF ({$table}.{$priceVsDestColName} = '0' , {$table}.{$weightPriceColName}, NULL)")));
155
- $select->columns(array('price_and_above' => new Zend_Db_Expr("IF ({$table}.{$priceVsDestColName} <> '0' , {$table}.{$weightPriceColName}, NULL)")));
156
- } else {
157
- $select->columns(array('weight_and_above' => "{$table}.{$weightPriceColName}"));
158
- $select->columns(array('price_and_above' => null));
159
- }
160
-
161
- if (self::_getHelper()->supportsCashOnDelivery()) {
162
- $cashOnDeliverySurchargeColName = $map['cashondelivery_surcharge'];
163
- $select->columns(array('cod_surcharge_price' => new Zend_Db_Expr("IF(not ISNULL({$table}.{$cashOnDeliverySurchargeColName}) and RIGHT({$table}.{$cashOnDeliverySurchargeColName}, 1) <> '%' , CAST({$table}.{$cashOnDeliverySurchargeColName} AS DECIMAL(10,2)), NULL) ")));
164
- $select->columns(array('cod_surcharge_percentage' => new Zend_Db_Expr("IF(RIGHT({$table}.{$cashOnDeliverySurchargeColName}, 1) = '%', CAST(LEFT({$table}.{$cashOnDeliverySurchargeColName}, LENGTH({$table}.{$cashOnDeliverySurchargeColName}) - 1) AS DECIMAL(10,2)), NULL)")));
165
- } else {
166
- $select->columns(array('cod_surcharge_price' => null, 'cod_surcharge_percentage' => null));
167
- }
168
-
169
- return $select;
170
- }
171
-
172
- /**
173
- *
174
- * @return Zitec_TableRates_Helper_Data
175
- */
176
- protected static function _getHelper()
177
- {
178
- return Mage::helper('zitec_tablerates');
179
- }
180
-
181
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_TableRates_Model_Mysql4_Tablerate extends Mage_Core_Model_Mysql4_Abstract
25
+ {
26
+
27
+ /**
28
+ * Initialize resource model
29
+ *
30
+ */
31
+ protected function _construct()
32
+ {
33
+ $this->_init(self::_getHelper()->getTableratesDbTable(), self::getDbTableIdField());
34
+ }
35
+
36
+ /**
37
+ *
38
+ * @param string $field
39
+ * @param mixed $value
40
+ * @param Mage_Core_Model_Abstract $object
41
+ *
42
+ * @return Zend_Db_Select
43
+ */
44
+ protected function _getLoadSelect($field, $value, $object)
45
+ {
46
+ $select = parent::_getLoadSelect($field, $value, $object);
47
+ self::prepareSelectColumns($select, $this->getTable(self::_getHelper()->getTableratesDbTable()));
48
+ $selectStr = (string)$select;
49
+ $this->_getHelper()->log($selectStr);
50
+
51
+ return $select;
52
+ }
53
+
54
+ /**
55
+ *
56
+ * @return string
57
+ */
58
+ public static function getDbTableIdField()
59
+ {
60
+ $map = self::getLogicalDbFieldNamesMap();
61
+
62
+ return self::getDbTableFieldName($map['pk']);
63
+ }
64
+
65
+ /**
66
+ * You may tablerates table for shipping method has a column whose name is distanto than normal for extensions.
67
+ * Must set up the columns and in the config shipping method.
68
+ * Eg the id column is usually called 'pk' but if something else (eg "entity_id"
69
+ * will in the config module shipping method this:
70
+ * carriers / carrier_code / zitec_tablerates / db_table_field_names / pk / entity_id
71
+ *
72
+ *
73
+ * @param string $logicalName
74
+ *
75
+ * @return string
76
+ */
77
+ public static function getDbTableFieldName($logicalName)
78
+ {
79
+ $mappedFieldName = self::_getHelper()->getCarrierConfigDbTableFieldName($logicalName);
80
+
81
+ return $mappedFieldName ? $mappedFieldName : $logicalName;
82
+ }
83
+
84
+ /**
85
+ *
86
+ * @return array
87
+ */
88
+ public static function getLogicalDbFieldNames()
89
+ {
90
+ return array(
91
+ 'pk',
92
+ 'website_id',
93
+ 'dest_country_id',
94
+ 'dest_region_id',
95
+ 'dest_zip',
96
+ 'weight_price',
97
+ 'price_vs_dest',
98
+ 'price',
99
+ 'method',
100
+ 'product',
101
+ 'markup_type',
102
+ 'cashondelivery_surcharge',
103
+ 'cod_min_surcharge'
104
+ );
105
+ }
106
+
107
+ /**
108
+ *
109
+ * @return array
110
+ */
111
+ public static function getLogicalDbFieldNamesMap()
112
+ {
113
+ $map = array();
114
+ foreach (self::getLogicalDbFieldNames() as $logicalName) {
115
+ $map[$logicalName] = self::getDbTableFieldName($logicalName);
116
+ }
117
+
118
+ return $map;
119
+ }
120
+
121
+ /**
122
+ *
123
+ * @param Zend_Db_Select $select
124
+ *
125
+ * @return \Zend_Db_Select
126
+ */
127
+ public static function prepareSelectColumns(Zend_Db_Select $select, $table = 'main_table')
128
+ {
129
+ $map = self::getLogicalDbFieldNamesMap();
130
+
131
+ $pricePercentageColName = $map['price'];
132
+ if (self::_getHelper()->supportsMarkup()) {
133
+ $markupColumnName = $map['markup_type'];
134
+ $select->columns(array('shipping_price' => new Zend_Db_Expr("IF ({$table}.{$markupColumnName} = '0', {$table}.{$pricePercentageColName}, NULL)")));
135
+ $select->columns(array('shipping_percentage' => new Zend_Db_Expr("IF ({$table}.{$markupColumnName} = '1', {$table}.{$pricePercentageColName}, NULL)")));
136
+ $select->columns(array('shipping_price_grid' => new Zend_Db_Expr("IF ({$table}.{$markupColumnName} = '0' and {$table}.{$pricePercentageColName} >= 0, {$table}.{$pricePercentageColName}, NULL)")));
137
+ $select->columns(array('shipping_percentage_grid' => new Zend_Db_Expr("IF ({$table}.{$markupColumnName} = '1' and {$table}.{$pricePercentageColName} >= 0, {$table}.{$pricePercentageColName}, NULL)")));
138
+ $select->columns(array('addition_amount_grid' => new Zend_Db_Expr("IF ({$table}.{$markupColumnName} = '2' and {$table}.{$pricePercentageColName} >= 0, {$table}.{$pricePercentageColName}, NULL)")));
139
+ } else {
140
+
141
+ $select->columns(array('shipping_price' => "{$table}.{$pricePercentageColName}"));
142
+ $select->columns(array('shipping_percentage' => null));
143
+ $select->columns(array('shipping_price_grid' => new Zend_Db_Expr("IF({$table}.{$pricePercentageColName} >= 0, {$table}.{$pricePercentageColName}, NULL)")));
144
+ $select->columns(array('shipping_percentage_grid' => null));
145
+ $select->columns(array('addition_amount_grid' => null));
146
+
147
+ }
148
+
149
+ $select->columns(array('is_enabled_grid' => new Zend_Db_Expr("IF ({$table}.{$pricePercentageColName} >= 0, 1, 0)")));
150
+
151
+ $weightPriceColName = $map['weight_price'];
152
+ if (self::_getHelper()->supportsPriceVsDest()) {
153
+ $priceVsDestColName = $map['price_vs_dest'];
154
+ $select->columns(array('weight_and_above' => new Zend_Db_Expr("IF ({$table}.{$priceVsDestColName} = '0' , {$table}.{$weightPriceColName}, NULL)")));
155
+ $select->columns(array('price_and_above' => new Zend_Db_Expr("IF ({$table}.{$priceVsDestColName} <> '0' , {$table}.{$weightPriceColName}, NULL)")));
156
+ } else {
157
+ $select->columns(array('weight_and_above' => "{$table}.{$weightPriceColName}"));
158
+ $select->columns(array('price_and_above' => null));
159
+ }
160
+
161
+ if (self::_getHelper()->supportsCashOnDelivery()) {
162
+ $cashOnDeliverySurchargeColName = $map['cashondelivery_surcharge'];
163
+ $select->columns(array('cod_surcharge_price' => new Zend_Db_Expr("IF(not ISNULL({$table}.{$cashOnDeliverySurchargeColName}) and RIGHT({$table}.{$cashOnDeliverySurchargeColName}, 1) <> '%' , CAST({$table}.{$cashOnDeliverySurchargeColName} AS DECIMAL(10,2)), NULL) ")));
164
+ $select->columns(array('cod_surcharge_percentage' => new Zend_Db_Expr("IF(RIGHT({$table}.{$cashOnDeliverySurchargeColName}, 1) = '%', CAST(LEFT({$table}.{$cashOnDeliverySurchargeColName}, LENGTH({$table}.{$cashOnDeliverySurchargeColName}) - 1) AS DECIMAL(10,2)), NULL)")));
165
+ } else {
166
+ $select->columns(array('cod_surcharge_price' => null, 'cod_surcharge_percentage' => null));
167
+ }
168
+
169
+ return $select;
170
+ }
171
+
172
+ /**
173
+ *
174
+ * @return Zitec_TableRates_Helper_Data
175
+ */
176
+ protected static function _getHelper()
177
+ {
178
+ return Mage::helper('zitec_tablerates');
179
+ }
180
+
181
  }
app/code/community/Zitec/TableRates/Model/Mysql4/Tablerate/Collection.php CHANGED
@@ -1,92 +1,92 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_TableRates_Model_Mysql4_Tablerate_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
25
- {
26
-
27
- /**
28
- *
29
- * @var array
30
- */
31
- protected $_map = null;
32
-
33
- /**
34
- * directory/country table name
35
- *
36
- * @var string
37
- */
38
- protected $_countryTable;
39
-
40
- /**
41
- * directory/country_region table name
42
- *
43
- * @var string
44
- */
45
- protected $_regionTable;
46
-
47
- /**
48
- * Constructor
49
- */
50
-
51
- /**
52
- * Define resource model
53
- *
54
- */
55
- protected function _construct()
56
- {
57
- $this->_map = Zitec_TableRates_Model_Mysql4_Tablerate::getLogicalDbFieldNamesMap();
58
- $this->_init('zitec_tablerates/tablerate');
59
- $this->_countryTable = $this->getTable('directory/country');
60
- $this->_regionTable = $this->getTable('directory/country_region');
61
- }
62
-
63
- /**
64
- * Initialize select, add country iso3 code and region name
65
- *
66
- * @return void
67
- */
68
- public function _initSelect()
69
- {
70
- parent::_initSelect();
71
- Zitec_TableRates_Model_Mysql4_Tablerate::prepareSelectColumns($this->_select);
72
-
73
- $this->_select->joinLeft(
74
- array('country_table' => $this->_countryTable), "country_table.country_id = main_table.{$this->_map['dest_country_id']}", array('dest_country' => 'iso2_code'))
75
- ->joinLeft(
76
- array('region_table' => $this->_regionTable), "region_table.region_id = main_table.{$this->_map['dest_region_id']}", array('dest_region' => 'code', 'dest_region_name' => 'default_name'));
77
-
78
- $select = (string)$this->_select;
79
- $this->_getHelper()->log($select);
80
- }
81
-
82
-
83
- /**
84
- *
85
- * @return Zitec_TableRates_Helper_Data
86
- */
87
- protected function _getHelper()
88
- {
89
- return Mage::helper('zitec_tablerates');
90
- }
91
-
92
- }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_TableRates_Model_Mysql4_Tablerate_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
25
+ {
26
+
27
+ /**
28
+ *
29
+ * @var array
30
+ */
31
+ protected $_map = null;
32
+
33
+ /**
34
+ * directory/country table name
35
+ *
36
+ * @var string
37
+ */
38
+ protected $_countryTable;
39
+
40
+ /**
41
+ * directory/country_region table name
42
+ *
43
+ * @var string
44
+ */
45
+ protected $_regionTable;
46
+
47
+ /**
48
+ * Constructor
49
+ */
50
+
51
+ /**
52
+ * Define resource model
53
+ *
54
+ */
55
+ protected function _construct()
56
+ {
57
+ $this->_map = Zitec_TableRates_Model_Mysql4_Tablerate::getLogicalDbFieldNamesMap();
58
+ $this->_init('zitec_tablerates/tablerate');
59
+ $this->_countryTable = $this->getTable('directory/country');
60
+ $this->_regionTable = $this->getTable('directory/country_region');
61
+ }
62
+
63
+ /**
64
+ * Initialize select, add country iso3 code and region name
65
+ *
66
+ * @return void
67
+ */
68
+ public function _initSelect()
69
+ {
70
+ parent::_initSelect();
71
+ Zitec_TableRates_Model_Mysql4_Tablerate::prepareSelectColumns($this->_select);
72
+
73
+ $this->_select->joinLeft(
74
+ array('country_table' => $this->_countryTable), "country_table.country_id = main_table.{$this->_map['dest_country_id']}", array('dest_country' => 'iso2_code'))
75
+ ->joinLeft(
76
+ array('region_table' => $this->_regionTable), "region_table.region_id = main_table.{$this->_map['dest_region_id']}", array('dest_region' => 'code', 'dest_region_name' => 'default_name'));
77
+
78
+ $select = (string)$this->_select;
79
+ $this->_getHelper()->log($select);
80
+ }
81
+
82
+
83
+ /**
84
+ *
85
+ * @return Zitec_TableRates_Helper_Data
86
+ */
87
+ protected function _getHelper()
88
+ {
89
+ return Mage::helper('zitec_tablerates');
90
+ }
91
+
92
+ }
app/code/community/Zitec/TableRates/Model/Source/Website.php CHANGED
@@ -1,55 +1,55 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_TableRates_Model_Source_Website
25
- {
26
-
27
- /**
28
- *
29
- * @return array
30
- */
31
- public function getWebsites()
32
- {
33
- $websiteOptions = array();
34
- foreach (Mage::getModel('core/website')->getCollection() as $website) {
35
- $websiteOptions[$website->getId()] = $website->getName();
36
- }
37
-
38
- return $websiteOptions;
39
- }
40
-
41
- /**
42
- *
43
- * @return array
44
- */
45
- public function toOptionArray()
46
- {
47
- $options = array();
48
- foreach ($this->getWebsites() as $value => $name) {
49
- $options[] = array('label' => $name, 'value' => $value);
50
- }
51
-
52
- return $options;
53
- }
54
- }
55
-
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_TableRates_Model_Source_Website
25
+ {
26
+
27
+ /**
28
+ *
29
+ * @return array
30
+ */
31
+ public function getWebsites()
32
+ {
33
+ $websiteOptions = array();
34
+ foreach (Mage::getModel('core/website')->getCollection() as $website) {
35
+ $websiteOptions[$website->getId()] = $website->getName();
36
+ }
37
+
38
+ return $websiteOptions;
39
+ }
40
+
41
+ /**
42
+ *
43
+ * @return array
44
+ */
45
+ public function toOptionArray()
46
+ {
47
+ $options = array();
48
+ foreach ($this->getWebsites() as $value => $name) {
49
+ $options[] = array('label' => $name, 'value' => $value);
50
+ }
51
+
52
+ return $options;
53
+ }
54
+ }
55
+
app/code/community/Zitec/TableRates/Model/Tablerate.php CHANGED
@@ -1,89 +1,89 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_TableRates_Model_Tablerate extends Mage_Core_Model_Abstract
25
- {
26
- const COD_NOT_AVAILABLE = 0;
27
- const COD_SURCHARGE_ZERO = 1;
28
- const COD_SURCHARGE_FIXED = 2;
29
- const COD_SURCHARGE_PERCENTAGE = 3;
30
-
31
- /**
32
- *
33
- * @var array
34
- */
35
- protected $_map = null;
36
-
37
- public function _construct()
38
- {
39
- parent::_construct();
40
- $this->_map = Zitec_TableRates_Model_Mysql4_Tablerate::getLogicalDbFieldNamesMap();
41
- $this->_init('zitec_tablerates/tablerate');
42
- }
43
-
44
- /**
45
- *
46
- * @param string $logicalFieldName
47
- *
48
- * @return mixed
49
- */
50
- public function getMappedData($logicalFieldName)
51
- {
52
- return $this->getData($this->getMappedName($logicalFieldName));
53
- }
54
-
55
- /**
56
- *
57
- * @param string $logicalFieldName
58
- *
59
- * @return string
60
- * @throws Exception
61
- */
62
- public function getMappedName($logicalFieldName)
63
- {
64
- if (isset($this->_map[$logicalFieldName])) {
65
- return $this->_map[$logicalFieldName];
66
- } else {
67
- throw new Exception("Invalid logical field name $logicalFieldName");
68
- }
69
- }
70
-
71
- /**
72
- *
73
- * @return int
74
- */
75
- public function getCashOnDeliverySurchargeOption()
76
- {
77
- if (is_null($this->getMappedData('cashondelivery_surcharge'))) {
78
- return self::COD_NOT_AVAILABLE;
79
- } elseif (round($this->getData('cod_surcharge_price'), 2) > 0) {
80
- return self::COD_SURCHARGE_FIXED;
81
- } elseif (round($this->getData('cod_surcharge_percentage'), 2) > 0) {
82
- return self::COD_SURCHARGE_PERCENTAGE;
83
- } else {
84
- return self::COD_SURCHARGE_ZERO;
85
- }
86
- }
87
-
88
-
89
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_TableRates_Model_Tablerate extends Mage_Core_Model_Abstract
25
+ {
26
+ const COD_NOT_AVAILABLE = 0;
27
+ const COD_SURCHARGE_ZERO = 1;
28
+ const COD_SURCHARGE_FIXED = 2;
29
+ const COD_SURCHARGE_PERCENTAGE = 3;
30
+
31
+ /**
32
+ *
33
+ * @var array
34
+ */
35
+ protected $_map = null;
36
+
37
+ public function _construct()
38
+ {
39
+ parent::_construct();
40
+ $this->_map = Zitec_TableRates_Model_Mysql4_Tablerate::getLogicalDbFieldNamesMap();
41
+ $this->_init('zitec_tablerates/tablerate');
42
+ }
43
+
44
+ /**
45
+ *
46
+ * @param string $logicalFieldName
47
+ *
48
+ * @return mixed
49
+ */
50
+ public function getMappedData($logicalFieldName)
51
+ {
52
+ return $this->getData($this->getMappedName($logicalFieldName));
53
+ }
54
+
55
+ /**
56
+ *
57
+ * @param string $logicalFieldName
58
+ *
59
+ * @return string
60
+ * @throws Exception
61
+ */
62
+ public function getMappedName($logicalFieldName)
63
+ {
64
+ if (isset($this->_map[$logicalFieldName])) {
65
+ return $this->_map[$logicalFieldName];
66
+ } else {
67
+ throw new Exception("Invalid logical field name $logicalFieldName");
68
+ }
69
+ }
70
+
71
+ /**
72
+ *
73
+ * @return int
74
+ */
75
+ public function getCashOnDeliverySurchargeOption()
76
+ {
77
+ if (is_null($this->getMappedData('cashondelivery_surcharge'))) {
78
+ return self::COD_NOT_AVAILABLE;
79
+ } elseif (round($this->getData('cod_surcharge_price'), 2) > 0) {
80
+ return self::COD_SURCHARGE_FIXED;
81
+ } elseif (round($this->getData('cod_surcharge_percentage'), 2) > 0) {
82
+ return self::COD_SURCHARGE_PERCENTAGE;
83
+ } else {
84
+ return self::COD_SURCHARGE_ZERO;
85
+ }
86
+ }
87
+
88
+
89
  }
app/code/community/Zitec/TableRates/controllers/Adminhtml/IndexController.php CHANGED
@@ -1,462 +1,462 @@
1
- <?php
2
- /**
3
- * Zitec_Dpd – shipping carrier extension
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
- *
12
- * @category Zitec
13
- * @package Zitec_Dpd
14
- * @copyright Copyright (c) 2014 Zitec COM
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- *
20
- * @category Zitec
21
- * @package Zitec_Dpd
22
- * @author Zitec COM <magento@zitec.ro>
23
- */
24
- class Zitec_TableRates_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
25
- {
26
-
27
- /**
28
- *
29
- * @return array
30
- */
31
- protected function _getMap()
32
- {
33
- return Zitec_TableRates_Model_Mysql4_Tablerate::getLogicalDbFieldNamesMap();
34
- }
35
-
36
- protected function _initTablerate($idFieldName = 'tablerate_id')
37
- {
38
- $this->_title($this->__('DPD Table Rate'))
39
- ->_title($this->_getTableRateHelper()->getGridTitle());
40
-
41
- $tablerateId = (int)$this->getRequest()->getParam($idFieldName);
42
-
43
- $tablerate = Mage::getModel('zitec_tablerates/tablerate');
44
-
45
- if ($tablerateId) {
46
- $tablerate->load($tablerateId);
47
- }
48
-
49
- Mage::register('tablerate_data', $tablerate);
50
- Mage::register('current_tablerate', $tablerate);
51
-
52
- return $this;
53
- }
54
-
55
- /**
56
- *
57
- * @return \Zitec_TableRates_Adminhtml_IndexController
58
- */
59
- protected function _initAction()
60
- {
61
- $this->loadLayout()->_setActiveMenu("zitec_dpd/zitec_tablerates/{$this->_getCarrierCode()}");
62
-
63
- return $this;
64
- }
65
-
66
- /**
67
- *
68
- * @return string
69
- */
70
- protected function _getCarrierCode()
71
- {
72
- return $this->_getTableRateHelper()->getCarrierCode();
73
- }
74
-
75
- /**
76
- *
77
- * @return Zitec_TableRates_Helper_Data
78
- */
79
- protected function _getTableRateHelper()
80
- {
81
- return Mage::helper('zitec_tablerates');
82
- }
83
-
84
- public function indexAction()
85
- {
86
- if (!$this->_checkCarrierCode()) {
87
- return;
88
- }
89
-
90
- $this->_initAction()
91
- ->renderLayout();
92
- }
93
-
94
- public function gridAction()
95
- {
96
- if (!$this->_checkCarrierCode()) {
97
- return;
98
- }
99
-
100
- $this->getResponse()->setBody(
101
- $this->getLayout()->createBlock('zitec_tablerates/adminhtml_tablerate_grid')->toHtml()
102
- );
103
- }
104
-
105
- public function newAction()
106
- {
107
- if (!$this->_checkCarrierCode()) {
108
- return;
109
- }
110
- Mage::getSingleton('adminhtml/session')->setTablerateData(false);
111
- $this->_forward('edit');
112
- }
113
-
114
- public function editAction()
115
- {
116
- if (!$this->_checkCarrierCode()) {
117
- return;
118
- }
119
-
120
- $this->_initTablerate();
121
- $this->loadLayout();
122
-
123
- /* @var $store Zitec_SeurMfCustom_Model_Tablerate */
124
- $tablerate = Mage::registry('current_tablerate');
125
-
126
- $this->_title($tablerate->getTablerateId() ? implode(', ', array($tablerate->getDestCountryId(), $tablerate->getDestRegionId(), $tablerate->getDestZip())) : $this->__('New Rate'));
127
-
128
- /**
129
- * Set active menu item
130
- */
131
- $this->_setActiveMenu("zitec_dpd/{$this->_getTableRateHelper()->getCarrierCode()}");
132
-
133
- $this->renderLayout();
134
- }
135
-
136
- public function importAction()
137
- {
138
- if (!$this->_checkCarrierCode()) {
139
- return;
140
- }
141
-
142
- $this->loadLayout();
143
-
144
- $this->_title($this->__('Import Rates'));
145
-
146
- /**
147
- * Set active menu item
148
- */
149
- $this->_setActiveMenu("zitec_dpd/{$this->_getTableRateHelper()->getCarrierCode()}");
150
-
151
- $this->renderLayout();
152
- }
153
-
154
- public function exportAction()
155
- {
156
- if (!$this->_checkCarrierCode()) {
157
- return;
158
- }
159
-
160
- $this->loadLayout();
161
-
162
- $this->_title($this->__('Export Rates'));
163
-
164
- /**
165
- * Set active menu item
166
- */
167
- $this->_setActiveMenu("zitec_dpd/{$this->_getTableRateHelper()->getCarrierCode()}");
168
-
169
- $this->renderLayout();
170
- }
171
-
172
- /**
173
- *
174
- * @param Zitec_TableRates_Model_Tablerate $tablerate
175
- * @param array $data
176
- *
177
- * @return boolean
178
- */
179
- protected function _prepareSaveData(Zitec_TableRates_Model_Tablerate $tablerate, array $data)
180
- {
181
- if (isset($data['pk']) && !$data['pk']) {
182
- unset($data['pk']);
183
- }
184
-
185
- $data['dest_zip'] = isset($data['dest_zip']) && $data['dest_zip'] != '*' ? $data['dest_zip'] : '';
186
-
187
- if (!$this->_getTableRateHelper()->supportsProduct() && isset($data['product'])) {
188
- unset($data['product']);
189
- }
190
-
191
- if ($this->_getTableRateHelper()->supportsPriceVsDest()) {
192
- $data['price_vs_dest'] = isset($data['price_vs_dest']) ? $data['price_vs_dest'] : '0';
193
- } elseif (isset($data['price_vs_dest'])) {
194
- unset($data['price_vs_dest']);
195
- }
196
-
197
- $data['weight_price'] = isset($data['weight_price']) && trim($data['weight_price']) ? $data['weight_price'] : '0';
198
-
199
- if (!isset($data['shipping_method_enabled']) || $data['shipping_method_enabled']) {
200
- if ($this->_getTableRateHelper()->supportsCashOnDelivery()) {
201
- if (!isset($data['cod_option'])) {
202
- $data['cod_option'] = Zitec_TableRates_Model_Tablerate::COD_NOT_AVAILABLE;
203
- }
204
- switch ($data['cod_option']) {
205
- case Zitec_TableRates_Model_Tablerate::COD_NOT_AVAILABLE:
206
- $data['cashondelivery_surcharge'] = null;
207
- if ($this->_getTableRateHelper()->supportsCodMinSurcharge()) {
208
- $data['cod_min_surcharge'] = null;
209
- }
210
- break;
211
- case Zitec_TableRates_Model_Tablerate::COD_SURCHARGE_ZERO:
212
- $data['cashondelivery_surcharge'] = '0';
213
- if ($this->_getTableRateHelper()->supportsCodMinSurcharge()) {
214
- $data['cod_min_surcharge'] = null;
215
- }
216
- break;
217
- case Zitec_TableRates_Model_Tablerate::COD_SURCHARGE_FIXED:
218
- if (!isset($data['cashondelivery_surcharge']) || !trim($data['cashondelivery_surcharge'])) {
219
- $data['cashondelivery_surcharge'] = '0';
220
- }
221
- if ($this->_getTableRateHelper()->supportsCodMinSurcharge()) {
222
- $data['cod_min_surcharge'] = null;
223
- }
224
- break;
225
- case Zitec_TableRates_Model_Tablerate::COD_SURCHARGE_PERCENTAGE:
226
- if (!isset($data['cashondelivery_surcharge']) || !trim($data['cashondelivery_surcharge'])) {
227
- $data['cashondelivery_surcharge'] = '0';
228
- }
229
- $data['cashondelivery_surcharge'] = $data['cashondelivery_surcharge'] ? $data['cashondelivery_surcharge'] . '%' : '0';
230
- if ($this->_getTableRateHelper()->supportsCodMinSurcharge()) {
231
- $data['cod_min_surcharge'] = isset($data['cod_min_surcharge']) && trim($data['cod_min_surcharge']) ? $data['cod_min_surcharge'] : null;
232
- }
233
- break;
234
- default:
235
- $data['cashondelivery_surcharge'] = null;
236
- if ($this->_getTableRateHelper()->supportsCodMinSurcharge()) {
237
- $data['cod_min_surcharge'] = null;
238
- }
239
- }
240
- }
241
- } else {
242
- if ($this->_getTableRateHelper()->supportsMarkup()) {
243
- $data['markup_type'] = '0';
244
- }
245
- $data['price'] = -1;
246
- if ($this->_getTableRateHelper()->supportsCashOnDelivery()) {
247
- $data['cashondelivery_surcharge'] = null;
248
- }
249
- if ($this->_getTableRateHelper()->supportsCodMinSurcharge()) {
250
- $data['cod_min_surcharge'] = null;
251
- }
252
- }
253
-
254
- if (isset($data['shipping_method_enabled'])) {
255
- unset($data['shipping_method_enabled']);
256
- }
257
-
258
- if (!$this->_getTableRateHelper()->supportsMarkup() && isset($data['markup_type'])) {
259
- unset($data['markup_type']);
260
- }
261
-
262
-
263
- if (isset($data['cod_option'])) {
264
- unset($data['cod_option']);
265
- }
266
-
267
- if (!$this->_getTableRateHelper()->supportsCashOnDelivery() && isset($data['cashondelivery_surcharge'])) {
268
- unset($data['cashondelivery_surcharge']);
269
- }
270
-
271
- if (!$this->_getTableRateHelper()->supportsCodMinSurcharge() && isset($data['cod_min_surcharge'])) {
272
- unset($data['cod_min_surcharge']);
273
- }
274
-
275
-
276
- $saveData = array();
277
- foreach ($this->_getMap() as $logicalName => $dbFieldName) {
278
- $saveData[$dbFieldName] = isset($data[$logicalName]) ? $data[$logicalName] : null;
279
- }
280
-
281
- $tablerate->setData($saveData);
282
-
283
- return true;
284
- }
285
-
286
- public function saveAction()
287
- {
288
- if (!$this->_checkCarrierCode()) {
289
- return;
290
- }
291
-
292
- $data = $this->getRequest()->getPost();
293
- if ($data) {
294
- if ($this->getRequest()->getParam("duplicate") && isset($data['pk'])) {
295
- unset($data['pk']);
296
- Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Rate duplicated successfully'));
297
- Mage::getSingleton('adminhtml/session')->setTablerateData($data);
298
- $this->_redirect("*/*/edit", array("carrier" => $this->_getTableRateHelper()->getCarrierCode()));
299
-
300
- return;
301
- }
302
-
303
- $tablerate = Mage::getModel('zitec_tablerates/tablerate');
304
- /* @var $tablerate Zitec_TableRates_Model_Tablerate */
305
- $this->_prepareSaveData($tablerate, $data);
306
- try {
307
- $tablerate->save();
308
-
309
- Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('zitec_tablerates')->__('Rate was successfully saved'));
310
- Mage::getSingleton('adminhtml/session')->setTablerateData(false);
311
-
312
- if ($this->getRequest()->getParam('back')) {
313
- $this->_redirect('*/*/edit', array('tablerate_id' => $tablerate->getTablerateId(), "carrier" => $this->_getTableRateHelper()->getCarrierCode()));
314
-
315
- return;
316
- }
317
- $this->_redirect('*/*/', array("carrier" => $this->_getTableRateHelper()->getCarrierCode()));
318
-
319
- return;
320
- } catch (Exception $e) {
321
- if ($this->_getTableRateHelper()->isMySqlDuplicateKeyErrorMessage($e->getMessage())) {
322
- $message = $this->__("The rate could not be saved because it duplicates the destination, service/product and weight/price of an existing rate. Change some of the rate's values and try saving again.");
323
- } else {
324
- $message = $e->getMessage();
325
- }
326
- Mage::getSingleton('adminhtml/session')->addError($message);
327
- Mage::getSingleton('adminhtml/session')->setTablerateData($data);
328
- $this->_redirect('*/*/edit', array('tablerate_id' => $this->getRequest()->getParam('tablerate_id'), "carrier" => $this->_getTableRateHelper()->getCarrierCode()));
329
-
330
- return;
331
- }
332
- }
333
- Mage::getSingleton('adminhtml/session')->addError(Mage::helper('zitec_tablerates')->__('Unable to find rate to save'));
334
- $this->_redirect('*/*/', array("carrier" => $this->_getTableRateHelper()->getCarrierCode()));
335
- }
336
-
337
-
338
- public function deleteAction()
339
- {
340
- if (!$this->_checkCarrierCode()) {
341
- return;
342
- }
343
-
344
- $tablerateId = $this->getRequest()->getParam('tablerate_id');
345
- if ($tablerateId > 0) {
346
- try {
347
- $model = Mage::getModel('zitec_tablerates/tablerate')->load($tablerateId);
348
- $model->delete();
349
- Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Rate was successfully deleted'));
350
- $this->_redirect('*/*/', array('tablerate_id' => $this->getRequest()->getParam('tablerate_id'), "carrier" => $this->_getTableRateHelper()->getCarrierCode()));
351
- } catch (Exception $e) {
352
- Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
353
- $this->_redirect('*/*/edit', array('tablerate_id' => $this->getRequest()->getParam('tablerate_id'), "carrier" => $this->_getTableRateHelper()->getCarrierCode()));
354
- }
355
- }
356
- $this->_redirect('*/*/', array("carrier" => $this->_getTableRateHelper()->getCarrierCode()));
357
- }
358
-
359
- public function massDeleteAction()
360
- {
361
- if (!$this->_checkCarrierCode()) {
362
- return;
363
- }
364
-
365
- $Ids = (array)$this->getRequest()->getParam('tablerates');
366
- try {
367
- foreach ($Ids as $id) {
368
- $result = Mage::getModel('zitec_tablerates/tablerate')->load($id);
369
- $result->delete();
370
- }
371
- $this->_getSession()->addSuccess(
372
- $this->__('Total of %d record(s) have been deleted.', count($Ids))
373
- );
374
- } catch (Mage_Core_Model_Exception $e) {
375
- $this->_getSession()->addError($e->getMessage());
376
- } catch (Mage_Core_Exception $e) {
377
- $this->_getSession()->addError($e->getMessage());
378
- } catch (Exception $e) {
379
- $this->_getSession()->addException($e, $this->__('An error occurred while updating records.'));
380
- }
381
- $this->_redirect('*/*/', array("carrier" => $this->_getTableRateHelper()->getCarrierCode()));
382
- }
383
-
384
- public function importratesAction()
385
- {
386
- if (!$this->_checkCarrierCode()) {
387
- return;
388
- }
389
-
390
- $websiteId = $this->getRequest()->getParam('website_id');
391
- $csvFile = !empty($_FILES['import']['tmp_name']) ? $_FILES['import']['tmp_name'] : null;
392
- if (!$websiteId || !$csvFile) {
393
- $this->_getSession()->addError($this->__("Please specify the website and file you wish to import"));
394
- $this->_redirect('*/*/import', array("carrier" => $this->_getTableRateHelper()->getCarrierCode()));
395
-
396
- return;
397
- }
398
-
399
- $params = new Varien_Object();
400
- $params->setScopeId($websiteId);
401
-
402
- $resourceClass = null;
403
- $method = null;
404
- $this->_getTableRateHelper()->getImportAction($resourceClass, $method);
405
-
406
- $message = "";
407
- try {
408
- Mage::getResourceModel($resourceClass)->$method($params, $csvFile);
409
- } catch (Mage_Core_Exception $e) {
410
- $message = $e->getMessage();
411
- } catch (Exception $e) {
412
- $this->_getSession()->addError($this->__("An error occurred whilst importing the tablerates: %s", $e->getMessage()));
413
- $this->_redirect('*/*/import', array("carrier" => $this->_getTableRateHelper()->getCarrierCode()));
414
-
415
- return;
416
- }
417
- if (!$message) {
418
- $message = $this->__("Table rates imported successfully");
419
- $this->_getSession()->addSuccess($message);
420
- } else {
421
- $this->_getSession()->addError(str_replace("\n", "<br />", $message));
422
- }
423
- $this->_redirect('*/*/index', array("carrier" => $this->_getTableRateHelper()->getCarrierCode()));
424
- }
425
-
426
- public function exportratesAction()
427
- {
428
- $websiteId = $this->getRequest()->getParam('website_id');
429
- if (!$websiteId) {
430
- $this->_getSession()->addError($this->__("Please specify the website whose rates you want to export"));
431
- $this->_redirect('*/*/export', array("carrier" => $this->_getTableRateHelper()->getCarrierCode()));
432
-
433
- return;
434
- }
435
- $module = null;
436
- $controller = null;
437
- $action = null;
438
- $exportAction = $this->_getTableRateHelper()->getExportAction($module, $controller, $action);
439
- $params = array('website' => $websiteId);
440
- if (!$this->_getTableRateHelper()->isExportUsingRedirect()) {
441
- $this->_forward($action, $controller, $module, $params);
442
- } else {
443
- $this->_redirect($exportAction, $params);
444
- }
445
-
446
- }
447
-
448
- /**
449
- * @return boolean
450
- */
451
- protected function _checkCarrierCode()
452
- {
453
- try {
454
- $this->_getTableRateHelper()->getCarrierCode();
455
- } catch (Exception $e) {
456
- return false;
457
- }
458
-
459
- return true;
460
- }
461
-
462
  }
1
+ <?php
2
+ /**
3
+ * Zitec_Dpd – shipping carrier extension
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
+ *
12
+ * @category Zitec
13
+ * @package Zitec_Dpd
14
+ * @copyright Copyright (c) 2014 Zitec COM
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ *
20
+ * @category Zitec
21
+ * @package Zitec_Dpd
22
+ * @author Zitec COM <magento@zitec.ro>
23
+ */
24
+ class Zitec_TableRates_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
25
+ {
26
+
27
+ /**
28
+ *
29
+ * @return array
30
+ */
31
+ protected function _getMap()
32
+ {
33
+ return Zitec_TableRates_Model_Mysql4_Tablerate::getLogicalDbFieldNamesMap();
34
+ }
35
+
36
+ protected function _initTablerate($idFieldName = 'tablerate_id')
37
+ {
38
+ $this->_title($this->__('DPD Table Rate'))
39
+ ->_title($this->_getTableRateHelper()->getGridTitle());
40
+
41
+ $tablerateId = (int)$this->getRequest()->getParam($idFieldName);
42
+
43
+ $tablerate = Mage::getModel('zitec_tablerates/tablerate');
44
+
45
+ if ($tablerateId) {
46
+ $tablerate->load($tablerateId);
47
+ }
48
+
49
+ Mage::register('tablerate_data', $tablerate);
50
+ Mage::register('current_tablerate', $tablerate);
51
+
52
+ return $this;
53
+ }
54
+
55
+ /**
56
+ *
57
+ * @return \Zitec_TableRates_Adminhtml_IndexController
58
+ */
59
+ protected function _initAction()
60
+ {
61
+ $this->loadLayout()->_setActiveMenu("zitec_dpd/zitec_tablerates/{$this->_getCarrierCode()}");
62
+
63
+ return $this;
64
+ }
65
+
66
+ /**
67
+ *
68
+ * @return string
69
+ */
70
+ protected function _getCarrierCode()
71
+ {
72
+ return $this->_getTableRateHelper()->getCarrierCode();
73
+ }
74
+
75
+ /**
76
+ *
77
+ * @return Zitec_TableRates_Helper_Data
78
+ */
79
+ protected function _getTableRateHelper()
80
+ {
81
+ return Mage::helper('zitec_tablerates');
82
+ }
83
+
84
+ public function indexAction()
85
+ {
86
+ if (!$this->_checkCarrierCode()) {
87
+ return;
88
+ }
89
+
90
+ $this->_initAction()
91
+ ->renderLayout();
92
+ }
93
+
94
+ public function gridAction()
95
+ {
96
+ if (!$this->_checkCarrierCode()) {
97
+ return;
98
+ }
99
+
100
+ $this->getResponse()->setBody(
101
+ $this->getLayout()->createBlock('zitec_tablerates/adminhtml_tablerate_grid')->toHtml()
102
+ );
103
+ }
104
+
105
+ public function newAction()
106
+ {
107
+ if (!$this->_checkCarrierCode()) {
108
+ return;
109
+ }
110
+ Mage::getSingleton('adminhtml/session')->setTablerateData(false);
111
+ $this->_forward('edit');
112
+ }
113
+
114
+ public function editAction()
115
+ {
116
+ if (!$this->_checkCarrierCode()) {
117
+ return;
118
+ }
119
+
120
+ $this->_initTablerate();
121
+ $this->loadLayout();
122
+
123
+ /* @var $store Zitec_SeurMfCustom_Model_Tablerate */
124
+ $tablerate = Mage::registry('current_tablerate');
125
+
126
+ $this->_title($tablerate->getTablerateId() ? implode(', ', array($tablerate->getDestCountryId(), $tablerate->getDestRegionId(), $tablerate->getDestZip())) : $this->__('New Rate'));
127
+
128
+ /**
129
+ * Set active menu item
130
+ */
131
+ $this->_setActiveMenu("zitec_dpd/{$this->_getTableRateHelper()->getCarrierCode()}");
132
+
133
+ $this->renderLayout();
134
+ }
135
+
136
+ public function importAction()
137
+ {
138
+ if (!$this->_checkCarrierCode()) {
139
+ return;
140
+ }
141
+
142
+ $this->loadLayout();
143
+
144
+ $this->_title($this->__('Import Rates'));
145
+
146
+ /**
147
+ * Set active menu item
148
+ */
149
+ $this->_setActiveMenu("zitec_dpd/{$this->_getTableRateHelper()->getCarrierCode()}");
150
+
151
+ $this->renderLayout();
152
+ }
153
+
154
+ public function exportAction()
155
+ {
156
+ if (!$this->_checkCarrierCode()) {
157
+ return;
158
+ }
159
+
160
+ $this->loadLayout();
161
+
162
+ $this->_title($this->__('Export Rates'));
163
+
164
+ /**
165
+ * Set active menu item
166
+ */
167
+ $this->_setActiveMenu("zitec_dpd/{$this->_getTableRateHelper()->getCarrierCode()}");
168
+
169
+ $this->renderLayout();
170
+ }
171
+
172
+ /**
173
+ *
174
+ * @param Zitec_TableRates_Model_Tablerate $tablerate
175
+ * @param array $data
176
+ *
177
+ * @return boolean
178
+ */
179
+ protected function _prepareSaveData(Zitec_TableRates_Model_Tablerate $tablerate, array $data)
180
+ {
181
+ if (isset($data['pk']) && !$data['pk']) {
182
+ unset($data['pk']);
183
+ }
184
+
185
+ $data['dest_zip'] = isset($data['dest_zip']) && $data['dest_zip'] != '*' ? $data['dest_zip'] : '';
186
+
187
+ if (!$this->_getTableRateHelper()->supportsProduct() && isset($data['product'])) {
188
+ unset($data['product']);
189
+ }
190
+
191
+ if ($this->_getTableRateHelper()->supportsPriceVsDest()) {
192
+ $data['price_vs_dest'] = isset($data['price_vs_dest']) ? $data['price_vs_dest'] : '0';
193
+ } elseif (isset($data['price_vs_dest'])) {
194
+ unset($data['price_vs_dest']);
195
+ }
196
+
197
+ $data['weight_price'] = isset($data['weight_price']) && trim($data['weight_price']) ? $data['weight_price'] : '0';
198
+
199
+ if (!isset($data['shipping_method_enabled']) || $data['shipping_method_enabled']) {
200
+ if ($this->_getTableRateHelper()->supportsCashOnDelivery()) {
201
+ if (!isset($data['cod_option'])) {
202
+ $data['cod_option'] = Zitec_TableRates_Model_Tablerate::COD_NOT_AVAILABLE;
203
+ }
204
+ switch ($data['cod_option']) {
205
+ case Zitec_TableRates_Model_Tablerate::COD_NOT_AVAILABLE:
206
+ $data['cashondelivery_surcharge'] = null;
207
+ if ($this->_getTableRateHelper()->supportsCodMinSurcharge()) {
208
+ $data['cod_min_surcharge'] = null;
209
+ }
210
+ break;
211
+ case Zitec_TableRates_Model_Tablerate::COD_SURCHARGE_ZERO:
212
+ $data['cashondelivery_surcharge'] = '0';
213
+ if ($this->_getTableRateHelper()->supportsCodMinSurcharge()) {
214
+ $data['cod_min_surcharge'] = null;
215
+ }
216
+ break;
217
+ case Zitec_TableRates_Model_Tablerate::COD_SURCHARGE_FIXED:
218
+ if (!isset($data['cashondelivery_surcharge']) || !trim($data['cashondelivery_surcharge'])) {
219
+ $data['cashondelivery_surcharge'] = '0';
220
+ }
221
+ if ($this->_getTableRateHelper()->supportsCodMinSurcharge()) {
222
+ $data['cod_min_surcharge'] = null;
223
+ }
224
+ break;
225
+ case Zitec_TableRates_Model_Tablerate::COD_SURCHARGE_PERCENTAGE:
226
+ if (!isset($data['cashondelivery_surcharge']) || !trim($data['cashondelivery_surcharge'])) {
227
+ $data['cashondelivery_surcharge'] = '0';
228
+ }
229
+ $data['cashondelivery_surcharge'] = $data['cashondelivery_surcharge'] ? $data['cashondelivery_surcharge'] . '%' : '0';
230
+ if ($this->_getTableRateHelper()->supportsCodMinSurcharge()) {
231
+ $data['cod_min_surcharge'] = isset($data['cod_min_surcharge']) && trim($data['cod_min_surcharge']) ? $data['cod_min_surcharge'] : null;
232
+ }
233
+ break;
234
+ default:
235
+ $data['cashondelivery_surcharge'] = null;
236
+ if ($this->_getTableRateHelper()->supportsCodMinSurcharge()) {
237
+ $data['cod_min_surcharge'] = null;
238
+ }
239
+ }
240
+ }
241
+ } else {
242
+ if ($this->_getTableRateHelper()->supportsMarkup()) {
243
+ $data['markup_type'] = '0';
244
+ }
245
+ $data['price'] = -1;
246
+ if ($this->_getTableRateHelper()->supportsCashOnDelivery()) {
247
+ $data['cashondelivery_surcharge'] = null;
248
+ }
249
+ if ($this->_getTableRateHelper()->supportsCodMinSurcharge()) {
250
+ $data['cod_min_surcharge'] = null;
251
+ }
252
+ }
253
+
254
+ if (isset($data['shipping_method_enabled'])) {
255
+ unset($data['shipping_method_enabled']);
256
+ }
257
+
258
+ if (!$this->_getTableRateHelper()->supportsMarkup() && isset($data['markup_type'])) {
259
+ unset($data['markup_type']);
260
+ }
261
+
262
+
263
+ if (isset($data['cod_option'])) {
264
+ unset($data['cod_option']);
265
+ }
266
+
267
+ if (!$this->_getTableRateHelper()->supportsCashOnDelivery() && isset($data['cashondelivery_surcharge'])) {
268
+ unset($data['cashondelivery_surcharge']);
269
+ }
270
+
271
+ if (!$this->_getTableRateHelper()->supportsCodMinSurcharge() && isset($data['cod_min_surcharge'])) {
272
+ unset($data['cod_min_surcharge']);
273
+ }
274
+
275
+
276
+ $saveData = array();
277
+ foreach ($this->_getMap() as $logicalName => $dbFieldName) {
278
+ $saveData[$dbFieldName] = isset($data[$logicalName]) ? $data[$logicalName] : null;
279
+ }
280
+
281
+ $tablerate->setData($saveData);
282
+
283
+ return true;
284
+ }
285
+
286
+ public function saveAction()
287
+ {
288
+ if (!$this->_checkCarrierCode()) {
289
+ return;
290
+ }
291
+
292
+ $data = $this->getRequest()->getPost();
293
+ if ($data) {
294
+ if ($this->getRequest()->getParam("duplicate") && isset($data['pk'])) {
295
+ unset($data['pk']);
296
+ Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Rate duplicated successfully'));
297
+ Mage::getSingleton('adminhtml/session')->setTablerateData($data);
298
+ $this->_redirect("*/*/edit", array("carrier" => $this->_getTableRateHelper()->getCarrierCode()));
299
+
300
+ return;
301
+ }
302
+
303
+ $tablerate = Mage::getModel('zitec_tablerates/tablerate');
304
+ /* @var $tablerate Zitec_TableRates_Model_Tablerate */
305
+ $this->_prepareSaveData($tablerate, $data);
306
+ try {
307
+ $tablerate->save();
308
+
309
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('zitec_tablerates')->__('Rate was successfully saved'));
310
+ Mage::getSingleton('adminhtml/session')->setTablerateData(false);
311
+
312
+ if ($this->getRequest()->getParam('back')) {
313
+ $this->_redirect('*/*/edit', array('tablerate_id' => $tablerate->getTablerateId(), "carrier" => $this->_getTableRateHelper()->getCarrierCode()));
314
+
315
+ return;
316
+ }
317
+ $this->_redirect('*/*/', array("carrier" => $this->_getTableRateHelper()->getCarrierCode()));
318
+
319
+ return;
320
+ } catch (Exception $e) {
321
+ if ($this->_getTableRateHelper()->isMySqlDuplicateKeyErrorMessage($e->getMessage())) {
322
+ $message = $this->__("The rate could not be saved because it duplicates the destination, service/product and weight/price of an existing rate. Change some of the rate's values and try saving again.");
323
+ } else {
324
+ $message = $e->getMessage();
325
+ }
326
+ Mage::getSingleton('adminhtml/session')->addError($message);
327
+ Mage::getSingleton('adminhtml/session')->setTablerateData($data);
328
+ $this->_redirect('*/*/edit', array('tablerate_id' => $this->getRequest()->getParam('tablerate_id'), "carrier" => $this->_getTableRateHelper()->getCarrierCode()));
329
+
330
+ return;
331
+ }
332
+ }
333
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('zitec_tablerates')->__('Unable to find rate to save'));
334
+ $this->_redirect('*/*/', array("carrier" => $this->_getTableRateHelper()->getCarrierCode()));
335
+ }
336
+
337
+
338
+ public function deleteAction()
339
+ {
340
+ if (!$this->_checkCarrierCode()) {
341
+ return;
342
+ }
343
+
344
+ $tablerateId = $this->getRequest()->getParam('tablerate_id');
345
+ if ($tablerateId > 0) {
346
+ try {
347
+ $model = Mage::getModel('zitec_tablerates/tablerate')->load($tablerateId);
348
+ $model->delete();
349
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Rate was successfully deleted'));
350
+ $this->_redirect('*/*/', array('tablerate_id' => $this->getRequest()->getParam('tablerate_id'), "carrier" => $this->_getTableRateHelper()->getCarrierCode()));
351
+ } catch (Exception $e) {
352
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
353
+ $this->_redirect('*/*/edit', array('tablerate_id' => $this->getRequest()->getParam('tablerate_id'), "carrier" => $this->_getTableRateHelper()->getCarrierCode()));
354
+ }
355
+ }
356
+ $this->_redirect('*/*/', array("carrier" => $this->_getTableRateHelper()->getCarrierCode()));
357
+ }
358
+
359
+ public function massDeleteAction()
360
+ {
361
+ if (!$this->_checkCarrierCode()) {
362
+ return;
363
+ }
364
+
365
+ $Ids = (array)$this->getRequest()->getParam('tablerates');
366
+ try {
367
+ foreach ($Ids as $id) {
368
+ $result = Mage::getModel('zitec_tablerates/tablerate')->load($id);
369
+ $result->delete();
370
+ }
371
+ $this->_getSession()->addSuccess(
372
+ $this->__('Total of %d record(s) have been deleted.', count($Ids))
373
+ );
374
+ } catch (Mage_Core_Model_Exception $e) {
375
+ $this->_getSession()->addError($e->getMessage());
376
+ } catch (Mage_Core_Exception $e) {
377
+ $this->_getSession()->addError($e->getMessage());
378
+ } catch (Exception $e) {
379
+ $this->_getSession()->addException($e, $this->__('An error occurred while updating records.'));
380
+ }
381
+ $this->_redirect('*/*/', array("carrier" => $this->_getTableRateHelper()->getCarrierCode()));
382
+ }
383
+
384
+ public function importratesAction()
385
+ {
386
+ if (!$this->_checkCarrierCode()) {
387
+ return;
388
+ }
389
+
390
+ $websiteId = $this->getRequest()->getParam('website_id');
391
+ $csvFile = !empty($_FILES['import']['tmp_name']) ? $_FILES['import']['tmp_name'] : null;
392
+ if (!$websiteId || !$csvFile) {
393
+ $this->_getSession()->addError($this->__("Please specify the website and file you wish to import"));
394
+ $this->_redirect('*/*/import', array("carrier" => $this->_getTableRateHelper()->getCarrierCode()));
395
+
396
+ return;
397
+ }
398
+
399
+ $params = new Varien_Object();
400
+ $params->setScopeId($websiteId);
401
+
402
+ $resourceClass = null;
403
+ $method = null;
404
+ $this->_getTableRateHelper()->getImportAction($resourceClass, $method);
405
+
406
+ $message = "";
407
+ try {
408
+ Mage::getResourceModel($resourceClass)->$method($params, $csvFile);
409
+ } catch (Mage_Core_Exception $e) {
410
+ $message = $e->getMessage();
411
+ } catch (Exception $e) {
412
+ $this->_getSession()->addError($this->__("An error occurred whilst importing the tablerates: %s", $e->getMessage()));
413
+ $this->_redirect('*/*/import', array("carrier" => $this->_getTableRateHelper()->getCarrierCode()));
414
+
415
+ return;
416
+ }
417
+ if (!$message) {
418
+ $message = $this->__("Table rates imported successfully");
419
+ $this->_getSession()->addSuccess($message);
420
+ } else {
421
+ $this->_getSession()->addError(str_replace("\n", "<br />", $message));
422
+ }
423
+ $this->_redirect('*/*/index', array("carrier" => $this->_getTableRateHelper()->getCarrierCode()));
424
+ }
425
+
426
+ public function exportratesAction()
427
+ {
428
+ $websiteId = $this->getRequest()->getParam('website_id');
429
+ if (!$websiteId) {
430
+ $this->_getSession()->addError($this->__("Please specify the website whose rates you want to export"));
431
+ $this->_redirect('*/*/export', array("carrier" => $this->_getTableRateHelper()->getCarrierCode()));
432
+
433
+ return;
434
+ }
435
+ $module = null;
436
+ $controller = null;
437
+ $action = null;
438
+ $exportAction = $this->_getTableRateHelper()->getExportAction($module, $controller, $action);
439
+ $params = array('website' => $websiteId);
440
+ if (!$this->_getTableRateHelper()->isExportUsingRedirect()) {
441
+ $this->_forward($action, $controller, $module, $params);
442
+ } else {
443
+ $this->_redirect($exportAction, $params);
444
+ }
445
+
446
+ }
447
+
448
+ /**
449
+ * @return boolean
450
+ */
451
+ protected function _checkCarrierCode()
452
+ {
453
+ try {
454
+ $this->_getTableRateHelper()->getCarrierCode();
455
+ } catch (Exception $e) {
456
+ return false;
457
+ }
458
+
459
+ return true;
460
+ }
461
+
462
  }
app/code/community/Zitec/TableRates/etc/adminhtml.xml CHANGED
@@ -1,21 +1,21 @@
1
- <config>
2
- <acl>
3
- <resources>
4
- <all>
5
- <title>Allow Everything</title>
6
- </all>
7
- <admin>
8
- <children>
9
- <promo>
10
- <children>
11
- <zitec_tablerates translate="title" module="zitec_tablerates">
12
- <title>DPD Table Rates</title>
13
- <sort_order>500</sort_order>
14
- </zitec_tablerates>
15
- </children>
16
- </promo>
17
- </children>
18
- </admin>
19
- </resources>
20
- </acl>
21
- </config>
1
+ <config>
2
+ <acl>
3
+ <resources>
4
+ <all>
5
+ <title>Allow Everything</title>
6
+ </all>
7
+ <admin>
8
+ <children>
9
+ <promo>
10
+ <children>
11
+ <zitec_tablerates translate="title" module="zitec_tablerates">
12
+ <title>DPD Table Rates</title>
13
+ <sort_order>500</sort_order>
14
+ </zitec_tablerates>
15
+ </children>
16
+ </promo>
17
+ </children>
18
+ </admin>
19
+ </resources>
20
+ </acl>
21
+ </config>
app/code/community/Zitec/TableRates/etc/config.xml CHANGED
@@ -1,101 +1,101 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Zitec_TableRates>
5
- <version>0.1.0</version>
6
- </Zitec_TableRates>
7
- </modules>
8
- <global>
9
- <models>
10
- <zitec_tablerates>
11
- <class>Zitec_TableRates_Model</class>
12
- <resourceModel>zitec_tablerates_mysql4</resourceModel>
13
- </zitec_tablerates>
14
- <zitec_tablerates_mysql4>
15
- <class>Zitec_TableRates_Model_Mysql4</class>
16
- </zitec_tablerates_mysql4>
17
- </models>
18
- <resources>
19
- <zitec_tablerates_write>
20
- <connection>
21
- <use>core_write</use>
22
- </connection>
23
- </zitec_tablerates_write>
24
- <zitec_tablerates_read>
25
- <connection>
26
- <use>core_read</use>
27
- </connection>
28
- </zitec_tablerates_read>
29
- </resources>
30
- <blocks>
31
- <zitec_tablerates>
32
- <class>Zitec_TableRates_Block</class>
33
- </zitec_tablerates>
34
- </blocks>
35
- <helpers>
36
- <zitec_tablerates>
37
- <class>Zitec_TableRates_Helper</class>
38
- </zitec_tablerates>
39
- </helpers>
40
- </global>
41
- <adminhtml>
42
- <translate>
43
- <modules>
44
- <Zitec_TableRates>
45
- <files>
46
- <default>Zitec_TableRates.csv</default>
47
- </files>
48
- </Zitec_TableRates>
49
- </modules>
50
- </translate>
51
-
52
- <layout>
53
- <updates>
54
- <zitec_tablerates>
55
- <file>zitec_tablerates.xml</file>
56
- </zitec_tablerates>
57
- </updates>
58
- </layout>
59
- </adminhtml>
60
- <frontend>
61
- <layout>
62
- <updates>
63
- <zitec_tablerates>
64
- <file>zitec_tablerates.xml</file>
65
- </zitec_tablerates>
66
- </updates>
67
- </layout>
68
- <translate>
69
- <modules>
70
- <Zitec_TableRates>
71
- <files>
72
- <default>Zitec_TableRates_frontend.csv</default>
73
- </files>
74
- </Zitec_TableRates>
75
- </modules>
76
- </translate>
77
- </frontend>
78
- <admin>
79
- <routers>
80
- <zitec_tablerates>
81
- <use>admin</use>
82
- <args>
83
- <module>Zitec_TableRates</module>
84
- <frontName>zitec_tablerates</frontName>
85
- </args>
86
- </zitec_tablerates>
87
- </routers>
88
- </admin>
89
- <frontend>
90
- <routers>
91
- <zitec_tablerates>
92
- <use>standard</use>
93
- <args>
94
- <module>Zitec_TableRates</module>
95
- <frontName>zitec_tablerates</frontName>
96
- </args>
97
- </zitec_tablerates>
98
- </routers>
99
- </frontend>
100
-
101
  </config>
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Zitec_TableRates>
5
+ <version>0.1.0</version>
6
+ </Zitec_TableRates>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <zitec_tablerates>
11
+ <class>Zitec_TableRates_Model</class>
12
+ <resourceModel>zitec_tablerates_mysql4</resourceModel>
13
+ </zitec_tablerates>
14
+ <zitec_tablerates_mysql4>
15
+ <class>Zitec_TableRates_Model_Mysql4</class>
16
+ </zitec_tablerates_mysql4>
17
+ </models>
18
+ <resources>
19
+ <zitec_tablerates_write>
20
+ <connection>
21
+ <use>core_write</use>
22
+ </connection>
23
+ </zitec_tablerates_write>
24
+ <zitec_tablerates_read>
25
+ <connection>
26
+ <use>core_read</use>
27
+ </connection>
28
+ </zitec_tablerates_read>
29
+ </resources>
30
+ <blocks>
31
+ <zitec_tablerates>
32
+ <class>Zitec_TableRates_Block</class>
33
+ </zitec_tablerates>
34
+ </blocks>
35
+ <helpers>
36
+ <zitec_tablerates>
37
+ <class>Zitec_TableRates_Helper</class>
38
+ </zitec_tablerates>
39
+ </helpers>
40
+ </global>
41
+ <adminhtml>
42
+ <translate>
43
+ <modules>
44
+ <Zitec_TableRates>
45
+ <files>
46
+ <default>Zitec_TableRates.csv</default>
47
+ </files>
48
+ </Zitec_TableRates>
49
+ </modules>
50
+ </translate>
51
+
52
+ <layout>
53
+ <updates>
54
+ <zitec_tablerates>
55
+ <file>zitec_tablerates.xml</file>
56
+ </zitec_tablerates>
57
+ </updates>
58
+ </layout>
59
+ </adminhtml>
60
+ <frontend>
61
+ <layout>
62
+ <updates>
63
+ <zitec_tablerates>
64
+ <file>zitec_tablerates.xml</file>
65
+ </zitec_tablerates>
66
+ </updates>
67
+ </layout>
68
+ <translate>
69
+ <modules>
70
+ <Zitec_TableRates>
71
+ <files>
72
+ <default>Zitec_TableRates_frontend.csv</default>
73
+ </files>
74
+ </Zitec_TableRates>
75
+ </modules>
76
+ </translate>
77
+ </frontend>
78
+ <admin>
79
+ <routers>
80
+ <zitec_tablerates>
81
+ <use>admin</use>
82
+ <args>
83
+ <module>Zitec_TableRates</module>
84
+ <frontName>zitec_tablerates</frontName>
85
+ </args>
86
+ </zitec_tablerates>
87
+ </routers>
88
+ </admin>
89
+ <frontend>
90
+ <routers>
91
+ <zitec_tablerates>
92
+ <use>standard</use>
93
+ <args>
94
+ <module>Zitec_TableRates</module>
95
+ <frontName>zitec_tablerates</frontName>
96
+ </args>
97
+ </zitec_tablerates>
98
+ </routers>
99
+ </frontend>
100
+
101
  </config>
app/design/adminhtml/default/default/layout/zitec_dpd.xml CHANGED
@@ -1,94 +1,94 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <layout>
3
- <adminhtml_sales_order_create_index>
4
- <reference name="head">
5
- <action method="addJs"><script>zitec/dpd/admin/sales.js</script></action>
6
- </reference>
7
- </adminhtml_sales_order_create_index>
8
-
9
- <adminhtml_sales_order_shipment_view>
10
- <reference name="shipment_tracking" >
11
- <action method="setTemplate">
12
- <template helper="zitec_dpd/layout/getAdminhtmlTrackingTemplate" />
13
- </action>
14
- </reference>
15
- </adminhtml_sales_order_shipment_view>
16
- <adminhtml_sales_shipment_index>
17
- <reference name="head">
18
- <action method="addItem"><type>skin_css</type><name>zitec_dpd/zitec_dpd.css</name></action>
19
- </reference>
20
- </adminhtml_sales_shipment_index>
21
-
22
- <shipping_tracking_popup translate="label">
23
- <reference name="shipping.tracking.popup">
24
- <action method="setTemplate"><template helper="zitec_dpd/layout/changeShippingTrackingPopupTemplate" /></action>
25
- </reference>
26
- </shipping_tracking_popup>
27
-
28
- <adminhtml_sales_order_view>
29
- <reference name="order_totals">
30
- <block type="zitec_dpd/order_totals_cashondeliverysurchage" />
31
- </reference>
32
- </adminhtml_sales_order_view>
33
-
34
- <adminhtml_sales_order_invoice_view>
35
- <reference name="invoice_totals">
36
- <block type="zitec_dpd/order_invoice_totals_cashondeliverysurcharge" />
37
- </reference>
38
- </adminhtml_sales_order_invoice_view>
39
-
40
- <adminhtml_sales_order_invoice_new>
41
- <reference name="invoice_totals">
42
- <block type="zitec_dpd/order_invoice_totals_cashondeliverysurcharge" />
43
- </reference>
44
- </adminhtml_sales_order_invoice_new>
45
-
46
- <adminhtml_sales_order_invoice_new>
47
- <reference name="invoice_totals">
48
- <block type="zitec_dpd/order_invoice_totals_cashondeliverysurcharge" />
49
- </reference>
50
- </adminhtml_sales_order_invoice_new>
51
-
52
- <adminhtml_sales_order_invoice_updateqty>
53
- <reference name="invoice_totals">
54
- <block type="zitec_dpd/order_totals_cashondeliverysurchage" />
55
- </reference>
56
- </adminhtml_sales_order_invoice_updateqty>
57
-
58
- <adminhtml_sales_order_creditmemo_view>
59
- <reference name="creditmemo_totals">
60
- <block type="zitec_dpd/order_creditmemo_totals_cashondeliverysurcharge" />
61
- </reference>
62
- </adminhtml_sales_order_creditmemo_view>
63
-
64
- <adminhtml_sales_order_creditmemo_new>
65
- <reference name="creditmemo_totals">
66
- <block type="zitec_dpd/adminhtml_order_totals_cashondeliverysurcharge_newcreditmemo" />
67
- </reference>
68
- </adminhtml_sales_order_creditmemo_new>
69
-
70
- <adminhtml_sales_order_creditmemo_updateqty>
71
- <reference name="creditmemo_totals">
72
- <block type="zitec_dpd/adminhtml_order_totals_cashondeliverysurcharge_newcreditmemo" />
73
- </reference>
74
- </adminhtml_sales_order_creditmemo_updateqty>
75
-
76
- <adminhtml_sales_order_address>
77
- <reference name="head">
78
- <action method="addJs"><script>zitec_fieldlengths/validator.js</script></action>
79
- <action method="addJs"><script>zitec/dpd/admin/PostcodeAutocompleter.js</script></action>
80
- </reference>
81
- <reference name="before_body_end">
82
- <block name="zitec_addresslength" type="zitec_dpd/adminhtml_sales_order_address_form_addresslength" />
83
- </reference>
84
- </adminhtml_sales_order_address>
85
-
86
-
87
- <adminhtml_customer_edit>
88
- <reference name="head">
89
- <action method="addJs"><script>zitec_fieldlengths/validator.js</script></action>
90
- </reference>
91
- </adminhtml_customer_edit>
92
-
93
-
94
- </layout>
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <layout>
3
+ <adminhtml_sales_order_create_index>
4
+ <reference name="head">
5
+ <action method="addJs"><script>zitec/dpd/admin/sales.js</script></action>
6
+ </reference>
7
+ </adminhtml_sales_order_create_index>
8
+
9
+ <adminhtml_sales_order_shipment_view>
10
+ <reference name="shipment_tracking" >
11
+ <action method="setTemplate">
12
+ <template helper="zitec_dpd/layout/getAdminhtmlTrackingTemplate" />
13
+ </action>
14
+ </reference>
15
+ </adminhtml_sales_order_shipment_view>
16
+ <adminhtml_sales_shipment_index>
17
+ <reference name="head">
18
+ <action method="addItem"><type>skin_css</type><name>zitec_dpd/zitec_dpd.css</name></action>
19
+ </reference>
20
+ </adminhtml_sales_shipment_index>
21
+
22
+ <shipping_tracking_popup translate="label">
23
+ <reference name="shipping.tracking.popup">
24
+ <action method="setTemplate"><template helper="zitec_dpd/layout/changeShippingTrackingPopupTemplate" /></action>
25
+ </reference>
26
+ </shipping_tracking_popup>
27
+
28
+ <adminhtml_sales_order_view>
29
+ <reference name="order_totals">
30
+ <block type="zitec_dpd/order_totals_cashondeliverysurchage" />
31
+ </reference>
32
+ </adminhtml_sales_order_view>
33
+
34
+ <adminhtml_sales_order_invoice_view>
35
+ <reference name="invoice_totals">
36
+ <block type="zitec_dpd/order_invoice_totals_cashondeliverysurcharge" />
37
+ </reference>
38
+ </adminhtml_sales_order_invoice_view>
39
+
40
+ <adminhtml_sales_order_invoice_new>
41
+ <reference name="invoice_totals">
42
+ <block type="zitec_dpd/order_invoice_totals_cashondeliverysurcharge" />
43
+ </reference>
44
+ </adminhtml_sales_order_invoice_new>
45
+
46
+ <adminhtml_sales_order_invoice_new>
47
+ <reference name="invoice_totals">
48
+ <block type="zitec_dpd/order_invoice_totals_cashondeliverysurcharge" />
49
+ </reference>
50
+ </adminhtml_sales_order_invoice_new>
51
+
52
+ <adminhtml_sales_order_invoice_updateqty>
53
+ <reference name="invoice_totals">
54
+ <block type="zitec_dpd/order_totals_cashondeliverysurchage" />
55
+ </reference>
56
+ </adminhtml_sales_order_invoice_updateqty>
57
+
58
+ <adminhtml_sales_order_creditmemo_view>
59
+ <reference name="creditmemo_totals">
60
+ <block type="zitec_dpd/order_creditmemo_totals_cashondeliverysurcharge" />
61
+ </reference>
62
+ </adminhtml_sales_order_creditmemo_view>
63
+
64
+ <adminhtml_sales_order_creditmemo_new>
65
+ <reference name="creditmemo_totals">
66
+ <block type="zitec_dpd/adminhtml_order_totals_cashondeliverysurcharge_newcreditmemo" />
67
+ </reference>
68
+ </adminhtml_sales_order_creditmemo_new>
69
+
70
+ <adminhtml_sales_order_creditmemo_updateqty>
71
+ <reference name="creditmemo_totals">
72
+ <block type="zitec_dpd/adminhtml_order_totals_cashondeliverysurcharge_newcreditmemo" />
73
+ </reference>
74
+ </adminhtml_sales_order_creditmemo_updateqty>
75
+
76
+ <adminhtml_sales_order_address>
77
+ <reference name="head">
78
+ <action method="addJs"><script>zitec_fieldlengths/validator.js</script></action>
79
+ <action method="addJs"><script>zitec/dpd/admin/PostcodeAutocompleter.js</script></action>
80
+ </reference>
81
+ <reference name="before_body_end">
82
+ <block name="zitec_addresslength" type="zitec_dpd/adminhtml_sales_order_address_form_addresslength" />
83
+ </reference>
84
+ </adminhtml_sales_order_address>
85
+
86
+
87
+ <adminhtml_customer_edit>
88
+ <reference name="head">
89
+ <action method="addJs"><script>zitec_fieldlengths/validator.js</script></action>
90
+ </reference>
91
+ </adminhtml_customer_edit>
92
+
93
+
94
+ </layout>
app/design/adminhtml/default/default/layout/zitec_packedshipment.xml CHANGED
@@ -1,34 +1,34 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <layout>
3
- <adminhtml_sales_order_shipment_new>
4
- <reference name="head">
5
- <action method="addJs">
6
- <script>zitec_packedshipment/packedshipment.js</script>
7
- </action>
8
- <action method="addCss">
9
- <name>zitec_packedshipment/windows/themes/default.css</name>
10
- </action>
11
- <action method="addCss">
12
- <name>zitec_packedshipment/windows/themes/magento.css</name>
13
- </action>
14
- <!-- <action method="addCss"><name>zitec_packedshipment/windows/themes/spread.css</name></action>-->
15
- <!-- <action method="addCss"><name>zitec_packedshipment/windows/themes/alert.css</name></action>-->
16
- <!-- <action method="addCss"><name>zitec_packedshipment/windows/themes/alert_lite.css</name></action>-->
17
- <!-- <action method="addCss"><name>zitec_packedshipment/windows/themes/alphacube.css</name></action>-->
18
- <!-- <action method="addCss"><name>zitec_packedshipment/windows/themes/debug.css</name></action>-->
19
-
20
- </reference>
21
- <reference name="order_items">
22
- <action method="setTemplate">
23
- <template helper="zitec_packedshipment/data/changeOrderItemsTemplate" />
24
- </action>
25
- </reference>
26
- <reference name="js">
27
- <block name="address_validation_info_js" type="zitec_packedshipment/addressvalidationinfojs">
28
- <action method="setTemplate">
29
- <template helper="zitec_packedshipment/data/changeAddressValidationJsTemplate" />
30
- </action>
31
- </block>
32
- </reference>
33
- </adminhtml_sales_order_shipment_new>
34
- </layout>
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <layout>
3
+ <adminhtml_sales_order_shipment_new>
4
+ <reference name="head">
5
+ <action method="addJs">
6
+ <script>zitec_packedshipment/packedshipment.js</script>
7
+ </action>
8
+ <action method="addCss">
9
+ <name>zitec_packedshipment/windows/themes/default.css</name>
10
+ </action>
11
+ <action method="addCss">
12
+ <name>zitec_packedshipment/windows/themes/magento.css</name>
13
+ </action>
14
+ <!-- <action method="addCss"><name>zitec_packedshipment/windows/themes/spread.css</name></action>-->
15
+ <!-- <action method="addCss"><name>zitec_packedshipment/windows/themes/alert.css</name></action>-->
16
+ <!-- <action method="addCss"><name>zitec_packedshipment/windows/themes/alert_lite.css</name></action>-->
17
+ <!-- <action method="addCss"><name>zitec_packedshipment/windows/themes/alphacube.css</name></action>-->
18
+ <!-- <action method="addCss"><name>zitec_packedshipment/windows/themes/debug.css</name></action>-->
19
+
20
+ </reference>
21
+ <reference name="order_items">
22
+ <action method="setTemplate">
23
+ <template helper="zitec_packedshipment/data/changeOrderItemsTemplate" />
24
+ </action>
25
+ </reference>
26
+ <reference name="js">
27
+ <block name="address_validation_info_js" type="zitec_packedshipment/addressvalidationinfojs">
28
+ <action method="setTemplate">
29
+ <template helper="zitec_packedshipment/data/changeAddressValidationJsTemplate" />
30
+ </action>
31
+ </block>
32
+ </reference>
33
+ </adminhtml_sales_order_shipment_new>
34
+ </layout>
app/design/adminhtml/default/default/layout/zitec_shippingreports.xml CHANGED
@@ -1,8 +1,8 @@
1
- <?xml version="1.0"?>
2
- <layout version="0.1.0">
3
- <zitec_shippingreports_adminhtml_reports_profitability_index>
4
- <reference name="content">
5
- <block type="zitec_shippingreports/adminhtml_profitability" name="zitec_shippingreports_profitability" />
6
- </reference>
7
- </zitec_shippingreports_adminhtml_reports_profitability_index>
8
  </layout>
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <zitec_shippingreports_adminhtml_reports_profitability_index>
4
+ <reference name="content">
5
+ <block type="zitec_shippingreports/adminhtml_profitability" name="zitec_shippingreports_profitability" />
6
+ </reference>
7
+ </zitec_shippingreports_adminhtml_reports_profitability_index>
8
  </layout>
app/design/adminhtml/default/default/layout/zitec_tablerates.xml CHANGED
@@ -1,38 +1,38 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <layout>
3
- <zitec_tablerates_adminhtml_index_index>
4
- <reference name="content">
5
- <block type="zitec_tablerates/adminhtml_tablerate" name="tablerates">
6
- <block name="zitec_dpd_export" as="zitec_dpd_export" type="zitec_dpd/adminhtml_system_config_button_export" />
7
- </block>
8
- </reference>
9
- </zitec_tablerates_adminhtml_index_index>
10
- <zitec_tablerates_adminhtml_index_grid>
11
- <block type="core/text_list" name="root" output="toHtml">
12
- </block>
13
-
14
- </zitec_tablerates_adminhtml_index_grid>
15
- <zitec_tablerates_adminhtml_index_new>
16
- <update handle="zitec_tablerates_adminhtml_index_edit"/>
17
- </zitec_tablerates_adminhtml_index_new>
18
- <zitec_tablerates_adminhtml_index_edit>
19
- <update handle="editor"/>
20
- <reference name="content">
21
- <block type="zitec_tablerates/adminhtml_tablerate_edit" name="tablerate_edit"></block>
22
- </reference>
23
- </zitec_tablerates_adminhtml_index_edit>
24
-
25
- <zitec_tablerates_adminhtml_index_import>
26
- <update handle="editor"/>
27
- <reference name="content">
28
- <block type="zitec_tablerates/adminhtml_tablerate_import" name="tablerate_edit"></block>
29
- </reference>
30
- </zitec_tablerates_adminhtml_index_import>
31
-
32
- <zitec_tablerates_adminhtml_index_export>
33
- <update handle="editor"/>
34
- <reference name="content">
35
- <block type="zitec_tablerates/adminhtml_tablerate_export" name="tablerate_edit"></block>
36
- </reference>
37
- </zitec_tablerates_adminhtml_index_export>
38
  </layout>
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <layout>
3
+ <zitec_tablerates_adminhtml_index_index>
4
+ <reference name="content">
5
+ <block type="zitec_tablerates/adminhtml_tablerate" name="tablerates">
6
+ <block name="zitec_dpd_export" as="zitec_dpd_export" type="zitec_dpd/adminhtml_system_config_button_export" />
7
+ </block>
8
+ </reference>
9
+ </zitec_tablerates_adminhtml_index_index>
10
+ <zitec_tablerates_adminhtml_index_grid>
11
+ <block type="core/text_list" name="root" output="toHtml">
12
+ </block>
13
+
14
+ </zitec_tablerates_adminhtml_index_grid>
15
+ <zitec_tablerates_adminhtml_index_new>
16
+ <update handle="zitec_tablerates_adminhtml_index_edit"/>
17
+ </zitec_tablerates_adminhtml_index_new>
18
+ <zitec_tablerates_adminhtml_index_edit>
19
+ <update handle="editor"/>
20
+ <reference name="content">
21
+ <block type="zitec_tablerates/adminhtml_tablerate_edit" name="tablerate_edit"></block>
22
+ </reference>
23
+ </zitec_tablerates_adminhtml_index_edit>
24
+
25
+ <zitec_tablerates_adminhtml_index_import>
26
+ <update handle="editor"/>
27
+ <reference name="content">
28
+ <block type="zitec_tablerates/adminhtml_tablerate_import" name="tablerate_edit"></block>
29
+ </reference>
30
+ </zitec_tablerates_adminhtml_index_import>
31
+
32
+ <zitec_tablerates_adminhtml_index_export>
33
+ <update handle="editor"/>
34
+ <reference name="content">
35
+ <block type="zitec_tablerates/adminhtml_tablerate_export" name="tablerate_edit"></block>
36
+ </reference>
37
+ </zitec_tablerates_adminhtml_index_export>
38
  </layout>
app/design/adminhtml/default/default/template/zitec_dpd/potcode/update/available-files.phtml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $files = $this->getAvailableCsvFiles(); ?>
2
+
3
+ <h2><?php echo $this->__("Available import files"); ?></h2>
4
+ <div class="fieldset grid" style="height: 220px; overflow: scroll;">
5
+ <?php if (count($files)): ?>
6
+ <table class="data" >
7
+ <thead>
8
+ <tr class="headings">
9
+ <th><?php echo $this->__("File"); ?></th>
10
+ <th><?php echo $this->__("Uploaded time"); ?></th>
11
+ </tr>
12
+ </thead>
13
+ <tbody>
14
+ <?php foreach($files as $file => $modified): ?>
15
+ <tr>
16
+ <td><?php echo $file; ?></td>
17
+ <td><?php echo date('d-m-Y H:i',$modified); ?></td>
18
+ </tr>
19
+ <?php endforeach; ?>
20
+ </tbody>
21
+ </table>
22
+ <?php else : ?>
23
+ <h3><?php echo $this->__("No update files are available in media/dpd/postcode_updates"); ?></h3>
24
+ <?php endif; ?>
25
+ </div>
app/design/adminhtml/default/default/template/zitec_dpd/sales/order/address/postcode/alert-problem.phtml CHANGED
@@ -1,25 +1,25 @@
1
- <?php
2
- $shippingAddress = $this->getOrder()->getShippingAddress();
3
- $shippingAddressData = $shippingAddress->getData();
4
-
5
- $autoPostcode = (!empty($shippingAddressData['auto_postcode'])) ? $shippingAddressData['auto_postcode'] : '';
6
-
7
- ?>
8
- <script type="text/javascript">
9
- var isPostCodeValid = '<?php echo (!empty($shippingAddressData['valid_auto_postcode'])) ? '1': '0'; ?>';
10
- var postCodeUsedByDPD = '<?php echo $autoPostcode; ?>';
11
-
12
- if (isPostCodeValid != '1') {
13
- $$('.head-shipping-address').each(function (el) {
14
- el.setStyle({
15
- background: 'red'
16
- });
17
- el.up().up().select('fieldset').each(function(el2){
18
- el2.insert({bottom:'<div class="fieldset" style="color: #ff0000;"> <?php echo $this->__(
19
- 'DPD shipping carrier detected an other postcode for current address: %s. You can validate this postcode before scheduling deliveries by clicking the edit button.', $autoPostcode
20
- ); ?> </div>'});
21
- });
22
-
23
- });
24
- }
25
  </script>
1
+ <?php
2
+ $shippingAddress = $this->getOrder()->getShippingAddress();
3
+ $shippingAddressData = $shippingAddress->getData();
4
+
5
+ $autoPostcode = (!empty($shippingAddressData['auto_postcode'])) ? $shippingAddressData['auto_postcode'] : '';
6
+
7
+ ?>
8
+ <script type="text/javascript">
9
+ var isPostCodeValid = '<?php echo (!empty($shippingAddressData['valid_auto_postcode'])) ? '1': '0'; ?>';
10
+ var postCodeUsedByDPD = '<?php echo $autoPostcode; ?>';
11
+
12
+ if (isPostCodeValid != '1') {
13
+ $$('.head-shipping-address').each(function (el) {
14
+ el.setStyle({
15
+ background: 'red'
16
+ });
17
+ el.up().up().select('fieldset').each(function(el2){
18
+ el2.insert({bottom:'<div class="fieldset" style="color: #ff0000;"> <?php echo $this->__(
19
+ 'DPD shipping carrier detected an other postcode for current address: %s. You can validate this postcode before scheduling deliveries by clicking the edit button.', $autoPostcode
20
+ ); ?> </div>'});
21
+ });
22
+
23
+ });
24
+ }
25
  </script>
app/design/adminhtml/default/default/template/zitec_dpd/sales/order/address/postcode/validate.phtml CHANGED
@@ -1,38 +1,38 @@
1
- <div id="postcode_autocomplete" class="autocomplete"></div>
2
- <script type="text/javascript">
3
- $('postcode').insert ({'before': '<a id="refresh-postcode" href="#refresh-postcode"><?php echo $this->__('DPD - search postcode') ?></a> <span id="postcode_indicator" class="autocomplete-indicator" style="display: none">' +
4
- '<img src="<?php echo $this->getSkinUrl('images/ajax-loader.gif') ?>" alt="<?php echo $this->__('Loading...') ?>" class="v-middle"/>' +
5
- '</span>'
6
- });
7
- var postcodeAutocompleter = new PostcodeAutocompleter(
8
- 'postcode',
9
- 'postcode_autocomplete',
10
- '<?php echo $this->getUrl('zitec_dpd/adminhtml_shipment/validatePostcode') ?>',
11
- {
12
- paramName:"query",
13
- minChars:2,
14
- indicator:"postcode_indicator",
15
- updateElement:getSelectionPostcodeValidateId,
16
- evalJSON:'force'
17
- }
18
- );
19
-
20
- $('refresh-postcode').observe('click', function(event) {
21
- console.log(postcodeAutocompleter);
22
- postcodeAutocompleter.activate();
23
- });
24
- function getSelectionPostcodeValidateId(li) {
25
- $('postcode').setValue(li.getAttribute('postcode'));
26
- }
27
-
28
- </script>
29
- <style type="text/css">
30
- #postcode_autocomplete ul{
31
- max-height: 250px;
32
- overflow-y: scroll;
33
- }
34
- #refresh-postcode{
35
- clear: both;
36
- display: block;
37
- }
38
  </style>
1
+ <div id="postcode_autocomplete" class="autocomplete"></div>
2
+ <script type="text/javascript">
3
+ $('postcode').insert ({'before': '<a id="refresh-postcode" href="#refresh-postcode"><?php echo $this->__('DPD - search postcode') ?></a> <span id="postcode_indicator" class="autocomplete-indicator" style="display: none">' +
4
+ '<img src="<?php echo $this->getSkinUrl('images/ajax-loader.gif') ?>" alt="<?php echo $this->__('Loading...') ?>" class="v-middle"/>' +
5
+ '</span>'
6
+ });
7
+ var postcodeAutocompleter = new PostcodeAutocompleter(
8
+ 'postcode',
9
+ 'postcode_autocomplete',
10
+ '<?php echo $this->getUrl('zitec_dpd/adminhtml_shipment/validatePostcode') ?>',
11
+ {
12
+ paramName:"query",
13
+ minChars:2,
14
+ indicator:"postcode_indicator",
15
+ updateElement:getSelectionPostcodeValidateId,
16
+ evalJSON:'force'
17
+ }
18
+ );
19
+
20
+ $('refresh-postcode').observe('click', function(event) {
21
+ console.log(postcodeAutocompleter);
22
+ postcodeAutocompleter.activate();
23
+ });
24
+ function getSelectionPostcodeValidateId(li) {
25
+ $('postcode').setValue(li.getAttribute('postcode'));
26
+ }
27
+
28
+ </script>
29
+ <style type="text/css">
30
+ #postcode_autocomplete ul{
31
+ max-height: 250px;
32
+ overflow-y: scroll;
33
+ }
34
+ #refresh-postcode{
35
+ clear: both;
36
+ display: block;
37
+ }
38
  </style>
app/design/adminhtml/default/default/template/zitec_dpd/sales/order/address/street/alert-problem.phtml CHANGED
@@ -1,23 +1,23 @@
1
- <?php
2
- $shippingAddress = $this->getOrder()->getShippingAddress();
3
-
4
- $isValidStreet = Mage::helper('zitec_dpd')->checkAddressStreetLength($shippingAddress);
5
-
6
- ?>
7
- <script type="text/javascript">
8
- var isStreetLengthValid = '<?php echo (!empty($isValidStreet)) ? '1': '0'; ?>';
9
-
10
- if (isStreetLengthValid != '1') {
11
- $$('.head-shipping-address').each(function (el) {
12
- el.setStyle({
13
- background: 'red'
14
- });
15
- el.up().up().select('fieldset').each(function(el2){
16
- el2.insert({bottom:'<div class="fieldset" style="color: #ff0000;"> <?php echo $this->__(
17
- 'DPD shipping carrier requirements: The length of address provided by your customer is too long. Please provide a maximum 70 characters length address (street field).'
18
- ); ?> </div>'});
19
- });
20
-
21
- });
22
- }
23
  </script>
1
+ <?php
2
+ $shippingAddress = $this->getOrder()->getShippingAddress();
3
+
4
+ $isValidStreet = Mage::helper('zitec_dpd')->checkAddressStreetLength($shippingAddress);
5
+
6
+ ?>
7
+ <script type="text/javascript">
8
+ var isStreetLengthValid = '<?php echo (!empty($isValidStreet)) ? '1': '0'; ?>';
9
+
10
+ if (isStreetLengthValid != '1') {
11
+ $$('.head-shipping-address').each(function (el) {
12
+ el.setStyle({
13
+ background: 'red'
14
+ });
15
+ el.up().up().select('fieldset').each(function(el2){
16
+ el2.insert({bottom:'<div class="fieldset" style="color: #ff0000;"> <?php echo $this->__(
17
+ 'DPD shipping carrier requirements: The length of address provided by your customer is too long. Please provide a maximum 70 characters length address (street field).'
18
+ ); ?> </div>'});
19
+ });
20
+
21
+ });
22
+ }
23
  </script>
app/design/adminhtml/default/default/template/zitec_dpd/sales/order/shipment/postcode/autocompleter.phtml CHANGED
@@ -1,15 +1,15 @@
1
- <?php $foundAddresses = $this->getFoundAddresses(); ?>
2
-
3
- <?php if (is_array($foundAddresses) && count($foundAddresses)): ?>
4
- <ul>
5
- <?php foreach($foundAddresses as $address) : ?>
6
- <li postcode="<?php echo $address['postcode']; ?>">
7
- <div style="float:right; color:red; font-weight:bold;">[<?php echo $address['region']; ?>]</div>
8
- <strong><?php echo $address['address']; ?></strong><br/>
9
- <span class="informal"><?php echo $address['postcode']; ?></span>
10
- </li>
11
- <?php endforeach; ?>
12
- </ul>
13
- <?php else : ?>
14
- <ul><li><?php echo $this->__('No results available'); ?></li></ul>
15
  <?php endif; ?>
1
+ <?php $foundAddresses = $this->getFoundAddresses(); ?>
2
+
3
+ <?php if (is_array($foundAddresses) && count($foundAddresses)): ?>
4
+ <ul>
5
+ <?php foreach($foundAddresses as $address) : ?>
6
+ <li postcode="<?php echo $address['postcode']; ?>">
7
+ <div style="float:right; color:red; font-weight:bold;">[<?php echo $address['region']; ?>]</div>
8
+ <strong><?php echo $address['address']; ?></strong><br/>
9
+ <span class="informal"><?php echo $address['postcode']; ?></span>
10
+ </li>
11
+ <?php endforeach; ?>
12
+ </ul>
13
+ <?php else : ?>
14
+ <ul><li><?php echo $this->__('No results available'); ?></li></ul>
15
  <?php endif; ?>
app/design/adminhtml/default/default/template/zitec_dpd/sales/order/shipment/view/tracking.phtml CHANGED
@@ -1,87 +1,87 @@
1
- <?
2
- /* @var $this Zitec_Dpd_Block_Adminhtml_Sales_Order_Shipment_View_Tracking */
3
- ?>
4
- <div class="field-row grid" id="shipment_tracking_info">
5
- <table cellspacing="0" class="data">
6
- <col width="100" />
7
- <col />
8
- <col />
9
- <col width="80" />
10
- <thead>
11
- <tr class="headings">
12
- <th><?php echo Mage::helper('sales')->__('Carrier') ?></th>
13
- <th><?php echo Mage::helper('sales')->__('Title') ?></th>
14
- <th><?php echo Mage::helper('sales')->__('Number') ?></th>
15
- <?php if($this->isDPD()): ?>
16
-
17
- <th><?php echo Mage::helper('sales')->__('Label') ?></th>
18
- <?php endif; ?>
19
- <th class="last"><?php echo Mage::helper('sales')->__('Action') ?></th>
20
- </tr>
21
- </thead>
22
- <tfoot>
23
- <tr>
24
- <td>
25
- <select name="carrier" class="select" style="width:110px" onchange="selectCarrier(this)">
26
- <?php foreach ($this->getCarriers() as $_code=>$_name): ?>
27
- <option value="<?php echo $_code ?>"><?php echo $_name ?></option>
28
- <?php endforeach; ?>
29
- </select>
30
- </td>
31
- <td><input class="input-text" type="text" id="tracking_title" name="title" value="" /></td>
32
- <td><input class="input-text" type="text" id="tracking_number" name="number" value="" /></td>
33
- <?php if($this->isDPD()): ?>
34
- <td></td>
35
- <?php endif; ?>
36
- <td class="last"><?php echo $this->getSaveButtonHtml() ?></td>
37
- </tr>
38
- </tfoot>
39
- <?php if($_tracks = $this->getShipment()->getAllTracks()): ?>
40
- <tbody>
41
- <?php $i=0;foreach ($_tracks as $_track):$i++ ?>
42
- <tr class="<?php echo ($i%2==0)?'even':'odd' ?>">
43
- <td><?php echo $this->getCarrierTitle($_track->getCarrierCode()) ?></td>
44
- <td><?php echo $this->escapeHtml($_track->getTitle()) ?></td>
45
- <td>
46
- <?php if ($_track->isCustom()): ?>
47
- <?php echo $this->escapeHtml($_track->getNumber()) ?>
48
- <?php else: ?>
49
- <a href="#" onclick="popWin('<?php echo $this->helper('shipping')->getTrackingPopupUrlBySalesModel($_track) ?>','trackorder','width=800,height=600,resizable=yes,scrollbars=yes')"><?php echo $_track->getNumber() ?></a>
50
- <div id="shipment_tracking_info_response_<?php echo $_track->getId() ?>"></div>
51
- <?php endif; ?>
52
- </td>
53
- <?php if($this->isDpdTrack($_track)): ?>
54
- <td>
55
- <a href="<?php echo $this->helper('adminhtml')->getUrl('zitec_dpd/adminhtml_shipment/getlabelpdf', Array('shipmentid' => $this->getShipment()->getId())); ?>" style="display:block;margin-bottom:0.6em;"><?php echo $this->__('PDF'); ?></a>
56
- </td>
57
- <?php else: ?>
58
- <td />
59
- <?php endif; ?>
60
- <td class="last"><a href="#" onclick="deleteTrackingNumber('<?php echo $this->getRemoveUrl($_track) ?>', <?php echo $this->isDpdTrack($_track) ? "true" : "false"; ?>); return false;"><?php echo Mage::helper('sales')->__('Delete') ?></a></td>
61
- </tr>
62
- <?php endforeach; ?>
63
- </tbody>
64
- <?php endif; ?>
65
- </table>
66
- </div>
67
- <script type="text/javascript">
68
- //<![CDATA[
69
-
70
- var zitecDPDVars = {
71
- dpdDeleteConfirmationMessage: "<?php echo $this->__("Taking this action will cancel the shipment with DPD. Are you sure you want to continue?"); ?>",
72
- defaultDeleteMessage: "<?php echo Mage::helper('sales')->__('Are you sure?') ?>"
73
- }
74
-
75
- function selectCarrier(elem) {
76
- var option = elem.options[elem.selectedIndex];
77
- $('tracking_title').value = option.value && option.value != 'custom' ? option.text : '';
78
- }
79
-
80
- function deleteTrackingNumber(url, isDpdTrack) {
81
- var confirmationMessage = isDpdTrack ? zitecDPDVars.dpdDeleteConfirmationMessage : zitecDPDVars.defaultDeleteMessage;
82
- if (confirm(confirmationMessage)) {
83
- submitAndReloadArea($('shipment_tracking_info').parentNode, url)
84
- }
85
- }
86
- //]]>
1
+ <?
2
+ /* @var $this Zitec_Dpd_Block_Adminhtml_Sales_Order_Shipment_View_Tracking */
3
+ ?>
4
+ <div class="field-row grid" id="shipment_tracking_info">
5
+ <table cellspacing="0" class="data">
6
+ <col width="100" />
7
+ <col />
8
+ <col />
9
+ <col width="80" />
10
+ <thead>
11
+ <tr class="headings">
12
+ <th><?php echo Mage::helper('sales')->__('Carrier') ?></th>
13
+ <th><?php echo Mage::helper('sales')->__('Title') ?></th>
14
+ <th><?php echo Mage::helper('sales')->__('Number') ?></th>
15
+ <?php if($this->isDPD()): ?>
16
+
17
+ <th><?php echo Mage::helper('sales')->__('Label') ?></th>
18
+ <?php endif; ?>
19
+ <th class="last"><?php echo Mage::helper('sales')->__('Action') ?></th>
20
+ </tr>
21
+ </thead>
22
+ <tfoot>
23
+ <tr>
24
+ <td>
25
+ <select name="carrier" class="select" style="width:110px" onchange="selectCarrier(this)">
26
+