Transsmart_Shipping - Version 1.0.0

Version Notes

1.0.0

Download this release

Release Info

Developer Techtwo Webdevelopment B.V.
Extension Transsmart_Shipping
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

Files changed (116) hide show
  1. app/code/community/Transsmart/Shipping/Block/Adminhtml/Sales/Order/Grid.php +62 -0
  2. app/code/community/Transsmart/Shipping/Block/Adminhtml/Sales/Order/Shipment/Create/Detail.php +213 -0
  3. app/code/community/Transsmart/Shipping/Block/Adminhtml/Sales/Order/Shipment/Create/Package.php +92 -0
  4. app/code/community/Transsmart/Shipping/Block/Adminhtml/Sales/Order/Shipment/Masscreate.php +35 -0
  5. app/code/community/Transsmart/Shipping/Block/Adminhtml/Sales/Order/Shipment/Masscreate/Form.php +175 -0
  6. app/code/community/Transsmart/Shipping/Block/Adminhtml/Sales/Order/Shipment/View/Detail.php +164 -0
  7. app/code/community/Transsmart/Shipping/Block/Adminhtml/Sales/Order/Shipment/View/Package.php +59 -0
  8. app/code/community/Transsmart/Shipping/Block/Adminhtml/Sales/Order/View/Tab/Shipments.php +76 -0
  9. app/code/community/Transsmart/Shipping/Block/Adminhtml/Sales/Shipment/Grid.php +74 -0
  10. app/code/community/Transsmart/Shipping/Block/Adminhtml/Sales/Shipment/Grid/Renderer/Link.php +20 -0
  11. app/code/community/Transsmart/Shipping/Block/Adminhtml/Shipping/Location/Info.php +31 -0
  12. app/code/community/Transsmart/Shipping/Block/Adminhtml/System/Config/Form/Field/Fetch.php +110 -0
  13. app/code/community/Transsmart/Shipping/Block/Adminhtml/System/Config/Form/Fieldset/Carrierprofile.php +41 -0
  14. app/code/community/Transsmart/Shipping/Block/Adminhtml/System/Config/Form/Fieldset/Carrierprofile/Header.php +35 -0
  15. app/code/community/Transsmart/Shipping/Block/Adminhtml/System/Config/Form/Fieldset/Versioninfo.php +49 -0
  16. app/code/community/Transsmart/Shipping/Block/Location/Selector.php +18 -0
  17. app/code/community/Transsmart/Shipping/Helper/Data.php +242 -0
  18. app/code/community/Transsmart/Shipping/Helper/Location.php +355 -0
  19. app/code/community/Transsmart/Shipping/Helper/Pickupaddress.php +123 -0
  20. app/code/community/Transsmart/Shipping/Helper/Shipment.php +560 -0
  21. app/code/community/Transsmart/Shipping/Model/Abstract.php +37 -0
  22. app/code/community/Transsmart/Shipping/Model/Adminhtml/Observer.php +304 -0
  23. app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Backend/Localized.php +24 -0
  24. app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Source/Basedata/Abstract.php +45 -0
  25. app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Source/Basedata/Carrierprofile.php +37 -0
  26. app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Source/Basedata/Costcenter.php +18 -0
  27. app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Source/Basedata/Emailtype.php +18 -0
  28. app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Source/Basedata/Incoterm.php +18 -0
  29. app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Source/Basedata/Packagetype.php +18 -0
  30. app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Source/Basedata/Shipmentlocation.php +18 -0
  31. app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Source/Environment.php +33 -0
  32. app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Source/Mapping/Attribute.php +37 -0
  33. app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Source/Mapping/Street.php +53 -0
  34. app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Source/Method.php +38 -0
  35. app/code/community/Transsmart/Shipping/Model/Carrier.php +41 -0
  36. app/code/community/Transsmart/Shipping/Model/Carrierprofile.php +123 -0
  37. app/code/community/Transsmart/Shipping/Model/Client.php +713 -0
  38. app/code/community/Transsmart/Shipping/Model/Costcenter.php +41 -0
  39. app/code/community/Transsmart/Shipping/Model/Emailtype.php +41 -0
  40. app/code/community/Transsmart/Shipping/Model/Incoterm.php +41 -0
  41. app/code/community/Transsmart/Shipping/Model/Observer.php +354 -0
  42. app/code/community/Transsmart/Shipping/Model/Packagetype.php +53 -0
  43. app/code/community/Transsmart/Shipping/Model/Resource/Carrier.php +24 -0
  44. app/code/community/Transsmart/Shipping/Model/Resource/Carrier/Collection.php +19 -0
  45. app/code/community/Transsmart/Shipping/Model/Resource/Carrierprofile.php +76 -0
  46. app/code/community/Transsmart/Shipping/Model/Resource/Carrierprofile/Collection.php +110 -0
  47. app/code/community/Transsmart/Shipping/Model/Resource/Costcenter.php +24 -0
  48. app/code/community/Transsmart/Shipping/Model/Resource/Costcenter/Collection.php +19 -0
  49. app/code/community/Transsmart/Shipping/Model/Resource/Emailtype.php +24 -0
  50. app/code/community/Transsmart/Shipping/Model/Resource/Emailtype/Collection.php +19 -0
  51. app/code/community/Transsmart/Shipping/Model/Resource/Incoterm.php +24 -0
  52. app/code/community/Transsmart/Shipping/Model/Resource/Incoterm/Collection.php +19 -0
  53. app/code/community/Transsmart/Shipping/Model/Resource/Packagetype.php +24 -0
  54. app/code/community/Transsmart/Shipping/Model/Resource/Packagetype/Collection.php +19 -0
  55. app/code/community/Transsmart/Shipping/Model/Resource/Servicelevel/Other.php +24 -0
  56. app/code/community/Transsmart/Shipping/Model/Resource/Servicelevel/Other/Collection.php +19 -0
  57. app/code/community/Transsmart/Shipping/Model/Resource/Servicelevel/Time.php +24 -0
  58. app/code/community/Transsmart/Shipping/Model/Resource/Servicelevel/Time/Collection.php +19 -0
  59. app/code/community/Transsmart/Shipping/Model/Resource/Shipmentlocation.php +24 -0
  60. app/code/community/Transsmart/Shipping/Model/Resource/Shipmentlocation/Collection.php +19 -0
  61. app/code/community/Transsmart/Shipping/Model/Resource/Sync.php +17 -0
  62. app/code/community/Transsmart/Shipping/Model/Resource/Sync/Collection.php +14 -0
  63. app/code/community/Transsmart/Shipping/Model/Sales/Resource/Order.php +66 -0
  64. app/code/community/Transsmart/Shipping/Model/Servicelevel/Other.php +36 -0
  65. app/code/community/Transsmart/Shipping/Model/Servicelevel/Time.php +36 -0
  66. app/code/community/Transsmart/Shipping/Model/Shipmentlocation.php +75 -0
  67. app/code/community/Transsmart/Shipping/Model/Shipping/Carrier/Abstract.php +139 -0
  68. app/code/community/Transsmart/Shipping/Model/Shipping/Carrier/Delivery.php +12 -0
  69. app/code/community/Transsmart/Shipping/Model/Shipping/Carrier/Pickup.php +12 -0
  70. app/code/community/Transsmart/Shipping/Model/Sync.php +743 -0
  71. app/code/community/Transsmart/Shipping/controllers/Adminhtml/Transsmart/Shipping/LocationController.php +35 -0
  72. app/code/community/Transsmart/Shipping/controllers/Adminhtml/Transsmart/Shipping/ShipmentController.php +475 -0
  73. app/code/community/Transsmart/Shipping/controllers/Adminhtml/TranssmartController.php +53 -0
  74. app/code/community/Transsmart/Shipping/controllers/LocationController.php +22 -0
  75. app/code/community/Transsmart/Shipping/etc/adminhtml.xml +34 -0
  76. app/code/community/Transsmart/Shipping/etc/config.xml +302 -0
  77. app/code/community/Transsmart/Shipping/etc/jstranslator.xml +25 -0
  78. app/code/community/Transsmart/Shipping/etc/system.xml +321 -0
  79. app/code/community/Transsmart/Shipping/sql/transsmart_shipping_setup/install-1.0.0.php +558 -0
  80. app/code/community/Transsmart/Shipping/ssl/CARoot.crt +25 -0
  81. app/design/adminhtml/base/default/layout/transsmart_shipping.xml +102 -0
  82. app/design/adminhtml/base/default/template/transsmart/shipping/location/info.phtml +18 -0
  83. app/design/adminhtml/base/default/template/transsmart/shipping/location/selector.phtml +72 -0
  84. app/design/adminhtml/base/default/template/transsmart/shipping/sales/order/address/form/container.phtml +49 -0
  85. app/design/adminhtml/base/default/template/transsmart/shipping/sales/order/shipment/address/form/container.phtml +53 -0
  86. app/design/adminhtml/base/default/template/transsmart/shipping/sales/order/shipment/create/action.phtml +26 -0
  87. app/design/adminhtml/base/default/template/transsmart/shipping/sales/order/shipment/create/detail.phtml +91 -0
  88. app/design/adminhtml/base/default/template/transsmart/shipping/sales/order/shipment/create/package.phtml +134 -0
  89. app/design/adminhtml/base/default/template/transsmart/shipping/sales/order/shipment/masscreate/form.phtml +235 -0
  90. app/design/adminhtml/base/default/template/transsmart/shipping/sales/order/shipment/view/detail.phtml +47 -0
  91. app/design/adminhtml/base/default/template/transsmart/shipping/sales/order/shipment/view/package.phtml +42 -0
  92. app/design/adminhtml/base/default/template/transsmart/shipping/system/config/form/field/fetch.phtml +101 -0
  93. app/design/frontend/base/default/layout/transsmart_shipping.xml +90 -0
  94. app/design/frontend/base/default/template/transsmart/shipping/location/selector.phtml +65 -0
  95. app/design/frontend/base/default/template/transsmart/shipping/onepage/progress/pickup.phtml +26 -0
  96. app/etc/modules/Transsmart_Shipping.xml +16 -0
  97. app/locale/nl_NL/Transsmart_Shipping.csv +117 -0
  98. js/transsmart/shipping/admin/pickup_selector.js +128 -0
  99. js/transsmart/shipping/base64.js +113 -0
  100. js/transsmart/shipping/logger.js +19 -0
  101. js/transsmart/shipping/pickup_selector.js +899 -0
  102. package.xml +18 -0
  103. skin/adminhtml/base/default/transsmart/shipping/images/arrow.png +0 -0
  104. skin/adminhtml/base/default/transsmart/shipping/images/checkmark.png +0 -0
  105. skin/adminhtml/base/default/transsmart/shipping/images/close-btn.png +0 -0
  106. skin/adminhtml/base/default/transsmart/shipping/images/info-icon.png +0 -0
  107. skin/adminhtml/base/default/transsmart/shipping/images/loader.gif +0 -0
  108. skin/adminhtml/base/default/transsmart/shipping/images/radio.png +0 -0
  109. skin/adminhtml/base/default/transsmart/shipping/pickup_selector.css +342 -0
  110. skin/adminhtml/base/default/transsmart/shipping/styles.css +30 -0
  111. skin/frontend/base/default/transsmart/shipping/images/arrow.png +0 -0
  112. skin/frontend/base/default/transsmart/shipping/images/close-btn.png +0 -0
  113. skin/frontend/base/default/transsmart/shipping/images/info-icon.png +0 -0
  114. skin/frontend/base/default/transsmart/shipping/images/loader.gif +0 -0
  115. skin/frontend/base/default/transsmart/shipping/images/radio.png +0 -0
  116. skin/frontend/base/default/transsmart/shipping/pickup_selector.css +342 -0
app/code/community/Transsmart/Shipping/Block/Adminhtml/Sales/Order/Grid.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
9
+ {
10
+ /**
11
+ * Prepare grid massaction actions
12
+ *
13
+ * @return $this
14
+ */
15
+ protected function _prepareMassaction()
16
+ {
17
+ parent::_prepareMassaction();
18
+ $this->getMassactionBlock()->removeItem('print_shipping_label');
19
+
20
+ if (Mage::getSingleton('admin/session')->isAllowed('sales/shipment')) {
21
+ $this->getMassactionBlock()->addItem('transsmart_create_shipment', array(
22
+ 'label'=> Mage::helper('transsmart_shipping')->__('Transsmart: Create Shipment(s)'),
23
+ 'url' => $this->getUrl('*/transsmart_shipping_shipment/massCreate'),
24
+ ));
25
+
26
+ $this->getMassactionBlock()->addItem('transsmart_book_and_print', array(
27
+ 'label'=> Mage::helper('transsmart_shipping')->__('Transsmart: Book & Print'),
28
+ 'url' => $this->getUrl('*/transsmart_shipping_shipment/massBookAndPrint'),
29
+ ));
30
+
31
+ $this->getMassactionBlock()->addItem('transsmart_booking', array(
32
+ 'label'=> Mage::helper('transsmart_shipping')->__('Transsmart: Book Shipment(s)'),
33
+ 'url' => $this->getUrl('*/transsmart_shipping_shipment/massBooking'),
34
+ ));
35
+
36
+ $this->getMassactionBlock()->addItem('transsmart_label', array(
37
+ 'label'=> Mage::helper('transsmart_shipping')->__('Transsmart: Print Label(s)'),
38
+ 'url' => $this->getUrl('*/transsmart_shipping_shipment/massLabel'),
39
+ ));
40
+ }
41
+
42
+ return $this;
43
+ }
44
+
45
+ /**
46
+ * Prepare and add columns to grid
47
+ *
48
+ * @return $this
49
+ */
50
+ protected function _prepareColumns()
51
+ {
52
+ $this->addColumnAfter('transsmart_status', array(
53
+ 'header' => Mage::helper('sales')->__('Transsmart Status'),
54
+ 'index' => 'transsmart_status',
55
+ 'type' => 'options',
56
+ 'width' => '70px',
57
+ 'options' => Mage::helper('transsmart_shipping')->getOrderStatuses(),
58
+ ), 'status');
59
+
60
+ return parent::_prepareColumns();
61
+ }
62
+ }
app/code/community/Transsmart/Shipping/Block/Adminhtml/Sales/Order/Shipment/Create/Detail.php ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Block_Adminhtml_Sales_Order_Shipment_Create_Detail extends Mage_Adminhtml_Block_Template
9
+ {
10
+ protected $_defaultCarrierprofileId;
11
+ protected $_defaultShipmentlocationId;
12
+ protected $_defaultEmailtypeId;
13
+ protected $_defaultCostcenterId;
14
+ protected $_defaultIncotermId;
15
+
16
+ /**
17
+ * Constructor.
18
+ */
19
+ public function _construct()
20
+ {
21
+ $this->setTemplate('transsmart/shipping/sales/order/shipment/create/detail.phtml');
22
+ return parent::_construct();
23
+ }
24
+
25
+ /**
26
+ * Prepares layout of block
27
+ *
28
+ * @return $this
29
+ */
30
+ protected function _prepareLayout()
31
+ {
32
+ $this->setChild('package', $this->getLayout()->createBlock(
33
+ 'transsmart_shipping/adminhtml_sales_order_shipment_create_package'
34
+ ));
35
+ return parent::_prepareLayout();
36
+ }
37
+
38
+ /**
39
+ * Get store for current shipment.
40
+ *
41
+ * @return Mage_Core_Model_Store|null
42
+ */
43
+ public function getStore()
44
+ {
45
+ $shipment = Mage::registry('current_shipment');
46
+ if ($shipment) {
47
+ return $shipment->getStore();
48
+ }
49
+ return null;
50
+ }
51
+
52
+ /**
53
+ * Returns TRUE if the carrierprofile may be changed. This is not allowed when the order has a pickup shipping
54
+ * method.
55
+ *
56
+ * @return bool
57
+ */
58
+ public function getAllowChangeCarrierprofile()
59
+ {
60
+ $shipment = Mage::registry('current_shipment');
61
+ if ($shipment) {
62
+ $shippingMethod = $shipment->getOrder()->getShippingMethod(false);
63
+ if (Mage::helper('transsmart_shipping')->isTranssmartPickup($shippingMethod)) {
64
+ return false;
65
+ }
66
+ }
67
+ return true;
68
+ }
69
+
70
+ /**
71
+ * Get available carrier profiles.
72
+ *
73
+ * @return array
74
+ */
75
+ public function getAvailableCarrierprofiles()
76
+ {
77
+ $carrierprofiles = Mage::getResourceSingleton('transsmart_shipping/carrierprofile_collection')->toOptionHash();
78
+ foreach ($carrierprofiles as $_id => $_name) {
79
+ $_method = Mage::getStoreConfig('transsmart_carrier_profiles/carrierprofile_' . $_id . '/method');
80
+ if ($_method == Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Method::PICKUP) {
81
+ unset($carrierprofiles[$_id]);
82
+ }
83
+ }
84
+ return $carrierprofiles;
85
+ }
86
+
87
+ /**
88
+ * Get the default carrier profile ID for the current shipment.
89
+ *
90
+ * @return int
91
+ */
92
+ public function getDefaultCarrierprofileId()
93
+ {
94
+ if (empty($this->_defaultCarrierprofileId)) {
95
+ $this->_defaultCarrierprofileId = Mage::helper('transsmart_shipping/shipment')
96
+ ->getDefaultCarrierprofileId(Mage::registry('current_shipment'));
97
+ }
98
+ return $this->_defaultCarrierprofileId;
99
+ }
100
+
101
+ /**
102
+ * Get the default carrier profile for the current shipment.
103
+ *
104
+ * @return string
105
+ */
106
+ public function getDefaultCarrierprofile()
107
+ {
108
+ $carrierprofile = Mage::getResourceSingleton('transsmart_shipping/carrierprofile_collection')
109
+ ->joinCarrier()
110
+ ->joinServicelevelTime()
111
+ ->joinServicelevelOther()
112
+ ->getItemById($this->getDefaultCarrierprofileId());
113
+ if ($carrierprofile) {
114
+ return $carrierprofile->getName();
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Get available shipment locations.
120
+ *
121
+ * @return array
122
+ */
123
+ public function getShipmentlocations()
124
+ {
125
+ return Mage::getResourceSingleton('transsmart_shipping/shipmentlocation_collection')->toOptionHash();
126
+ }
127
+
128
+ /**
129
+ * Get the default shipment location for the current shipment.
130
+ *
131
+ * @return array
132
+ */
133
+ public function getDefaultShipmentlocationId()
134
+ {
135
+ if (is_null($this->_defaultShipmentlocationId)) {
136
+ $this->_defaultShipmentlocationId = Mage::helper('transsmart_shipping/shipment')
137
+ ->getDefaultShipmentlocationId($this->getStore());
138
+ }
139
+ return $this->_defaultShipmentlocationId;
140
+ }
141
+
142
+ /**
143
+ * Get available email types.
144
+ *
145
+ * @return array
146
+ */
147
+ public function getEmailtypes()
148
+ {
149
+ return Mage::getResourceSingleton('transsmart_shipping/emailtype_collection')->toOptionHash();
150
+ }
151
+
152
+ /**
153
+ * Get the default email type for the current shipment.
154
+ *
155
+ * @return array
156
+ */
157
+ public function getDefaultEmailtypeId()
158
+ {
159
+ if (is_null($this->_defaultEmailtypeId)) {
160
+ $this->_defaultEmailtypeId = Mage::helper('transsmart_shipping/shipment')
161
+ ->getDefaultEmailtypeId($this->getStore());
162
+ }
163
+ return $this->_defaultEmailtypeId;
164
+ }
165
+
166
+ /**
167
+ * Get available cost centers.
168
+ *
169
+ * @return array
170
+ */
171
+ public function getCostcenters()
172
+ {
173
+ return Mage::getResourceSingleton('transsmart_shipping/costcenter_collection')->toOptionHash();
174
+ }
175
+
176
+ /**
177
+ * Get the default cost center for the current shipment.
178
+ *
179
+ * @return array
180
+ */
181
+ public function getDefaultCostcenterId()
182
+ {
183
+ if (is_null($this->_defaultCostcenterId)) {
184
+ $this->_defaultCostcenterId = Mage::helper('transsmart_shipping/shipment')
185
+ ->getDefaultCostcenterId($this->getStore());
186
+ }
187
+ return $this->_defaultCostcenterId;
188
+ }
189
+
190
+ /**
191
+ * Get available incoterms.
192
+ *
193
+ * @return array
194
+ */
195
+ public function getIncoterms()
196
+ {
197
+ return Mage::getResourceSingleton('transsmart_shipping/incoterm_collection')->toOptionHash();
198
+ }
199
+
200
+ /**
201
+ * Get the default incoterm for the current shipment.
202
+ *
203
+ * @return array
204
+ */
205
+ public function getDefaultIncotermId()
206
+ {
207
+ if (is_null($this->_defaultIncotermId)) {
208
+ $this->_defaultIncotermId = Mage::helper('transsmart_shipping/shipment')
209
+ ->getDefaultIncotermId($this->getStore());
210
+ }
211
+ return $this->_defaultIncotermId;
212
+ }
213
+ }
app/code/community/Transsmart/Shipping/Block/Adminhtml/Sales/Order/Shipment/Create/Package.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Block_Adminhtml_Sales_Order_Shipment_Create_Package extends Mage_Adminhtml_Block_Template
9
+ {
10
+ /**
11
+ * Constructor.
12
+ */
13
+ public function _construct()
14
+ {
15
+ $this->setTemplate('transsmart/shipping/sales/order/shipment/create/package.phtml');
16
+ return parent::_construct();
17
+ }
18
+
19
+ /**
20
+ * Prepares layout of block
21
+ *
22
+ * @return $this
23
+ */
24
+ protected function _prepareLayout()
25
+ {
26
+ $this->setChild('add_button',
27
+ $this->getLayout()->createBlock('adminhtml/widget_button')
28
+ ->setData(array(
29
+ 'label' => $this->__('Add Package'),
30
+ 'class' => '',
31
+ 'onclick' => 'tssPackageControl.add()'
32
+ ))
33
+
34
+ );
35
+ return parent::_prepareLayout();
36
+ }
37
+
38
+ /**
39
+ * Get store for current shipment.
40
+ *
41
+ * @return Mage_Core_Model_Store|null
42
+ */
43
+ public function getStore()
44
+ {
45
+ $shipment = Mage::registry('current_shipment');
46
+ if ($shipment) {
47
+ return $shipment->getStore();
48
+ }
49
+ return null;
50
+ }
51
+
52
+ /**
53
+ * Get package type configuration.
54
+ *
55
+ * @return array
56
+ */
57
+ public function getPackageConfig()
58
+ {
59
+ $result = array(
60
+ 'default' => 0,
61
+ 'types' => array(),
62
+ );
63
+
64
+ if (($store = $this->getStore())) {
65
+ $result['default'] = Mage::helper('transsmart_shipping/shipment')->getDefaultPackagetypeId($store);
66
+ }
67
+ else {
68
+ $result['types'][] = array(
69
+ 'id' => 0,
70
+ 'name' => $this->__('Use Configured Default')
71
+ );
72
+ }
73
+
74
+ $format = array(
75
+ 'locale' => new Zend_Locale(Mage::app()->getLocale()->getLocale()),
76
+ 'number_format' => '0.###'
77
+ );
78
+
79
+ foreach (Mage::getResourceSingleton('transsmart_shipping/packagetype_collection') as $_packagetype) {
80
+ $result['types'][] = array(
81
+ 'id' => $_packagetype->getId(),
82
+ 'name' => $_packagetype->getName(),
83
+ 'length' => Zend_Locale_Format::toNumber((float)$_packagetype->getLength(), $format),
84
+ 'width' => Zend_Locale_Format::toNumber((float)$_packagetype->getWidth(), $format),
85
+ 'height' => Zend_Locale_Format::toNumber((float)$_packagetype->getHeight(), $format),
86
+ 'weight' => Zend_Locale_Format::toNumber((float)$_packagetype->getWeight(), $format),
87
+ );
88
+ }
89
+
90
+ return $result;
91
+ }
92
+ }
app/code/community/Transsmart/Shipping/Block/Adminhtml/Sales/Order/Shipment/Masscreate.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Block_Adminhtml_Sales_Order_Shipment_Masscreate
9
+ extends Mage_Adminhtml_Block_Widget_Form_Container
10
+ {
11
+ public function __construct()
12
+ {
13
+ $this->_blockGroup = 'transsmart_shipping';
14
+ $this->_objectId = 'order_ids';
15
+ $this->_controller = 'adminhtml_sales_order_shipment';
16
+ $this->_mode = 'masscreate';
17
+
18
+ parent::__construct();
19
+
20
+ //$this->_updateButton('save', 'label', Mage::helper('sales')->__('Submit Shipment'));
21
+ $this->_removeButton('save');
22
+ $this->_removeButton('delete');
23
+ }
24
+
25
+ public function getHeaderText()
26
+ {
27
+ $header = $this->__('Create New Shipment(s) for Order(s)');
28
+ return $header;
29
+ }
30
+
31
+ public function getBackUrl()
32
+ {
33
+ return $this->getUrl('*/sales_order/index');
34
+ }
35
+ }
app/code/community/Transsmart/Shipping/Block/Adminhtml/Sales/Order/Shipment/Masscreate/Form.php ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Block_Adminhtml_Sales_Order_Shipment_Masscreate_Form extends Mage_Adminhtml_Block_Sales_Order_Abstract
9
+ {
10
+ /**
11
+ * Constructor.
12
+ */
13
+ public function _construct()
14
+ {
15
+ $this->setTemplate('transsmart/shipping/sales/order/shipment/masscreate/form.phtml');
16
+ return parent::_construct();
17
+ }
18
+
19
+ /**
20
+ * Prepares layout of block
21
+ *
22
+ * @return $this
23
+ */
24
+ protected function _prepareLayout()
25
+ {
26
+ $this->setChild('package', $this->getLayout()->createBlock(
27
+ 'transsmart_shipping/adminhtml_sales_order_shipment_create_package'
28
+ ));
29
+
30
+ $this->setChild('action', $this->getLayout()->createBlock(
31
+ 'adminhtml/template',
32
+ 'shipment.create.transsmart.action',
33
+ array(
34
+ 'template' => 'transsmart/shipping/sales/order/shipment/create/action.phtml'
35
+ )
36
+ ));
37
+
38
+ $this->setChild(
39
+ 'submit_button',
40
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
41
+ 'label' => Mage::helper('sales')->__('Create Shipment'),
42
+ 'class' => 'save submit-button',
43
+ 'onclick' => 'submitShipment(this);',
44
+ ))
45
+ );
46
+
47
+ return parent::_prepareLayout();
48
+ }
49
+
50
+ /**
51
+ * @return string
52
+ */
53
+ public function getSaveUrl()
54
+ {
55
+ return $this->getUrl('*/*/massCreateSave');
56
+ }
57
+
58
+ /**
59
+ * @return Mage_Sales_Model_Resource_Order_Collection
60
+ */
61
+ public function getOrderCollection()
62
+ {
63
+ return $this->getParentBlock()->getOrderCollection();
64
+ }
65
+
66
+ /**
67
+ * @param Mage_Sales_Model_Order $order
68
+ * @return float
69
+ */
70
+ public function getQtyToShip($order)
71
+ {
72
+ $qty = 0.0;
73
+ if ($order->canShip()) {
74
+ foreach ($order->getAllItems() as $_item) {
75
+ if ($_item->getQtyToShip() > 0 && !$_item->getIsVirtual() && !$_item->getLockedDoShip()) {
76
+ $qty += $_item->getQtyToShip();
77
+ }
78
+ }
79
+ }
80
+ return $qty;
81
+ }
82
+
83
+ /**
84
+ * @return int
85
+ */
86
+ public function getTotalOrderCount()
87
+ {
88
+ return count($this->getOrderCollection());
89
+ }
90
+
91
+ /**
92
+ * @return int
93
+ */
94
+ public function getTotalShipmentsToCreate()
95
+ {
96
+ $count = 0;
97
+ /** @var Mage_Sales_Model_Order $_order */
98
+ foreach ($this->getOrderCollection() as $_order) {
99
+ if ($this->getQtyToShip($_order) > 0) {
100
+ $count++;
101
+ }
102
+ }
103
+ return $count;
104
+ }
105
+
106
+ /**
107
+ * @return float
108
+ */
109
+ public function getTotalQtyToShip()
110
+ {
111
+ $qty = 0.0;
112
+ /** @var Mage_Sales_Model_Order $_order */
113
+ foreach ($this->getOrderCollection() as $_order) {
114
+ $qty += $this->getQtyToShip($_order);
115
+ }
116
+ return $qty;
117
+ }
118
+
119
+ /**
120
+ * Get available carrier profiles.
121
+ *
122
+ * @return array
123
+ */
124
+ public function getAvailableCarrierprofiles()
125
+ {
126
+ $carrierprofiles = Mage::getResourceSingleton('transsmart_shipping/carrierprofile_collection')->toOptionHash();
127
+ foreach ($carrierprofiles as $_id => $_name) {
128
+ $_method = Mage::getStoreConfig('transsmart_carrier_profiles/carrierprofile_' . $_id . '/method');
129
+ if ($_method == Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Method::PICKUP) {
130
+ unset($carrierprofiles[$_id]);
131
+ }
132
+ }
133
+ return $carrierprofiles;
134
+ }
135
+
136
+ /**
137
+ * Return array with available shipment locations.
138
+ *
139
+ * @return array
140
+ */
141
+ public function getShipmentlocations()
142
+ {
143
+ return Mage::getResourceSingleton('transsmart_shipping/shipmentlocation_collection')->toOptionHash();
144
+ }
145
+
146
+ /**
147
+ * Return array with available incoterms.
148
+ *
149
+ * @return array
150
+ */
151
+ public function getIncoterms()
152
+ {
153
+ return Mage::getResourceSingleton('transsmart_shipping/incoterm_collection')->toOptionHash();
154
+ }
155
+
156
+ /**
157
+ * Return array with available email types.
158
+ *
159
+ * @return array
160
+ */
161
+ public function getEmailtypes()
162
+ {
163
+ return Mage::getResourceSingleton('transsmart_shipping/emailtype_collection')->toOptionHash();
164
+ }
165
+
166
+ /**
167
+ * Return array with available cost centers.
168
+ *
169
+ * @return array
170
+ */
171
+ public function getCostcenters()
172
+ {
173
+ return Mage::getResourceSingleton('transsmart_shipping/costcenter_collection')->toOptionHash();
174
+ }
175
+ }
app/code/community/Transsmart/Shipping/Block/Adminhtml/Sales/Order/Shipment/View/Detail.php ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Block_Adminhtml_Sales_Order_Shipment_View_Detail extends Mage_Adminhtml_Block_Template
9
+ {
10
+ /**
11
+ * Constructor.
12
+ */
13
+ public function _construct()
14
+ {
15
+ $this->setTemplate('transsmart/shipping/sales/order/shipment/view/detail.phtml');
16
+ return parent::_construct();
17
+ }
18
+
19
+ /**
20
+ * Prepares layout of block
21
+ *
22
+ * @return $this
23
+ */
24
+ protected function _prepareLayout()
25
+ {
26
+ $this->setChild('package', $this->getLayout()->createBlock(
27
+ 'transsmart_shipping/adminhtml_sales_order_shipment_view_package'
28
+ ));
29
+ return parent::_prepareLayout();
30
+ }
31
+
32
+ /**
33
+ * Retrieve shipment model instance
34
+ *
35
+ * @return Mage_Sales_Model_Order_Shipment
36
+ */
37
+ public function getShipment()
38
+ {
39
+ return Mage::registry('current_shipment');
40
+ }
41
+
42
+ /**
43
+ * Get name of carrier profile for current shipment.
44
+ *
45
+ * @return string
46
+ */
47
+ public function getCarrierprofile()
48
+ {
49
+ $carrierprofile = Mage::getResourceSingleton('transsmart_shipping/carrierprofile_collection')
50
+ ->joinCarrier()
51
+ ->joinServicelevelTime()
52
+ ->joinServicelevelOther()
53
+ ->getItemById($this->getShipment()->getTranssmartCarrierprofileId());
54
+ if ($carrierprofile) {
55
+ return $carrierprofile->getName();
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Get name of shipment location for current shipment.
61
+ *
62
+ * @return string
63
+ */
64
+ public function getShipmentlocation()
65
+ {
66
+ $shipmentlocation = Mage::getResourceSingleton('transsmart_shipping/shipmentlocation_collection')
67
+ ->getItemById($this->getShipment()->getTranssmartShipmentlocationId());
68
+ if ($shipmentlocation) {
69
+ return $shipmentlocation->getName();
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Get name of email type for current shipment.
75
+ *
76
+ * @return string
77
+ */
78
+ public function getEmailtype()
79
+ {
80
+ $emailtype = Mage::getResourceSingleton('transsmart_shipping/emailtype_collection')
81
+ ->getItemById($this->getShipment()->getTranssmartEmailtypeId());
82
+ if ($emailtype) {
83
+ return $emailtype->getName();
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Get name of cost center for current shipment.
89
+ *
90
+ * @return string
91
+ */
92
+ public function getCostcenter()
93
+ {
94
+ $costcenter = Mage::getResourceSingleton('transsmart_shipping/costcenter_collection')
95
+ ->getItemById($this->getShipment()->getTranssmartCostcenterId());
96
+ if ($costcenter) {
97
+ return $costcenter->getName();
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Get name of incoterm for current shipment.
103
+ *
104
+ * @return string
105
+ */
106
+ public function getIncoterm()
107
+ {
108
+ $incoterm = Mage::getResourceSingleton('transsmart_shipping/incoterm_collection')
109
+ ->getItemById($this->getShipment()->getTranssmartIncotermId());
110
+ if ($incoterm) {
111
+ return $incoterm->getName();
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Get Transsmart Document Id
117
+ *
118
+ * @return string
119
+ */
120
+ public function getTranssmartDocumentId()
121
+ {
122
+ $result = $this->getShipment()->getTranssmartDocumentId();
123
+ if (empty($result)) {
124
+ $result = $this->__('(empty)');
125
+ }
126
+ return $result;
127
+ }
128
+
129
+ /**
130
+ * Get Transsmart Status
131
+ *
132
+ * @return string
133
+ */
134
+ public function getTranssmartStatus()
135
+ {
136
+ $result = $this->getShipment()->getTranssmartStatus();
137
+ if (empty($result)) {
138
+ $result = $this->__('(empty)');
139
+ }
140
+ return $result;
141
+ }
142
+
143
+ /**
144
+ * Get tracking link for current shipment.
145
+ *
146
+ * @return string
147
+ */
148
+ public function getTrackingLink()
149
+ {
150
+ $url = $this->getShipment()->getTranssmartTrackingUrl();
151
+ if ($url) {
152
+ $label = Mage::helper('transsmart_shipping')->getTrackingCodeFromUrl($url);
153
+ if (empty($label)) {
154
+ $label = $this->__('Click here');
155
+ }
156
+ $result = '<a href="' . $this->escapeHtml($url) . '" title="' . $this->escapeHtml($url) . '"'
157
+ . ' target="_blank">' . $this->escapeHtml($label) . '</a>';
158
+ }
159
+ else {
160
+ $result = $this->escapeHtml($this->__('(empty)'));
161
+ }
162
+ return $result;
163
+ }
164
+ }
app/code/community/Transsmart/Shipping/Block/Adminhtml/Sales/Order/Shipment/View/Package.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Block_Adminhtml_Sales_Order_Shipment_View_Package extends Mage_Adminhtml_Block_Template
9
+ {
10
+ /**
11
+ * Constructor.
12
+ */
13
+ public function _construct()
14
+ {
15
+ $this->setTemplate('transsmart/shipping/sales/order/shipment/view/package.phtml');
16
+ return parent::_construct();
17
+ }
18
+
19
+ /**
20
+ * Retrieve shipment model instance
21
+ *
22
+ * @return Mage_Sales_Model_Order_Shipment
23
+ */
24
+ public function getShipment()
25
+ {
26
+ return Mage::registry('current_shipment');
27
+ }
28
+
29
+ /**
30
+ * Get formatted package lines for the current shipment.
31
+ *
32
+ * @return array
33
+ */
34
+ public function getFormattedPackageLines()
35
+ {
36
+ $packages = $this->getShipment()->getTranssmartPackages();
37
+ if ($packages) {
38
+ $packages = @unserialize($packages);
39
+ }
40
+
41
+ $result = array();
42
+ if ($packages) {
43
+ $format = array('locale' => new Zend_Locale(Mage::app()->getLocale()->getLocale()));
44
+
45
+ foreach ($packages as $_package) {
46
+ $result[] = array(
47
+ 'package_type' => $_package['PackagingType'],
48
+ 'qty' => $_package['Quantity'],
49
+ 'length' => Zend_Locale_Format::toNumber($_package['Length'], $format),
50
+ 'width' => Zend_Locale_Format::toNumber($_package['Width'], $format),
51
+ 'height' => Zend_Locale_Format::toNumber($_package['Height'], $format),
52
+ 'weight' => Zend_Locale_Format::toNumber($_package['Weight'], $format),
53
+ );
54
+ }
55
+ }
56
+
57
+ return $result;
58
+ }
59
+ }
app/code/community/Transsmart/Shipping/Block/Adminhtml/Sales/Order/View/Tab/Shipments.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Block_Adminhtml_Sales_Order_View_Tab_Shipments
9
+ extends Mage_Adminhtml_Block_Sales_Order_View_Tab_Shipments
10
+ {
11
+ /**
12
+ * Returns TRUE if the order uses a Transsmart shipping method.
13
+ *
14
+ * @return bool
15
+ */
16
+ public function usesTranssmartShippingMethod()
17
+ {
18
+ $shippingMethod = $this->getOrder()->getShippingMethod();
19
+ return Mage::helper('transsmart_shipping')->isTranssmartShippingMethod($shippingMethod);
20
+ }
21
+
22
+ /**
23
+ * Set collection object
24
+ *
25
+ * @param Varien_Data_Collection $collection
26
+ */
27
+ public function setCollection($collection)
28
+ {
29
+ if ($collection instanceof Mage_Sales_Model_Resource_Order_Shipment_Grid_Collection) {
30
+ if ($this->usesTranssmartShippingMethod()) {
31
+ $collection
32
+ ->addFieldToSelect('transsmart_document_id')
33
+ ->addFieldToSelect('transsmart_status')
34
+ ->addFieldToSelect('transsmart_tracking_url');
35
+ }
36
+ }
37
+ return parent::setCollection($collection);
38
+ }
39
+
40
+ /**
41
+ * Prepare and add columns to grid
42
+ *
43
+ * @return Mage_Adminhtml_Block_Widget_Grid
44
+ */
45
+ protected function _prepareColumns()
46
+ {
47
+ if ($this->usesTranssmartShippingMethod()) {
48
+ $this->addColumnAfter('transsmart_document_id', array(
49
+ 'header' => Mage::helper('sales')->__('Transsmart Document Id'),
50
+ 'index' => 'transsmart_document_id',
51
+ 'type' => 'text',
52
+ 'width' => '70px',
53
+ ), 'total_qty');
54
+
55
+ $this->addColumnAfter('transsmart_status', array(
56
+ 'header' => Mage::helper('sales')->__('Transsmart Status'),
57
+ 'index' => 'transsmart_status',
58
+ 'type' => 'options',
59
+ 'width' => '70px',
60
+ 'options' => Mage::helper('transsmart_shipping/shipment')->getShipmentStatuses(),
61
+ ), 'transsmart_document_id');
62
+
63
+ $this->addColumnAfter('transsmart_tracking_url', array(
64
+ 'header' => Mage::helper('transsmart_shipping')->__('Track & Trace'),
65
+ 'index' => 'transsmart_tracking_url',
66
+ 'width' => '70px',
67
+ 'renderer' => 'transsmart_shipping/adminhtml_sales_shipment_grid_renderer_link',
68
+ 'filter' => false,
69
+ 'sortable' => false,
70
+ 'is_system' => true
71
+ ), 'transsmart_status');
72
+ }
73
+
74
+ return parent::_prepareColumns();
75
+ }
76
+ }
app/code/community/Transsmart/Shipping/Block/Adminhtml/Sales/Shipment/Grid.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Block_Adminhtml_Sales_Shipment_Grid extends Mage_Adminhtml_Block_Sales_Shipment_Grid
9
+ {
10
+ /**
11
+ * Prepare grid massaction actions
12
+ *
13
+ * @return $this
14
+ */
15
+ protected function _prepareMassaction()
16
+ {
17
+ parent::_prepareMassaction();
18
+ $this->getMassactionBlock()->removeItem('print_shipping_label');
19
+
20
+ if (Mage::getSingleton('admin/session')->isAllowed('sales/shipment')) {
21
+ $this->getMassactionBlock()->addItem('transsmart_book_and_print', array(
22
+ 'label'=> Mage::helper('transsmart_shipping')->__('Transsmart: Book & Print'),
23
+ 'url' => $this->getUrl('*/transsmart_shipping_shipment/massBookAndPrint'),
24
+ ));
25
+
26
+ $this->getMassactionBlock()->addItem('transsmart_booking', array(
27
+ 'label'=> Mage::helper('transsmart_shipping')->__('Transsmart: Book Shipment(s)'),
28
+ 'url' => $this->getUrl('*/transsmart_shipping_shipment/massBooking'),
29
+ ));
30
+
31
+ $this->getMassactionBlock()->addItem('transsmart_label', array(
32
+ 'label'=> Mage::helper('transsmart_shipping')->__('Transsmart: Print Label(s)'),
33
+ 'url' => $this->getUrl('*/transsmart_shipping_shipment/massLabel'),
34
+ ));
35
+ }
36
+
37
+ return $this;
38
+ }
39
+
40
+ /**
41
+ * Prepare and add columns to grid
42
+ *
43
+ * @return $this
44
+ */
45
+ protected function _prepareColumns()
46
+ {
47
+ $this->addColumnAfter('transsmart_document_id', array(
48
+ 'header' => Mage::helper('transsmart_shipping')->__('Transsmart Document Id'),
49
+ 'index' => 'transsmart_document_id',
50
+ 'type' => 'text',
51
+ 'width' => '70px',
52
+ ), 'total_qty');
53
+
54
+ $this->addColumnAfter('transsmart_status', array(
55
+ 'header' => Mage::helper('transsmart_shipping')->__('Transsmart Status'),
56
+ 'index' => 'transsmart_status',
57
+ 'type' => 'options',
58
+ 'width' => '70px',
59
+ 'options' => Mage::helper('transsmart_shipping/shipment')->getShipmentStatuses(),
60
+ ), 'transsmart_document_id');
61
+
62
+ $this->addColumnAfter('transsmart_tracking_url', array(
63
+ 'header' => Mage::helper('transsmart_shipping')->__('Track & Trace'),
64
+ 'index' => 'transsmart_tracking_url',
65
+ 'width' => '70px',
66
+ 'renderer' => 'transsmart_shipping/adminhtml_sales_shipment_grid_renderer_link',
67
+ 'filter' => false,
68
+ 'sortable' => false,
69
+ 'is_system' => true
70
+ ), 'transsmart_status');
71
+
72
+ return parent::_prepareColumns();
73
+ }
74
+ }
app/code/community/Transsmart/Shipping/Block/Adminhtml/Sales/Shipment/Grid/Renderer/Link.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Block_Adminhtml_Sales_Shipment_Grid_Renderer_Link
9
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
10
+ {
11
+ public function render(Varien_Object $row)
12
+ {
13
+ $value = $row->getData($this->getColumn()->getIndex());
14
+ if ($value == null || strlen($value) == 0) {
15
+ return '';
16
+ }
17
+
18
+ return '<a href="'. $value . '" target="_blank">' . Mage::helper('transsmart_shipping')->__('View') . '</span>';
19
+ }
20
+ }
app/code/community/Transsmart/Shipping/Block/Adminhtml/Shipping/Location/Info.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Block_Adminhtml_Shipping_Location_Info extends Mage_Adminhtml_Block_Template
9
+ {
10
+ /**
11
+ * Constructor.
12
+ */
13
+ public function _construct()
14
+ {
15
+ $this->setTemplate('transsmart/shipping/location/info.phtml');
16
+ return parent::_construct();
17
+ }
18
+
19
+ /**
20
+ * Retrieves the pickup address from the current quote.
21
+ *
22
+ * @return Mage_Sales_Model_Quote_Address|null
23
+ */
24
+ public function getPickupAddress()
25
+ {
26
+ /** @var Mage_Sales_Model_Quote $quote */
27
+ $quote = Mage::getSingleton('adminhtml/sales_order_create')->getQuote();
28
+
29
+ return Mage::helper('transsmart_shipping/pickupaddress')->getPickupAddressFromQuote($quote);
30
+ }
31
+ }
app/code/community/Transsmart/Shipping/Block/Adminhtml/System/Config/Form/Field/Fetch.php ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Block_Adminhtml_System_Config_Form_Field_Fetch
9
+ extends Mage_Adminhtml_Block_Widget
10
+ implements Varien_Data_Form_Element_Renderer_Interface
11
+ {
12
+ /**
13
+ * @param Varien_Data_Form_Element_Abstract $element
14
+ * @return string
15
+ */
16
+ public function render(Varien_Data_Form_Element_Abstract $element)
17
+ {
18
+ $time = Mage::getModel('transsmart_shipping/sync')->getLastSync();
19
+ if ($time) {
20
+ $time = new Zend_Date($time);
21
+ $message = $this->__('Base data last fetched on %s.', Mage::helper('core')->formatDate($time, 'long', true));
22
+ $class = 'success-msg';
23
+ }
24
+ else {
25
+ $message = $this->__('Base data not fetched yet.');
26
+ $class = 'error-msg';
27
+ }
28
+
29
+ if ($this->getError()) {
30
+ $message .= "\n\n" . $this->getError();
31
+ $class = 'error-msg';
32
+ }
33
+
34
+ $this->setElement($element);
35
+ $this->setMessageClass($class);
36
+ $this->setMessageText($message);
37
+
38
+ $this->setTemplate('transsmart/shipping/system/config/form/field/fetch.phtml');
39
+
40
+ return $this->renderView();
41
+ }
42
+
43
+ /**
44
+ * @return bool
45
+ */
46
+ public function useContainer()
47
+ {
48
+ $htmlId = $this->getRequest()->getParam('htmlId');
49
+ if (!empty($htmlId) && preg_match('/^[a-z0-9_]+$/i', $htmlId)) {
50
+ return false;
51
+ }
52
+ return true;
53
+ }
54
+
55
+ /**
56
+ * @return string
57
+ */
58
+ public function getHtmlId()
59
+ {
60
+ $htmlId = $this->getRequest()->getParam('htmlId');
61
+ if (!empty($htmlId) && preg_match('/^[a-z0-9_]+$/i', $htmlId)) {
62
+ return $htmlId;
63
+ }
64
+ return $this->getElement()->getHtmlId();
65
+ }
66
+
67
+ /**
68
+ * @return bool
69
+ */
70
+ public function showFetchButton()
71
+ {
72
+ // only show 'Fetch Now' button when username and password are configured
73
+ $username = Mage::getStoreConfig(Transsmart_Shipping_Helper_Data::XML_PATH_CONNECTION_USERNAME);
74
+ $password = Mage::getStoreConfig(Transsmart_Shipping_Helper_Data::XML_PATH_CONNECTION_PASSWORD);
75
+
76
+ if (strlen($username) == 0 || strlen($password) == 0) {
77
+ return false;
78
+ }
79
+
80
+ return true;
81
+ }
82
+
83
+ /**
84
+ * @return string
85
+ */
86
+ public function getFetchUrl()
87
+ {
88
+ return $this->getUrl('*/transsmart/fetch', array('htmlId' => $this->getHtmlId()));
89
+ }
90
+
91
+ /**
92
+ * Retrieve 'Fetch Now' button HTML
93
+ *
94
+ * @return string
95
+ */
96
+ public function getFetchButtonHtml()
97
+ {
98
+ $htmlId = $this->getHtmlId();
99
+
100
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')
101
+ ->setData(array(
102
+ 'label' => $this->__('Fetch Now'),
103
+ 'onclick' => "transsmart_fetchBaseData('$htmlId'); return false;",
104
+ 'class' => 'go',
105
+ 'id' => $htmlId . '_button'
106
+ ));
107
+
108
+ return $button->toHtml();
109
+ }
110
+ }
app/code/community/Transsmart/Shipping/Block/Adminhtml/System/Config/Form/Fieldset/Carrierprofile.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Block_Adminhtml_System_Config_Form_Fieldset_Carrierprofile
9
+ extends Mage_Adminhtml_Block_System_Config_Form_Fieldset
10
+ {
11
+ /**
12
+ * Return header title part of html for fieldset
13
+ *
14
+ * @param Varien_Data_Form_Element_Fieldset $element
15
+ * @return string
16
+ */
17
+ protected function _getHeaderTitleHtml($element)
18
+ {
19
+ $originalData = $element->getOriginalData();
20
+
21
+ $carrierprofileId = $originalData['carrierprofile_id'];
22
+ $carrierName = $originalData['carrier_name'];
23
+ $servicelevelTimeName = $originalData['servicelevel_time_name'];
24
+ $servicelevelOtherName = $originalData['servicelevel_other_name'];
25
+
26
+ $style = "display:inline-block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;";
27
+
28
+ $html = "<span style=\"width:10%;$style\">$carrierprofileId</span>"
29
+ . "<span style=\"width:30%;$style\">$carrierName</span>"
30
+ . "<span style=\"width:30%;$style\">$servicelevelTimeName</span>"
31
+ . "<span style=\"width:30%;$style\">$servicelevelOtherName</span>";
32
+
33
+ $element->setLegend($html);
34
+
35
+ return parent::_getHeaderTitleHtml($element);
36
+
37
+ //return '<div class="entry-edit-head collapseable" ><a id="' . $element->getHtmlId()
38
+ //. '-head" href="#" onclick="Fieldset.toggleCollapse(\'' . $element->getHtmlId() . '\', \''
39
+ //. $this->getUrl('*/*/state') . '\'); return false;">' . $html . '</a></div>';
40
+ }
41
+ }
app/code/community/Transsmart/Shipping/Block/Adminhtml/System/Config/Form/Fieldset/Carrierprofile/Header.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Block_Adminhtml_System_Config_Form_Fieldset_Carrierprofile_Header
9
+ extends Transsmart_Shipping_Block_Adminhtml_System_Config_Form_Fieldset_Carrierprofile
10
+ {
11
+ /**
12
+ * Render fieldset html
13
+ *
14
+ * @param Varien_Data_Form_Element_Abstract $element
15
+ * @return string
16
+ */
17
+ public function render(Varien_Data_Form_Element_Abstract $element)
18
+ {
19
+ $this->setElement($element);
20
+
21
+ $carrierprofileId = $this->__('ID');
22
+ $carrierName = $this->__('Carrier');
23
+ $servicelevelTimeName = $this->__('Servicelevel Time');
24
+ $servicelevelOtherName = $this->__('Servicelevel Other');
25
+
26
+ $style = "display:inline-block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;";
27
+
28
+ $html = "<span style=\"width:10%;$style\">$carrierprofileId</span>"
29
+ . "<span style=\"width:30%;$style\">$carrierName</span>"
30
+ . "<span style=\"width:30%;$style\">$servicelevelTimeName</span>"
31
+ . "<span style=\"width:30%;$style\">$servicelevelOtherName</span>";
32
+
33
+ return '<div style="padding:2px 10px"><strong>' . $html . '</strong></div>';
34
+ }
35
+ }
app/code/community/Transsmart/Shipping/Block/Adminhtml/System/Config/Form/Fieldset/Versioninfo.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Block_Adminhtml_System_Config_Form_Fieldset_Versioninfo
9
+ extends Mage_Adminhtml_Block_Abstract implements Varien_Data_Form_Element_Renderer_Interface
10
+ {
11
+ /**
12
+ * @param Varien_Data_Form_Element_Abstract $element
13
+ * @return string
14
+ */
15
+ public function render(Varien_Data_Form_Element_Abstract $element)
16
+ {
17
+ $version = Mage::getConfig()->getNode('modules/Transsmart_Shipping/version');
18
+ $helper = Mage::helper('transsmart_shipping');
19
+
20
+ $helpdesk = 'http://transsmart.freshdesk.com/solution/articles/';
21
+
22
+ $links = array(
23
+ 'Transsmart API' => 'https://connect.api.transwise.eu/',
24
+ 'User Manual' => $helpdesk . '3000046401-gebruikershandleiding-magento-transsmart-connector',
25
+ 'Configuration Manual' => $helpdesk . '3000046402-configuratie-handleiding-magento-transsmart-connector',
26
+ 'Transsmart Support' => 'http://support.transsmart.com/',
27
+ );
28
+
29
+ $linksHtml = '';
30
+ foreach ($links as $_title => $_url) {
31
+ $linksHtml .= (($linksHtml != '') ? ' | ' : '')
32
+ . '<a href="' . $this->escapeHtml($_url) . '" target="_blank">'
33
+ . $helper->__($_title)
34
+ . '</a>';
35
+ }
36
+
37
+ $html = '<fieldset class="config">'
38
+ . '<p><strong>'
39
+ . $helper->__('Transsmart Shipping extension version %s', $version)
40
+ . '</strong>'
41
+ . '<span style="float:right"><a href="http://www.transsmart.com/" target="_blank">'
42
+ . $helper->__('www.transsmart.com') . '</a></span>'
43
+ . "</p>\n"
44
+ . '<p style="margin-bottom:0">' . $linksHtml . '</p>'
45
+ . '</fieldset>';
46
+
47
+ return $html;
48
+ }
49
+ }
app/code/community/Transsmart/Shipping/Block/Location/Selector.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Block_Location_Selector extends Mage_Core_Block_Template
9
+ {
10
+ /**
11
+ * Retrieve the shipping address
12
+ * @return Mage_Sales_Model_Quote_Address
13
+ */
14
+ public function getShippingAddress()
15
+ {
16
+ return Mage::getSingleton('checkout/cart')->getQuote()->getShippingAddress();
17
+ }
18
+ }
app/code/community/Transsmart/Shipping/Helper/Data.php ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Helper_Data extends Mage_Core_Helper_Abstract
9
+ {
10
+ const XML_PATH_CONNECTION_USERNAME = 'transsmart_shipping/connection/username';
11
+ const XML_PATH_CONNECTION_PASSWORD = 'transsmart_shipping/connection/password';
12
+ const XML_PATH_CONNECTION_ENVIRONMENT = 'transsmart_shipping/connection/environment';
13
+
14
+ const XML_PATH_PRINT_QZHOST = 'transsmart_shipping/print/qzhost';
15
+ const XML_PATH_PRINT_SELECTEDPRINTER = 'transsmart_shipping/print/selectedprinter';
16
+
17
+ const TRANSSMART_ORDER_STATUS_NOT_APPLICABLE = 0;
18
+ const TRANSSMART_ORDER_STATUS_PENDING = 1;
19
+ const TRANSSMART_ORDER_STATUS_PARTIALLY_EXPORTED = 2;
20
+ const TRANSSMART_ORDER_STATUS_EXPORTED = 3;
21
+ const TRANSSMART_ORDER_STATUS_ERROR = 4;
22
+
23
+ /**
24
+ * @var Transsmart_Shipping_Model_Client
25
+ */
26
+ protected $_apiClient;
27
+
28
+ /**
29
+ * A list of carrier profiles that can use the location selector
30
+ * @var array
31
+ */
32
+ protected $_locationSelectCarrierProfiles = array();
33
+
34
+ /**
35
+ * Get the Transsmart API client, and initialize it with the configured authentication details. The same instance
36
+ * will be returned for subsequent calls. Configuration settings are always read from the global scope, as there
37
+ * can be only one Transsmart account per Magento installation.
38
+ *
39
+ * @return Transsmart_Shipping_Model_Client
40
+ */
41
+ public function getApiClient()
42
+ {
43
+ if (is_null($this->_apiClient)) {
44
+ // collect configuration settings
45
+ $username = Mage::getStoreConfig(self::XML_PATH_CONNECTION_USERNAME, 0);
46
+ $password = Mage::getStoreConfig(self::XML_PATH_CONNECTION_PASSWORD, 0);
47
+ $environment = Mage::getStoreConfig(self::XML_PATH_CONNECTION_ENVIRONMENT, 0);
48
+
49
+ // check if username and password are specified
50
+ if (empty($username)) {
51
+ Mage::throwException('No Transsmart connection username is configured');
52
+ }
53
+ if (empty($password)) {
54
+ Mage::throwException('No Transsmart connection password is configured');
55
+ }
56
+
57
+ // use environment setting to determine url
58
+ if ($environment == Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Environment::STAGING) {
59
+ $url = 'https://connect.test.api.transwise.eu';
60
+ }
61
+ elseif ($environment == Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Environment::PRODUCTION) {
62
+ $url = 'https://connect.api.transwise.eu';
63
+ }
64
+ else {
65
+ Mage::throwException('An invalid Transsmart connection environment is configured');
66
+ }
67
+
68
+ // instantiate API client model
69
+ $this->_apiClient = Mage::getModel('transsmart_shipping/client', array(
70
+ 'url' => $url,
71
+ 'username' => $username,
72
+ 'password' => $password
73
+ ));
74
+ }
75
+
76
+ return $this->_apiClient;
77
+ }
78
+
79
+ /**
80
+ * Get all possible Transsmart order statuses.
81
+ *
82
+ * @return array
83
+ */
84
+ public function getOrderStatuses()
85
+ {
86
+ return array(
87
+ self::TRANSSMART_ORDER_STATUS_NOT_APPLICABLE => $this->__('N/A'),
88
+ self::TRANSSMART_ORDER_STATUS_PENDING => $this->__('Pending'),
89
+ self::TRANSSMART_ORDER_STATUS_PARTIALLY_EXPORTED => $this->__('Partially Exported'),
90
+ self::TRANSSMART_ORDER_STATUS_EXPORTED => $this->__('Exported'),
91
+ self::TRANSSMART_ORDER_STATUS_ERROR => $this->__('Error'),
92
+ );
93
+ }
94
+
95
+ /**
96
+ * Checks the provided shipping method to see if it's a Transsmart shipping method.
97
+ *
98
+ * @param string $shippingMethod
99
+ * @return bool
100
+ */
101
+ public function isTranssmartShippingMethod($shippingMethod)
102
+ {
103
+ return preg_match('/^transsmart(delivery|pickup)_carrierprofile_([0-9]+)$/', $shippingMethod) === 1;
104
+ }
105
+
106
+ /**
107
+ * Checks the provided shipping method to see if it's a Transsmart shipping method for pickup.
108
+ *
109
+ * @param string $shippingMethod
110
+ * @return bool
111
+ */
112
+ public function isTranssmartPickup($shippingMethod)
113
+ {
114
+ return preg_match('/^transsmartpickup_carrierprofile_([0-9]+)$/', $shippingMethod) === 1;
115
+ }
116
+
117
+
118
+ /**
119
+ * Retrieves carrier profiles that can have the location selector
120
+ * @todo This could return (old) carrier profiles, deleted from the database, but still present in the config table.
121
+ * @todo Refactor to Transsmart_Shipping_Model_Resource_Carrierprofile_Collection::addLocationSelectEnabledFilter
122
+ * @param Mage_Core_Model_Store|int $store
123
+ * @return array
124
+ */
125
+ public function getLocationSelectCarrierProfiles($store = null)
126
+ {
127
+ if ($store == null) {
128
+ $store = Mage::app()->getStore();
129
+ }
130
+
131
+ // We were provided a store ID
132
+ if (is_numeric($store)) {
133
+ $store = Mage::app()->getStore($store);
134
+ }
135
+
136
+ if (!isset($this->_locationSelectCarrierProfiles[$store->getId()])) {
137
+
138
+ $carrierProfiles = Mage::getModel('core/config_data')
139
+ ->getCollection()
140
+ ->addFieldToFilter('path', array('like' => 'transsmart_carrier_profiles/carrierprofile_%/method'))
141
+ ->addFieldToFilter('value', 'transsmartpickup')
142
+ ->addFieldToFilter('scope_id', array('in' => array(0, $store->getId())))
143
+ ->addOrder('scope')
144
+ ->load();
145
+
146
+ $pickupCarrierProfileConfigs = array();
147
+ $carrierProfileIds = array();
148
+
149
+ if ($carrierProfiles->count() > 0) {
150
+ foreach ($carrierProfiles as $carrierProfile) {
151
+ preg_match('#transsmart_carrier_profiles/carrierprofile_([0-9]+)/#', $carrierProfile->getPath(), $matches);
152
+
153
+ if (count($matches) == 2) {
154
+ $pickupCarrierProfileConfigs [] = 'transsmart_carrier_profiles/carrierprofile_' . $matches[1] . '/location_select';
155
+ }
156
+ }
157
+
158
+ $locationSelectProfiles = Mage::getModel('core/config_data')
159
+ ->getCollection()
160
+ ->addFieldToFilter('path', array('in' => $pickupCarrierProfileConfigs))
161
+ ->addFieldToFilter('value', 1)
162
+ ->addFieldToFilter('scope_id', array('in' => array(0, $store->getId())))
163
+ ->addOrder('scope')
164
+ ->load();
165
+
166
+ foreach ($locationSelectProfiles as $locationSelectProfile) {
167
+ preg_match('#transsmart_carrier_profiles/carrierprofile_([0-9]+)/#', $locationSelectProfile->getPath(), $matches);
168
+
169
+ if (count($matches) == 2) {
170
+ $carrierProfileIds [] = $matches[1];
171
+ }
172
+ }
173
+ }
174
+
175
+
176
+ $this->_locationSelectCarrierProfiles[$store->getId()] = $carrierProfileIds;
177
+ }
178
+
179
+ return $this->_locationSelectCarrierProfiles[$store->getId()];
180
+ }
181
+
182
+ /**
183
+ * Translates the provided string with the provided localeCode.
184
+ * This way it is possible to force a translation in a certain language.
185
+ *
186
+ * @param string|array $translationArgs This can either be the string that needs to be localized or
187
+ * an array can be provided which servers as arguments. For example: ["Translation number %s", 1]
188
+ * @param string $localeCode Locale code to translate the string to
189
+ * @param string $moduleName The module name to translate for. When none is provided transsmart_shipping is used.
190
+ * @return string
191
+ */
192
+ public function forceTranslate($translationArgs, $localeCode, $moduleName = null)
193
+ {
194
+ if ($moduleName == null) {
195
+ $moduleName = $this->_getModuleName();
196
+ }
197
+
198
+ $translationString = null;
199
+
200
+ if (is_array($translationArgs)) {
201
+ $translationString = array_shift($translationArgs);
202
+ }
203
+ else {
204
+ $translationString = $translationArgs;
205
+ $translationArgs = array();
206
+ }
207
+
208
+ $origLocaleCode = Mage::app()->getLocale()->getLocaleCode();
209
+ Mage::app()->getLocale()->setLocale($localeCode);
210
+
211
+ $translator = Mage::getModel('core/translate')->init('frontend')->setTranslateInline(false);
212
+ $translateExpr = Mage::getModel('core/translate_expr')
213
+ ->setModule($moduleName)
214
+ ->setText($translationString);
215
+
216
+ array_unshift($translationArgs, $translateExpr);
217
+
218
+ $translatedString = $translator->translate($translationArgs);
219
+ Mage::app()->getLocale()->setLocale($origLocaleCode);
220
+
221
+ return $translatedString;
222
+ }
223
+
224
+ /**
225
+ * Extract the track-and-trace code from the given URL. Returns FALSE if none is found.
226
+ *
227
+ * @param string $url
228
+ * @return string|FALSE
229
+ */
230
+ public function getTrackingCodeFromUrl($url)
231
+ {
232
+ $code = false;
233
+ if (preg_match_all('/=([A-Z0-9-]+)/si', $url, $matches)) {
234
+ foreach ($matches[1] as $_match) {
235
+ if ($code === false || strlen($_match) > strlen($code)) {
236
+ $code = $_match;
237
+ }
238
+ }
239
+ }
240
+ return $code;
241
+ }
242
+ }
app/code/community/Transsmart/Shipping/Helper/Location.php ADDED
@@ -0,0 +1,355 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Helper_Location extends Mage_Core_Helper_Abstract
9
+ {
10
+ /**
11
+ * Retrieve geo location from the provided details
12
+ * @param $zipcode
13
+ * @param $country
14
+ * @param $city
15
+ * @param $street
16
+ * @param $housenr
17
+ * @return null
18
+ * @throws Mage_Core_Exception
19
+ */
20
+ public function getGeoLocation($zipcode, $country, $city, $street, $housenr)
21
+ {
22
+ $address = urlencode($zipcode . ', ' . $country);
23
+ $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . $address . '&region=' . $country;
24
+
25
+ $ch = curl_init($url);
26
+ curl_setopt($ch, CURLINFO_HEADER_OUT, true);
27
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
28
+
29
+ $responseBody = curl_exec($ch);
30
+
31
+ // collect details and close cURL resource
32
+ $curlError = curl_error($ch);
33
+ $httpResponseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
34
+ curl_close($ch);
35
+
36
+ // check for cURL failure
37
+ if ($responseBody === false) {
38
+ Mage::throwException('Google GeoCode failure: ' . $curlError);
39
+ }
40
+
41
+ // check for unexpected HTTP response code
42
+ if ($httpResponseCode == 200) {
43
+ // try to extract JSON encoded message from response body
44
+ if ($responseBody !== false) {
45
+ try {
46
+ $response = Zend_Json_Decoder::decode($responseBody);
47
+ if (isset($response['results']) && count($response['results']) > 0) {
48
+ if (isset($response['results'][0]['geometry'])) {
49
+ return $response['results'][0]['geometry']['location'];
50
+ }
51
+
52
+ return null;
53
+ }
54
+ }
55
+ catch (Zend_Json_Exception $exception) {
56
+ Mage::logException($exception);
57
+ }
58
+ }
59
+ }
60
+ else {
61
+ Mage::throwException('Google GeoCode returned unexpected HTTP response code: ' . $httpResponseCode);
62
+ }
63
+
64
+ return null;
65
+ }
66
+
67
+ /**
68
+ * Retrieves lookup response
69
+ * @param Mage_Checkout_Model_Cart|Mage_Adminhtml_Model_Sales_Order_Create $model
70
+ * @param Mage_Core_Controller_Request_Http $request
71
+ * @return array
72
+ */
73
+ public function getLookupResponse($model, Mage_Core_Controller_Request_Http $request)
74
+ {
75
+ $response = array();
76
+
77
+ try {
78
+ // fetch address parameters
79
+ $street = $request->getParam('street');
80
+ $housenr = $request->getParam('housenr');
81
+ $zipcode = $request->getParam('zipcode');
82
+ $city = $request->getParam('city');
83
+ $country = $request->getParam('country');
84
+
85
+ // We need the zipcode, city and country or an active cart
86
+ if (empty($zipcode) || empty($city) || empty($country)) {
87
+ // Retrieve the quote
88
+ $quote = $model->getQuote();
89
+
90
+ if (empty($quote)) {
91
+ Mage::throwException($this->__('Missing required parameters'));
92
+ }
93
+
94
+ $shippingAddress = $quote->getShippingAddress();
95
+
96
+ // We need to have a shipping address
97
+ if (empty($shippingAddress)) {
98
+ Mage::throwException($this->__('Quote does not contain a shipping address'));
99
+ }
100
+
101
+ $zipcode = $shippingAddress->getPostcode();
102
+ $city = $shippingAddress->getCity();
103
+ $country = $shippingAddress->getCountryId();
104
+ $street = $shippingAddress->getStreet(1);
105
+
106
+ if (!empty($street) && strlen($street) > 0) {
107
+ preg_match('#^([^\d]*[^\d\s]) *(\d.*)$#', $street, $match);
108
+ if (count($match) == 3) {
109
+ $street = $match[1];
110
+ $housenr = $match[2];
111
+ }
112
+ }
113
+ else {
114
+ $street = null;
115
+ $housenr = null;
116
+ }
117
+ }
118
+
119
+ // Validate everything once more
120
+ if (empty($zipcode) || empty($city) || empty($country)) {
121
+ Mage::throwException($this->__('Zipcode, city and country are required.'));
122
+ }
123
+
124
+ // fetch carrier parameters
125
+ $carrier = $request->getParam('carrier');
126
+ $shippingMethod = $request->getParam('shipping_method');
127
+ $search = $request->getParam('search');
128
+
129
+ if (strlen(trim($search)) > 0) {
130
+ // Otherwise we are looking for <zipcode>,<city>,<street>,<housenumber>
131
+ $searchParts = explode(',', $search);
132
+ $zipcode = isset($searchParts[0]) ? $searchParts[0] : $zipcode;
133
+ $city = isset($searchParts[1]) ? $searchParts[1] : $city;
134
+ $street = isset($searchParts[2]) ? $searchParts[2] : $street;
135
+ $housenr = isset($searchParts[3]) ? $searchParts[3] : $housenr;
136
+ }
137
+
138
+ if (empty($carrier) && !empty($shippingMethod)) {
139
+ /** @var Transsmart_Shipping_Model_Carrierprofile $carrierprofile */
140
+ $carrierprofile = Mage::getModel('transsmart_shipping/carrierprofile')
141
+ ->loadByShippingMethodCode($shippingMethod);
142
+
143
+ if (!$carrierprofile->isLocationSelectEnabled()) {
144
+ Mage::throwException($this->__('Location selector not available for this shipping method.'));
145
+ }
146
+
147
+ $carrier = $carrierprofile->getCarrierCode();
148
+ }
149
+
150
+ $pickupAddress = null;
151
+ if (($quote = $model->getQuote())) {
152
+ $pickupAddress = Mage::helper('transsmart_shipping/pickupaddress')->getPickupAddressFromQuote($quote);
153
+ }
154
+
155
+ /** @var Transsmart_Shipping_Helper_Data $helper */
156
+ $helper = Mage::helper('transsmart_shipping');
157
+
158
+ /** @var Transsmart_Shipping_Model_Client $client */
159
+ $client = $helper->getApiClient();
160
+
161
+ $apiResponse = $client->getLocationSelect($zipcode, $country, $carrier, $city, $street, $housenr);
162
+
163
+ // convert API response so it can be used by the JavaScript module
164
+ $locations = array(); $selected = false;
165
+ foreach ($apiResponse as $_item) {
166
+ // convert address fields
167
+ $_location['name'] = $_item['Name'];
168
+ $_location['street'] = $_item['Street'];
169
+ $_location['street_no'] = $_item['StreetNo'];
170
+ $_location['zipcode'] = $_item['Zipcode'];
171
+ $_location['city'] = $_item['City'];
172
+ $_location['country'] = $_item['Country'];
173
+ $_location['phone'] = $_item['Phone'];
174
+
175
+ // convert coordinates
176
+ $_location['lat'] = (float)$_item['Latitude'];
177
+ $_location['lng'] = (float)$_item['Longitude'];
178
+
179
+ // convert other data
180
+ $_location['servicepoint_id'] = $_item['ServicePoinTID'];
181
+
182
+ $_location['selected'] = false;
183
+ if (!$selected && !empty($_location['servicepoint_id']) && $pickupAddress) {
184
+ if ($pickupAddress->getTranssmartServicepointId() == $_location['servicepoint_id']) {
185
+ $_location['selected'] = true;
186
+ $selected = true;
187
+ }
188
+ }
189
+
190
+ // convert opening hours
191
+ $_location['has_openinghours'] = false;
192
+ $_location['openinghours'] = array();
193
+ $_location['is_open_early'] = false;
194
+ $_location['is_open_late'] = false;
195
+ $_location['is_open_sunday'] = false;
196
+
197
+ if ($_item['HasOpeningHours']) {
198
+ foreach ($_item['OpeningHours'] as $_openingHoursItem) {
199
+ $_convertedOpeningHoursItem = $this->_convertOpeningHoursItem($_openingHoursItem);
200
+ if ($_convertedOpeningHoursItem) {
201
+ if ($_convertedOpeningHoursItem['open_morning'] && (
202
+ $_convertedOpeningHoursItem['open_morning'] < '08:00')) {
203
+ $_location['is_open_early'] = true;
204
+ }
205
+ if ($_convertedOpeningHoursItem['close_afternoon'] > '18:00') {
206
+ $_location['is_open_late'] = true;
207
+ }
208
+ if ($_convertedOpeningHoursItem['day'] == 7 && (
209
+ $_convertedOpeningHoursItem['open_morning'] ||
210
+ $_convertedOpeningHoursItem['close_afternoon'])) {
211
+ $_location['is_open_sunday'] = true;
212
+ }
213
+ $_location['openinghours'][] = $_convertedOpeningHoursItem;
214
+ $_location['has_openinghours'] = true;
215
+ }
216
+ }
217
+ }
218
+
219
+ // dispatch event so other extensions can update the location
220
+ $_transport = new Varien_Object(array('location' => $_location));
221
+ Mage::dispatchEvent('transsmart_shipping_pickup_location_convert', array(
222
+ 'data' => $_item,
223
+ 'transport' => $_transport
224
+ ));
225
+ $_location = $_transport->getLocation();
226
+
227
+ if ($_location) {
228
+ $locations[] = $_location;
229
+ }
230
+ }
231
+
232
+ if (count($locations) == 0) {
233
+ Mage::throwException($this->__('No pickup locations found.'));
234
+ }
235
+
236
+ $response['locations'] = $locations;
237
+ $response['current_location'] = $this->getGeoLocation($zipcode, $country, $city, $street, $housenr);
238
+ $response['result'] = true;
239
+ }
240
+ catch (Mage_Core_Exception $exception) {
241
+ $response['error'] = $exception->getMessage();
242
+ $response['result'] = false;
243
+ }
244
+ catch (Exception $exception) {
245
+ Mage::logException($exception);
246
+ $response['error'] = $this->__('Unknown error');
247
+ $response['result'] = false;
248
+ }
249
+
250
+ return $response;
251
+ }
252
+
253
+ /**
254
+ * Convert and validate openinghours items.
255
+ *
256
+ * @param array $data
257
+ * @return array
258
+ */
259
+ protected function _convertOpeningHoursItem($data)
260
+ {
261
+ // detect Dutch or English day names or abbreviations
262
+ switch (strtolower(substr($data['Day'], 0, 2))) {
263
+ case 'mo';
264
+ case 'ma';
265
+ $day = 1;
266
+ $dayName = $this->__('Monday');
267
+ break;
268
+ case 'tu';
269
+ case 'di';
270
+ $day = 2;
271
+ $dayName = $this->__('Tuesday');
272
+ break;
273
+ case 'we';
274
+ case 'wo';
275
+ $day = 3;
276
+ $dayName = $this->__('Wednesday');
277
+ break;
278
+ case 'th';
279
+ case 'do';
280
+ $day = 4;
281
+ $dayName = $this->__('Thursday');
282
+ break;
283
+ case 'fr';
284
+ case 'vr';
285
+ $day = 5;
286
+ $dayName = $this->__('Friday');
287
+ break;
288
+ case 'sa';
289
+ case 'za';
290
+ $day = 6;
291
+ $dayName = $this->__('Saturday');
292
+ break;
293
+ case 'su';
294
+ case 'zo';
295
+ $day = 7;
296
+ $dayName = $this->__('Sunday');
297
+ break;
298
+ default:
299
+ return false;
300
+ }
301
+
302
+ $result = array(
303
+ 'day' => $day,
304
+ 'day_name' => $dayName,
305
+ 'open_morning' => $this->_convertOpeningHoursTime($data['OpenMorning']),
306
+ 'close_morning' => $this->_convertOpeningHoursTime($data['CloseMorning']),
307
+ 'open_afternoon' => $this->_convertOpeningHoursTime($data['OpenAfternoon']),
308
+ 'close_afternoon' => $this->_convertOpeningHoursTime($data['CloseAfternoon'])
309
+ );
310
+
311
+ $display = '';
312
+ if ($result['open_morning']) {
313
+ $display .= $result['open_morning'] . ' - ';
314
+ if ($result['close_morning']) {
315
+ $display .= $result['close_morning'];
316
+ if ($result['open_afternoon']) {
317
+ $display .= ' / ';
318
+ }
319
+ }
320
+ }
321
+ if ($result['open_afternoon']) {
322
+ $display .= $result['open_afternoon'] . ' - ';
323
+ }
324
+ if ($result['close_afternoon']) {
325
+ $display .= $result['close_afternoon'];
326
+ }
327
+ if ($display == '') {
328
+ $display = $this->__('Closed');
329
+ }
330
+
331
+ $result['display'] = $display;
332
+
333
+ return $result;
334
+ }
335
+
336
+ /**
337
+ * Converts and validate times. For example, '08.00' is converted to '08:00'.
338
+ *
339
+ * @param string $time
340
+ * @return null|string
341
+ */
342
+ protected function _convertOpeningHoursTime($time)
343
+ {
344
+ $value = substr(preg_replace('/[^0-9]+/', '', (string)$time), 0, 4);
345
+ if ($value === '' || $value === false) {
346
+ return null;
347
+ }
348
+ $hour = floor(intval($value) / 100);
349
+ $minute = intval($value) % 100;
350
+ if ($hour < 0 || $hour > 23 || $minute < 0 || $minute > 59) {
351
+ return null;
352
+ }
353
+ return sprintf('%02d:%02d', $hour, $minute);
354
+ }
355
+ }
app/code/community/Transsmart/Shipping/Helper/Pickupaddress.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Helper_Pickupaddress extends Mage_Core_Helper_Abstract
9
+ {
10
+ /**
11
+ * Retrieves the pickup address from a quote.
12
+ *
13
+ * @param Mage_Sales_Model_Quote $quote
14
+ * @return Mage_Sales_Model_Quote_Address|null Returns the pickup address, otherwise null
15
+ */
16
+ public function getPickupAddressFromQuote($quote)
17
+ {
18
+ /** @var Mage_Sales_Model_Quote_Address $_address */
19
+ foreach ($quote->getAddressesCollection() as $_address) {
20
+ if (!$_address->isDeleted() && $_address->getAddressType() == 'transsmart_pickup') {
21
+ return $_address;
22
+ }
23
+ }
24
+ return null;
25
+ }
26
+
27
+ /**
28
+ * Retrieves the pickup address from an order.
29
+ *
30
+ * @param Mage_Sales_Model_Order $order
31
+ * @return Mage_Sales_Model_Order_Address|null Returns the pickup address, otherwise null
32
+ */
33
+ public function getPickupAddressFromOrder($order)
34
+ {
35
+ /** @var Mage_Sales_Model_Quote_Address $_address */
36
+ foreach ($order->getAddressesCollection() as $_address) {
37
+ if (!$_address->isDeleted() && $_address->getAddressType() == 'transsmart_pickup') {
38
+ return $_address;
39
+ }
40
+ }
41
+ return null;
42
+ }
43
+
44
+ /**
45
+ * @param Mage_Sales_Model_Quote $quote
46
+ * @param Mage_Sales_Model_Quote_Address $pickupAddress
47
+ * @return $this
48
+ */
49
+ public function setQuotePickupAddress($quote, $pickupAddress)
50
+ {
51
+ $currentPickupAddress = null;
52
+ foreach ($quote->getAddressesCollection() as $_address) {
53
+ if (!$_address->isDeleted() && $_address->getAddressType() == 'transsmart_pickup') {
54
+ $currentPickupAddress = $_address;
55
+ break;
56
+ }
57
+ }
58
+
59
+ if (!empty($currentPickupAddress)) {
60
+ $currentPickupAddress->addData($pickupAddress->getData());
61
+ }
62
+ else {
63
+ $quote->addAddress($pickupAddress->setAddressType('transsmart_pickup'));
64
+ }
65
+
66
+ return $this;
67
+ }
68
+
69
+ /**
70
+ * Saves the location data into the specified quote.
71
+ *
72
+ * @param Mage_Sales_Model_Quote $quote
73
+ * @param array $pickupAddressData
74
+ * @return $this
75
+ * @throws Exception
76
+ */
77
+ public function savePickupAddressIntoQuote($quote, $pickupAddressData)
78
+ {
79
+ /** @var Mage_Sales_Model_Quote_Address $pickupAddress */
80
+ $pickupAddress = Mage::getModel('sales/quote_address')
81
+ ->setSaveInAddressBook(0);
82
+
83
+ // pre-populate the pickup address with the shipping address details
84
+ /** @var Mage_Sales_Model_Quote_Address $shippingAddress */
85
+ $shippingAddress = $quote->getShippingAddress();
86
+ $pickupAddress->setCustomerId($shippingAddress->getCustomerId())
87
+ ->setPrefix($shippingAddress->getPrefix())
88
+ ->setFirstname($shippingAddress->getFirstname())
89
+ ->setMiddlename($shippingAddress->getMiddlename())
90
+ ->setLastname($shippingAddress->getLastname())
91
+ ->setSuffix($shippingAddress->getSuffix())
92
+ ->setTelephone($shippingAddress->getTelephone());
93
+
94
+ // add the location data
95
+ $pickupAddress->setCompany($pickupAddressData['name'])
96
+ ->setPostcode($pickupAddressData['zipcode'])
97
+ ->setCity($pickupAddressData['city'])
98
+ ->setCountryId($pickupAddressData['country'])
99
+ ->setStreetFull($pickupAddressData['street'] . "\n" . $pickupAddressData['street_no'])
100
+ ->setTranssmartServicepointId($pickupAddressData['servicepoint_id']);
101
+
102
+ return $this->setQuotePickupAddress($quote, $pickupAddress);
103
+ }
104
+
105
+ /**
106
+ * Removes the pickup address from the quote.
107
+ *
108
+ * @param Mage_Sales_Model_Quote $quote
109
+ * @return $this
110
+ * @throws Exception
111
+ */
112
+ public function removePickupAddressFromQuote($quote)
113
+ {
114
+ /** @var Mage_Sales_Model_Quote_Address $_address */
115
+ foreach ($quote->getAddressesCollection() as $_address) {
116
+ if ($_address->getAddressType() == 'transsmart_pickup') {
117
+ $_address->isDeleted(true);
118
+ break;
119
+ }
120
+ }
121
+ return $this;
122
+ }
123
+ }
app/code/community/Transsmart/Shipping/Helper/Shipment.php ADDED
@@ -0,0 +1,560 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Helper_Shipment extends Mage_Core_Helper_Abstract
9
+ {
10
+ const XML_PATH_DEFAULT_CARRIERPROFILE = 'transsmart_shipping/default_shipment/carrierprofile';
11
+ const XML_PATH_DEFAULT_SHIPMENTLOCATION = 'transsmart_shipping/default_shipment/shipmentlocation';
12
+ const XML_PATH_DEFAULT_EMAILTYPE = 'transsmart_shipping/default_shipment/emailtype';
13
+ const XML_PATH_DEFAULT_INCOTERM = 'transsmart_shipping/default_shipment/incoterm';
14
+ const XML_PATH_DEFAULT_COSTCENTER = 'transsmart_shipping/default_shipment/costcenter';
15
+ const XML_PATH_DEFAULT_PACKAGETYPE = 'transsmart_shipping/default_shipment/packagetype';
16
+
17
+ const XML_PATH_MAPPING_STREET = 'transsmart_shipping/mapping/street';
18
+ const XML_PATH_MAPPING_STREETNO = 'transsmart_shipping/mapping/streetno';
19
+ const XML_PATH_MAPPING_STREET2 = 'transsmart_shipping/mapping/street2';
20
+ const XML_PATH_MAPPING_COUNTRY_OF_ORIGIN = 'transsmart_shipping/mapping/country_of_origin';
21
+ const XML_PATH_MAPPING_HS_CODE = 'transsmart_shipping/mapping/hs_code';
22
+ const XML_PATH_MAPPING_REASON_OF_EXPORT = 'transsmart_shipping/mapping/reason_of_export';
23
+
24
+ // OR'ed values for the 'transsmart_flags' field in the shipment table
25
+ const FLAG_BOOK_ON_CREATE = 1;
26
+ const FLAG_BOOKANDPRINT_ON_CREATE = 2;
27
+
28
+ /**
29
+ * Get all possible Transsmart shipment statuses.
30
+ *
31
+ * @return array
32
+ */
33
+ public function getShipmentStatuses()
34
+ {
35
+ return array(
36
+ 'NONE' => $this->__('NONE'),
37
+ 'NEW' => $this->__('NEW'),
38
+ 'BOOK' => $this->__('BOOK'),
39
+ 'LABL' => $this->__('LABL'),
40
+ 'MANI' => $this->__('MANI'),
41
+ 'ACCEP' => $this->__('ACCEP'),
42
+ 'TRNS' => $this->__('TRNS'),
43
+ 'DONE' => $this->__('DONE'),
44
+ 'APOD' => $this->__('APOD'),
45
+ 'REFU' => $this->__('REFU'),
46
+ 'ERR' => $this->__('ERR'),
47
+ 'DEL' => $this->__('DEL'),
48
+ 'ONHOLD' => $this->__('ONHOLD'),
49
+ );
50
+ }
51
+
52
+ /**
53
+ * Get configured default carrierprofile for the given shipment or store.
54
+ *
55
+ * @param Mage_Sales_Model_Order_Shipment|null $shipment
56
+ * @param null $store
57
+ * @return int
58
+ */
59
+ public function getDefaultCarrierprofileId($shipment = null, $store = null)
60
+ {
61
+ $defaultValue = false;
62
+ if ($shipment instanceof Mage_Sales_Model_Order_Shipment) {
63
+ $shippingMethod = $shipment->getOrder()->getShippingMethod(false);
64
+ $carrierprofile = Mage::getModel('transsmart_shipping/carrierprofile')
65
+ ->loadByShippingMethodCode($shippingMethod);
66
+ $defaultValue = $carrierprofile->getId();
67
+ if (!$defaultValue) {
68
+ $defaultValue = Mage::getStoreConfig(self::XML_PATH_DEFAULT_CARRIERPROFILE, $shipment->getStore());
69
+ }
70
+ }
71
+ if (!$defaultValue) {
72
+ $defaultValue = Mage::getStoreConfig(self::XML_PATH_DEFAULT_CARRIERPROFILE, $store);
73
+ }
74
+ return $defaultValue;
75
+ }
76
+
77
+ /**
78
+ * Get configured default shipmentlocation for the given store.
79
+ *
80
+ * @param null $store
81
+ * @return int
82
+ */
83
+ public function getDefaultShipmentlocationId($store = null)
84
+ {
85
+ $defaultValue = Mage::getStoreConfig(self::XML_PATH_DEFAULT_SHIPMENTLOCATION, $store);
86
+ if (!$defaultValue) {
87
+ $ids = Mage::getResourceModel('transsmart_shipping/shipmentlocation_collection')
88
+ ->addFieldToFilter('is_default', array('eq' => 1))
89
+ ->setPageSize(1)
90
+ ->getAllIds();
91
+ if (count($ids)) {
92
+ $defaultValue = $ids[0];
93
+ }
94
+ }
95
+ return $defaultValue;
96
+ }
97
+
98
+ /**
99
+ * Get configured default emailtype for the given store.
100
+ *
101
+ * @param null $store
102
+ * @return int
103
+ */
104
+ public function getDefaultEmailtypeId($store = null)
105
+ {
106
+ $defaultValue = Mage::getStoreConfig(self::XML_PATH_DEFAULT_EMAILTYPE, $store);
107
+ if (!$defaultValue) {
108
+ $ids = Mage::getResourceModel('transsmart_shipping/emailtype_collection')
109
+ ->addFieldToFilter('is_default', array('eq' => 1))
110
+ ->setPageSize(1)
111
+ ->getAllIds();
112
+ if (count($ids)) {
113
+ $defaultValue = $ids[0];
114
+ }
115
+ }
116
+ return $defaultValue;
117
+ }
118
+
119
+ /**
120
+ * Get configured default incoterm for the given store.
121
+ *
122
+ * @param null $store
123
+ * @return int
124
+ */
125
+ public function getDefaultIncotermId($store = null)
126
+ {
127
+ $defaultValue = Mage::getStoreConfig(self::XML_PATH_DEFAULT_INCOTERM, $store);
128
+ if (!$defaultValue) {
129
+ $ids = Mage::getResourceModel('transsmart_shipping/incoterm_collection')
130
+ ->addFieldToFilter('is_default', array('eq' => 1))
131
+ ->setPageSize(1)
132
+ ->getAllIds();
133
+ if (count($ids)) {
134
+ $defaultValue = $ids[0];
135
+ }
136
+ }
137
+ return $defaultValue;
138
+ }
139
+
140
+ /**
141
+ * Get configured default costcenter for the given store.
142
+ *
143
+ * @param null $store
144
+ * @return int
145
+ */
146
+ public function getDefaultCostcenterId($store = null)
147
+ {
148
+ $defaultValue = Mage::getStoreConfig(self::XML_PATH_DEFAULT_COSTCENTER, $store);
149
+ if (!$defaultValue) {
150
+ $ids = Mage::getResourceModel('transsmart_shipping/costcenter_collection')
151
+ ->addFieldToFilter('is_default', array('eq' => 1))
152
+ ->setPageSize(1)
153
+ ->getAllIds();
154
+ if (count($ids)) {
155
+ $defaultValue = $ids[0];
156
+ }
157
+ }
158
+ return $defaultValue;
159
+ }
160
+
161
+ /**
162
+ * Get configured default packagetype for the given store.
163
+ *
164
+ * @param null $store
165
+ * @return int
166
+ */
167
+ public function getDefaultPackagetypeId($store = null)
168
+ {
169
+ $defaultValue = Mage::getStoreConfig(self::XML_PATH_DEFAULT_PACKAGETYPE, $store);
170
+ if (!$defaultValue) {
171
+ $ids = Mage::getResourceModel('transsmart_shipping/packagetype_collection')
172
+ ->addFieldToFilter('is_default', array('eq' => 1))
173
+ ->setPageSize(1)
174
+ ->getAllIds();
175
+ if (count($ids)) {
176
+ $defaultValue = $ids[0];
177
+ }
178
+ }
179
+ return $defaultValue;
180
+ }
181
+
182
+ /**
183
+ * Get the street and housenumber from the given address. If there's only one street field, try to split it into
184
+ * separate fields.
185
+ *
186
+ * @param Mage_Sales_Model_Order_Address $address
187
+ * @param mixed $store
188
+ * @return array
189
+ */
190
+ protected function _getStreetFields($address, $store = null)
191
+ {
192
+ if ($address->hasTranssmartServicepointId()) {
193
+ // for addresses from the location selector, always use predetermined fields
194
+ $street = $address->getStreet(1);
195
+ $streetNo = $address->getStreet(2);
196
+ $street2 = $address->getStreet(3);
197
+ }
198
+ else {
199
+ // read config settings for street fields mapping
200
+ $mappingStreet = Mage::getStoreConfig(self::XML_PATH_MAPPING_STREET, $store);
201
+ $mappingStreetNo = Mage::getStoreConfig(self::XML_PATH_MAPPING_STREETNO, $store);
202
+ $mappingStreet2 = Mage::getStoreConfig(self::XML_PATH_MAPPING_STREET2, $store);
203
+
204
+ // get street value
205
+ switch ($mappingStreet) {
206
+ case Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Mapping_Street::NONE:
207
+ $street = '';
208
+ break;
209
+ case Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Mapping_Street::FULL:
210
+ $street = trim(implode(' ', $address->getStreet()));
211
+ break;
212
+ default:
213
+ $street = $address->getStreet($mappingStreet);
214
+ }
215
+
216
+ // get streetno value
217
+ switch ($mappingStreetNo) {
218
+ case Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Mapping_Street::NONE:
219
+ $streetNo = '';
220
+ break;
221
+ case Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Mapping_Street::FULL:
222
+ $streetNo = trim(implode(' ', $address->getStreet()));
223
+ break;
224
+ default:
225
+ $streetNo = $address->getStreet($mappingStreetNo);
226
+ }
227
+
228
+ // get street2 value
229
+ switch ($mappingStreet2) {
230
+ case Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Mapping_Street::NONE:
231
+ $street2 = '';
232
+ break;
233
+ case Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Mapping_Street::FULL:
234
+ $street2 = trim(implode(' ', $address->getStreet()));
235
+ break;
236
+ default:
237
+ $street2 = $address->getStreet($mappingStreet2);
238
+ }
239
+
240
+ // automatic house number detection
241
+ if ($mappingStreet == $mappingStreetNo) {
242
+ $streetNo = '';
243
+
244
+ if (preg_match('/^(.*) ([0-9]+ .*)$/', $street, $matches)) {
245
+ $street = $matches[1];
246
+ $streetNo = $matches[2];
247
+ }
248
+ elseif (preg_match('/^(.*) ([0-9]+.*)$/', $street, $matches)) {
249
+ $street = $matches[1];
250
+ $streetNo = $matches[2];
251
+ }
252
+ elseif (preg_match('/^(.*) ([0-9]+.*)$/', $street, $matches)) {
253
+ $street = $matches[1];
254
+ $streetNo = $matches[2];
255
+ }
256
+ }
257
+ }
258
+
259
+ // house number cannot be empty
260
+ if ($streetNo === '') {
261
+ $streetNo = '.';
262
+ }
263
+
264
+ return array($street, $streetNo, $street2);
265
+ }
266
+
267
+ /**
268
+ * Export the given shipment to the Transsmart API.
269
+ *
270
+ * @param Mage_Sales_Model_Order_Shipment $shipment
271
+ */
272
+ public function doExport($shipment)
273
+ {
274
+ // is it already exported?
275
+ if ($shipment->getTranssmartDocumentId()) {
276
+ return;
277
+ }
278
+
279
+ /** @var Transsmart_Shipping_Model_Carrierprofile $carrierprofile */
280
+ $carrierprofile = Mage::getModel('transsmart_shipping/carrierprofile')
281
+ ->load($shipment->getTranssmartCarrierprofileId());
282
+ if (!$carrierprofile->getId()) {
283
+ return;
284
+ }
285
+
286
+ $store = $shipment->getStore();
287
+ $address = $shipment->getShippingAddress();
288
+ $invoiceAddress = $shipment->getBillingAddress();
289
+
290
+ // check if the order has a pickup address (location selector is used)
291
+ $pickupAddress = Mage::helper('transsmart_shipping/pickupaddress')
292
+ ->getPickupAddressFromOrder($shipment->getOrder());
293
+ $servicePointId = null;
294
+ if ($pickupAddress) {
295
+ $address = $pickupAddress;
296
+ $invoiceAddress = $shipment->getShippingAddress();
297
+ $servicePointId = $pickupAddress->getTranssmartServicepointId();
298
+ }
299
+
300
+ // determine address name and contact
301
+ $addressName = $address->getCompany();
302
+ $addressContact = $address->getName();
303
+ if ($addressName == '') {
304
+ $addressName = $addressContact;
305
+ }
306
+
307
+ // determine invoice address name and contact
308
+ $invoiceAddressName = $invoiceAddress->getCompany();
309
+ $invoiceAddressContact = $invoiceAddress->getName();
310
+ if ($invoiceAddressName == '') {
311
+ $invoiceAddressName = $invoiceAddressContact;
312
+ }
313
+
314
+ // split street fields into street and house number
315
+ list($addressStreet, $addressStreetNo, $addressStreet2) =
316
+ $this->_getStreetFields($address, $store);
317
+ list($invoiceAddressStreet, $invoiceAddressStreetNo, $invoiceAddressStreet2) =
318
+ $this->_getStreetFields($invoiceAddress, $store);
319
+
320
+ // calculate shipment value and prepare delivery note lines
321
+ $shipmentValue = 0.0;
322
+ $deliveryNoteInfoLines = array();
323
+ /** @var Mage_Sales_Model_Order_Shipment_Item $_item */
324
+ foreach ($shipment->getAllItems() as $_item) {
325
+ $shipmentValue += $_item->getPrice() * $_item->getQty();
326
+
327
+ $_line = array(
328
+ 'ArticleId' => $_item->getSku(),
329
+ 'ArticleName' => $_item->getName(),
330
+ 'Description' => $_item->getDescription(),
331
+ 'Price' => $_item->getPrice(),
332
+ 'Currency' => $store->getCurrentCurrencyCode(),
333
+ 'Quantity' => $_item->getQty(),
334
+ 'QuantityBackorder' => floatval($_item->getOrderItem()->getQtyBackordered()),
335
+ 'QuantityOrder' => $_item->getOrderItem()->getQtyOrdered(),
336
+ 'CountryOfOrigin' => Mage::getStoreConfig('shipping/origin/country_id', $store),
337
+ 'ReasonOfExport' => 'Sale',
338
+ );
339
+
340
+ $_additionalFields = array(
341
+ 'Description' => 'description',
342
+ 'CountryOfOrigin' => Mage::getStoreConfig(self::XML_PATH_MAPPING_COUNTRY_OF_ORIGIN, $store),
343
+ 'HSCode' => Mage::getStoreConfig(self::XML_PATH_MAPPING_HS_CODE, $store),
344
+ 'ReasonOfExport' => Mage::getStoreConfig(self::XML_PATH_MAPPING_REASON_OF_EXPORT, $store),
345
+ );
346
+ $_product = $_item->getOrderItem()->getProduct();
347
+ foreach ($_additionalFields as $_field => $_attributeCode) {
348
+ if (empty($_attributeCode)) {
349
+ continue;
350
+ }
351
+ if ($_attribute = $_product->getResource()->getAttribute($_attributeCode)) {
352
+ if ($_attribute->getBackendType() == 'int' && $_attribute->getFrontendInput() == 'select') {
353
+ // dropdown or multiselect field; use the frontend label
354
+ $_attribute->setStoreId($store->getId());
355
+ $_value = $_attribute->getFrontend()->getValue($_product);
356
+ }
357
+ else {
358
+ $_value = $_product->getData($_attributeCode);
359
+ }
360
+ if ($_value) {
361
+ $_line[$_field] = $_value;
362
+ }
363
+ }
364
+ }
365
+
366
+ $deliveryNoteInfoLines[] = $_line;
367
+ }
368
+
369
+ // prepare the document
370
+ $document = array(
371
+ 'Reference' => $shipment->getIncrementId(),
372
+ 'CarrierProfileId' => $carrierprofile->getId(),
373
+ 'CarrierId' => $carrierprofile->getCarrierId(),
374
+ 'ServiceLevelTimeId' => $carrierprofile->getServicelevelTimeId(),
375
+ 'ServiceLevelOtherId' => $carrierprofile->getServicelevelOtherId(),
376
+ 'ShipmentLocationId' => $shipment->getTranssmartShipmentlocationId(),
377
+ 'MailTypeId' => $shipment->getTranssmartEmailtypeId(),
378
+ 'IncotermId' => $shipment->getTranssmartIncotermId(),
379
+ 'CostCenterId' => $shipment->getTranssmartCostcenterId(),
380
+ 'RefOrder' => $shipment->getOrder()->getIncrementId(),
381
+ 'RefServicePoint' => $servicePointId,
382
+ 'ShipmentValue' => $shipmentValue,
383
+ 'AddressEmailPickup' => Mage::getStoreConfig('trans_email/ident_general/email', $store),
384
+ 'AddressName' => $addressName,
385
+ 'AddressContact' => $addressContact,
386
+ 'AddressStreet' => $addressStreet,
387
+ 'AddressStreetNo' => $addressStreetNo,
388
+ 'AddressStreet2' => $addressStreet2,
389
+ 'AddressZipcode' => $address->getPostcode(),
390
+ 'AddressCity' => $address->getCity(),
391
+ 'AddressState' => $address->getRegionCode(),
392
+ 'AddressCountry' => $address->getCountry(),
393
+ 'AddressPhone' => $address->getTelephone(),
394
+ 'AddressFax' => $address->getFax(),
395
+ 'AddressEmail' => $shipment->getShippingAddress()->getEmail(),
396
+ 'AddressCustomerNo' => $address->getCustomerId(),
397
+ 'AddressNameInvoice' => $invoiceAddressName,
398
+ 'AddressContactInvoice' => $invoiceAddressContact,
399
+ 'AddressStreetInvoice' => $invoiceAddressStreet,
400
+ 'AddressStreetNoInvoice' => $invoiceAddressStreetNo,
401
+ 'AddressStreet2Invoice' => $invoiceAddressStreet2,
402
+ 'AddressZipcodeInvoice' => $invoiceAddress->getPostcode(),
403
+ 'AddressCityInvoice' => $invoiceAddress->getCity(),
404
+ 'AddressStateInvoice' => $invoiceAddress->getRegionCode(),
405
+ 'AddressCountryInvoice' => $invoiceAddress->getCountry(),
406
+ 'AddressPhoneInvoice' => $invoiceAddress->getTelephone(),
407
+ 'AddressFaxInvoice' => $invoiceAddress->getFax(),
408
+ 'AddressEmailInvoice' => $invoiceAddress->getEmail(),
409
+ 'AddressCustomerNoInvoice' => $invoiceAddress->getCustomerId(),
410
+ 'AddressVatNumberInvoice' => $shipment->getOrder()->getCustomerTaxvat(),
411
+ 'ColliInformation' => unserialize($shipment->getTranssmartPackages()),
412
+ 'DeliveryNoteInfo' => array(
413
+ array(
414
+ 'DeliveryNoteInfoLines' => $deliveryNoteInfoLines
415
+ )
416
+ )
417
+ );
418
+
419
+ // dispatch event so other extensions can update the document
420
+ $transport = new Varien_Object(array('document' => $document));
421
+ Mage::dispatchEvent('transsmart_shipping_shipment_export_before', array(
422
+ 'shipment' => $shipment,
423
+ 'transport' => $transport
424
+ ));
425
+ $document = $transport->getDocument();
426
+
427
+ // send the document to Transsmart
428
+ $response = Mage::helper('transsmart_shipping')->getApiClient()->createDocument($document);
429
+
430
+ // save document ID and status into shipment record
431
+ if (isset($response['Id']) && isset($response['Status'])) {
432
+ $shipment->setTranssmartDocumentId($response['Id']);
433
+ $shipment->setTranssmartStatus($response['Status']);
434
+
435
+ $shipment->getResource()->saveAttribute($shipment, array(
436
+ 'transsmart_document_id',
437
+ 'transsmart_status'
438
+ ));
439
+
440
+ // book and print if flags indicate so
441
+ $flags = (int)$shipment->getTranssmartFlags();
442
+ try {
443
+ if (($flags & Transsmart_Shipping_Helper_Shipment::FLAG_BOOKANDPRINT_ON_CREATE)) {
444
+ $this->doBookAndPrint($shipment);
445
+ }
446
+ elseif (($flags & Transsmart_Shipping_Helper_Shipment::FLAG_BOOK_ON_CREATE)) {
447
+ $this->doBooking($shipment);
448
+ }
449
+ }
450
+ catch (Exception $exception) {
451
+ Mage::logException($exception);
452
+ }
453
+ }
454
+ }
455
+
456
+ /**
457
+ * Call doBookAndPrint for a Transsmart shipment and process the response. Returns TRUE if successful.
458
+ *
459
+ * @param Mage_Sales_Model_Order_Shipment $shipment
460
+ * @return bool
461
+ * @throws Exception
462
+ */
463
+ public function doBookAndPrint($shipment)
464
+ {
465
+ if (!$shipment->getTranssmartDocumentId()) {
466
+ Mage::throwException($this->__('Transsmart document ID is not known.'));
467
+ }
468
+
469
+ try {
470
+ // call Transsmart API doBookAndPrint method
471
+ Mage::helper('transsmart_shipping')->getApiClient()->doBookAndPrint(
472
+ $shipment->getTranssmartDocumentId(),
473
+ Mage::getStoreConfig(Transsmart_Shipping_Helper_Data::XML_PATH_CONNECTION_USERNAME, 0),
474
+ false,
475
+ Mage::getStoreConfig(
476
+ Transsmart_Shipping_Helper_Data::XML_PATH_PRINT_QZHOST,
477
+ $shipment->getStore()
478
+ ),
479
+ Mage::getStoreConfig(
480
+ Transsmart_Shipping_Helper_Data::XML_PATH_PRINT_SELECTEDPRINTER,
481
+ $shipment->getStore()
482
+ )
483
+ );
484
+ }
485
+ catch (Exception $exception) {
486
+ Mage::getSingleton('transsmart_shipping/sync')->syncShipment($shipment);
487
+ throw $exception;
488
+ }
489
+ Mage::getSingleton('transsmart_shipping/sync')->syncShipment($shipment);
490
+
491
+ return true;
492
+ }
493
+
494
+ /**
495
+ * Call doBooking for a Transsmart shipment and process the response. Returns TRUE if successful.
496
+ *
497
+ * @param Mage_Sales_Model_Order_Shipment $shipment
498
+ * @return bool
499
+ * @throws Exception
500
+ */
501
+ public function doBooking($shipment)
502
+ {
503
+ if (!$shipment->getTranssmartDocumentId()) {
504
+ Mage::throwException($this->__('Transsmart document ID is not known.'));
505
+ }
506
+
507
+ try {
508
+ // call Transsmart API doBooking method
509
+ Mage::helper('transsmart_shipping')->getApiClient()->doBooking(
510
+ $shipment->getTranssmartDocumentId()
511
+ );
512
+ }
513
+ catch (Exception $exception) {
514
+ Mage::getSingleton('transsmart_shipping/sync')->syncShipment($shipment);
515
+ throw $exception;
516
+ }
517
+ Mage::getSingleton('transsmart_shipping/sync')->syncShipment($shipment);
518
+
519
+ return true;
520
+ }
521
+
522
+ /**
523
+ * Call doLabel for a Transsmart shipment and return the label contents (PDF)
524
+ *
525
+ * @param Mage_Sales_Model_Order_Shipment $shipment
526
+ * @return bool
527
+ * @throws Exception
528
+ */
529
+ public function doLabel($shipment)
530
+ {
531
+ if (!$shipment->getTranssmartDocumentId()) {
532
+ Mage::throwException($this->__('Transsmart document ID is not known.'));
533
+ }
534
+
535
+ try {
536
+ // call Transsmart API doLabel method
537
+ Mage::helper('transsmart_shipping')->getApiClient()->doLabel(
538
+ $shipment->getTranssmartDocumentId(),
539
+ Mage::getStoreConfig(Transsmart_Shipping_Helper_Data::XML_PATH_CONNECTION_USERNAME, 0),
540
+ false,
541
+ false,
542
+ Mage::getStoreConfig(
543
+ Transsmart_Shipping_Helper_Data::XML_PATH_PRINT_QZHOST,
544
+ $shipment->getStore()
545
+ ),
546
+ Mage::getStoreConfig(
547
+ Transsmart_Shipping_Helper_Data::XML_PATH_PRINT_SELECTEDPRINTER,
548
+ $shipment->getStore()
549
+ )
550
+ );
551
+ }
552
+ catch (Exception $exception) {
553
+ Mage::getSingleton('transsmart_shipping/sync')->syncShipment($shipment);
554
+ throw $exception;
555
+ }
556
+ Mage::getSingleton('transsmart_shipping/sync')->syncShipment($shipment);
557
+
558
+ return true;
559
+ }
560
+ }
app/code/community/Transsmart/Shipping/Model/Abstract.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Transsmart Abstract Model
4
+ *
5
+ * @category Transsmart
6
+ * @package Transsmart_Shipping
7
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
8
+ */
9
+ abstract class Transsmart_Shipping_Model_Abstract extends Mage_Core_Model_Abstract
10
+ {
11
+ /**
12
+ * A list of API keys to be mapped to database columns.
13
+ * @var array
14
+ */
15
+ protected $apiKeysMapping = array();
16
+
17
+ /**
18
+ * Maps the API keys to the database columns.
19
+ * When an API key is not present in the mapping list, the API key is used as is.
20
+ * This ensures that all data is always present.
21
+ *
22
+ * @param array $data
23
+ * @return array
24
+ */
25
+ public function mapApiKeysToDbColumns(array $data)
26
+ {
27
+ $mappedData = array();
28
+
29
+ foreach ($data as $key => $value) {
30
+ $newKey = isset($this->apiKeysMapping[$key]) ? $this->apiKeysMapping[$key] : $key;
31
+ $mappedData[$newKey] = $value;
32
+ }
33
+
34
+ return $mappedData;
35
+ }
36
+
37
+ }
app/code/community/Transsmart/Shipping/Model/Adminhtml/Observer.php ADDED
@@ -0,0 +1,304 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Adminhtml_Observer
9
+ {
10
+ /**
11
+ * This event observer is responsible for adding the carrier profiles to the system configuration section.
12
+ *
13
+ * @see Mage_Adminhtml_Model_Config::_initSectionsAndTabs
14
+ * @param Varien_Event_Observer $observer
15
+ */
16
+ public function adminhtmlInitSystemConfig($observer)
17
+ {
18
+ // no need to add the carrier profiles for other config sections
19
+ $section = Mage::app()->getRequest()->getParam('section');
20
+ if ($section != 'transsmart_carrier_profiles') {
21
+ return;
22
+ }
23
+
24
+ Varien_Profiler::start(__METHOD__);
25
+
26
+ /** @var Mage_Core_Model_Config_Base $config */
27
+ $config = $observer->getConfig();
28
+
29
+ /** @var Mage_Core_Model_Config_Element $groups */
30
+ $groups = $config->getNode('sections/transsmart_carrier_profiles/groups');
31
+
32
+ /** @var Transsmart_Shipping_Model_Resource_Carrierprofile_Collection $carrierprofileCollection */
33
+ $carrierprofileCollection = Mage::getResourceModel('transsmart_shipping/carrierprofile_collection')
34
+ ->joinCarrier()
35
+ ->joinServicelevelTime()
36
+ ->joinServicelevelOther();
37
+
38
+ foreach ($carrierprofileCollection as $_carrierprofile) {
39
+ /** @var Mage_Core_Model_Config_Element $_group */
40
+ $_group = clone $groups->template;
41
+ $groups->template->sort_order += 10;
42
+
43
+ // add carrierprofile data to the fieldset so it can be used by the renderer
44
+ foreach ($_carrierprofile->getData() as $_key => $_value) {
45
+ $_group->$_key = $_value;
46
+ }
47
+
48
+ // remove location_select if carrier does not allow location selector
49
+ if (!$_carrierprofile->getCarrierLocationSelect()) {
50
+ unset($_group->fields->location_select);
51
+ }
52
+
53
+ $groups->addChild('carrierprofile_' . $_carrierprofile->getId())
54
+ ->extend($_group);
55
+ }
56
+
57
+ unset($groups->template);
58
+
59
+ Varien_Profiler::stop(__METHOD__);
60
+ //echo '<pre>'.htmlspecialchars($groups->asNiceXml());exit;
61
+ }
62
+
63
+ /**
64
+ * Method is triggered when the data is being processed after a post is done on sales order create.
65
+ *
66
+ * @see Mage_Adminhtml_Sales_Order_CreateController::_processActionData
67
+ * @param Varien_Event_Observer $observer
68
+ */
69
+ public function adminhtmlSalesOrderCreateProcessData($observer)
70
+ {
71
+ /** @var Mage_Adminhtml_Model_Sales_Order_Create $orderCreateModel */
72
+ $orderCreateModel = $observer->getOrderCreateModel();
73
+
74
+ // prevent removing pickup address when no shipping method is posted
75
+ if (!$orderCreateModel->hasShippingMethod()) {
76
+ return;
77
+ }
78
+
79
+ /** @var Mage_Sales_Model_Quote $quote */
80
+ $quote = $orderCreateModel->getQuote();
81
+
82
+ // try to load the carrierprofile based on the shipping method
83
+ $carrierProfile = Mage::getModel('transsmart_shipping/carrierprofile')
84
+ ->loadByShippingMethodCode($orderCreateModel->getShippingMethod());
85
+ if (!$carrierProfile->getId() || !$carrierProfile->isLocationSelectEnabled()) {
86
+ // location selector disabled. remove the pickup addresses, if there are any
87
+ Mage::helper('transsmart_shipping/pickupaddress')->removePickupAddressFromQuote($quote);
88
+ return;
89
+ }
90
+
91
+ // get pickup address data from order create model (post data)
92
+ $pickupAddressData = $orderCreateModel->getData('transsmart_pickup_address_data');
93
+ if (empty($pickupAddressData)) {
94
+ // nothing posted... does the quote already have a pickup address?
95
+ $pickupAddress = Mage::helper('transsmart_shipping/pickupaddress')->getPickupAddressFromQuote($quote);
96
+ if ($pickupAddress) {
97
+ return;
98
+ }
99
+ Mage::throwException(Mage::helper('transsmart_shipping')->__('A pickup location has to be selected'));
100
+ }
101
+
102
+ // base64 decode, convert Latin1 to UTF-8 and JSON decode
103
+ $pickupAddressData = Zend_Json_Decoder::decode(utf8_encode(base64_decode($pickupAddressData)));
104
+ // TODO: verify pickup address data
105
+ Mage::helper('transsmart_shipping/pickupaddress')
106
+ ->savePickupAddressIntoQuote($quote, $pickupAddressData);
107
+ }
108
+
109
+ /**
110
+ * This observer adds the Transsmart shipment detail fields to the create/view shipment pages in the admin panel.
111
+ *
112
+ * @see Mage_Adminhtml_Block_Template::_toHtml
113
+ * @param Varien_Event_Observer $observer
114
+ */
115
+ public function adminhtmlBlockHtmlBefore($observer)
116
+ {
117
+ /** @var Mage_Adminhtml_Block_Template $block */
118
+ $block = $observer->getEvent()->getBlock();
119
+
120
+ if ($block instanceof Mage_Adminhtml_Block_Sales_Order_Shipment_Create_Form) {
121
+ // verify shipping method
122
+ $shippingMethod = $block->getOrder()->getShippingMethod();
123
+ if (!Mage::helper('transsmart_shipping')->isTranssmartShippingMethod($shippingMethod)) {
124
+ return;
125
+ }
126
+
127
+ // add the Transsmart shipment detail block, replacing the original 'shipment_tracking' block
128
+ $block->setChild('shipment_tracking', $block->getLayout()->createBlock(
129
+ 'transsmart_shipping/adminhtml_sales_order_shipment_create_detail',
130
+ 'shipment.create.transsmart.detail'
131
+ ));
132
+ }
133
+ elseif ($block instanceof Mage_Adminhtml_Block_Sales_Order_Shipment_Create_Items) {
134
+ // verify shipping method
135
+ $shippingMethod = $block->getOrder()->getShippingMethod();
136
+ if (!Mage::helper('transsmart_shipping')->isTranssmartShippingMethod($shippingMethod)) {
137
+ return;
138
+ }
139
+
140
+ /** @var Mage_Adminhtml_Block_Widget_Button $submitButton */
141
+ $submitButton = $block->getChild('submit_button');
142
+ if (!$submitButton) {
143
+ return;
144
+ }
145
+
146
+ // add the Transsmart action checkboxes to the 'Submit Shipment' button
147
+ $submitButton->setBeforeHtml($block->getLayout()->createBlock(
148
+ 'adminhtml/template',
149
+ 'shipment.create.transsmart.action',
150
+ array(
151
+ 'template' => 'transsmart/shipping/sales/order/shipment/create/action.phtml'
152
+ )
153
+ )->toHtml());
154
+
155
+ // change button caption from 'Submit Shipment' to 'Create Shipment' for clarity
156
+ $submitButton->setLabel(Mage::helper('sales')->__('Create Shipment'));
157
+ }
158
+ elseif ($block instanceof Mage_Adminhtml_Block_Sales_Order_Shipment_View_Form) {
159
+ // verify shipping method
160
+ $shippingMethod = $block->getOrder()->getShippingMethod();
161
+ if (!Mage::helper('transsmart_shipping')->isTranssmartShippingMethod($shippingMethod)) {
162
+ return;
163
+ }
164
+
165
+ // add the Transsmart shipment detail block, replacing the original 'shipment_tracking' block
166
+ $block->setChild('shipment_tracking', $block->getLayout()->createBlock(
167
+ 'transsmart_shipping/adminhtml_sales_order_shipment_view_detail',
168
+ 'shipment.view.transsmart.detail'
169
+ ));
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Observer for the 'sales_order_shipment_save_before' event. Set the posted default shipmentlocation, emailtype,
175
+ * incoterm, costcenter, packages and flags for new shipments created from the admin panel.
176
+ *
177
+ * Note: There's also a global observer for this event, which is called before this one.
178
+ * @see Transsmart_Shipping_Model_Observer::salesOrderShipmentSaveBefore
179
+ *
180
+ * @see Mage_Sales_Model_Order_Shipment::_beforeSave
181
+ * @param Varien_Event_Observer $observer
182
+ */
183
+ public function salesOrderShipmentSaveBefore($observer)
184
+ {
185
+ /** @var Mage_Sales_Model_Order_Shipment $shipment */
186
+ $shipment = $observer->getShipment();
187
+
188
+ // is it a new shipment?
189
+ if (!$shipment->isObjectNew()) {
190
+ return;
191
+ }
192
+
193
+ // does it use one of our shipping methods?
194
+ $shippingMethod = $shipment->getOrder()->getShippingMethod();
195
+ if (!Mage::helper('transsmart_shipping')->isTranssmartShippingMethod($shippingMethod)) {
196
+ return;
197
+ }
198
+
199
+ // get posted data
200
+ if (!($frontController = Mage::app()->getFrontController())) {
201
+ return;
202
+ }
203
+ $shipmentPostData = $frontController->getRequest()->getPost('shipment');
204
+
205
+ // update the shipment model
206
+ if (!Mage::helper('transsmart_shipping')->isTranssmartPickup($shippingMethod)) {
207
+ if (!empty($shipmentPostData['transsmart_carrierprofile_id'])) {
208
+ $shipment->setTranssmartCarrierprofileId($shipmentPostData['transsmart_carrierprofile_id']);
209
+ }
210
+ }
211
+ if (!empty($shipmentPostData['transsmart_shipmentlocation_id'])) {
212
+ $shipment->setTranssmartShipmentlocationId($shipmentPostData['transsmart_shipmentlocation_id']);
213
+ }
214
+ if (!empty($shipmentPostData['transsmart_emailtype_id'])) {
215
+ $shipment->setTranssmartEmailtypeId($shipmentPostData['transsmart_emailtype_id']);
216
+ }
217
+ if (!empty($shipmentPostData['transsmart_costcenter_id'])) {
218
+ $shipment->setTranssmartCostcenterId($shipmentPostData['transsmart_costcenter_id']);
219
+ }
220
+ if (!empty($shipmentPostData['transsmart_incoterm'])) {
221
+ $shipment->setTranssmartIncotermId($shipmentPostData['transsmart_incoterm']);
222
+ }
223
+
224
+ if (!empty($shipmentPostData['transsmart_package'])) {
225
+ /** @var Transsmart_Shipping_Model_Resource_Packagetype_Collection $packageTypeCollection */
226
+ $packageTypeCollection = Mage::getResourceSingleton('transsmart_shipping/packagetype_collection');
227
+
228
+ $packages = array();
229
+ foreach ($shipmentPostData['transsmart_package'] as $_index => $_packageData) {
230
+ // skip non-numeric indexes
231
+ if (!ctype_digit((string)$_index)) {
232
+ continue;
233
+ }
234
+
235
+ // use default package type if none is specified
236
+ if ($_packageData['package_type'] == 0) {
237
+ $_packageData['package_type'] = Mage::helper('transsmart_shipping/shipment')
238
+ ->getDefaultPackagetypeId($shipment->getStore());
239
+ }
240
+
241
+ $_packageTypeCode = (string)$_packageData['package_type'];
242
+ $_packageTypeDescription = '';
243
+
244
+ /** @var Transsmart_Shipping_Model_Packagetype $_packageType */
245
+ if (($_packageType = $packageTypeCollection->getItemById($_packageData['package_type']))) {
246
+ $_packageTypeCode = $_packageType->getCode();
247
+ $_packageTypeDescription = $_packageType->getName();
248
+
249
+ if (!isset($_packageData['length'])) {
250
+ $_packageData['length'] = $_packageType->getLength();
251
+ }
252
+ if (!isset($_packageData['width'])) {
253
+ $_packageData['width'] = $_packageType->getWidth();
254
+ }
255
+ if (!isset($_packageData['height'])) {
256
+ $_packageData['height'] = $_packageType->getHeight();
257
+ }
258
+ if (!isset($_packageData['weight'])) {
259
+ $_packageData['weight'] = $_packageType->getWeight();
260
+ }
261
+ }
262
+
263
+ $packages[] = array(
264
+ 'PackagingType' => $_packageTypeCode,
265
+ 'Description' => $_packageTypeDescription,
266
+ 'Quantity' => (int)$_packageData['qty'],
267
+ 'Length' => Mage::app()->getLocale()->getNumber($_packageData['length']),
268
+ 'Width' => Mage::app()->getLocale()->getNumber($_packageData['width']),
269
+ 'Height' => Mage::app()->getLocale()->getNumber($_packageData['height']),
270
+ 'Weight' => Mage::app()->getLocale()->getNumber($_packageData['weight']),
271
+ );
272
+ }
273
+
274
+ $shipment->setTranssmartPackages(serialize($packages));
275
+ }
276
+
277
+ $flags = (int)$shipment->getTranssmartFlags();
278
+ if (!empty($shipmentPostData['transsmart_book'])) {
279
+ $flags |= Transsmart_Shipping_Helper_Shipment::FLAG_BOOK_ON_CREATE;
280
+ }
281
+ if (!empty($shipmentPostData['transsmart_bookandprint'])) {
282
+ $flags |= Transsmart_Shipping_Helper_Shipment::FLAG_BOOKANDPRINT_ON_CREATE;
283
+ }
284
+ $shipment->setTranssmartFlags($flags);
285
+ }
286
+
287
+ /**
288
+ * Observer for the 'sales_order_shipment_save_after' event. Create a document for new shipments created from the
289
+ * admin panel immediately.
290
+ *
291
+ * @see Mage_Sales_Model_Order_Shipment::_afterSave
292
+ * @param Varien_Event_Observer $observer
293
+ */
294
+ public function salesOrderShipmentSaveAfter($observer)
295
+ {
296
+ /** @var Mage_Sales_Model_Order_Shipment $shipment */
297
+ $shipment = $observer->getShipment();
298
+
299
+ // TODO: make a setting for this?
300
+
301
+ // export to Transsmart API
302
+ Mage::helper('transsmart_shipping/shipment')->doExport($shipment);
303
+ }
304
+ }
app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Backend/Localized.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Adminhtml_System_Config_Backend_Localized extends Varien_Object
9
+ {
10
+ /**
11
+ * Translate config value after loading.
12
+ */
13
+ public function afterLoad()
14
+ {
15
+ $value = (string)$this->getValue();
16
+ $helper = Mage::helper('transsmart_shipping');
17
+
18
+ if (!empty($value) && ($localized = $helper->__($value))) {
19
+ $this->setValue($localized);
20
+ }
21
+
22
+ return $this;
23
+ }
24
+ }
app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Source/Basedata/Abstract.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Basedata_Abstract
9
+ {
10
+ /**
11
+ * @param string $modelName
12
+ * @param string $idField
13
+ * @param string $nameField
14
+ * @param string $defaultField
15
+ * @return array
16
+ */
17
+ public function getAvailableOptions($modelName, $idField = 'id', $nameField = 'name', $defaultField = 'is_default')
18
+ {
19
+ $_helper = Mage::helper('adminhtml');
20
+
21
+ $options = array();
22
+
23
+ $default = $_helper->__('(empty)');
24
+
25
+ /** @var Mage_Core_Model_Resource_Db_Collection_Abstract $collection */
26
+ $collection = Mage::getModel($modelName)->getCollection();
27
+ foreach ($collection as $_model) {
28
+ $options[] = array(
29
+ 'value' => $_model->getData($idField),
30
+ 'label' => $_model->getData($nameField),
31
+ );
32
+
33
+ if ($_model->getData($defaultField)) {
34
+ $default = $_model->getData($nameField);
35
+ }
36
+ }
37
+
38
+ array_unshift($options, array(
39
+ 'value' => 0,
40
+ 'label' => $_helper->__('Transsmart default value: %s', $default)
41
+ ));
42
+
43
+ return $options;
44
+ }
45
+ }
app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Source/Basedata/Carrierprofile.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Basedata_Carrierprofile
9
+ extends Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Basedata_Abstract
10
+ {
11
+ /**
12
+ * @return array
13
+ */
14
+ public function toOptionArray()
15
+ {
16
+ $options = array(
17
+ array(
18
+ 'value' => 0,
19
+ 'label' => Mage::helper('adminhtml')->__('(empty)')
20
+ )
21
+ );
22
+
23
+ /** @var Mage_Core_Model_Resource_Db_Collection_Abstract $collection */
24
+ $collection = Mage::getModel('transsmart_shipping/carrierprofile')->getCollection()
25
+ ->joinCarrier()
26
+ ->joinServicelevelTime()
27
+ ->joinServicelevelOther();
28
+ foreach ($collection as $_model) {
29
+ $options[] = array(
30
+ 'value' => $_model->getData('carrierprofile_id'),
31
+ 'label' => $_model->getName(),
32
+ );
33
+ }
34
+
35
+ return $options;
36
+ }
37
+ }
app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Source/Basedata/Costcenter.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Basedata_Costcenter
9
+ extends Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Basedata_Abstract
10
+ {
11
+ /**
12
+ * @return array
13
+ */
14
+ public function toOptionArray()
15
+ {
16
+ return $this->getAvailableOptions('transsmart_shipping/costcenter', 'costcenter_id');
17
+ }
18
+ }
app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Source/Basedata/Emailtype.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Basedata_Emailtype
9
+ extends Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Basedata_Abstract
10
+ {
11
+ /**
12
+ * @return array
13
+ */
14
+ public function toOptionArray()
15
+ {
16
+ return $this->getAvailableOptions('transsmart_shipping/emailtype', 'emailtype_id');
17
+ }
18
+ }
app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Source/Basedata/Incoterm.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Basedata_Incoterm
9
+ extends Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Basedata_Abstract
10
+ {
11
+ /**
12
+ * @return array
13
+ */
14
+ public function toOptionArray()
15
+ {
16
+ return $this->getAvailableOptions('transsmart_shipping/incoterm', 'incoterm_id');
17
+ }
18
+ }
app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Source/Basedata/Packagetype.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Basedata_Packagetype
9
+ extends Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Basedata_Abstract
10
+ {
11
+ /**
12
+ * @return array
13
+ */
14
+ public function toOptionArray()
15
+ {
16
+ return $this->getAvailableOptions('transsmart_shipping/packagetype', 'packagetype_id');
17
+ }
18
+ }
app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Source/Basedata/Shipmentlocation.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Basedata_Shipmentlocation
9
+ extends Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Basedata_Abstract
10
+ {
11
+ /**
12
+ * @return array
13
+ */
14
+ public function toOptionArray()
15
+ {
16
+ return $this->getAvailableOptions('transsmart_shipping/shipmentlocation', 'shipmentlocation_id');
17
+ }
18
+ }
app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Source/Environment.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Environment
9
+ {
10
+ const STAGING = 0;
11
+ const PRODUCTION = 1;
12
+
13
+ /**
14
+ * @return array
15
+ */
16
+ public function toOptionArray()
17
+ {
18
+ $_helper = Mage::helper('adminhtml');
19
+
20
+ $options = array(
21
+ array(
22
+ 'value' => self::STAGING,
23
+ 'label' => $_helper->__('Staging')
24
+ ),
25
+ array(
26
+ 'value' => self::PRODUCTION,
27
+ 'label' => $_helper->__('Production')
28
+ ),
29
+ );
30
+
31
+ return $options;
32
+ }
33
+ }
app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Source/Mapping/Attribute.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Mapping_Attribute
9
+ {
10
+ /**
11
+ * @return array
12
+ */
13
+ public function toOptionArray()
14
+ {
15
+ $options = array(
16
+ array(
17
+ 'value' => '',
18
+ 'label' => Mage::helper('adminhtml')->__('(empty)')
19
+ )
20
+ );
21
+
22
+ /** @var Mage_Catalog_Model_Resource_Product_Attribute_Collection $attributeCollection */
23
+ $attributeCollection = Mage::getResourceModel('catalog/product_attribute_collection')
24
+ ->addFieldToFilter('is_visible', 1)
25
+ ->addFieldToFilter('frontend_input', array('nin' => array('media_image', 'gallery')))
26
+ ->setOrder('frontend_label', Varien_Data_Collection::SORT_ORDER_ASC);
27
+
28
+ foreach ($attributeCollection as $_attribute) {
29
+ $options[] = array(
30
+ 'value' => $_attribute->getAttributeCode(),
31
+ 'label' => $_attribute->getFrontendLabel()
32
+ );
33
+ }
34
+
35
+ return $options;
36
+ }
37
+ }
app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Source/Mapping/Street.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Mapping_Street
9
+ {
10
+ const FULL = -1;
11
+ const NONE = 0;
12
+ const STREET_1 = 1;
13
+ const STREET_2 = 2;
14
+ const STREET_3 = 3;
15
+ const STREET_4 = 4;
16
+
17
+ /**
18
+ * @return array
19
+ */
20
+ public function toOptionArray()
21
+ {
22
+ $_helper = Mage::helper('adminhtml');
23
+
24
+ $options = array(
25
+ array(
26
+ 'value' => self::NONE,
27
+ 'label' => $_helper->__('(empty)')
28
+ ),
29
+ array(
30
+ 'value' => self::STREET_1,
31
+ 'label' => $_helper->__('Street %s', 1)
32
+ ),
33
+ array(
34
+ 'value' => self::STREET_2,
35
+ 'label' => $_helper->__('Street %s', 2)
36
+ ),
37
+ array(
38
+ 'value' => self::STREET_3,
39
+ 'label' => $_helper->__('Street %s', 3)
40
+ ),
41
+ array(
42
+ 'value' => self::STREET_4,
43
+ 'label' => $_helper->__('Street %s', 4)
44
+ ),
45
+ array(
46
+ 'value' => self::FULL,
47
+ 'label' => $_helper->__('Combined Street Fields')
48
+ ),
49
+ );
50
+
51
+ return $options;
52
+ }
53
+ }
app/code/community/Transsmart/Shipping/Model/Adminhtml/System/Config/Source/Method.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Method
9
+ {
10
+ const NOT_AVAILABLE = '';
11
+ const DELIVERY = 'transsmartdelivery';
12
+ const PICKUP = 'transsmartpickup';
13
+
14
+ /**
15
+ * @return array
16
+ */
17
+ public function toOptionArray()
18
+ {
19
+ $_helper = Mage::helper('adminhtml');
20
+
21
+ $options = array(
22
+ array(
23
+ 'value' => self::NOT_AVAILABLE,
24
+ 'label' => $_helper->__('No')
25
+ ),
26
+ array(
27
+ 'value' => self::DELIVERY,
28
+ 'label' => $_helper->__('As Delivery Option')
29
+ ),
30
+ array(
31
+ 'value' => self::PICKUP,
32
+ 'label' => $_helper->__('As Pickup Option')
33
+ ),
34
+ );
35
+
36
+ return $options;
37
+ }
38
+ }
app/code/community/Transsmart/Shipping/Model/Carrier.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Transsmart Carrier Model
5
+ *
6
+ * @method Transsmart_Shipping_Model_Resource_Carrier _getResource()
7
+ * @method Transsmart_Shipping_Model_Resource_Carrier getResource()
8
+ * @method int getCarrierId()
9
+ * @method Transsmart_Shipping_Model_Carrier setCarrierId(int $value)
10
+ * @method string getCode()
11
+ * @method Transsmart_Shipping_Model_Carrier setCode(string $value)
12
+ * @method string getName()
13
+ * @method Transsmart_Shipping_Model_Carrier setName(string $value)
14
+ * @method bool getLocationSelect()
15
+ * @method Transsmart_Shipping_Model_Carrier setLocationSelect(bool $value)
16
+ *
17
+ * @category Transsmart
18
+ * @package Transsmart_Shipping
19
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
20
+ */
21
+ class Transsmart_Shipping_Model_Carrier extends Transsmart_Shipping_Model_Abstract
22
+ {
23
+ /**
24
+ * A list of API keys to be mapped to database columns.
25
+ * @var array
26
+ */
27
+ protected $apiKeysMapping = array(
28
+ 'Id' => 'carrier_id',
29
+ 'Code' => 'code',
30
+ 'Name' => 'name',
31
+ 'LocationSelect' => 'location_select'
32
+ );
33
+
34
+ /**
35
+ * Object initialization
36
+ */
37
+ protected function _construct()
38
+ {
39
+ $this->_init('transsmart_shipping/carrier');
40
+ }
41
+ }
app/code/community/Transsmart/Shipping/Model/Carrierprofile.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Transsmart Carrier Profile Model
5
+ *
6
+ * @method Transsmart_Shipping_Model_Resource_Carrierprofile _getResource()
7
+ * @method Transsmart_Shipping_Model_Resource_Carrierprofile getResource()
8
+ * @method int getCarrierprofileId()
9
+ * @method Transsmart_Shipping_Model_Carrierprofile setCarrierprofileId(int $value)
10
+ * @method int getCarrierId()
11
+ * @method Transsmart_Shipping_Model_Carrierprofile setCarrierId(int $value)
12
+ * @method int getServicelevelTimeId()
13
+ * @method Transsmart_Shipping_Model_Carrierprofile setServicelevelTimeId(int $value)
14
+ * @method int getServicelevelOtherId()
15
+ * @method Transsmart_Shipping_Model_Carrierprofile setServicelevelOtherId(int $value)
16
+ *
17
+ * @method string getCarrierCode()
18
+ * @method string getCarrierName()
19
+ * @method bool getCarrierLocationSelect()
20
+ * @method string getServicelevelTimeCode()
21
+ * @method string getServicelevelTimeName()
22
+ * @method string getServicelevelOtherCode()
23
+ * @method string getServicelevelOtherName()
24
+ *
25
+ * @category Transsmart
26
+ * @package Transsmart_Shipping
27
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
28
+ */
29
+ class Transsmart_Shipping_Model_Carrierprofile extends Transsmart_Shipping_Model_Abstract
30
+ {
31
+ /**
32
+ * A list of API keys to be mapped to database columns.
33
+ * @var array
34
+ */
35
+ protected $apiKeysMapping = array(
36
+ 'Id' => 'carrierprofile_id',
37
+ 'CarrierId' => 'carrier_id',
38
+ 'ServiceLevelTimeId' => 'servicelevel_time_id',
39
+ 'ServiceLevelOtherId' => 'servicelevel_other_id'
40
+ );
41
+
42
+ /**
43
+ * Object initialization
44
+ */
45
+ protected function _construct()
46
+ {
47
+ $this->_init('transsmart_shipping/carrierprofile');
48
+ }
49
+
50
+ /**
51
+ * Load the carrierprofile by the shipping method code.
52
+ *
53
+ * @param string $shippingMethodCode
54
+ * @return $this
55
+ */
56
+ public function loadByShippingMethodCode($shippingMethodCode)
57
+ {
58
+ if (preg_match('/^transsmart(delivery|pickup)_carrierprofile_([0-9]+)$/', $shippingMethodCode, $match)) {
59
+ $id = (int)$match[2];
60
+ if ($id) {
61
+ $this->load($id);
62
+ }
63
+ }
64
+ return $this;
65
+ }
66
+
67
+ /**
68
+ * Retrieve information from carrier profile configuration
69
+ *
70
+ * @param string $field
71
+ * @param mixed $store
72
+ * @return mixed
73
+ */
74
+ public function getConfigData($field, $store = null)
75
+ {
76
+ $path = 'transsmart_carrier_profiles/carrierprofile_' . $this->getId() . '/' . $field;
77
+ return Mage::getStoreConfig($path, $store);
78
+ }
79
+
80
+ /**
81
+ * Check if the location selector is enabled for this carrier profile.
82
+ *
83
+ * @param mixed $store
84
+ * @return bool
85
+ */
86
+ public function isLocationSelectEnabled($store = null)
87
+ {
88
+ $result = false;
89
+
90
+ if ($this->getCarrierLocationSelect()) {
91
+ if ($this->getConfigData('method') == Transsmart_Shipping_Model_Adminhtml_System_Config_Source_Method::PICKUP) {
92
+ if ($this->getConfigData('location_select', $store)) {
93
+ $result = true;
94
+ }
95
+ }
96
+ }
97
+
98
+ return $result;
99
+ }
100
+
101
+ /**
102
+ * Return a name identifying this carrier profile. Because there is no 'name' attribute, this name is constructed
103
+ * using config settings, or the carrier/servicelevel name if no name is configured.
104
+ *
105
+ * @return string
106
+ */
107
+ public function getName()
108
+ {
109
+ $id = $this->getData('carrierprofile_id');
110
+
111
+ $title = Mage::getStoreConfig('transsmart_carrier_profiles/carrierprofile_' . $id . '/title', 0);
112
+ if (empty($title)) {
113
+ $title = sprintf(
114
+ '(%s / %s / %s)',
115
+ $this->getData('carrier_name'),
116
+ $this->getData('servicelevel_time_name'),
117
+ $this->getData('servicelevel_other_name')
118
+ );
119
+ }
120
+
121
+ return $id . ' - ' . $title;
122
+ }
123
+ }
app/code/community/Transsmart/Shipping/Model/Client.php ADDED
@@ -0,0 +1,713 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Transsmart API client.
5
+ *
6
+ * @see http://www.odata.org/documentation/odata-version-2-0/uri-conventions/#FilterSystemQueryOption
7
+ *
8
+ * @category Transsmart
9
+ * @package Transsmart_Shipping
10
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
11
+ */
12
+ class Transsmart_Shipping_Model_Client
13
+ {
14
+ /**
15
+ * @var string
16
+ */
17
+ protected $_url;
18
+
19
+ /**
20
+ * @var string
21
+ */
22
+ protected $_username;
23
+
24
+ /**
25
+ * @var string
26
+ */
27
+ protected $_password;
28
+
29
+ /**
30
+ * Constructor.
31
+ *
32
+ * @param array $options
33
+ */
34
+ public function __construct($options)
35
+ {
36
+ $this->_url = isset($options['url'] ) ? $options['url'] : null;
37
+ $this->_username = isset($options['username']) ? $options['username'] : null;
38
+ $this->_password = isset($options['password']) ? $options['password'] : null;
39
+ }
40
+
41
+ /**
42
+ * Wrapper for curl_init and curl_exec, which also performs error checking and logging. Returns the response body.
43
+ *
44
+ * @param string $method API method (e.g.: "/Api/MethodName")
45
+ * @param string|null $requestBody This is usually a JSON encoded string
46
+ * @return string This is usually a JSON encoded string
47
+ * @throws Mage_Core_Exception
48
+ */
49
+ protected function _curlExec($method, $requestBody = null)
50
+ {
51
+ $curlOptions = array(
52
+ // SSL credentials
53
+ CURLOPT_CAINFO => dirname(dirname(__FILE__)) . DS . 'ssl' . DS . 'CARoot.crt',
54
+ CURLOPT_SSL_VERIFYPEER => true,
55
+ CURLOPT_SSL_VERIFYHOST => 2,
56
+ // HTTP authentication
57
+ CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
58
+ CURLOPT_USERPWD => $this->_username . ':' . $this->_password,
59
+ // HTTP request
60
+ CURLOPT_URL => $this->_url . $method,
61
+ CURLOPT_HTTPHEADER => array(
62
+ 'User-Agent: ' . sprintf(
63
+ 'Magento/%s Transsmart_Shipping/%s',
64
+ Mage::getVersion(),
65
+ (string)Mage::getConfig()->getNode('modules/Transsmart_Shipping/version')
66
+ ),
67
+ 'Accept: application/json',
68
+ ),
69
+ // connection settings
70
+ CURLINFO_HEADER_OUT => true,
71
+ CURLOPT_RETURNTRANSFER => true,
72
+ CURLOPT_CONNECTTIMEOUT => 5,
73
+ CURLOPT_TIMEOUT => 10,
74
+ );
75
+
76
+ if (!is_null($requestBody)) {
77
+ $curlOptions[CURLOPT_HTTPHEADER][] = 'Content-Type: application/json';
78
+ $curlOptions[CURLOPT_POST] = true;
79
+ $curlOptions[CURLOPT_POSTFIELDS] = $requestBody;
80
+ }
81
+
82
+ // initialize cURL
83
+ $ch = curl_init();
84
+ curl_setopt_array($ch, $curlOptions);
85
+
86
+ // execute the request
87
+ $time = microtime(true);
88
+ $responseBody = curl_exec($ch);
89
+ $time = microtime(true) - $time;
90
+
91
+ // write request details and response to log
92
+ Mage::log(sprintf(
93
+ "REQUEST: %s\nREQUEST BODY: %s\nDURATION: %0.4f sec\nRESPONSE CODE: %s\nRESPONSE BODY: %s",
94
+ rtrim(curl_getinfo($ch, CURLINFO_HEADER_OUT)),
95
+ $requestBody,
96
+ $time,
97
+ curl_getinfo($ch, CURLINFO_HTTP_CODE),
98
+ $responseBody
99
+ ), Zend_Log::DEBUG, 'transsmart_shipping.log');
100
+
101
+ // collect details and close cURL resource
102
+ $curlError = curl_error($ch);
103
+ $httpResponseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
104
+ curl_close($ch);
105
+
106
+ // check for cURL failure
107
+ if ($responseBody === false) {
108
+ Mage::throwException('Transsmart API connection failure: ' . $curlError);
109
+ }
110
+
111
+ // check for unexpected HTTP response code
112
+ if ($httpResponseCode < 200 || $httpResponseCode >= 300) {
113
+ // try to extract JSON encoded message from response body
114
+ $message = false;
115
+ if ($responseBody !== false) {
116
+ $message = str_replace(array("\r", "\n"), ' ', strip_tags($responseBody));
117
+ try {
118
+ $response = Zend_Json_Decoder::decode($responseBody);
119
+ if (is_string($response)) {
120
+ $message = $response;
121
+ }
122
+ elseif (is_array($response) && isset($response['Message'])) {
123
+ $message = $response['Message'];
124
+ }
125
+ }
126
+ catch (Zend_Json_Exception $exception) {
127
+ Mage::logException($exception);
128
+ }
129
+ }
130
+
131
+ if ($message) {
132
+ Mage::throwException('Transsmart API error: ' . $message);
133
+ }
134
+ else {
135
+ Mage::throwException('Transsmart API returned unexpected HTTP response code: ' . $httpResponseCode);
136
+ }
137
+ }
138
+
139
+ return $responseBody;
140
+ }
141
+
142
+ /**
143
+ * Get configured carriers.
144
+ *
145
+ * @param string $filter OData filter argument
146
+ * @return array
147
+ * @throws Zend_Json_Exception
148
+ */
149
+ public function getCarrier($filter = null)
150
+ {
151
+ $query = '';
152
+ if (!is_null($filter)) {
153
+ $query = '?' . http_build_query(array('$filter' => $filter));
154
+ }
155
+
156
+ $responseBody = $this->_curlExec('/Api/Carrier' . $query);
157
+
158
+ $response = Zend_Json_Decoder::decode($responseBody);
159
+
160
+ return $response;
161
+ }
162
+
163
+ /**
164
+ * Get configured time service levels.
165
+ *
166
+ * @param string $filter OData filter argument
167
+ * @return array
168
+ * @throws Zend_Json_Exception
169
+ */
170
+ public function getServiceLevelTime($filter = null)
171
+ {
172
+ $query = '';
173
+ if (!is_null($filter)) {
174
+ $query = '?' . http_build_query(array('$filter' => $filter));
175
+ }
176
+
177
+ $responseBody = $this->_curlExec('/Api/ServiceLevelTime' . $query);
178
+
179
+ $response = Zend_Json_Decoder::decode($responseBody);
180
+
181
+ return $response;
182
+ }
183
+
184
+ /**
185
+ * Get configured other service levels.
186
+ *
187
+ * @param string $filter OData filter argument
188
+ * @return array
189
+ * @throws Zend_Json_Exception
190
+ */
191
+ public function getServiceLevelOther($filter = null)
192
+ {
193
+ $query = '';
194
+ if (!is_null($filter)) {
195
+ $query = '?' . http_build_query(array('$filter' => $filter));
196
+ }
197
+
198
+ $responseBody = $this->_curlExec('/Api/ServiceLevelOther' . $query);
199
+
200
+ $response = Zend_Json_Decoder::decode($responseBody);
201
+
202
+ return $response;
203
+ }
204
+
205
+ /**
206
+ * Get configured carrier profiles.
207
+ *
208
+ * @param string $filter OData filter argument
209
+ * @return array
210
+ * @throws Zend_Json_Exception
211
+ */
212
+ public function getCarrierProfile($filter = null)
213
+ {
214
+ $query = '';
215
+ if (!is_null($filter)) {
216
+ $query = '?' . http_build_query(array('$filter' => $filter));
217
+ }
218
+
219
+ $responseBody = $this->_curlExec('/Api/CarrierProfile' . $query);
220
+
221
+ $response = Zend_Json_Decoder::decode($responseBody);
222
+
223
+ return $response;
224
+ }
225
+
226
+ /**
227
+ * Get configured shipment locations.
228
+ *
229
+ * @param string $filter OData filter argument
230
+ * @return array
231
+ * @throws Zend_Json_Exception
232
+ */
233
+ public function getShipmentLocation($filter = null)
234
+ {
235
+ $query = '';
236
+ if (!is_null($filter)) {
237
+ $query = '?' . http_build_query(array('$filter' => $filter));
238
+ }
239
+
240
+ $responseBody = $this->_curlExec('/Api/ShipmentLocation' . $query);
241
+
242
+ $response = Zend_Json_Decoder::decode($responseBody);
243
+
244
+ return $response;
245
+ }
246
+
247
+ /**
248
+ * Get configured email types.
249
+ *
250
+ * @param string $filter OData filter argument
251
+ * @return array
252
+ * @throws Zend_Json_Exception
253
+ */
254
+ public function getEmailType($filter = null)
255
+ {
256
+ $query = '';
257
+ if (!is_null($filter)) {
258
+ $query = '?' . http_build_query(array('$filter' => $filter));
259
+ }
260
+
261
+ $responseBody = $this->_curlExec('/Api/EmailType' . $query);
262
+
263
+ $response = Zend_Json_Decoder::decode($responseBody);
264
+
265
+ return $response;
266
+ }
267
+
268
+ /**
269
+ * Get configured incoterms.
270
+ *
271
+ * @param string $filter OData filter argument
272
+ * @return array
273
+ * @throws Zend_Json_Exception
274
+ */
275
+ public function getIncoterm($filter = null)
276
+ {
277
+ $query = '';
278
+ if (!is_null($filter)) {
279
+ $query = '?' . http_build_query(array('$filter' => $filter));
280
+ }
281
+
282
+ $responseBody = $this->_curlExec('/Api/Incoterm' . $query);
283
+
284
+ $response = Zend_Json_Decoder::decode($responseBody);
285
+
286
+ return $response;
287
+ }
288
+
289
+ /**
290
+ * Get configured cost centers.
291
+ *
292
+ * @param string $filter OData filter argument
293
+ * @return array
294
+ * @throws Zend_Json_Exception
295
+ */
296
+ public function getCostcenter($filter = null)
297
+ {
298
+ $query = '';
299
+ if (!is_null($filter)) {
300
+ $query = '?' . http_build_query(array('$filter' => $filter));
301
+ }
302
+
303
+ $responseBody = $this->_curlExec('/Api/Costcenter' . $query);
304
+
305
+ $response = Zend_Json_Decoder::decode($responseBody);
306
+
307
+ return $response;
308
+ }
309
+
310
+ /**
311
+ * Get configured package types.
312
+ *
313
+ * @param string $filter OData filter argument
314
+ * @return array
315
+ * @throws Zend_Json_Exception
316
+ */
317
+ public function getPackage($filter = null)
318
+ {
319
+ $query = '';
320
+ if (!is_null($filter)) {
321
+ $query = '?' . http_build_query(array('$filter' => $filter));
322
+ }
323
+
324
+ $responseBody = $this->_curlExec('/Api/Package' . $query);
325
+
326
+ $response = Zend_Json_Decoder::decode($responseBody);
327
+
328
+ return $response;
329
+ }
330
+
331
+ /**
332
+ * @param string $zipcode
333
+ * @param string $country
334
+ * @param string $carrier
335
+ * @param string $city
336
+ * @param string $street
337
+ * @param string $housenr
338
+ * @return array
339
+ * @throws Zend_Json_Exception
340
+ */
341
+ public function getLocationSelect($zipcode, $country, $carrier, $city, $street, $housenr)
342
+ {
343
+ $query = '?' . http_build_query(array(
344
+ 'Zipcode' => $zipcode,
345
+ 'Country' => $country,
346
+ 'Carrier' => $carrier,
347
+ 'City' => $city,
348
+ 'Street' => $street,
349
+ 'HouseNr' => $housenr
350
+ ));
351
+
352
+ $responseBody = $this->_curlExec('/Api/LocationSelect' . $query);
353
+
354
+ $response = Zend_Json_Decoder::decode($responseBody);
355
+
356
+ return $response;
357
+ }
358
+
359
+ /**
360
+ * Get documents.
361
+ *
362
+ * @param string $id Document id (optional)
363
+ * @return array
364
+ * @throws Zend_Json_Exception
365
+ */
366
+ public function getDocument($id = null)
367
+ {
368
+ $query = '';
369
+ if (!is_null($id)) {
370
+ $query = '/' . (string)$id;
371
+ }
372
+
373
+ $responseBody = $this->_curlExec('/Api/Document' . $query);
374
+
375
+ $response = Zend_Json_Decoder::decode($responseBody);
376
+
377
+ return $response;
378
+ }
379
+
380
+ /**
381
+ * Get shipment status info.
382
+ *
383
+ * @param array $queryDefinition
384
+ * @return array
385
+ * @throws Zend_Json_Exception
386
+ */
387
+ public function getStatus($queryDefinition)
388
+ {
389
+ $responseBody = $this->_curlExec('/Api/Status', Zend_Json_Encoder::encode($queryDefinition));
390
+
391
+ $response = Zend_Json_Decoder::decode($responseBody);
392
+
393
+ return $response;
394
+ }
395
+
396
+ /**
397
+ * Create a new document.
398
+ *
399
+ * @param string|array $referenceOrDocument Referentie van het adres of het complete document als array
400
+ * @param int|null $carrierId Carrier van het document
401
+ * @param int|null $serviceLevelTimeId Tijd servicelevel van het document
402
+ * @param int|null $serviceLevelOtherId Overig servicelevel van het document
403
+ * @param int|null $shipmentLocationId Verzendlocatie van het document
404
+ * @param int|null $mailTypeId Mailtype van het document
405
+ * @param int|null $incotermId Incoterm van het document
406
+ * @param string|null $serviceType Servicetype van het document
407
+ * @param int|null $costCenterId Kostenplaats van het document
408
+ * @param float|null $spotPrice Spotprijs van het document
409
+ * @param float|null $codCosts Rembourskosten van het document
410
+ * @param float|null $loadMeter Laadmeter van het document
411
+ * @param string|null $preferredPickupDateFrom Voorkeursophaaldatum (van) van het document '2015-10-22T08:00:00'
412
+ * @param string|null $preferredPickupDateTo Voorkeursophaaldatum (tot) van het document 'yyyy-mm-ddThh:mm:ss'
413
+ * @param string|null $preferredDeliveryDateFrom Afleverdatum (van) van het document 'yyyy-mm-ddThh:mm:ss'
414
+ * @param string|null $preferredDeliveryDateTo Afleverdatum (tot) van het document 'yyyy-mm-ddThh:mm:ss'
415
+ * @param string|null $refInvoice Factuursreferentie van het document
416
+ * @param string|null $refCustomerOrder Klantorderreferentie van het document
417
+ * @param string|null $refOrder Orderreferentie van het document
418
+ * @param string|null $refDeliveryNote Pakbonreferentie van het document
419
+ * @param string|null $refDeliveryId Leveringsnummerreferentie van het document
420
+ * @param string|null $refOther Overige referentie van het document
421
+ * @param string|null $refServicePoint Servicepoint referentie van het document
422
+ * @param string|null $refProject Projectreferentie van het document
423
+ * @param string|null $refYourReference Eigen referentie van het document
424
+ * @param string|null $refEngineer Engineersreferentie van het document
425
+ * @param string|null $addressName Naam van het afleveradres
426
+ * @param string|null $addressStreet Straat van het afleveradres
427
+ * @param string|null $addressStreetNo Huisnummer van het afleveradres
428
+ * @param string|null $addressZipcode Postcode van het afleveradres
429
+ * @param string|null $addressCity Plaats van het afleveradres
430
+ * @param string|null $addressState Staat van het afleveradres
431
+ * @param string|null $addressCountry Land van het afleveradres
432
+ * @param string|null $addressContact Contactpersoon van het afleveradres
433
+ * @param string|null $addressPhone Telefoonnummer van het afleveradres
434
+ * @param string|null $addressFax Faxnummer van het afleveradres
435
+ * @param string|null $addressEmail Emailadres van het afleveradres
436
+ * @param string|null $addressAccountNo Accountnummer van het afleveradres
437
+ * @param string|null $addressCustomerNo Klantnummer van het afleveradres
438
+ * @param string|null $addressVatNumber BTW Nummer van het afleveradres
439
+ * @param string|null $addressNamePickup Naam van het ophaaladres
440
+ * @param string|null $addressStreetPickup Straat van het ophaaladres
441
+ * @param string|null $addressStreetNoPickup Huisnummer van het ophaaladres
442
+ * @param string|null $addressZipcodePickup Postcode van het ophaaladres
443
+ * @param string|null $addressCityPickup Plaats van het ophaaladres
444
+ * @param string|null $addressStatePickup Staat van het ophaaladres
445
+ * @param string|null $addressCountryPickup Land van het ophaaladres
446
+ * @param string|null $addressContactPickup Contactpersoon van het ophaaladres
447
+ * @param string|null $addressPhonePickup Telefoonnummer van het ophaaladres
448
+ * @param string|null $addressFaxPickup Faxnummer van het ophaaladres
449
+ * @param string|null $addressEmailPickup Emailadres van het ophaaladres
450
+ * @param string|null $addressAccountNoPickup Accountnummer van het ophaaladres
451
+ * @param string|null $addressCustomerNoPickup Klantnummer van het ophaaladres
452
+ * @param string|null $addressVatNumberPickup BTN Nummer van het ophaaladres
453
+ * @param string|null $addressNameInvoice Naam van het factuuradres
454
+ * @param string|null $addressStreetInvoice Staat van het factuuradres
455
+ * @param string|null $addressStreetNoInvoice Huisnummer van het factuuradres
456
+ * @param string|null $addressZipcodeInvoice Postcode van het factuuradres
457
+ * @param string|null $addressCityInvoice Plaats van het factuuradres
458
+ * @param string|null $addressStateInvoice Staat van het factuuradres
459
+ * @param string|null $addressCountryInvoice Land van het factuuradres
460
+ * @param string|null $addressContactInvoice Contactpersoon van het factuuradres
461
+ * @param string|null $addressPhoneInvoice Telefoonnummer van het factuuradres
462
+ * @param string|null $addressFaxInvoice Faxnummer van het factuuradres
463
+ * @param string|null $addressEmailInvoice Emailadres van het factuuradres
464
+ * @param string|null $addressAccountNoInvoice Accountnummer van het factuuradres
465
+ * @param string|null $addressCustomerNoInvoice Klantnummer van het factuuradres
466
+ * @param string|null $addressVatNumberInvoice BTW Nummer van het factuuradres
467
+ * @return mixed
468
+ * @throws Zend_Json_Exception
469
+ */
470
+ public function createDocument(
471
+ $referenceOrDocument,
472
+ $carrierId = null,
473
+ $serviceLevelTimeId = null,
474
+ $serviceLevelOtherId = null,
475
+ $shipmentLocationId = null,
476
+ $mailTypeId = null,
477
+ $incotermId = null,
478
+ $serviceType = null,
479
+ $costCenterId = null,
480
+ $spotPrice = null,
481
+ $codCosts = null,
482
+ $loadMeter = null,
483
+ $preferredPickupDateFrom = null,
484
+ $preferredPickupDateTo = null,
485
+ $preferredDeliveryDateFrom = null,
486
+ $preferredDeliveryDateTo = null,
487
+ $refInvoice = null,
488
+ $refCustomerOrder = null,
489
+ $refOrder = null,
490
+ $refDeliveryNote = null,
491
+ $refDeliveryId = null,
492
+ $refOther = null,
493
+ $refServicePoint = null,
494
+ $refProject = null,
495
+ $refYourReference = null,
496
+ $refEngineer = null,
497
+ $addressName = null,
498
+ $addressStreet = null,
499
+ $addressStreetNo = null,
500
+ $addressZipcode = null,
501
+ $addressCity = null,
502
+ $addressState = null,
503
+ $addressCountry = null,
504
+ $addressContact = null,
505
+ $addressPhone = null,
506
+ $addressFax = null,
507
+ $addressEmail = null,
508
+ $addressAccountNo = null,
509
+ $addressCustomerNo = null,
510
+ $addressVatNumber = null,
511
+ $addressNamePickup = null,
512
+ $addressStreetPickup = null,
513
+ $addressStreetNoPickup = null,
514
+ $addressZipcodePickup = null,
515
+ $addressCityPickup = null,
516
+ $addressStatePickup = null,
517
+ $addressCountryPickup = null,
518
+ $addressContactPickup = null,
519
+ $addressPhonePickup = null,
520
+ $addressFaxPickup = null,
521
+ $addressEmailPickup = null,
522
+ $addressAccountNoPickup = null,
523
+ $addressCustomerNoPickup = null,
524
+ $addressVatNumberPickup = null,
525
+ $addressNameInvoice = null,
526
+ $addressStreetInvoice = null,
527
+ $addressStreetNoInvoice = null,
528
+ $addressZipcodeInvoice = null,
529
+ $addressCityInvoice = null,
530
+ $addressStateInvoice = null,
531
+ $addressCountryInvoice = null,
532
+ $addressContactInvoice = null,
533
+ $addressPhoneInvoice = null,
534
+ $addressFaxInvoice = null,
535
+ $addressEmailInvoice = null,
536
+ $addressAccountNoInvoice = null,
537
+ $addressCustomerNoInvoice = null,
538
+ $addressVatNumberInvoice = null
539
+ )
540
+ {
541
+ if (is_array($referenceOrDocument)) {
542
+ $document = $referenceOrDocument;
543
+ }
544
+ else {
545
+ $document = array(
546
+ 'Reference' => $referenceOrDocument,
547
+ 'CarrierId' => $carrierId,
548
+ 'ServiceLevelTimeId' => $serviceLevelTimeId,
549
+ 'ServiceLevelOtherId' => $serviceLevelOtherId,
550
+ 'ShipmentLocationId' => $shipmentLocationId,
551
+ 'MailTypeId' => $mailTypeId,
552
+ 'IncotermId' => $incotermId,
553
+ 'ServiceType' => $serviceType,
554
+ 'CostCenterId' => $costCenterId,
555
+ 'SpotPrice' => $spotPrice,
556
+ 'CodCosts' => $codCosts,
557
+ 'LoadMeter' => $loadMeter,
558
+ 'PreferredPickupDateFrom' => $preferredPickupDateFrom,
559
+ 'PreferredPickupDateTo' => $preferredPickupDateTo,
560
+ 'PreferredDeliveryDateFrom' => $preferredDeliveryDateFrom,
561
+ 'PreferredDeliveryDateTo' => $preferredDeliveryDateTo,
562
+ 'RefInvoice' => $refInvoice,
563
+ 'RefCustomerOrder' => $refCustomerOrder,
564
+ 'RefOrder' => $refOrder,
565
+ 'RefDeliveryNote' => $refDeliveryNote,
566
+ 'RefDeliveryId' => $refDeliveryId,
567
+ 'RefOther' => $refOther,
568
+ 'RefServicePoint' => $refServicePoint,
569
+ 'RefProject' => $refProject,
570
+ 'RefYourReference' => $refYourReference,
571
+ 'RefEngineer' => $refEngineer,
572
+ 'AddressName' => $addressName,
573
+ 'AddressStreet' => $addressStreet,
574
+ 'AddressStreetNo' => $addressStreetNo,
575
+ 'AddressZipcode' => $addressZipcode,
576
+ 'AddressCity' => $addressCity,
577
+ 'AddressState' => $addressState,
578
+ 'AddressCountry' => $addressCountry,
579
+ 'AddressContact' => $addressContact,
580
+ 'AddressPhone' => $addressPhone,
581
+ 'AddressFax' => $addressFax,
582
+ 'AddressEmail' => $addressEmail,
583
+ 'AddressAccountNo' => $addressAccountNo,
584
+ 'AddressCustomerNo' => $addressCustomerNo,
585
+ 'AddressVatNumber' => $addressVatNumber,
586
+ 'AddressNamePickup' => $addressNamePickup,
587
+ 'AddressStreetPickup' => $addressStreetPickup,
588
+ 'AddressStreetNoPickup' => $addressStreetNoPickup,
589
+ 'AddressZipcodePickup' => $addressZipcodePickup,
590
+ 'AddressCityPickup' => $addressCityPickup,
591
+ 'AddressStatePickup' => $addressStatePickup,
592
+ 'AddressCountryPickup' => $addressCountryPickup,
593
+ 'AddressContactPickup' => $addressContactPickup,
594
+ 'AddressPhonePickup' => $addressPhonePickup,
595
+ 'AddressFaxPickup' => $addressFaxPickup,
596
+ 'AddressEmailPickup' => $addressEmailPickup,
597
+ 'AddressAccountNoPickup' => $addressAccountNoPickup,
598
+ 'AddressCustomerNoPickup' => $addressCustomerNoPickup,
599
+ 'AddressVatNumberPickup' => $addressVatNumberPickup,
600
+ 'AddressNameInvoice' => $addressNameInvoice,
601
+ 'AddressStreetInvoice' => $addressStreetInvoice,
602
+ 'AddressStreetNoInvoice' => $addressStreetNoInvoice,
603
+ 'AddressZipcodeInvoice' => $addressZipcodeInvoice,
604
+ 'AddressCityInvoice' => $addressCityInvoice,
605
+ 'AddressStateInvoice' => $addressStateInvoice,
606
+ 'AddressCountryInvoice' => $addressCountryInvoice,
607
+ 'AddressContactInvoice' => $addressContactInvoice,
608
+ 'AddressPhoneInvoice' => $addressPhoneInvoice,
609
+ 'AddressFaxInvoice' => $addressFaxInvoice,
610
+ 'AddressEmailInvoice' => $addressEmailInvoice,
611
+ 'AddressAccountNoInvoice' => $addressAccountNoInvoice,
612
+ 'AddressCustomerNoInvoice' => $addressCustomerNoInvoice,
613
+ 'AddressVatNumberInvoice' => $addressVatNumberInvoice,
614
+ );
615
+ }
616
+
617
+ $document = array_filter($document);
618
+
619
+ $responseBody = $this->_curlExec('/Api/Document', Zend_Json_Encoder::encode($document));
620
+
621
+ $response = Zend_Json_Decoder::decode($responseBody);
622
+
623
+ return $response;
624
+ }
625
+
626
+ /**
627
+ * @param int $id Id of the document
628
+ * @throws Zend_Json_Exception
629
+ * @return mixed
630
+ */
631
+ public function doBooking($id)
632
+ {
633
+ $query = '?' . http_build_query(array('id' => $id));
634
+
635
+ $responseBody = $this->_curlExec('/Api/DoBooking' . $query);
636
+
637
+ $response = Zend_Json_Decoder::decode($responseBody);
638
+
639
+ return $response;
640
+ }
641
+
642
+ /**
643
+ * @param int $id
644
+ * @param string $username
645
+ * @param int|null $pdf
646
+ * @param int|null $downloadonly
647
+ * @param string|null $qzhost
648
+ * @param string|null $selectedprinter
649
+ * @return mixed
650
+ * @throws Zend_Json_Exception
651
+ */
652
+ public function doLabel($id, $username, $pdf = null, $downloadonly = null, $qzhost = null, $selectedprinter = null)
653
+ {
654
+ $parameters = array(
655
+ 'id' => $id,
656
+ 'username' => $username,
657
+ );
658
+ if (!is_null($pdf)) {
659
+ $parameters['pdf'] = $pdf;
660
+ }
661
+ if (!is_null($downloadonly)) {
662
+ $parameters['downloadonly'] = $downloadonly;
663
+ }
664
+ if (!is_null($qzhost)) {
665
+ $parameters['qzhost'] = $qzhost;
666
+ }
667
+ if (!is_null($selectedprinter)) {
668
+ $parameters['selectedprinter'] = $selectedprinter;
669
+ }
670
+
671
+ $query = '?' . http_build_query($parameters);
672
+
673
+ $responseBody = $this->_curlExec('/Api/DoLabel' . $query);
674
+
675
+ $response = Zend_Json_Decoder::decode($responseBody);
676
+
677
+ return $response;
678
+ }
679
+
680
+ /**
681
+ * @param int $id
682
+ * @param string $username
683
+ * @param int|null $downloadonly
684
+ * @param string|null $qzhost
685
+ * @param string|null $selectedprinter
686
+ * @return mixed
687
+ * @throws Zend_Json_Exception
688
+ */
689
+ public function doBookAndPrint($id, $username, $downloadonly = null, $qzhost = null, $selectedprinter = null)
690
+ {
691
+ $parameters = array(
692
+ 'id' => $id,
693
+ 'username' => $username,
694
+ );
695
+ if (!is_null($downloadonly)) {
696
+ $parameters['downloadonly'] = $downloadonly;
697
+ }
698
+ if (!is_null($qzhost)) {
699
+ $parameters['qzhost'] = $qzhost;
700
+ }
701
+ if (!is_null($selectedprinter)) {
702
+ $parameters['selectedprinter'] = $selectedprinter;
703
+ }
704
+
705
+ $query = '?' . http_build_query($parameters);
706
+
707
+ $responseBody = $this->_curlExec('/Api/DoBookAndPrint' . $query);
708
+
709
+ $response = Zend_Json_Decoder::decode($responseBody);
710
+
711
+ return $response;
712
+ }
713
+ }
app/code/community/Transsmart/Shipping/Model/Costcenter.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Transsmart Cost Center Model
5
+ *
6
+ * @method Transsmart_Shipping_Model_Resource_Costcenter _getResource()
7
+ * @method Transsmart_Shipping_Model_Resource_Costcenter getResource()
8
+ * @method int getCostcenterId()
9
+ * @method Transsmart_Shipping_Model_Costcenter setCostcenterId(int $value)
10
+ * @method string getCode()
11
+ * @method Transsmart_Shipping_Model_Costcenter setCode(string $value)
12
+ * @method string getName()
13
+ * @method Transsmart_Shipping_Model_Costcenter setName(string $value)
14
+ * @method bool getIsDefault()
15
+ * @method Transsmart_Shipping_Model_Costcenter setIsDefault(bool $value)
16
+ *
17
+ * @category Transsmart
18
+ * @package Transsmart_Shipping
19
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
20
+ */
21
+ class Transsmart_Shipping_Model_Costcenter extends Transsmart_Shipping_Model_Abstract
22
+ {
23
+ /**
24
+ * A list of API keys to be mapped to database columns.
25
+ * @var array
26
+ */
27
+ protected $apiKeysMapping = array(
28
+ 'Id' => 'costcenter_id',
29
+ 'Code' => 'code',
30
+ 'Name' => 'name',
31
+ 'IsDefault' => 'is_default'
32
+ );
33
+
34
+ /**
35
+ * Object initialization
36
+ */
37
+ protected function _construct()
38
+ {
39
+ $this->_init('transsmart_shipping/costcenter');
40
+ }
41
+ }
app/code/community/Transsmart/Shipping/Model/Emailtype.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Transsmart Email Type Model
5
+ *
6
+ * @method Transsmart_Shipping_Model_Resource_Emailtype _getResource()
7
+ * @method Transsmart_Shipping_Model_Resource_Emailtype getResource()
8
+ * @method int getEmailtypeId()
9
+ * @method Transsmart_Shipping_Model_Emailtype setEmailtypeId(int $value)
10
+ * @method string getCode()
11
+ * @method Transsmart_Shipping_Model_Emailtype setCode(string $value)
12
+ * @method string getName()
13
+ * @method Transsmart_Shipping_Model_Emailtype setName(string $value)
14
+ * @method bool getIsDefault()
15
+ * @method Transsmart_Shipping_Model_Emailtype setIsDefault(bool $value)
16
+ *
17
+ * @category Transsmart
18
+ * @package Transsmart_Shipping
19
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
20
+ */
21
+ class Transsmart_Shipping_Model_Emailtype extends Transsmart_Shipping_Model_Abstract
22
+ {
23
+ /**
24
+ * A list of API keys to be mapped to database columns.
25
+ * @var array
26
+ */
27
+ protected $apiKeysMapping = array(
28
+ 'Id' => 'emailtype_id',
29
+ 'Code' => 'code',
30
+ 'Name' => 'name',
31
+ 'IsDefault' => 'is_default'
32
+ );
33
+
34
+ /**
35
+ * Object initialization
36
+ */
37
+ protected function _construct()
38
+ {
39
+ $this->_init('transsmart_shipping/emailtype');
40
+ }
41
+ }
app/code/community/Transsmart/Shipping/Model/Incoterm.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Transsmart Incoterm Model
5
+ *
6
+ * @method Transsmart_Shipping_Model_Resource_Incoterm _getResource()
7
+ * @method Transsmart_Shipping_Model_Resource_Incoterm getResource()
8
+ * @method int getIncotermId()
9
+ * @method Transsmart_Shipping_Model_Incoterm setIncotermId(int $value)
10
+ * @method string getCode()
11
+ * @method Transsmart_Shipping_Model_Incoterm setCode(string $value)
12
+ * @method string getName()
13
+ * @method Transsmart_Shipping_Model_Incoterm setName(string $value)
14
+ * @method bool getIsDefault()
15
+ * @method Transsmart_Shipping_Model_Incoterm setIsDefault(bool $value)
16
+ *
17
+ * @category Transsmart
18
+ * @package Transsmart_Shipping
19
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
20
+ */
21
+ class Transsmart_Shipping_Model_Incoterm extends Transsmart_Shipping_Model_Abstract
22
+ {
23
+ /**
24
+ * A list of API keys to be mapped to database columns.
25
+ * @var array
26
+ */
27
+ protected $apiKeysMapping = array(
28
+ 'Id' => 'incoterm_id',
29
+ 'Code' => 'code',
30
+ 'Name' => 'name',
31
+ 'IsDefault' => 'is_default'
32
+ );
33
+
34
+ /**
35
+ * Object initialization
36
+ */
37
+ protected function _construct()
38
+ {
39
+ $this->_init('transsmart_shipping/incoterm');
40
+ }
41
+ }
app/code/community/Transsmart/Shipping/Model/Observer.php ADDED
@@ -0,0 +1,354 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Observer
9
+ {
10
+ /**
11
+ * Observer for the 'sales_order_shipment_save_before' event. Set default shipmentlocation, emailtype, incoterm,
12
+ * costcenter and packages for new shipments.
13
+ *
14
+ * Note: There's also an admin-only observer for this event, which is called after this one.
15
+ * @see Transsmart_Shipping_Model_Adminhtml_Observer::salesOrderShipmentSaveBefore
16
+ *
17
+ * @see Mage_Sales_Model_Order_Shipment::_beforeSave
18
+ * @param Varien_Event_Observer $observer
19
+ */
20
+ public function salesOrderShipmentSaveBefore($observer)
21
+ {
22
+ /** @var Mage_Sales_Model_Order_Shipment $shipment */
23
+ $shipment = $observer->getShipment();
24
+
25
+ // is it a new shipment?
26
+ if (!$shipment->isObjectNew()) {
27
+ return;
28
+ }
29
+
30
+ // does it use one of our shipping methods?
31
+ $shippingMethod = $shipment->getOrder()->getShippingMethod();
32
+ if (!Mage::helper('transsmart_shipping')->isTranssmartShippingMethod($shippingMethod)) {
33
+ return;
34
+ }
35
+
36
+ /** @var Transsmart_Shipping_Helper_Shipment $helper */
37
+ $helper = Mage::helper('transsmart_shipping/shipment');
38
+
39
+ // set defaults Transsmart shipment properties if not set
40
+ if (!$shipment->hasTranssmartCarrierprofileId()) {
41
+ $shipment->setTranssmartCarrierprofileId($helper->getDefaultCarrierprofileId($shipment));
42
+ }
43
+ if (!$shipment->hasTranssmartShipmentlocationId()) {
44
+ $shipment->setTranssmartShipmentlocationId($helper->getDefaultShipmentlocationId($shipment->getStore()));
45
+ }
46
+ if (!$shipment->hasTranssmartEmailtypeId()) {
47
+ $shipment->setTranssmartEmailtypeId($helper->getDefaultEmailtypeId($shipment->getStore()));
48
+ }
49
+ if (!$shipment->hasTranssmartIncotermId()) {
50
+ $shipment->setTranssmartIncotermId($helper->getDefaultIncotermId($shipment->getStore()));
51
+ }
52
+ if (!$shipment->hasTranssmartCostcenterId()) {
53
+ $shipment->setTranssmartCostcenterId($helper->getDefaultCostcenterId($shipment->getStore()));
54
+ }
55
+ if (!$shipment->hasTranssmartPackages()) {
56
+ $packageType = Mage::getResourceSingleton('transsmart_shipping/packagetype_collection')
57
+ ->getItemById($helper->getDefaultPackagetypeId($shipment->getStore()));
58
+ $packages = array();
59
+ if ($packageType) {
60
+ $packages[] = array(
61
+ 'PackagingType' => $packageType->getCode(),
62
+ 'Description' => $packageType->getName(),
63
+ 'Quantity' => 1,
64
+ 'Length' => (float)$packageType->getLength(),
65
+ 'Width' => (float)$packageType->getWidth(),
66
+ 'Height' => (float)$packageType->getHeight(),
67
+ 'Weight' => (float)$packageType->getWeight(),
68
+ );
69
+ }
70
+ $shipment->setTranssmartPackages(serialize($packages));
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Observer for the 'sales_order_shipment_resource_save_attribute_after' event. This will update the associated
76
+ * record in the order grid table when the transsmart_status field is updated for a shipment. Also dispatches a
77
+ * new event if the status changed to LABL, which means the label was printed.
78
+ *
79
+ * @see Mage_Sales_Model_Resource_Order_Shipment::_afterSaveAttribute
80
+ * @param Varien_Event_Observer $observer
81
+ */
82
+ public function salesOrderShipmentResourceSaveAttributeAfter($observer)
83
+ {
84
+ // only do something when the transsmart_status field was saved
85
+ if (!in_array('transsmart_status', $observer->getAttribute())) {
86
+ return;
87
+ }
88
+
89
+ /** @var Mage_Sales_Model_Order_Shipment $shipment */
90
+ $shipment = $observer->getObject();
91
+
92
+ if ($shipment->hasDataChanges() && $shipment->getOrderId()) {
93
+ // update order grid table after status update
94
+ Mage::getResourceModel('sales/order')->updateOnRelatedRecordChanged(
95
+ 'entity_id',
96
+ $shipment->getOrderId()
97
+ );
98
+
99
+ // check if status changed to LABL
100
+ $oldStatus = $shipment->getOrigData('transsmart_status');
101
+ $newStatus = $shipment->getData('transsmart_status');
102
+ if ($oldStatus != $newStatus && $newStatus == 'LABL') {
103
+ Mage::dispatchEvent('transsmart_shipping_shipment_label_printed', array(
104
+ 'shipment' => $shipment
105
+ ));
106
+ }
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Method is triggered when saving the shipping method.
112
+ * We use this to store the store location data.
113
+ *
114
+ * @see Mage_Checkout_OnepageController::saveShippingMethodAction()
115
+ * @param Varien_Event_Observer $observer
116
+ */
117
+ public function checkoutControllerOnepageSaveShippingMethod($observer)
118
+ {
119
+ /** @var Mage_Core_Controller_Request_Http $request */
120
+ $request = $observer->getRequest();
121
+
122
+ /** @var Mage_Sales_Model_Quote $quote */
123
+ $quote = $observer->getQuote();
124
+
125
+ $shippingAddress = $quote->getShippingAddress();
126
+ $shippingMethod = $shippingAddress->getShippingMethod();
127
+
128
+ // remove the pickup addresses, if there are any
129
+ Mage::helper('transsmart_shipping/pickupaddress')->removePickupAddressFromQuote($quote);
130
+
131
+ // try to load the carrierprofile based on the shipping method
132
+ $carrierProfile = Mage::getModel('transsmart_shipping/carrierprofile')
133
+ ->loadByShippingMethodCode($shippingMethod);
134
+ if (!$carrierProfile->getId() || !$carrierProfile->isLocationSelectEnabled()) {
135
+ // not a Transsmart shipping method with enabled location selector
136
+ return;
137
+ }
138
+
139
+ if (!($pickupAddressData = $request->getPost('transsmart_pickup_address_data'))) {
140
+ // No location data provided
141
+ $errorMessage = Mage::helper('transsmart_shipping')->__('A pickup location has to be selected');
142
+ if ($request->isAjax()) {
143
+ Mage::app()->getFrontController()->getResponse()
144
+ ->setHeader('Content-Type', 'application/json', true)
145
+ ->setBody(Mage::helper('core')->jsonEncode(array('error' => -1, 'message' => $errorMessage)))
146
+ ->sendResponse();
147
+ exit;
148
+ }
149
+ return;
150
+ }
151
+
152
+ // base64 decode, convert Latin1 to UTF-8 and JSON decode
153
+ $pickupAddressData = Zend_Json_Decoder::decode(utf8_encode(base64_decode($pickupAddressData)));
154
+ // TODO: verify pickup address data
155
+ Mage::helper('transsmart_shipping/pickupaddress')
156
+ ->savePickupAddressIntoQuote($quote, $pickupAddressData);
157
+ }
158
+
159
+ /**
160
+ * Method is triggered when calling a controller action in GoMage LightCheckout, for example when saving the
161
+ * shipping method. We use this to store the store location data.
162
+ *
163
+ * @see GoMage_Checkout_OnepageController::saveAction
164
+ * @see GoMage_Checkout_OnepageController::ajaxAction
165
+ * @param Varien_Event_Observer $observer
166
+ */
167
+ public function controllerActionPredispatchGomageCheckout($observer)
168
+ {
169
+ /** @var GoMage_Checkout_OnepageController $controllerAction */
170
+ $controllerAction = $observer->getEvent()->getControllerAction();
171
+
172
+ // verify controller and action name
173
+ $request = $controllerAction->getRequest();
174
+ if ($request->getRequestedControllerName() != 'onepage') {
175
+ return;
176
+ }
177
+ if (!in_array($request->getRequestedActionName(), array('ajax', 'save'))) {
178
+ return;
179
+ }
180
+
181
+ // verify ajax action name
182
+ if ($request->getRequestedActionName() == 'ajax') {
183
+ if (!in_array($request->getParam('action'), array('get_totals'))) {
184
+ return;
185
+ }
186
+ }
187
+
188
+ $quote = $controllerAction->getOnepage()->getQuote();
189
+
190
+ $shippingMethod = $request->getPost('shipping_method', $quote->getShippingAddress()->getShippingMethod());
191
+
192
+ // remove the pickup addresses, if there are any
193
+ Mage::helper('transsmart_shipping/pickupaddress')->removePickupAddressFromQuote($quote);
194
+
195
+ // try to load the carrierprofile based on the shipping method
196
+ $carrierProfile = Mage::getModel('transsmart_shipping/carrierprofile')
197
+ ->loadByShippingMethodCode($shippingMethod);
198
+ if (!$carrierProfile->getId() || !$carrierProfile->isLocationSelectEnabled()) {
199
+ // not a Transsmart shipping method with enabled location selector
200
+ return;
201
+ }
202
+
203
+ if (!($pickupAddressData = $request->getPost('transsmart_pickup_address_data'))) {
204
+ // No location data provided
205
+ if ($request->isAjax() && $request->getRequestedActionName() == 'save') {
206
+ $errorMessage = Mage::helper('transsmart_shipping')->__('A pickup location has to be selected');
207
+ Mage::app()->getFrontController()->getResponse()
208
+ ->setHeader('Content-Type', 'application/json', true)
209
+ ->setBody(Mage::helper('core')->jsonEncode(array('error' => -1, 'message' => $errorMessage)))
210
+ ->sendResponse();
211
+ exit;
212
+ }
213
+ return;
214
+ }
215
+
216
+ // base64 decode, convert Latin1 to UTF-8 and JSON decode
217
+ $pickupAddressData = Zend_Json_Decoder::decode(utf8_encode(base64_decode($pickupAddressData)));
218
+ // TODO: verify pickup address data
219
+ Mage::helper('transsmart_shipping/pickupaddress')
220
+ ->savePickupAddressIntoQuote($quote, $pickupAddressData);
221
+ }
222
+
223
+ /**
224
+ * Method is triggered when converting the quote to the order.
225
+ *
226
+ * @see Mage_Sales_Model_Convert_Quote::toOrder()
227
+ * @param Varien_Event_Observer $observer
228
+ */
229
+ public function salesConvertQuoteToOrder($observer)
230
+ {
231
+ /** @var Mage_Sales_Model_Order $order */
232
+ $order = $observer->getOrder();
233
+
234
+ /** @var Mage_Sales_Model_Quote $quote */
235
+ $quote = $observer->getQuote();
236
+
237
+ $shippingMethod = $quote->getShippingAddress()->getShippingMethod();
238
+
239
+ // check whether this is a Transsmart shipping method
240
+ if (!Mage::helper('transsmart_shipping')->isTranssmartPickup($shippingMethod)) {
241
+ return;
242
+ }
243
+
244
+ /** @var Mage_Sales_Model_Quote_Address $pickupAddress */
245
+ if (!($pickupAddress = Mage::helper('transsmart_shipping/pickupaddress')->getPickupAddressFromQuote($quote))) {
246
+ // no pickup address
247
+ Mage::throwException(Mage::helper('transsmart_shipping')->__('A pickup location has to be selected'));
248
+ }
249
+
250
+ $orderAddress = Mage::getModel('sales/convert_quote')->addressToOrderAddress($pickupAddress);
251
+ $orderAddress->setParentId($order->getId());
252
+
253
+ $order->addAddress($orderAddress);
254
+ }
255
+
256
+ /**
257
+ * Method is triggered when submitting an order is placed. Make sure it has a pickup address if needed.
258
+ *
259
+ * @see Mage_Sales_Model_Service_Quote::submitOrder
260
+ * @param Varien_Event_Observer $observer
261
+ */
262
+ public function checkoutTypeOnepageSaveOrder($observer)
263
+ {
264
+ /** @var Mage_Sales_Model_Order $order */
265
+ $order = $observer->getOrder();
266
+
267
+ // check whether this is a Transsmart shipping method
268
+ if (!Mage::helper('transsmart_shipping')->isTranssmartPickup($order->getShippingMethod())) {
269
+ return;
270
+ }
271
+
272
+ /** @var Mage_Sales_Model_Quote_Address $pickupAddress */
273
+ if (!($pickupAddress = Mage::helper('transsmart_shipping/pickupaddress')->getPickupAddressFromOrder($order))) {
274
+ Mage::throwException(Mage::helper('transsmart_shipping')->__('A pickup location has to be selected'));
275
+ }
276
+ }
277
+
278
+ /**
279
+ * Method is triggered when converting an order to a quote. This currently only happens during reorder in admin.
280
+ *
281
+ * @see Mage_Adminhtml_Model_Sales_Order_Create::initFromOrder
282
+ * @param Varien_Event_Observer $observer
283
+ */
284
+ public function salesConvertOrderToQuote($observer)
285
+ {
286
+ /** @var Mage_Sales_Model_Order $order */
287
+ $order = $observer->getOrder();
288
+
289
+ /** @var Mage_Sales_Model_Quote $quote */
290
+ $quote = $observer->getQuote();
291
+
292
+ // check whether this is a Transsmart shipping method
293
+ if (!Mage::helper('transsmart_shipping')->isTranssmartPickup($order->getShippingMethod())) {
294
+ return;
295
+ }
296
+
297
+ $shippingAddress = $quote->getShippingAddress();
298
+ if ($shippingAddress) {
299
+ $shippingAddress->unsShippingMethod();
300
+ }
301
+ }
302
+
303
+ /**
304
+ * Triggered when a label is printed for a Transsmart shipment.
305
+ *
306
+ * @see Transsmart_Shipping_Model_Observer::salesOrderShipmentResourceSaveAttributeAfter
307
+ * @param Varien_Event_Observer $observer
308
+ * @throws Exception
309
+ */
310
+ public function transsmartShippingShipmentLabelPrinted($observer)
311
+ {
312
+ /** @var Mage_Sales_Model_Shipment $shipment */
313
+ $shipment = $observer->getEvent()->getShipment();
314
+
315
+ $trackingUrl = $shipment->getData('transsmart_tracking_url');
316
+
317
+ // get carrier name for this shipping method
318
+ $carrierName = Mage::getModel('transsmart_shipping/carrierprofile')
319
+ ->load($shipment->getTranssmartCarrierprofileId())
320
+ ->getCarrierName();
321
+
322
+ // prepare message before translation
323
+ if ($carrierName) {
324
+ $trackingMessage = array(
325
+ 'The shipment is carried by %s and can be tracked <a href="%s">here</a>.',
326
+ $carrierName,
327
+ $trackingUrl
328
+ );
329
+ }
330
+ else {
331
+ $trackingMessage = array(
332
+ 'The shipment can be tracked <a href="%s">here</a>.',
333
+ $trackingUrl
334
+ );
335
+ }
336
+
337
+ // emulate the store and translate the message
338
+ $appEmulation = Mage::getSingleton('core/app_emulation');
339
+ $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($shipment->getStoreId());
340
+ $trackingMessage = Mage::helper('transsmart_shipping')->forceTranslate(
341
+ $trackingMessage,
342
+ Mage::app()->getTranslator()->getLocale()
343
+ );
344
+ $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
345
+
346
+ // add comment and send the tracking URL email
347
+ $shipment->addComment($trackingMessage, true, true);
348
+ /** @var Mage_Sales_Model_Order_Shipment_Comment $_comment */
349
+ foreach ($shipment->getCommentsCollection() as $_comment) {
350
+ $_comment->save();
351
+ }
352
+ $shipment->sendUpdateEmail(true, $trackingMessage);
353
+ }
354
+ }
app/code/community/Transsmart/Shipping/Model/Packagetype.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Transsmart Package Type Model
5
+ *
6
+ * @method Transsmart_Shipping_Model_Resource_Packagetype _getResource()
7
+ * @method Transsmart_Shipping_Model_Resource_Packagetype getResource()
8
+ * @method int getPackagetypeId()
9
+ * @method Transsmart_Shipping_Model_Packagetype setPackagetypeId(int $value)
10
+ * @method string getCode()
11
+ * @method Transsmart_Shipping_Model_Packagetype setCode(string $value)
12
+ * @method string getName()
13
+ * @method Transsmart_Shipping_Model_Packagetype setName(string $value)
14
+ * @method float getLength()
15
+ * @method Transsmart_Shipping_Model_Packagetype setLength(float $value)
16
+ * @method float getWidth()
17
+ * @method Transsmart_Shipping_Model_Packagetype setWidth(float $value)
18
+ * @method float getHeight()
19
+ * @method Transsmart_Shipping_Model_Packagetype setHeight(float $value)
20
+ * @method float getWeight()
21
+ * @method Transsmart_Shipping_Model_Packagetype setWeight(float $value)
22
+ * @method bool getIsDefault()
23
+ * @method Transsmart_Shipping_Model_Packagetype setIsDefault(bool $value)
24
+ *
25
+ * @category Transsmart
26
+ * @package Transsmart_Shipping
27
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
28
+ */
29
+ class Transsmart_Shipping_Model_Packagetype extends Transsmart_Shipping_Model_Abstract
30
+ {
31
+ /**
32
+ * A list of API keys to be mapped to database columns.
33
+ * @var array
34
+ */
35
+ protected $apiKeysMapping = array(
36
+ 'Id' => 'packagetype_id',
37
+ 'Type' => 'code',
38
+ 'Name' => 'name',
39
+ 'Length' => 'length',
40
+ 'Width' => 'width',
41
+ 'Height' => 'height',
42
+ 'Weight' => 'weight',
43
+ 'IsDefault' => 'is_default'
44
+ );
45
+
46
+ /**
47
+ * Object initialization
48
+ */
49
+ protected function _construct()
50
+ {
51
+ $this->_init('transsmart_shipping/packagetype');
52
+ }
53
+ }
app/code/community/Transsmart/Shipping/Model/Resource/Carrier.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Resource_Carrier extends Mage_Core_Model_Resource_Db_Abstract
9
+ {
10
+ /**
11
+ * Primary key auto increment flag
12
+ *
13
+ * @var bool
14
+ */
15
+ protected $_isPkAutoIncrement = false;
16
+
17
+ /**
18
+ * Resource initialization
19
+ */
20
+ protected function _construct()
21
+ {
22
+ $this->_init('transsmart_shipping/carrier', 'carrier_id');
23
+ }
24
+ }
app/code/community/Transsmart/Shipping/Model/Resource/Carrier/Collection.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Resource_Carrier_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
9
+ {
10
+ protected function _construct()
11
+ {
12
+ $this->_init('transsmart_shipping/carrier');
13
+ }
14
+
15
+ public function toOptionHash()
16
+ {
17
+ return $this->_toOptionHash('carrier_id');
18
+ }
19
+ }
app/code/community/Transsmart/Shipping/Model/Resource/Carrierprofile.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Resource_Carrierprofile extends Mage_Core_Model_Resource_Db_Abstract
9
+ {
10
+ /**
11
+ * Primary key auto increment flag
12
+ *
13
+ * @var bool
14
+ */
15
+ protected $_isPkAutoIncrement = false;
16
+
17
+ /**
18
+ * Resource initialization
19
+ */
20
+ protected function _construct()
21
+ {
22
+ $this->_init('transsmart_shipping/carrierprofile', 'carrierprofile_id');
23
+ }
24
+
25
+ /**
26
+ * Retrieve select object for load object data
27
+ *
28
+ * @param string $field
29
+ * @param mixed $value
30
+ * @param Mage_Core_Model_Abstract $object
31
+ * @return Zend_Db_Select
32
+ */
33
+ protected function _getLoadSelect($field, $value, $object)
34
+ {
35
+ $select = parent::_getLoadSelect($field, $value, $object);
36
+
37
+ // join the carrier table
38
+ $select->join(
39
+ array(
40
+ 'carrier' => $this->getTable('transsmart_shipping/carrier')
41
+ ),
42
+ 'carrier.carrier_id = ' . $this->getMainTable() . '.carrier_id',
43
+ array(
44
+ 'carrier_code' => 'code',
45
+ 'carrier_name' => 'name',
46
+ 'carrier_location_select' => 'location_select',
47
+ )
48
+ );
49
+
50
+ // join the servicelevel_time table
51
+ $select->join(
52
+ array(
53
+ 'servicelevel_time' => $this->getTable('transsmart_shipping/servicelevel_time')
54
+ ),
55
+ 'servicelevel_time.servicelevel_time_id = ' . $this->getMainTable() . '.servicelevel_time_id',
56
+ array(
57
+ 'servicelevel_time_code' => 'code',
58
+ 'servicelevel_time_name' => 'name',
59
+ )
60
+ );
61
+
62
+ // join the servicelevel_other table
63
+ $select->join(
64
+ array(
65
+ 'servicelevel_other' => $this->getTable('transsmart_shipping/servicelevel_other')
66
+ ),
67
+ 'servicelevel_other.servicelevel_other_id = ' . $this->getMainTable() . '.servicelevel_other_id',
68
+ array(
69
+ 'servicelevel_other_code' => 'code',
70
+ 'servicelevel_other_name' => 'name',
71
+ )
72
+ );
73
+
74
+ return $select;
75
+ }
76
+ }
app/code/community/Transsmart/Shipping/Model/Resource/Carrierprofile/Collection.php ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Resource_Carrierprofile_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
9
+ {
10
+ protected $_hasJoinedCarrier = false;
11
+ protected $_hasJoinedServicelevelTime = false;
12
+ protected $_hasJoinedServicelevelOther = false;
13
+
14
+ protected function _construct()
15
+ {
16
+ $this->_init('transsmart_shipping/carrierprofile');
17
+ }
18
+
19
+ public function toOptionHash()
20
+ {
21
+ $this->joinCarrier()
22
+ ->joinServicelevelTime()
23
+ ->joinServicelevelOther();
24
+
25
+ $res = array();
26
+ foreach ($this as $item) {
27
+ $res[$item->getData('carrierprofile_id')] = $item->getName();
28
+ }
29
+ return $res;
30
+ }
31
+
32
+ /**
33
+ * Join the carrier table.
34
+ *
35
+ * @return $this
36
+ */
37
+ public function joinCarrier()
38
+ {
39
+ if ($this->_hasJoinedCarrier) {
40
+ return $this;
41
+ }
42
+ $this->_hasJoinedCarrier = true;
43
+
44
+ $this->getSelect()
45
+ ->join(
46
+ array(
47
+ 'carrier' => $this->getTable('transsmart_shipping/carrier')
48
+ ),
49
+ 'carrier.carrier_id = main_table.carrier_id',
50
+ array(
51
+ 'carrier_code' => 'code',
52
+ 'carrier_name' => 'name',
53
+ 'carrier_location_select' => 'location_select',
54
+ )
55
+ );
56
+ return $this;
57
+ }
58
+
59
+ /**
60
+ * Join the servicelevel_time table.
61
+ *
62
+ * @return $this
63
+ */
64
+ public function joinServicelevelTime()
65
+ {
66
+ if ($this->_hasJoinedServicelevelTime) {
67
+ return $this;
68
+ }
69
+ $this->_hasJoinedServicelevelTime = true;
70
+
71
+ $this->getSelect()
72
+ ->join(
73
+ array(
74
+ 'servicelevel_time' => $this->getTable('transsmart_shipping/servicelevel_time')
75
+ ),
76
+ 'servicelevel_time.servicelevel_time_id = main_table.servicelevel_time_id',
77
+ array(
78
+ 'servicelevel_time_code' => 'code',
79
+ 'servicelevel_time_name' => 'name',
80
+ )
81
+ );
82
+ return $this;
83
+ }
84
+
85
+ /**
86
+ * Join the servicelevel_other table.
87
+ *
88
+ * @return $this
89
+ */
90
+ public function joinServicelevelOther()
91
+ {
92
+ if ($this->_hasJoinedServicelevelOther) {
93
+ return $this;
94
+ }
95
+ $this->_hasJoinedServicelevelOther = true;
96
+
97
+ $this->getSelect()
98
+ ->join(
99
+ array(
100
+ 'servicelevel_other' => $this->getTable('transsmart_shipping/servicelevel_other')
101
+ ),
102
+ 'servicelevel_other.servicelevel_other_id = main_table.servicelevel_other_id',
103
+ array(
104
+ 'servicelevel_other_code' => 'code',
105
+ 'servicelevel_other_name' => 'name',
106
+ )
107
+ );
108
+ return $this;
109
+ }
110
+ }
app/code/community/Transsmart/Shipping/Model/Resource/Costcenter.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Resource_Costcenter extends Mage_Core_Model_Resource_Db_Abstract
9
+ {
10
+ /**
11
+ * Primary key auto increment flag
12
+ *
13
+ * @var bool
14
+ */
15
+ protected $_isPkAutoIncrement = false;
16
+
17
+ /**
18
+ * Resource initialization
19
+ */
20
+ protected function _construct()
21
+ {
22
+ $this->_init('transsmart_shipping/costcenter', 'costcenter_id');
23
+ }
24
+ }
app/code/community/Transsmart/Shipping/Model/Resource/Costcenter/Collection.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Resource_Costcenter_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
9
+ {
10
+ protected function _construct()
11
+ {
12
+ $this->_init('transsmart_shipping/costcenter');
13
+ }
14
+
15
+ public function toOptionHash()
16
+ {
17
+ return $this->_toOptionHash('costcenter_id');
18
+ }
19
+ }
app/code/community/Transsmart/Shipping/Model/Resource/Emailtype.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Resource_Emailtype extends Mage_Core_Model_Resource_Db_Abstract
9
+ {
10
+ /**
11
+ * Primary key auto increment flag
12
+ *
13
+ * @var bool
14
+ */
15
+ protected $_isPkAutoIncrement = false;
16
+
17
+ /**
18
+ * Resource initialization
19
+ */
20
+ protected function _construct()
21
+ {
22
+ $this->_init('transsmart_shipping/emailtype', 'emailtype_id');
23
+ }
24
+ }
app/code/community/Transsmart/Shipping/Model/Resource/Emailtype/Collection.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Resource_Emailtype_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
9
+ {
10
+ protected function _construct()
11
+ {
12
+ $this->_init('transsmart_shipping/emailtype');
13
+ }
14
+
15
+ public function toOptionHash()
16
+ {
17
+ return $this->_toOptionHash('emailtype_id');
18
+ }
19
+ }
app/code/community/Transsmart/Shipping/Model/Resource/Incoterm.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Resource_Incoterm extends Mage_Core_Model_Resource_Db_Abstract
9
+ {
10
+ /**
11
+ * Primary key auto increment flag
12
+ *
13
+ * @var bool
14
+ */
15
+ protected $_isPkAutoIncrement = false;
16
+
17
+ /**
18
+ * Resource initialization
19
+ */
20
+ protected function _construct()
21
+ {
22
+ $this->_init('transsmart_shipping/incoterm', 'incoterm_id');
23
+ }
24
+ }
app/code/community/Transsmart/Shipping/Model/Resource/Incoterm/Collection.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Resource_Incoterm_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
9
+ {
10
+ protected function _construct()
11
+ {
12
+ $this->_init('transsmart_shipping/incoterm');
13
+ }
14
+
15
+ public function toOptionHash()
16
+ {
17
+ return $this->_toOptionHash('incoterm_id');
18
+ }
19
+ }
app/code/community/Transsmart/Shipping/Model/Resource/Packagetype.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Resource_Packagetype extends Mage_Core_Model_Resource_Db_Abstract
9
+ {
10
+ /**
11
+ * Primary key auto increment flag
12
+ *
13
+ * @var bool
14
+ */
15
+ protected $_isPkAutoIncrement = false;
16
+
17
+ /**
18
+ * Resource initialization
19
+ */
20
+ protected function _construct()
21
+ {
22
+ $this->_init('transsmart_shipping/packagetype', 'packagetype_id');
23
+ }
24
+ }
app/code/community/Transsmart/Shipping/Model/Resource/Packagetype/Collection.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Resource_Packagetype_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
9
+ {
10
+ protected function _construct()
11
+ {
12
+ $this->_init('transsmart_shipping/packagetype');
13
+ }
14
+
15
+ public function toOptionHash()
16
+ {
17
+ return $this->_toOptionHash('packagetype_id');
18
+ }
19
+ }
app/code/community/Transsmart/Shipping/Model/Resource/Servicelevel/Other.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Resource_Servicelevel_Other extends Mage_Core_Model_Resource_Db_Abstract
9
+ {
10
+ /**
11
+ * Primary key auto increment flag
12
+ *
13
+ * @var bool
14
+ */
15
+ protected $_isPkAutoIncrement = false;
16
+
17
+ /**
18
+ * Resource initialization
19
+ */
20
+ protected function _construct()
21
+ {
22
+ $this->_init('transsmart_shipping/servicelevel_other', 'servicelevel_other_id');
23
+ }
24
+ }
app/code/community/Transsmart/Shipping/Model/Resource/Servicelevel/Other/Collection.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Resource_Servicelevel_Other_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
9
+ {
10
+ protected function _construct()
11
+ {
12
+ $this->_init('transsmart_shipping/servicelevel_other');
13
+ }
14
+
15
+ public function toOptionHash()
16
+ {
17
+ return $this->_toOptionHash('servicelevel_other_id');
18
+ }
19
+ }
app/code/community/Transsmart/Shipping/Model/Resource/Servicelevel/Time.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Resource_Servicelevel_Time extends Mage_Core_Model_Resource_Db_Abstract
9
+ {
10
+ /**
11
+ * Primary key auto increment flag
12
+ *
13
+ * @var bool
14
+ */
15
+ protected $_isPkAutoIncrement = false;
16
+
17
+ /**
18
+ * Resource initialization
19
+ */
20
+ protected function _construct()
21
+ {
22
+ $this->_init('transsmart_shipping/servicelevel_time', 'servicelevel_time_id');
23
+ }
24
+ }
app/code/community/Transsmart/Shipping/Model/Resource/Servicelevel/Time/Collection.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Resource_Servicelevel_Time_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
9
+ {
10
+ protected function _construct()
11
+ {
12
+ $this->_init('transsmart_shipping/servicelevel_time');
13
+ }
14
+
15
+ public function toOptionHash()
16
+ {
17
+ return $this->_toOptionHash('servicelevel_time_id');
18
+ }
19
+ }
app/code/community/Transsmart/Shipping/Model/Resource/Shipmentlocation.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Resource_Shipmentlocation extends Mage_Core_Model_Resource_Db_Abstract
9
+ {
10
+ /**
11
+ * Primary key auto increment flag
12
+ *
13
+ * @var bool
14
+ */
15
+ protected $_isPkAutoIncrement = false;
16
+
17
+ /**
18
+ * Resource initialization
19
+ */
20
+ protected function _construct()
21
+ {
22
+ $this->_init('transsmart_shipping/shipmentlocation', 'shipmentlocation_id');
23
+ }
24
+ }
app/code/community/Transsmart/Shipping/Model/Resource/Shipmentlocation/Collection.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Resource_Shipmentlocation_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
9
+ {
10
+ protected function _construct()
11
+ {
12
+ $this->_init('transsmart_shipping/shipmentlocation');
13
+ }
14
+
15
+ public function toOptionHash()
16
+ {
17
+ return $this->_toOptionHash('shipmentlocation_id');
18
+ }
19
+ }
app/code/community/Transsmart/Shipping/Model/Resource/Sync.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Resource_Sync extends Mage_Core_Model_Resource_Db_Abstract
9
+ {
10
+ /**
11
+ * Resource initialization
12
+ */
13
+ protected function _construct()
14
+ {
15
+ $this->_init('transsmart_shipping/sync', 'sync_id');
16
+ }
17
+ }
app/code/community/Transsmart/Shipping/Model/Resource/Sync/Collection.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Resource_Sync_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
9
+ {
10
+ protected function _construct()
11
+ {
12
+ $this->_init('transsmart_shipping/sync');
13
+ }
14
+ }
app/code/community/Transsmart/Shipping/Model/Sales/Resource/Order.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Sales_Resource_Order extends Mage_Sales_Model_Resource_Order
9
+ {
10
+ /**
11
+ * Join virtual grid columns to select. These will be copied into the sales_flat_order_grid table.
12
+ *
13
+ * @param string $mainTableAlias
14
+ * @param Zend_Db_Select $select
15
+ * @param array $columnsToSelect
16
+ * @return Mage_Sales_Model_Resource_Order_Abstract
17
+ */
18
+ public function joinVirtualGridColumnsToSelect($mainTableAlias, Zend_Db_Select $select, &$columnsToSelect)
19
+ {
20
+ /** @var Magento_Db_Adapter_Pdo_Mysql $adapter */
21
+ $adapter = $this->getReadConnection();
22
+
23
+ // join Transsmart shipments and group by order ID, so we can use aggregate functions
24
+ $select
25
+ ->joinLeft(
26
+ array('transsmart_shipments' => $this->getTable('sales/shipment')),
27
+ "transsmart_shipments.order_id = $mainTableAlias.entity_id" .
28
+ " AND transsmart_shipments.transsmart_status IS NOT NULL",
29
+ array()
30
+ )
31
+ ->joinLeft(
32
+ array('transsmart_shipments_error' => $this->getTable('sales/shipment')),
33
+ "transsmart_shipments_error.order_id = $mainTableAlias.entity_id" .
34
+ " AND transsmart_shipments_error.transsmart_status = 'ERR'",
35
+ array()
36
+ )
37
+ ->group("$mainTableAlias.entity_id");
38
+
39
+ // define the logic that determines the Transsmart order status
40
+ $casesResults = array();
41
+
42
+ $casesResults['main_table.shipping_method NOT LIKE \'transsmart%\_carrierprofile\_%\''] =
43
+ Transsmart_Shipping_Helper_Data::TRANSSMART_ORDER_STATUS_NOT_APPLICABLE;
44
+
45
+ $casesResults['SUM(transsmart_shipments_error.total_qty) > 0'] =
46
+ Transsmart_Shipping_Helper_Data::TRANSSMART_ORDER_STATUS_ERROR;
47
+
48
+ $casesResults['SUM(transsmart_shipments.total_qty) = main_table.total_qty_ordered'] =
49
+ Transsmart_Shipping_Helper_Data::TRANSSMART_ORDER_STATUS_EXPORTED;
50
+
51
+ $casesResults['SUM(transsmart_shipments.total_qty) > 0'] =
52
+ Transsmart_Shipping_Helper_Data::TRANSSMART_ORDER_STATUS_PARTIALLY_EXPORTED;
53
+
54
+ $defaultValue =
55
+ Transsmart_Shipping_Helper_Data::TRANSSMART_ORDER_STATUS_PENDING;
56
+
57
+ // add the transsmart_status column
58
+ $select
59
+ ->columns(
60
+ array('transsmart_status' => new Zend_Db_Expr($adapter->getCaseSql('', $casesResults, $defaultValue)))
61
+ );
62
+ $columnsToSelect[] = 'transsmart_status';
63
+
64
+ return parent::joinVirtualGridColumnsToSelect($mainTableAlias, $select, $columnsToSelect);
65
+ }
66
+ }
app/code/community/Transsmart/Shipping/Model/Servicelevel/Other.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Transsmart Servicelevel Other Model
5
+ *
6
+ * @method Transsmart_Shipping_Model_Resource_Servicelevel_Other _getResource()
7
+ * @method Transsmart_Shipping_Model_Resource_Servicelevel_Other getResource()
8
+ * @method int getServicelevelOtherId()
9
+ * @method Transsmart_Shipping_Model_Servicelevel_Other setServicelevelOtherId(int $value)
10
+ * @method string getCode()
11
+ * @method Transsmart_Shipping_Model_Servicelevel_Other setCode(string $value)
12
+ * @method string getName()
13
+ * @method Transsmart_Shipping_Model_Servicelevel_Other setName(string $value)
14
+ *
15
+ * @category Transsmart
16
+ * @package Transsmart_Shipping
17
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
18
+ */
19
+ class Transsmart_Shipping_Model_Servicelevel_Other extends Transsmart_Shipping_Model_Abstract
20
+ {
21
+ /**
22
+ * A list of API keys to be mapped to database columns.
23
+ * @var array
24
+ */
25
+ protected $apiKeysMapping = array(
26
+ 'Id' => 'servicelevel_other_id',
27
+ 'Code' => 'code',
28
+ 'Name' => 'name',
29
+ 'Deleted' => 'deleted'
30
+ );
31
+
32
+ protected function _construct()
33
+ {
34
+ $this->_init('transsmart_shipping/servicelevel_other');
35
+ }
36
+ }
app/code/community/Transsmart/Shipping/Model/Servicelevel/Time.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Transsmart Servicelevel Time Model
5
+ *
6
+ * @method Transsmart_Shipping_Model_Resource_Servicelevel_Time _getResource()
7
+ * @method Transsmart_Shipping_Model_Resource_Servicelevel_Time getResource()
8
+ * @method int getServicelevelTimeId()
9
+ * @method Transsmart_Shipping_Model_Servicelevel_Time setServicelevelTimeId(int $value)
10
+ * @method string getCode()
11
+ * @method Transsmart_Shipping_Model_Servicelevel_Time setCode(string $value)
12
+ * @method string getName()
13
+ * @method Transsmart_Shipping_Model_Servicelevel_Time setName(string $value)
14
+ *
15
+ * @category Transsmart
16
+ * @package Transsmart_Shipping
17
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
18
+ */
19
+ class Transsmart_Shipping_Model_Servicelevel_Time extends Transsmart_Shipping_Model_Abstract
20
+ {
21
+ /**
22
+ * A list of API keys to be mapped to database columns.
23
+ * @var array
24
+ */
25
+ protected $apiKeysMapping = array(
26
+ 'Id' => 'servicelevel_time_id',
27
+ 'Code' => 'code',
28
+ 'Name' => 'name',
29
+ 'Deleted' => 'deleted'
30
+ );
31
+
32
+ protected function _construct()
33
+ {
34
+ $this->_init('transsmart_shipping/servicelevel_time');
35
+ }
36
+ }
app/code/community/Transsmart/Shipping/Model/Shipmentlocation.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Transsmart Shipment Location Model
5
+ *
6
+ * @method Transsmart_Shipping_Model_Resource_Shipmentlocation _getResource()
7
+ * @method Transsmart_Shipping_Model_Resource_Shipmentlocation getResource()
8
+ * @method int getShipmentlocationId()
9
+ * @method Transsmart_Shipping_Model_Shipmentlocation setShipmentlocationId(int $value)
10
+ * @method string getName()
11
+ * @method Transsmart_Shipping_Model_Shipmentlocation setName(string $value)
12
+ * @method string getStreet()
13
+ * @method Transsmart_Shipping_Model_Shipmentlocation setStreet(string $value)
14
+ * @method string getStreetNo()
15
+ * @method Transsmart_Shipping_Model_Shipmentlocation setStreetNo(string $value)
16
+ * @method string getZipCode()
17
+ * @method Transsmart_Shipping_Model_Shipmentlocation setZipCode(string $value)
18
+ * @method string getCity()
19
+ * @method Transsmart_Shipping_Model_Shipmentlocation setCity(string $value)
20
+ * @method string getCountry()
21
+ * @method Transsmart_Shipping_Model_Shipmentlocation setCountry(string $value)
22
+ * @method string getContactPerson()
23
+ * @method Transsmart_Shipping_Model_Shipmentlocation setContactPerson(string $value)
24
+ * @method string getPhoneNumber()
25
+ * @method Transsmart_Shipping_Model_Shipmentlocation setPhoneNumber(string $value)
26
+ * @method string getFaxNumber()
27
+ * @method Transsmart_Shipping_Model_Shipmentlocation setFaxNumber(string $value)
28
+ * @method string getEmailAddress()
29
+ * @method Transsmart_Shipping_Model_Shipmentlocation setEmailAddress(string $value)
30
+ * @method string getAccountNumber()
31
+ * @method Transsmart_Shipping_Model_Shipmentlocation setAccountNumber(string $value)
32
+ * @method string getCustomerNumber()
33
+ * @method Transsmart_Shipping_Model_Shipmentlocation setCustomerNumber(string $value)
34
+ * @method string getVatNumber()
35
+ * @method Transsmart_Shipping_Model_Shipmentlocation setVatNumber(string $value)
36
+ * @method bool getIsDefault()
37
+ * @method Transsmart_Shipping_Model_Shipmentlocation setIsDefault(bool $value)
38
+ *
39
+ * @category Transsmart
40
+ * @package Transsmart_Shipping
41
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
42
+ */
43
+ class Transsmart_Shipping_Model_Shipmentlocation extends Transsmart_Shipping_Model_Abstract
44
+ {
45
+ /**
46
+ * A list of API keys to be mapped to database columns.
47
+ * @var array
48
+ */
49
+ protected $apiKeysMapping = array(
50
+ 'Id' => 'shipmentlocation_id',
51
+ 'Name' => 'name',
52
+ 'Street' => 'street',
53
+ 'StreetNo' => 'street_no',
54
+ 'ZipCode' => 'zip_code',
55
+ 'City' => 'city',
56
+ 'Country' => 'country',
57
+ 'ContactPerson' => 'contact_person',
58
+ 'PhoneNumber' => 'phone_number',
59
+ 'FaxNumber' => 'fax_number',
60
+ 'EmailAddress' => 'email_address',
61
+ 'AccountNumber' => 'account_number',
62
+ 'CustomerNumber' => 'customer_number',
63
+ 'VatNumber' => 'vat_number',
64
+ 'IsDefault' => 'is_default'
65
+ // TODO: Unmapped: CostcenterId
66
+ );
67
+
68
+ /**
69
+ * Object initialization
70
+ */
71
+ protected function _construct()
72
+ {
73
+ $this->_init('transsmart_shipping/shipmentlocation');
74
+ }
75
+ }
app/code/community/Transsmart/Shipping/Model/Shipping/Carrier/Abstract.php ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Shipping_Carrier_Abstract
9
+ extends Mage_Shipping_Model_Carrier_Abstract
10
+ implements Mage_Shipping_Model_Carrier_Interface
11
+ {
12
+ protected $_isFixed = true;
13
+
14
+ /**
15
+ * Collect available shipping methods and calculate rates.
16
+ *
17
+ * @param Mage_Shipping_Model_Rate_Request $request
18
+ * @return Mage_Shipping_Model_Rate_Result
19
+ */
20
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request)
21
+ {
22
+ $freeBoxes = 0;
23
+ if ($request->getAllItems()) {
24
+ foreach ($request->getAllItems() as $_item) {
25
+ if ($_item->getProduct()->isVirtual() || $_item->getParentItem()) {
26
+ continue;
27
+ }
28
+
29
+ if ($_item->getHasChildren() && $_item->isShipSeparately()) {
30
+ foreach ($_item->getChildren() as $_child) {
31
+ if ($_child->getFreeShipping() && !$_child->getProduct()->isVirtual()) {
32
+ $freeBoxes += $_item->getQty() * $_child->getQty();
33
+ }
34
+ }
35
+ } elseif ($_item->getFreeShipping()) {
36
+ $freeBoxes += $_item->getQty();
37
+ }
38
+ }
39
+ }
40
+ $this->setFreeBoxes($freeBoxes);
41
+
42
+ $result = Mage::getModel('shipping/rate_result');
43
+
44
+ /** @var Transsmart_Shipping_Model_Resource_Carrierprofile_Collection $carrierprofiles */
45
+ $carrierprofiles = Mage::getResourceSingleton('transsmart_shipping/carrierprofile_collection');
46
+
47
+ foreach ($carrierprofiles as $_carrierprofile) {
48
+ if ($_carrierprofile->getConfigData('method', $this->getStore()) != $this->getCarrierCode()) {
49
+ continue;
50
+ }
51
+
52
+ // check if carrier profile is allowed for this country
53
+ if ($_carrierprofile->getConfigData('sallowspecific', $this->getStore()) == 1) {
54
+ $_availableCountries = $_carrierprofile->getConfigData('specificcountry', $this->getStore());
55
+ $_availableCountries = array_filter(explode(',', $_availableCountries));
56
+ if (!in_array($request->getDestCountryId(), $_availableCountries)) {
57
+ continue;
58
+ }
59
+ }
60
+
61
+ // calculate shipping price
62
+ $_shippingPrice = $_carrierprofile->getConfigData('price', $this->getStore());
63
+
64
+ // apply free shipping
65
+ if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
66
+ $_shippingPrice = '0.00';
67
+ }
68
+
69
+ // append the method to the result
70
+ $_method = Mage::getModel('shipping/rate_result_method');
71
+
72
+ $_method->setCarrier($this->getCarrierCode());
73
+ $_method->setCarrierTitle($this->getConfigData('title'));
74
+
75
+ $_method->setMethod('carrierprofile_' . $_carrierprofile->getId());
76
+ $_method->setMethodTitle($_carrierprofile->getConfigData('title', $this->getStore()));
77
+
78
+ $_method->setPrice($_shippingPrice);
79
+ $_method->setCost($_shippingPrice);
80
+
81
+ $result->append($_method);
82
+ }
83
+
84
+ return $result;
85
+ }
86
+
87
+ /**
88
+ * Get allowed shipping methods
89
+ *
90
+ * @return array
91
+ */
92
+ public function getAllowedMethods()
93
+ {
94
+ $result = array();
95
+
96
+ /** @var Transsmart_Shipping_Model_Resource_Carrierprofile_Collection $carrierprofiles */
97
+ $carrierprofiles = Mage::getResourceSingleton('transsmart_shipping/carrierprofile_collection');
98
+
99
+ foreach ($carrierprofiles as $_carrierprofile) {
100
+ if ($_carrierprofile->getConfigData('method', $this->getStore()) != $this->getCarrierCode()) {
101
+ continue;
102
+ }
103
+
104
+ $result['carrierprofile_' . $_carrierprofile->getId()]
105
+ = $_carrierprofile->getConfigData('title', $this->getStore());
106
+ }
107
+
108
+ return $result;
109
+ }
110
+
111
+ /**
112
+ * @param Mage_Shipping_Model_Rate_Request $request
113
+ * @return $this
114
+ */
115
+ public function checkAvailableShipCountries(Mage_Shipping_Model_Rate_Request $request)
116
+ {
117
+ return $this;
118
+ }
119
+
120
+ /**
121
+ * Check if carrier has shipping tracking option available
122
+ *
123
+ * @return boolean
124
+ */
125
+ public function isTrackingAvailable()
126
+ {
127
+ return true;
128
+ }
129
+
130
+ /**
131
+ * Check if carrier has shipping label option available
132
+ *
133
+ * @return boolean
134
+ */
135
+ public function isShippingLabelsAvailable()
136
+ {
137
+ return false; // yes, but labels are not created in Magento
138
+ }
139
+ }
app/code/community/Transsmart/Shipping/Model/Shipping/Carrier/Delivery.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Shipping_Carrier_Delivery extends Transsmart_Shipping_Model_Shipping_Carrier_Abstract
9
+ {
10
+ protected $_code = 'transsmartdelivery';
11
+ protected $_locationSelect = false;
12
+ }
app/code/community/Transsmart/Shipping/Model/Shipping/Carrier/Pickup.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Model_Shipping_Carrier_Pickup extends Transsmart_Shipping_Model_Shipping_Carrier_Abstract
9
+ {
10
+ protected $_code = 'transsmartpickup';
11
+ protected $_locationSelect = true;
12
+ }
app/code/community/Transsmart/Shipping/Model/Sync.php ADDED
@@ -0,0 +1,743 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Transsmart Sync Model
5
+ *
6
+ * @todo Cleanup old records from sync table
7
+ *
8
+ * @method Transsmart_Shipping_Model_Resource_Sync _getResource()
9
+ * @method Transsmart_Shipping_Model_Resource_Sync getResource()
10
+ * @method Transsmart_Shipping_Model_Resource_Sync_Collection getCollection()
11
+ * @method int getSyncId()
12
+ * @method Transsmart_Shipping_Model_Sync setSyncId(int $value)
13
+ * @method string getType()
14
+ * @method Transsmart_Shipping_Model_Sync setType(string $value)
15
+ * @method string getStatus()
16
+ * @method Transsmart_Shipping_Model_Sync setStatus(string $value)
17
+ * @method string getMessage()
18
+ * @method Transsmart_Shipping_Model_Sync setMessage(string $value)
19
+ * @method string getCreatedAt()
20
+ * @method Transsmart_Shipping_Model_Sync setCreatedAt(string $value)
21
+ *
22
+ * @category Transsmart
23
+ * @package Transsmart_Shipping
24
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
25
+ */
26
+ class Transsmart_Shipping_Model_Sync extends Mage_Core_Model_Abstract
27
+ {
28
+ /**
29
+ * Represents the initial synchronization to retrieve base data.
30
+ */
31
+ const TYPE_BASE = 'base';
32
+ const TYPE_SHIPMENTS = 'shipments';
33
+
34
+ const STATUS_RUNNING = 'running';
35
+ const STATUS_FAILED = 'failed';
36
+ const STATUS_FINISHED = 'finished';
37
+
38
+ /**
39
+ * Object initialization
40
+ */
41
+ protected function _construct()
42
+ {
43
+ $this->_init('transsmart_shipping/sync');
44
+ }
45
+
46
+ /**
47
+ * Synchronizes the basic data that is necessary to show shipping details.
48
+ * The data is retrieved through the Transsmart API and then stored in the database.
49
+ *
50
+ * The following information is synchronized:
51
+ * - Carriers
52
+ * - Carrier profiles
53
+ * - Service level time
54
+ * - Service level other
55
+ * - E-mail types
56
+ * - Package types
57
+ * - Incoterms
58
+ * - Cost centers
59
+ */
60
+ public function syncBaseData()
61
+ {
62
+ $this->clearInstance();
63
+ $this->setType(self::TYPE_BASE)
64
+ ->setStatus(self::STATUS_RUNNING)
65
+ ->setCreatedAt(Mage::getModel('core/date')->gmtDate())
66
+ ->save();
67
+
68
+ $this->syncCarriers()
69
+ ->syncServiceLevelTimes()
70
+ ->syncServiceLevelOther()
71
+ ->syncCarrierProfiles()
72
+ ->syncEmailTypes()
73
+ ->syncPackageTypes()
74
+ ->syncIncoterms()
75
+ ->syncCostCenters()
76
+ ->syncShipmentLocations();
77
+
78
+ $this->setStatus(self::STATUS_FINISHED)
79
+ ->save();
80
+ }
81
+
82
+ /**
83
+ * Retrieve carriers from the API and insert into the database.
84
+ * Carriers that are not present in the API will be deleted.
85
+ * @return Transsmart_Shipping_Model_Sync
86
+ */
87
+ public function syncCarriers()
88
+ {
89
+ $apiClient = $this->getApiClient();
90
+
91
+ // Keep track of all carrier ID's that come from the API
92
+ $apiItemIds = array();
93
+
94
+ // Retrieve the items from the API
95
+ $apiItems = $apiClient->getCarrier();
96
+
97
+ if (is_array($apiItems)) {
98
+ foreach ($apiItems as $apiItem) {
99
+ /** @var Transsmart_Shipping_Model_Carrier $model */
100
+ $model = Mage::getModel('transsmart_shipping/carrier');
101
+ $mappedData = $model->mapApiKeysToDbColumns($apiItem);
102
+
103
+ // LocationSelect is returned as Y/N from the API, Map that to 1 and 0
104
+ if (isset($mappedData['location_select'])) {
105
+ $mappedData['location_select'] = $mappedData['location_select'] == 'Y' ? 1 : 0;
106
+ }
107
+
108
+ $model->setData($mappedData);
109
+ $model->save();
110
+
111
+ $apiItemIds []= $model->getId();
112
+ }
113
+ }
114
+
115
+ // Remove all items that we didn't receive from the API
116
+ $this->deleteItemsNotInApi(
117
+ Mage::getModel('transsmart_shipping/carrier'),
118
+ $apiItemIds
119
+ );
120
+
121
+ return $this;
122
+ }
123
+
124
+ /**
125
+ * Retrieve carrier profiles from the API and insert into the database.
126
+ * Carrier profiles that are not present in the API will be deleted.
127
+ * @return Transsmart_Shipping_Model_Sync
128
+ */
129
+ public function syncCarrierProfiles()
130
+ {
131
+ $apiClient = $this->getApiClient();
132
+
133
+ // Keep track of all carrier ID's that come from the API
134
+ $apiItemIds = array();
135
+
136
+ // Retrieve the items from the API
137
+ $apiItems = $apiClient->getCarrierProfile();
138
+
139
+ if (is_array($apiItems)) {
140
+ foreach ($apiItems as $apiItem) {
141
+ /** @var Transsmart_Shipping_Model_Carrierprofile $model */
142
+ $model = Mage::getModel('transsmart_shipping/carrierprofile');
143
+ $mappedData = $model->mapApiKeysToDbColumns($apiItem);
144
+
145
+ $model->setData($mappedData);
146
+ $model->save();
147
+
148
+ $apiItemIds []= $model->getId();
149
+ }
150
+ }
151
+
152
+ // Remove all items that we didn't receive from the API
153
+ $this->deleteItemsNotInApi(
154
+ Mage::getModel('transsmart_shipping/carrierprofile'),
155
+ $apiItemIds
156
+ );
157
+
158
+ return $this;
159
+ }
160
+
161
+ /**
162
+ * Retrieve service level times from the API and insert into the database.
163
+ * Service level times that are not present in the API will be deleted.
164
+ * @return Transsmart_Shipping_Model_Sync
165
+ */
166
+ public function syncServiceLevelTimes()
167
+ {
168
+ $apiClient = $this->getApiClient();
169
+
170
+ // Keep track of all ID's that come from the API
171
+ $apiItemIds = array();
172
+
173
+ // Retrieve the items from the API
174
+ $apiItems = $apiClient->getServiceLevelTime();
175
+
176
+ if (is_array($apiItems)) {
177
+ foreach ($apiItems as $apiItem) {
178
+ /** @var Transsmart_Shipping_Model_Servicelevel_Time $model */
179
+ $model = Mage::getModel('transsmart_shipping/servicelevel_time');
180
+ $mappedData = $model->mapApiKeysToDbColumns($apiItem);
181
+
182
+ // Skip this item if it has been marked as deleted, it will be deleted later
183
+ if (isset($mappedData['deleted']) && $mappedData['deleted']) {
184
+ continue;
185
+ }
186
+
187
+ $model->setData($mappedData);
188
+ $model->save();
189
+
190
+ $apiItemIds []= $model->getId();
191
+ }
192
+ }
193
+
194
+ // Remove all items that we didn't receive from the API
195
+ $this->deleteItemsNotInApi(
196
+ Mage::getModel('transsmart_shipping/servicelevel_time'),
197
+ $apiItemIds
198
+ );
199
+
200
+ return $this;
201
+ }
202
+
203
+ /**
204
+ * Retrieve service level other from the API and insert into the database.
205
+ * Service level other that are not present in the API will be deleted.
206
+ * @return Transsmart_Shipping_Model_Sync
207
+ */
208
+ public function syncServiceLevelOther()
209
+ {
210
+ $apiClient = $this->getApiClient();
211
+
212
+ // Keep track of all ID's that come from the API
213
+ $apiItemIds = array();
214
+
215
+ // Retrieve the items from the API
216
+ $apiItems = $apiClient->getServiceLevelOther();
217
+
218
+ if (is_array($apiItems)) {
219
+ foreach ($apiItems as $apiItem) {
220
+ /** @var Transsmart_Shipping_Model_Servicelevel_Other $model */
221
+ $model = Mage::getModel('transsmart_shipping/servicelevel_other');
222
+ $mappedData = $model->mapApiKeysToDbColumns($apiItem);
223
+
224
+ // Skip this item if it has been marked as deleted, it will be deleted later
225
+ if (isset($mappedData['deleted']) && $mappedData['deleted']) {
226
+ continue;
227
+ }
228
+
229
+ $model->setData($mappedData);
230
+ $model->save();
231
+
232
+ $apiItemIds []= $model->getId();
233
+ }
234
+ }
235
+
236
+ // Remove all items that we didn't receive from the API
237
+ $this->deleteItemsNotInApi(
238
+ Mage::getModel('transsmart_shipping/servicelevel_other'),
239
+ $apiItemIds
240
+ );
241
+
242
+ return $this;
243
+ }
244
+
245
+ /**
246
+ * Retrieve email types from the API and insert into the database.
247
+ * Email types that are not present in the API will be deleted.
248
+ * @return Transsmart_Shipping_Model_Sync
249
+ */
250
+ public function syncEmailTypes()
251
+ {
252
+ $apiClient = $this->getApiClient();
253
+
254
+ // Keep track of all ID's that come from the API
255
+ $apiItemIds = array();
256
+
257
+ // Retrieve the items from the API
258
+ $apiItems = $apiClient->getEmailType();
259
+
260
+ if (is_array($apiItems)) {
261
+ foreach ($apiItems as $apiItem) {
262
+ /** @var Transsmart_Shipping_Model_Emailtype $model */
263
+ $model = Mage::getModel('transsmart_shipping/emailtype');
264
+ $mappedData = $model->mapApiKeysToDbColumns($apiItem);
265
+
266
+ // is_default is returned as Y/N from the API, Map that to 1 and 0
267
+ if (isset($mappedData['is_default'])) {
268
+ $mappedData['is_default'] = $mappedData['is_default'] == 'Y' ? 1 : 0;
269
+ }
270
+
271
+ $model->setData($mappedData);
272
+ $model->save();
273
+
274
+ $apiItemIds []= $model->getId();
275
+ }
276
+ }
277
+
278
+ // Remove all items that we didn't receive from the API
279
+ $this->deleteItemsNotInApi(
280
+ Mage::getModel('transsmart_shipping/emailtype'),
281
+ $apiItemIds
282
+ );
283
+
284
+ return $this;
285
+ }
286
+
287
+ /**
288
+ * Retrieve package types from the API and insert into the database.
289
+ * Package types that are not present in the API will be deleted.
290
+ * @return Transsmart_Shipping_Model_Sync
291
+ */
292
+ public function syncPackageTypes()
293
+ {
294
+ $apiClient = $this->getApiClient();
295
+
296
+ // Keep track of all ID's that come from the API
297
+ $apiItemIds = array();
298
+
299
+ // Retrieve the items from the API
300
+ $apiItems = $apiClient->getPackage();
301
+
302
+ if (is_array($apiItems)) {
303
+ foreach ($apiItems as $apiItem) {
304
+ /** @var Transsmart_Shipping_Model_Packagetype $model */
305
+ $model = Mage::getModel('transsmart_shipping/packagetype');
306
+ $mappedData = $model->mapApiKeysToDbColumns($apiItem);
307
+
308
+ // is_default is returned as Y/N from the API, Map that to 1 and 0
309
+ if (isset($mappedData['is_default'])) {
310
+ $mappedData['is_default'] = $mappedData['is_default'] == 'Y' ? 1 : 0;
311
+ }
312
+
313
+ $model->setData($mappedData);
314
+ $model->save();
315
+
316
+ $apiItemIds []= $model->getId();
317
+ }
318
+ }
319
+
320
+ // Remove all items that we didn't receive from the API
321
+ $this->deleteItemsNotInApi(
322
+ Mage::getModel('transsmart_shipping/packagetype'),
323
+ $apiItemIds
324
+ );
325
+
326
+ return $this;
327
+ }
328
+
329
+ /**
330
+ * Retrieve incoterms from the API and insert into the database.
331
+ * Incoterms that are not present in the API will be deleted.
332
+ * @return Transsmart_Shipping_Model_Sync
333
+ */
334
+ public function syncIncoterms()
335
+ {
336
+ $apiClient = $this->getApiClient();
337
+
338
+ // Keep track of all ID's that come from the API
339
+ $apiItemIds = array();
340
+
341
+ // Retrieve the items from the API
342
+ $apiItems = $apiClient->getIncoterm();
343
+
344
+ if (is_array($apiItems)) {
345
+ foreach ($apiItems as $apiItem) {
346
+ /** @var Transsmart_Shipping_Model_Incoterm $model */
347
+ $model = Mage::getModel('transsmart_shipping/incoterm');
348
+ $mappedData = $model->mapApiKeysToDbColumns($apiItem);
349
+
350
+ // is_default is returned as Y/N from the API, Map that to 1 and 0
351
+ if (isset($mappedData['is_default'])) {
352
+ $mappedData['is_default'] = $mappedData['is_default'] == 'Y' ? 1 : 0;
353
+ }
354
+
355
+ $model->setData($mappedData);
356
+ $model->save();
357
+
358
+ $apiItemIds []= $model->getId();
359
+ }
360
+ }
361
+
362
+ // Remove all items that we didn't receive from the API
363
+ $this->deleteItemsNotInApi(
364
+ Mage::getModel('transsmart_shipping/incoterm'),
365
+ $apiItemIds
366
+ );
367
+
368
+ return $this;
369
+ }
370
+
371
+ /**
372
+ * Retrieve cost centers from the API and insert into the database.
373
+ * Cost centers that are not present in the API will be deleted.
374
+ * @return Transsmart_Shipping_Model_Sync
375
+ */
376
+ public function syncCostCenters()
377
+ {
378
+ $apiClient = $this->getApiClient();
379
+
380
+ // Keep track of all ID's that come from the API
381
+ $apiItemIds = array();
382
+
383
+ // Retrieve the items from the API
384
+ $apiItems = $apiClient->getCostcenter();
385
+
386
+ if (is_array($apiItems)) {
387
+ foreach ($apiItems as $apiItem) {
388
+ /** @var Transsmart_Shipping_Model_Costcenter $model */
389
+ $model = Mage::getModel('transsmart_shipping/costcenter');
390
+ $mappedData = $model->mapApiKeysToDbColumns($apiItem);
391
+
392
+ // is_default is returned as Y/N from the API, Map that to 1 and 0
393
+ if (isset($mappedData['is_default'])) {
394
+ $mappedData['is_default'] = $mappedData['is_default'] == 'Y' ? 1 : 0;
395
+ }
396
+
397
+ $model->setData($mappedData);
398
+ $model->save();
399
+
400
+ $apiItemIds []= $model->getId();
401
+ }
402
+ }
403
+
404
+ // Remove all items that we didn't receive from the API
405
+ $this->deleteItemsNotInApi(
406
+ Mage::getModel('transsmart_shipping/costcenter'),
407
+ $apiItemIds
408
+ );
409
+
410
+ return $this;
411
+ }
412
+
413
+ /**
414
+ * Retrieve shipment locations from the API and insert into the database.
415
+ * Shipment locations that are not present in the API will be deleted.
416
+ * @return Transsmart_Shipping_Model_Sync
417
+ */
418
+ public function syncShipmentLocations()
419
+ {
420
+ $apiClient = $this->getApiClient();
421
+
422
+ // Keep track of all ID's that come from the API
423
+ $apiItemIds = array();
424
+
425
+ // Retrieve the items from the API
426
+ $apiItems = $apiClient->getShipmentLocation();
427
+
428
+ if (is_array($apiItems)) {
429
+ foreach ($apiItems as $apiItem) {
430
+ /** @var Transsmart_Shipping_Model_Shipmentlocation $model */
431
+ $model = Mage::getModel('transsmart_shipping/shipmentlocation');
432
+ $mappedData = $model->mapApiKeysToDbColumns($apiItem);
433
+
434
+ // is_default is returned as Y/N from the API, Map that to 1 and 0
435
+ if (isset($mappedData['is_default'])) {
436
+ $mappedData['is_default'] = $mappedData['is_default'] == 'Y' ? 1 : 0;
437
+ }
438
+
439
+ $model->setData($mappedData);
440
+ $model->save();
441
+
442
+ $apiItemIds []= $model->getId();
443
+ }
444
+ }
445
+
446
+ // Remove all items that we didn't receive from the API
447
+ $this->deleteItemsNotInApi(
448
+ Mage::getModel('transsmart_shipping/shipmentlocation'),
449
+ $apiItemIds
450
+ );
451
+
452
+ return $this;
453
+ }
454
+
455
+ /**
456
+ * Deletes items from the database that are not present in the API
457
+ * @param Mage_Core_Model_Abstract $model
458
+ * @param $apiItemIds array A list of ID's that should not be deleted
459
+ * @return Transsmart_Shipping_Model_Sync
460
+ */
461
+ protected function deleteItemsNotInApi(Mage_Core_Model_Abstract $model, array $apiItemIds)
462
+ {
463
+ // Remove all items that are not present in the API.
464
+ // But only if we receive any id's.
465
+ // This prevents us from deleting items when the API returns an error
466
+ if (count($apiItemIds) > 0) {
467
+ $expiredItems = $model->getCollection()
468
+ ->addFieldToFilter($model->getIdFieldName(), array('nin' => $apiItemIds))
469
+ ->load();
470
+
471
+ /** @var Transsmart_Shipping_Model_Servicelevel_Other $expiredItem */
472
+ foreach ($expiredItems as $expiredItem) {
473
+ $expiredItem->delete();
474
+ }
475
+ }
476
+
477
+ return $this;
478
+ }
479
+
480
+ /**
481
+ * Retrieve the API client from the shipping helper
482
+ * @return Transsmart_Shipping_Model_Client
483
+ */
484
+ protected function getApiClient()
485
+ {
486
+ return Mage::helper('transsmart_shipping')->getApiClient();
487
+ }
488
+
489
+ /**
490
+ * Retrieve the most recent date that we synchronized this type on
491
+ * @param string $type Type of synchronization. See constants TYPE_* for available options.
492
+ * @return null|string Returns null when no record could be found
493
+ */
494
+ public function getLastSync($type = self::TYPE_BASE)
495
+ {
496
+ $syncDateCollection = $this->getCollection()
497
+ ->addFieldToFilter('type', $type)
498
+ ->setOrder('created_at', Mage_Core_Model_Resource_Db_Collection_Abstract::SORT_ORDER_DESC)
499
+ ->setPageSize(1)
500
+ ->load();
501
+
502
+ if ($syncDateCollection->count() == 0) {
503
+ return null;
504
+ }
505
+
506
+ /** @var Transsmart_Shipping_Model_Sync $lastSyncDate */
507
+ $lastSyncDate = $syncDateCollection->getFirstItem();
508
+ return $lastSyncDate->getCreatedAt();
509
+ }
510
+
511
+ /**
512
+ * @return $this
513
+ */
514
+ protected function exportShipments()
515
+ {
516
+ /** @var Mage_Sales_Model_Resource_Order_Shipment_Collection $shipmentCollection */
517
+ $shipmentCollection = Mage::getResourceModel('sales/order_shipment_collection');
518
+
519
+ // join the shipping_method column from the order table
520
+ $shipmentCollection->join(
521
+ array('order' => 'sales/order'),
522
+ 'order.entity_id = main_table.order_id',
523
+ ''
524
+ );
525
+
526
+ // we need only valid Transsmart shipments without document ID
527
+ $shipmentCollection
528
+ ->addFieldToFilter('shipping_method', array('like' => 'transsmart%\_carrierprofile\_%'))
529
+ ->addFieldToFilter('transsmart_shipmentlocation_id', array('notnull' => true))
530
+ ->addFieldToFilter('transsmart_emailtype_id', array('notnull' => true))
531
+ ->addFieldToFilter('transsmart_incoterm_id', array('notnull' => true))
532
+ ->addFieldToFilter('transsmart_costcenter_id', array('notnull' => true))
533
+ ->addFieldToFilter('transsmart_packages', array('notnull' => true))
534
+ ->addFieldToFilter('transsmart_document_id', array('null' => true));
535
+
536
+ /** @var Transsmart_Shipping_Helper_Shipment $shipmentHelper */
537
+ $shipmentHelper = Mage::helper('transsmart_shipping/shipment');
538
+
539
+ /** @var Mage_Sales_Model_Order_Shipment $_shipment */
540
+ foreach ($shipmentCollection as $_shipment) {
541
+ // set original data manually (because we didn't call object load())
542
+ $_shipment->setOrigData();
543
+
544
+ $shipmentHelper->doExport($_shipment);
545
+ }
546
+
547
+ return $this;
548
+ }
549
+
550
+ /**
551
+ * Convert GMT timestamp (which is used by Magento) to CET timestamp (which is used by Transsmart API).
552
+ * Input and output format: 'YYYY-MM-DD HH:MM:SS'
553
+ *
554
+ * @param string $gmtTimestamp
555
+ * @return string
556
+ * @throws Zend_Date_Exception
557
+ */
558
+ protected function _convertGmtToCet($gmtTimestamp)
559
+ {
560
+ $date = new Zend_Date($gmtTimestamp . ' GMT');
561
+ $date->setTimezone('CET');
562
+ return $date->toString('Y-MM-dd HH:m:s');
563
+ }
564
+
565
+ /**
566
+ * Convert CET timestamp (which is used by Transsmart API) to GMT timestamp (which is used by Magento).
567
+ * Input and output format: 'YYYY-MM-DD HH:MM:SS'
568
+ *
569
+ * @param string $cetTimestamp
570
+ * @return string
571
+ * @throws Zend_Date_Exception
572
+ */
573
+ protected function _convertCetToGmt($cetTimestamp)
574
+ {
575
+ $date = new Zend_Date($cetTimestamp . ' CET');
576
+ $date->setTimezone('GMT');
577
+ return $date->toString('Y-MM-dd HH:m:s');
578
+ }
579
+
580
+ /**
581
+ * Get actual document statuses and tracking URL's since a given timestamp.
582
+ *
583
+ * @param string $sinceTime "YYYY-MM-DD HH:MM:SS"
584
+ * @param string $maxTime Returns the newest timestamp in the results.
585
+ * @return array
586
+ */
587
+ protected function _getShipmentStatuses($sinceTime = null, &$maxTime = null)
588
+ {
589
+ $result = array();
590
+
591
+ if (is_null($sinceTime)) {
592
+ $maxTime = Mage::getModel('core/date')->gmtDate();
593
+ $response = $this->getApiClient()->getDocument();
594
+ foreach ($response as $_item) {
595
+ $result[$_item['Reference']] = array(
596
+ 'Status' => $_item['Status'],
597
+ 'TrackingUrl' => $_item['TrackingUrl']
598
+ );
599
+ }
600
+ }
601
+ else {
602
+ $maxTime = $sinceTime;
603
+ $queryDefinition = array(
604
+ 'Carriers' => array(),
605
+ 'CostCenters' => array(),
606
+ 'SubAccounts' => array(),
607
+ 'DateTimeFrom' => $this->_convertGmtToCet($sinceTime),
608
+ 'DateTimeTo' => $this->_convertGmtToCet(Mage::getModel('core/date')->gmtDate()),
609
+ 'MaxResults' => 100,
610
+ 'IsIncremental' => false
611
+ );
612
+ $response = $this->getApiClient()->getStatus($queryDefinition);
613
+ foreach ($response as $_item) {
614
+ $_timestamp = $sinceTime;
615
+ $_resultItem = array(
616
+ 'Status' => isset($_item['GenericStatusCode']) ? $_item['GenericStatusCode'] : false,
617
+ 'TrackingUrl' => $_item['TrackingUrl']
618
+ );
619
+ foreach ($_item['Statuses'] as $_status) {
620
+ $_eventTime = $this->_convertCetToGmt(sprintf(
621
+ '%04d-%02d-%02d %02d:%02d:%02d',
622
+ (int)substr($_status['EventDate'], 0, 4),
623
+ (int)substr($_status['EventDate'], 4, 2),
624
+ (int)substr($_status['EventDate'], 6, 2),
625
+ (int)substr($_status['EventTime'], 0, 2),
626
+ (int)substr($_status['EventTime'], 2, 2),
627
+ (int)substr($_status['EventTime'], 4, 2)
628
+ ));
629
+ if ($_eventTime > $maxTime) {
630
+ $maxTime = $_eventTime;
631
+ }
632
+ if ($_eventTime >= $_timestamp || empty($_resultItem['Status'])) {
633
+ $_timestamp = $_eventTime;
634
+ $_resultItem['Status'] = $_status['StatusCode'];
635
+ }
636
+ }
637
+ $result[$_item['Reference']] = $_resultItem;
638
+ }
639
+ }
640
+
641
+ return $result;
642
+ }
643
+
644
+ /**
645
+ * @return $this
646
+ */
647
+ protected function updateShipmentStatuses($lastSyncTime)
648
+ {
649
+ $statuses = $this->_getShipmentStatuses($lastSyncTime, $maxTime);
650
+
651
+ /** @var Mage_Sales_Model_Resource_Order_Shipment_Collection $shipmentCollection */
652
+ $shipmentCollection = Mage::getResourceModel('sales/order_shipment_collection')
653
+ ->addFieldToFilter('transsmart_document_id', array('notnull' => true))
654
+ ->addFieldToFilter('increment_id', array('in' => array_keys($statuses)));
655
+
656
+ /** @var Mage_Sales_Model_Order_Shipment $_shipment */
657
+ foreach ($shipmentCollection as $_shipment) {
658
+ // set original data manually (because we didn't call object load())
659
+ $_shipment->setOrigData();
660
+
661
+ $this->syncShipment($_shipment, $statuses[$_shipment->getIncrementId()]);
662
+ }
663
+
664
+ $this->setCreatedAt($maxTime);
665
+
666
+ return $this;
667
+ }
668
+
669
+ /**
670
+ * Fetch actual Transsmart status and track-and-trace URL for a single shipment and update its database record.
671
+ * Returns TRUE if something changed.
672
+ *
673
+ * @param Mage_Sales_Model_Order_Shipment $shipment
674
+ * @param array|null $documentData Optional. Array containing 'Status' and/or 'TrackingUrl' keys
675
+ * @return bool
676
+ */
677
+ public function syncShipment($shipment, $documentData = null)
678
+ {
679
+ $updatedAttributes = array();
680
+
681
+ if (is_null($documentData)) {
682
+ $documentId = $shipment->getTranssmartDocumentId();
683
+ if (!empty($documentId)) {
684
+ $documentData = $this->getApiClient()->getDocument($documentId);
685
+ }
686
+ }
687
+
688
+ if (is_array($documentData)) {
689
+ if (array_key_exists('Status', $documentData)) {
690
+ $value = $documentData['Status'];
691
+ if ($shipment->getData('transsmart_status') != $value) {
692
+ $shipment->setData('transsmart_status', $value);
693
+ $updatedAttributes[] = 'transsmart_status';
694
+ }
695
+ }
696
+
697
+ if (array_key_exists('TrackingUrl', $documentData)) {
698
+ $value = $documentData['TrackingUrl'];
699
+ if ($shipment->getData('transsmart_tracking_url') != $value) {
700
+ $shipment->setData('transsmart_tracking_url', $value);
701
+ $updatedAttributes[] = 'transsmart_tracking_url';
702
+ }
703
+ }
704
+ }
705
+
706
+ if (count($updatedAttributes)) {
707
+ $shipment->getResource()->saveAttribute($shipment, $updatedAttributes);
708
+
709
+ // write log message
710
+ $message = Mage::helper('transsmart_shipping')->__('Shipment #%s updated.', $shipment->getIncrementId());
711
+ foreach ($updatedAttributes as $_attributeCode) {
712
+ $message .= ' ' . Mage::helper('transsmart_shipping')->__(
713
+ 'New %s value: "%s".', $_attributeCode, $shipment->getData($_attributeCode)
714
+ );
715
+ }
716
+ Mage::log($message, Zend_Log::INFO, 'transsmart_shipping.log');
717
+
718
+ return true;
719
+ }
720
+
721
+ return false;
722
+ }
723
+
724
+ /**
725
+ * @return $this
726
+ */
727
+ public function syncShipments()
728
+ {
729
+ $lastSyncTime = $this->getLastSync(self::TYPE_SHIPMENTS);
730
+
731
+ $this->clearInstance();
732
+ $this->setType(self::TYPE_SHIPMENTS)
733
+ ->setStatus(self::STATUS_RUNNING)
734
+ ->setCreatedAt(Mage::getModel('core/date')->gmtDate())
735
+ ->save();
736
+
737
+ $this->updateShipmentStatuses($lastSyncTime);
738
+ $this->exportShipments();
739
+
740
+ $this->setStatus(self::STATUS_FINISHED)
741
+ ->save();
742
+ }
743
+ }
app/code/community/Transsmart/Shipping/controllers/Adminhtml/Transsmart/Shipping/LocationController.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Adminhtml_Transsmart_Shipping_LocationController extends Mage_Adminhtml_Controller_Action
9
+ {
10
+ /**
11
+ * Route to lookup locations
12
+ */
13
+ public function lookupAction()
14
+ {
15
+ $model = Mage::getSingleton('adminhtml/sales_order_create');
16
+ $response = Mage::helper('transsmart_shipping/location')->getLookupResponse($model, $this->getRequest());
17
+
18
+ $this->getResponse()
19
+ ->setHeader('Content-Type', 'application/json')
20
+ ->setBody(Zend_Json_Encoder::encode($response));
21
+ }
22
+
23
+ /**
24
+ * Check if action is allowed for the current user.
25
+ *
26
+ * @return bool
27
+ */
28
+ protected function _isAllowed()
29
+ {
30
+ if ($this->getRequest()->getActionName() == 'lookup') {
31
+ return Mage::getSingleton('admin/session')->isAllowed('admin/system/config/transsmart_shipping');
32
+ }
33
+ return false;
34
+ }
35
+ }
app/code/community/Transsmart/Shipping/controllers/Adminhtml/Transsmart/Shipping/ShipmentController.php ADDED
@@ -0,0 +1,475 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Adminhtml_Transsmart_Shipping_ShipmentController extends Mage_Adminhtml_Controller_Action
9
+ {
10
+ /**
11
+ * Mass Create Shipment Action
12
+ */
13
+ public function massCreateAction()
14
+ {
15
+ if ($this->getRequest()->isPost()) {
16
+ // redirect post request to prevent 'confirm submit' browser message when using back-button
17
+ $orderIds = $this->getRequest()->getPost('order_ids');
18
+ $this->_redirect('*/*/*', array('order_ids' => implode(',', $orderIds)));
19
+ return;
20
+ }
21
+
22
+ // get order ID's from URL
23
+ $orderIds = $this->getRequest()->getParam('order_ids');
24
+ if (is_string($orderIds)) {
25
+ $orderIds = explode(',', $orderIds);
26
+ }
27
+ $orderIds = array_filter($orderIds, 'intval');
28
+
29
+ /** @var Mage_Sales_Model_Resource_Order_Collection $orderCollection */
30
+ $orderCollection = $this->_getMassActionOrderCollection($orderIds);
31
+ if (count($orderCollection) == 0) {
32
+ $this->_getSession()->addError($this->__('No shipments can be created for the selected order(s).'));
33
+ $this->_redirect('*/sales_order');
34
+ return;
35
+ }
36
+
37
+ $this->loadLayout()
38
+ ->_setActiveMenu('sales/order')
39
+ ->_addBreadcrumb(Mage::helper('sales')->__('Sales'), Mage::helper('sales')->__('Sales'))
40
+ ->_addBreadcrumb(Mage::helper('sales')->__('Orders'), Mage::helper('sales')->__('Orders'))
41
+ ->_title(Mage::helper('sales')->__('Sales'))->_title(Mage::helper('sales')->__('Orders'))
42
+ ->_title($this->__('Create New Shipment(s) for Order(s)'));
43
+
44
+ $this->getLayout()->getBlock('sales_shipment_create')->setOrderCollection($orderCollection);
45
+ $this->renderLayout();
46
+ }
47
+
48
+ /**
49
+ * Mass Create Shipment Save Action
50
+ */
51
+ public function massCreateSaveAction()
52
+ {
53
+ $orderQty = $this->getRequest()->getPost('order_qty');
54
+ $data = $this->getRequest()->getPost('shipment');
55
+
56
+ /** @var Mage_Sales_Model_Resource_Order_Collection $orderCollection */
57
+ $orderCollection = $this->_getMassActionOrderCollection(array_keys($orderQty));
58
+
59
+ // check if qty's have changed since the form was loaded
60
+ $totalQty = 0.0;
61
+ foreach ($orderCollection as $_order) {
62
+ foreach ($_order->getAllItems() as $_item) {
63
+ if ($_item->getQtyToShip() > 0 && !$_item->getIsVirtual() && !$_item->getLockedDoShip()) {
64
+ $totalQty += $_item->getQtyToShip();
65
+ }
66
+ }
67
+ }
68
+ if (count($orderCollection) != count($orderQty) || $totalQty != array_sum($orderQty)) {
69
+ $this->_getSession()->addWarning($this->__('One or more selected orders have changed. Please confirm.'));
70
+ $this->_redirect('*/*/massCreate', array('order_ids' => implode(',', $orderCollection->getAllIds())));
71
+ return;
72
+ }
73
+
74
+ // create shipments
75
+ $successCount = 0; $errorCount = 0;
76
+ foreach ($orderCollection as $_order) {
77
+ try {
78
+ // create and register shipment
79
+ $_shipment = Mage::getModel('sales/service_order', $_order)->prepareShipment();
80
+ $_shipment->register();
81
+
82
+ // add comment (notification)
83
+ $_comment = '';
84
+ if (!empty($data['comment_text'])) {
85
+ $_shipment->addComment(
86
+ $data['comment_text'],
87
+ !empty($data['comment_customer_notify'])
88
+ );
89
+ if (!empty($data['comment_customer_notify'])) {
90
+ $_comment = $data['comment_text'];
91
+ }
92
+ }
93
+ if (!empty($data['send_email'])) {
94
+ $_shipment->setEmailSent(true);
95
+ }
96
+
97
+ // update order
98
+ $_order->setCustomerNoteNotify(!empty($data['send_email']))
99
+ ->setIsInProcess(true);
100
+
101
+ // save changes to the shipment and order into database
102
+ Mage::getModel('core/resource_transaction')
103
+ ->addObject($_shipment)
104
+ ->addObject($_order)
105
+ ->save();
106
+
107
+ $_shipment->sendEmail(!empty($data['send_email']), $_comment);
108
+
109
+ $successCount++;
110
+ }
111
+ catch (Mage_Core_Exception $exception) {
112
+ $this->_getSession()->addError(
113
+ $this->__(
114
+ 'Error creating shipment for order #%s: %s',
115
+ $_order->getIncrementId(),
116
+ $exception->getMessage()
117
+ )
118
+ );
119
+ $errorCount++;
120
+ }
121
+ }
122
+ if ($successCount > 0) {
123
+ $this->_getSession()->addSuccess($this->__('Successfully created %s shipment(s)!', $successCount));
124
+ }
125
+
126
+ // redirect user
127
+ if ($errorCount > 0) {
128
+ $this->_redirect('*/*/massCreate', array('order_ids' => implode(',', $orderCollection->getAllIds())));
129
+ }
130
+ else {
131
+ $this->_redirect('*/sales_order');
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Get selection of orders for which shipments may to be created. Used by massCreateAction and massCreateSaveAction.
137
+ *
138
+ * @param array $orderIds
139
+ * @return Mage_Sales_Model_Resource_Order_Collection
140
+ */
141
+ protected function _getMassActionOrderCollection($orderIds)
142
+ {
143
+ /** @var Mage_Sales_Model_Resource_Order_Collection $orderCollection */
144
+ $orderCollection = Mage::getResourceModel('sales/order_collection')
145
+ ->addFieldToFilter('entity_id', array('in' => $orderIds));
146
+
147
+ Mage::dispatchEvent('transsmart_shipping_shipment_masscreate_prepare_collection', array(
148
+ 'collection' => $orderCollection
149
+ ));
150
+
151
+ // remove orders that cannot be shipped
152
+ foreach ($orderCollection as $_key => $_order) {
153
+ if ($_order->getForcedDoShipmentWithInvoice() || !$_order->canShip()) {
154
+ $orderCollection->removeItemByKey($_key);
155
+ }
156
+ }
157
+
158
+ return $orderCollection;
159
+ }
160
+
161
+ /**
162
+ * Book and print selected Transsmart shipments.
163
+ */
164
+ public function massBookAndPrintAction()
165
+ {
166
+ $shipmentCollection = $this->_getMassActionShipmentCollection();
167
+ $shipmentHelper = Mage::helper('transsmart_shipping/shipment');
168
+
169
+ $totalCount = 0;
170
+ $successCount = 0;
171
+ if ($shipmentCollection) {
172
+ /** @var Mage_Sales_Model_Order_Shipment $_shipment */
173
+ foreach ($shipmentCollection as $_shipment) {
174
+ if (!$_shipment->getTranssmartDocumentId()) {
175
+ continue;
176
+ }
177
+ $totalCount++;
178
+
179
+ try {
180
+ $shipmentHelper->doBookAndPrint($_shipment);
181
+ $successCount++;
182
+ }
183
+ catch (Mage_Core_Exception $_exception) {
184
+ $this->_getSession()->addError(
185
+ $this->__(
186
+ 'Shipment #%s for order #%s could not be booked and printed: %s',
187
+ $_shipment->getIncrementId(),
188
+ $_shipment->getOrder()->getIncrementId(),
189
+ $_exception->getMessage()
190
+ )
191
+ );
192
+ }
193
+ }
194
+ }
195
+
196
+ if ($totalCount == 0) {
197
+ if ($this->_isMassActionFromOrders()) {
198
+ $this->_getSession()->addError(
199
+ $this->__('There are no Transsmart documents related to selected order(s).')
200
+ );
201
+ }
202
+ else {
203
+ $this->_getSession()->addError(
204
+ $this->__('There are no Transsmart documents related to selected shipment(s).')
205
+ );
206
+ }
207
+ }
208
+ elseif ($successCount) {
209
+ $this->_getSession()->addSuccess(
210
+ $this->__('Successfully booked and printed %s Transsmart shipments.', $successCount)
211
+ );
212
+ }
213
+
214
+ if ($this->_isMassActionFromOrders()) {
215
+ $this->_redirect('*/sales_order/index');
216
+ }
217
+ else {
218
+ $this->_redirect('*/sales_order_shipment/index');
219
+ }
220
+ }
221
+
222
+ /**
223
+ * Book all selected Transsmart shipments.
224
+ */
225
+ public function massBookingAction()
226
+ {
227
+ $shipmentCollection = $this->_getMassActionShipmentCollection();
228
+ $shipmentHelper = Mage::helper('transsmart_shipping/shipment');
229
+
230
+ $totalCount = 0;
231
+ $successCount = 0;
232
+ if ($shipmentCollection) {
233
+ /** @var Mage_Sales_Model_Order_Shipment $_shipment */
234
+ foreach ($shipmentCollection as $_shipment) {
235
+ if (!$_shipment->getTranssmartDocumentId()) {
236
+ continue;
237
+ }
238
+
239
+ try {
240
+ $totalCount++;
241
+ $shipmentHelper->doBooking($_shipment);
242
+ $successCount++;
243
+ }
244
+ catch (Mage_Core_Exception $_exception) {
245
+ $this->_getSession()->addError(
246
+ $this->__(
247
+ 'Shipment #%s for order #%s could not be booked: %s',
248
+ $_shipment->getIncrementId(),
249
+ $_shipment->getOrder()->getIncrementId(),
250
+ $_exception->getMessage()
251
+ )
252
+ );
253
+ }
254
+ }
255
+ }
256
+
257
+ if ($totalCount == 0) {
258
+ if ($this->_isMassActionFromOrders()) {
259
+ $this->_getSession()->addError(
260
+ $this->__('There are no Transsmart documents related to selected order(s).')
261
+ );
262
+ }
263
+ else {
264
+ $this->_getSession()->addError(
265
+ $this->__('There are no Transsmart documents related to selected shipment(s).')
266
+ );
267
+ }
268
+ }
269
+ elseif ($successCount) {
270
+ $this->_getSession()->addSuccess(
271
+ $this->__('Successfully booked %s Transsmart shipments.', $successCount)
272
+ );
273
+ }
274
+
275
+ if ($this->_isMassActionFromOrders()) {
276
+ $this->_redirect('*/sales_order/index');
277
+ }
278
+ else {
279
+ $this->_redirect('*/sales_order_shipment/index');
280
+ }
281
+ }
282
+
283
+ /**
284
+ * Print (create labels for) all selected Transsmart shipments.
285
+ * In addition, this also works for non-Transsmart shipments, by calling getShippingLabel.
286
+ * The combined PDF document with all shipping labels will be downloaded to user browser.
287
+ * @see Mage_Adminhtml_Sales_Order_ShipmentController::massPrintShippingLabelAction
288
+ */
289
+ public function massLabelAction()
290
+ {
291
+ $shipmentCollection = $this->_getMassActionShipmentCollection();
292
+ $shipmentHelper = Mage::helper('transsmart_shipping/shipment');
293
+
294
+ $pdfLabels = array();
295
+ $totalCount = 0;
296
+ $successCount = 0;
297
+ if ($shipmentCollection) {
298
+ /** @var Mage_Sales_Model_Order_Shipment $_shipment */
299
+ foreach ($shipmentCollection as $_shipment) {
300
+ // print Transsmart shipping labels
301
+ if ($_shipment->getTranssmartDocumentId()) {
302
+ try {
303
+ $totalCount++;
304
+ $shipmentHelper->doLabel($_shipment);
305
+ $successCount++;
306
+ }
307
+ catch (Mage_Core_Exception $_exception) {
308
+ $this->_getSession()->addError(
309
+ $this->__(
310
+ 'Shipment #%s for order #%s could not be printed: %s',
311
+ $_shipment->getIncrementId(),
312
+ $_shipment->getOrder()->getIncrementId(),
313
+ $_exception->getMessage()
314
+ )
315
+ );
316
+ }
317
+ }
318
+
319
+ // get original Magento shipping labels
320
+ $_labelContent = $_shipment->getShippingLabel();
321
+ if ($_labelContent) {
322
+ $totalCount++;
323
+ $pdfLabels[] = $_labelContent;
324
+ }
325
+ }
326
+ }
327
+
328
+ if ($totalCount == 0) {
329
+ if ($this->_isMassActionFromOrders()) {
330
+ $this->_getSession()->addError(
331
+ $this->__('There are no Transsmart documents or shipping labels related to selected order(s).')
332
+ );
333
+ }
334
+ else {
335
+ $this->_getSession()->addError(
336
+ $this->__('There are no Transsmart documents or shipping labels related to selected shipment(s).')
337
+ );
338
+ }
339
+ }
340
+ elseif ($successCount) {
341
+ $this->_getSession()->addSuccess(
342
+ $this->__('Successfully printed %s Transsmart shipments.', $successCount)
343
+ );
344
+ }
345
+
346
+ // process Magento shipping labels
347
+ if (!empty($pdfLabels)) {
348
+ $outputPdf = $this->_combineLabelsPdf($pdfLabels);
349
+ $this->_prepareDownloadResponse('ShippingLabels.pdf', $outputPdf, 'application/pdf');
350
+ return;
351
+ }
352
+
353
+ if ($this->_isMassActionFromOrders()) {
354
+ $this->_redirect('*/sales_order/index');
355
+ }
356
+ else {
357
+ $this->_redirect('*/sales_order_shipment/index');
358
+ }
359
+ }
360
+
361
+ /**
362
+ * Get the shipments to which the mass action should be applied, or NULL if none are selected.
363
+ *
364
+ * @return Mage_Sales_Model_Resource_Order_Shipment_Collection|null
365
+ */
366
+ protected function _getMassActionShipmentCollection()
367
+ {
368
+ $request = $this->getRequest();
369
+
370
+ $shipmentCollection = null;
371
+ switch ($request->getParam('massaction_prepare_key')) {
372
+ case 'shipment_ids':
373
+ $ids = $request->getParam('shipment_ids');
374
+ array_filter($ids, 'intval');
375
+ if (!empty($ids)) {
376
+ $shipmentCollection = Mage::getResourceModel('sales/order_shipment_collection')
377
+ ->addFieldToFilter('entity_id', array('in' => $ids));
378
+ }
379
+ break;
380
+
381
+ case 'order_ids':
382
+ $ids = $request->getParam('order_ids');
383
+ array_filter($ids, 'intval');
384
+ if (!empty($ids)) {
385
+ $shipmentCollection = Mage::getResourceModel('sales/order_shipment_collection')
386
+ ->setOrderFilter(array('in' => $ids));
387
+ }
388
+ break;
389
+ }
390
+
391
+ return $shipmentCollection;
392
+ }
393
+
394
+ /**
395
+ * Return TRUE if the mass action should redirect back to the orders grid, or FALSE for the shipments grid.
396
+ *
397
+ * @return bool
398
+ */
399
+ protected function _isMassActionFromOrders()
400
+ {
401
+ $ids = $this->getRequest()->getParam('order_ids');
402
+ $fromOrders = !empty($ids);
403
+ return $fromOrders;
404
+ }
405
+
406
+ /**
407
+ * Combine array of labels as instance PDF
408
+ *
409
+ * @see Mage_Adminhtml_Sales_Order_ShipmentController::_combineLabelsPdf
410
+ * @param array $labelsContent
411
+ * @return Zend_Pdf
412
+ */
413
+ protected function _combineLabelsPdf(array $labelsContent)
414
+ {
415
+ $outputPdf = new Zend_Pdf();
416
+ foreach ($labelsContent as $_content) {
417
+ if (stripos($_content, '%PDF-') !== false) {
418
+ if (count($labelsContent) == 1) {
419
+ // only one PDF, no need to combine so just return it
420
+ return $_content;
421
+ }
422
+
423
+ $_contentPdf = Zend_Pdf::parse($_content);
424
+ foreach ($_contentPdf->pages as $_page) {
425
+ $outputPdf->pages[] = clone $_page;
426
+ }
427
+ }
428
+ else {
429
+ $_page = $this->_createPdfPageFromImageString($_content);
430
+ if ($_page) {
431
+ $outputPdf->pages[] = $_page;
432
+ }
433
+ }
434
+ }
435
+ return $outputPdf->render();
436
+ }
437
+
438
+ /**
439
+ * Create Zend_Pdf_Page instance with image from $imageString. Supports JPEG, PNG, GIF, WBMP, and GD2 formats.
440
+ *
441
+ * @see Mage_Adminhtml_Sales_Order_ShipmentController::_createPdfPageFromImageString
442
+ * @param string $imageString
443
+ * @return Zend_Pdf_Page|bool
444
+ */
445
+ protected function _createPdfPageFromImageString($imageString)
446
+ {
447
+ $image = imagecreatefromstring($imageString);
448
+ if (!$image) {
449
+ return false;
450
+ }
451
+
452
+ $xSize = imagesx($image);
453
+ $ySize = imagesy($image);
454
+ $page = new Zend_Pdf_Page($xSize, $ySize);
455
+
456
+ imageinterlace($image, 0);
457
+ $tmpFileName = sys_get_temp_dir() . DS . 'shipping_labels_' . uniqid(mt_rand()) . time() . '.png';
458
+ imagepng($image, $tmpFileName);
459
+ $pdfImage = Zend_Pdf_Image::imageWithPath($tmpFileName);
460
+ $page->drawImage($pdfImage, 0, 0, $xSize, $ySize);
461
+ unlink($tmpFileName);
462
+
463
+ return $page;
464
+ }
465
+
466
+ /**
467
+ * Check if action is allowed for the current user.
468
+ *
469
+ * @return bool
470
+ */
471
+ protected function _isAllowed()
472
+ {
473
+ return Mage::getSingleton('admin/session')->isAllowed('sales/shipment');
474
+ }
475
+ }
app/code/community/Transsmart/Shipping/controllers/Adminhtml/TranssmartController.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_Adminhtml_TranssmartController extends Mage_Adminhtml_Controller_Action
9
+ {
10
+ /**
11
+ * Fetch the base data from Transsmart.
12
+ */
13
+ public function fetchAction()
14
+ {
15
+ $error = false;
16
+ try {
17
+ Mage::getModel('transsmart_shipping/sync')->syncBaseData();
18
+ }
19
+ catch (Mage_Core_Exception $exception) {
20
+ $error = $exception->getMessage();
21
+ }
22
+ catch (Exception $exception) {
23
+ Mage::logException($exception);
24
+ $error = Mage::helper('transsmart_shipping')->__('Unknown error');
25
+ }
26
+
27
+ /** @var Transsmart_Shipping_Block_Adminhtml_System_Config_Form_Field_Fetch $block */
28
+ $block = $this->getLayout()->createBlock('transsmart_shipping/adminhtml_system_config_form_field_fetch');
29
+
30
+ $element = new Varien_Data_Form_Element_Text(array(
31
+ 'html_id' => 'transsmart_shipping_fetch'
32
+ ));
33
+
34
+ if ($error) {
35
+ $block->setError($error);
36
+ }
37
+
38
+ $this->getResponse()->setBody($block->render($element));
39
+ }
40
+
41
+ /**
42
+ * Check if action is allowed for the current user.
43
+ *
44
+ * @return bool
45
+ */
46
+ protected function _isAllowed()
47
+ {
48
+ if ($this->getRequest()->getActionName() == 'fetch') {
49
+ return Mage::getSingleton('admin/session')->isAllowed('admin/system/config/transsmart_shipping');
50
+ }
51
+ return false;
52
+ }
53
+ }
app/code/community/Transsmart/Shipping/controllers/LocationController.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ class Transsmart_Shipping_LocationController extends Mage_Core_Controller_Front_Action
9
+ {
10
+ /**
11
+ * Route to lookup locations
12
+ */
13
+ public function lookupAction()
14
+ {
15
+ $model = Mage::getSingleton('checkout/cart');
16
+ $response = Mage::helper('transsmart_shipping/location')->getLookupResponse($model, $this->getRequest());
17
+
18
+ $this->getResponse()
19
+ ->setHeader('Content-Type', 'application/json')
20
+ ->setBody(Zend_Json_Encoder::encode($response));
21
+ }
22
+ }
app/code/community/Transsmart/Shipping/etc/adminhtml.xml ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ -->
9
+ <config>
10
+ <acl>
11
+ <resources>
12
+ <admin>
13
+ <children>
14
+ <system>
15
+ <children>
16
+ <config>
17
+ <children>
18
+ <transsmart_shipping translate="title">
19
+ <title>Transsmart Shipping Settings</title>
20
+ <sort_order>315</sort_order>
21
+ </transsmart_shipping>
22
+ <transsmart_carrier_profiles translate="title">
23
+ <title>Transsmart Carrier Profiles</title>
24
+ <sort_order>316</sort_order>
25
+ </transsmart_carrier_profiles>
26
+ </children>
27
+ </config>
28
+ </children>
29
+ </system>
30
+ </children>
31
+ </admin>
32
+ </resources>
33
+ </acl>
34
+ </config>
app/code/community/Transsmart/Shipping/etc/config.xml ADDED
@@ -0,0 +1,302 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ -->
9
+ <config>
10
+ <modules>
11
+ <Transsmart_Shipping>
12
+ <version>1.0.0</version>
13
+ </Transsmart_Shipping>
14
+ </modules>
15
+ <global>
16
+ <blocks>
17
+ <transsmart_shipping>
18
+ <class>Transsmart_Shipping_Block</class>
19
+ </transsmart_shipping>
20
+ <adminhtml>
21
+ <rewrite>
22
+ <sales_order_grid>Transsmart_Shipping_Block_Adminhtml_Sales_Order_Grid</sales_order_grid>
23
+ <sales_order_view_tab_shipments>Transsmart_Shipping_Block_Adminhtml_Sales_Order_View_Tab_Shipments</sales_order_view_tab_shipments>
24
+ <sales_shipment_grid>Transsmart_Shipping_Block_Adminhtml_Sales_Shipment_Grid</sales_shipment_grid>
25
+ </rewrite>
26
+ </adminhtml>
27
+ </blocks>
28
+ <helpers>
29
+ <transsmart_shipping>
30
+ <class>Transsmart_Shipping_Helper</class>
31
+ </transsmart_shipping>
32
+ </helpers>
33
+ <models>
34
+ <transsmart_shipping>
35
+ <class>Transsmart_Shipping_Model</class>
36
+ <resourceModel>transsmart_shipping_resource</resourceModel>
37
+ </transsmart_shipping>
38
+ <transsmart_shipping_resource>
39
+ <class>Transsmart_Shipping_Model_Resource</class>
40
+ <entities>
41
+ <sync>
42
+ <table>transsmart_sync</table>
43
+ </sync>
44
+ <carrier>
45
+ <table>transsmart_carrier</table>
46
+ </carrier>
47
+ <servicelevel_time>
48
+ <table>transsmart_servicelevel_time</table>
49
+ </servicelevel_time>
50
+ <servicelevel_other>
51
+ <table>transsmart_servicelevel_other</table>
52
+ </servicelevel_other>
53
+ <carrierprofile>
54
+ <table>transsmart_carrierprofile</table>
55
+ </carrierprofile>
56
+ <shipmentlocation>
57
+ <table>transsmart_shipmentlocation</table>
58
+ </shipmentlocation>
59
+ <emailtype>
60
+ <table>transsmart_emailtype</table>
61
+ </emailtype>
62
+ <packagetype>
63
+ <table>transsmart_packagetype</table>
64
+ </packagetype>
65
+ <incoterm>
66
+ <table>transsmart_incoterm</table>
67
+ </incoterm>
68
+ <costcenter>
69
+ <table>transsmart_costcenter</table>
70
+ </costcenter>
71
+ </entities>
72
+ </transsmart_shipping_resource>
73
+ <sales_resource>
74
+ <rewrite>
75
+ <order>Transsmart_Shipping_Model_Sales_Resource_Order</order>
76
+ </rewrite>
77
+ </sales_resource>
78
+ </models>
79
+ <resources>
80
+ <transsmart_shipping_setup>
81
+ <setup>
82
+ <module>Transsmart_Shipping</module>
83
+ </setup>
84
+ </transsmart_shipping_setup>
85
+ </resources>
86
+ <events>
87
+ <sales_order_shipment_save_before>
88
+ <observers>
89
+ <transsmart_shipping>
90
+ <class>transsmart_shipping/observer</class>
91
+ <method>salesOrderShipmentSaveBefore</method>
92
+ </transsmart_shipping>
93
+ </observers>
94
+ </sales_order_shipment_save_before>
95
+ <sales_order_shipment_resource_save_attribute_after>
96
+ <observers>
97
+ <transsmart_shipping>
98
+ <class>transsmart_shipping/observer</class>
99
+ <method>salesOrderShipmentResourceSaveAttributeAfter</method>
100
+ </transsmart_shipping>
101
+ </observers>
102
+ </sales_order_shipment_resource_save_attribute_after>
103
+ <checkout_controller_onepage_save_shipping_method>
104
+ <observers>
105
+ <transsmart_shipping>
106
+ <class>transsmart_shipping/observer</class>
107
+ <method>checkoutControllerOnepageSaveShippingMethod</method>
108
+ </transsmart_shipping>
109
+ </observers>
110
+ </checkout_controller_onepage_save_shipping_method>
111
+ <controller_action_predispatch_gomage_checkout>
112
+ <observers>
113
+ <transsmart_shipping>
114
+ <class>transsmart_shipping/observer</class>
115
+ <method>controllerActionPredispatchGomageCheckout</method>
116
+ </transsmart_shipping>
117
+ </observers>
118
+ </controller_action_predispatch_gomage_checkout>
119
+ <sales_convert_quote_to_order>
120
+ <observers>
121
+ <transsmart_shipping>
122
+ <class>transsmart_shipping/observer</class>
123
+ <method>salesConvertQuoteToOrder</method>
124
+ </transsmart_shipping>
125
+ </observers>
126
+ </sales_convert_quote_to_order>
127
+ <checkout_type_onepage_save_order>
128
+ <observers>
129
+ <transsmart_shipping>
130
+ <class>transsmart_shipping/observer</class>
131
+ <method>checkoutTypeOnepageSaveOrder</method>
132
+ </transsmart_shipping>
133
+ </observers>
134
+ </checkout_type_onepage_save_order>
135
+ <sales_convert_order_to_quote>
136
+ <observers>
137
+ <transsmart_shipping>
138
+ <class>transsmart_shipping/observer</class>
139
+ <method>salesConvertOrderToQuote</method>
140
+ </transsmart_shipping>
141
+ </observers>
142
+ </sales_convert_order_to_quote>
143
+ <transsmart_shipping_shipment_label_printed>
144
+ <observers>
145
+ <transsmart_shipping>
146
+ <class>transsmart_shipping/observer</class>
147
+ <method>transsmartShippingShipmentLabelPrinted</method>
148
+ </transsmart_shipping>
149
+ </observers>
150
+ </transsmart_shipping_shipment_label_printed>
151
+ </events>
152
+ <fieldsets>
153
+ <sales_convert_quote_address>
154
+ <transsmart_servicepoint_id>
155
+ <to_order_address>*</to_order_address>
156
+ </transsmart_servicepoint_id>
157
+ </sales_convert_quote_address>
158
+ <sales_convert_order_address>
159
+ <transsmart_servicepoint_id>
160
+ <to_quote_address>*</to_quote_address>
161
+ </transsmart_servicepoint_id>
162
+ </sales_convert_order_address>
163
+ </fieldsets>
164
+ </global>
165
+ <admin>
166
+ <routers>
167
+ <adminhtml>
168
+ <args>
169
+ <modules>
170
+ <transsmart_shipping before="Mage_Adminhtml">Transsmart_Shipping_Adminhtml</transsmart_shipping>
171
+ </modules>
172
+ </args>
173
+ </adminhtml>
174
+ </routers>
175
+ </admin>
176
+ <adminhtml>
177
+ <translate>
178
+ <modules>
179
+ <Mage_Adminhtml>
180
+ <files>
181
+ <transsmart_shipping>Transsmart_Shipping.csv</transsmart_shipping>
182
+ </files>
183
+ </Mage_Adminhtml>
184
+ </modules>
185
+ </translate>
186
+ <layout>
187
+ <updates>
188
+ <transsmart_shipping>
189
+ <file>transsmart_shipping.xml</file>
190
+ </transsmart_shipping>
191
+ </updates>
192
+ </layout>
193
+ <events>
194
+ <adminhtml_init_system_config>
195
+ <observers>
196
+ <transsmart_shipping>
197
+ <class>transsmart_shipping/adminhtml_observer</class>
198
+ <method>adminhtmlInitSystemConfig</method>
199
+ </transsmart_shipping>
200
+ </observers>
201
+ </adminhtml_init_system_config>
202
+ <adminhtml_sales_order_create_process_data>
203
+ <observers>
204
+ <transsmart_shipping>
205
+ <class>transsmart_shipping/adminhtml_observer</class>
206
+ <method>adminhtmlSalesOrderCreateProcessData</method>
207
+ </transsmart_shipping>
208
+ </observers>
209
+ </adminhtml_sales_order_create_process_data>
210
+ <adminhtml_block_html_before>
211
+ <observers>
212
+ <transsmart_shipping>
213
+ <class>transsmart_shipping/adminhtml_observer</class>
214
+ <method>adminhtmlBlockHtmlBefore</method>
215
+ </transsmart_shipping>
216
+ </observers>
217
+ </adminhtml_block_html_before>
218
+ <sales_order_shipment_save_before>
219
+ <observers>
220
+ <transsmart_shipping>
221
+ <class>transsmart_shipping/adminhtml_observer</class>
222
+ <method>salesOrderShipmentSaveBefore</method>
223
+ </transsmart_shipping>
224
+ </observers>
225
+ </sales_order_shipment_save_before>
226
+ <sales_order_shipment_save_after>
227
+ <observers>
228
+ <transsmart_shipping>
229
+ <class>transsmart_shipping/adminhtml_observer</class>
230
+ <method>salesOrderShipmentSaveAfter</method>
231
+ </transsmart_shipping>
232
+ </observers>
233
+ </sales_order_shipment_save_after>
234
+ </events>
235
+ </adminhtml>
236
+ <frontend>
237
+ <translate>
238
+ <modules>
239
+ <Transsmart_Shipping>
240
+ <files>
241
+ <default>Transsmart_Shipping.csv</default>
242
+ </files>
243
+ </Transsmart_Shipping>
244
+ </modules>
245
+ </translate>
246
+ <layout>
247
+ <updates>
248
+ <transsmart_shipping>
249
+ <file>transsmart_shipping.xml</file>
250
+ </transsmart_shipping>
251
+ </updates>
252
+ </layout>
253
+ <routers>
254
+ <transsmart_shipping>
255
+ <use>standard</use>
256
+ <args>
257
+ <module>Transsmart_Shipping</module>
258
+ <frontName>transsmart_shipping</frontName>
259
+ </args>
260
+ </transsmart_shipping>
261
+ </routers>
262
+ </frontend>
263
+ <default>
264
+ <carriers>
265
+ <transsmartdelivery>
266
+ <active>1</active>
267
+ <model>transsmart_shipping/shipping_carrier_delivery</model>
268
+ <title backend_model="transsmart_shipping/adminhtml_system_config_backend_localized">Delivery</title>
269
+ <sort_order>10</sort_order>
270
+ </transsmartdelivery>
271
+ <transsmartpickup>
272
+ <active>1</active>
273
+ <model>transsmart_shipping/shipping_carrier_pickup</model>
274
+ <title backend_model="transsmart_shipping/adminhtml_system_config_backend_localized">Pickup</title>
275
+ <sort_order>20</sort_order>
276
+ </transsmartpickup>
277
+ </carriers>
278
+ <transsmart_shipping>
279
+ <connection>
280
+ <environment>1</environment>
281
+ </connection>
282
+ <mapping>
283
+ <street>1</street>
284
+ <streetno>0</streetno>
285
+ <street2>2</street2>
286
+ <country_of_origin>country_of_manufacture</country_of_origin>
287
+ </mapping>
288
+ </transsmart_shipping>
289
+ </default>
290
+ <crontab>
291
+ <jobs>
292
+ <transsmart_shipping_sync_shipments>
293
+ <schedule>
294
+ <cron_expr>*/5 * * * *</cron_expr>
295
+ </schedule>
296
+ <run>
297
+ <model>transsmart_shipping/sync::syncShipments</model>
298
+ </run>
299
+ </transsmart_shipping_sync_shipments>
300
+ </jobs>
301
+ </crontab>
302
+ </config>
app/code/community/Transsmart/Shipping/etc/jstranslator.xml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ -->
9
+ <jstranslator>
10
+ <tss-ls-error translate="message" module="transsmart_shipping">
11
+ <message>Error loading pickup location selector. Please try again.</message>
12
+ </tss-ls-error>
13
+ <tss-ls-search-error translate="message" module="transsmart_shipping">
14
+ <message>Search did not succeed. Please try again.</message>
15
+ </tss-ls-search-error>
16
+ <tss-ls-select-location translate="message" module="transsmart_shipping">
17
+ <message>Select pickup location</message>
18
+ </tss-ls-select-location>
19
+ <tss-ls-validate-pickup-location-error translate="message" module="transsmart_shipping">
20
+ <message>A pickup location has to be selected</message>
21
+ </tss-ls-validate-pickup-location-error>
22
+ <tss-ls-openinghours translate="message" module="transsmart_shipping">
23
+ <message>Opening hours:</message>
24
+ </tss-ls-openinghours>
25
+ </jstranslator>
app/code/community/Transsmart/Shipping/etc/system.xml ADDED
@@ -0,0 +1,321 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ -->
9
+ <config>
10
+ <sections>
11
+ <transsmart_shipping translate="label">
12
+ <label>Transsmart Shipping</label>
13
+ <tab>sales</tab>
14
+ <sort_order>325</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>1</show_in_store>
18
+ <groups>
19
+ <versioninfo>
20
+ <frontend_model>transsmart_shipping/adminhtml_system_config_form_fieldset_versioninfo</frontend_model>
21
+ <sort_order>10</sort_order>
22
+ <show_in_default>1</show_in_default>
23
+ <show_in_website>1</show_in_website>
24
+ <show_in_store>1</show_in_store>
25
+ </versioninfo>
26
+ <connection translate="label">
27
+ <label>Connection Details</label>
28
+ <sort_order>20</sort_order>
29
+ <show_in_default>1</show_in_default>
30
+ <show_in_website>0</show_in_website>
31
+ <show_in_store>0</show_in_store>
32
+ <expanded>1</expanded>
33
+ <fields>
34
+ <username translate="label">
35
+ <label>Username</label>
36
+ <sort_order>10</sort_order>
37
+ <frontend_type>text</frontend_type>
38
+ <validate>validate-email</validate>
39
+ <show_in_default>1</show_in_default>
40
+ <show_in_website>0</show_in_website>
41
+ <show_in_store>0</show_in_store>
42
+ </username>
43
+ <password translate="label">
44
+ <label>Password</label>
45
+ <sort_order>20</sort_order>
46
+ <frontend_type>text</frontend_type>
47
+ <show_in_default>1</show_in_default>
48
+ <show_in_website>0</show_in_website>
49
+ <show_in_store>0</show_in_store>
50
+ </password>
51
+ <environment translate="label">
52
+ <label>Environment</label>
53
+ <sort_order>30</sort_order>
54
+ <frontend_type>select</frontend_type>
55
+ <source_model>transsmart_shipping/adminhtml_system_config_source_environment</source_model>
56
+ <show_in_default>1</show_in_default>
57
+ <show_in_website>0</show_in_website>
58
+ <show_in_store>0</show_in_store>
59
+ </environment>
60
+ <fetch translate="label">
61
+ <sort_order>40</sort_order>
62
+ <frontend_model>transsmart_shipping/adminhtml_system_config_form_field_fetch</frontend_model>
63
+ <show_in_default>1</show_in_default>
64
+ <show_in_website>0</show_in_website>
65
+ <show_in_store>0</show_in_store>
66
+ </fetch>
67
+ </fields>
68
+ </connection>
69
+ <print>
70
+ <label>Printing</label>
71
+ <sort_order>30</sort_order>
72
+ <show_in_default>1</show_in_default>
73
+ <show_in_website>1</show_in_website>
74
+ <show_in_store>1</show_in_store>
75
+ <expanded>1</expanded>
76
+ <fields>
77
+ <qzhost translate="label">
78
+ <label>QZ Host</label>
79
+ <sort_order>10</sort_order>
80
+ <frontend_type>text</frontend_type>
81
+ <show_in_default>1</show_in_default>
82
+ <show_in_website>1</show_in_website>
83
+ <show_in_store>1</show_in_store>
84
+ </qzhost>
85
+ <selectedprinter translate="label">
86
+ <label>Selected Printer</label>
87
+ <sort_order>20</sort_order>
88
+ <frontend_type>text</frontend_type>
89
+ <show_in_default>1</show_in_default>
90
+ <show_in_website>1</show_in_website>
91
+ <show_in_store>1</show_in_store>
92
+ </selectedprinter>
93
+ </fields>
94
+ </print>
95
+ <default_shipment translate="label">
96
+ <label>Default Shipment Properties</label>
97
+ <comment>These properties are applied to a new shipment by default, and can be configured per storeview.</comment>
98
+ <sort_order>40</sort_order>
99
+ <show_in_default>1</show_in_default>
100
+ <show_in_website>1</show_in_website>
101
+ <show_in_store>1</show_in_store>
102
+ <expanded>1</expanded>
103
+ <fields>
104
+ <carrierprofile translate="label">
105
+ <label>Carrier Profile</label>
106
+ <sort_order>10</sort_order>
107
+ <frontend_type>select</frontend_type>
108
+ <source_model>transsmart_shipping/adminhtml_system_config_source_basedata_carrierprofile</source_model>
109
+ <show_in_default>1</show_in_default>
110
+ <show_in_website>1</show_in_website>
111
+ <show_in_store>1</show_in_store>
112
+ </carrierprofile>
113
+ <shipmentlocation translate="label">
114
+ <label>Shipment Location</label>
115
+ <sort_order>20</sort_order>
116
+ <frontend_type>select</frontend_type>
117
+ <source_model>transsmart_shipping/adminhtml_system_config_source_basedata_shipmentlocation</source_model>
118
+ <show_in_default>1</show_in_default>
119
+ <show_in_website>1</show_in_website>
120
+ <show_in_store>1</show_in_store>
121
+ </shipmentlocation>
122
+ <emailtype translate="label">
123
+ <label>Email Type</label>
124
+ <sort_order>30</sort_order>
125
+ <frontend_type>select</frontend_type>
126
+ <source_model>transsmart_shipping/adminhtml_system_config_source_basedata_emailtype</source_model>
127
+ <show_in_default>1</show_in_default>
128
+ <show_in_website>1</show_in_website>
129
+ <show_in_store>1</show_in_store>
130
+ </emailtype>
131
+ <incoterm translate="label">
132
+ <label>Incoterm</label>
133
+ <sort_order>40</sort_order>
134
+ <frontend_type>select</frontend_type>
135
+ <source_model>transsmart_shipping/adminhtml_system_config_source_basedata_incoterm</source_model>
136
+ <show_in_default>1</show_in_default>
137
+ <show_in_website>1</show_in_website>
138
+ <show_in_store>1</show_in_store>
139
+ </incoterm>
140
+ <costcenter translate="label">
141
+ <label>Cost Center</label>
142
+ <sort_order>50</sort_order>
143
+ <frontend_type>select</frontend_type>
144
+ <source_model>transsmart_shipping/adminhtml_system_config_source_basedata_costcenter</source_model>
145
+ <show_in_default>1</show_in_default>
146
+ <show_in_website>1</show_in_website>
147
+ <show_in_store>1</show_in_store>
148
+ </costcenter>
149
+ <packagetype translate="label">
150
+ <label>Package Type</label>
151
+ <sort_order>60</sort_order>
152
+ <frontend_type>select</frontend_type>
153
+ <source_model>transsmart_shipping/adminhtml_system_config_source_basedata_packagetype</source_model>
154
+ <show_in_default>1</show_in_default>
155
+ <show_in_website>1</show_in_website>
156
+ <show_in_store>1</show_in_store>
157
+ </packagetype>
158
+ </fields>
159
+ </default_shipment>
160
+ <mapping>
161
+ <label>Mapping</label>
162
+ <comment>If the shop uses multiple street fields, please specify which field should be used for what.</comment>
163
+ <sort_order>50</sort_order>
164
+ <show_in_default>1</show_in_default>
165
+ <show_in_website>1</show_in_website>
166
+ <show_in_store>1</show_in_store>
167
+ <expanded>1</expanded>
168
+ <fields>
169
+ <street translate="label">
170
+ <label>Street</label>
171
+ <sort_order>10</sort_order>
172
+ <frontend_type>select</frontend_type>
173
+ <source_model>transsmart_shipping/adminhtml_system_config_source_mapping_street</source_model>
174
+ <show_in_default>1</show_in_default>
175
+ <show_in_website>1</show_in_website>
176
+ <show_in_store>1</show_in_store>
177
+ </street>
178
+ <streetno translate="label">
179
+ <label>House Number</label>
180
+ <sort_order>20</sort_order>
181
+ <frontend_type>select</frontend_type>
182
+ <source_model>transsmart_shipping/adminhtml_system_config_source_mapping_street</source_model>
183
+ <show_in_default>1</show_in_default>
184
+ <show_in_website>1</show_in_website>
185
+ <show_in_store>1</show_in_store>
186
+ </streetno>
187
+ <street2 translate="label">
188
+ <label>Street 2</label>
189
+ <sort_order>30</sort_order>
190
+ <frontend_type>select</frontend_type>
191
+ <source_model>transsmart_shipping/adminhtml_system_config_source_mapping_street</source_model>
192
+ <show_in_default>1</show_in_default>
193
+ <show_in_website>1</show_in_website>
194
+ <show_in_store>1</show_in_store>
195
+ </street2>
196
+ <country_of_origin translate="label">
197
+ <label>Country of Origin</label>
198
+ <sort_order>40</sort_order>
199
+ <frontend_type>select</frontend_type>
200
+ <source_model>transsmart_shipping/adminhtml_system_config_source_mapping_attribute</source_model>
201
+ <show_in_default>1</show_in_default>
202
+ <show_in_website>1</show_in_website>
203
+ <show_in_store>1</show_in_store>
204
+ </country_of_origin>
205
+ <hs_code translate="label">
206
+ <label>HS Code</label>
207
+ <sort_order>50</sort_order>
208
+ <frontend_type>select</frontend_type>
209
+ <source_model>transsmart_shipping/adminhtml_system_config_source_mapping_attribute</source_model>
210
+ <show_in_default>1</show_in_default>
211
+ <show_in_website>1</show_in_website>
212
+ <show_in_store>1</show_in_store>
213
+ </hs_code>
214
+ <reason_of_export translate="label">
215
+ <label>Reason of Export</label>
216
+ <sort_order>60</sort_order>
217
+ <frontend_type>select</frontend_type>
218
+ <source_model>transsmart_shipping/adminhtml_system_config_source_mapping_attribute</source_model>
219
+ <show_in_default>1</show_in_default>
220
+ <show_in_website>1</show_in_website>
221
+ <show_in_store>1</show_in_store>
222
+ </reason_of_export>
223
+ </fields>
224
+ </mapping>
225
+ </groups>
226
+ </transsmart_shipping>
227
+ <transsmart_carrier_profiles>
228
+ <label>Transsmart Carrier Profiles</label>
229
+ <tab>sales</tab>
230
+ <sort_order>326</sort_order>
231
+ <show_in_default>1</show_in_default>
232
+ <show_in_website>1</show_in_website>
233
+ <show_in_store>1</show_in_store>
234
+ <groups>
235
+ <versioninfo>
236
+ <frontend_model>transsmart_shipping/adminhtml_system_config_form_fieldset_versioninfo</frontend_model>
237
+ <sort_order>10</sort_order>
238
+ <show_in_default>1</show_in_default>
239
+ <show_in_website>1</show_in_website>
240
+ <show_in_store>1</show_in_store>
241
+ </versioninfo>
242
+ <header>
243
+ <frontend_model>transsmart_shipping/adminhtml_system_config_form_fieldset_carrierprofile_header</frontend_model>
244
+ <sort_order>20</sort_order>
245
+ <show_in_default>1</show_in_default>
246
+ <show_in_website>1</show_in_website>
247
+ <show_in_store>1</show_in_store>
248
+ </header>
249
+ <template>
250
+ <frontend_model>transsmart_shipping/adminhtml_system_config_form_fieldset_carrierprofile</frontend_model>
251
+ <sort_order>30</sort_order>
252
+ <show_in_default>1</show_in_default>
253
+ <show_in_website>1</show_in_website>
254
+ <show_in_store>1</show_in_store>
255
+ <fields>
256
+ <method translate="label">
257
+ <label>Show in Checkout</label>
258
+ <sort_order>10</sort_order>
259
+ <frontend_type>select</frontend_type>
260
+ <source_model>transsmart_shipping/adminhtml_system_config_source_method</source_model>
261
+ <show_in_default>1</show_in_default>
262
+ <show_in_website>1</show_in_website>
263
+ <show_in_store>1</show_in_store>
264
+ </method>
265
+ <title translate="label">
266
+ <label>Title</label>
267
+ <sort_order>20</sort_order>
268
+ <frontend_type>text</frontend_type>
269
+ <show_in_default>1</show_in_default>
270
+ <show_in_website>1</show_in_website>
271
+ <show_in_store>1</show_in_store>
272
+ </title>
273
+ <price translate="label" module="shipping">
274
+ <label>Price</label>
275
+ <frontend_type>text</frontend_type>
276
+ <validate>validate-number validate-zero-or-greater</validate>
277
+ <sort_order>30</sort_order>
278
+ <show_in_default>1</show_in_default>
279
+ <show_in_website>1</show_in_website>
280
+ <show_in_store>0</show_in_store>
281
+ </price>
282
+ <sallowspecific translate="label" module="shipping">
283
+ <label>Ship to Applicable Countries</label>
284
+ <frontend_type>select</frontend_type>
285
+ <sort_order>60</sort_order>
286
+ <source_model>adminhtml/system_config_source_shipping_allspecificcountries</source_model>
287
+ <show_in_default>1</show_in_default>
288
+ <show_in_website>1</show_in_website>
289
+ <show_in_store>0</show_in_store>
290
+ </sallowspecific>
291
+ <specificcountry translate="label" module="shipping">
292
+ <label>Ship to Specific Countries</label>
293
+ <frontend_type>multiselect</frontend_type>
294
+ <sort_order>61</sort_order>
295
+ <source_model>adminhtml/system_config_source_country</source_model>
296
+ <show_in_default>1</show_in_default>
297
+ <show_in_website>1</show_in_website>
298
+ <show_in_store>0</show_in_store>
299
+ <can_be_empty>1</can_be_empty>
300
+ <depends>
301
+ <sallowspecific>1</sallowspecific>
302
+ </depends>
303
+ </specificcountry>
304
+ <location_select translate="label">
305
+ <label>Use Location Selector</label>
306
+ <sort_order>70</sort_order>
307
+ <frontend_type>select</frontend_type>
308
+ <source_model>adminhtml/system_config_source_yesno</source_model>
309
+ <show_in_default>1</show_in_default>
310
+ <show_in_website>1</show_in_website>
311
+ <show_in_store>1</show_in_store>
312
+ <depends>
313
+ <method>transsmartpickup</method>
314
+ </depends>
315
+ </location_select>
316
+ </fields>
317
+ </template>
318
+ </groups>
319
+ </transsmart_carrier_profiles>
320
+ </sections>
321
+ </config>
app/code/community/Transsmart/Shipping/sql/transsmart_shipping_setup/install-1.0.0.php ADDED
@@ -0,0 +1,558 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Transsmart
4
+ * @package Transsmart_Shipping
5
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
6
+ */
7
+
8
+ /** @var Mage_Core_Model_Resource_Setup $installer */
9
+ $installer = $this;
10
+
11
+ $installer->startSetup();
12
+
13
+ /** @var Magento_Db_Adapter_Pdo_Mysql $connection */
14
+ $connection = $installer->getConnection();
15
+
16
+ /**
17
+ * Create table 'transsmart_shipping/carrier'
18
+ */
19
+ $table = $connection->newTable($installer->getTable('transsmart_shipping/carrier'))
20
+ ->addColumn('carrier_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
21
+ 'primary' => true,
22
+ 'unsigned' => true,
23
+ 'nullable' => false,
24
+ ), 'Carrier ID')
25
+ ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
26
+ 'nullable' => true,
27
+ ), 'Carrier Code')
28
+ ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
29
+ 'nullable' => true,
30
+ ), 'Carrier Name')
31
+ ->addColumn('location_select', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
32
+ 'nullable' => true,
33
+ 'unsigned' => true,
34
+ ), 'Location Selector Enabled')
35
+ ->setComment('Transsmart Carrier');
36
+ $connection->createTable($table);
37
+
38
+ /**
39
+ * Create table 'transsmart_shipping/servicelevel_time'
40
+ */
41
+ $table = $connection->newTable($installer->getTable('transsmart_shipping/servicelevel_time'))
42
+ ->addColumn('servicelevel_time_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
43
+ 'primary' => true,
44
+ 'unsigned' => true,
45
+ 'nullable' => false,
46
+ ), 'Servicelevel Time ID')
47
+ ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
48
+ 'nullable' => true,
49
+ ), 'Servicelevel Time Code')
50
+ ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
51
+ 'nullable' => true,
52
+ ), 'Servicelevel Time Name')
53
+ ->setComment('Transsmart Servicelevel Time');
54
+ $connection->createTable($table);
55
+
56
+ /**
57
+ * Create table 'transsmart_shipping/servicelevel_other'
58
+ */
59
+ $table = $connection->newTable($installer->getTable('transsmart_shipping/servicelevel_other'))
60
+ ->addColumn('servicelevel_other_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
61
+ 'primary' => true,
62
+ 'unsigned' => true,
63
+ 'nullable' => false,
64
+ ), 'Servicelevel Other ID')
65
+ ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
66
+ 'nullable' => true,
67
+ ), 'Servicelevel Other Code')
68
+ ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
69
+ 'nullable' => true,
70
+ ), 'Servicelevel Other Name')
71
+ ->setComment('Transsmart Servicelevel Other');
72
+ $connection->createTable($table);
73
+
74
+ /**
75
+ * Create table 'transsmart_shipping/carrierprofile'
76
+ */
77
+ $table = $connection->newTable($installer->getTable('transsmart_shipping/carrierprofile'))
78
+ ->addColumn('carrierprofile_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
79
+ 'primary' => true,
80
+ 'unsigned' => true,
81
+ 'nullable' => false,
82
+ ), 'Carrier Profile ID')
83
+ ->addColumn('carrier_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
84
+ 'unsigned' => true,
85
+ 'nullable' => false,
86
+ ), 'Carrier ID')
87
+ ->addColumn('servicelevel_time_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
88
+ 'unsigned' => true,
89
+ 'nullable' => false,
90
+ ), 'Servicelevel Time ID')
91
+ ->addColumn('servicelevel_other_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
92
+ 'unsigned' => true,
93
+ 'nullable' => false,
94
+ ), 'Servicelevel Other ID')
95
+ ->addForeignKey($installer->getFkName('transsmart_shipping/carrierprofile', 'carrier_id',
96
+ 'transsmart_shipping/carrier', 'carrier_id'),
97
+ 'carrier_id', $installer->getTable('transsmart_shipping/carrier'),
98
+ 'carrier_id', Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
99
+ ->addForeignKey($installer->getFkName('transsmart_shipping/servicelevel_time', 'servicelevel_time_id',
100
+ 'transsmart_shipping/servicelevel_time', 'servicelevel_time_id'),
101
+ 'servicelevel_time_id', $installer->getTable('transsmart_shipping/servicelevel_time'),
102
+ 'servicelevel_time_id', Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
103
+ ->addForeignKey($installer->getFkName('transsmart_shipping/servicelevel_other', 'servicelevel_other_id',
104
+ 'transsmart_shipping/servicelevel_other', 'servicelevel_other_id'),
105
+ 'servicelevel_other_id', $installer->getTable('transsmart_shipping/servicelevel_other'),
106
+ 'servicelevel_other_id', Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
107
+ ->setComment('Transsmart Carrier Profile');
108
+ $connection->createTable($table);
109
+
110
+ /**
111
+ * Create table 'transsmart_shipping/shipmentlocation'
112
+ */
113
+ $table = $connection->newTable($installer->getTable('transsmart_shipping/shipmentlocation'))
114
+ ->addColumn('shipmentlocation_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
115
+ 'primary' => true,
116
+ 'unsigned' => true,
117
+ 'nullable' => false,
118
+ ), 'Shipment Location ID')
119
+ ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
120
+ 'nullable' => true,
121
+ ), 'Shipment Location Name')
122
+ ->addColumn('street', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
123
+ 'nullable' => true,
124
+ ), 'Shipment Location Street')
125
+ ->addColumn('street_no', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
126
+ 'nullable' => true,
127
+ ), 'Shipment Location Street No')
128
+ ->addColumn('zip_code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
129
+ 'nullable' => true,
130
+ ), 'Shipment Location Zip Code')
131
+ ->addColumn('city', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
132
+ 'nullable' => true,
133
+ ), 'Shipment Location City')
134
+ ->addColumn('country', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
135
+ 'nullable' => true,
136
+ ), 'Shipment Location Country')
137
+ ->addColumn('contact_person', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
138
+ 'nullable' => true,
139
+ ), 'Shipment Location Contact Person')
140
+ ->addColumn('phone_number', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
141
+ 'nullable' => true,
142
+ ), 'Shipment Location Phone Number')
143
+ ->addColumn('fax_number', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
144
+ 'nullable' => true,
145
+ ), 'Shipment Location Fax Number')
146
+ ->addColumn('email_address', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
147
+ 'nullable' => true,
148
+ ), 'Shipment Location Email Address')
149
+ ->addColumn('account_number', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
150
+ 'nullable' => true,
151
+ ), 'Shipment Location Account Number')
152
+ ->addColumn('customer_number', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
153
+ 'nullable' => true,
154
+ ), 'Shipment Location Customer Number')
155
+ ->addColumn('vat_number', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
156
+ 'nullable' => true,
157
+ ), 'Shipment Location Vat Number')
158
+ ->addColumn('is_default', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
159
+ 'nullable' => true,
160
+ 'unsigned' => true,
161
+ ), 'Is Default')
162
+ ->setComment('Transsmart Shipment Location');
163
+ $connection->createTable($table);
164
+
165
+ /**
166
+ * Create table 'transsmart_shipping/emailtype'
167
+ */
168
+ $table = $connection->newTable($installer->getTable('transsmart_shipping/emailtype'))
169
+ ->addColumn('emailtype_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
170
+ 'primary' => true,
171
+ 'unsigned' => true,
172
+ 'nullable' => false,
173
+ ), 'Email Type ID')
174
+ ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
175
+ 'nullable' => true,
176
+ ), 'Email Type Code')
177
+ ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
178
+ 'nullable' => true,
179
+ ), 'Email Type Name')
180
+ ->addColumn('is_default', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
181
+ 'nullable' => true,
182
+ 'unsigned' => true,
183
+ ), 'Is Default')
184
+ ->setComment('Transsmart Email Type');
185
+ $connection->createTable($table);
186
+
187
+ /**
188
+ * Create table 'transsmart_shipping/packagetype'
189
+ */
190
+ $table = $connection->newTable($installer->getTable('transsmart_shipping/packagetype'))
191
+ ->addColumn('packagetype_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
192
+ 'primary' => true,
193
+ 'unsigned' => true,
194
+ 'nullable' => false,
195
+ ), 'Package Type ID')
196
+ ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
197
+ 'nullable' => true,
198
+ ), 'Package Type Code')
199
+ ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
200
+ 'nullable' => true,
201
+ ), 'Package Type Name')
202
+ ->addColumn('length', Varien_Db_Ddl_Table::TYPE_DECIMAL, '19,6', array(
203
+ 'nullable' => true,
204
+ 'unsigned' => false,
205
+ ), 'Package Length')
206
+ ->addColumn('width', Varien_Db_Ddl_Table::TYPE_DECIMAL, '19,6', array(
207
+ 'nullable' => true,
208
+ 'unsigned' => false,
209
+ ), 'Package Width')
210
+ ->addColumn('height', Varien_Db_Ddl_Table::TYPE_DECIMAL, '19,6', array(
211
+ 'nullable' => true,
212
+ 'unsigned' => false,
213
+ ), 'Package Height')
214
+ ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_DECIMAL, '19,6', array(
215
+ 'nullable' => true,
216
+ 'unsigned' => false,
217
+ ), 'Package Weight')
218
+ ->addColumn('is_default', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
219
+ 'nullable' => true,
220
+ 'unsigned' => true,
221
+ ), 'Is Default')
222
+ ->setComment('Transsmart Package Type');
223
+ $connection->createTable($table);
224
+
225
+ /**
226
+ * Create table 'transsmart_shipping/incoterm'
227
+ */
228
+ $table = $connection->newTable($installer->getTable('transsmart_shipping/incoterm'))
229
+ ->addColumn('incoterm_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
230
+ 'primary' => true,
231
+ 'unsigned' => true,
232
+ 'nullable' => false,
233
+ ), 'Incoterm ID')
234
+ ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
235
+ 'nullable' => true,
236
+ ), 'Incoterm Code')
237
+ ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
238
+ 'nullable' => true,
239
+ ), 'Incoterm Name')
240
+ ->addColumn('is_default', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
241
+ 'nullable' => true,
242
+ 'unsigned' => true,
243
+ ), 'Is Default')
244
+ ->setComment('Transsmart Incoterm');
245
+ $connection->createTable($table);
246
+
247
+ /**
248
+ * Create table 'transsmart_shipping/costcenter'
249
+ */
250
+ $table = $connection->newTable($installer->getTable('transsmart_shipping/costcenter'))
251
+ ->addColumn('costcenter_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
252
+ 'primary' => true,
253
+ 'unsigned' => true,
254
+ 'nullable' => false,
255
+ ), 'Cost Center ID')
256
+ ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
257
+ 'nullable' => true,
258
+ ), 'Cost Center Code')
259
+ ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
260
+ 'nullable' => true,
261
+ ), 'Cost Center Name')
262
+ ->addColumn('is_default', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
263
+ 'nullable' => true,
264
+ 'unsigned' => true,
265
+ ), 'Is Default')
266
+ ->setComment('Transsmart Cost Center');
267
+ $connection->createTable($table);
268
+
269
+ /**
270
+ * Create table 'transsmart_shipping/sync'
271
+ */
272
+ $table = $connection->newTable($installer->getTable('transsmart_shipping/sync'))
273
+ ->addColumn('sync_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
274
+ 'primary' => true,
275
+ 'unsigned' => true,
276
+ 'auto_increment' => true,
277
+ 'nullable' => false
278
+ ), 'Sync ID')
279
+ ->addColumn('type', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(), 'Sync Type')
280
+ ->addColumn('status', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(), 'Sync Status')
281
+ ->addColumn('message', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(), 'Sync Message')
282
+ ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_DATETIME, null, array(), 'Created at')
283
+ ->setComment('Transsmart Sync');
284
+ $connection->createTable($table);
285
+
286
+ // add carrierprofile to shipment table
287
+ $connection->addColumn(
288
+ $this->getTable('sales/shipment'),
289
+ 'transsmart_carrierprofile_id',
290
+ array(
291
+ 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
292
+ 'unsigned' => true,
293
+ 'nullable' => true,
294
+ 'comment' => 'Transsmart Carrier Profile Id'
295
+ )
296
+ );
297
+ $connection->addForeignKey(
298
+ $installer->getFkName(
299
+ 'sales/shipment',
300
+ 'transsmart_carrierprofile_id',
301
+ 'transsmart_shipping/carrierprofile',
302
+ 'carrierprofile_id'
303
+ ),
304
+ $this->getTable('sales/shipment'),
305
+ 'transsmart_carrierprofile_id',
306
+ $installer->getTable('transsmart_shipping/carrierprofile'),
307
+ 'carrierprofile_id',
308
+ Varien_Db_Ddl_Table::ACTION_SET_NULL,
309
+ Varien_Db_Ddl_Table::ACTION_CASCADE
310
+ );
311
+
312
+ // add shipmentlocation to shipment table
313
+ $connection->addColumn(
314
+ $this->getTable('sales/shipment'),
315
+ 'transsmart_shipmentlocation_id',
316
+ array(
317
+ 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
318
+ 'unsigned' => true,
319
+ 'nullable' => true,
320
+ 'comment' => 'Transsmart Shipment Location Id'
321
+ )
322
+ );
323
+ $connection->addForeignKey(
324
+ $installer->getFkName(
325
+ 'sales/shipment',
326
+ 'transsmart_shipmentlocation_id',
327
+ 'transsmart_shipping/shipmentlocation',
328
+ 'shipmentlocation_id'
329
+ ),
330
+ $this->getTable('sales/shipment'),
331
+ 'transsmart_shipmentlocation_id',
332
+ $installer->getTable('transsmart_shipping/shipmentlocation'),
333
+ 'shipmentlocation_id',
334
+ Varien_Db_Ddl_Table::ACTION_SET_NULL,
335
+ Varien_Db_Ddl_Table::ACTION_CASCADE
336
+ );
337
+
338
+ // add emailtype to shipment table
339
+ $connection->addColumn(
340
+ $this->getTable('sales/shipment'),
341
+ 'transsmart_emailtype_id',
342
+ array(
343
+ 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
344
+ 'unsigned' => true,
345
+ 'nullable' => true,
346
+ 'comment' => 'Transsmart Email Type Id'
347
+ )
348
+ );
349
+ $connection->addForeignKey(
350
+ $installer->getFkName(
351
+ 'sales/shipment',
352
+ 'transsmart_emailtype_id',
353
+ 'transsmart_shipping/emailtype',
354
+ 'emailtype_id'
355
+ ),
356
+ $this->getTable('sales/shipment'),
357
+ 'transsmart_emailtype_id',
358
+ $installer->getTable('transsmart_shipping/emailtype'),
359
+ 'emailtype_id',
360
+ Varien_Db_Ddl_Table::ACTION_SET_NULL,
361
+ Varien_Db_Ddl_Table::ACTION_CASCADE
362
+ );
363
+
364
+ // add incoterm to shipment table
365
+ $connection->addColumn(
366
+ $this->getTable('sales/shipment'),
367
+ 'transsmart_incoterm_id',
368
+ array(
369
+ 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
370
+ 'unsigned' => true,
371
+ 'nullable' => true,
372
+ 'comment' => 'Transsmart Incoterm Id'
373
+ )
374
+ );
375
+ $connection->addForeignKey(
376
+ $installer->getFkName(
377
+ 'sales/shipment',
378
+ 'transsmart_incoterm_id',
379
+ 'transsmart_shipping/incoterm',
380
+ 'incoterm_id'
381
+ ),
382
+ $this->getTable('sales/shipment'),
383
+ 'transsmart_incoterm_id',
384
+ $installer->getTable('transsmart_shipping/incoterm'),
385
+ 'incoterm_id',
386
+ Varien_Db_Ddl_Table::ACTION_SET_NULL,
387
+ Varien_Db_Ddl_Table::ACTION_CASCADE
388
+ );
389
+
390
+ // add costcenter to shipment table
391
+ $connection->addColumn(
392
+ $this->getTable('sales/shipment'),
393
+ 'transsmart_costcenter_id',
394
+ array(
395
+ 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
396
+ 'unsigned' => true,
397
+ 'nullable' => true,
398
+ 'comment' => 'Transsmart Cost Center Id'
399
+ )
400
+ );
401
+ $connection->addForeignKey(
402
+ $installer->getFkName(
403
+ 'sales/shipment',
404
+ 'transsmart_costcenter_id',
405
+ 'transsmart_shipping/costcenter',
406
+ 'costcenter_id'
407
+ ),
408
+ $this->getTable('sales/shipment'),
409
+ 'transsmart_costcenter_id',
410
+ $installer->getTable('transsmart_shipping/costcenter'),
411
+ 'costcenter_id',
412
+ Varien_Db_Ddl_Table::ACTION_SET_NULL,
413
+ Varien_Db_Ddl_Table::ACTION_CASCADE
414
+ );
415
+
416
+ // add packages to shipment table
417
+ $connection->addColumn(
418
+ $this->getTable('sales/shipment'),
419
+ 'transsmart_packages',
420
+ array(
421
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
422
+ 'length' => '20000',
423
+ 'comment' => 'Transsmart Package Data',
424
+ 'after' => 'transsmart_costcenter_id'
425
+ )
426
+ );
427
+
428
+ // add flags to shipment table
429
+ $connection->addColumn(
430
+ $this->getTable('sales/shipment'),
431
+ 'transsmart_flags',
432
+ array(
433
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
434
+ 'unsigned' => true,
435
+ 'comment' => 'Transsmart Flags',
436
+ 'after' => 'transsmart_packages'
437
+ )
438
+ );
439
+
440
+ // add document ID to shipment table
441
+ $connection->addColumn(
442
+ $this->getTable('sales/shipment'),
443
+ 'transsmart_document_id',
444
+ array(
445
+ 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
446
+ 'unsigned' => true,
447
+ 'nullable' => true,
448
+ 'comment' => 'Transsmart Document Id'
449
+ )
450
+ );
451
+ $connection->addIndex(
452
+ $this->getTable('sales/shipment'),
453
+ $installer->getIdxName(
454
+ $this->getTable('sales/shipment'),
455
+ 'transsmart_document_id',
456
+ Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
457
+ ),
458
+ 'transsmart_document_id',
459
+ Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
460
+ );
461
+
462
+ // add status to shipment table
463
+ $connection->addColumn(
464
+ $this->getTable('sales/shipment'),
465
+ 'transsmart_status',
466
+ array(
467
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
468
+ 'length' => 255,
469
+ 'nullable' => true,
470
+ 'comment' => 'Transsmart Status'
471
+ )
472
+ );
473
+
474
+ // add document ID to shipment grid table
475
+ $connection->addColumn(
476
+ $this->getTable('sales/shipment_grid'),
477
+ 'transsmart_document_id',
478
+ array(
479
+ 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
480
+ 'unsigned' => true,
481
+ 'nullable' => true,
482
+ 'comment' => 'Transsmart Document Id'
483
+ )
484
+ );
485
+
486
+ // add status to shipment grid table
487
+ $connection->addColumn(
488
+ $this->getTable('sales/shipment_grid'),
489
+ 'transsmart_status',
490
+ array(
491
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
492
+ 'length' => 255,
493
+ 'nullable' => true,
494
+ 'comment' => 'Transsmart Status'
495
+ )
496
+ );
497
+
498
+ // add status to order grid table
499
+ $connection->addColumn(
500
+ $this->getTable('sales/order_grid'),
501
+ 'transsmart_status',
502
+ array(
503
+ 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
504
+ 'unsigned' => true,
505
+ 'nullable' => true,
506
+ 'comment' => 'Transsmart Status'
507
+ )
508
+ );
509
+
510
+ // add tracking url to shipment table
511
+ $connection->addColumn(
512
+ $this->getTable('sales/shipment'),
513
+ 'transsmart_tracking_url',
514
+ array(
515
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
516
+ 'length' => 255,
517
+ 'nullable' => true,
518
+ 'comment' => 'Transsmart Tracking URL'
519
+ )
520
+ );
521
+
522
+ // add tracking url to shipment grid table
523
+ $connection->addColumn(
524
+ $this->getTable('sales/shipment_grid'),
525
+ 'transsmart_tracking_url',
526
+ array(
527
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
528
+ 'length' => 255,
529
+ 'nullable' => true,
530
+ 'comment' => 'Transsmart Tracking URL'
531
+ )
532
+ );
533
+
534
+ // add servicepoint_id to quote address table
535
+ $connection->addColumn(
536
+ $this->getTable('sales/quote_address'),
537
+ 'transsmart_servicepoint_id',
538
+ array(
539
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
540
+ 'length' => 255,
541
+ 'nullable' => true,
542
+ 'comment' => 'Transsmart Servicepoint Id'
543
+ )
544
+ );
545
+
546
+ // add servicepoint_id to order address table
547
+ $connection->addColumn(
548
+ $this->getTable('sales/order_address'),
549
+ 'transsmart_servicepoint_id',
550
+ array(
551
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
552
+ 'length' => 255,
553
+ 'nullable' => true,
554
+ 'comment' => 'Transsmart Servicepoint Id'
555
+ )
556
+ );
557
+
558
+ $installer->endSetup();
app/code/community/Transsmart/Shipping/ssl/CARoot.crt ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIENjCCAx6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBvMQswCQYDVQQGEwJTRTEU
3
+ MBIGA1UEChMLQWRkVHJ1c3QgQUIxJjAkBgNVBAsTHUFkZFRydXN0IEV4dGVybmFs
4
+ IFRUUCBOZXR3b3JrMSIwIAYDVQQDExlBZGRUcnVzdCBFeHRlcm5hbCBDQSBSb290
5
+ MB4XDTAwMDUzMDEwNDgzOFoXDTIwMDUzMDEwNDgzOFowbzELMAkGA1UEBhMCU0Ux
6
+ FDASBgNVBAoTC0FkZFRydXN0IEFCMSYwJAYDVQQLEx1BZGRUcnVzdCBFeHRlcm5h
7
+ bCBUVFAgTmV0d29yazEiMCAGA1UEAxMZQWRkVHJ1c3QgRXh0ZXJuYWwgQ0EgUm9v
8
+ dDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALf3GjPm8gAELTngTlvt
9
+ H7xsD821+iO2zt6bETOXpClMfZOfvUq8k+0DGuOPz+VtUFrWlymUWoCwSXrbLpX9
10
+ uMq/NzgtHj6RQa1wVsfwTz/oMp50ysiQVOnGXw94nZpAPA6sYapeFI+eh6FqUNzX
11
+ mk6vBbOmcZSccbNQYArHE504B4YCqOmoaSYYkKtMsE8jqzpPhNjfzp/haW+710LX
12
+ a0Tkx63ubUFfclpxCDezeWWkWaCUN/cALw3CknLa0Dhy2xSoRcRdKn23tNbE7qzN
13
+ E0S3ySvdQwAl+mG5aWpYIxG3pzOPVnVZ9c0p10a3CitlttNCbxWyuHv77+ldU9U0
14
+ WicCAwEAAaOB3DCB2TAdBgNVHQ4EFgQUrb2YejS0Jvf6xCZU7wO94CTLVBowCwYD
15
+ VR0PBAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wgZkGA1UdIwSBkTCBjoAUrb2YejS0
16
+ Jvf6xCZU7wO94CTLVBqhc6RxMG8xCzAJBgNVBAYTAlNFMRQwEgYDVQQKEwtBZGRU
17
+ cnVzdCBBQjEmMCQGA1UECxMdQWRkVHJ1c3QgRXh0ZXJuYWwgVFRQIE5ldHdvcmsx
18
+ IjAgBgNVBAMTGUFkZFRydXN0IEV4dGVybmFsIENBIFJvb3SCAQEwDQYJKoZIhvcN
19
+ AQEFBQADggEBALCb4IUlwtYj4g+WBpKdQZic2YR5gdkeWxQHIzZlj7DYd7usQWxH
20
+ YINRsPkyPef89iYTx4AWpb9a/IfPeHmJIZriTAcKhjW88t5RxNKWt9x+Tu5w/Rw5
21
+ 6wwCURQtjr0W4MHfRnXnJK3s9EK0hZNwEGe6nQY1ShjTK3rMUUKhemPR5ruhxSvC
22
+ Nr4TDea9Y355e6cJDUCrat2PisP29owaQgVR1EX1n6diIWgVIEM8med8vSTYqZEX
23
+ c4g/VhsxOBi0cQ+azcgOno4uG+GMmIPLHzHxREzGBHNJdmAPx/i9F4BrLunMTA5a
24
+ mnkPIAou1Z5jJh5VkpTYghdae9C8x49OhgQ=
25
+ -----END CERTIFICATE-----
app/design/adminhtml/base/default/layout/transsmart_shipping.xml ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ -->
9
+ <layout>
10
+ <adminhtml_sales_order_view>
11
+ <reference name="head">
12
+ <action method="addCss">
13
+ <stylesheet>transsmart/shipping/styles.css</stylesheet>
14
+ </action>
15
+ </reference>
16
+ <reference name="content">
17
+ <block type="adminhtml/template" name="transsmart_shipping.pickup.address_container"
18
+ template="transsmart/shipping/sales/order/address/form/container.phtml"/>
19
+ </reference>
20
+ </adminhtml_sales_order_view>
21
+
22
+ <adminhtml_sales_order_create_index>
23
+ <reference name="head">
24
+ <action method="addLinkRel">
25
+ <rel>stylesheet</rel>
26
+ <href>//fonts.googleapis.com/css?family=Dosis:500,600</href>
27
+ </action>
28
+ <action method="addJs">
29
+ <file>transsmart/shipping/base64.js</file>
30
+ </action>
31
+ <action method="addJs">
32
+ <file>transsmart/shipping/logger.js</file>
33
+ </action>
34
+ <action method="addJs">
35
+ <file>transsmart/shipping/pickup_selector.js</file>
36
+ </action>
37
+ <action method="addJs">
38
+ <file>transsmart/shipping/admin/pickup_selector.js</file>
39
+ </action>
40
+ <action method="addCss">
41
+ <stylesheet>transsmart/shipping/pickup_selector.css</stylesheet>
42
+ </action>
43
+ </reference>
44
+ <reference name="before_body_end">
45
+ <block type="adminhtml/template" name="transsmart_shipping.pickup.selector"
46
+ template="transsmart/shipping/location/selector.phtml"/>
47
+ </reference>
48
+ <reference name="shipping_method">
49
+ <block type="transsmart_shipping/adminhtml_shipping_location_info"
50
+ name="transsmart_shipping.pickup.location_info" />
51
+ </reference>
52
+ </adminhtml_sales_order_create_index>
53
+
54
+ <adminhtml_sales_order_create_load_block_data>
55
+ <reference name="shipping_method">
56
+ <block type="transsmart_shipping/adminhtml_shipping_location_info"
57
+ name="transsmart_shipping.pickup.location_info" />
58
+ </reference>
59
+ </adminhtml_sales_order_create_load_block_data>
60
+
61
+ <adminhtml_sales_order_create_load_block_shipping_method>
62
+ <reference name="shipping_method">
63
+ <block type="transsmart_shipping/adminhtml_shipping_location_info"
64
+ name="transsmart_shipping.pickup.location_info" />
65
+ </reference>
66
+ </adminhtml_sales_order_create_load_block_shipping_method>
67
+
68
+ <adminhtml_sales_order_shipment_new>
69
+ <reference name="head">
70
+ <action method="addCss">
71
+ <stylesheet>transsmart/shipping/styles.css</stylesheet>
72
+ </action>
73
+ </reference>
74
+ <reference name="content">
75
+ <block type="adminhtml/template" name="transsmart_shipping.pickup.address_container"
76
+ template="transsmart/shipping/sales/order/shipment/address/form/container.phtml"/>
77
+ </reference>
78
+ </adminhtml_sales_order_shipment_new>
79
+
80
+ <adminhtml_sales_order_shipment_view>
81
+ <reference name="head">
82
+ <action method="addCss">
83
+ <stylesheet>transsmart/shipping/styles.css</stylesheet>
84
+ </action>
85
+ </reference>
86
+ <reference name="content">
87
+ <block type="adminhtml/template" name="transsmart_shipping.pickup.address_container"
88
+ template="transsmart/shipping/sales/order/shipment/address/form/container.phtml"/>
89
+ </reference>
90
+ </adminhtml_sales_order_shipment_view>
91
+
92
+ <adminhtml_transsmart_shipping_shipment_masscreate>
93
+ <reference name="head">
94
+ <action method="addCss">
95
+ <stylesheet>transsmart/shipping/styles.css</stylesheet>
96
+ </action>
97
+ </reference>
98
+ <reference name="content">
99
+ <block type="transsmart_shipping/adminhtml_sales_order_shipment_masscreate" name="sales_shipment_create"/>
100
+ </reference>
101
+ </adminhtml_transsmart_shipping_shipment_masscreate>
102
+ </layout>
app/design/adminhtml/base/default/template/transsmart/shipping/location/info.phtml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Transsmart
4
+ * @package Transsmart_Shipping
5
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
6
+ */
7
+ ?>
8
+ <?php /** @var Transsmart_Shipping_Block_Adminhtml_Shipping_Location_Info $this */ ?>
9
+ <div id="tss-ls-admin-selected-location">
10
+ <?php if ($_pickupAddress = $this->getPickupAddress()): ?>
11
+ <p style="margin: 10px 0 0">
12
+ <strong><?php echo $this->escapeHtml($_pickupAddress->getCompany()); ?></strong><br />
13
+ <?php echo $this->escapeHtml($_pickupAddress->getStreetFull()); ?><br />
14
+ <?php echo $this->escapeHtml($_pickupAddress->getPostcode()); ?> <?php echo $this->escapeHtml($_pickupAddress->getCity()); ?><br />
15
+ <?php echo $this->escapeHtml($_pickupAddress->getTelephone()); ?>
16
+ </p>
17
+ <?php endif; ?>
18
+ </div>
app/design/adminhtml/base/default/template/transsmart/shipping/location/selector.phtml ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Transsmart
4
+ * @package Transsmart_Shipping
5
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
6
+ */
7
+ ?>
8
+ <?php /** @var Transsmart_Shipping_Block_Location_Selector $this */ ?>
9
+ <?php $helper = Mage::helper('transsmart_shipping'); ?>
10
+
11
+ <div id="tss-pickup-container" style="display: none;">
12
+ <div class="tss-selector">
13
+ <div class="tss-selector-inner">
14
+ <button id="tss-ls-close"></button>
15
+ <div class="tss-loader">
16
+ <img src="<?php echo $this->getSkinUrl('transsmart/shipping/images/loader.gif'); ?>" />
17
+ </div>
18
+
19
+ <div class="tss-selector-container" style="display: none">
20
+ <div class="tss-ls-header">
21
+ <span class="tss-ls-header-title"><?php echo $helper->__('Select pickup location'); ?></span>
22
+ <div class="tss-ls-search-wrapper">
23
+ <input type="text" id="tss-ls-search" placeholder="<?php echo $helper->__('1234 AB'); ?>" />
24
+ <button type="button" id="tss-ls-search-btn"><?php echo $helper->__('Search'); ?></button>
25
+ </div>
26
+ <div class="tss-ls-options">
27
+ <div class="tss-ls-checkbox-wrapper">
28
+ <input type="checkbox" id="tss-ls-show-open-late" name="tss-ls-show-open-late" /> <label for="tss-ls-show-open-late"><?php echo $helper->__('Open late'); ?></label>
29
+ </div>
30
+ <div class="tss-ls-checkbox-wrapper">
31
+ <input type="checkbox" id="tss-ls-show-open-early" name="tss-ls-show-open-early" /> <label for="tss-ls-show-open-early"><?php echo $helper->__('Open early'); ?></label>
32
+ </div>
33
+ <div class="tss-ls-checkbox-wrapper">
34
+ <input type="checkbox" id="tss-ls-show-open-sunday" name="tss-ls-show-open-sunday" /> <label for="tss-ls-show-open-sunday"><?php echo $helper->__('Open on sunday'); ?></label>
35
+ </div>
36
+ </div>
37
+ </div>
38
+
39
+ <div class="tss-ls-content">
40
+ <div class="tss-ls-map-container">
41
+ <div id="tss-ls-map"></div>
42
+ </div>
43
+ <div class="tss-ls-location-wrapper">
44
+ <h3><?php echo $helper->__('Found pickup locations:'); ?></h3>
45
+ <div id="tss-ls-locations"></div>
46
+ </div>
47
+ </div>
48
+ <div class="tss-ls-footer-controls">
49
+ <button id="tss-ls-select"><?php echo $helper->__('Save'); ?></button>
50
+ </div>
51
+ </div>
52
+ </div>
53
+ </div>
54
+
55
+ <div class="tss-background-overlay"></div>
56
+ </div>
57
+
58
+ <script type="text/javascript">
59
+ Translator.add([
60
+ 'Error loading pickup location selector. Please try again.', '<?php echo $this->jsQuoteEscape($this->__('Error loading pickup location selector. Please try again.')); ?>',
61
+ 'Search did not succeed. Please try again.', '<?php echo $this->jsQuoteEscape($this->__('Search did not succeed. Please try again.')); ?>',
62
+ 'Select pickup location', '<?php echo $this->jsQuoteEscape($this->__('Select pickup location')); ?>',
63
+ 'A pickup location has to be selected', '<?php echo $this->jsQuoteEscape($this->__('A pickup location has to be selected')); ?>',
64
+ 'Opening hours:', '<?php echo $this->jsQuoteEscape($this->__('Opening hours:')); ?>'
65
+ ]);
66
+ var transsmartShippingPickup = new Transsmart.Shipping.PickupAdmin({
67
+ lookupUrl: '<?php echo $this->getUrl('*/transsmart_shipping_location/lookup'); ?>',
68
+ carrierProfileIds: <?php echo Zend_Json_Encoder::encode($helper->getLocationSelectCarrierProfiles()); ?>
69
+ });
70
+ </script>
71
+
72
+ <script src="https://maps.googleapis.com/maps/api/js?callback=transsmartShippingPickup.googleMapsLoaded&libraries=geometry"></script>
app/design/adminhtml/base/default/template/transsmart/shipping/sales/order/address/form/container.phtml ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Transsmart
4
+ * @package Transsmart_Shipping
5
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
6
+ */
7
+ ?>
8
+ <?php $_helper = Mage::helper('transsmart_shipping'); ?>
9
+ <?php $_order = Mage::registry('current_order'); ?>
10
+
11
+ <?php if (!$_helper->isTranssmartShippingMethod($_order->getShippingMethod())): ?>
12
+ <?php return ''; ?>
13
+ <?php endif; ?>
14
+
15
+ <?php $_pickupAddress = Mage::helper('transsmart_shipping/pickupaddress')->getPickupAddressFromOrder($_order); ?>
16
+ <?php if (!$_pickupAddress): ?>
17
+ <?php return ''; ?>
18
+ <?php endif; ?>
19
+
20
+ <div class="three-column box-right" id="transsmart_pickup_address">
21
+ <!--Transsmart Pickup Address-->
22
+ <div class="entry-edit">
23
+ <div class="entry-edit-head">
24
+ <h4 class="icon-head head-transsmart-pickup-address"><?php echo $this->__('Pickup Address'); ?></h4>
25
+ <div class="tools"><a href="<?php echo $this->getUrl('adminhtml/sales_order/address', array('address_id' => $_pickupAddress->getId())); ?>"><?php echo $this->__('Edit'); ?></a></div>
26
+ </div>
27
+ <fieldset>
28
+ <address><?php echo $_pickupAddress->format('html'); ?></address>
29
+ </fieldset>
30
+ </div>
31
+ </div>
32
+
33
+ <script type="text/javascript">
34
+ //<[CDATA[
35
+ document.observe('dom:loaded', function() {
36
+ var billingAddress = $$('#sales_order_view_tabs_order_info_content .box-left')[1];
37
+ var shippingAddress = $$('#sales_order_view_tabs_order_info_content .box-right')[1];
38
+
39
+ billingAddress.addClassName('three-column');
40
+ shippingAddress.addClassName('three-column box-middle')
41
+ .removeClassName('box-right')
42
+ .insert(
43
+ {
44
+ after : $('transsmart_pickup_address')
45
+ }
46
+ );
47
+ });
48
+ //]]>
49
+ </script>
app/design/adminhtml/base/default/template/transsmart/shipping/sales/order/shipment/address/form/container.phtml ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Transsmart
4
+ * @package Transsmart_Shipping
5
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
6
+ */
7
+ ?>
8
+ <?php $_helper = Mage::helper('transsmart_shipping'); ?>
9
+
10
+ <?php /** @var Mage_Sales_Model_Order_Shipment $_shipment */ ?>
11
+ <?php $_shipment = Mage::registry('current_shipment'); ?>
12
+ <?php $_order = $_shipment->getOrder(); ?>
13
+
14
+ <?php if (!$_helper->isTranssmartShippingMethod($_order->getShippingMethod())): ?>
15
+ <?php return ''; ?>
16
+ <?php endif; ?>
17
+
18
+ <?php $_pickupAddress = Mage::helper('transsmart_shipping/pickupaddress')->getPickupAddressFromOrder($_order); ?>
19
+ <?php if (!$_pickupAddress): ?>
20
+ <?php return ''; ?>
21
+ <?php endif; ?>
22
+
23
+ <div class="three-column box-right" id="transsmart_pickup_address">
24
+ <!--Transsmart Pickup Address-->
25
+ <div class="entry-edit">
26
+ <div class="entry-edit-head">
27
+ <h4 class="icon-head head-transsmart-pickup-address"><?php echo $this->__('Pickup Address'); ?></h4>
28
+ <div class="tools"><a href="<?php echo $this->getUrl('adminhtml/sales_order/address', array('address_id' => $_pickupAddress->getId())); ?>"><?php echo $this->__('Edit'); ?></a></div>
29
+ </div>
30
+ <fieldset>
31
+ <address><?php echo $_pickupAddress->format('html'); ?></address>
32
+ </fieldset>
33
+ </div>
34
+ </div>
35
+
36
+ <script type="text/javascript">
37
+ //<[CDATA[
38
+ document.observe('dom:loaded', function() {
39
+ var pageContainer = $('page:main-container');
40
+ var billingAddress = pageContainer.select('.box-left')[1];
41
+ var shippingAddress = pageContainer.select('.box-right')[1];
42
+
43
+ billingAddress.addClassName('three-column');
44
+ shippingAddress.addClassName('three-column box-middle')
45
+ .removeClassName('box-right')
46
+ .insert(
47
+ {
48
+ after : $('transsmart_pickup_address')
49
+ }
50
+ );
51
+ });
52
+ //]]>
53
+ </script>
app/design/adminhtml/base/default/template/transsmart/shipping/sales/order/shipment/create/action.phtml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Transsmart
4
+ * @package Transsmart_Shipping
5
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
6
+ */
7
+ ?>
8
+ <?php /** @var Mage_Adminhtml_Block_Template $this */ ?>
9
+ <p>
10
+ <label class="normal" for="transsmart_book"><?php echo $this->jsQuoteEscape(Mage::helper('transsmart_shipping')->__('Transsmart: Book Shipment(s)')); ?></label>
11
+ <input id="transsmart_book" name="shipment[transsmart_book]" value="1" type="checkbox" />
12
+ </p>
13
+ <p>
14
+ <label class="normal" for="transsmart_bookandprint"><?php echo $this->jsQuoteEscape(Mage::helper('transsmart_shipping')->__('Transsmart: Book & Print')); ?></label>
15
+ <input id="transsmart_bookandprint" name="shipment[transsmart_bookandprint]" value="1" type="checkbox" onclick="toggleTranssmartBookAndPrintCheckbox();" />
16
+ </p>
17
+ <script type="text/javascript">
18
+ //<![CDATA[
19
+ function toggleTranssmartBookAndPrintCheckbox() {
20
+ $('transsmart_book').disabled = $('transsmart_bookandprint').checked;
21
+ if ($('transsmart_bookandprint').checked) {
22
+ $('transsmart_book').checked = true;
23
+ }
24
+ }
25
+ //]]>
26
+ </script>
app/design/adminhtml/base/default/template/transsmart/shipping/sales/order/shipment/create/detail.phtml ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Transsmart
4
+ * @package Transsmart_Shipping
5
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
6
+ */
7
+ ?>
8
+ <?php /** @var Transsmart_Shipping_Block_Adminhtml_Sales_Order_Shipment_Create_Detail $this */ ?>
9
+ <table cellspacing="0" class="form-list transsmart-shipment-detail">
10
+ <tbody>
11
+ <tr>
12
+ <td class="label"><label for="tss_carrierprofile"><?php echo $this->__('Carrier Profile'); ?> <span class="required">*</span></label></td>
13
+ <td class="value" colspan="3">
14
+ <?php if ($this->getAllowChangeCarrierprofile()): ?>
15
+ <select id="tss_carrierprofile" name="shipment[transsmart_carrierprofile_id]" class="required-entry select">
16
+ <?php foreach ($this->getAvailableCarrierprofiles() as $_key => $_label): ?>
17
+ <option value="<?php echo $_key; ?>"<?php if ($_key == $this->getDefaultCarrierprofileId()): ?> selected="selected"<?php endif; ?>>
18
+ <?php echo $this->escapeHtml($_label); ?>
19
+ </option>
20
+ <?php endforeach; ?>
21
+ </select>
22
+ <?php else: ?>
23
+ <strong><?php echo $this->escapeHtml($this->getDefaultCarrierprofile()); ?></strong>
24
+ <?php endif; ?>
25
+ </td>
26
+ </tr>
27
+ <tr>
28
+ <td class="label"><label for="tss_shipmentlocation"><?php echo $this->__('Shipment Location'); ?> <span class="required">*</span></label></td>
29
+ <td class="value">
30
+ <select id="tss_shipmentlocation" name="shipment[transsmart_shipmentlocation_id]" class="required-entry select">
31
+ <?php foreach ($this->getShipmentlocations() as $_key => $_label): ?>
32
+ <option value="<?php echo $_key; ?>"<?php if ($_key == $this->getDefaultShipmentlocationId()): ?> selected="selected"<?php endif; ?>>
33
+ <?php echo $this->escapeHtml($_label); ?>
34
+ </option>
35
+ <?php endforeach; ?>
36
+ </select>
37
+ </td>
38
+ <td class="label"><label for="tss_emailtype"><?php echo $this->__('Email Type'); ?> <span class="required">*</span></label></td>
39
+ <td class="value">
40
+ <select id="tss_emailtype" name="shipment[transsmart_emailtype_id]" class="required-entry select">
41
+ <?php foreach ($this->getEmailtypes() as $_key => $_label): ?>
42
+ <option value="<?php echo $_key; ?>"<?php if ($_key == $this->getDefaultEmailtypeId()): ?> selected="selected"<?php endif; ?>>
43
+ <?php echo $this->escapeHtml($_label); ?>
44
+ </option>
45
+ <?php endforeach; ?>
46
+ </select>
47
+ </td>
48
+ </tr>
49
+ <tr>
50
+ <td class="label"><label for="tss_costcenter"><?php echo $this->__('Cost Center'); ?> <span class="required">*</span></label></td>
51
+ <td class="value">
52
+ <select id="tss_costcenter" name="shipment[transsmart_costcenter_id]" class="required-entry select">
53
+ <?php foreach ($this->getCostcenters() as $_key => $_label): ?>
54
+ <option value="<?php echo $_key; ?>"<?php if ($_key == $this->getDefaultCostcenterId()): ?> selected="selected"<?php endif; ?>>
55
+ <?php echo $this->escapeHtml($_label); ?>
56
+ </option>
57
+ <?php endforeach; ?>
58
+ </select>
59
+ </td>
60
+ <td class="label"><label for="tss_incoterm"><?php echo $this->__('Incoterm'); ?> <span class="required">*</span></label></td>
61
+ <td class="value">
62
+ <select id="tss_incoterm" name="shipment[transsmart_incoterm]" class="required-entry select">
63
+ <?php foreach ($this->getIncoterms() as $_key => $_label): ?>
64
+ <option value="<?php echo $_key; ?>"<?php if ($_key == $this->getDefaultIncotermId()): ?> selected="selected"<?php endif; ?>>
65
+ <?php echo $this->escapeHtml($_label); ?>
66
+ </option>
67
+ <?php endforeach; ?>
68
+ </select>
69
+ </td>
70
+ </tr>
71
+ </tbody>
72
+ </table>
73
+ <script type="text/javascript">
74
+ //<![CDATA[
75
+ (function () {
76
+ var origCarrierprofileId = $('tss_carrierprofile').value, confirmed = false;
77
+ $('tss_carrierprofile').observe('change', function () {
78
+ if (this.value != origCarrierprofileId && !confirmed) {
79
+ if (confirm('<?php echo $this->jsQuoteEscape($this->__('Please note! The carrier profile will be changed. This change will NOT be made to the Magento order. This could affect the calculated shipping costs and tracking and tracing emails. Do you want to continue?')); ?>')) {
80
+ confirmed = true;
81
+ }
82
+ else {
83
+ this.value = origCarrierprofileId;
84
+ }
85
+ }
86
+ });
87
+ })();
88
+ //]]>
89
+ </script>
90
+
91
+ <?php echo $this->getChildHtml('package'); ?>
app/design/adminhtml/base/default/template/transsmart/shipping/sales/order/shipment/create/package.phtml ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Transsmart
4
+ * @package Transsmart_Shipping
5
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
6
+ */
7
+ ?>
8
+ <?php /** @var Transsmart_Shipping_Block_Adminhtml_Sales_Order_Shipment_Create_Package $this */ ?>
9
+ <script type="text/javascript">
10
+ //<![CDATA[
11
+ var tssPackageControl = {
12
+ index: 0,
13
+ init: function (config) {
14
+ this.config = config;
15
+ Event.observe(document, 'dom:loaded', this.add.bind(this));
16
+ },
17
+ add: function () {
18
+ this.index++;
19
+ var data = {index:this.index};
20
+ Element.insert($('tss_package_row_container'), {bottom: this.template.evaluate(data)});
21
+ this.initPackageType();
22
+ this.updateRowCount();
23
+ },
24
+ deleteRow: function (event) {
25
+ var row = Event.findElement(event, 'tr');
26
+ if (row) {
27
+ row.parentNode.removeChild(row);
28
+ this.updateRowCount();
29
+ }
30
+ },
31
+ updateRowCount: function () {
32
+ $('tss_package_table_row_count').value = $('tss_package_table').select('.select').length - 1;
33
+ },
34
+ initPackageType: function () {
35
+ var elems = $('tss_package_table').select('.select');
36
+ elems.each(function (elem) {
37
+ if (!elem.tssInitialized) {
38
+ elem.tssInitialized = true;
39
+ for (var i = 0; i < this.config.types.length; i++) {
40
+ var option = document.createElement('option');
41
+ option.value = this.config.types[i].id;
42
+ option.text = this.config.types[i].name;
43
+ if (this.config.default == option.value) {
44
+ option.selected = true;
45
+ }
46
+ elem.add(option);
47
+ }
48
+ elem.observe('change', this.packageTypeOnchange.bind(this));
49
+ this.fillDefaults(elem);
50
+ }
51
+ }.bind(this));
52
+ },
53
+ packageTypeOnchange: function (event) {
54
+ var elem = Event.element(event);
55
+ this.fillDefaults(elem);
56
+ },
57
+ fillDefaults: function (elem) {
58
+ var index = elem.id.substr('tss_packageT'.length);
59
+ var option = parseInt(elem.options[elem.selectedIndex].value, 10);
60
+
61
+ for (var i = 0; i < this.config.types.length; i++) {
62
+ if (this.config.types[i].id == option) {
63
+ $('tss_packageL' + index).disabled = (!option);
64
+ Element[(option ? 'remove' : 'add') + 'ClassName']('tss_packageL' + index, 'disabled');
65
+ $('tss_packageW' + index).disabled = (!option);
66
+ Element[(option ? 'remove' : 'add') + 'ClassName']('tss_packageW' + index, 'disabled');
67
+ $('tss_packageH' + index).disabled = (!option);
68
+ Element[(option ? 'remove' : 'add') + 'ClassName']('tss_packageH' + index, 'disabled');
69
+ $('tss_packageK' + index).disabled = (!option);
70
+ Element[(option ? 'remove' : 'add') + 'ClassName']('tss_packageK' + index, 'disabled');
71
+
72
+ $('tss_packageL' + index).value = option ? this.config.types[i].length : '';
73
+ $('tss_packageW' + index).value = option ? this.config.types[i].width : '';
74
+ $('tss_packageH' + index).value = option ? this.config.types[i].height : '';
75
+ $('tss_packageK' + index).value = option ? this.config.types[i].weight : '';
76
+ break;
77
+ }
78
+ }
79
+ }
80
+ };
81
+ Validation.add('tss-validate-package-table-row-count', 'Please add at lease one package.', function (v) {
82
+ v = parseInt(v, 10);
83
+ return !isNaN(v) && v > 0;
84
+ });
85
+ //]]>
86
+ </script>
87
+ <div class="grid">
88
+ <table cellspacing="0" class="data" id="tss_package_table">
89
+ <colgroup>
90
+ <col />
91
+ <col />
92
+ <col />
93
+ <col />
94
+ <col />
95
+ <col />
96
+ <col width="80" />
97
+ </colgroup>
98
+ <thead>
99
+ <tr class="headings">
100
+ <th><?php echo $this->__('Package Type') ?></th>
101
+ <th><?php echo Mage::helper('sales')->__('Qty') ?> <span class="required">*</span></th>
102
+ <th><?php echo $this->__('Length (cm)') ?> <span class="required">*</span></th>
103
+ <th><?php echo $this->__('Width (cm)') ?> <span class="required">*</span></th>
104
+ <th><?php echo $this->__('Height (cm)') ?> <span class="required">*</span></th>
105
+ <th><?php echo $this->__('Weight (Kg)') ?> <span class="required">*</span></th>
106
+ <th class="last"><?php echo Mage::helper('sales')->__('Action') ?></th>
107
+ </tr>
108
+ </thead>
109
+ <tfoot>
110
+ <tr>
111
+ <td colspan="7" class="a-center last" style="padding:8px;"><?php echo $this->getChildHtml('add_button') ?></td>
112
+ </tr>
113
+ </tfoot>
114
+ <tbody id="tss_package_row_container">
115
+ <tr id="tss_package_row_template" class="template no-display">
116
+ <td><select name="shipment[transsmart_package][__index__][package_type]" id="tss_packageT__index__" class="select" style="width:110px;"></select></td>
117
+ <td><input class="input-text required-entry validate-greater-than-zero validate-digits" type="text" name="shipment[transsmart_package][__index__][qty]" id="tss_packageQ__index__" value="1" /></td>
118
+ <td><input class="input-text required-entry validate-greater-than-zero" type="text" name="shipment[transsmart_package][__index__][length]" id="tss_packageL__index__" value="" /></td>
119
+ <td><input class="input-text required-entry validate-greater-than-zero" type="text" name="shipment[transsmart_package][__index__][width]" id="tss_packageW__index__" value="" /></td>
120
+ <td><input class="input-text required-entry validate-greater-than-zero" type="text" name="shipment[transsmart_package][__index__][height]" id="tss_packageH__index__" value="" /></td>
121
+ <td><input class="input-text required-entry validate-greater-than-zero" type="text" name="shipment[transsmart_package][__index__][weight]" id="tss_packageK__index__" value="" /></td>
122
+ <td class="last"><a href="#" onclick="tssPackageControl.deleteRow(event);return false"><?php echo Mage::helper('sales')->__('Delete') ?></a></td>
123
+ </tr>
124
+ </tbody>
125
+ </table>
126
+ <input type="hidden" class="tss-validate-package-table-row-count" id="tss_package_table_row_count" value="0" />
127
+ </div>
128
+ <script type="text/javascript">
129
+ //<![CDATA[
130
+ Translator.add('Please add at lease one package.', '<?php echo $this->jsQuoteEscape($this->__('Please add at lease one package.')); ?>');
131
+ tssPackageControl.template = new Template('<tr>' + $('tss_package_row_template').innerHTML.replace(/__index__/g, '#{index}') + '<\/tr>');
132
+ tssPackageControl.init(<?php echo Mage::helper('core')->jsonEncode($this->getPackageConfig()); ?>);
133
+ //]]>
134
+ </script>
app/design/adminhtml/base/default/template/transsmart/shipping/sales/order/shipment/masscreate/form.phtml ADDED
@@ -0,0 +1,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Transsmart
4
+ * @package Transsmart_Shipping
5
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
6
+ */
7
+ ?>
8
+ <?php /** @var Transsmart_Shipping_Block_Adminhtml_Sales_Order_Shipment_Masscreate_Form $this */ ?>
9
+ <form id="edit_form" method="post" action="<?php echo $this->getSaveUrl() ?>">
10
+ <?php echo $this->getBlockHtml('formkey')?>
11
+
12
+ <div>
13
+ <?php /** @var Mage_Sales_Model_Order $_order */ ?>
14
+ <?php foreach ($this->getOrderCollection() as $_order): ?>
15
+ <input type="hidden" name="order_qty[<?php echo $_order->getId(); ?>]" value="<?php echo $this->getQtyToShip($_order); ?>" />
16
+ <?php endforeach; ?>
17
+ </div>
18
+
19
+ <div class="box-left">
20
+ <div class="entry-edit">
21
+ <div class="entry-edit-head">
22
+ <h4 class="icon-head head-transsmart-shipping-details"><?php echo $this->__('Transsmart Shipping Details'); ?></h4>
23
+ </div>
24
+ <fieldset>
25
+ <div>
26
+ <table cellspacing="0" class="form-list transsmart-shipment-detail">
27
+ <tbody>
28
+ <tr>
29
+ <td class="label"><label for="tss_carrierprofile"><?php echo $this->__('Carrier Profile'); ?> <span class="required">*</span></label></td>
30
+ <td class="value" colspan="3">
31
+ <select id="tss_carrierprofile" name="shipment[transsmart_carrierprofile_id]" class="required-entry select">
32
+ <option value="0" selected="selected"><?php echo $this->escapeHtml($this->__('Determine Automatically')); ?></option>
33
+ <?php foreach ($this->getAvailableCarrierprofiles() as $_key => $_label): ?>
34
+ <option value="<?php echo $_key; ?>">
35
+ <?php echo $this->escapeHtml($_label); ?>
36
+ </option>
37
+ <?php endforeach; ?>
38
+ </select><br/>
39
+ <p class="note"><span><?php echo $this->__('This does not affect shipments using a pickup option.'); ?></span></p>
40
+ </td>
41
+ </tr>
42
+ <tr>
43
+ <td class="label"><label for="tss_shipment_location"><?php echo $this->__('Shipment Location'); ?> <span class="required">*</span></label></td>
44
+ <td class="value">
45
+ <select id="tss_shipment_location" name="shipment[transsmart_shipmentlocation_id]" class="required-entry select">
46
+ <option value="0" selected="selected"><?php echo $this->escapeHtml($this->__('Use Configured Default')); ?></option>
47
+ <?php foreach ($this->getShipmentlocations() as $_value => $_label): ?>
48
+ <option value="<?php echo $_value; ?>"><?php echo $this->escapeHtml($_label); ?></option>
49
+ <?php endforeach; ?>
50
+ </select>
51
+ </td>
52
+ <td class="label"><label for="tss_email_type"><?php echo $this->__('Email Type'); ?> <span class="required">*</span></label></td>
53
+ <td class="value">
54
+ <select id="tss_email_type" name="shipment[transsmart_emailtype_id]" class="required-entry select">
55
+ <option value="0" selected="selected"><?php echo $this->escapeHtml($this->__('Use Configured Default')); ?></option>
56
+ <?php foreach ($this->getEmailtypes() as $_value => $_label): ?>
57
+ <option value="<?php echo $_value; ?>"><?php echo $this->escapeHtml($_label); ?></option>
58
+ <?php endforeach; ?>
59
+ </select>
60
+ </td>
61
+ </tr>
62
+ <tr>
63
+ <td class="label"><label for="tss_cost_center"><?php echo $this->__('Cost Center'); ?> <span class="required">*</span></label></td>
64
+ <td class="value">
65
+ <select id="tss_cost_center" name="shipment[transsmart_costcenter_id]" class="required-entry select">
66
+ <option value="0" selected="selected"><?php echo $this->escapeHtml($this->__('Use Configured Default')); ?></option>
67
+ <?php foreach ($this->getCostcenters() as $_value => $_label): ?>
68
+ <option value="<?php echo $_value; ?>"><?php echo $this->escapeHtml($_label); ?></option>
69
+ <?php endforeach; ?>
70
+ </select>
71
+ </td>
72
+ <td class="label"><label for="tss_incoterm"><?php echo $this->__('Incoterm'); ?> <span class="required">*</span></label></td>
73
+ <td class="value">
74
+ <select id="tss_incoterm" name="shipment[transsmart_incoterm]" class="required-entry select">
75
+ <option value="0" selected="selected"><?php echo $this->escapeHtml($this->__('Use Configured Default')); ?></option>
76
+ <?php foreach ($this->getIncoterms() as $_value => $_label): ?>
77
+ <option value="<?php echo $_value; ?>"><?php echo $this->escapeHtml($_label); ?></option>
78
+ <?php endforeach; ?>
79
+ </select>
80
+ </td>
81
+ </tr>
82
+ </tbody>
83
+ </table>
84
+ <script type="text/javascript">
85
+ //<![CDATA[
86
+ (function () {
87
+ var origCarrierprofileId = $('tss_carrierprofile').value, confirmed = false;
88
+ $('tss_carrierprofile').observe('change', function () {
89
+ if (this.value != origCarrierprofileId && !confirmed) {
90
+ if (confirm('<?php echo $this->jsQuoteEscape($this->__('Please note! The carrier profile will be changed. This change will NOT be made to the Magento order. This could affect the calculated shipping costs and tracking and tracing emails. Do you want to continue?')); ?>')) {
91
+ confirmed = true;
92
+ }
93
+ else {
94
+ this.value = origCarrierprofileId;
95
+ }
96
+ }
97
+ });
98
+ })();
99
+ //]]>
100
+ </script>
101
+
102
+ <?php echo $this->getChildHtml('package'); ?>
103
+ </div>
104
+ </fieldset>
105
+ </div>
106
+ </div>
107
+ <div class="box-right">
108
+ <div class="entry-edit">
109
+ <div class="entry-edit-head">
110
+ <h4 class="icon-head head-orders-summary"><?php echo $this->__('Summary') ?></h4>
111
+ </div>
112
+ <fieldset>
113
+ <table cellspacing="0" class="form-list">
114
+ <tbody>
115
+ <tr>
116
+ <td class="label"><?php echo $this->__('Selected Orders'); ?></td>
117
+ <td class="value"><strong><?php echo $this->getTotalOrderCount(); ?></strong></td>
118
+ </tr>
119
+ <tr>
120
+ <td class="label"><?php echo $this->__('Shipments To Create'); ?></td>
121
+ <td class="value"><strong><?php echo $this->getTotalShipmentsToCreate(); ?></strong></td>
122
+ </tr>
123
+ <tr>
124
+ <td class="label"><?php echo $this->__('Qty to Ship'); ?></td>
125
+ <td class="value"><strong><?php echo $this->getTotalQtyToShip(); ?></strong></td>
126
+ </tr>
127
+ </tbody>
128
+ </table>
129
+ </fieldset>
130
+ </div>
131
+ </div>
132
+ <div class="clear"></div>
133
+
134
+ <div class="entry-edit">
135
+ <div class="entry-edit-head">
136
+ <h4 class="icon-head head-orders"><?php echo $this->__('Shipments To Create') ?></h4>
137
+ </div>
138
+ </div>
139
+ <div class="grid np">
140
+ <div class="hor-scroll">
141
+ <table cellspacing="0" class="data order-tables">
142
+ <colgroup>
143
+ <col />
144
+ <col />
145
+ <col />
146
+ <col />
147
+ <col />
148
+ <col />
149
+ </colgroup>
150
+ <thead>
151
+ <tr class="headings">
152
+ <th><?php echo Mage::helper('sales')->__('Order #'); ?></th>
153
+ <th><?php echo Mage::helper('sales')->__('Order Date'); ?></th>
154
+ <th><?php echo Mage::helper('sales')->__('Ship to Name'); ?></th>
155
+ <th><?php echo Mage::helper('sales')->__('Shipping Method'); ?></th>
156
+ <th class="a-right"><?php echo Mage::helper('sales')->__('Quantity Ordered'); ?></th>
157
+ <th class="a-right last"><?php echo Mage::helper('sales')->__('Qty to Ship'); ?></th>
158
+ </tr>
159
+ </thead>
160
+ <tbody>
161
+ <?php /** @var Mage_Sales_Model_Order $_order */ ?>
162
+ <?php $i = 0; foreach ($this->getOrderCollection() as $_order): ?>
163
+ <tr class="border <?php echo ($i % 2) ? 'odd' : 'even'; ?>">
164
+ <td><?php echo $_order->getIncrementId(); ?></td>
165
+ <td><?php echo $_order->getCreatedAtFormated(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); ?></td>
166
+ <td><?php echo $this->escapeHtml($_order->getShippingAddress()->getName()); ?></td>
167
+ <td><?php echo $this->escapeHtml($_order->getShippingDescription()); ?></td>
168
+ <td class="a-right"><?php echo 1*$_order->getTotalQtyOrdered(); ?></td>
169
+ <td class="a-right last"><?php echo $this->getQtyToShip($_order); ?></td>
170
+ </tr>
171
+ <?php $i++; endforeach; ?>
172
+ </tbody>
173
+ </table>
174
+ </div>
175
+ </div>
176
+ <br />
177
+
178
+ <div class="box-left entry-edit">
179
+ <div class="entry-edit-head"><h4><?php echo Mage::helper('sales')->__('Shipment Comments') ?></h4></div>
180
+ <fieldset>
181
+ <div id="order-history_form">
182
+ <span class="field-row">
183
+ <label class="normal" for="shipment_comment_text"><?php echo Mage::helper('sales')->__('Shipment Comments') ?></label>
184
+ <textarea id="shipment_comment_text" name="shipment[comment_text]" rows="3" cols="5" style="height:6em; width:99%;"></textarea>
185
+ </span>
186
+ <div class="clear"></div>
187
+ </div>
188
+ </fieldset>
189
+ </div>
190
+
191
+ <div class="box-right entry-edit">
192
+ <div class="order-totals">
193
+ <div class="order-totals-bottom">
194
+ <p>
195
+ <label class="normal" for="notify_customer"><?php echo Mage::helper('sales')->__('Append Comments') ?></label>
196
+ <input id="notify_customer" name="shipment[comment_customer_notify]" value="1" type="checkbox" />
197
+ </p>
198
+ <p>
199
+ <label class="normal" for="send_email"><?php echo Mage::helper('sales')->__('Email Copy of Shipment') ?></label>
200
+ <input id="send_email" name="shipment[send_email]" value="1" type="checkbox" />
201
+ </p>
202
+ <div class="a-right">
203
+ <?php echo $this->getChildHtml('action') ?>
204
+ <?php echo $this->getChildHtml('submit_button') ?>
205
+ </div>
206
+ </div>
207
+ </div>
208
+ </div>
209
+ <div class="clear"></div>
210
+ </form>
211
+ <script type="text/javascript">
212
+ //<![CDATA[
213
+ editForm = new varienForm('edit_form');
214
+ var sendEmailCheckbox = $('send_email');
215
+ if (sendEmailCheckbox) {
216
+ var notifyCustomerCheckbox = $('notify_customer');
217
+ var shipmentCommentText = $('shipment_comment_text');
218
+ Event.observe(sendEmailCheckbox, 'change', bindSendEmail);
219
+ bindSendEmail();
220
+ }
221
+ function bindSendEmail() {
222
+ if (sendEmailCheckbox.checked == true) {
223
+ notifyCustomerCheckbox.disabled = false;
224
+ }
225
+ else {
226
+ notifyCustomerCheckbox.disabled = true;
227
+ }
228
+ }
229
+ function submitShipment(btn) {
230
+ if (editForm.submit()) {
231
+ disableElements('submit-button');
232
+ }
233
+ }
234
+ //]]>
235
+ </script>
app/design/adminhtml/base/default/template/transsmart/shipping/sales/order/shipment/view/detail.phtml ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Transsmart
4
+ * @package Transsmart_Shipping
5
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
6
+ */
7
+ ?>
8
+ <?php /** @var Transsmart_Shipping_Block_Adminhtml_Sales_Order_Shipment_View_Detail $this */ ?>
9
+ <table cellspacing="0" class="form-list transsmart-shipment-detail">
10
+ <tbody>
11
+ <tr>
12
+ <td class="label"><label><?php echo $this->escapeHtml($this->__('Carrier Profile')); ?></label></td>
13
+ <td class="value" colspan="3"><strong><?php echo $this->escapeHtml($this->getCarrierprofile()); ?></strong></td>
14
+ </tr>
15
+ <tr>
16
+ <td class="label"><label><?php echo $this->escapeHtml($this->__('Shipment Location')); ?></label></td>
17
+ <td class="value"><strong><?php echo $this->escapeHtml($this->getShipmentlocation()); ?></strong></td>
18
+ <td class="label"><label><?php echo $this->escapeHtml($this->__('Email Type')); ?></label></td>
19
+ <td class="value"><strong><?php echo $this->escapeHtml($this->getEmailtype()); ?></strong></td>
20
+ </tr>
21
+ <tr>
22
+ <td class="label"><label><?php echo $this->escapeHtml($this->__('Cost Center')); ?></label></td>
23
+ <td class="value"><strong><?php echo $this->escapeHtml($this->getCostcenter()); ?></strong></td>
24
+ <td class="label"><label><?php echo $this->escapeHtml($this->__('Incoterm')); ?></label></td>
25
+ <td class="value"><strong><?php echo $this->escapeHtml($this->getIncoterm()); ?></strong></td>
26
+ </tr>
27
+ </tbody>
28
+ </table>
29
+
30
+ <?php echo $this->getChildHtml('package'); ?>
31
+
32
+ <table cellspacing="0" class="form-list transsmart-shipment-detail-extra">
33
+ <tbody>
34
+ <tr>
35
+ <td class="label"><label><?php echo $this->escapeHtml($this->__('Transsmart Document Id')); ?></label></td>
36
+ <td class="value"><strong><?php echo $this->escapeHtml($this->getTranssmartDocumentId()); ?></strong></td>
37
+ </tr>
38
+ <tr>
39
+ <td class="label"><label><?php echo $this->escapeHtml($this->__('Transsmart Status')); ?></label></td>
40
+ <td class="value"><strong><?php echo $this->escapeHtml($this->getTranssmartStatus()); ?></strong></td>
41
+ </tr>
42
+ <tr>
43
+ <td class="label"><label><?php echo $this->escapeHtml($this->__('Track & Trace')); ?></label></td>
44
+ <td class="value"><strong><?php echo $this->getTrackingLink(); ?></strong></td>
45
+ </tr>
46
+ </tbody>
47
+ </table>
app/design/adminhtml/base/default/template/transsmart/shipping/sales/order/shipment/view/package.phtml ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Transsmart
4
+ * @package Transsmart_Shipping
5
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
6
+ */
7
+ ?>
8
+ <?php /** @var Transsmart_Shipping_Block_Adminhtml_Sales_Order_Shipment_View_Package $this */ ?>
9
+ <div class="grid">
10
+ <table cellspacing="0" class="data" id="tss_package_table">
11
+ <colgroup>
12
+ <col />
13
+ <col />
14
+ <col />
15
+ <col />
16
+ <col />
17
+ <col />
18
+ </colgroup>
19
+ <thead>
20
+ <tr class="headings">
21
+ <th><?php echo $this->__('Package Type') ?></th>
22
+ <th><?php echo Mage::helper('sales')->__('Qty') ?></th>
23
+ <th><?php echo $this->__('Length (cm)') ?></th>
24
+ <th><?php echo $this->__('Width (cm)') ?></th>
25
+ <th><?php echo $this->__('Height (cm)') ?></th>
26
+ <th class="last"><?php echo $this->__('Weight (Kg)') ?></th>
27
+ </tr>
28
+ </thead>
29
+ <tbody id="tss_package_row_container">
30
+ <?php foreach ($this->getFormattedPackageLines() as $_index => $_line): ?>
31
+ <tr class="border <?php echo ($_index % 2) ? 'odd' : 'even'; ?>">
32
+ <td><strong><?php echo $this->escapeHtml($_line['package_type']); ?></strong></td>
33
+ <td><?php echo $this->escapeHtml($_line['qty']); ?></td>
34
+ <td><?php echo $this->escapeHtml($_line['length']); ?></td>
35
+ <td><?php echo $this->escapeHtml($_line['width']); ?></td>
36
+ <td><?php echo $this->escapeHtml($_line['height']); ?></td>
37
+ <td class="last"><?php echo $this->escapeHtml($_line['weight']); ?></td>
38
+ </tr>
39
+ <?php endforeach; ?>
40
+ </tbody>
41
+ </table>
42
+ </div>
app/design/adminhtml/base/default/template/transsmart/shipping/system/config/form/field/fetch.phtml ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Transsmart
4
+ * @package Transsmart_Shipping
5
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
6
+ */
7
+ ?>
8
+ <?php /** @var Transsmart_Shipping_Block_Adminhtml_System_Config_Form_Field_Fetch $this */ ?>
9
+ <?php if ($this->useContainer()): ?>
10
+ <tr id="row_<?php echo $this->getHtmlId() ?>">
11
+ <td colspan="2">
12
+ <div class="comment" id="<?php echo $this->getHtmlId() ?>">
13
+ <?php endif; ?>
14
+ <ul class="messages">
15
+ <li class="<?php echo $this->getMessageClass() ?>">
16
+ <ul>
17
+ <li>
18
+ <?php if ($this->showFetchButton()): ?>
19
+ <div style="float:right"><?php echo $this->getFetchButtonHtml() ?></div>
20
+ <?php endif; ?>
21
+ <span><?php echo nl2br($this->escapeHtml($this->getMessageText())) ?></span>
22
+ </li>
23
+ </ul>
24
+ </li>
25
+ </ul>
26
+ <?php if ($this->useContainer()): ?>
27
+ </div>
28
+ </td>
29
+ </tr>
30
+ <script type="text/javascript">
31
+ //<![CDATA[
32
+ /**
33
+ * Disable the 'Fetch Now' button when connection settings are changed (need to save first).
34
+ * @param string htmlId
35
+ */
36
+ function transsmart_enableFetch(htmlId) {
37
+ var table = $(htmlId).up('table');
38
+ var inputs = table.select('input, select');
39
+ var initialValues = inputs.collect(function (e) { return e.getValue(); });
40
+
41
+ var check = function () {
42
+ var button = $(htmlId + '_button');
43
+ if (!button) {
44
+ return;
45
+ }
46
+
47
+ var newValues = inputs.collect(function (e) { return e.getValue(); });
48
+
49
+ // compare values
50
+ var diff = false;
51
+ for (var i = 0; i < initialValues.length; i++) {
52
+ if (newValues[i] != initialValues[i]) {
53
+ diff = true;
54
+ break;
55
+ }
56
+ }
57
+
58
+ // update 'Fetch Now' button state
59
+ if (diff) {
60
+ button.addClassName('disabled');
61
+ button.disabled = true;
62
+ }
63
+ else {
64
+ button.removeClassName('disabled');
65
+ button.disabled = false;
66
+ }
67
+ };
68
+
69
+ inputs.invoke('observe', 'change', check);
70
+ inputs.invoke('observe', 'keyup', check);
71
+ check();
72
+ }
73
+ Event.observe(document, 'dom:loaded', function () {
74
+ transsmart_enableFetch('<?php echo $this->getHtmlId() ?>');
75
+ });
76
+
77
+ function transsmart_fetchBaseData(htmlId) {
78
+ // disable the 'Fetch Now' button during the ajax request
79
+ var button = $(htmlId + '_button');
80
+ var result = $(htmlId);
81
+ button.disabled = true;
82
+ button.addClassName('disabled');
83
+
84
+ new Ajax.Request('<?php echo $this->jsQuoteEscape($this->getFetchUrl()); ?>', {
85
+ method: 'get',
86
+ onSuccess: function (transport) {
87
+ button.disabled = false;
88
+ button.removeClassName('disabled');
89
+ result.innerHTML = transport.responseText;
90
+ },
91
+ onFailure: function () {
92
+ button.disabled = false;
93
+ button.removeClassName('disabled');
94
+ var message = '<?php echo $this->jsQuoteEscape($this->__('Unknown error')); ?>';
95
+ alert(message);
96
+ }
97
+ });
98
+ }
99
+ //]]>
100
+ </script>
101
+ <?php endif; ?>
app/design/frontend/base/default/layout/transsmart_shipping.xml ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ -->
9
+ <layout>
10
+ <checkout_onepage_index>
11
+ <reference name="head">
12
+ <action method="addLinkRel"><rel>stylesheet</rel><href>//fonts.googleapis.com/css?family=Dosis:500,600</href></action>
13
+ <action method="addJs">
14
+ <script>transsmart/shipping/base64.js</script>
15
+ </action>
16
+ <action method="addJs">
17
+ <script>transsmart/shipping/logger.js</script>
18
+ </action>
19
+ <action method="addJs">
20
+ <script>transsmart/shipping/pickup_selector.js</script>
21
+ </action>
22
+ <action method="addCss">
23
+ <style>transsmart/shipping/pickup_selector.css</style>
24
+ </action>
25
+ </reference>
26
+
27
+ <reference name="before_body_end">
28
+ <block type="transsmart_shipping/location_selector"
29
+ template="transsmart/shipping/location/selector.phtml"
30
+ name="transsmart_shipping.location.selector" />
31
+ </reference>
32
+ </checkout_onepage_index>
33
+
34
+ <checkout_onepage_progress_shipping_method>
35
+ <block type="checkout/onepage_progress" name="transsmart_shipping.location.selector.progress"
36
+ output="toHtml"
37
+ template="transsmart/shipping/onepage/progress/pickup.phtml">
38
+
39
+ <action method="setInfoTemplate"><method></method><template></template></action>
40
+ </block>
41
+ </checkout_onepage_progress_shipping_method>
42
+
43
+ <onestepcheckout_index_index>
44
+ <reference name="head">
45
+ <action method="addLinkRel"><rel>stylesheet</rel><href>//fonts.googleapis.com/css?family=Dosis:500,600</href></action>
46
+ <action method="addJs">
47
+ <script>transsmart/shipping/base64.js</script>
48
+ </action>
49
+ <action method="addJs">
50
+ <script>transsmart/shipping/logger.js</script>
51
+ </action>
52
+ <action method="addJs">
53
+ <script>transsmart/shipping/pickup_selector.js</script>
54
+ </action>
55
+ <action method="addCss">
56
+ <style>transsmart/shipping/pickup_selector.css</style>
57
+ </action>
58
+ </reference>
59
+
60
+ <reference name="before_body_end">
61
+ <block type="transsmart_shipping/location_selector"
62
+ template="transsmart/shipping/location/selector.phtml"
63
+ name="transsmart_shipping.location.selector" />
64
+ </reference>
65
+ </onestepcheckout_index_index>
66
+
67
+ <gomage_checkout_onepage_index>
68
+ <reference name="head">
69
+ <action method="addLinkRel"><rel>stylesheet</rel><href>//fonts.googleapis.com/css?family=Dosis:500,600</href></action>
70
+ <action method="addJs">
71
+ <script>transsmart/shipping/base64.js</script>
72
+ </action>
73
+ <action method="addJs">
74
+ <script>transsmart/shipping/logger.js</script>
75
+ </action>
76
+ <action method="addJs">
77
+ <script>transsmart/shipping/pickup_selector.js</script>
78
+ </action>
79
+ <action method="addCss">
80
+ <style>transsmart/shipping/pickup_selector.css</style>
81
+ </action>
82
+ </reference>
83
+
84
+ <reference name="before_body_end">
85
+ <block type="transsmart_shipping/location_selector"
86
+ template="transsmart/shipping/location/selector.phtml"
87
+ name="transsmart_shipping.location.selector" />
88
+ </reference>
89
+ </gomage_checkout_onepage_index>
90
+ </layout>
app/design/frontend/base/default/template/transsmart/shipping/location/selector.phtml ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Transsmart
4
+ * @package Transsmart_Shipping
5
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
6
+ */
7
+ ?>
8
+ <?php /** @var Transsmart_Shipping_Block_Location_Selector $this */ ?>
9
+ <?php $helper = Mage::helper('transsmart_shipping'); ?>
10
+
11
+ <div id="tss-pickup-container" style="display: none;">
12
+ <div class="tss-selector">
13
+ <div class="tss-selector-inner">
14
+ <button id="tss-ls-close"></button>
15
+ <div class="tss-loader">
16
+ <img src="<?php echo $this->getSkinUrl('transsmart/shipping/images/loader.gif'); ?>" />
17
+ </div>
18
+
19
+ <div class="tss-selector-container" style="display: none">
20
+ <div class="tss-ls-header">
21
+ <span class="tss-ls-header-title"><?php echo $helper->__('Select pickup location'); ?></span>
22
+ <div class="tss-ls-search-wrapper">
23
+ <input type="text" id="tss-ls-search" placeholder="<?php echo $helper->__('1234 AB'); ?>" />
24
+ <button type="button" id="tss-ls-search-btn"><?php echo $helper->__('Search'); ?></button>
25
+ </div>
26
+ <div class="tss-ls-options">
27
+ <div class="tss-ls-checkbox-wrapper">
28
+ <input type="checkbox" id="tss-ls-show-open-late" name="tss-ls-show-open-late" /> <label for="tss-ls-show-open-late"><?php echo $helper->__('Open late'); ?></label>
29
+ </div>
30
+ <div class="tss-ls-checkbox-wrapper">
31
+ <input type="checkbox" id="tss-ls-show-open-early" name="tss-ls-show-open-early" /> <label for="tss-ls-show-open-early"><?php echo $helper->__('Open early'); ?></label>
32
+ </div>
33
+ <div class="tss-ls-checkbox-wrapper">
34
+ <input type="checkbox" id="tss-ls-show-open-sunday" name="tss-ls-show-open-sunday" /> <label for="tss-ls-show-open-sunday"><?php echo $helper->__('Open on sunday'); ?></label>
35
+ </div>
36
+ </div>
37
+ </div>
38
+
39
+ <div class="tss-ls-content">
40
+ <div class="tss-ls-map-container">
41
+ <div id="tss-ls-map"></div>
42
+ </div>
43
+ <div class="tss-ls-location-wrapper">
44
+ <h3><?php echo $helper->__('Found pickup locations:'); ?></h3>
45
+ <div id="tss-ls-locations"></div>
46
+ </div>
47
+ </div>
48
+ <div class="tss-ls-footer-controls">
49
+ <button id="tss-ls-select"><?php echo $helper->__('Save'); ?></button>
50
+ </div>
51
+ </div>
52
+ </div>
53
+ </div>
54
+
55
+ <div class="tss-background-overlay"></div>
56
+ </div>
57
+
58
+ <script type="text/javascript">
59
+ var transsmartShippingPickup = new Transsmart.Shipping.Pickup({
60
+ lookupUrl: '<?php echo $this->getUrl('transsmart_shipping/location/lookup'); ?>',
61
+ carrierProfileIds: <?php echo Zend_Json_Encoder::encode($helper->getLocationSelectCarrierProfiles()); ?>
62
+ });
63
+ </script>
64
+
65
+ <script src="https://maps.googleapis.com/maps/api/js?callback=transsmartShippingPickup.googleMapsLoaded&libraries=geometry"></script>
app/design/frontend/base/default/template/transsmart/shipping/onepage/progress/pickup.phtml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Transsmart
4
+ * @package Transsmart_Shipping
5
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
6
+ */
7
+ ?>
8
+ <?php /** @var Mage_Checkout_Block_Onepage_Progress $this */ ?>
9
+ <?php $_helper = Mage::helper('transsmart_shipping'); ?>
10
+ <?php $_quote = $this->getQuote(); ?>
11
+ <?php $_shippingAddress = $_quote->getShippingAddress(); ?>
12
+ <?php $_pickupLocation = Mage::helper('transsmart_shipping/pickupaddress')->getPickupAddressFromQuote($_quote); ?>
13
+
14
+ <?php if (!$_helper->isTranssmartShippingMethod($_shippingAddress->getShippingMethod()) || !$_pickupLocation): ?>
15
+ <?php return ''; ?>
16
+ <?php endif; ?>
17
+
18
+ <dt class="complete" id="tss-ls-progress-pickup-header">
19
+ <?php echo $_helper->__('Pickup Address'); ?> <span class="changelink"><span class="separator">|</span> <a
20
+ href="#shipping_method"
21
+ onclick="checkout.changeSection('opc-shipping_method'); return false;"><?php echo $this->__('Change') ?></a></span>
22
+ </dt>
23
+
24
+ <dd class="complete" id="tss-ls-progress-pickup-content">
25
+ <?php echo $_pickupLocation->format('html'); ?>
26
+ </dd>
app/etc/modules/Transsmart_Shipping.xml ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ /**
4
+ * @category Transsmart
5
+ * @package Transsmart_Shipping
6
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
7
+ */
8
+ -->
9
+ <config>
10
+ <modules>
11
+ <Transsmart_Shipping>
12
+ <active>true</active>
13
+ <codePool>community</codePool>
14
+ </Transsmart_Shipping>
15
+ </modules>
16
+ </config>
app/locale/nl_NL/Transsmart_Shipping.csv ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Transsmart Shipping","Transsmart verzending"
2
+ "Transsmart Shipping extension version %s","Transsmart verzending extensie versie %s"
3
+ "Transsmart Shipping Settings","Transsmart verzending instellingen"
4
+ "Transsmart API","Transsmart API"
5
+ "User Manual","Gebruikershandleiding"
6
+ "Configuration Manual","Configuratie handleiding"
7
+ "Transsmart Support","Transsmart support"
8
+ "Connection Details","Verbinding details"
9
+ "Username","Gebruikersnaam"
10
+ "Password","Wachtwoord"
11
+ "Environment","Omgeving"
12
+ "Staging","Staging"
13
+ "Production","Productie"
14
+ "Fetch Base Data","Basisgegevens ophalen"
15
+ "Base data not fetched yet.","Basisgegevens nog niet opgehaald."
16
+ "Base data last fetched on %s.","Basisgegevens laatst opgehaald op %s."
17
+ "Fetch Now","Nu ophalen"
18
+ "Printing","Afdrukken"
19
+ "QZ Host","QZ Host"
20
+ "Selected Printer","Geselecteerde printer"
21
+ "Default Shipment Properties","Standaard eigenschappen zending"
22
+ "These properties are applied to a new shipment by default, and can be configured per storeview.","Deze eigenschappen worden standaard toegekend aan een nieuwe zending, en kunnen per winkelzicht worden ingesteld."
23
+ "Transsmart default value: %s","Transsmart standaardwaarde: %s"
24
+ "Use Config Settings","Gebruik configuratieinstellingen"
25
+ "(empty)","(leeg)"
26
+ "Mapping","Toewijzing"
27
+ "If the shop uses multiple street fields, please specify which field should be used for what.","Als de winkel gebruik maakt van meerdere straat velden, stelt u hier in welk veld waarvoor gebruikt dient te worden."
28
+ "Street","Straat"
29
+ "House Number","Huisnummer"
30
+ "Street 2","Straat 2"
31
+ "Street %s","Straat %s"
32
+ "Combined Street Fields","Samengevoegde straat velden"
33
+ "Carrier Profile","Vervoerdersprofiel"
34
+ "Shipment Location","Verzendlocatie"
35
+ "Email Type","E-mailtype"
36
+ "Cost Center","Kostenplaats"
37
+ "Package Type","Verpakkingstype"
38
+ "Incoterm","Incoterm"
39
+ "Length (cm)","Lengte (cm)"
40
+ "Width (cm)","Breedte (cm)"
41
+ "Height (cm)","Hoogte (cm)"
42
+ "Weight (Kg)","Gewicht (Kg)"
43
+ "Transsmart Carrier Profiles","Transsmart vervoerdersprofielen"
44
+ "Servicelevel Time","Servicelevel tijd"
45
+ "Servicelevel Other","Servicelevel overig"
46
+ "Show in Checkout","Toon op afrekenpagina"
47
+ "No","Nee"
48
+ "As Delivery Option","Als bezorgoptie"
49
+ "As Pickup Option","Als afhaaloptie"
50
+ "Title","Titel"
51
+ "Use Location Selector","Gebruik locatiekiezer"
52
+ "Delivery","Bezorging"
53
+ "Pickup","Afhalen"
54
+ "Location selector not available for this shipping method.","Locatiekiezer is niet beschikbaar voor deze verzendmethode."
55
+ "Zipcode, city and country are required.","Postcode, plaats en land zijn vereist."
56
+ "Opening hours:","Openingstijden:"
57
+ "Select pickup location","Afhaallocatie kiezen"
58
+ "Save","Opslaan"
59
+ "Search","Zoeken"
60
+ "Found pickup locations:","Gevonden afhaallocaties:"
61
+ "Pickup Address","Afhaallocatie"
62
+ "A pickup location has to be selected","Geen afhaallocatie gekozen"
63
+ "Zipcode, City, Street, Housenumber","Postcode, Plaats, Straat, Huisnummer"
64
+ "Transsmart Document Id","Transsmart Document Id"
65
+ "Transsmart Status","Transsmart Status"
66
+ "N/A","N.v.t."
67
+ "Pending","Wachtende"
68
+ "Partially Exported","Gedeeltelijk geëxporteerd"
69
+ "Exported","Geëxporteerd"
70
+ "Error","Foutmelding"
71
+ "Transsmart: Create Shipment(s)","Transsmart: Zending(en) aanmaken"
72
+ "Transsmart: Book & Print","Transsmart: Boeken & Printen"
73
+ "Transsmart: Book Shipment(s)","Transsmart: Zending(en) boeken"
74
+ "Transsmart: Print Label(s)","Transsmart: Label(s) printen"
75
+ "Transsmart document ID is not known.","Transsmart document ID is niet bekend."
76
+ "Shipment #%s for order #%s could not be booked and printed: %s","Zending #%s voor bestelling #%s kon niet geboekt en geprint worden: %s"
77
+ "Successfully booked and printed %s Transsmart shipments.","Succesvol %s Transsmart zendingen geboekt en geprint."
78
+ "Shipment #%s for order #%s could not be booked: %s","Zending #%s voor bestelling #%s kon niet geboekt worden: %s"
79
+ "Successfully booked %s Transsmart shipments.","Succesvol %s Transsmart zendingen geboekt."
80
+ "Shipment #%s for order #%s could not be printed: %s","Zending #%s voor bestelling #%s kon niet geprint worden: %s"
81
+ "Successfully printed %s Transsmart shipments.","Succesvol %s Transsmart zendingen geprint."
82
+ "There are no Transsmart documents related to selected order(s).","Er zijn geen Transsmart documenten gerelateerd aan de geselecteerde bestelling(en)."
83
+ "There are no Transsmart documents related to selected shipment(s).","Er zijn geen Transsmart documenten gerelateerd aan de geselecteerde zending(en)."
84
+ "There are no Transsmart documents or shipping labels related to selected order(s).","Er zijn geen Transsmart documenten of verzendlabels gerelateerd aan de geselecteerde bestelling(en)."
85
+ "There are no Transsmart documents or shipping labels related to selected shipment(s).","Er zijn geen Transsmart documenten of verzendlabels gerelateerd aan de geselecteerde zending(en)."
86
+ "Open late","Laat open"
87
+ "Open early","Vroeg open"
88
+ "Open on sunday","Zondag open"
89
+ "No shipments can be created for the selected order(s).","Er kunnen geen zendingen aangemaakt worden voor de geselecteerde bestelling(en)."
90
+ "Create New Shipment(s) for Order(s)","Nieuwe zending(en) aanmaken voor bestelling(en)"
91
+ "Transsmart Shipping Details","Eigenschappen Transsmart zending"
92
+ "Determine Automatically","Automatisch bepalen"
93
+ "Use Configured Default","Gebruik geconfigureerde standaardwaarde"
94
+ "Summary","Samenvatting"
95
+ "Selected Orders","Geselecteerde bestellingen"
96
+ "Shipments To Create","Aan te maken zendingen"
97
+ "The shipment can be tracked <a href=""%s"">here</a>","De zending kan <a href=""%s"">hier</a> gevolgd worden"
98
+ "The shipment is carried by %s and can be tracked <a href=""%s"">here</a>.","De zending wordt vervoerd door %s en kan <a href=""%s"">hier</a> gevolgd worden."
99
+ "One or more selected orders have changed. Please confirm.","Één of meer geselecteerde bestellingen zijn gewijzigd. Bevestig a.u.b."
100
+ "Error creating shipment for order #%s: %s","Kan geen zending aanmaken voor bestelling #%s: %s"
101
+ "Successfully created %s shipment(s)!","Succesvol %s zending(en) aangemaakt!"
102
+ "Track & Trace","Track & Trace"
103
+ "View","Bekijk"
104
+ "Monday","Maandag"
105
+ "Tuesday","Dinsdag"
106
+ "Wednesday","Woensdag"
107
+ "Thursday","Donderdag"
108
+ "Friday","Vrijdag"
109
+ "Saturday","Zaterdag"
110
+ "Sunday","Zondag"
111
+ "Closed","Gesloten"
112
+ "No pickup locations found.","Geen afhaallocaties gevonden."
113
+ "Error loading pickup location selector. Please try again.","Fout bij laden van afhaallocatie kiezer. Probeer het nogmaals."
114
+ "Search did not succeed. Please try again.","Zoeken is niet gelukt. Probeer het nogmaals."
115
+ "Please add at lease one package.","Voeg ten minste één regel toe alstublieft."
116
+ "Please note! The carrier profile will be changed. This change will NOT be made to the Magento order. This could affect the calculated shipping costs and tracking and tracing emails. Do you want to continue?","Let op! Het vervoerdersprofiel wordt nu gewijzigd. Deze wijziging wordt NIET doorgevoerd in de Magento bestelling. Dit heeft mogelijk invloed op de berekende verzendkosten en tracking en tracing mails. Wilt u doorgaan?"
117
+ "This does not affect shipments using a pickup option.","Heeft geen invloed op zendingen met een afhaaloptie."
js/transsmart/shipping/admin/pickup_selector.js ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @category Transsmart
3
+ * @package Transsmart_Shipping
4
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
5
+ */
6
+ if (!Transsmart) var Transsmart = { };
7
+ if (!Transsmart.Shipping) Transsmart.Shipping = { };
8
+
9
+ Transsmart.Shipping.PickupAdmin = Class.create(Transsmart.Shipping.Pickup, {
10
+
11
+ /**
12
+ * Triggered when the initialization has been done
13
+ */
14
+ attachListenHandler: function() {
15
+ var self = this;
16
+
17
+ // Attach click event to close button
18
+ $(self.config.closeButtonId).observe('click', function(event) {
19
+ self.close();
20
+ event.stop();
21
+ });
22
+
23
+ // Wait for the document to load
24
+ document.observe('dom:loaded', function() {
25
+ self.detectCheckedShippingMethod();
26
+
27
+ // Add our customer validator
28
+ self.addValidators();
29
+
30
+ var parentSetShippingMethod = order.setShippingMethod.bind(order);
31
+
32
+ // Override the setShippingMethod, since we need it to determine when a shipping method was clicked
33
+ order.setShippingMethod = function(value) {
34
+ // Check to see if this is a pickup profile that allows a location selector
35
+ var valueBits = value.match(/transsmartpickup_carrierprofile_([0-9]+)/);
36
+
37
+ // Nothing to attach, it doesn't match
38
+ if (valueBits == null || valueBits.length != 2) {
39
+ return parentSetShippingMethod(value);
40
+ }
41
+
42
+ // Not a carrierprofile that has location selector enabled
43
+ if (self.config.carrierProfileIds.indexOf(valueBits[1]) == -1) {
44
+ Transsmart.Logger.log('Carrier profile with id: ' + valueBits[1] + ' does not allow location selector');
45
+ Transsmart.Logger.log('Allowed location selectors are: ', self.config.carrierProfileIds);
46
+ return parentSetShippingMethod(value);
47
+ }
48
+
49
+ self.selectedShippingMethod = value;
50
+ if (self.selectedShippingMethod != self.origShippingMethod) {
51
+ $('tss-ls-admin-selected-location').update('');
52
+ }
53
+ self.attachPickupDiv($('s_method_' + value));
54
+ };
55
+
56
+ // We need to move the container to after the anchor-content, so it lines up correctly
57
+ $('anchor-content').insert({
58
+ after: $('tss-pickup-container')
59
+ });
60
+
61
+ $(self.config.selectButtonId).observe('click', function(event, elemnt) {
62
+ self.selectLocationAndClose();
63
+ event.stop();
64
+ });
65
+
66
+ var parentLoadAreaResponseHandler = order.loadAreaResponseHandler.bind(order);
67
+
68
+ // Override the area response handler so that we can detect which shipping method is selected
69
+ order.loadAreaResponseHandler = function(response) {
70
+ parentLoadAreaResponseHandler(response);
71
+ self.detectCheckedShippingMethod();
72
+ }
73
+ });
74
+ },
75
+
76
+ detectCheckedShippingMethod: function() {
77
+ var checkedShippingMethod = $$('input[name="order[shipping_method]"]:checked');
78
+
79
+ if (checkedShippingMethod.length > 0) {
80
+ var checkedShippingMethodValue = checkedShippingMethod[0].value;
81
+ if (/transsmartpickup_carrierprofile_[0-9]+/.test(checkedShippingMethodValue)) {
82
+ this.selectedShippingMethod = checkedShippingMethodValue;
83
+ this.attachPickupDiv($('s_method_' + checkedShippingMethodValue));
84
+ }
85
+ }
86
+ },
87
+
88
+ /**
89
+ * Triggered when a location has been selected
90
+ */
91
+ selectLocationAndClose: function() {
92
+ // If we have a location, we need to set the shipping method
93
+ if (this.selectedMarker != null && this.selectedMarker.locationData) {
94
+ var locationData = this.selectedMarker.locationData;
95
+ $('tss-ls-location-data').value = btoa(Object.toJSON(locationData));
96
+
97
+ // Update the div
98
+ $('tss-ls-admin-selected-location').update(this.formatLocationAddress(locationData));
99
+
100
+ // Close the pop-up
101
+ this.close();
102
+ this.origShippingMethod = this.selectedShippingMethod;
103
+ this.origPickupDivHtml = $(this.config.shippingPickupContainerId).outerHTML;
104
+
105
+ var data = {};
106
+ data['order[shipping_method]'] = this.selectedShippingMethod;
107
+ // TODO: btoa only supports Latin1 characters. Make this work with all UTF-8 characters.
108
+ data['order[transsmart_pickup_address_data]'] = btoa(Object.toJSON(locationData));
109
+
110
+ order.loadArea(['shipping_method', 'totals', 'billing_method'], true, data);
111
+ }
112
+ },
113
+
114
+ /**
115
+ * Adds the required validators to the validation class.
116
+ */
117
+ addValidators: function() {
118
+ Validation.add(
119
+ 'validate-selected-location',
120
+ Translator.translate("A pickup location has to be selected"),
121
+ function(v) {
122
+ return $('order-shipping-method-choose').visible() ? !Validation.get('IsEmpty').test(v) : true;
123
+ });
124
+ }
125
+
126
+ });
127
+
128
+ Transsmart.Shipping.PickupAdmin.prototype.parent = Transsmart.Shipping.Pickup.prototype;
js/transsmart/shipping/base64.js ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright (C) 1999 Masanao Izumo <iz@onicos.co.jp>
2
+ * Version: 1.0
3
+ * LastModified: Dec 25 1999
4
+ * This library is free. You can redistribute it and/or modify it.
5
+ */
6
+
7
+ /*
8
+ * Interfaces:
9
+ * b64 = base64encode(data);
10
+ * data = base64decode(b64);
11
+ */
12
+
13
+ ;(function() {
14
+
15
+ var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
16
+ var base64DecodeChars = [
17
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
18
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
19
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
20
+ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
21
+ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
22
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
23
+ -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
24
+ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1];
25
+
26
+ function base64encode(str) {
27
+ var out, i, len;
28
+ var c1, c2, c3;
29
+
30
+ len = str.length;
31
+ i = 0;
32
+ out = "";
33
+ while(i < len) {
34
+ c1 = str.charCodeAt(i++) & 0xff;
35
+ if(i == len)
36
+ {
37
+ out += base64EncodeChars.charAt(c1 >> 2);
38
+ out += base64EncodeChars.charAt((c1 & 0x3) << 4);
39
+ out += "==";
40
+ break;
41
+ }
42
+ c2 = str.charCodeAt(i++);
43
+ if(i == len)
44
+ {
45
+ out += base64EncodeChars.charAt(c1 >> 2);
46
+ out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
47
+ out += base64EncodeChars.charAt((c2 & 0xF) << 2);
48
+ out += "=";
49
+ break;
50
+ }
51
+ c3 = str.charCodeAt(i++);
52
+ out += base64EncodeChars.charAt(c1 >> 2);
53
+ out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
54
+ out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6));
55
+ out += base64EncodeChars.charAt(c3 & 0x3F);
56
+ }
57
+ return out;
58
+ }
59
+
60
+ function base64decode(str) {
61
+ var c1, c2, c3, c4;
62
+ var i, len, out;
63
+
64
+ len = str.length;
65
+ i = 0;
66
+ out = "";
67
+ while(i < len) {
68
+ /* c1 */
69
+ do {
70
+ c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
71
+ } while(i < len && c1 == -1);
72
+ if(c1 == -1)
73
+ break;
74
+
75
+ /* c2 */
76
+ do {
77
+ c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
78
+ } while(i < len && c2 == -1);
79
+ if(c2 == -1)
80
+ break;
81
+
82
+ out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));
83
+
84
+ /* c3 */
85
+ do {
86
+ c3 = str.charCodeAt(i++) & 0xff;
87
+ if(c3 == 61)
88
+ return out;
89
+ c3 = base64DecodeChars[c3];
90
+ } while(i < len && c3 == -1);
91
+ if(c3 == -1)
92
+ break;
93
+
94
+ out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));
95
+
96
+ /* c4 */
97
+ do {
98
+ c4 = str.charCodeAt(i++) & 0xff;
99
+ if(c4 == 61)
100
+ return out;
101
+ c4 = base64DecodeChars[c4];
102
+ } while(i < len && c4 == -1);
103
+ if(c4 == -1)
104
+ break;
105
+ out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
106
+ }
107
+ return out;
108
+ }
109
+
110
+ if (!window.btoa) window.btoa = base64encode;
111
+ if (!window.atob) window.atob = base64decode;
112
+
113
+ })();
js/transsmart/shipping/logger.js ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @category Transsmart
3
+ * @package Transsmart_Shipping
4
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
5
+ */
6
+ if (!Transsmart) var Transsmart = { };
7
+
8
+ /**
9
+ * Log helper to make logging easier.
10
+ * Regardless of whether console logging is enabled or not.
11
+ * @type {{log: Function}}
12
+ */
13
+ Transsmart.Logger = {
14
+ log: function() {
15
+ if (typeof console != 'undefined' && typeof console.log == 'function') {
16
+ return console.log.apply(console, arguments);
17
+ }
18
+ }
19
+ };
js/transsmart/shipping/pickup_selector.js ADDED
@@ -0,0 +1,899 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @category Transsmart
3
+ * @package Transsmart_Shipping
4
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
5
+ */
6
+ if (!Transsmart) var Transsmart = { };
7
+ if (!Transsmart.Shipping) Transsmart.Shipping = { };
8
+
9
+ Transsmart.Shipping.Pickup = Class.create({
10
+
11
+ /**
12
+ * Define configuration for the pickup shipping method
13
+ */
14
+ config: {
15
+ shippingMethodName: 'transsmartpickup',
16
+ shippingPickupContainerId: 'tss-location-selector',
17
+ shippingMethodLoadDivId: 'checkout-shipping-method-load',
18
+ locationsListDivId: 'tss-ls-locations',
19
+ googleMapsId: 'tss-ls-map',
20
+ selectButtonId: 'tss-ls-select',
21
+ closeButtonId: 'tss-ls-close',
22
+ shippingPickupSelectButtonId: 'tss-ls-select-location',
23
+ selectedLocationDivId: 'tss-ls-selected-location-info'
24
+ },
25
+
26
+ googleMaps: null,
27
+ googleGeocoder: null,
28
+ selectedShippingMethod: null,
29
+ markers: [],
30
+ infoWindow: null,
31
+ selectedMarker: null,
32
+ ajaxRequest: null,
33
+ isLoading: false,
34
+ isClosing: false,
35
+
36
+ origShippingMethod: null,
37
+ origPickupDivHtml: '',
38
+
39
+ /**
40
+ * Initialize the pickup location selector
41
+ */
42
+ initialize: function(config) {
43
+ // Check whether the viewUrl is provided
44
+ if (typeof config == 'undefined' || typeof config.lookupUrl == 'undefined') {
45
+ Transsmart.Logger.log('Transsmart_Shipping: Missing lookupUrl in the supplied config');
46
+ return;
47
+ }
48
+
49
+ // Set the view url
50
+ this.config.lookupUrl = config.lookupUrl;
51
+
52
+ // Check whether the carrierProfileIds is provided
53
+ if (typeof config == 'undefined' || typeof config.carrierProfileIds == 'undefined') {
54
+ Transsmart.Logger.log('Transsmart_Shipping: Missing carrierProfileIds in the supplied config');
55
+ return;
56
+ }
57
+
58
+ this.config.carrierProfileIds = config.carrierProfileIds;
59
+
60
+ this.attachListenHandler();
61
+ this.attachFilterHandlers();
62
+ this.attachSearchHandler();
63
+
64
+ // attach window resize handler
65
+ document.observe('dom:loaded', function() {
66
+ Event.observe(window, 'resize', this.onWindowResize.bind(this));
67
+ }.bind(this));
68
+
69
+ // observe ajax update event
70
+ Ajax.Responders.register({ onComplete: this.onAjaxComplete.bind(this) });
71
+ },
72
+
73
+ /**
74
+ * Attaches the listen handler so that we know when we should be
75
+ * showing the pickup selector popup.
76
+ */
77
+ attachListenHandler: function() {
78
+ var self = this;
79
+
80
+ // Attach click event to close button
81
+ $(this.config.closeButtonId).observe('click', function(event) {
82
+ self.close();
83
+ event.stop();
84
+ });
85
+
86
+ // Wait for the dom to be ready
87
+ document.observe('dom:loaded', function () {
88
+ // Add our custom validator
89
+ this.addValidators();
90
+
91
+ if (typeof checkout.gotoSection == 'function') {
92
+ // hook into Magento's OnePage checkout
93
+ var parentGotoSection = checkout.gotoSection.bind(checkout);
94
+
95
+ // Triggered when the checkout switches to the shipping method selection
96
+ checkout.gotoSection = function (section, reloadProgressBlock) {
97
+ // Remove the progress block when we switch to a different section
98
+ if (['billing', 'shipping', 'shipping_method'].indexOf(section) !== -1) {
99
+ if ($('tss-ls-progress-pickup-header')) {
100
+ $('tss-ls-progress-pickup-header').remove();
101
+ }
102
+
103
+ if ($('tss-ls-progress-pickup-content')) {
104
+ $('tss-ls-progress-pickup-content').remove();
105
+ }
106
+ }
107
+
108
+ if (section == 'shipping_method') {
109
+ this.updateShippingMethods();
110
+ }
111
+
112
+ parentGotoSection(section, reloadProgressBlock);
113
+ }.bind(this);
114
+ }
115
+
116
+ // The shipping methods are generated dynamically
117
+ // So we need to observe for dom changes and then trigger the click event based on that
118
+ $(document).on('click', 'input[name=shipping_method]', function (event, element) {
119
+ // Skip shipping methods that do not match the shipping method name
120
+ if (element.value && element.value.indexOf(self.config.shippingMethodName) == -1) {
121
+ this.removePickupDiv();
122
+ return;
123
+ }
124
+
125
+ this.selectedShippingMethod = element.value;
126
+ this.attachPickupDiv(element);
127
+ }.bind(this));
128
+
129
+ this.updateShippingMethods();
130
+
131
+ $(this.config.selectButtonId).observe('click', function (event) {
132
+ this.selectLocationAndClose();
133
+ event.stop();
134
+ }.bind(this));
135
+ }.bind(this));
136
+ },
137
+
138
+ onAjaxComplete: function () {
139
+ this.updateShippingMethods();
140
+ },
141
+
142
+ updateShippingMethods: function () {
143
+ // Check which shipping method has been selected
144
+ var checkedShippingMethods = $$('input[name=shipping_method]:checked');
145
+
146
+ if (checkedShippingMethods.length != 0) {
147
+ // The pre-selected shipping method is the pickup one.
148
+ // Attach the pickup div to the radio button
149
+ if (checkedShippingMethods[0].value.indexOf(this.config.shippingMethodName) != -1) {
150
+ this.selectedShippingMethod = checkedShippingMethods[0].value;
151
+ this.attachPickupDiv(checkedShippingMethods[0]);
152
+ }
153
+ }
154
+ },
155
+
156
+ /**
157
+ * The filter handlers determine which markers should be shown
158
+ */
159
+ attachFilterHandlers: function() {
160
+ $('tss-ls-show-open-early').observe('click', this.updateMapMarkers.bind(this));
161
+ $('tss-ls-show-open-late').observe('click', this.updateMapMarkers.bind(this));
162
+ $('tss-ls-show-open-sunday').observe('click', this.updateMapMarkers.bind(this));
163
+ },
164
+
165
+ /**
166
+ * Attaches the search handler
167
+ */
168
+ attachSearchHandler: function() {
169
+ $('tss-ls-search-btn').observe('click', this.attachSearch.bind(this));
170
+ $('tss-ls-search').observe('keypress', this.attachSearch.bind(this));
171
+ },
172
+
173
+ /**
174
+ * Perform search
175
+ * @param event
176
+ */
177
+ attachSearch: function (event) {
178
+ if (event.type == 'keypress' && event.keyCode != Event.KEY_RETURN) {
179
+ return;
180
+ }
181
+
182
+ var searchField = $('tss-ls-search');
183
+ var searchButton = $('tss-ls-search-btn');
184
+
185
+ var searchValue = searchField.value;
186
+ if (searchValue == '') {
187
+ return;
188
+ }
189
+
190
+ searchField.disabled = true;
191
+ searchField.addClassName('disabled');
192
+ searchButton.disabled = true;
193
+ searchButton.addClassName('disabled');
194
+
195
+ this.retrieveLocation(searchValue, function (bounds) {
196
+ searchField.disabled = false;
197
+ searchField.removeClassName('disabled');
198
+ searchButton.disabled = false;
199
+ searchButton.removeClassName('disabled');
200
+
201
+ this.updateMapMarkers();
202
+
203
+ google.maps.event.trigger(this.googleMaps, 'resize');
204
+ this.googleMaps.setCenter(bounds.getCenter());
205
+ this.googleMaps.fitBounds(bounds);
206
+
207
+ }.bind(this),
208
+ function (error) {
209
+ searchField.disabled = false;
210
+ searchField.removeClassName('disabled');
211
+ searchButton.disabled = false;
212
+ searchButton.removeClassName('disabled');
213
+
214
+ if (this.isClosing) {
215
+ return;
216
+ }
217
+ Transsmart.Logger.log('Transsmart_Shipping error: ' + error);
218
+ alert(Translator.translate('Search did not succeed. Please try again.'));
219
+
220
+ }.bind(this));
221
+ },
222
+
223
+ /**
224
+ * Attaches the pickup location selector div to the parent item of the input element.
225
+ * @param inputElement The input radio element that's part of a carrier
226
+ */
227
+ attachPickupDiv: function(inputElement) {
228
+ var containerItem = $(this.config.shippingPickupContainerId);
229
+
230
+ // Remove the shipping pickup div if it exists
231
+ if (containerItem) {
232
+ containerItem.remove();
233
+ }
234
+
235
+ var valueBits = inputElement.value.match(/transsmartpickup_carrierprofile_([0-9]+)/);
236
+
237
+ // Nothing to attach, it doesn't match
238
+ if (valueBits == null || valueBits.length != 2) {
239
+ return;
240
+ }
241
+
242
+ // Not a carrierprofile that has location selector enabled
243
+ if (this.config.carrierProfileIds.indexOf(valueBits[1]) == -1) {
244
+ Transsmart.Logger.log('Carrier profile with id: ' + valueBits[1] + ' does not allow location selector');
245
+ Transsmart.Logger.log('Allowed location selectors are: ', this.config.carrierProfileIds);
246
+ return;
247
+ }
248
+
249
+ // Find the container for transsmart pickup shipping method
250
+ var shippingMethodContainer = this.getButtonContainer(inputElement);
251
+ if (typeof shippingMethodContainer == 'undefined') {
252
+ Transsmart.Logger.log('Transsmart.Shipping: ' +
253
+ Translator.translate('Could not find shipping container for ' + this.config.shippingMethodName));
254
+ return;
255
+ }
256
+
257
+ // insert the location selector button
258
+ shippingMethodContainer.insert(this.getPickupDiv());
259
+ $(this.config.shippingPickupSelectButtonId).observe('click', function(event) {
260
+ this.showLocationPopUp();
261
+ event.stop();
262
+ }.bind(this));
263
+ },
264
+
265
+ /**
266
+ * Find the container for transsmart pickup shipping method button
267
+ *
268
+ * @param inputElement
269
+ */
270
+ getButtonContainer: function (inputElement) {
271
+ // Find the container for transsmart pickup shipping method
272
+ var buttonContainer = inputElement.up('dd, div');
273
+ return buttonContainer;
274
+ },
275
+
276
+ /**
277
+ * Removes the pickup div element
278
+ */
279
+ removePickupDiv: function() {
280
+ var containerItem = $(this.config.shippingPickupContainerId);
281
+
282
+ if (containerItem != null) {
283
+ containerItem.remove();
284
+ }
285
+ },
286
+
287
+ /**
288
+ * Returns the div that is used near the shipping radio button
289
+ * @returns {string}
290
+ */
291
+ getPickupDiv: function() {
292
+ if (this.origPickupDivHtml == '' || this.origShippingMethod != this.selectedShippingMethod) {
293
+ this.origShippingMethod = this.selectedShippingMethod;
294
+ this.origPickupDivHtml = '<div id="' + this.config.shippingPickupContainerId + '">' +
295
+ '<button id="' + this.config.shippingPickupSelectButtonId + '" class="tss-ls-select-location button" onclick="return false">' +
296
+ '<span><span>' +
297
+ Translator.translate('Select pickup location') +
298
+ '</span></span>' +
299
+ '</button>' +
300
+ '<div id="' + this.config.selectedLocationDivId + '"></div>' +
301
+ '<input id="tss-ls-location-data" name="transsmart_pickup_address_data" type="hidden" class="validate-selected-location" />' +
302
+ '</div>';
303
+ }
304
+ return this.origPickupDivHtml;
305
+ },
306
+
307
+ /**
308
+ * Adds the required validators to the validation class.
309
+ */
310
+ addValidators: function() {
311
+ Validation.add(
312
+ 'validate-selected-location',
313
+ Translator.translate("A pickup location has to be selected"),
314
+ function(v) {
315
+ return !Validation.get('IsEmpty').test(v);
316
+ });
317
+ },
318
+
319
+ /**
320
+ * Shows the pickup location selector popup
321
+ */
322
+ showLocationPopUp: function() {
323
+ var pickupContainer = $('tss-pickup-container');
324
+ var pickupLoader = pickupContainer.select('.tss-loader')[0];
325
+ var pickupContent = pickupContainer.select('.tss-selector-container')[0];
326
+
327
+ this.isClosing = false;
328
+ if (this.originalLoaderHtml) {
329
+ pickupLoader.innerHTML = this.originalLoaderHtml;
330
+ }
331
+ else {
332
+ this.originalLoaderHtml = pickupLoader.innerHTML;
333
+ }
334
+
335
+ // remove validation advice
336
+ $$('#' + this.config.shippingPickupContainerId + ' .validation-advice').each(function(item) {
337
+ new Effect.Fade(item);
338
+ });
339
+
340
+ // Reset the markers
341
+ this.clearMapMarkers();
342
+
343
+ // Reset input fields
344
+ $('tss-ls-search').value = '';
345
+ $('tss-ls-show-open-early').checked = false;
346
+ $('tss-ls-show-open-late').checked = false;
347
+ $('tss-ls-show-open-sunday').checked = false;
348
+
349
+ pickupLoader.show();
350
+ pickupContent.hide();
351
+ this.isLoading = true;
352
+
353
+ // Show the pickup container
354
+ pickupContainer.appear({ duration: 0.3, afterSetup: this.onWindowResize.bind(this) });
355
+
356
+ this.retrieveLocation(null, function(bounds) {
357
+ pickupLoader.hide();
358
+ pickupContent.show();
359
+ this.isLoading = false;
360
+ this.onWindowResize();
361
+
362
+ this.googleMaps.setCenter(bounds.getCenter());
363
+ this.googleMaps.fitBounds(bounds);
364
+
365
+ try {
366
+ var locationData = eval('(' + atob($('tss-ls-location-data').value) + ')');
367
+
368
+ for (var i = 0; i < this.markers.length; i++) {
369
+ if (this.markers[i].locationData.servicepoint_id == locationData.servicepoint_id) {
370
+ this.selectedMarker = this.markers[i];
371
+ break;
372
+ }
373
+ }
374
+ }
375
+ catch (e) {
376
+ }
377
+
378
+ }.bind(this), function (error) {
379
+ if (this.isClosing) {
380
+ return;
381
+ }
382
+ Transsmart.Logger.log('Transsmart_Shipping error: ' + error);
383
+ pickupLoader.innerHTML = '<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>' +
384
+ Translator.translate('Error loading pickup location selector. Please try again.') +
385
+ '<p>&nbsp;</p><p>&nbsp;</p>';
386
+ }.bind(this));
387
+ },
388
+
389
+ /**
390
+ * Get the current shipping address if possible.
391
+ * Needed for LightCheckout when the quote address is not updated via AJAX.
392
+ */
393
+ getCurrentAddress: function () {
394
+ var result = null;
395
+
396
+ try {
397
+ // determine address prefix
398
+ var addressPrefix;
399
+ var billingUseForShipping1 = $('billing_use_for_shipping_yes');
400
+ var billingUseForShipping2 = $('billing:use_for_shipping_yes');
401
+ var shippingSameAsBilling = $('shipping:same_as_billing');
402
+ if (billingUseForShipping1) {
403
+ addressPrefix = billingUseForShipping1.checked ? 'billing_' : 'shipping_';
404
+ }
405
+ else if (shippingSameAsBilling) {
406
+ // if an address is selected in the address book, ignore the address fields
407
+ var addressSelect = $((shippingSameAsBilling.checked ? 'billing' : 'shipping') + '-address-select');
408
+ if (addressSelect && addressSelect.value) {
409
+ return result;
410
+ }
411
+ addressPrefix = shippingSameAsBilling.checked ? 'billing:' : 'shipping:';
412
+ }
413
+ else if (billingUseForShipping2) {
414
+ // if an address is selected in the address book, ignore the address fields
415
+ var addressSelect = $((billingUseForShipping2.checked ? 'billing' : 'shipping') + '-address-select');
416
+ if (addressSelect && addressSelect.value) {
417
+ return result;
418
+ }
419
+ addressPrefix = billingUseForShipping2.checked ? 'billing:' : 'shipping:';
420
+ }
421
+ else if ($('shipping_postcode')) {
422
+ addressPrefix = 'shipping_';
423
+ }
424
+ else if ($('shipping:postcode')) {
425
+ addressPrefix = 'shipping:';
426
+ }
427
+ else if ($('billing_postcode')) {
428
+ addressPrefix = 'billing_';
429
+ }
430
+ else {
431
+ addressPrefix = 'billing:';
432
+ }
433
+
434
+ var postcode = $(addressPrefix + 'postcode');
435
+ var city = $(addressPrefix + 'city');
436
+ var street = $(addressPrefix + 'street1');
437
+ var housenr = $(addressPrefix + 'street2');
438
+
439
+ if (postcode) {
440
+ result = postcode.value;
441
+ if (city) {
442
+ result += ',' + city.value;
443
+ if (street) {
444
+ result += ',' + street.value;
445
+ if (housenr) {
446
+ result += ',' + housenr.value;
447
+ }
448
+ }
449
+ }
450
+ }
451
+ }
452
+ catch (e) {
453
+ }
454
+
455
+ return result;
456
+ },
457
+
458
+ /**
459
+ * Retrieves location and updates the map
460
+ * @param searchValue
461
+ * @param callback
462
+ */
463
+ retrieveLocation: function(searchValue, callback, errorCallback) {
464
+ // Attach the selected shipping method
465
+ var url = this.config.lookupUrl;
466
+ url += '?shipping_method=' + encodeURIComponent(this.selectedShippingMethod);
467
+
468
+ if (!searchValue) {
469
+ searchValue = this.getCurrentAddress();
470
+ }
471
+
472
+ if (searchValue != null) {
473
+ url += '&search=' + encodeURIComponent(searchValue);
474
+ }
475
+
476
+ this.ajaxRequest = new Ajax.Request(url, {
477
+ onComplete: function (response) {
478
+ try {
479
+ if (!response.responseJSON) {
480
+ return errorCallback('Empty server response');
481
+ }
482
+ if (response.responseJSON) {
483
+ if (!response.responseJSON.result) {
484
+ return errorCallback(response.responseJSON.error);
485
+ }
486
+ }
487
+
488
+ // Reset the markers
489
+ this.clearMapMarkers();
490
+
491
+ var currentLocation = response.responseJSON.current_location;
492
+ var originLatLng = currentLocation != null ? new google.maps.LatLng(currentLocation.lat, currentLocation.lng) : null;
493
+
494
+ // parse the location
495
+ var locations = response.responseJSON.locations;
496
+
497
+ var bounds = new google.maps.LatLngBounds();
498
+ var localMarkers = [];
499
+
500
+ for (var i = 0; i < locations.length; i++) {
501
+ var location = locations[i];
502
+
503
+ // Add the location to google maps
504
+ var latLng = new google.maps.LatLng(location.lat, location.lng);
505
+ var distance = originLatLng != null ? google.maps.geometry.spherical.computeDistanceBetween(originLatLng, latLng) : null;
506
+
507
+ // Create a marker
508
+ var marker = new google.maps.Marker({
509
+ position: latLng,
510
+ title: location.Name,
511
+
512
+ markerId: i,
513
+ locationData: location,
514
+ distance: distance
515
+ });
516
+
517
+ localMarkers.push(marker);
518
+ }
519
+
520
+ // Sort the markers
521
+ localMarkers.sort(this.sortMarkersByDistance);
522
+
523
+ for (i = 0; i < localMarkers.length; i++) {
524
+ var localMarker = localMarkers[i];
525
+
526
+ // Add the marker to the map
527
+ localMarker.setMap(this.googleMaps);
528
+
529
+ // Only add the 5 closest to the boundaries
530
+ if (i < 5) {
531
+ // Add the latitude and longitude to the bounds
532
+ bounds.extend(localMarker.position);
533
+ }
534
+
535
+ // add click listener
536
+ var self = this;
537
+ localMarker.addListener('click', function() {
538
+ self.setSelectedMarker(this);
539
+ });
540
+
541
+ // Store the market
542
+ this.markers[localMarker.markerId] = localMarker;
543
+
544
+ // Add the location to the list
545
+ this.addLocationToList(localMarker.locationData, localMarker);
546
+
547
+ if (!this.selectedMarker && localMarker.locationData.selected) {
548
+ this.selectedMarker = localMarker;
549
+ }
550
+ }
551
+
552
+ callback(bounds);
553
+ this.setSelectedMarker(this.selectedMarker);
554
+ }
555
+ catch (e) {
556
+ errorCallback(e);
557
+ }
558
+ }.bind(this)
559
+ });
560
+ },
561
+
562
+ /**
563
+ * Updates the map markers based on the filters
564
+ */
565
+ updateMapMarkers: function() {
566
+ // Only update the markers if there are any
567
+ if (this.markers.length == 0) {
568
+ return;
569
+ }
570
+
571
+ var shouldShowOpenEarly = $('tss-ls-show-open-early').checked;
572
+ var shouldShowOpenLate = $('tss-ls-show-open-late').checked;
573
+ var shouldShowOpenSunday = $('tss-ls-show-open-sunday').checked;
574
+ var shouldFilter = shouldShowOpenEarly || shouldShowOpenLate || shouldShowOpenSunday;
575
+
576
+ var localMarkers = [];
577
+
578
+ for (var i = 0; i < this.markers.length; i++) {
579
+ var currentMarker = this.markers[i];
580
+ if (currentMarker) {
581
+ if (shouldFilter && !(
582
+ (shouldShowOpenEarly && currentMarker.locationData.is_open_early) ||
583
+ (shouldShowOpenLate && currentMarker.locationData.is_open_late) ||
584
+ (shouldShowOpenSunday && currentMarker.locationData.is_open_sunday))) {
585
+ currentMarker.setMap(null);
586
+ continue;
587
+ }
588
+ localMarkers.push(currentMarker);
589
+ }
590
+ }
591
+
592
+ // Remove all list items
593
+ $(this.config.locationsListDivId).update('');
594
+
595
+ // Sort the markers
596
+ localMarkers.sort(this.sortMarkersByDistance);
597
+
598
+ for (var x = 0; x < localMarkers.length; x++) {
599
+ var localMarker = localMarkers[x];
600
+
601
+ // Add them back to the map, only if they aren't already on it
602
+ if (localMarker.getMap() == null) {
603
+ localMarker.setMap(this.googleMaps);
604
+ }
605
+
606
+ this.addLocationToList(localMarker.locationData, localMarker);
607
+ }
608
+ },
609
+
610
+ /**
611
+ * Removes all markers from the map and list
612
+ * and resets the marker array on the shipping object
613
+ */
614
+ clearMapMarkers: function() {
615
+ for (var i = 0; i < this.markers.length; i++) {
616
+ var currentMarker = this.markers[i];
617
+ if (currentMarker) {
618
+ currentMarker.setMap(null);
619
+ this.markers[i] = null;
620
+ }
621
+ }
622
+ this.markers = [];
623
+
624
+ $(this.config.locationsListDivId).update('');
625
+ this.setSelectedMarker(null);
626
+ },
627
+
628
+ /**
629
+ * Triggered when a marker is selected.
630
+ * Enables the select button when a marker has been select.
631
+ * @param marker
632
+ */
633
+ setSelectedMarker: function(marker) {
634
+ this.selectedMarker = marker;
635
+
636
+ // Remove all other selected markers
637
+ $$('.tss-ls-location-item[data-marker-id].selected').each(function(element) {
638
+ Element.removeClassName(element, 'selected');
639
+ });
640
+
641
+ var selectButton = $(this.config.selectButtonId);
642
+ if (marker) {
643
+ selectButton.addClassName('active');
644
+
645
+ var markerId = marker.markerId;
646
+ var markerListItem = $$('.tss-ls-location-item[data-marker-id=' + markerId + ']')[0];
647
+ markerListItem.addClassName('selected');
648
+
649
+ var contentString = this.getInfoWindowContent(marker.locationData);
650
+ this.infoWindow.setContent(contentString);
651
+ this.infoWindow.open(this.googleMaps, marker);
652
+
653
+ // scroll list item into view
654
+ var parent = $(this.config.locationsListDivId);
655
+ if (parent.scrollTop > markerListItem.offsetTop - parent.offsetTop) {
656
+ //parent.scrollTop = markerListItem.offsetTop - parent.offsetTop;
657
+ new Effect.Tween(parent, parent.scrollTop, markerListItem.offsetTop - parent.offsetTop, { duration: 0.3 }, 'scrollTop');
658
+ }
659
+ else if (parent.scrollTop + parent.offsetHeight < markerListItem.offsetTop - parent.offsetTop + markerListItem.offsetHeight) {
660
+ //parent.scrollTop = markerListItem.offsetTop - parent.offsetTop + markerListItem.offsetHeight - parent.offsetHeight;
661
+ new Effect.Tween(parent, parent.scrollTop, markerListItem.offsetTop - parent.offsetTop + markerListItem.offsetHeight - parent.offsetHeight, { duration: 0.3 }, 'scrollTop');
662
+ }
663
+ }
664
+ else {
665
+ selectButton.removeClassName('active');
666
+ }
667
+ },
668
+
669
+ /**
670
+ * Adds the location and the marker to the list of locations
671
+ * @param location
672
+ * @param marker
673
+ */
674
+ addLocationToList: function(location, marker) {
675
+ var locationsListDiv = $(this.config.locationsListDivId);
676
+
677
+ // Don't add it to the list if it's already there
678
+ if (locationsListDiv.select('div[data-marker-id="' + marker.markerId + '"]').length != 0) {
679
+ return;
680
+ }
681
+
682
+ var html = '<div class="tss-ls-location-item" data-marker-id="' + marker.markerId + '">' +
683
+ '<span class="tss-ls-name">' +
684
+ '<span class="tss-ls-company-name">' + location.name.escapeHTML() + '</span>' +
685
+ '<span class="tss-ls-address">' + location.street.escapeHTML() + ' ' + location.street_no.escapeHTML() + ', ' + location.city.escapeHTML() + '</span>' +
686
+ '</span>' +
687
+ '<span class="tss-ls-distance">(' + this.getFormattedDistanceForMarker(marker) + ')</span>' +
688
+ '<span class="tss-ls-check"><span class="tss-ls-img"></span></span>' +
689
+ '</div>';
690
+
691
+ locationsListDiv.insert(html);
692
+
693
+ locationsListDiv.select('.tss-ls-location-item[data-marker-id=' + marker.markerId + ']')[0]
694
+ .stopObserving('click')
695
+ .observe('click', function(event) {
696
+ new google.maps.event.trigger(marker, 'click');
697
+
698
+ // Prevent the event from bubbling
699
+ event.stop();
700
+ });
701
+ },
702
+
703
+ /**
704
+ * Formats the marker to meters or kilometers
705
+ * @param marker
706
+ * @returns {string}
707
+ */
708
+ getFormattedDistanceForMarker: function(marker) {
709
+ if (marker.distance < 1000) {
710
+ return String(Math.round(marker.distance)).replace('.', ',') + ' m'
711
+ }
712
+
713
+ return String(Math.round((marker.distance/1000) * 100)/100).replace('.', ',') + ' km';
714
+ },
715
+
716
+ /**
717
+ * Sorts markers by distance
718
+ * @param a
719
+ * @param b
720
+ */
721
+ sortMarkersByDistance: function(a, b) {
722
+ if (a.distance < b.distance)
723
+ return -1;
724
+ if (a.distance > b.distance)
725
+ return 1;
726
+
727
+ return 0;
728
+ },
729
+
730
+ /**
731
+ * Returns the Google Map info window content
732
+ * @param location
733
+ * @returns {string}
734
+ */
735
+ getInfoWindowContent: function(location) {
736
+ var openingHoursHtml = '';
737
+
738
+ if (location.has_openinghours) {
739
+ openingHoursHtml = Translator.translate('Opening hours:') + '<br />'
740
+ + '<table class="tss-ls-openinghours-table">';
741
+
742
+ // Add the opening hours
743
+ for (var x = 0; x < location.openinghours.length; x++) {
744
+ var openingHoursItem = location.openinghours[x];
745
+
746
+ openingHoursHtml += '<tr>' +
747
+ '<td style="padding-right:8px">' + openingHoursItem.day_name.escapeHTML() + '<td>' +
748
+ '<td>' + openingHoursItem.display.escapeHTML() + '</td>' +
749
+ '</tr>';
750
+ }
751
+
752
+ openingHoursHtml += '</table>';
753
+ }
754
+
755
+ var contentString = '<div id="content">'+
756
+ '<h1 id="firstHeading" class="firstHeading">' + location.name.escapeHTML() + '</h1>'+
757
+ '<div id="bodyContent">' +
758
+ '<p>' +
759
+ location.street.escapeHTML() + ' ' + location.street_no.escapeHTML() + '<br />' +
760
+ location.zipcode.escapeHTML() + ' ' + location.city.escapeHTML() +
761
+ (location.phone != null ? '<br />' + location.phone.escapeHTML() : '') +
762
+ '</p>' +
763
+ openingHoursHtml +
764
+ '</div>' +
765
+ '</div>';
766
+
767
+ return contentString;
768
+ },
769
+
770
+ /**
771
+ * Formats the location data into HTML
772
+ * @param locationData
773
+ * @returns {string}
774
+ */
775
+ formatLocationAddress: function(locationData) {
776
+ var html = '<strong>' + locationData.name.escapeHTML() + '</strong> <br />';
777
+ html += locationData.street.escapeHTML() + ' ' + locationData.street_no.escapeHTML() + '<br />';
778
+ html += locationData.zipcode.escapeHTML() + ' ' + locationData.city.escapeHTML() + '<br />';
779
+ html += (locationData.phone != null ? locationData.phone.escapeHTML() : '');
780
+
781
+ return html;
782
+ },
783
+
784
+ /**
785
+ * Triggered when the Google maps API has been loaded.
786
+ * Create the map as soon as the API has been loaded
787
+ */
788
+ googleMapsLoaded: function() {
789
+ this.googleMaps = new google.maps.Map($(this.config.googleMapsId), {
790
+ zoom: 8,
791
+ center: {lat: 52.0795, lng: 5.4492},
792
+ disableDefaultUI: true,
793
+ zoomControl: true,
794
+ panControl: false,
795
+ mapTypeId: google.maps.MapTypeId.ROADMAP
796
+ });
797
+
798
+ this.googleGeocoder = new google.maps.Geocoder();
799
+ this.infoWindow = new google.maps.InfoWindow();
800
+ },
801
+
802
+ /**
803
+ * Called when window is resized.
804
+ */
805
+ onWindowResize: function () {
806
+ try {
807
+ var container = $('tss-pickup-container');
808
+ var containerHeight = container.offsetHeight;
809
+ var selector = container.select('.tss-selector')[0];
810
+ var headerHeight = container.select('.tss-ls-header')[0].offsetHeight;
811
+ var footerHeight = container.select('.tss-ls-footer-controls')[0].offsetHeight;
812
+ var padding = 20;
813
+ var contentHeight = containerHeight - headerHeight - footerHeight - (padding * 2);
814
+ var minContentHeight = (this.isLoading || this.isClosing) ? 212 : 131;
815
+ if (contentHeight < minContentHeight) {
816
+ padding = 20 - (minContentHeight - contentHeight);
817
+ if (padding < 0) {
818
+ padding = 0;
819
+ }
820
+ contentHeight = minContentHeight;
821
+ }
822
+ else if (contentHeight > 460) {
823
+ contentHeight = 460;
824
+ }
825
+ if (this.isLoading || this.isClosing) {
826
+ contentHeight = 212;
827
+ headerHeight = 0;
828
+ footerHeight = 0;
829
+ }
830
+ var marginTop = Math.round((containerHeight - contentHeight - headerHeight - footerHeight) / 2);
831
+ if (marginTop < padding) {
832
+ marginTop = padding;
833
+ }
834
+
835
+ selector.style.marginTop = marginTop + 'px';
836
+ if (this.isLoading || this.isClosing) {
837
+ return;
838
+ }
839
+ $('tss-ls-map').style.height = contentHeight + 'px';
840
+ $('tss-ls-locations').style.height = (contentHeight - 68) + 'px';
841
+ google.maps.event.trigger(this.googleMaps, 'resize');
842
+ }
843
+ catch (e) {}
844
+ },
845
+
846
+ /**
847
+ * If a location has been selected, the location data is inserted into the input
848
+ * and then closed off.
849
+ */
850
+ selectLocationAndClose: function() {
851
+ if (this.selectedMarker != null && this.selectedMarker.locationData) {
852
+ var locationData = this.selectedMarker.locationData;
853
+ // TODO: btoa only supports Latin1 characters. Make this work with all UTF-8 characters.
854
+ $('tss-ls-location-data').value = btoa(Object.toJSON(locationData));
855
+ $(this.config.selectedLocationDivId).update(this.formatLocationAddress(locationData));
856
+ this.close();
857
+ this.origShippingMethod = this.selectedShippingMethod;
858
+ this.origPickupDivHtml = $(this.config.shippingPickupContainerId).outerHTML;
859
+
860
+ // submit LightCheckout shipping methods
861
+ if (typeof window.Lightcheckout == 'function' && typeof window.checkout == 'object') {
862
+ if (typeof window.checkout.submit == 'function' && typeof window.checkout.getFormData == 'function') {
863
+ window.checkout.submit(window.checkout.getFormData(), 'get_totals');
864
+ }
865
+ }
866
+ }
867
+ },
868
+
869
+ /**
870
+ * Closes off the location selector box
871
+ */
872
+ close: function() {
873
+ this.isClosing = true;
874
+ var pickupContainer = $('tss-pickup-container');
875
+ var pickupLoader = pickupContainer.select('.tss-loader')[0];
876
+ var pickupContent = pickupContainer.select('.tss-selector-container')[0];
877
+
878
+ // Reset the markers
879
+ this.clearMapMarkers();
880
+
881
+ pickupLoader.show();
882
+ pickupContent.hide();
883
+ this.onWindowResize();
884
+
885
+ // Show the pickup container
886
+ pickupContainer.appear({
887
+ duration: 0.3,
888
+ from: 1,
889
+ to: 0,
890
+ afterFinish: function () {
891
+ pickupContainer.hide();
892
+ }
893
+ });
894
+
895
+ if (this.ajaxRequest) {
896
+ this.ajaxRequest.transport.abort();
897
+ }
898
+ }
899
+ });
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Transsmart_Shipping</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL 3.0)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Transsmart Magento connector</summary>
10
+ <description>Integrates Transsmart Shipping into Magento.</description>
11
+ <notes>1.0.0</notes>
12
+ <authors><author><name>Techtwo Webdevelopment B.V.</name><user>techtwo</user><email>info@techtwo.nl</email></author><author><name>Bastiaan Heeren</name><user>techtwobastiaan</user><email>bastiaan@techtwo.nl</email></author></authors>
13
+ <date>2016-01-14</date>
14
+ <time>12:50:12</time>
15
+ <contents><target name="magecommunity"><dir name="Transsmart"><dir name="Shipping"><dir name="Block"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><file name="Grid.php" hash="bafce0b64ee9545b3a355df1b0b8e18d"/><dir name="Shipment"><dir name="Create"><file name="Detail.php" hash="b8b8b391b781f5d9de8b2578ad84d540"/><file name="Package.php" hash="7054391262f4bcc78d77bbd8d7131d61"/></dir><dir name="Masscreate"><file name="Form.php" hash="1bef6372fca204ba939fca5a02f3fa3d"/></dir><file name="Masscreate.php" hash="244adc0427800e5df7ea050947cff0d5"/><dir name="View"><file name="Detail.php" hash="0c5a780a5a4095164b02b06a5cd5ec16"/><file name="Package.php" hash="ccdda1fc1a9710ff1d317575fd53baa7"/></dir></dir><dir name="View"><dir name="Tab"><file name="Shipments.php" hash="e8b2006ed7c6541ea61c309123457c7c"/></dir></dir></dir><dir name="Shipment"><dir name="Grid"><dir name="Renderer"><file name="Link.php" hash="f42b111af0b6fa7dbdd171b9ef9f5655"/></dir></dir><file name="Grid.php" hash="931e2c538a9f61c62fc838d441419c48"/></dir></dir><dir name="Shipping"><dir name="Location"><file name="Info.php" hash="fa01c870d4a5cd521ed312a447f10dda"/></dir></dir><dir name="System"><dir name="Config"><dir name="Form"><dir name="Field"><file name="Fetch.php" hash="43361767a4367c59fea55c23bb52aaed"/></dir><dir name="Fieldset"><dir name="Carrierprofile"><file name="Header.php" hash="01bda5320d4fcb5493f7fc2fd7ec01ac"/></dir><file name="Carrierprofile.php" hash="a75608f6b98458f1797d41d24a52030b"/><file name="Versioninfo.php" hash="84f740e55f0abc8fda7d95d26a638214"/></dir></dir></dir></dir></dir><dir name="Location"><file name="Selector.php" hash="f13d261827cb806fcc14c73058128653"/></dir></dir><dir name="Helper"><file name="Data.php" hash="32590b34298ed7ee39ebc011485e970e"/><file name="Location.php" hash="59dd6de96da501192e995f3688cba950"/><file name="Pickupaddress.php" hash="c71ad4ae7e2c4536a2d57c18d57b8919"/><file name="Shipment.php" hash="1b18a32b3215efa4e0e737d7378e8d1e"/></dir><dir name="Model"><file name="Abstract.php" hash="5b8973d5f3ce40cd641e9f16cdcd6620"/><dir name="Adminhtml"><file name="Observer.php" hash="308cd5a5688d799b3227fcc06cfe0a29"/><dir name="System"><dir name="Config"><dir name="Backend"><file name="Localized.php" hash="3f7ee8815b1f71168ba3fe2f2eb6389f"/></dir><dir name="Source"><dir name="Basedata"><file name="Abstract.php" hash="ac0c0632d16278357cc4128b3a5ef9a8"/><file name="Carrierprofile.php" hash="f01d6e81905f9481a8906253ccfc24e3"/><file name="Costcenter.php" hash="4dabd6942ab4e27e8c7e7032e3d01ca9"/><file name="Emailtype.php" hash="5d5d02c41970795f42e86ec4184a1072"/><file name="Incoterm.php" hash="8724e4b8bd9267fe843d62ffaa939b1e"/><file name="Packagetype.php" hash="6277448d89f3eeaae2dd15dd8a318af1"/><file name="Shipmentlocation.php" hash="f025e24746908e9c5aea82109f3b79fa"/></dir><file name="Environment.php" hash="4d011d8f728c3582022178da0c26ea66"/><dir name="Mapping"><file name="Attribute.php" hash="f2302357356f4c4b6f43cc63c408722a"/><file name="Street.php" hash="e42fa0ede4bc76876cf0c1f783189e87"/></dir><file name="Method.php" hash="672e247ef3764ff9294607102b152c78"/></dir></dir></dir></dir><file name="Carrier.php" hash="9aac846543c6b82cd3a06f9e307593ae"/><file name="Carrierprofile.php" hash="fb3bc266d34c00dbc10b76e89f6de20f"/><file name="Client.php" hash="2042bb6b78e29c41356f8e3ac7e0bbb0"/><file name="Costcenter.php" hash="bf6a9a5a95fa7cf1e0a609c6e0cf6365"/><file name="Emailtype.php" hash="b7128a27c6937c63f9a8ba14510dad13"/><file name="Incoterm.php" hash="8ebd437537680f375568f7873607ef87"/><file name="Observer.php" hash="e42f9c5c5a241e9ed8fef967fe194dee"/><file name="Packagetype.php" hash="d9f5012184c0e52429be7396e4081c69"/><dir name="Resource"><dir name="Carrier"><file name="Collection.php" hash="aabffe27624593ec59d489aaea12319c"/></dir><file name="Carrier.php" hash="57b812414155d31fe39977be1483ab1e"/><dir name="Carrierprofile"><file name="Collection.php" hash="59c40952ae124b257a30eebd72651df7"/></dir><file name="Carrierprofile.php" hash="53d9e49e8cf00b080f80489a476e43ef"/><dir name="Costcenter"><file name="Collection.php" hash="e338f05492a12988d3066bbc2f7569fe"/></dir><file name="Costcenter.php" hash="338db8721bcd09dabbece8e9c862ac92"/><dir name="Emailtype"><file name="Collection.php" hash="fe4ee29a8af109be50e7d928a8d5a9c3"/></dir><file name="Emailtype.php" hash="27b7d676aabf4e16891ccadee409aeba"/><dir name="Incoterm"><file name="Collection.php" hash="7490a144291e1b2a81f5c243173627e3"/></dir><file name="Incoterm.php" hash="5076d4828c71f71178d7d33213d2e735"/><dir name="Packagetype"><file name="Collection.php" hash="f20c13999570a2338feaf1f8af72c85b"/></dir><file name="Packagetype.php" hash="b8de7857c71a26be8915a67c38a1d347"/><dir name="Servicelevel"><dir name="Other"><file name="Collection.php" hash="c48542bc38fc957c97b90bcc2d0d0773"/></dir><file name="Other.php" hash="df8672bc7a5383a6a985703ece13041d"/><dir name="Time"><file name="Collection.php" hash="ee5e6e59deed414768205cc695b4cda3"/></dir><file name="Time.php" hash="2fc0d74b96cf8b7fe38593d9bdaf1a82"/></dir><dir name="Shipmentlocation"><file name="Collection.php" hash="c284bdadf29cf34160e7f8af189f5a43"/></dir><file name="Shipmentlocation.php" hash="99792ed958bffa3d333453888be4b1c4"/><dir name="Sync"><file name="Collection.php" hash="5b837d6fc0fde6c0a7ebef66132d7bcd"/></dir><file name="Sync.php" hash="a538626ff74fa096eb20c95ccf936794"/></dir><dir name="Sales"><dir name="Resource"><file name="Order.php" hash="f078ab890e8a294a75183bcbbb667f2e"/></dir></dir><dir name="Servicelevel"><file name="Other.php" hash="cf779fc0762b7e34974605256d941993"/><file name="Time.php" hash="60188779fd9cfb1e237fd915090acb53"/></dir><file name="Shipmentlocation.php" hash="38147d641e55c3b68a9cecd123081993"/><dir name="Shipping"><dir name="Carrier"><file name="Abstract.php" hash="65c5fc48da295a19c90153ac693c523f"/><file name="Delivery.php" hash="5c2faa12f798aea53343a657bd7c7010"/><file name="Pickup.php" hash="436630941a50a968cf54e929e25fd0c3"/></dir></dir><file name="Sync.php" hash="3bf6c2507b9f679fbda4145afdf326f1"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Transsmart"><dir name="Shipping"><file name="LocationController.php" hash="9ed198c21dd4569cc604c19d6865a74b"/><file name="ShipmentController.php" hash="9967e3414b80aaed728dff5a71694720"/></dir></dir><file name="TranssmartController.php" hash="b5b688249bce5a74bef95319674e5698"/></dir><file name="LocationController.php" hash="f39c3a08069cefc6169c9eed12a97f63"/></dir><dir name="etc"><file name="adminhtml.xml" hash="07f3353cf1d7275e528a18b9883b206f"/><file name="config.xml" hash="05e578944cdb0e5b0069747219a71fba"/><file name="jstranslator.xml" hash="b50cf9cd74e37d6e34b3e360f3353313"/><file name="system.xml" hash="913acd885f5c4a1d33182f022720fe10"/></dir><dir name="sql"><dir name="transsmart_shipping_setup"><file name="install-1.0.0.php" hash="242d4b2aff6d23151dcca7c9cadab352"/></dir></dir><dir name="ssl"><file name="CARoot.crt" hash="f85d1ff17b0079709f131f3ce3f288d2"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="base"><dir name="default"><dir name="layout"><file name="transsmart_shipping.xml" hash="c0578eb781adc2df96e79fe776e387da"/></dir><dir name="template"><dir name="transsmart"><dir name="shipping"><dir name="location"><file name="info.phtml" hash="74ce67c6f39c308995a478279ca1e1bc"/><file name="selector.phtml" hash="841e1d59d042c2b53c622593150675c6"/></dir><dir name="sales"><dir name="order"><dir name="address"><dir name="form"><file name="container.phtml" hash="57a3f3de61e96127659dbf53952a0b33"/></dir></dir><dir name="shipment"><dir name="address"><dir name="form"><file name="container.phtml" hash="9763785687d9f4dfa03d6d1887a3f867"/></dir></dir><dir name="create"><file name="action.phtml" hash="164c1c632265816113e8eb172762871c"/><file name="detail.phtml" hash="c12734fe34fb4a526eb29075d2b80120"/><file name="package.phtml" hash="a39776c6e5f95112e10b9dbc9e29bd14"/></dir><dir name="masscreate"><file name="form.phtml" hash="5e2a281942e88379fa28698a85e519ec"/></dir><dir name="view"><file name="detail.phtml" hash="e901e78ba712f7e99b82409a07c9dedd"/><file name="package.phtml" hash="4ba3f81ed371d87542102974566cb522"/></dir></dir></dir></dir><dir name="system"><dir name="config"><dir name="form"><dir name="field"><file name="fetch.phtml" hash="bf8377c0df88e37305d0d39b5ad72101"/></dir></dir></dir></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="transsmart_shipping.xml" hash="99c0e35e1ef97c0251485fee9b39297e"/></dir><dir name="template"><dir name="transsmart"><dir name="shipping"><dir name="location"><file name="selector.phtml" hash="25000d2769c4e282cdb07dbdc6cb1722"/></dir><dir name="onepage"><dir name="progress"><file name="pickup.phtml" hash="e3874f42cb1d4a9629069d50c39f338e"/></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Transsmart_Shipping.xml" hash="1f526fc89db267b44b7425e2ff645a68"/></dir></target><target name="magelocale"><dir><dir name="nl_NL"><file name="Transsmart_Shipping.csv" hash="6cf4535ee1497b4df66b5526f1ec7f2f"/></dir></dir></target><target name="mageweb"><dir name="js"><dir name="transsmart"><dir name="shipping"><dir name="admin"><file name="pickup_selector.js" hash="7da3ddbbd8e5e4adc4a134faaa7fee0b"/></dir><file name="base64.js" hash="795b1ac117d08652a3a43552c83332ac"/><file name="logger.js" hash="b852d48e077a6114ffe56bd647d1ea5c"/><file name="pickup_selector.js" hash="817d84055cfea02b3f3ce7a073a6e5db"/></dir></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="base"><dir name="default"><dir name="transsmart"><dir name="shipping"><dir name="images"><file name="arrow.png" hash="5b0966d990b40b3510cd2bb57081812d"/><file name="checkmark.png" hash="e5cf08c5943037b8ccc3a5449febdb7b"/><file name="close-btn.png" hash="975d2b3ee2879d4e4b812df8351ccf05"/><file name="info-icon.png" hash="a6baeffe65721d6995f8f06b1669a0ad"/><file name="loader.gif" hash="c5cd7f5300576ab4c88202b42f6ded62"/><file name="radio.png" hash="f149b9aa48f1c3a9da34173c40c882dc"/></dir><file name="pickup_selector.css" hash="9e4b6c280cfd0e2dc6d2d05714b94073"/><file name="styles.css" hash="d61eebd814903f153eb2210bf5f27c5f"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="transsmart"><dir name="shipping"><dir name="images"><file name="arrow.png" hash="5b0966d990b40b3510cd2bb57081812d"/><file name="close-btn.png" hash="975d2b3ee2879d4e4b812df8351ccf05"/><file name="info-icon.png" hash="a6baeffe65721d6995f8f06b1669a0ad"/><file name="loader.gif" hash="c5cd7f5300576ab4c88202b42f6ded62"/><file name="radio.png" hash="f149b9aa48f1c3a9da34173c40c882dc"/></dir><file name="pickup_selector.css" hash="9e4b6c280cfd0e2dc6d2d05714b94073"/></dir></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.3.29</min><max>5.9.9</max></php><extension><name>curl</name><min/><max/></extension></required></dependencies>
18
+ </package>
skin/adminhtml/base/default/transsmart/shipping/images/arrow.png ADDED
Binary file
skin/adminhtml/base/default/transsmart/shipping/images/checkmark.png ADDED
Binary file
skin/adminhtml/base/default/transsmart/shipping/images/close-btn.png ADDED
Binary file
skin/adminhtml/base/default/transsmart/shipping/images/info-icon.png ADDED
Binary file
skin/adminhtml/base/default/transsmart/shipping/images/loader.gif ADDED
Binary file
skin/adminhtml/base/default/transsmart/shipping/images/radio.png ADDED
Binary file
skin/adminhtml/base/default/transsmart/shipping/pickup_selector.css ADDED
@@ -0,0 +1,342 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @category Transsmart
3
+ * @package Transsmart_Shipping
4
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
5
+ */
6
+
7
+ #tss-pickup-container {
8
+ height: 100%;
9
+ left: 0;
10
+ position: absolute;
11
+ top: 0;
12
+ width: 100%;
13
+ z-index: 1000;
14
+ }
15
+
16
+ #tss-pickup-container input, #tss-pickup-container button {
17
+ margin: 0;
18
+ line-height: normal;
19
+ }
20
+
21
+ #tss-pickup-container button {
22
+ -webkit-appearance: button;
23
+ cursor: pointer;
24
+ }
25
+
26
+ #tss-ls-close{
27
+ position: absolute;
28
+ right: 0;
29
+ width: 40px;
30
+ height: 40px;
31
+ border: none;
32
+ text-indent: -999px;
33
+ background: url('images/close-btn.png') no-repeat center center #0094D4;
34
+ overflow: hidden;
35
+ }
36
+
37
+ #tss-ls-close:hover{
38
+ background-color: #0079ae;
39
+ }
40
+
41
+ .tss-selector {
42
+ background: #fff;
43
+ left: 50%;
44
+ text-align: left;
45
+ margin-top: 20px;
46
+ margin-left: -377px;
47
+ position: fixed;
48
+ width: 754px;
49
+ z-index: 1;
50
+ }
51
+
52
+ .tss-selector-inner {
53
+ padding: 0;
54
+ }
55
+
56
+ #tss-pickup-container .tss-background-overlay {
57
+ background-color: #636363;
58
+ height: 100%;
59
+ left: 0;
60
+ opacity: 0.6;
61
+ position: fixed;
62
+ top: 0;
63
+ width: 100%;
64
+ }
65
+
66
+ .tss-selector-container .tss-ls-header {
67
+ -webkit-box-sizing: border-box;
68
+ -moz-box-sizing: border-box;
69
+ box-sizing: border-box;
70
+ float: left;
71
+ padding: 20px;
72
+ width: 100%;
73
+ }
74
+
75
+ .tss-selector-container .tss-ls-header #tss-ls-search{
76
+ -webkit-box-sizing: border-box;
77
+ -moz-box-sizing: border-box;
78
+ box-sizing: border-box;
79
+ background: #EFEFEF;
80
+ border-radius: 5px;
81
+ -moz-border-radius: 5px;
82
+ -webkit-border-radius: 5px;
83
+ border: none;
84
+ color: black;
85
+ height: 36px;
86
+ padding: 0 10px;
87
+ width: 145px;
88
+ }
89
+
90
+ .tss-selector-container .tss-ls-header #tss-ls-search-btn {
91
+ -webkit-box-sizing: border-box;
92
+ -moz-box-sizing: border-box;
93
+ box-sizing: border-box;
94
+ height: 36px;
95
+ padding: 7px 20px;
96
+ }
97
+
98
+ .tss-selector-container .tss-ls-header .tss-ls-options{
99
+ float: right;
100
+ max-width: 274px;
101
+ }
102
+ .tss-selector-container .tss-ls-header .tss-ls-options .tss-ls-checkbox-wrapper{
103
+ float: left;
104
+ margin-left: 10px;
105
+ }
106
+ .tss-selector-container .tss-ls-header .tss-ls-options .tss-ls-checkbox-wrapper label{
107
+ display: inline;
108
+ font-size: 11px;
109
+ vertical-align: text-top;
110
+ }
111
+ .tss-selector-container .tss-ls-header .tss-ls-options .tss-ls-checkbox-wrapper input,
112
+ .tss-selector-container .tss-ls-header .tss-ls-options .tss-ls-checkbox-wrapper label {
113
+ cursor: pointer;
114
+ }
115
+
116
+ .tss-selector-container .tss-ls-header .tss-ls-search-wrapper{
117
+ float: left;
118
+ }
119
+
120
+ .tss-ls-footer-controls button#tss-ls-select,
121
+ .tss-selector-container .tss-ls-header .tss-ls-search-wrapper button{
122
+ background: #0094D4;
123
+ border: none;
124
+ border-radius: 5px;
125
+ -moz-border-radius: 5px;
126
+ -webkit-border-radius: 5px;
127
+ color: white;
128
+ font-family: 'Dosis', sans-serif;
129
+ font-size: 14px;
130
+ font-weight: 500;
131
+ padding: 7px 15px;
132
+ text-transform: uppercase;
133
+ }
134
+
135
+ .tss-ls-footer-controls button#tss-ls-select:hover,
136
+ .tss-selector-container .tss-ls-header .tss-ls-search-wrapper button:hover{
137
+ background-color: #0079ae;
138
+ }
139
+
140
+ .tss-ls-footer-controls button#tss-ls-select.disabled,
141
+ .tss-selector-container .tss-ls-header .tss-ls-search-wrapper button.disabled{
142
+ background-color: #999;
143
+ color: #CCC;
144
+ }
145
+
146
+ .tss-ls-footer-controls button#tss-ls-select{
147
+ background: url('images/arrow.png') no-repeat 87% center #0094D4;
148
+ padding-right: 30px;
149
+ }
150
+
151
+
152
+ .tss-selector-container .tss-ls-header .tss-ls-header-title {
153
+ color: #202020;
154
+ display: block;
155
+ font-family: 'Dosis', sans-serif;
156
+ font-size: 24px;
157
+ font-weight: 600;
158
+ text-transform: uppercase;
159
+ margin-bottom: 10px;
160
+ }
161
+
162
+ .tss-selector-container .tss-ls-header .tss-ls-header-controls {
163
+ margin-top: 5px;
164
+ }
165
+
166
+ .tss-selector-container .tss-ls-content{
167
+ clear: both;
168
+ }
169
+
170
+ .tss-ls-map-container #tss-ls-map {
171
+ float: left;
172
+ height: 460px;
173
+ width: 454px;
174
+ }
175
+
176
+ .tss-ls-map-container #tss-ls-map h1{
177
+ font-family: 'Dosis', sans-serif;
178
+ font-size: 15px;
179
+ max-width: 150px;
180
+ }
181
+
182
+ .tss-ls-map-container #tss-ls-map table td {
183
+ font-size: 11px;
184
+ }
185
+
186
+ #tss-ls-locations {
187
+ -webkit-box-sizing: border-box;
188
+ -moz-box-sizing: border-box;
189
+ box-sizing: border-box;
190
+ width: 300px;
191
+ height: 392px;
192
+ overflow-x: hidden;
193
+ overflow-y: auto;
194
+ padding-left: 15px;
195
+ padding-right: 15px;
196
+ }
197
+
198
+ .tss-ls-location-wrapper{
199
+ -webkit-box-sizing: border-box;
200
+ -moz-box-sizing: border-box;
201
+ box-sizing: border-box;
202
+ float: left;
203
+ }
204
+
205
+ .tss-ls-location-wrapper h3{
206
+ background: #EBF0F3;
207
+ color: #0094D4;
208
+ display: block;
209
+ font-family: 'Dosis', sans-serif;
210
+ font-size: 20px;
211
+ font-weight: 600;
212
+ margin-bottom: 10px;
213
+ padding: 15px;
214
+ text-transform: uppercase;
215
+ }
216
+
217
+ .tss-ls-footer-controls {
218
+ background: white;
219
+ clear: both;
220
+ margin-top: 10px;
221
+ padding: 10px 20px;
222
+ text-align: right;
223
+ }
224
+
225
+
226
+ .tss-ls-location-item {
227
+ border-bottom: 1px solid #E2E2E2;
228
+ display: table;
229
+ padding: 10px 0;
230
+ width: 100%;
231
+ cursor: pointer;
232
+ }
233
+
234
+ .tss-ls-location-item .tss-ls-check{
235
+ display: table-cell;
236
+ line-height: 16px;
237
+ vertical-align: middle;
238
+ width: 25px;
239
+ }
240
+
241
+ .tss-ls-location-item .tss-ls-check .tss-ls-img{
242
+ background: url('images/radio.png') no-repeat center top;
243
+ display: block;
244
+ height: 15px;
245
+ width: 100%;
246
+ }
247
+
248
+ .tss-ls-location-item.selected .tss-ls-check .tss-ls-img{
249
+ background: url('images/radio.png') no-repeat center bottom;
250
+ }
251
+
252
+ .tss-ls-location-item.selected {
253
+ color: #0093d0;
254
+ }
255
+
256
+ .tss-ls-location-item .tss-ls-name{
257
+ display: table-cell;
258
+ min-width: 140px;
259
+ padding-right: 5px;
260
+ }
261
+
262
+ .tss-ls-location-item .tss-ls-distance{
263
+ display: table-cell;
264
+ font-size: 11px;
265
+ margin: 0;
266
+ padding: 0;
267
+ text-align: right;
268
+ vertical-align: middle;
269
+ }
270
+
271
+ .tss-ls-location-item .tss-ls-name .tss-ls-company-name{
272
+ display: block;
273
+ font-weight: bold;
274
+ font-size: 12px;
275
+ line-height: 14px;
276
+ padding-bottom: 3px;
277
+ }
278
+ .tss-ls-location-item .tss-ls-name .tss-ls-address{
279
+ float: left;
280
+ font-size: 11px;
281
+ line-height: 10px;
282
+ }
283
+
284
+ .tss-loader {
285
+ padding-bottom: 20px;
286
+ text-align: center;
287
+ }
288
+
289
+ .tss-loader img{
290
+ display: inline-block;
291
+ margin: 80px 0;
292
+ }
293
+
294
+ #tss-ls-selected-location-info {
295
+ margin-top: 10px;
296
+ }
297
+
298
+ @media (max-width: 770px) {
299
+ .tss-selector {
300
+ width: 300px;
301
+ margin-left: -150px;
302
+ }
303
+ .tss-ls-map-container{
304
+ display: none;
305
+ }
306
+ .tss-selector-container .tss-ls-header{
307
+ padding: 15px 45px 20px 20px;
308
+ }
309
+ .tss-selector-container .tss-ls-header .tss-ls-header-title{
310
+ font-size: 22px;
311
+ }
312
+ .tss-selector-container .tss-ls-header .tss-ls-options{
313
+ float: left;
314
+ margin-top: 10px;
315
+ }
316
+ .tss-selector-container .tss-ls-header .tss-ls-options .tss-ls-checkbox-wrapper{
317
+ margin-left: 0;
318
+ clear: both;
319
+ }
320
+ }
321
+
322
+ @media (min-width: 1200px) {
323
+ .tss-selector {
324
+ width: 950px;
325
+ margin-left: -475px;
326
+ }
327
+ .tss-selector-container .tss-ls-header .tss-ls-options{
328
+ max-width: none;
329
+ }
330
+ .tss-ls-map-container #tss-ls-map{
331
+ width: 540px;
332
+ }
333
+ #tss-ls-locations{
334
+ width: 410px;
335
+ }
336
+ .tss-ls-location-item{
337
+ padding: 18px 0;
338
+ }
339
+ .tss-ls-location-item .tss-ls-check{
340
+ width: 50px;
341
+ }
342
+ }
skin/adminhtml/base/default/transsmart/shipping/styles.css ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @category Transsmart
3
+ * @package Transsmart_Shipping
4
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
5
+ */
6
+
7
+ .three-column { width:32%; }
8
+ .box-middle { float:left; margin-left:2%; }
9
+
10
+ .transsmart-shipment-detail.form-list {
11
+ width: 100%;
12
+ margin-bottom: 5px;
13
+ }
14
+
15
+ .transsmart-shipment-detail.form-list td.label {
16
+ width: auto;
17
+ }
18
+
19
+ .transsmart-shipment-detail.form-list td.label:first-child {
20
+ padding-left: 0 !important;
21
+ }
22
+
23
+ .transsmart-shipment-detail.form-list td.label label {
24
+ white-space: nowrap;
25
+ width: auto;
26
+ }
27
+
28
+ .transsmart-shipment-detail.form-list td.value select {
29
+ width: 100%;
30
+ }
skin/frontend/base/default/transsmart/shipping/images/arrow.png ADDED
Binary file
skin/frontend/base/default/transsmart/shipping/images/close-btn.png ADDED
Binary file
skin/frontend/base/default/transsmart/shipping/images/info-icon.png ADDED
Binary file
skin/frontend/base/default/transsmart/shipping/images/loader.gif ADDED
Binary file
skin/frontend/base/default/transsmart/shipping/images/radio.png ADDED
Binary file
skin/frontend/base/default/transsmart/shipping/pickup_selector.css ADDED
@@ -0,0 +1,342 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @category Transsmart
3
+ * @package Transsmart_Shipping
4
+ * @copyright Copyright (c) 2016 Techtwo Webdevelopment B.V. (http://www.techtwo.nl)
5
+ */
6
+
7
+ #tss-pickup-container {
8
+ height: 100%;
9
+ left: 0;
10
+ position: absolute;
11
+ top: 0;
12
+ width: 100%;
13
+ z-index: 1000;
14
+ }
15
+
16
+ #tss-pickup-container input, #tss-pickup-container button {
17
+ margin: 0;
18
+ line-height: normal;
19
+ }
20
+
21
+ #tss-pickup-container button {
22
+ -webkit-appearance: button;
23
+ cursor: pointer;
24
+ }
25
+
26
+ #tss-ls-close{
27
+ position: absolute;
28
+ right: 0;
29
+ width: 40px;
30
+ height: 40px;
31
+ border: none;
32
+ text-indent: -999px;
33
+ background: url('images/close-btn.png') no-repeat center center #0094D4;
34
+ overflow: hidden;
35
+ }
36
+
37
+ #tss-ls-close:hover{
38
+ background-color: #0079ae;
39
+ }
40
+
41
+ .tss-selector {
42
+ background: #fff;
43
+ left: 50%;
44
+ text-align: left;
45
+ margin-top: 20px;
46
+ margin-left: -377px;
47
+ position: fixed;
48
+ width: 754px;
49
+ z-index: 1;
50
+ }
51
+
52
+ .tss-selector-inner {
53
+ padding: 0;
54
+ }
55
+
56
+ #tss-pickup-container .tss-background-overlay {
57
+ background-color: #636363;
58
+ height: 100%;
59
+ left: 0;
60
+ opacity: 0.6;
61
+ position: fixed;
62
+ top: 0;
63
+ width: 100%;
64
+ }
65
+
66
+ .tss-selector-container .tss-ls-header {
67
+ -webkit-box-sizing: border-box;
68
+ -moz-box-sizing: border-box;
69
+ box-sizing: border-box;
70
+ float: left;
71
+ padding: 20px;
72
+ width: 100%;
73
+ }
74
+
75
+ .tss-selector-container .tss-ls-header #tss-ls-search{
76
+ -webkit-box-sizing: border-box;
77
+ -moz-box-sizing: border-box;
78
+ box-sizing: border-box;
79
+ background: #EFEFEF;
80
+ border-radius: 5px;
81
+ -moz-border-radius: 5px;
82
+ -webkit-border-radius: 5px;
83
+ border: none;
84
+ color: black;
85
+ height: 36px;
86
+ padding: 0 10px;
87
+ width: 145px;
88
+ }
89
+
90
+ .tss-selector-container .tss-ls-header #tss-ls-search-btn {
91
+ -webkit-box-sizing: border-box;
92
+ -moz-box-sizing: border-box;
93
+ box-sizing: border-box;
94
+ height: 36px;
95
+ padding: 7px 20px;
96
+ }
97
+
98
+ .tss-selector-container .tss-ls-header .tss-ls-options{
99
+ float: right;
100
+ max-width: 274px;
101
+ }
102
+ .tss-selector-container .tss-ls-header .tss-ls-options .tss-ls-checkbox-wrapper{
103
+ float: left;
104
+ margin-left: 10px;
105
+ }
106
+ .tss-selector-container .tss-ls-header .tss-ls-options .tss-ls-checkbox-wrapper label{
107
+ display: inline;
108
+ font-size: 11px;
109
+ vertical-align: text-top;
110
+ }
111
+ .tss-selector-container .tss-ls-header .tss-ls-options .tss-ls-checkbox-wrapper input,
112
+ .tss-selector-container .tss-ls-header .tss-ls-options .tss-ls-checkbox-wrapper label {
113
+ cursor: pointer;
114
+ }
115
+
116
+ .tss-selector-container .tss-ls-header .tss-ls-search-wrapper{
117
+ float: left;
118
+ }
119
+
120
+ .tss-ls-footer-controls button#tss-ls-select,
121
+ .tss-selector-container .tss-ls-header .tss-ls-search-wrapper button{
122
+ background: #0094D4;
123
+ border: none;
124
+ border-radius: 5px;
125
+ -moz-border-radius: 5px;
126
+ -webkit-border-radius: 5px;
127
+ color: white;
128
+ font-family: 'Dosis', sans-serif;
129
+ font-size: 14px;
130
+ font-weight: 500;
131
+ padding: 7px 15px;
132
+ text-transform: uppercase;
133
+ }
134
+
135
+ .tss-ls-footer-controls button#tss-ls-select:hover,
136
+ .tss-selector-container .tss-ls-header .tss-ls-search-wrapper button:hover{
137
+ background-color: #0079ae;
138
+ }
139
+
140
+ .tss-ls-footer-controls button#tss-ls-select.disabled,
141
+ .tss-selector-container .tss-ls-header .tss-ls-search-wrapper button.disabled{
142
+ background-color: #999;
143
+ color: #CCC;
144
+ }
145
+
146
+ .tss-ls-footer-controls button#tss-ls-select{
147
+ background: url('images/arrow.png') no-repeat 87% center #0094D4;
148
+ padding-right: 30px;
149
+ }
150
+
151
+
152
+ .tss-selector-container .tss-ls-header .tss-ls-header-title {
153
+ color: #202020;
154
+ display: block;
155
+ font-family: 'Dosis', sans-serif;
156
+ font-size: 24px;
157
+ font-weight: 600;
158
+ text-transform: uppercase;
159
+ margin-bottom: 10px;
160
+ }
161
+
162
+ .tss-selector-container .tss-ls-header .tss-ls-header-controls {
163
+ margin-top: 5px;
164
+ }
165
+
166
+ .tss-selector-container .tss-ls-content{
167
+ clear: both;
168
+ }
169
+
170
+ .tss-ls-map-container #tss-ls-map {
171
+ float: left;
172
+ height: 460px;
173
+ width: 454px;
174
+ }
175
+
176
+ .tss-ls-map-container #tss-ls-map h1{
177
+ font-family: 'Dosis', sans-serif;
178
+ font-size: 15px;
179
+ max-width: 150px;
180
+ }
181
+
182
+ .tss-ls-map-container #tss-ls-map table td {
183
+ font-size: 11px;
184
+ }
185
+
186
+ #tss-ls-locations {
187
+ -webkit-box-sizing: border-box;
188
+ -moz-box-sizing: border-box;
189
+ box-sizing: border-box;
190
+ width: 300px;
191
+ height: 392px;
192
+ overflow-x: hidden;
193
+ overflow-y: auto;
194
+ padding-left: 15px;
195
+ padding-right: 15px;
196
+ }
197
+
198
+ .tss-ls-location-wrapper{
199
+ -webkit-box-sizing: border-box;
200
+ -moz-box-sizing: border-box;
201
+ box-sizing: border-box;
202
+ float: left;
203
+ }
204
+
205
+ .tss-ls-location-wrapper h3{
206
+ background: #EBF0F3;
207
+ color: #0094D4;
208
+ display: block;
209
+ font-family: 'Dosis', sans-serif;
210
+ font-size: 20px;
211
+ font-weight: 600;
212
+ margin-bottom: 10px;
213
+ padding: 15px;
214
+ text-transform: uppercase;
215
+ }
216
+
217
+ .tss-ls-footer-controls {
218
+ background: white;
219
+ clear: both;
220
+ margin-top: 10px;
221
+ padding: 10px 20px;
222
+ text-align: right;
223
+ }
224
+
225
+
226
+ .tss-ls-location-item {
227
+ border-bottom: 1px solid #E2E2E2;
228
+ display: table;
229
+ padding: 10px 0;
230
+ width: 100%;
231
+ cursor: pointer;
232
+ }
233
+
234
+ .tss-ls-location-item .tss-ls-check{
235
+ display: table-cell;
236
+ line-height: 16px;
237
+ vertical-align: middle;
238
+ width: 25px;
239
+ }
240
+
241
+ .tss-ls-location-item .tss-ls-check .tss-ls-img{
242
+ background: url('images/radio.png') no-repeat center top;
243
+ display: block;
244
+ height: 15px;
245
+ width: 100%;
246
+ }
247
+
248
+ .tss-ls-location-item.selected .tss-ls-check .tss-ls-img{
249
+ background: url('images/radio.png') no-repeat center bottom;
250
+ }
251
+
252
+ .tss-ls-location-item.selected {
253
+ color: #0093d0;
254
+ }
255
+
256
+ .tss-ls-location-item .tss-ls-name{
257
+ display: table-cell;
258
+ min-width: 140px;
259
+ padding-right: 5px;
260
+ }
261
+
262
+ .tss-ls-location-item .tss-ls-distance{
263
+ display: table-cell;
264
+ font-size: 11px;
265
+ margin: 0;
266
+ padding: 0;
267
+ text-align: right;
268
+ vertical-align: middle;
269
+ }
270
+
271
+ .tss-ls-location-item .tss-ls-name .tss-ls-company-name{
272
+ display: block;
273
+ font-weight: bold;
274
+ font-size: 12px;
275
+ line-height: 14px;
276
+ padding-bottom: 3px;
277
+ }
278
+ .tss-ls-location-item .tss-ls-name .tss-ls-address{
279
+ float: left;
280
+ font-size: 11px;
281
+ line-height: 10px;
282
+ }
283
+
284
+ .tss-loader {
285
+ padding-bottom: 20px;
286
+ text-align: center;
287
+ }
288
+
289
+ .tss-loader img{
290
+ display: inline-block;
291
+ margin: 80px 0;
292
+ }
293
+
294
+ #tss-ls-selected-location-info {
295
+ margin-top: 10px;
296
+ }
297
+
298
+ @media (max-width: 770px) {
299
+ .tss-selector {
300
+ width: 300px;
301
+ margin-left: -150px;
302
+ }
303
+ .tss-ls-map-container{
304
+ display: none;
305
+ }
306
+ .tss-selector-container .tss-ls-header{
307
+ padding: 15px 45px 20px 20px;
308
+ }
309
+ .tss-selector-container .tss-ls-header .tss-ls-header-title{
310
+ font-size: 22px;
311
+ }
312
+ .tss-selector-container .tss-ls-header .tss-ls-options{
313
+ float: left;
314
+ margin-top: 10px;
315
+ }
316
+ .tss-selector-container .tss-ls-header .tss-ls-options .tss-ls-checkbox-wrapper{
317
+ margin-left: 0;
318
+ clear: both;
319
+ }
320
+ }
321
+
322
+ @media (min-width: 1200px) {
323
+ .tss-selector {
324
+ width: 950px;
325
+ margin-left: -475px;
326
+ }
327
+ .tss-selector-container .tss-ls-header .tss-ls-options{
328
+ max-width: none;
329
+ }
330
+ .tss-ls-map-container #tss-ls-map{
331
+ width: 540px;
332
+ }
333
+ #tss-ls-locations{
334
+ width: 410px;
335
+ }
336
+ .tss-ls-location-item{
337
+ padding: 18px 0;
338
+ }
339
+ .tss-ls-location-item .tss-ls-check{
340
+ width: 50px;
341
+ }
342
+ }