PostPal_Shipping - Version 0.1.0

Version Notes

First version of PostPal extension

Download this release

Release Info

Developer PostPal
Extension PostPal_Shipping
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/community/PostPal/Shipping/Block/Adminhtml/Sales/Order/Shipment/View.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Jana Vassiljeva <jana@artmarka.com>
4
+ */
5
+
6
+ class PostPal_Shipping_Block_Adminhtml_Sales_Order_Shipment_View extends Mage_Adminhtml_Block_Sales_Order_Shipment_View
7
+ {
8
+
9
+
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ $trackPdfUrl = '';
15
+ $trackUrl = Mage::getStoreConfig('carriers/postpal_shipping/track_url');
16
+
17
+ $orderId = $this->getShipment()->getOrderId();
18
+ $order = Mage::getModel("sales/order")->load($orderId);
19
+
20
+ $shippingMethod = $order->getShippingMethod();
21
+
22
+ if ($shippingMethod != 'postpal_shipping_fixed')
23
+ return $this;
24
+
25
+ $tracks = Mage::getResourceModel('sales/order_shipment_collection')
26
+ ->setOrderFilter($order)
27
+ ->load();
28
+
29
+ foreach ($tracks as $shipment){
30
+ foreach($shipment->getAllTracks() as $tracknum)
31
+ {
32
+ $trackPdfUrl = $tracknum->getDescription();
33
+ $trackNumber = $tracknum->getTrackNumber();
34
+ }
35
+ }
36
+
37
+ if (empty($trackPdfUrl))
38
+ return $this;
39
+
40
+ $this->_addButton('print_label', array(
41
+ 'label' => Mage::helper('postpal')->__('Print package label'),
42
+ 'class' => 'save',
43
+ 'target' => '_blank',
44
+ 'onclick' => 'window.open(\''.$trackPdfUrl.'\', \'_blank\')'
45
+ )
46
+ );
47
+
48
+ $this->_addButton('track_label', array(
49
+ 'label' => Mage::helper('postpal')->__('Track this shipment'),
50
+ 'class' => 'save',
51
+ 'target' => '_blank',
52
+ 'onclick' => 'window.open(\''.$trackUrl.'/'.$trackNumber.'\', \'_blank\')'
53
+ )
54
+ );
55
+
56
+ }
57
+
58
+ }
app/code/community/PostPal/Shipping/Helper/Data.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Jana Vassiljeva <jana@artmarka.com>
4
+ */
5
+
6
+ class PostPal_Shipping_Helper_Data extends Mage_Core_Helper_Abstract {
7
+
8
+ }
app/code/community/PostPal/Shipping/Model/Api.php ADDED
@@ -0,0 +1 @@
 
0
  * @author Jana Vassiljeva <jana@artmarka.com>
1
  */
2
  public $location, $key, $warehouseCode;
3
  public function __construct()
4
  {
5
  $this->location = Mage::getStoreConfig('carriers/postpal_shipping/api_url');
6
  $this->key = Mage::getStoreConfig('carriers/postpal_shipping/api_key');
7
  $this->warehouseCode = Mage::getStoreConfig('carriers/postpal_shipping/warehouse_code');
8
  }
9
  /**
10
  * Delivery arrival estimation
11
  * This request will provide information about the estimated delivery arrival to the destination.
12
  * This estimation should be displayed to the enduser before the order is placed.
13
  *
14
  * URL: /estimation
15
  * Type: POST
16
  *
17
  * Parameters:
18
  * token Required. Has to ba valid authentication token.
19
  * warehouse Required. Has to be valid warehouse code.
20
  *
21
  * Response
22
  * Response will contain HTTP code and content in JSON format
23
  *
24
  * Warehouses with open times defined
25
  * HTTP Code: 200 OK
26
  * JSON
27
  * {
28
  * "status": true,
29
  * "estimate": "2015-10-27 00:34:00"
30
  * }
31
  * Warehouses without any upcoming opened times
32
  * HTTP Code: 200 OK
33
  * JSON
34
  * {
35
  * "status": false
36
  * }
37
  * Authentication failed
38
  * HTTP Code: 401 Unauthorized
39
  */
40
  public function getDeliveryArrivalEstimation()
41
  {
42
  $data = array(
43
  'token' => $this->key,
44
  'warehouse' => $this->warehouseCode
45
  );
46
  $url = $this->location . '/estimation';
47
  return $this->sendRequest($url, $data);
48
  }
49
  /**
50
  * Validate before placing a new order
51
  * This request is for validating order details, before placing a new delivery order to PostPal
52
  *
53
  * URL: /orders/new/warehouse/validate
54
  * Type: POST
55
  *
56
  * Parameters:
57
  * token - Required. Has to ba valid authentication token Authentication token
58
  * warehouse - Required. Warehouse code
59
  * destinationFirstName - Required. (if destinationFullName is empty). Max 225 characters. Package receiver name
60
  * destinationLastName - Required. (if destinationFullName is empty). Max 225 characters. Package receiver lastname
61
  * destinationFullName - Required. (if destinationFirstName and destinationLastName are empty). Max 225 characters. Package receiver full name
62
  * destinationCompany - Optional. Max 255 characters Package receiver company name
63
  * destinationEmail - Optional. Max 255. Must be valid email address. Package receiver email
64
  * destinationApartment - Optional. Max 50. Apartment number, floor etc. Where in the building it should be delivered
65
  * destinationAddress - Required. Address of the building (street and building number), where the package will be delivered
66
  * destinationLocality - Optional. Max 50. Destination city. If missing, warehouse city will be used.
67
  * destinationCountry - Optional. Max 50. Destination country name. If missing, warehouse country will be used.
68
  * destinationPostalCode - Optional. Max 50. Destination postal code
69
  * destinationPhone - Required. Can start with +, can contain numbers from 0-9, has to be 6 to 13 digits long. Package receiver phone number notes Optional Notes for the order/courier
70
  * packageSize Required. Enum [ size20x36x60D10W ,size60x36x60D10W ] Package size that will be delivered
71
  *
72
  * Response
73
  * Response will contain HTTP code and content in JSON format.
74
  * Order successfully validated
75
  * HTTP Code: 200 OK
76
  * JSON
77
  * {
78
  * "status": true,
79
  * }
80
  *
81
  * Order validation failed
82
  * HTTP Code: 422 Unprocessable Entity
83
  * JSON
84
  * {
85
  * "status": false,
86
  * "errors": {
87
  * "destinationLastName": {
88
  * "Code": 001,
89
  * "Text": "destinationLastName Missing"
90
  * },
91
  * "destinationAddress": {
92
  * " Code": 001,
93
  * "Text": "destinationAddress Missing"
94
  * }
95
  * }
96
  * }
97
  * Authentication failed
98
  * HTTP Code: 401 Unauthorized
99
  */
100
 
101
  public function getOrderValidation(array $data)
102
  {
103
  $data = array(
104
  'token' => $this->key,
105
  'warehouse' => $this->warehouseCode,
106
  'destinationFirstName' => $data['shippingAddress']['firstname'],
107
  'destinationLastName' => $data['shippingAddress']['lastname'],
108
  'destinationFullName' => '',
109
  'destinationCompany' => $data['shippingAddress']['company'],
110
  'destinationEmail' => $data['shippingAddress']['email'],
111
  'destinationApartment' => '',
112
  'destinationAddress' => $data['shippingAddress']['street'],
113
  'destinationLocality' => $data['shippingAddress']['city'],
114
  'destinationCountry' => $data['shippingAddress']['country_id'],
115
  'destinationPostalCode' => $data['shippingAddress']['postcode'],
116
  'destinationPhone' => $data['shippingAddress']['telephone'],
117
  'notes' => '',
118
  'packageSize' => $data['packageSize']
119
  );
120
  $url = $this->location . '/orders/new/warehouse/validate';
121
  return $this->sendRequest($url, $data);
122
  }
123
  /**
124
  * Validate before placing a new order
125
  * This request is for validating order details, before placing a new delivery order to PostPal
126
  *
127
  * URL: /orders/new/warehouse
128
  * Type: POST
129
  *
130
  * Parameters:
131
  * token - Required. Has to ba valid authentication token Authentication token
132
  * warehouse - Required. Warehouse code
133
  * destinationFirstName - Required. (if destinationFullName is empty). Max 225 characters. Package receiver name
134
  * destinationLastName - Required. (if destinationFullName is empty). Max 225 characters. Package receiver lastname
135
  * destinationFullName - Required. (if destinationFirstName and destinationLastName are empty). Max 225 characters. Package receiver full name
136
  * destinationCompany - Optional. Max 255 characters Package receiver company name
137
  * destinationEmail - Optional. Max 255. Must be valid email address. Package receiver email
138
  * destinationApartment - Optional. Max 50. Apartment number, floor etc. Where in the building it should be delivered
139
  * destinationAddress - Required. Address of the building (street and building number), where the package will be delivered
140
  * destinationLocality - Optional. Max 50. Destination city. If missing, warehouse city will be used.
141
  * destinationCountry - Optional. Max 50. Destination country name. If missing, warehouse country will be used.
142
  * destinationPostalCode - Optional. Max 50. Destination postal code
143
  * destinationPhone - Required. Can start with +, can contain numbers from 0-9, has to be 6 to 13 digits long. Package receiver phone number notes Optional Notes for the order/courier
144
  * packageSize Required. Enum [ size20x36x60D10W ,size60x36x60D10W ] Package size that will be delivered
145
  *
146
  * Response
147
  * Response will contain HTTP code and content in JSON format.
148
  * Order successfully validated
149
  * HTTP Code: 200 OK
150
  * JSON
151
  * {
152
  * "status": true,
153
  * "trackingCode": "994887674",
154
  * "trackingURL": "http://test.postpal.ee/track/994887674",
155
  * "packageLabelPDF": "http://test.postpal.ee/label/pdf/eae336ce1fec0d54d2ff2ac702da31e0"
156
  * }
157
  *
158
  * Order validation failed
159
  * HTTP Code: 422 Unprocessable Entity
160
  * JSON
161
  * {
162
  * "status": false,
163
  * "errors": {
164
  * "destinationLastName": {
165
  * "Code": 001,
166
  * "Text": "destinationLastName Missing"
167
  * },
168
  * "destinationAddress": {
169
  * " Code": 001,
170
  * "Text": "destinationAddress Missing"
171
  * }
172
  * }
173
  * }
174
  * Authentication failed
175
  * HTTP Code: 401 Unauthorized
176
  */
177
  public function sendNewOrder(array $data)
178
  {
179
  $data = array(
180
  'token' => $this->key,
181
  'warehouse' => $this->warehouseCode,
182
  'destinationFirstName' => $data['shippingAddress']['firstname'],
183
  'destinationLastName' => $data['shippingAddress']['lastname'],
184
  'destinationFullName' => '',
185
  'destinationCompany' => $data['shippingAddress']['company'],
186
  'destinationEmail' => $data['shippingAddress']['email'],
187
  'destinationApartment' => '',
188
  'destinationAddress' => $data['shippingAddress']['street'],
189
  'destinationLocality' => $data['shippingAddress']['city'],
190
  'destinationCountry' => $data['shippingAddress']['country_id'],
191
  'destinationPostalCode' => $data['shippingAddress']['postcode'],
192
  'destinationPhone' => $data['shippingAddress']['telephone'],
193
  'notes' => '',
194
  'packageSize' => $data['packageSize']
195
  );
196
  $url = $this->location . '/orders/new/warehouse';
197
  return $this->sendRequest($url, $data);
198
  }
199
  private function sendRequest($url, $data)
200
  {
201
  $httpClient = new Varien_Http_Client();
202
  $httpClient->setUri($url);
203
  $httpClient->setMethod('POST');
204
  $httpClient->setHeaders('Content-Type', 'application/json');
205
  $httpClient->setParameterPost($data);
206
  $response = $httpClient->request();
207
  $responseBody = $response->getRawBody();
208
  //Mage::log('PostPal response body:\n ' . print_r($responseBody, true));
209
  return json_decode($responseBody);
210
  }
1
+ <?php
2
  * @author Jana Vassiljeva <jana@artmarka.com>
3
  */
4
  public $location, $key, $warehouseCode;
5
  public function __construct()
6
  {
7
  $this->location = Mage::getStoreConfig('carriers/postpal_shipping/api_url');
8
  $this->key = Mage::getStoreConfig('carriers/postpal_shipping/api_key');
9
  $this->warehouseCode = Mage::getStoreConfig('carriers/postpal_shipping/warehouse_code');
10
  }
11
  /**
12
  * Delivery arrival estimation
13
  * This request will provide information about the estimated delivery arrival to the destination.
14
  * This estimation should be displayed to the enduser before the order is placed.
15
  *
16
  * URL: /estimation
17
  * Type: POST
18
  *
19
  * Parameters:
20
  * token Required. Has to ba valid authentication token.
21
  * warehouse Required. Has to be valid warehouse code.
22
  *
23
  * Response
24
  * Response will contain HTTP code and content in JSON format
25
  *
26
  * Warehouses with open times defined
27
  * HTTP Code: 200 OK
28
  * JSON
29
  * {
30
  * "status": true,
31
  * "estimate": "2015-10-27 00:34:00"
32
  * }
33
  * Warehouses without any upcoming opened times
34
  * HTTP Code: 200 OK
35
  * JSON
36
  * {
37
  * "status": false
38
  * }
39
  * Authentication failed
40
  * HTTP Code: 401 Unauthorized
41
  */
42
  public function getDeliveryArrivalEstimation()
43
  {
44
  $data = array(
45
  'token' => $this->key,
46
  'warehouse' => $this->warehouseCode
47
  );
48
  $url = $this->location . '/estimation';
49
  return $this->sendRequest($url, $data);
50
  }
51
  /**
52
  * Validate before placing a new order
53
  * This request is for validating order details, before placing a new delivery order to PostPal
54
  *
55
  * URL: /orders/new/warehouse/validate
56
  * Type: POST
57
  *
58
  * Parameters:
59
  * token - Required. Has to ba valid authentication token Authentication token
60
  * warehouse - Required. Warehouse code
61
  * destinationFirstName - Required. (if destinationFullName is empty). Max 225 characters. Package receiver name
62
  * destinationLastName - Required. (if destinationFullName is empty). Max 225 characters. Package receiver lastname
63
  * destinationFullName - Required. (if destinationFirstName and destinationLastName are empty). Max 225 characters. Package receiver full name
64
  * destinationCompany - Optional. Max 255 characters Package receiver company name
65
  * destinationEmail - Optional. Max 255. Must be valid email address. Package receiver email
66
  * destinationApartment - Optional. Max 50. Apartment number, floor etc. Where in the building it should be delivered
67
  * destinationAddress - Required. Address of the building (street and building number), where the package will be delivered
68
  * destinationLocality - Optional. Max 50. Destination city. If missing, warehouse city will be used.
69
  * destinationCountry - Optional. Max 50. Destination country name. If missing, warehouse country will be used.
70
  * destinationPostalCode - Optional. Max 50. Destination postal code
71
  * destinationPhone - Required. Can start with +, can contain numbers from 0-9, has to be 6 to 13 digits long. Package receiver phone number notes Optional Notes for the order/courier
72
  * packageSize Required. Enum [ size20x36x60D10W ,size60x36x60D10W ] Package size that will be delivered
73
  *
74
  * Response
75
  * Response will contain HTTP code and content in JSON format.
76
  * Order successfully validated
77
  * HTTP Code: 200 OK
78
  * JSON
79
  * {
80
  * "status": true,
81
  * }
82
  *
83
  * Order validation failed
84
  * HTTP Code: 422 Unprocessable Entity
85
  * JSON
86
  * {
87
  * "status": false,
88
  * "errors": {
89
  * "destinationLastName": {
90
  * "Code": 001,
91
  * "Text": "destinationLastName Missing"
92
  * },
93
  * "destinationAddress": {
94
  * " Code": 001,
95
  * "Text": "destinationAddress Missing"
96
  * }
97
  * }
98
  * }
99
  * Authentication failed
100
  * HTTP Code: 401 Unauthorized
101
  */
102
 
103
  public function getOrderValidation(array $data)
104
  {
105
  $data = array(
106
  'token' => $this->key,
107
  'warehouse' => $this->warehouseCode,
108
  'destinationFirstName' => $data['shippingAddress']['firstname'],
109
  'destinationLastName' => $data['shippingAddress']['lastname'],
110
  'destinationFullName' => '',
111
  'destinationCompany' => $data['shippingAddress']['company'],
112
  'destinationEmail' => $data['shippingAddress']['email'],
113
  'destinationApartment' => '',
114
  'destinationAddress' => $data['shippingAddress']['street'],
115
  'destinationLocality' => $data['shippingAddress']['city'],
116
  'destinationCountry' => $data['shippingAddress']['country_id'],
117
  'destinationPostalCode' => $data['shippingAddress']['postcode'],
118
  'destinationPhone' => $data['shippingAddress']['telephone'],
119
  'notes' => '',
120
  'packageSize' => $data['packageSize']
121
  );
122
  $url = $this->location . '/orders/new/warehouse/validate';
123
  return $this->sendRequest($url, $data);
124
  }
125
  /**
126
  * Validate before placing a new order
127
  * This request is for validating order details, before placing a new delivery order to PostPal
128
  *
129
  * URL: /orders/new/warehouse
130
  * Type: POST
131
  *
132
  * Parameters:
133
  * token - Required. Has to ba valid authentication token Authentication token
134
  * warehouse - Required. Warehouse code
135
  * destinationFirstName - Required. (if destinationFullName is empty). Max 225 characters. Package receiver name
136
  * destinationLastName - Required. (if destinationFullName is empty). Max 225 characters. Package receiver lastname
137
  * destinationFullName - Required. (if destinationFirstName and destinationLastName are empty). Max 225 characters. Package receiver full name
138
  * destinationCompany - Optional. Max 255 characters Package receiver company name
139
  * destinationEmail - Optional. Max 255. Must be valid email address. Package receiver email
140
  * destinationApartment - Optional. Max 50. Apartment number, floor etc. Where in the building it should be delivered
141
  * destinationAddress - Required. Address of the building (street and building number), where the package will be delivered
142
  * destinationLocality - Optional. Max 50. Destination city. If missing, warehouse city will be used.
143
  * destinationCountry - Optional. Max 50. Destination country name. If missing, warehouse country will be used.
144
  * destinationPostalCode - Optional. Max 50. Destination postal code
145
  * destinationPhone - Required. Can start with +, can contain numbers from 0-9, has to be 6 to 13 digits long. Package receiver phone number notes Optional Notes for the order/courier
146
  * packageSize Required. Enum [ size20x36x60D10W ,size60x36x60D10W ] Package size that will be delivered
147
  *
148
  * Response
149
  * Response will contain HTTP code and content in JSON format.
150
  * Order successfully validated
151
  * HTTP Code: 200 OK
152
  * JSON
153
  * {
154
  * "status": true,
155
  * "trackingCode": "994887674",
156
  * "trackingURL": "http://test.postpal.ee/track/994887674",
157
  * "packageLabelPDF": "http://test.postpal.ee/label/pdf/eae336ce1fec0d54d2ff2ac702da31e0"
158
  * }
159
  *
160
  * Order validation failed
161
  * HTTP Code: 422 Unprocessable Entity
162
  * JSON
163
  * {
164
  * "status": false,
165
  * "errors": {
166
  * "destinationLastName": {
167
  * "Code": 001,
168
  * "Text": "destinationLastName Missing"
169
  * },
170
  * "destinationAddress": {
171
  * " Code": 001,
172
  * "Text": "destinationAddress Missing"
173
  * }
174
  * }
175
  * }
176
  * Authentication failed
177
  * HTTP Code: 401 Unauthorized
178
  */
179
  public function sendNewOrder(array $data)
180
  {
181
  $data = array(
182
  'token' => $this->key,
183
  'warehouse' => $this->warehouseCode,
184
  'destinationFirstName' => $data['shippingAddress']['firstname'],
185
  'destinationLastName' => $data['shippingAddress']['lastname'],
186
  'destinationFullName' => '',
187
  'destinationCompany' => $data['shippingAddress']['company'],
188
  'destinationEmail' => $data['shippingAddress']['email'],
189
  'destinationApartment' => '',
190
  'destinationAddress' => $data['shippingAddress']['street'],
191
  'destinationLocality' => $data['shippingAddress']['city'],
192
  'destinationCountry' => $data['shippingAddress']['country_id'],
193
  'destinationPostalCode' => $data['shippingAddress']['postcode'],
194
  'destinationPhone' => $data['shippingAddress']['telephone'],
195
  'notes' => '',
196
  'packageSize' => $data['packageSize']
197
  );
198
  $url = $this->location . '/orders/new/warehouse';
199
  return $this->sendRequest($url, $data);
200
  }
201
  private function sendRequest($url, $data)
202
  {
203
  $httpClient = new Varien_Http_Client();
204
  $httpClient->setUri($url);
205
  $httpClient->setMethod('POST');
206
  $httpClient->setHeaders('Content-Type', 'application/json');
207
  $httpClient->setParameterPost($data);
208
  $response = $httpClient->request();
209
  $responseBody = $response->getRawBody();
210
  //Mage::log('PostPal response body:\n ' . print_r($responseBody, true));
211
  return json_decode($responseBody);
212
  }
app/code/community/PostPal/Shipping/Model/Carrier.php ADDED
@@ -0,0 +1 @@
 
0
  * @author Jana Vassiljeva <jana@artmarka.com>
1
  */
2
  protected $_code = 'postpal_shipping';
3
  public function collectRates(Mage_Shipping_Model_Rate_Request $request)
4
  {
5
  $result = Mage::getModel('shipping/rate_result');
6
  /* @var $result Mage_Shipping_Model_Rate_Result */
7
  $result->append($this->_getStandardShippingRate());
8
  return $result;
9
  }
10
  public function isTrackingAvailable()
11
  {
12
  return true;
13
  }
14
  protected function _getStandardShippingRate()
15
  {
16
  $rate = Mage::getModel('shipping/rate_result_method');
17
  /* @var $rate Mage_Shipping_Model_Rate_Result_Method */
18
  $rate->setCarrier($this->_code);
19
  /**
20
  * getConfigData(config_key) returns the configuration value for the
21
  * carriers/[carrier_code]/[config_key]
22
  */
23
  $rate->setCarrierTitle($this->getConfigData('title'));
24
  $rate->setMethod('fixed');
25
  $result = Mage::getModel('postpal_shipping/api')->getDeliveryArrivalEstimation();
26
  if (empty($result) || $result->status == false)
27
  return false;
28
  $formatedTime = date('d.m.Y H:i', strtotime($result->estimateFriendly));
29
  $rate->setMethodTitle($this->getConfigData('name'). ' ('. Mage::helper('postpal')->__('ETA: '). ' ' . $result->estimateFriendly . ') ');
30
  $rate->setPrice($this->getConfigData('default_price'));
31
  $rate->setCost(0);
32
  return $rate;
33
  }
34
  public function getAllowedMethods() {
35
  return array();
36
  }
1
+ <?php
2
  * @author Jana Vassiljeva <jana@artmarka.com>
3
  */
4
  protected $_code = 'postpal_shipping';
5
  public function collectRates(Mage_Shipping_Model_Rate_Request $request)
6
  {
7
  $result = Mage::getModel('shipping/rate_result');
8
  /* @var $result Mage_Shipping_Model_Rate_Result */
9
  $result->append($this->_getStandardShippingRate());
10
  return $result;
11
  }
12
  public function isTrackingAvailable()
13
  {
14
  return true;
15
  }
16
  protected function _getStandardShippingRate()
17
  {
18
  $rate = Mage::getModel('shipping/rate_result_method');
19
  /* @var $rate Mage_Shipping_Model_Rate_Result_Method */
20
  $rate->setCarrier($this->_code);
21
  /**
22
  * getConfigData(config_key) returns the configuration value for the
23
  * carriers/[carrier_code]/[config_key]
24
  */
25
  $rate->setCarrierTitle($this->getConfigData('title'));
26
  $rate->setMethod('fixed');
27
  $result = Mage::getModel('postpal_shipping/api')->getDeliveryArrivalEstimation();
28
  if (empty($result) || $result->status == false)
29
  return false;
30
  $formatedTime = date('d.m.Y H:i', strtotime($result->estimateFriendly));
31
  $rate->setMethodTitle($this->getConfigData('name'). ' ('. Mage::helper('postpal')->__('ETA: '). ' ' . $result->estimateFriendly . ') ');
32
  $rate->setPrice($this->getConfigData('default_price'));
33
  $rate->setCost(0);
34
  return $rate;
35
  }
36
  public function getAllowedMethods() {
37
  return array();
38
  }
app/code/community/PostPal/Shipping/Model/Observer.php ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Jana Vassiljeva <jana@artmarka.com>
4
+ */
5
+
6
+ class PostPal_Shipping_Model_Observer extends Varien_Object
7
+ {
8
+
9
+ public function getOrderValidation($observer)
10
+ {
11
+ $passed = false;
12
+ $errors = '';
13
+ $order = $observer->getEvent()->getOrder();
14
+
15
+ $shippingMethod = $order->getShippingMethod();
16
+
17
+ if ($shippingMethod != 'postpal_shipping_fixed')
18
+ return $this;
19
+
20
+ $data = array(
21
+ 'shippingAddress' => $order->getShippingAddress()->getData(),
22
+ 'packageSize' => 'size20x36x60D10W'
23
+ );
24
+
25
+ $result = Mage::getModel('postpal_shipping/api')->getOrderValidation($data);
26
+
27
+ if (!empty($result) && $result->status == 'true')
28
+ $passed = true;
29
+
30
+ if(!$passed)
31
+ {
32
+ if (!empty($result->errors)) {
33
+ foreach ($result->errors as $key => $error) {
34
+
35
+ if($key == 'token' || $key == 'warehouse') {
36
+ $errors .= Mage::helper('postpal')->__('PostPal shipping plugin is not configured correctly').';';
37
+ }
38
+ elseif($error->Code == '201') {
39
+ $errors .= Mage::helper('postpal')->__('Address not Found').';';
40
+ }
41
+ elseif($error->Code == '202') {
42
+ $errors .= Mage::helper('postpal')->__('Address out of range').';';
43
+ }
44
+ elseif($error->Code == '001' && ($key == 'destinationFirstName' ||
45
+ $key == 'destinationLastName' || $key == 'destinationFullName')) {
46
+ $errors .= Mage::helper('postpal')->__('Name is missing').';';
47
+ }
48
+ elseif($error->Code == '001' && $key == 'destinationAddress') {
49
+ $errors .= Mage::helper('postpal')->__('Address is missing').';';
50
+ }
51
+ elseif($error->Code == '001' && $key == 'destinationPhone') {
52
+ $errors .= Mage::helper('postpal')->__('Phone number is missing').';';
53
+ }
54
+ elseif($error->Code == '001' && $key == 'packageSize') {
55
+ $errors .= Mage::helper('postpal')->__('Package size is missing').';';
56
+ }
57
+ elseif($error->Code == '002' && ($key == 'destinationFirstName' ||
58
+ $key == 'destinationLastName' || $key == 'destinationFullName')) {
59
+ $errors .= Mage::helper('postpal')->__('Name is not correct').';';
60
+ }
61
+ elseif($error->Code == '002' && $key == 'destinationCompany') {
62
+ $errors .= Mage::helper('postpal')->__('Company name is not correct').';';
63
+ }
64
+ elseif($error->Code == '002' && $key == 'destinationEmail') {
65
+ $errors .= Mage::helper('postpal')->__('E-mail is not correct').';';
66
+ }
67
+ elseif($error->Code == '002' && $key == 'destinationApartment') {
68
+ $errors .= Mage::helper('postpal')->__('Apartment in address is not correct').';';
69
+ }
70
+ elseif($error->Code == '002' && $key == 'destinationAddress') {
71
+ $errors .= Mage::helper('postpal')->__('Address is not correct').';';
72
+ }
73
+ elseif($error->Code == '002' && $key == 'destinationLocality') {
74
+ $errors .= Mage::helper('postpal')->__('Locality in address is not correct').';';
75
+ }
76
+ elseif($error->Code == '002' && $key == 'destinationCountry') {
77
+ $errors .= Mage::helper('postpal')->__('Country in address is not correct').';';
78
+ }
79
+ elseif($error->Code == '002' && $key == 'destinationPostalCode') {
80
+ $errors .= Mage::helper('postpal')->__('Postal code is not correct').';';
81
+ }
82
+ elseif($error->Code == '002' && $key == 'destinationPhone') {
83
+ $errors .= Mage::helper('postpal')->__('Phone number is not correct').';';
84
+ }
85
+ elseif($error->Code == '002' && $key == 'notes') {
86
+ $errors .= Mage::helper('postpal')->__('Notes are not correct').';';
87
+ }
88
+ elseif($error->Code == '002' && $key == 'packageSize') {
89
+ $errors .= Mage::helper('postpal')->__('Package size is not correct').';';
90
+ }
91
+ }
92
+ }
93
+ elseif($result == 'Unauthorized.')
94
+ $errors .= Mage::helper('postpal')->__('PostPal shipping plugin is not configured correctly').';';
95
+
96
+ Mage::throwException($errors);
97
+ }
98
+ }
99
+
100
+ public function sendOrderData($observer)
101
+ {
102
+ /* @var $invoice Mage_Sales_Model_Order_Invoice */
103
+ $invoice = $observer->getEvent()->getInvoice();
104
+ /* @var $order Mage_Sales_Model_Order */
105
+ $order = $invoice->getOrder();
106
+
107
+ $shippingMethod = $order->getShippingMethod();
108
+
109
+ if ($shippingMethod != 'postpal_shipping_fixed')
110
+ return $this;
111
+
112
+ $data = array(
113
+ 'shippingAddress' => $order->getShippingAddress()->getData(),
114
+ 'packageSize' => 'size20x36x60D10W'
115
+ );
116
+
117
+ if ($invoice instanceof Mage_Sales_Model_Order_Invoice)
118
+ {
119
+ $result = Mage::getModel('postpal_shipping/api')->sendNewOrder($data);
120
+ if (!empty($result) && $result->status == 'true') {
121
+ Mage::getModel('postpal_shipping/shipping')->completeShipment($order, $result);
122
+ }
123
+
124
+ }
125
+
126
+ return $this;
127
+ }
128
+
129
+ }
app/code/community/PostPal/Shipping/Model/Shipping.php ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Jana Vassiljeva <jana@artmarka.com>
4
+ */
5
+
6
+ class PostPal_Shipping_Model_Shipping
7
+ {
8
+ /**
9
+ * Completes the Shipment, followed by completing the Order life-cycle
10
+ * It is assumed that the Invoice has already been generated
11
+ * and the amount has been captured.
12
+ */
13
+ public function completeShipment($order, $shipmentResult)
14
+ {
15
+ if (!$order->getId()) {
16
+ Mage::throwException("Order does not exist, for the Shipment process to complete");
17
+ }
18
+
19
+ if ($order->canShip()) {
20
+ try {
21
+
22
+ $shipment = Mage::getModel('sales/service_order', $order)
23
+ ->prepareShipment($this->_getItemQtys($order));
24
+
25
+ /**
26
+ * Carrier Codes can be like "ups" / "fedex" / "custom",
27
+ * but they need to be active from the System Configuration area.
28
+ * These variables can be provided custom-value, but it is always
29
+ * suggested to use Order values
30
+ */
31
+
32
+ $arrTracking = array(
33
+ 'carrier_code' => 'postpal_shipping_fixed',
34
+ 'title' => 'PostPal',
35
+ 'description' =>$shipmentResult->packageLabelPDF,
36
+ 'number' => $shipmentResult->trackingCode,
37
+ );
38
+
39
+ $track = Mage::getModel('sales/order_shipment_track')->addData($arrTracking);
40
+ $shipment->addTrack($track);
41
+
42
+ // Register Shipment
43
+ $shipment->register();
44
+
45
+ // Save the Shipment
46
+ $this->_saveShipment($shipment, $order);
47
+
48
+ // Finally, Save the Order
49
+ $this->_saveOrder($order);
50
+ } catch (Exception $e) {
51
+ throw $e;
52
+ }
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Get the Quantities shipped for the Order, based on an item-level
58
+ * This method can also be modified, to have the Partial Shipment functionality in place
59
+ *
60
+ * @param $order Mage_Sales_Model_Order
61
+ * @return array
62
+ */
63
+ protected function _getItemQtys(Mage_Sales_Model_Order $order)
64
+ {
65
+ $qty = array();
66
+ foreach ($order->getAllItems() as $_eachItem) {
67
+ if ($_eachItem->getParentItemId()) {
68
+ $qty[$_eachItem->getParentItemId()] = $_eachItem->getQtyOrdered();
69
+ } else {
70
+ $qty[$_eachItem->getId()] = $_eachItem->getQtyOrdered();
71
+ }
72
+ }
73
+
74
+ return $qty;
75
+ }
76
+
77
+ /**
78
+ * Saves the Shipment changes in the Order
79
+ *
80
+ * @param $shipment Mage_Sales_Model_Order_Shipment
81
+ * @param $order Mage_Sales_Model_Order
82
+ * @param $customerEmailComments string
83
+ */
84
+ protected function _saveShipment(Mage_Sales_Model_Order_Shipment $shipment, Mage_Sales_Model_Order $order, $customerEmailComments = '')
85
+ {
86
+ $shipment->getOrder()->setIsInProcess(true);
87
+ $transactionSave = Mage::getModel('core/resource_transaction')
88
+ ->addObject($shipment)
89
+ ->addObject($order)
90
+ ->save();
91
+
92
+ $shippingAddress = $order->getShippingAddress()->getData();
93
+ $customerEmail = $shippingAddress['email'];
94
+ $emailSentStatus = $shipment->getData('email_sent');
95
+
96
+ if (!is_null($customerEmail) && !$emailSentStatus) {
97
+ $shipment->sendEmail(true, $customerEmailComments);
98
+ $shipment->setEmailSent(true);
99
+ }
100
+
101
+ return $this;
102
+ }
103
+
104
+ /**
105
+ * Saves the Order, to complete the full life-cycle of the Order
106
+ * Order status will now show as Complete
107
+ *
108
+ * @param $order Mage_Sales_Model_Order
109
+ */
110
+ protected function _saveOrder(Mage_Sales_Model_Order $order)
111
+ {
112
+ $order->setData('state', Mage_Sales_Model_Order::STATE_COMPLETE);
113
+ $order->setData('status', Mage_Sales_Model_Order::STATE_COMPLETE);
114
+
115
+ $order->save();
116
+
117
+ return $this;
118
+ }
119
+ }
app/code/community/PostPal/Shipping/etc/config.xml ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <PostPal_Shipping>
5
+ <module>0.0.1</module>
6
+ </PostPal_Shipping>
7
+ </modules>
8
+ <frontend>
9
+ <translate>
10
+ <modules>
11
+ <postpal_shipping>
12
+ <files>
13
+ <default>PostPal_Shipping.csv</default>
14
+ </files>
15
+ </postpal_shipping>
16
+ </modules>
17
+ </translate>
18
+ <layout>
19
+ <updates>
20
+ <postpal_shipping>
21
+ <file>postpal/shipping.xml</file>
22
+ </postpal_shipping>
23
+ </updates>
24
+ </layout>
25
+ </frontend>
26
+ <global>
27
+ <models>
28
+ <postpal_shipping>
29
+ <class>PostPal_Shipping_Model</class>
30
+ </postpal_shipping>
31
+ </models>
32
+ <helpers>
33
+ <postpal>
34
+ <class>PostPal_Shipping_Helper</class>
35
+ </postpal>
36
+ </helpers>
37
+ <blocks>
38
+ <overrides>
39
+ <class>PostPal_Shipping_Block</class>
40
+ </overrides>
41
+ <adminhtml>
42
+ <rewrite>
43
+ <sales_order_shipment_view>PostPal_Shipping_Block_Adminhtml_Sales_Order_Shipment_View</sales_order_shipment_view>
44
+ </rewrite>
45
+ </adminhtml>
46
+ </blocks>
47
+ <events>
48
+ <sales_order_invoice_pay>
49
+ <observers>
50
+ <postpal_shipping_send_order>
51
+ <type>singleton</type>
52
+ <class>PostPal_Shipping_Model_Observer</class>
53
+ <method>sendOrderData</method>
54
+ </postpal_shipping_send_order>
55
+ </observers>
56
+ </sales_order_invoice_pay>
57
+ <sales_order_place_before>
58
+ <observers>
59
+ <postpal_shipping_get_order_validation>
60
+ <class>PostPal_Shipping_Model_Observer</class>
61
+ <method>getOrderValidation</method>
62
+ </postpal_shipping_get_order_validation>
63
+ </observers>
64
+ </sales_order_place_before>
65
+ </events>
66
+ </global>
67
+ <!-- Default configuration -->
68
+ <default>
69
+ <carriers>
70
+ <postpal_shipping>
71
+ <active>1</active>
72
+ <model>postpal_shipping/carrier</model>
73
+ <title>PostPal</title>
74
+ <name>Express courier</name>
75
+ <sort_order>1</sort_order>
76
+ <sallowspecific>0</sallowspecific>
77
+ <api_url>http://dev.postpal.ee/api/shop/v1</api_url>
78
+ <track_url>http://dev.postpal.ee/track</track_url>
79
+ <specificerrmsg>This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us.</specificerrmsg>
80
+ <showmethod>1</showmethod>
81
+ </postpal_shipping>
82
+ </carriers>
83
+ </default>
84
+ </config>
app/code/community/PostPal/Shipping/etc/system.xml ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <sections>
4
+ <carriers translate="label" module="shipping">
5
+ <groups>
6
+ <postpal_shipping translate="label">
7
+ <label>PostPal</label>
8
+ <frontend_type>text</frontend_type>
9
+ <sort_order>1</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>1</show_in_store>
13
+ <fields>
14
+ <!--
15
+ The following fields are available
16
+ to modify in the admin panel.
17
+ The values are saved in the
18
+ database.
19
+
20
+ This shipping carrier abstract checks
21
+ this value to determine whether
22
+ the carrier should be shown.
23
+ -->
24
+ <active translate="label">
25
+ <label>Enabled</label>
26
+ <frontend_type>select</frontend_type>
27
+ <source_model>adminhtml/system_config_source_yesno</source_model>
28
+ <sort_order>1</sort_order>
29
+ <show_in_default>1</show_in_default>
30
+ <show_in_website>1</show_in_website>
31
+ <show_in_store>0</show_in_store>
32
+ </active>
33
+ <title translate="label">
34
+ <label>Title</label>
35
+ <frontend_type>text</frontend_type>
36
+ <sort_order>2</sort_order>
37
+ <show_in_default>1</show_in_default>
38
+ <show_in_website>1</show_in_website>
39
+ <show_in_store>1</show_in_store>
40
+ </title>
41
+ <name translate="label">
42
+ <label>Method Name</label>
43
+ <frontend_type>text</frontend_type>
44
+ <source_model>adminhtml/system_config_source_yesno</source_model>
45
+ <sort_order>3</sort_order>
46
+ <show_in_default>1</show_in_default>
47
+ <show_in_website>1</show_in_website>
48
+ <show_in_store>1</show_in_store>
49
+ </name>
50
+ <default_price translate="label">
51
+ <label>Fixed price</label>
52
+ <frontend_type>text</frontend_type>
53
+ <sort_order>4</sort_order>
54
+ <show_in_default>1</show_in_default>
55
+ <show_in_website>1</show_in_website>
56
+ <show_in_store>0</show_in_store>
57
+ </default_price>
58
+ <sallowspecific translate="label">
59
+ <label>Ship to Applicable Countries</label>
60
+ <frontend_type>select</frontend_type>
61
+ <sort_order>5</sort_order>
62
+ <frontend_class>shipping-applicable-country</frontend_class>
63
+ <source_model>adminhtml/system_config_source_shipping_allspecificcountries</source_model>
64
+ <show_in_default>1</show_in_default>
65
+ <show_in_website>1</show_in_website>
66
+ <show_in_store>0</show_in_store>
67
+ </sallowspecific>
68
+ <specificcountry translate="label">
69
+ <label>Ship to Specific Countries</label>
70
+ <frontend_type>multiselect</frontend_type>
71
+ <sort_order>6</sort_order>
72
+ <source_model>adminhtml/system_config_source_country</source_model>
73
+ <show_in_default>1</show_in_default>
74
+ <show_in_website>1</show_in_website>
75
+ <show_in_store>0</show_in_store>
76
+ <can_be_empty>1</can_be_empty>
77
+ </specificcountry>
78
+ <track_url translate="label">
79
+ <label>Postpal Track Url</label>
80
+ <frontend_type>text</frontend_type>
81
+ <sort_order>7</sort_order>
82
+ <show_in_default>0</show_in_default>
83
+ <show_in_website>0</show_in_website>
84
+ <show_in_store>0</show_in_store>
85
+ </track_url>
86
+ <api_url translate="label">
87
+ <label>Api Url</label>
88
+ <frontend_type>text</frontend_type>
89
+ <sort_order>7</sort_order>
90
+ <show_in_default>0</show_in_default>
91
+ <show_in_website>0</show_in_website>
92
+ <show_in_store>0</show_in_store>
93
+ </api_url>
94
+ <api_key translate="label">
95
+ <label>Api key</label>
96
+ <frontend_type>text</frontend_type>
97
+ <sort_order>8</sort_order>
98
+ <show_in_default>1</show_in_default>
99
+ <show_in_website>1</show_in_website>
100
+ <show_in_store>0</show_in_store>
101
+ <comment>Comment</comment>
102
+ </api_key>
103
+ <warehouse_code translate="label">
104
+ <label>Warehouse code</label>
105
+ <frontend_type>text</frontend_type>
106
+ <sort_order>9</sort_order>
107
+ <show_in_default>1</show_in_default>
108
+ <show_in_website>1</show_in_website>
109
+ <show_in_store>0</show_in_store>
110
+ <comment>Comment</comment>
111
+ </warehouse_code>
112
+ <specificerrmsg translate="label">
113
+ <label>Displayed Error Message</label>
114
+ <frontend_type>textarea</frontend_type>
115
+ <sort_order>10</sort_order>
116
+ <show_in_default>1</show_in_default>
117
+ <show_in_website>1</show_in_website>
118
+ <show_in_store>1</show_in_store>
119
+ </specificerrmsg>
120
+ <sort_order translate="label">
121
+ <label>Sort Order</label>
122
+ <frontend_type>text</frontend_type>
123
+ <sort_order>11</sort_order>
124
+ <show_in_default>1</show_in_default>
125
+ <show_in_website>1</show_in_website>
126
+ <show_in_store>0</show_in_store>
127
+ </sort_order>
128
+ </fields>
129
+ </postpal_shipping>
130
+ </groups>
131
+ </carriers>
132
+ </sections>
133
+ </config>
app/design/frontend/base/default/layout/postpal/shipping.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <checkout_onepage_index>
4
+ <reference name="head">
5
+ <action method="addCss"><stylesheet>postpal/css/postpal.css</stylesheet></action>
6
+ </reference>
7
+ <reference name="content">
8
+ <block type="page/html_head" name="extra_js" as="extraJs" after="-" template="postpal/extras.phtml"/>
9
+ </reference>
10
+ </checkout_onepage_index>
11
+
12
+ </layout>
app/design/frontend/base/default/template/postpal/extras.phtml ADDED
@@ -0,0 +1 @@
 
1
+ <script type="text/javascript" src="<?php echo $this->getSkinUrl('postpal/js/opcheckout_postpal.js') ?>"></script>
app/etc/modules/PostPal_Shipping.xml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <PostPal_Shipping>
5
+ <!-- Whether our module is active: true or false -->
6
+ <active>true</active>
7
+ <!-- Which code pool to use: core, community or local -->
8
+ <codePool>community</codePool>
9
+ <depends>
10
+ <Mage_Shipping />
11
+ </depends>
12
+ </PostPal_Shipping>
13
+ </modules>
14
+ </config>
app/locale/en_US/PostPal_Shipping.csv ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "PostPal shipping plugin is not configured correctly", "PostPal shipping plugin is not configured correctly"
2
+ "Address not Found", "Incorrect Shipping Address"
3
+ "Address out of range", "Address is out of PostPal covearage area"
4
+ "ETA:", "ETA:"
5
+ "Name is missing", "Name is missing"
6
+ "Address is missing", "Address is missing"
7
+ "Phone number is missing", "Phone number is missing"
8
+ "Package size is missing", "Package size is missing"
9
+ "Company name is not correct", "Company name is not correct"
10
+ "E-mail is not correct", "Email is not correct"
11
+ "Apartment in address is not correct", "Apartment in address is not correct"
12
+ "Address is not correct", "Address is not correct"
13
+ "Locality in address is not correct", "Locality in address is not correct"
14
+ "Country in address is not correct", "Country in address is not correct"
15
+ "Postal code is not correct", "Postal code is not correct"
16
+ "Phone number is not correct", "Phone number is not correct"
17
+ "Notes are not correct", "Notes are not correct"
18
+ "Package size is not correct", "Package size is not correct"
app/locale/et_EE/PostPal_Shipping.csv ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "PostPal shipping plugin is not configured correctly", "PostPal plugin ei ole korrektselt seadistatud"
2
+ "Address not Found", "Sellist aadressi ei leitud"
3
+ "Address out of range", "Address jääb PostPal levialast välja"
4
+ "ETA:", "ETA:"
5
+ "Name is missing", "Nime välja ei leitud"
6
+ "Address is missing", "Aadressi välja ei leitud"
7
+ "Phone number is missing", "Telefoninumbri välja ei leitud"
8
+ "Package size is missing", "Paki suuruse välja ei leitud"
9
+ "Company name is not correct", "Ettevõtte nimi ei ole õigesti sisestatud"
10
+ "E-mail is not correct", "E-mail ei ole õigesti sisestatud"
11
+ "Apartment in address is not correct", "Korteri number aadressis ei ole õigesti sisestatud"
12
+ "Address is not correct", "Aadresse ei ole õigesti sisestatud"
13
+ "Locality in address is not correct", "Aadress ei ole õige"
14
+ "Country in address is not correct", "Riik ei ole õigesti siestatud"
15
+ "Postal code is not correct", "Postikood ei ole õigesti sisestatud"
16
+ "Phone number is not correct", "Telefoninumber ei ole õigesti sisestatud"
17
+ "Notes are not correct", "Märkmed ei ole õigesti sisestatud"
18
+ "Package size is not correct", "Paki suurus ei ole õigesti sisestatud"
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>PostPal_Shipping</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>PostPal shipping extension</summary>
10
+ <description>This extension adds PostPal on-demand courier service to your shopping cart.</description>
11
+ <notes>First version of PostPal extension</notes>
12
+ <authors><author><name>PostPal</name><user>PostPal</user><email>hello@postpal.ee</email></author></authors>
13
+ <date>2015-12-20</date>
14
+ <time>18:16:57</time>
15
+ <contents><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="postpal"><dir name="css"><file name="postpal.css" hash="5b3f0d0cce5377aa5bf6978865d0061b"/></dir><dir name="img"><file name="postpal_logo.png" hash="fc3f0bbb0d70f229321bcdd31eaa7549"/></dir><dir name="js"><file name="opcheckout_postpal.js" hash="411e71bf3de1de55247e753fb965d480"/></dir></dir></dir></dir></dir></target><target name="magecommunity"><dir name="PostPal"><dir name="Shipping"><dir name="Block"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><dir name="Shipment"><file name="View.php" hash="edc39b75e3b0e69ae5dc122c4078ac7a"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="9dfca5f43c00ccab5f1f5b8ac5445c8e"/></dir><dir name="Model"><file name="Api.php" hash="fd8bd87f5798e5da81a1d5dcdf58f020"/><file name="Carrier.php" hash="611d97b1f48c9e0ca53404f33d7b64de"/><file name="Observer.php" hash="1e61ca4d0cb36d73137d4110ad4070b6"/><file name="Shipping.php" hash="5f3ceaa12a412f8c9bcf50551292dcf7"/></dir><dir name="etc"><file name="config.xml" hash="9912407bc11128f5d26c9e1d59b077f0"/><file name="system.xml" hash="ed221153d603cfa5f3bfaae51d5ab896"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="postpal"><file name="shipping.xml" hash="c078788b7f0659b061ea7c70bd2b4a70"/></dir></dir><dir name="template"><dir name="postpal"><file name="extras.phtml" hash="8bad02b894d8fc8da8dbd5729dfceff1"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="PostPal_Shipping.xml" hash="8336b32b2ec54a8ebf90029265ab5729"/></dir></target><target name="magelocale"><dir><dir name="en_US"><file name="PostPal_Shipping.csv" hash="50052dc9f9a55bc8a4ff56ce43606eff"/></dir><dir name="et_EE"><file name="PostPal_Shipping.csv" hash="d9d64841396d1a0fb705246409ea7933"/></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.3.0</min><max>7.0.0</max></php><extension><name>json</name><min/><max/></extension></required></dependencies>
18
+ </package>
skin/frontend/base/default/postpal/css/postpal.css ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ label[for=s_method_postpal_shipping_fixed]:before {
2
+ content: url('../img/postpal_logo.png');
3
+ position: relative;
4
+ top: 5px;
5
+ right: 2px;
6
+ }
7
+
8
+ .postpal_error_wrapper {
9
+ position: relative;
10
+ padding: 5px;
11
+ margin: 5px;
12
+ border: 1px solid red;
13
+ }
14
+
15
+ .postpal_error_close {
16
+ cursor: pointer;
17
+ position: absolute;
18
+ top: 0;
19
+ right: 4px;
20
+ }
skin/frontend/base/default/postpal/img/postpal_logo.png ADDED
Binary file
skin/frontend/base/default/postpal/js/opcheckout_postpal.js ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Review.prototype.nextStep = function(transport){
2
+ if (transport && transport.responseText) {
3
+ try{
4
+ response = eval('(' + transport.responseText + ')');
5
+ }
6
+ catch (e) {
7
+ response = {};
8
+ }
9
+ if (response.redirect) {
10
+ this.isSuccess = true;
11
+ location.href = response.redirect;
12
+ return;
13
+ }
14
+ if (response.success) {
15
+ this.isSuccess = true;
16
+ window.location=this.successUrl;
17
+ }
18
+ else{
19
+ var msg = response.error_messages;
20
+ if (typeof(msg)=='object') {
21
+ msg = msg.join("\n");
22
+ }
23
+ if (msg) {
24
+ msg = msg.replace(new RegExp((';').replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"), 'g'), '<br />');
25
+ if ($('checkout-step-review') != null) {
26
+ $('checkout-step-review').update('<div class="error postpal_error_wrapper" id="checkoutError">'+msg+'<span class="postpal_error_close">x</span></div>'+$('checkout-step-review').innerHTML);
27
+ }
28
+ else {
29
+ alert(msg);
30
+ }
31
+ }
32
+ }
33
+
34
+ if (response.update_section) {
35
+ $('checkout-'+response.update_section.name+'-load').update(response.update_section.html);
36
+ }
37
+
38
+ if (response.goto_section) {
39
+ checkout.gotoSection(response.goto_section, true);
40
+ }
41
+ }
42
+ }
43
+
44
+
45
+ $(document).on('click', '.section .button, .section .btn-checkout, .postpal_error_close', function() {
46
+ PostPal_Close_Error_Message();
47
+ });
48
+
49
+ function PostPal_Close_Error_Message() {
50
+
51
+ if($('checkout-step-review') != null && $('checkoutError') != null)
52
+ $('checkout-step-review').removeChild($('checkoutError'));
53
+
54
+ }