11<?php namespace Picqer \Carriers \SendCloud ;
22
3- class Parcel extends Model {
3+ class Parcel extends Model
4+ {
45
56 use Query \Findable;
67 use Persistance \Storable;
@@ -28,4 +29,51 @@ class Parcel extends Model {
2829 'singular ' => 'parcel ' ,
2930 'plural ' => 'parcels '
3031 ];
32+
33+ protected $ shipperShippingMethodIds = [
34+ 'BPost ' => [54 , 55 , 56 , 59 , 60 , 61 , 82 , 83 ],
35+ 'DHL ' => [9 , 10 , 11 , 12 , 14 , 16 , 38 , 40 ],
36+ 'DHL Germany ' => [],
37+ 'DPD ' => [41 , 51 , 68 ],
38+ 'Fadello ' => [88 ],
39+ 'PostNL ' => [1 , 2 , 3 , 4 , 5 , 6 , 7 , 39 ],
40+ ];
41+
42+ public function getTrackingUrl ()
43+ {
44+ $ shipper = $ this ->getShipperName ();
45+
46+ switch ($ shipper ) {
47+ case 'BPost ' :
48+ return sprintf ('http://track.bpost.be/btr/web/#/search?itemCode=%s&lang=en ' , $ this ->tracking_number );
49+ break ;
50+ case 'DHL ' :
51+ return sprintf ('https://www.dhlparcel%s/%s/track-trace?tt=%s ' , $ this ->country ['iso_2 ' ] == 'BE ' ? 'be ' : 'nl ' , 'EN ' , $ this ->tracking_number );
52+ break ;
53+ case 'DHL Germany ' :
54+ return sprintf ('https://nolp.dhl.de/nextt-online-public/set_identcodes.do?runtime=standalone&idc=%s ' , $ this ->tracking_number );
55+ break ;
56+ case 'DPD ' :
57+ return sprintf ('https://tracking.dpd.de/parcelstatus?locale=%s&query=%s ' , 'en_EN ' , $ this ->tracking_number );
58+ break ;
59+ case 'Fadello ' :
60+ return sprintf ('https://www.fadello.nl/livetracker?c=%s&pc=%s ' , $ this ->tracking_number , $ this ->postal_code );
61+ break ;
62+ case 'PostNL ' :
63+ return sprintf ('https://jouw.postnl.nl/#!/track-en-trace/%s/%s/%s ' , $ this ->tracking_number , $ this ->country ['iso_2 ' ], $ this ->postal_code );
64+ break ;
65+ default :
66+ return null ;
67+ break ;
68+ }
69+ }
70+
71+ private function getShipperName ()
72+ {
73+ foreach ($ this ->shipperShippingMethodIds as $ shipper => $ methodIdArray ) {
74+ if (in_array ($ this ->shipment ['id ' ], $ methodIdArray )) {
75+ return $ shipper ;
76+ }
77+ }
78+ }
3179}
0 commit comments