Skip to content

Commit fce3528

Browse files
committed
Tracking URL for parcels and better debugInfo
1 parent abaa853 commit fce3528

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

src/Picqer/Carriers/SendCloud/Model.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,18 @@ public function json()
136136
return json_encode($json);
137137
}
138138

139+
/**
140+
* Make var_dump and print_r look pretty
141+
*
142+
* @return array
143+
*/
144+
public function __debugInfo()
145+
{
146+
$result = [];
147+
foreach ($this->fillable as $attribute)
148+
{
149+
$result[$attribute] = $this->$attribute;
150+
}
151+
return $result;
152+
}
139153
}

src/Picqer/Carriers/SendCloud/Parcel.php

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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

Comments
 (0)