1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14:
15: class IllApps_Shipsync_Model_Shipping_Carrier_Fedex extends Mage_Usa_Model_Shipping_Carrier_Abstract implements Mage_Shipping_Model_Carrier_Interface
16: {
17:
18: protected $_code = 'fedex';
19: protected $_request;
20: protected $_rateResult;
21:
22:
23: 24: 25: 26: 27: 28:
29: public function collectRates(Mage_Shipping_Model_Rate_Request $request)
30: {
31:
32: if (!$this->getConfigFlag('active')) {
33: return false;
34: }
35:
36: if (Mage::getStoreConfig('carriers/fedex/disable_rating')) {
37: return false;
38: }
39:
40:
41: return Mage::getModel('usa/shipping_carrier_fedex_rate')->collectRates($request);
42: }
43:
44:
45:
46: 47: 48: 49: 50: 51:
52: public function createShipment($request)
53: {
54:
55: if (!$this->getConfigFlag('active')) {
56: return false;
57: }
58:
59:
60: return Mage::getModel('usa/shipping_carrier_fedex_ship')->createShipment($request);
61: }
62:
63:
64:
65: 66: 67: 68: 69: 70:
71: public function getTracking($trackings)
72: {
73: return Mage::getModel('usa/shipping_carrier_fedex_track')->getTracking($trackings);
74: }
75:
76:
77:
78: 79: 80:
81: public function getResidential($street, $postcode)
82: {
83: return Mage::getModel('usa/shipping_carrier_fedex_address')->getResidential($street, $postcode);
84: }
85:
86:
87: 88: 89: 90: 91:
92: public function getPackages()
93: {
94: return Mage::getModel('usa/shipping_carrier_fedex_package')->getPackages();
95: }
96:
97:
98: 99: 100: 101: 102: 103:
104: protected function _initWebServices($wsdlPath)
105: {
106: ini_set('soap.wsdl_cache_enabled', Mage::getStoreConfig('carriers/fedex/enable_soap_cache'));
107:
108: $this->setFedexAccountCountry(Mage::getStoreConfig('carriers/fedex/account_country'));
109:
110: if (Mage::getStoreConfig('carriers/fedex/test_mode')) {
111: $this->setFedexKey(Mage::getStoreConfig('carriers/fedex/test_key'));
112: $this->setFedexPassword(Mage::getStoreConfig('carriers/fedex/test_password'));
113: $this->setFedexAccount(Mage::getStoreConfig('carriers/fedex/test_account'));
114: $this->setFedexMeter(Mage::getStoreConfig('carriers/fedex/test_meter'));
115: $this->setWsdlPath(dirname(__FILE__) . '/Fedex/wsdl/test/' . $wsdlPath);
116: } else {
117: $this->setFedexKey(Mage::getStoreConfig('carriers/fedex/key'));
118: $this->setFedexPassword(Mage::getStoreConfig('carriers/fedex/password'));
119: $this->setFedexAccount(Mage::getStoreConfig('carriers/fedex/account'));
120: $this->setFedexMeter(Mage::getStoreConfig('carriers/fedex/meter_number'));
121: $this->setWsdlPath(dirname(__FILE__) . '/Fedex/wsdl/' . $wsdlPath);
122: }
123:
124: try {
125: $soapClient = new SoapClient($this->getWsdlPath(), array(
126: 'trace' => 1
127: ));
128: }
129: catch (Exception $ex) {
130: Mage::throwException($ex->getMessage());
131: }
132:
133: return $soapClient;
134: }
135:
136:
137:
138: 139: 140: 141: 142:
143: public function getDimensionUnits()
144: {
145: switch (Mage::getStoreConfig('carriers/fedex/unit_of_measure'))
146: {
147: case 'LB' : return 'IN';
148: case 'KG' : return 'CM';
149: case 'G' : return 'CM';
150: }
151: }
152:
153: 154: 155: 156: 157:
158: public function getWeightUnits()
159: {
160: return Mage::getStoreConfig('carriers/fedex/unit_of_measure');
161: }
162:
163:
164:
165: 166: 167: 168: 169:
170: public function getCurrencyCode()
171: {
172: $codes = array(
173: 'DOP' => 'RDD',
174: 'XCD' => 'ECD',
175: 'ARS' => 'ARN',
176: 'SGD' => 'SID',
177: 'KRW' => 'WON',
178: 'JMD' => 'JAD',
179: 'CHF' => 'SFR',
180: 'JPY' => 'JYE',
181: 'KWD' => 'KUD',
182: 'GBP' => 'UKL',
183: 'AED' => 'DHS',
184: 'MXN' => 'NMP',
185: 'UYU' => 'UYP',
186: 'CLP' => 'CHP',
187: 'TWD' => 'NTD'
188: );
189:
190: $currencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
191:
192: return isset($codes[$currencyCode]) ? $codes[$currencyCode] : $currencyCode;
193: }
194:
195:
196:
197: 198: 199: 200: 201: 202:
203: public function getUnderscoreCodeFromCode($code)
204: {
205:
206: $codes = array(
207: 'PRIORITYOVERNIGHT' => 'PRIORITY_OVERNIGHT',
208: 'STANDARDOVERNIGHT' => 'STANDARD_OVERNIGHT',
209: 'FIRSTOVERNIGHT' => 'FIRST_OVERNIGHT',
210: 'FEDEX2DAY' => 'FEDEX_2_DAY',
211: 'FEDEXEXPRESSSAVER' => 'FEDEX_EXPRESS_SAVER',
212: 'INTERNATIONALPRIORITY' => 'INTERNATIONAL_PRIORITY',
213: 'INTERNATIONALECONOMY' => 'INTERNATIONAL_ECONOMY',
214: 'INTERNATIONALFIRST' => 'INTERNATIONAL_FIRST',
215: 'FEDEX1DAYFREIGHT' => 'FEDEX_1_DAY_FREIGHT',
216: 'FEDEX2DAYFREIGHT' => 'FEDEX_2_DAY_FREIGHT',
217: 'FEDEX3DAYFREIGHT' => 'FEDEX_3_DAY_FREIGHT',
218: 'FEDEXGROUND' => 'FEDEX_GROUND',
219: 'GROUNDHOMEDELIVERY' => 'GROUND_HOME_DELIVERY',
220: 'INTERNATIONALPRIORITY FREIGHT' => 'INTERNATIONAL_PRIORITY_FREIGHT',
221: 'INTERNATIONALECONOMY FREIGHT' => 'INTERNATIONAL_ECONOMY_FREIGHT',
222: 'EUROPEFIRSTINTERNATIONALPRIORITY' => 'EUROPE_FIRST_INTERNATIONAL_PRIORITY',
223: 'REGULARPICKUP' => 'REGULAR_PICKUP',
224: 'REQUESTCOURIER' => 'REQUEST_COURIER',
225: 'DROPBOX' => 'DROP_BOX',
226: 'BUSINESSSERVICECENTER' => 'BUSINESS_SERVICE_CENTER',
227: 'STATION' => 'STATION',
228: 'FEDEXENVELOPE' => 'FEDEX_ENVELOPE',
229: 'FEDEXPAK' => 'FEDEX_PAK',
230: 'FEDEXTUBE' => 'FEDEX_TUBE',
231: 'FEDEX10KGBOX' => 'FEDEX_10KG_BOX',
232: 'FEDEX25KGBOX' => 'FEDEX_25KG_BOX',
233: 'YOURPACKAGING' => 'YOUR_PACKAGING',
234: 'SMARTPOST' => 'SMART_POST'
235: );
236:
237: return isset($codes[$code]) ? $codes[$code] : $code;
238: }
239:
240:
241:
242: 243: 244: 245: 246: 247: 248: 249:
250: public function getCode($type, $code = '', $underscore = false)
251: {
252: $codes_underscore = array(
253: 'method' => array(
254: 'PRIORITY_OVERNIGHT' => Mage::helper('usa')->__('Priority Overnight'),
255: 'STANDARD_OVERNIGHT' => Mage::helper('usa')->__('Standard Overnight'),
256: 'FIRST_OVERNIGHT' => Mage::helper('usa')->__('First Overnight'),
257: 'FEDEX_2DAY' => Mage::helper('usa')->__('2Day'),
258: 'FEDEX_2_DAY' => Mage::helper('usa')->__('2Day'),
259: 'FEDEX_EXPRESS_SAVER' => Mage::helper('usa')->__('Express Saver'),
260: 'INTERNATIONAL_PRIORITY' => Mage::helper('usa')->__('International Priority'),
261: 'INTERNATIONAL_ECONOMY' => Mage::helper('usa')->__('International Economy'),
262: 'INTERNATIONAL_FIRST' => Mage::helper('usa')->__('International First'),
263: 'FEDEX_1_DAY_FREIGHT' => Mage::helper('usa')->__('1 Day Freight'),
264: 'FEDEX_2_DAY_FREIGHT' => Mage::helper('usa')->__('2 Day Freight'),
265: 'FEDEX_3_DAY_FREIGHT' => Mage::helper('usa')->__('3 Day Freight'),
266: 'FEDEX_GROUND' => Mage::helper('usa')->__('Ground'),
267: 'GROUND_HOME_DELIVERY' => Mage::helper('usa')->__('Home Delivery'),
268: 'INTERNATIONAL_PRIORITY_FREIGHT' => Mage::helper('usa')->__('Intl Priority Freight'),
269: 'INTERNATIONAL_ECONOMY_FREIGHT' => Mage::helper('usa')->__('Intl Economy Freight'),
270: 'EUROPE_FIRST_INTERNATIONAL_PRIORITY' => Mage::helper('usa')->__('Europe First Priority'),
271: 'SMART_POST' => Mage::helper('usa')->__('SmartPost')
272: ),
273: 'dropoff' => array(
274: 'REGULAR_PICKUP' => Mage::helper('usa')->__('Regular Pickup'),
275: 'REQUEST_COURIER' => Mage::helper('usa')->__('Request Courier'),
276: 'DROP_BOX' => Mage::helper('usa')->__('Drop Box'),
277: 'BUSINESS_SERVICE_CENTER' => Mage::helper('usa')->__('Business Service Center'),
278: 'STATION' => Mage::helper('usa')->__('Station')
279: ),
280: 'packaging' => array(
281: 'FEDEX_ENVELOPE' => Mage::helper('usa')->__('FedEx Envelope'),
282: 'FEDEX_PAK' => Mage::helper('usa')->__('FedEx Pak'),
283: 'FEDEX_TUBE' => Mage::helper('usa')->__('FedEx Tube'),
284: 'FEDEX_10KG_BOX' => Mage::helper('usa')->__('FedEx 10kg Box'),
285: 'FEDEX_25KG_BOX' => Mage::helper('usa')->__('FedEx 25kg Box'),
286: 'YOUR_PACKAGING' => Mage::helper('usa')->__('Your Packaging')
287: )
288: );
289:
290: $codes = array(
291: 'method' => array(
292: 'PRIORITYOVERNIGHT' => Mage::helper('usa')->__('Priority Overnight'),
293: 'STANDARDOVERNIGHT' => Mage::helper('usa')->__('Standard Overnight'),
294: 'FIRSTOVERNIGHT' => Mage::helper('usa')->__('First Overnight'),
295: 'FEDEX2DAY' => Mage::helper('usa')->__('2Day'),
296: 'FEDEXEXPRESSSAVER' => Mage::helper('usa')->__('Express Saver'),
297: 'INTERNATIONALPRIORITY' => Mage::helper('usa')->__('International Priority'),
298: 'INTERNATIONALECONOMY' => Mage::helper('usa')->__('International Economy'),
299: 'INTERNATIONALFIRST' => Mage::helper('usa')->__('International First'),
300: 'FEDEX1DAYFREIGHT' => Mage::helper('usa')->__('1 Day Freight'),
301: 'FEDEX2DAYFREIGHT' => Mage::helper('usa')->__('2 Day Freight'),
302: 'FEDEX3DAYFREIGHT' => Mage::helper('usa')->__('3 Day Freight'),
303: 'FEDEXGROUND' => Mage::helper('usa')->__('Ground'),
304: 'GROUNDHOMEDELIVERY' => Mage::helper('usa')->__('Home Delivery'),
305: 'INTERNATIONALPRIORITY FREIGHT' => Mage::helper('usa')->__('Intl Priority Freight'),
306: 'INTERNATIONALECONOMY FREIGHT' => Mage::helper('usa')->__('Intl Economy Freight'),
307: 'EUROPEFIRSTINTERNATIONALPRIORITY' => Mage::helper('usa')->__('Europe First Priority'),
308: 'SMARTPOST' => Mage::helper('usa')->__('SmartPost')
309: ),
310: 'dropoff' => array(
311: 'REGULARPICKUP' => Mage::helper('usa')->__('Regular Pickup'),
312: 'REQUESTCOURIER' => Mage::helper('usa')->__('Request Courier'),
313: 'DROPBOX' => Mage::helper('usa')->__('Drop Box'),
314: 'BUSINESSSERVICECENTER' => Mage::helper('usa')->__('Business Service Center'),
315: 'STATION' => Mage::helper('usa')->__('Station')
316: ),
317:
318: 'packaging' => array(
319: 'FEDEXENVELOPE' => Mage::helper('usa')->__('FedEx Envelope'),
320: 'FEDEXPAK' => Mage::helper('usa')->__('FedEx Pak'),
321: 'FEDEXTUBE' => Mage::helper('usa')->__('FedEx Tube'),
322: 'FEDEX10KGBOX' => Mage::helper('usa')->__('FedEx 10kg Box'),
323: 'FEDEX25KGBOX' => Mage::helper('usa')->__('FedEx 25kg Box'),
324: 'YOURPACKAGING' => Mage::helper('usa')->__('Your Packaging')
325: ),
326: 'rate_type' => array(
327: 'LIST' => Mage::helper('usa')->__('List Rates'),
328: 'ACCOUNT' => Mage::helper('usa')->__('Account Rates'),
329: 'PREFERRED' => Mage::helper('usa')->__('Preferred Rates')
330: ),
331: 'label_image' => array(
332: 'PDF' => Mage::helper('usa')->__('Adobe PDF'),
333: 'PNG' => Mage::helper('usa')->__('PNG Image'),
334: 'EPL2' => Mage::helper('usa')->__('Zebra EPL2'),
335: 'ZPLII' => Mage::helper('usa')->__('Zebra ZPLII'),
336: 'DPL' => Mage::helper('usa')->__('Datamax DPL')
337: ),
338: 'label_stock' => array(
339: 'PAPER_7X4.75' => Mage::helper('usa')->__('PAPER_7X4.75'),
340: 'PAPER_4X6' => Mage::helper('usa')->__('PAPER_4X6'),
341: 'PAPER_4X8' => Mage::helper('usa')->__('PAPER_4X8'),
342: 'PAPER_4X9' => Mage::helper('usa')->__('PAPER_4X9'),
343: 'PAPER_8.5X11_BOTTOM_HALF_LABEL' => Mage::helper('usa')->__('PAPER_8.5X11_BOTTOM_HALF_LABEL'),
344: 'PAPER_8.5X11_TOP_HALF_LABEL' => Mage::helper('usa')->__('PAPER_8.5X11_TOP_HALF_LABEL'),
345: 'STOCK_4X6' => Mage::helper('usa')->__('STOCK_4X6'),
346: 'STOCK_4X6.75_LEADING_DOC_TAB' => Mage::helper('usa')->__('STOCK_4X6.75_LEADING_DOC_TAB'),
347: 'STOCK_4X6.75_TRAILING_DOC_TAB' => Mage::helper('usa')->__('STOCK_4X6.75_TRAILING_DOC_TAB'),
348: 'STOCK_4X8' => Mage::helper('usa')->__('STOCK_4X8'),
349: 'STOCK_4X9_LEADING_DOC_TAB' => Mage::helper('usa')->__('STOCK_4X9_LEADING_DOC_TAB'),
350: 'STOCK_4X9_TRAILING_DOC_TAB' => Mage::helper('usa')->__('STOCK_4X9_TRAILING_DOC_TAB')
351: ),
352: 'label_orientation' => array(
353: 'BOTTOM_EDGE_OF_TEXT_FIRST' => Mage::helper('usa')->__('Bottom edge of text first'),
354: 'TOP_EDGE_OF_TEXT_FIRST' => Mage::helper('usa')->__('Top edge of text first')
355: ),
356: 'smartpost_indicia' => array(
357: 'MEDIA_MAIL' => Mage::helper('usa')->__('Media Mail'),
358: 'PARCEL_SELECT' => Mage::helper('usa')->__('Parcel Select'),
359: 'PRESORTED_BOUND_PRINTED_MATTER' => Mage::helper('usa')->__('Presorted Bound Printed Matter'),
360: 'PRESORTED_STANDARD' => Mage::helper('usa')->__('Presorted Standard')
361: ),
362: 'smartpost_endorsement' => array(
363: 'ADDRESS_CORRECTION' => Mage::helper('usa')->__('Address Correction'),
364: 'CARRIER_LEAVE_IF_NO_RESPONSE' => Mage::helper('usa')->__('Carrier Leave If No Response'),
365: 'CHANGE_SERVICE' => Mage::helper('usa')->__('Change Service'),
366: 'FORWARDING_SERVICE' => Mage::helper('usa')->__('Forwarding Service'),
367: 'RETURN_SERVICE' => Mage::helper('usa')->__('Return Service')
368: ),
369: 'signature' => array(
370: 'NO_SIGNATURE_REQUIRED' => Mage::helper('usa')->__('No Signature Required'),
371: 'ADULT' => Mage::helper('usa')->__('Adult'),
372: 'DIRECT' => Mage::helper('usa')->__('Direct'),
373: 'INDIRECT' => Mage::helper('usa')->__('Indirect'),
374: 'SERVICE_DEFAULT' => Mage::helper('usa')->__('Service Default')
375: ),
376: 'unit_of_measure'=>array(
377: 'LB' => Mage::helper('usa')->__('Pounds'),
378: 'KG' => Mage::helper('usa')->__('Kilograms'),
379: 'G' => Mage::helper('usa')->__('Grams'),
380: ),
381: 'b13a_filing_option' => array(
382: 'FILED_ELECTRONICALLY' => Mage::helper('usa')->__('Filed Electronically'),
383: 'MANUALLY_ATTACHED' => Mage::helper('usa')->__('Manually Attached'),
384: 'NOT_REQUIRED' => Mage::helper('usa')->__('Not Required'),
385: 'SUMMARY_REPORTING' => Mage::helper('usa')->__('Summary Reporting'),
386: 'FEDEX_TO_STAMP' => Mage::helper('usa')->__('Fedex to Stamp')
387: ),
388: 'rate_discount' => array(
389: 'BONUS' => Mage::helper('usa')->__('Bonus'),
390: 'COUPON' => Mage::helper('usa')->__('Coupon'),
391: 'EARNED' => Mage::helper('usa')->__('Earned'),
392: 'OTHER' => Mage::helper('usa')->__('Other'),
393: 'VOLUME' => Mage::helper('usa')->__('Volume'),
394: ),
395: 'residence_delivery' => array(
396: 'VALIDATE' => Mage::helper('usa')->__('Validate'),
397: 'ENABLED' => Mage::helper('usa')->__('Enabled'),
398: 'DISABLED' => Mage::helper('usa')->__('Disabled'))
399: );
400:
401: if ($underscore) {
402: if (!isset($codes_underscore[$type])) {
403: return false;
404: } elseif ('' === $code) {
405: return $codes_underscore[$type];
406: }
407:
408: if (!isset($codes_underscore[$type][$code])) {
409: return false;
410: } else {
411: return $codes_underscore[$type][$code];
412: }
413: } else {
414: if (!isset($codes[$type])) {
415: return false;
416: } elseif ('' === $code) {
417: return $codes[$type];
418: }
419:
420: if (!isset($codes[$type][$code])) {
421: return false;
422: } else {
423: return $codes[$type][$code];
424: }
425: }
426: }
427:
428:
429: 430: 431: 432: 433:
434: public function getAllowedMethods()
435: {
436: $allowed = explode(',', Mage::getStoreConfig('carriers/fedex/allowed_methods'));
437:
438: $arr = array();
439:
440: foreach ($allowed as $k) {
441: $arr[$k] = $this->getCode('method', $k);
442: }
443:
444: if (is_array($arr)) {
445: return $arr;
446: } else {
447: return false;
448: }
449: }
450:
451:
452:
453: 454: 455: 456: 457:
458: public function getParsedAllowedMethods()
459: {
460: if ($allowedMethods = explode(",", Mage::getStoreConfig('carriers/fedex/allowed_methods'))) {
461: foreach ($allowedMethods as $method) {
462: $parsedAllowedMethods[] = $this->getUnderscoreCodeFromCode($method);
463: }
464:
465: return $parsedAllowedMethods;
466: }
467: }
468:
469: 470: 471: 472: 473:
474: public function getParsedAllowedRatingMethods()
475: {
476: if (!Mage::getStoreConfig('carriers/fedex/alternate_rating_methods')) {
477: return $this->getParsedAllowedMethods();
478: }
479:
480: if ($allowedMethods = explode(",", Mage::getStoreConfig('carriers/fedex/allowed_rating_methods'))) {
481: foreach ($allowedMethods as $method) {
482: $parsedAllowedMethods[] = $this->getUnderscoreCodeFromCode($method);
483: }
484:
485: return $parsedAllowedMethods;
486: }
487: }
488:
489:
490: protected function _doShipmentRequest(Varien_Object $request)
491: {
492: }
493: }
494: