Fontera_ShippingZA - Version 1.0.0

Version Notes

Fontera Digital Works Magento shipping extension for South Africa requests a shipping quote from a local courier, for any postal code in South Africa.

Download this release

Release Info

Developer Shaughn Le Grange - Hatlen
Extension Fontera_ShippingZA
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/Fontera/ShippingZA/Helper/Data.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Shipping South Africa Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ *
13
+ * @category Fontera
14
+ * @package Fontera_ShippingZA
15
+ * @copyright Copyright (c) 2012 Fontera (http://www.fontera.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ * @author Shaughn Le Grange - Hatlen <shaughn.legrange-hatlen@fontera.com>
18
+ */
19
+
20
+ class Fontera_ShippingZA_Helper_Data extends Mage_Core_Helper_Abstract
21
+ {
22
+ }
app/code/local/Fontera/ShippingZA/Model/Shipping/Carrier/Abstract.php ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Shipping South Africa Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ *
13
+ * @category Fontera
14
+ * @package Fontera_ShippingZA
15
+ * @copyright Copyright (c) 2012 Fontera (http://www.fontera.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ * @author Shaughn Le Grange - Hatlen <shaughn.legrange-hatlen@fontera.com>
18
+ */
19
+
20
+ abstract class Fontera_ShippingZA_Model_Shipping_Carrier_Abstract extends Mage_Shipping_Model_Carrier_Abstract
21
+ {
22
+
23
+ protected static $_quotesCache = array();
24
+
25
+ const ZA_COUNTRY_ID = 'ZA';
26
+
27
+ /**
28
+ * Flag for check carriers for activity
29
+ *
30
+ * @var string
31
+ */
32
+ protected $_activeFlag = 'active';
33
+
34
+ /**
35
+ * Set flag for check carriers for activity
36
+ *
37
+ * @param string $code
38
+ * @return Fontera_ShippingZA_Model_Shipping_Carrier_Abstract
39
+ */
40
+ public function setActiveFlag($code = 'active')
41
+ {
42
+ $this->_activeFlag = $code;
43
+ return $this;
44
+ }
45
+
46
+ /**
47
+ * Return code of carrier
48
+ *
49
+ * @return string
50
+ */
51
+ public function getCarrierCode()
52
+ {
53
+ return isset($this->_code) ? $this->_code : null;
54
+ }
55
+
56
+ /**
57
+ * Check if zip code option required
58
+ *
59
+ * @return boolean
60
+ */
61
+ public function isZipCodeRequired()
62
+ {
63
+ return true;
64
+ }
65
+
66
+ /**
67
+ * Check is Country ZA
68
+ *
69
+ * @param string $countyId
70
+ * @return boolean
71
+ */
72
+ protected function _isZACountry($countyId)
73
+ {
74
+ switch ($countyId) {
75
+ case 'ZA': // South Africa
76
+ return true;
77
+ }
78
+
79
+ return false;
80
+ }
81
+
82
+ /**
83
+ * Processing additional validation to check is carrier applicable.
84
+ *
85
+ * @param Mage_Shipping_Model_Rate_Request $request
86
+ * @return Mage_Shipping_Model_Carrier_Abstract|Mage_Shipping_Model_Rate_Result_Error|boolean
87
+ */
88
+ public function proccessAdditionalValidation(Mage_Shipping_Model_Rate_Request $request)
89
+ {
90
+ //Skip by item validation if there is no items in request
91
+ if(!count($request->getAllItems())) {
92
+ return $this;
93
+ }
94
+
95
+ $errorMsg = '';
96
+ $showMethod = $this->getConfigData('showmethod');
97
+
98
+ if (!$errorMsg && !$request->getDestPostcode() && $this->isZipCodeRequired()) {
99
+ $errorMsg = Mage::helper('shippingza')->__('This shipping method is not available, please specify a postal code');
100
+ }
101
+
102
+ if ($errorMsg && $showMethod) {
103
+ $error = Mage::getModel('shipping/rate_result_error');
104
+ $error->setCarrier($this->_code);
105
+ $error->setCarrierTitle($this->getConfigData('title'));
106
+ $error->setErrorMessage($errorMsg);
107
+ return $error;
108
+ } elseif ($errorMsg) {
109
+ return false;
110
+ }
111
+ return $this;
112
+ }
113
+
114
+ /**
115
+ * Returns cache key for some request to carrier quotes service
116
+ *
117
+ * @param string|array $requestParams
118
+ * @return string
119
+ */
120
+ protected function _getQuotesCacheKey($requestParams)
121
+ {
122
+ if (is_array($requestParams)) {
123
+ $requestParams = implode(',', array_merge(
124
+ array($this->getCarrierCode()),
125
+ array_keys($requestParams),
126
+ $requestParams)
127
+ );
128
+ }
129
+ return crc32($requestParams);
130
+ }
131
+
132
+ /**
133
+ * Checks whether some request to rates have already been done, so we have cache for it
134
+ * Used to reduce number of same requests done to carrier service during one session
135
+ *
136
+ * Returns cached response or null
137
+ *
138
+ * @param string|array $requestParams
139
+ * @return null|string
140
+ */
141
+ protected function _getCachedQuotes($requestParams)
142
+ {
143
+ $key = $this->_getQuotesCacheKey($requestParams);
144
+ return isset(self::$_quotesCache[$key]) ? self::$_quotesCache[$key] : null;
145
+ }
146
+
147
+ /**
148
+ * Sets received carrier quotes to cache
149
+ *
150
+ * @param string|array $requestParams
151
+ * @param string $response
152
+ * @return Fontera_ShippingZA_Model_Shipping_Carrier_Abstract
153
+ */
154
+ protected function _setCachedQuotes($requestParams, $response)
155
+ {
156
+ $key = $this->_getQuotesCacheKey($requestParams);
157
+ self::$_quotesCache[$key] = $response;
158
+ Mage::log(self::$_quotesCache);
159
+ return self::$_quotesCache[$key];
160
+ }
161
+
162
+ }
app/code/local/Fontera/ShippingZA/Model/Shipping/Carrier/Berco.php ADDED
@@ -0,0 +1,612 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Shipping South Africa Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ *
13
+ * @category Fontera
14
+ * @package Fontera_ShippingZA
15
+ * @copyright Copyright (c) 2012 Fontera (http://www.fontera.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ * @author Shaughn Le Grange - Hatlen <shaughn.legrange-hatlen@fontera.com>
18
+ */
19
+
20
+ class Fontera_ShippingZA_Model_Shipping_Carrier_Berco
21
+ extends Fontera_ShippingZA_Model_Shipping_Carrier_Abstract
22
+ implements Mage_Shipping_Model_Carrier_Interface
23
+ {
24
+ /**
25
+ * Code of the carrier
26
+ *
27
+ * @var string
28
+ */
29
+ const CODE = 'berco';
30
+
31
+ /**
32
+ * Code of the carrier
33
+ *
34
+ * @var string
35
+ */
36
+ protected $_code = self::CODE;
37
+
38
+ /**
39
+ * Rate request data
40
+ *
41
+ * @var Mage_Shipping_Model_Rate_Request|null
42
+ */
43
+ protected $_request = null;
44
+
45
+ /**
46
+ * Raw rate request data
47
+ *
48
+ * @var Varien_Object|null
49
+ */
50
+ protected $_rawRequest = null;
51
+
52
+ /**
53
+ * Rate result data
54
+ *
55
+ * @var Mage_Shipping_Model_Rate_Result|null
56
+ */
57
+ protected $_result = null;
58
+
59
+ /**
60
+ * Default gateway url
61
+ *
62
+ * @var string
63
+ */
64
+ protected $_defaultGatewayUrl = 'http://interfaces.bercoexpress.co.za/';
65
+
66
+ /**
67
+ * Get gateway url path
68
+ *
69
+ * @return string
70
+ */
71
+ protected function getGatewayUrlPath()
72
+ {
73
+ $serviceType = $this->getConfigData('service_type');
74
+ if ($serviceType == 'REST') {
75
+ $gatewayUrlPath = 'rest/';
76
+ }
77
+ if ($serviceType == 'SOAP') {
78
+ $gatewayUrlPath = 'BercoServices/BercoService.asmx/';
79
+ }
80
+ return $gatewayUrlPath;
81
+ }
82
+
83
+ /**
84
+ * Collect and get rates
85
+ *
86
+ * @param Mage_Shipping_Model_Rate_Request $request
87
+ * @return Mage_Shipping_Model_Rate_Result|bool|null
88
+ */
89
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request)
90
+ {
91
+ if (!$this->getConfigFlag($this->_activeFlag)) {
92
+ return false;
93
+ }
94
+
95
+ $this->setRequest($request);
96
+
97
+ $this->_result = $this->_getQuotes();
98
+
99
+ return $this->getResult();
100
+ }
101
+
102
+ /**
103
+ * Prepare and set request to this instance
104
+ *
105
+ * @param Mage_Shipping_Model_Rate_Request $request
106
+ * @return Fontera_ShippingZA_Model_Shipping_Carrier_Berco
107
+ */
108
+ public function setRequest(Mage_Shipping_Model_Rate_Request $request)
109
+ {
110
+ $this->_request = $request;
111
+
112
+ $r = new Varien_Object();
113
+
114
+ //Set action
115
+ $r->setAction('RateEstimate');
116
+
117
+ //Set store
118
+ $r->setStoreId($request->getStoreId());
119
+
120
+ //Set limited method
121
+ if ($request->getLimitMethod()) {
122
+ $r->setService($request->getLimitMethod());
123
+ }
124
+
125
+ //Set account number
126
+ if ($request->getBercoAccount()) {
127
+ $account = $request->getBercoAccount();
128
+ } else {
129
+ $account = $this->getConfigData('account');
130
+ }
131
+ $r->setAccountNumber($account);
132
+
133
+ //Set user id
134
+ if ($request->getBercoUserid()) {
135
+ $userId = $request->getBercoUserid();
136
+ } else {
137
+ $userId = $this->getConfigData('userid');
138
+ }
139
+ $r->setUserId($userId);
140
+
141
+ //Set multiple origins
142
+ if ($request->getBercoMultipleOrigins()) {
143
+ $multiOrigins = $request->getBercoMultipleOrigins();
144
+ } else {
145
+ $multiOrigins = $this->getConfigData('multiple_origins');
146
+ }
147
+ $multiOrigins = $multiOrigins ? 'Yes' : 'No';
148
+ $r->setMultiOrigins($multiOrigins);
149
+
150
+ $xmlPathStoreCountryId = Mage_Shipping_Model_Shipping::XML_PATH_STORE_COUNTRY_ID;
151
+ $xmlPathStoreRegionId = Mage_Shipping_Model_Shipping::XML_PATH_STORE_REGION_ID;
152
+ $xmlPathStoreZip = Mage_Shipping_Model_Shipping::XML_PATH_STORE_ZIP;
153
+ $xmlPathStoreCity = Mage_Shipping_Model_Shipping::XML_PATH_STORE_CITY;
154
+ $xmlPathStoreAddress1 = Mage_Shipping_Model_Shipping::XML_PATH_STORE_ADDRESS1;
155
+ $xmlPathStoreAddress2 = Mage_Shipping_Model_Shipping::XML_PATH_STORE_ADDRESS2;
156
+
157
+ //Set origin attributes
158
+ if ($multiOrigins == 'Yes') {
159
+ $websites = Mage::app()->getWebsites(true, true);
160
+ $origins = array();
161
+ $adminOrigins = array();
162
+ foreach ($websites as $code => $website) {
163
+ if ($code !== 'admin') {
164
+ $result = array(
165
+ 'country_id' => $website->getConfig($xmlPathStoreCountryId),
166
+ 'region_id' => $website->getConfig($xmlPathStoreRegionId),
167
+ 'postcode' => $website->getConfig($xmlPathStoreZip),
168
+ 'city' => $website->getConfig($xmlPathStoreCity),
169
+ 'address' => $website->getConfig($xmlPathStoreAddress1). ' ' .$website->getConfig($xmlPathStoreAddress2)
170
+ );
171
+
172
+ $origins[] = $result;
173
+ } else {
174
+ $result = array(
175
+ 'country_id' => $website->getConfig($xmlPathStoreCountryId),
176
+ 'region_id' => $website->getConfig($xmlPathStoreRegionId),
177
+ 'postcode' => $website->getConfig($xmlPathStoreZip),
178
+ 'city' => $website->getConfig($xmlPathStoreCity),
179
+ 'address' => $website->getConfig($xmlPathStoreAddress1). ' ' .$website->getConfig($xmlPathStoreAddress2)
180
+ );
181
+ $adminOrigins[] = $result;
182
+ }
183
+ }
184
+
185
+ if (count($origins) !== 0) {
186
+ $r->setOrigins($origins);
187
+ } else {
188
+ $r->setOrigins($adminOrigins);
189
+ }
190
+ } else {
191
+ //Set origin country id
192
+ if ($request->getOrigCountryId()) {
193
+ $r->setOrigCountryId($request->getOrigCountryId());
194
+ } else {
195
+ $r->setOrigCountryId(Mage::getStoreConfig($xmlPathStoreCountryId, $request->getStoreId()));
196
+ }
197
+
198
+ //Set origin region id
199
+ if ($request->getOrigRegionId()) {
200
+ $r->setOrigRegionId($request->getOrigRegionId());
201
+ } else {
202
+ $r->setOrigRegionId(Mage::getStoreConfig($xmlPathStoreRegionId, $request->getStoreId()));
203
+ }
204
+
205
+ //Set origin postal code
206
+ if ($request->getOrigPostcode()) {
207
+ $r->setOrigPostal($request->getOrigPostcode());
208
+ } else {
209
+ $r->setOrigPostal(Mage::getStoreConfig($xmlPathStoreZip, $request->getStoreId()));
210
+ }
211
+
212
+ //Set origin city
213
+ if ($request->getOrigCity()) {
214
+ $r->setOrigCity($request->getOrigCity());
215
+ } else {
216
+ $r->setOrigCity(Mage::getStoreConfig($xmlPathStoreCity, $request->getStoreId()));
217
+ }
218
+
219
+ //Set origin address
220
+ if ($request->getOrigAddress()) {
221
+ $r->setOrigAddress($request->getOrigAddress());
222
+ } else {
223
+ $r->setOrigAddress(Mage::getStoreConfig($xmlPathStoreAddress1, $request->getStoreId()). ' ' .Mage::getStoreConfig($xmlPathStoreAddress2, $request->getStoreId()));
224
+ }
225
+ }
226
+
227
+ //Set destination country id
228
+ if ($request->getDestCountryId()) {
229
+ $destCountry = $request->getDestCountryId();
230
+ } else {
231
+ $destCountry = self::ZA_COUNTRY_ID;
232
+ }
233
+ $r->setDestCountryId($destCountry);
234
+
235
+ //Set destination postal code
236
+ if ($request->getDestPostcode()) {
237
+ $r->setDestPostal($request->getDestPostcode());
238
+ }
239
+
240
+ //Set weight Kg
241
+ $weight = $request->getPackageWeight();
242
+ $r->setWeightKg($weight);
243
+
244
+ //Set volume
245
+ $volume = $this->getPackageVolume();
246
+ $r->setVolume($volume);
247
+
248
+ $this->_rawRequest = $r;
249
+
250
+ return $this;
251
+ }
252
+
253
+ /**
254
+ * Get package volume
255
+ *
256
+ * @return int
257
+ */
258
+ public function getPackageVolume()
259
+ {
260
+ $items = Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection()->getItems();
261
+ $totalVolume = 0;
262
+
263
+ foreach($items as $item) {
264
+ $qty = $item->getQty();
265
+ $product = Mage::getModel('catalog/product')->load($item->getProductId());
266
+ $volume = $product->getVolume();
267
+
268
+ $totalVolume = $totalVolume + ($volume * $qty);
269
+ }
270
+
271
+ return $totalVolume;
272
+ }
273
+
274
+ /**
275
+ * Get result of request
276
+ *
277
+ * @return mixed
278
+ */
279
+ public function getResult()
280
+ {
281
+ return $this->_result;
282
+ }
283
+
284
+ /**
285
+ * Get quotes
286
+ *
287
+ * @return Mage_Shipping_Model_Rate_Result
288
+ */
289
+ protected function _getQuotes()
290
+ {
291
+ return $this->_doRequest();
292
+ }
293
+
294
+ /**
295
+ * Do rate request and handle errors
296
+ *
297
+ * @return Mage_Shipping_Model_Rate_Result|Varien_Object
298
+ */
299
+ protected function _doRequest()
300
+ {
301
+ $r = $this->_rawRequest;
302
+
303
+ $allowedMethods = $this->getConfigData('allowed_methods');
304
+ $methods = explode(',', $allowedMethods);
305
+
306
+ $parsedResult = array();
307
+
308
+ $cache = Mage::getSingleton('shippingza/shipping_carrier_cache');
309
+
310
+ if ($allowedMethods !== '') {
311
+
312
+ foreach ($methods as $method) {
313
+ $serviceCode = $this->getCode('method_to_code', $method);
314
+
315
+ //Check if multi origins is set to yes
316
+ if ($r->getMultiOrigins() == 'Yes') {
317
+ foreach ($r->getOrigins() as $origin) {
318
+ $params = array(
319
+ 'user' => $r->getUserId(),
320
+ 'account' => $r->getAccountNumber(),
321
+ 'weight' => $r->getWeightKg(),
322
+ 'volume' => $r->getVolume(),
323
+ 'postalcodefrom' => $origin['postcode'],
324
+ 'postalcodeto' => $r->getDestPostal(),
325
+ 'servicetype' => $serviceCode,
326
+ );
327
+ $debugData = array('request_params' => $params);
328
+
329
+ //Attemp to load quote cache
330
+ $responseBody = $cache->_getCachedQuotes($params, $this->_code);
331
+
332
+ if ($responseBody === null) {
333
+ try {
334
+ //Get request URL
335
+ $urlDefault = $this->_defaultGatewayUrl;
336
+ $urlPath = $this->getGatewayUrlPath();
337
+ $serviceMethod = 'getQuoteByService';
338
+ $url = $urlDefault.$urlPath.$serviceMethod;
339
+
340
+ $debugData['request_url'] = $url;
341
+
342
+ $client = new Zend_Http_Client();
343
+ $client->setUri($url);
344
+ $client->setConfig(array('maxredirects'=>0, 'timeout'=>30));
345
+ $client->setParameterPost($params);
346
+ $response = $client->request('POST');
347
+ $responseBody = $response->getBody();
348
+
349
+ $debugData['result'] = $responseBody;
350
+
351
+ //Save to quote cache
352
+ $cache->_setCachedQuotes($params, $responseBody, $this->_code);
353
+ } catch (Exception $e) {
354
+ $debugData['result'] = array('error' => $e->getMessage(), 'code' => $e->getCode());
355
+ $responseBody = '';
356
+ }
357
+
358
+ $this->_debug($debugData);
359
+ }
360
+
361
+ $parsedResult[$origin['city']][] = $this->_parseXmlResponse($responseBody);
362
+ }
363
+ } else {
364
+ $params = array(
365
+ 'user' => $r->getUserId(),
366
+ 'account' => $r->getAccountNumber(),
367
+ 'weight' => $r->getWeightKg(),
368
+ 'volume' => $r->getVolume(),
369
+ 'postalcodefrom' => $r->getOrigPostal(),
370
+ 'postalcodeto' => $r->getDestPostal(),
371
+ 'servicetype' => $serviceCode,
372
+ );
373
+
374
+ $debugData = array('request_params' => $params);
375
+
376
+ //Attemp to load quote cache
377
+ $responseBody = $cache->_getCachedQuotes($params, $this->_code);
378
+
379
+ if ($responseBody === null) {
380
+ try {
381
+ //Get request URL
382
+ $urlDefault = $this->_defaultGatewayUrl;
383
+ $urlPath = $this->getGatewayUrlPath();
384
+ $serviceMethod = 'getQuoteByService';
385
+ $url = $urlDefault.$urlPath.$serviceMethod;
386
+
387
+ $debugData['request_url'] = $url;
388
+
389
+ $client = new Zend_Http_Client();
390
+ $client->setUri($url);
391
+ $client->setConfig(array('maxredirects'=>0, 'timeout'=>30));
392
+ $client->setParameterPost($params);
393
+ $response = $client->request('POST');
394
+ $responseBody = $response->getBody();
395
+
396
+ $debugData['result'] = $responseBody;
397
+
398
+ //Save to quote cache
399
+ $cache->_setCachedQuotes($params, $responseBody, $this->_code);
400
+ } catch (Exception $e) {
401
+ $debugData['result'] = array('error' => $e->getMessage(), 'code' => $e->getCode());
402
+ $responseBody = '';
403
+ }
404
+
405
+ $this->_debug($debugData);
406
+ }
407
+
408
+ $parsedResult[] = $this->_parseXmlResponse($responseBody);
409
+ }
410
+ }
411
+ } else {
412
+ $parsedResult[] = array(
413
+ 'status' => 'error',
414
+ );
415
+ }
416
+
417
+ $finalResult = $this->_setRates($parsedResult, $r);
418
+ return $finalResult;
419
+ }
420
+
421
+ /**
422
+ * Set rates
423
+ *
424
+ * @param array $parsedResult
425
+ * @param array $rawResults
426
+ * @return Mage_Shipping_Model_Rate_Result
427
+ */
428
+ protected function _setRates($parsedResult, $rawResults)
429
+ {
430
+ $result = Mage::getModel('shipping/rate_result');
431
+
432
+ foreach ($parsedResult as $key => $r) {
433
+
434
+ //Check if multi origins is set to yes
435
+ if ($rawResults->getMultiOrigins() == 'Yes') {
436
+ foreach ($rawResults->getOrigins() as $origin) {
437
+ if ($key == $origin['city']) {
438
+ foreach ($r as $s) {
439
+ if ($s['status'] == 'success') {
440
+ $rate = Mage::getModel('shipping/rate_result_method');
441
+ $rate->setCarrier($this->_code);
442
+ $rate->setCarrierTitle($this->getConfigData('title'). ' - From ' . $origin['city']);
443
+ $rate->setMethod($s['method']);
444
+ $rate->setMethodTitle($this->getCode('method', $s['method']));
445
+ $rate->setCost($s['delivery_price_incl_vat']);
446
+ $rate->setPrice($s['delivery_price_incl_vat']);
447
+ $result->append($rate);
448
+ } else if (($s['status'] == 'error') && (count($parsedResult[$key]) <= 1)){
449
+ $rate = Mage::getModel('shipping/rate_result_error');
450
+ $rate->setCarrier($this->_code);
451
+ $rate->setCarrierTitle($this->getConfigData('title'). ' - From ' . $origin['city']);
452
+ $rate->setErrorMessage($this->getConfigData('specificerrmsg'));
453
+ $result->append($rate);
454
+ }
455
+ }
456
+ }
457
+ }
458
+ } else {
459
+ if ($r['status'] == 'success') {
460
+ $rate = Mage::getModel('shipping/rate_result_method');
461
+ $rate->setCarrier($this->_code);
462
+ $rate->setCarrierTitle($this->getConfigData('title'));
463
+ $rate->setMethod($r['method']);
464
+ $rate->setMethodTitle($this->getCode('method', $r['method']));
465
+ $rate->setCost($r['delivery_price_incl_vat']);
466
+ $rate->setPrice($r['delivery_price_incl_vat']);
467
+ $result->append($rate);
468
+ } else if (($r['status'] == 'error') && (count($parsedResult) <= 1)){
469
+ $rate = Mage::getModel('shipping/rate_result_error');
470
+ $rate->setCarrier($this->_code);
471
+ $rate->setCarrierTitle($this->getConfigData('title'));
472
+ $rate->setErrorMessage($this->getConfigData('specificerrmsg'));
473
+ $result->append($rate);
474
+ }
475
+ }
476
+ }
477
+ return $result;
478
+ }
479
+
480
+ /**
481
+ * Parse XML response
482
+ *
483
+ * @param string $response
484
+ * @return array $results
485
+ */
486
+ protected function _parseXmlResponse($response)
487
+ {
488
+ if (strlen(trim($response)) > 0) {
489
+ if (strpos(trim($response), '<?xml') === 0) {
490
+ if (strpos($response, '<?xml version="1.0"?>') !== false) {
491
+ $response = str_replace(
492
+ '<?xml version="1.0"?>',
493
+ '<?xml version="1.0" encoding="ISO-8859-1"?>',
494
+ $response
495
+ );
496
+ }
497
+
498
+ $xml = simplexml_load_string($response);
499
+
500
+ //Debug XML
501
+ $this->_debug($xml);
502
+
503
+ if (is_object($xml)) {
504
+ $json = json_encode($xml);
505
+ $array = json_decode($json,TRUE);
506
+
507
+ //Debug array
508
+ $this->_debug($array);
509
+
510
+ foreach($array as $string) {
511
+ $status = $string[0];
512
+
513
+ if ($status == 'ERROR') {
514
+ $result = array(
515
+ 'status' => 'error',
516
+ 'error_title' => $string[1],
517
+ 'error_code' => $string[2]
518
+ );
519
+ } else if ($status == 'SUCCESS'){
520
+ $result = array(
521
+ 'status' => 'success',
522
+ 'berco_ref' => $string[1],
523
+ 'method' => $string[2],
524
+ 'sundry_charge' => $string[3],
525
+ 'delivery_price_excl_vat' => $string[4],
526
+ 'delivery_vat' => $string[5],
527
+ 'delivery_price_incl_vat' => $string[6]
528
+ );
529
+ } else {
530
+ $result = array(
531
+ 'status' => 'error',
532
+ 'error_title' => Mage::helper('shippingza')->__('Unknown Error')
533
+ );
534
+ }
535
+ }
536
+ }
537
+ } else {
538
+ $result = array(
539
+ 'status' => 'error',
540
+ 'error_title' => Mage::helper('shippingza')->__('Response is in the wrong format')
541
+ );
542
+ }
543
+
544
+ } else {
545
+ $result = array(
546
+ 'status' => 'error',
547
+ 'error_title' => Mage::helper('shippingza')->__('Response is in the wrong format')
548
+ );
549
+ }
550
+
551
+ return $result;
552
+ }
553
+
554
+ /**
555
+ * Get configuration data of the carrier
556
+ *
557
+ * @param string $type
558
+ * @param string $code
559
+ * @return array|bool
560
+ */
561
+ public function getCode($type, $code='')
562
+ {
563
+ $codes = array(
564
+
565
+ 'method'=>array(
566
+ 'DWX' => Mage::helper('shippingza')->__('Dawn Express'),
567
+ 'ECON' => Mage::helper('shippingza')->__('Economy Freight'),
568
+ 'EXR' => Mage::helper('shippingza')->__('Express Road Service'),
569
+ 'ONX' => Mage::helper('shippingza')->__('Overnight Express'),
570
+ 'SDX' => Mage::helper('shippingza')->__('Same Day Express')
571
+ ),
572
+ 'method_to_code'=>array(
573
+ 'Dawn Express' => 'DWX',
574
+ 'Economy Freight' => 'ECON',
575
+ 'Express Road Service' => 'EXR',
576
+ 'Overnight Express' => 'ONX',
577
+ 'Same Day Express' => 'SDX'
578
+ ),
579
+ 'service_type' => array(
580
+ 'SOAP' => Mage::helper('shippingza')->__('SOAP')
581
+ ),
582
+ );
583
+
584
+ if (!isset($codes[$type])) {
585
+ return false;
586
+ } elseif (''===$code) {
587
+ return $codes[$type];
588
+ }
589
+
590
+ if (!isset($codes[$type][$code])) {
591
+ return false;
592
+ } else {
593
+ return $codes[$type][$code];
594
+ }
595
+ }
596
+
597
+ /**
598
+ * Get allowed shipping methods
599
+ *
600
+ * @return array
601
+ */
602
+ public function getAllowedMethods()
603
+ {
604
+ $allowed = explode(',', $this->getConfigData('allowed_methods'));
605
+ $arr = array();
606
+ foreach ($allowed as $k) {
607
+ $arr[$k] = $k;
608
+ }
609
+ return $arr;
610
+ }
611
+
612
+ }
app/code/local/Fontera/ShippingZA/Model/Shipping/Carrier/Berco/Source/Country.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Shipping South Africa Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ *
13
+ * @category Fontera
14
+ * @package Fontera_ShippingZA
15
+ * @copyright Copyright (c) 2012 Fontera (http://www.fontera.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ * @author Shaughn Le Grange - Hatlen <shaughn.legrange-hatlen@fontera.com>
18
+ */
19
+
20
+ class Fontera_ShippingZA_Model_Shipping_Carrier_Berco_Source_Country
21
+ {
22
+ public function toOptionArray()
23
+ {
24
+ return array(
25
+ array(
26
+ 'value' => 'ZA',
27
+ 'label' => Mage::helper('shippingza')->__('South Africa')
28
+ ),
29
+ );
30
+ }
31
+ }
app/code/local/Fontera/ShippingZA/Model/Shipping/Carrier/Berco/Source/Method.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Shipping South Africa Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ *
13
+ * @category Fontera
14
+ * @package Fontera_ShippingZA
15
+ * @copyright Copyright (c) 2012 Fontera (http://www.fontera.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ * @author Shaughn Le Grange - Hatlen <shaughn.legrange-hatlen@fontera.com>
18
+ */
19
+
20
+ class Fontera_ShippingZA_Model_Shipping_Carrier_Berco_Source_Method
21
+ {
22
+ public function toOptionArray()
23
+ {
24
+ $usps = Mage::getSingleton('shippingza/shipping_carrier_berco');
25
+ $arr = array();
26
+ foreach ($usps->getCode('method') as $v) {
27
+ $arr[] = array('value'=>$v, 'label'=>$v);
28
+ }
29
+ return $arr;
30
+ }
31
+ }
app/code/local/Fontera/ShippingZA/Model/Shipping/Carrier/Berco/Source/Servicetype.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Shipping South Africa Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ *
13
+ * @category Fontera
14
+ * @package Fontera_ShippingZA
15
+ * @copyright Copyright (c) 2012 Fontera (http://www.fontera.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ * @author Shaughn Le Grange - Hatlen <shaughn.legrange-hatlen@fontera.com>
18
+ */
19
+
20
+ class Fontera_ShippingZA_Model_Shipping_Carrier_Berco_Source_Servicetype
21
+ {
22
+ public function toOptionArray()
23
+ {
24
+ $berco = Mage::getSingleton('shippingza/shipping_carrier_berco');
25
+ $arr = array();
26
+ foreach ($berco->getCode('service_type') as $k=>$v) {
27
+ $arr[] = array('value'=>$k, 'label'=>$v);
28
+ }
29
+ return $arr;
30
+ }
31
+ }
app/code/local/Fontera/ShippingZA/Model/Shipping/Carrier/Berco/Source/Specificcountries.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Shipping South Africa Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ *
13
+ * @category Fontera
14
+ * @package Fontera_ShippingZA
15
+ * @copyright Copyright (c) 2012 Fontera (http://www.fontera.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ * @author Shaughn Le Grange - Hatlen <shaughn.legrange-hatlen@fontera.com>
18
+ */
19
+
20
+ class Fontera_ShippingZA_Model_Shipping_Carrier_Berco_Source_Specificcountries
21
+ {
22
+ public function toOptionArray()
23
+ {
24
+ return array(
25
+ array(
26
+ 'value' => 1,
27
+ 'label' => Mage::helper('shippingza')->__('Specific Countries')
28
+ ),
29
+ );
30
+ }
31
+ }
app/code/local/Fontera/ShippingZA/Model/Shipping/Carrier/Cache.php ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Shipping South Africa Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ *
13
+ * @category Fontera
14
+ * @package Fontera_ShippingZA
15
+ * @copyright Copyright (c) 2012 Fontera (http://www.fontera.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ * @author Shaughn Le Grange - Hatlen <shaughn.legrange-hatlen@fontera.com>
18
+ */
19
+
20
+ class Fontera_ShippingZA_Model_Shipping_Carrier_Cache
21
+ {
22
+
23
+ public static $_quotesCache = array();
24
+
25
+ /**
26
+ * Returns cache key for some request to carrier quotes service
27
+ *
28
+ * @param string|array $requestParams
29
+ * @return string
30
+ */
31
+ public function getSession()
32
+ {
33
+ return Mage::getSingleton('customer/session');
34
+ }
35
+
36
+ /**
37
+ * Returns cache key for some request to carrier quotes service
38
+ *
39
+ * @param string|array $requestParams
40
+ * @return string
41
+ */
42
+ public function _getQuotesCacheKey($requestParams)
43
+ {
44
+ if (is_array($requestParams)) {
45
+ $requestParams = implode(',', array_merge(
46
+ array_keys($requestParams),
47
+ $requestParams)
48
+ );
49
+ }
50
+ return crc32($requestParams);
51
+ }
52
+
53
+ /**
54
+ * Checks whether some request to rates have already been done, so we have cache for it
55
+ * Used to reduce number of same requests done to carrier service during one session
56
+ *
57
+ * Returns cached response or null
58
+ *
59
+ * @param string|array $requestParams
60
+ * @return null|string
61
+ */
62
+ public function _getCachedQuotes($requestParams, $carrier)
63
+ {
64
+ $key = $this->_getQuotesCacheKey($requestParams);
65
+ $session = $this->getSession();
66
+
67
+ $shippingRates = $session->getShippingRates();
68
+
69
+ if (!$shippingRates[$carrier]) {
70
+ return null;
71
+ } else {
72
+ if (array_key_exists($key, $shippingRates[$carrier])) {
73
+ return $shippingRates[$carrier][$key];
74
+ } else {
75
+ return null;
76
+ }
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Sets received carrier quotes to cache
82
+ *
83
+ * @param string|array $requestParams
84
+ * @param string $response
85
+ * @return Fontera_ShippingZA_Model_Shipping_Carrier_Abstract
86
+ */
87
+ public function _setCachedQuotes($requestParams, $response, $carrier)
88
+ {
89
+ $key = $this->_getQuotesCacheKey($requestParams);
90
+ $session = $this->getSession();
91
+
92
+ self::$_quotesCache[$key] = $response;
93
+
94
+ $params = array($carrier => self::$_quotesCache);
95
+
96
+ $shippingRates = $session->getShippingRates();
97
+
98
+ if (!$shippingRates[$carrier]) {
99
+ $session->setShippingRates($params);
100
+ } else {
101
+ $shippingRates[$carrier][$key] = $response;
102
+ $session->setShippingRates($shippingRates);
103
+ }
104
+
105
+ return self::$_quotesCache;
106
+ }
107
+
108
+ }
app/code/local/Fontera/ShippingZA/etc/config.xml ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Shipping South Africa Extension
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ *
13
+ *
14
+ * @category Fontera
15
+ * @package Fontera_ShippingZA
16
+ * @copyright Copyright (c) 2012 Fontera (http://www.fontera.com)
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ * @author Shaughn Le Grange - Hatlen <shaughn.legrange-hatlen@fontera.com>
19
+ */
20
+ -->
21
+ <config>
22
+ <modules>
23
+ <Fontera_ShippingZA>
24
+ <version>1.0.0</version>
25
+ </Fontera_ShippingZA>
26
+ </modules>
27
+ <global>
28
+ <helpers>
29
+ <shippingza>
30
+ <class>Fontera_ShippingZA_Helper</class>
31
+ </shippingza>
32
+ </helpers>
33
+ <resources>
34
+ <shippingza_setup>
35
+ <setup>
36
+ <module>Fontera_ShippingZA</module>
37
+ </setup>
38
+ </shippingza_setup>
39
+ </resources>
40
+ <models>
41
+ <shippingza>
42
+ <class>Fontera_ShippingZA_Model</class>
43
+ </shippingza>
44
+ </models>
45
+ <sales>
46
+ <shipping>
47
+ <carriers>
48
+ <berco>
49
+ <class>Fontera_ShippingZA_Model_Shipping_Carrier_Berco</class>
50
+ </berco>
51
+ </carriers>
52
+ </shipping>
53
+ </sales>
54
+ </global>
55
+ <adminhtml>
56
+ <translate>
57
+ <modules>
58
+ <Fontera_ShippingZA>
59
+ <files>
60
+ <default>Fontera_ShippingZA.csv</default>
61
+ </files>
62
+ </Fontera_ShippingZA>
63
+ </modules>
64
+ </translate>
65
+ </adminhtml>
66
+ <frontend>
67
+ <translate>
68
+ <modules>
69
+ <Fontera_ShippingZA>
70
+ <files>
71
+ <default>Fontera_ShippingZA.csv</default>
72
+ </files>
73
+ </Fontera_ShippingZA>
74
+ </modules>
75
+ </translate>
76
+ </frontend>
77
+ <default>
78
+ <carriers>
79
+ <berco>
80
+ <active>0</active>
81
+ <service_type>SOAP</service_type>
82
+ <title>Berco Express</title>
83
+ <account backend_model="adminhtml/system_config_backend_encrypted"/>
84
+ <userid backend_model="adminhtml/system_config_backend_encrypted"/>
85
+ <multiple_origins>0</multiple_origins>
86
+ <allowed_methods>DWX,ECON,EXR,ONX,SDX</allowed_methods>
87
+ <sallowspecific>0</sallowspecific>
88
+ <specificcountry>ZA</specificcountry>
89
+ <specificerrmsg>This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us.</specificerrmsg>
90
+ <model>shippingza/shipping_carrier_berco</model>
91
+ </berco>
92
+ </carriers>
93
+ </default>
94
+ </config>
app/code/local/Fontera/ShippingZA/etc/system.xml ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Shipping South Africa Extension
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ *
13
+ *
14
+ * @category Fontera
15
+ * @package Fontera_ShippingZA
16
+ * @copyright Copyright (c) 2012 Fontera (http://www.fontera.com)
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ * @author Shaughn Le Grange - Hatlen <shaughn.legrange-hatlen@fontera.com>
19
+ */
20
+ -->
21
+ <config>
22
+ <sections>
23
+ <carriers>
24
+ <groups>
25
+ <berco translate="label" module="shippingza">
26
+ <label>Berco Express (South Africa Only)</label>
27
+ <frontend_type>text</frontend_type>
28
+ <sort_order>190</sort_order>
29
+ <show_in_default>1</show_in_default>
30
+ <show_in_website>1</show_in_website>
31
+ <show_in_store>1</show_in_store>
32
+ <comment><![CDATA[
33
+ <div style="border-radius:6px;color:#ffffff;background-color:#2f2f2f;padding:10px;margin-bottom:10px;width:auto;">
34
+ <p style="font-size:16px;font-weight:bold;">Berco Express:</p>
35
+ <a href="http://www.bercoexpress.co.za/"> www.bercoexpress.co.za</a><br /><br />
36
+ <p style="font-size:16px;font-weight:bold;">Setup Requirements:</p>
37
+ <ul style="list-style:circle; margin-left:20px;">
38
+ <li>An additional "Volume" attribute needs to be added as the calculated shipping rates from Berco are based on volume and weight.</li>
39
+ <li>The volume attribute needs to be added to an appropriate attribute set.</li>
40
+ <li>If a product does not have a weight and volume set, and the total weight and volume in the cart is equal to 0, then no shipping rates will be returned.</li>
41
+ </ul><br />
42
+ <p style="font-size:16px;font-weight:bold;">Features:</p>
43
+ <ul style="list-style:circle; margin-left:20px;">
44
+ <li>Supports multiple store origin's / websites. If stock is held in more than 1 location, separate shipping rates will be displayed to the customer per origin.</li>
45
+ <li>Each shipping rate request is cached (per customer) for the duration of the customer's session.</li>
46
+ <li>Support for multiple languages.</li>
47
+ </ul><br />
48
+ <p style="font-size:16px;font-weight:bold;">References:</p>
49
+ SOAP Service: <a href="http://interfaces.bercoexpress.co.za/"> http://interfaces.bercoexpress.co.za</a><br />
50
+ REST Service: <a href="http://service.bercoexpress.co.za/"> http://service.bercoexpress.co.za</a><br />
51
+ Created By: <a href="http://www.fontera.com/"> Fontera</a>
52
+ </div>
53
+ ]]></comment>
54
+ <fields>
55
+ <active translate="label">
56
+ <label>Enabled for Checkout</label>
57
+ <frontend_type>select</frontend_type>
58
+ <source_model>adminhtml/system_config_source_yesno</source_model>
59
+ <sort_order>10</sort_order>
60
+ <show_in_default>1</show_in_default>
61
+ <show_in_website>1</show_in_website>
62
+ <show_in_store>0</show_in_store>
63
+ </active>
64
+ <service_type translate="label">
65
+ <label>Service Type</label>
66
+ <frontend_type>select</frontend_type>
67
+ <source_model>shippingza/shipping_carrier_berco_source_servicetype</source_model>
68
+ <sort_order>11</sort_order>
69
+ <show_in_default>1</show_in_default>
70
+ <show_in_website>1</show_in_website>
71
+ <show_in_store>0</show_in_store>
72
+ </service_type>
73
+ <title translate="label">
74
+ <label>Title</label>
75
+ <frontend_type>text</frontend_type>
76
+ <sort_order>12</sort_order>
77
+ <show_in_default>1</show_in_default>
78
+ <show_in_website>1</show_in_website>
79
+ <show_in_store>1</show_in_store>
80
+ </title>
81
+ <account translate="label">
82
+ <label>Account Number</label>
83
+ <frontend_type>text</frontend_type>
84
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
85
+ <sort_order>13</sort_order>
86
+ <show_in_default>1</show_in_default>
87
+ <show_in_website>1</show_in_website>
88
+ <show_in_store>0</show_in_store>
89
+ <comment><![CDATA[<div style="color:#EB5E00;">Test Account: A12345</div>]]></comment>
90
+ </account>
91
+ <userid translate="label">
92
+ <label>User ID</label>
93
+ <frontend_type>obscure</frontend_type>
94
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
95
+ <sort_order>14</sort_order>
96
+ <show_in_default>1</show_in_default>
97
+ <show_in_website>1</show_in_website>
98
+ <show_in_store>0</show_in_store>
99
+ <comment><![CDATA[<div style="color:#EB5E00;">Test User ID: BTEST</div>]]></comment>
100
+ </userid>
101
+ <multiple_origins translate="label">
102
+ <label>Multiple Origins</label>
103
+ <frontend_type>select</frontend_type>
104
+ <source_model>adminhtml/system_config_source_yesno</source_model>
105
+ <sort_order>15</sort_order>
106
+ <show_in_default>1</show_in_default>
107
+ <show_in_website>1</show_in_website>
108
+ <show_in_store>0</show_in_store>
109
+ <comment><![CDATA[<div style="color:#EB5E00;">Set to Yes when you have multiple origins set per website.</div>]]></comment>
110
+ </multiple_origins>
111
+ <allowed_methods translate="label">
112
+ <label>Allowed Methods</label>
113
+ <frontend_type>multiselect</frontend_type>
114
+ <source_model>shippingza/shipping_carrier_berco_source_method</source_model>
115
+ <sort_order>16</sort_order>
116
+ <show_in_default>1</show_in_default>
117
+ <show_in_website>1</show_in_website>
118
+ <show_in_store>0</show_in_store>
119
+ <can_be_empty>1</can_be_empty>
120
+ </allowed_methods>
121
+ <sallowspecific translate="label">
122
+ <label>Ship to Applicable Countries</label>
123
+ <frontend_type>select</frontend_type>
124
+ <sort_order>17</sort_order>
125
+ <frontend_class>shipping-applicable-country</frontend_class>
126
+ <source_model>shippingza/shipping_carrier_berco_source_specificcountries</source_model>
127
+ <show_in_default>1</show_in_default>
128
+ <show_in_website>1</show_in_website>
129
+ <show_in_store>0</show_in_store>
130
+ </sallowspecific>
131
+ <specificcountry translate="label">
132
+ <label>Ship to Specific Countries</label>
133
+ <frontend_type>multiselect</frontend_type>
134
+ <sort_order>18</sort_order>
135
+ <source_model>shippingza/shipping_carrier_berco_source_country</source_model>
136
+ <show_in_default>1</show_in_default>
137
+ <show_in_website>1</show_in_website>
138
+ <show_in_store>0</show_in_store>
139
+ <can_be_empty>0</can_be_empty>
140
+ <comment><![CDATA[<div style="color:#EB5E00;">The Berco Express SOAP API only supports local South African shipping for now.</div>]]></comment>
141
+ </specificcountry>
142
+ <showmethod translate="label">
143
+ <label>Show Method if Not Applicable</label>
144
+ <frontend_type>select</frontend_type>
145
+ <sort_order>19</sort_order>
146
+ <frontend_class>shipping-skip-hide</frontend_class>
147
+ <source_model>adminhtml/system_config_source_yesno</source_model>
148
+ <show_in_default>1</show_in_default>
149
+ <show_in_website>1</show_in_website>
150
+ <show_in_store>0</show_in_store>
151
+ </showmethod>
152
+ <specificerrmsg translate="label">
153
+ <label>Displayed Error Message</label>
154
+ <frontend_type>textarea</frontend_type>
155
+ <sort_order>20</sort_order>
156
+ <show_in_default>1</show_in_default>
157
+ <show_in_website>1</show_in_website>
158
+ <show_in_store>1</show_in_store>
159
+ </specificerrmsg>
160
+ <sort_order translate="label">
161
+ <label>Sort Order</label>
162
+ <frontend_type>text</frontend_type>
163
+ <sort_order>21</sort_order>
164
+ <show_in_default>1</show_in_default>
165
+ <show_in_website>1</show_in_website>
166
+ <show_in_store>0</show_in_store>
167
+ </sort_order>
168
+ <debug translate="label">
169
+ <label>Debug</label>
170
+ <frontend_type>select</frontend_type>
171
+ <source_model>adminhtml/system_config_source_yesno</source_model>
172
+ <sort_order>22</sort_order>
173
+ <show_in_default>1</show_in_default>
174
+ <show_in_website>1</show_in_website>
175
+ <show_in_store>0</show_in_store>
176
+ </debug>
177
+ </fields>
178
+ </berco>
179
+ </groups>
180
+ </carriers>
181
+ </sections>
182
+ </config>
app/etc/modules/Fontera_ShippingZA.xml ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ /**
4
+ * Shipping South Africa Extension
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ *
13
+ *
14
+ * @category Fontera
15
+ * @package Fontera_ShippingZA
16
+ * @copyright Copyright (c) 2012 Fontera (http://www.fontera.com)
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ * @author Shaughn Le Grange - Hatlen <shaughn.legrange-hatlen@fontera.com>
19
+ */
20
+ -->
21
+ <config>
22
+ <modules>
23
+ <Fontera_ShippingZA>
24
+ <active>true</active>
25
+ <codePool>local</codePool>
26
+ <depends>
27
+ <Mage_Sales/>
28
+ <Mage_Shipping/>
29
+ </depends>
30
+ </Fontera_ShippingZA>
31
+ </modules>
32
+ </config>
app/locale/en_US/Fontera_ShippingZA.csv ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ "Dawn Express","Dawn Express"
2
+ "Economy Freight","Economy Freight"
3
+ "Express Road Service","Express Road Service"
4
+ "Overnight Express","Overnight Express"
5
+ "Same Day Express","Same Day Express"
6
+ "SOAP","SOAP"
7
+ "Unknown Error","Unknown Error"
8
+ "Response is in the wrong format","Response is in the wrong format"
9
+ "This shipping method is not available, please specify a postal code","This shipping method is not available, please specify a postal code"
10
+ "South Africa","South Africa"
11
+ "Specific Countries","Specific Countries"
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Fontera_ShippingZA</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</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Requests and displays shipping costs for South African couriers. Berco Express</summary>
10
+ <description>Fontera Digital Works Magento shipping extension for South Africa requests a shipping quote from a local courier, for any postal code in South Africa.</description>
11
+ <notes>Fontera Digital Works Magento shipping extension for South Africa requests a shipping quote from a local courier, for any postal code in South Africa.</notes>
12
+ <authors><author><name>Shaughn Le Grange - Hatlen</name><user>shaughn</user><email>shaughn@synergyx.za.net</email></author></authors>
13
+ <date>2012-03-16</date>
14
+ <time>10:43:40</time>
15
+ <contents><target name="magelocale"><dir name="en_US"><file name="Fontera_ShippingZA.csv" hash="0e864d3150f8258c1e3be5a4d51ae049"/></dir></target><target name="mageetc"><dir name="modules"><file name="Fontera_ShippingZA.xml" hash="6a57e49486a4cb372617a5c2771dc0f6"/></dir></target><target name="magelocal"><dir name="Fontera"><dir name="ShippingZA"><dir name="Helper"><file name="Data.php" hash="de70bf8af0614fba09dbfc8349a41b12"/></dir><dir name="Model"><dir name="Shipping"><dir name="Carrier"><file name="Abstract.php" hash="84cf1adaa66b04720501c0af706bbce8"/><dir name="Berco"><dir name="Source"><file name="Country.php" hash="2210e6a04da116e1f0a2031c475bbe41"/><file name="Method.php" hash="be4c2df2ad1092fdfb73db6cb994b990"/><file name="Servicetype.php" hash="d74bb0f19ebad2a05fadfa3dc0a1cf49"/><file name="Specificcountries.php" hash="97fabd83fd6cdc2084479284b81ced35"/></dir></dir><file name="Berco.php" hash="8ee687391f4d037dda1c0d1700ed9246"/><file name="Cache.php" hash="aca29d16043d05850cf1f2cbd4765b1e"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="4cab0c52677f9131ecfcc225cdfc994a"/><file name="system.xml" hash="dfb58934ef6824f2af3e9d5bfd7653e0"/></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>