Skip to content

Commit 38ca9ca

Browse files
committed
Initial release
0 parents  commit 38ca9ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+5162
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor/

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

classes/DpdCarrier.php

Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
<?php
2+
3+
namespace DpdConnect\classes;
4+
5+
/**
6+
* This file is part of the Prestashop Shipping module of DPD Nederland B.V.
7+
*
8+
* Copyright (C) 2017 DPD Nederland B.V.
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
24+
use Db;
25+
use Carrier;
26+
use DbQuery;
27+
use CarrierModule;
28+
use Configuration;
29+
30+
class DpdCarrier extends CarrierModule
31+
{
32+
public $carrierNames;
33+
public $dpdPrefix;
34+
35+
public function __construct()
36+
{
37+
$this->dpdPrefix = 'dpdconnect_';
38+
39+
$this->carrierNames['predict'] = [
40+
'name' => 'DPD Predict',
41+
'description' => $this->l('DPD predict delivery'),
42+
'type' => 'b2c'
43+
];
44+
45+
$this->carrierNames['parcelshop'] = [
46+
'name' => 'DPD Parcelshop',
47+
'description' => $this->l('deliver it at a Parcelshop'),
48+
'type' => 'b2c'
49+
];
50+
51+
$this->carrierNames['saturday'] = [
52+
'name' => 'DPD Zaterdag',
53+
'description' => $this->l('only deliver at a saturday'),
54+
'type' => 'b2c',
55+
];
56+
57+
$this->carrierNames['classic_saturday'] = [
58+
'name' => 'DPD Classic Zaterdag',
59+
'description' => $this->l('only deliver at a saturday'),
60+
'type' => 'b2b'
61+
];
62+
63+
$this->carrierNames['classic'] = [
64+
'name' => 'DPD Classic',
65+
'description' => $this->l('DPD classic delivery'),
66+
'type' => 'b2b'
67+
];
68+
69+
$this->carrierNames['guarantee18'] = [
70+
'name' => 'Guarantee 18:00',
71+
'description' => $this->l('DPD Guarantee 18:00 delivery'),
72+
'type' => 'b2b'
73+
];
74+
75+
$this->carrierNames['express12'] = [
76+
'name' => 'Express 12:00',
77+
'description' => $this->l('DPD Express 12:00 delivery'),
78+
'type' => 'b2b'
79+
];
80+
81+
$this->carrierNames['express10'] = [
82+
'name' => 'Express 10:00',
83+
'description' => $this->l('DPD Express 10:00 delivery'),
84+
'type' => 'b2b'
85+
];
86+
}
87+
88+
public function createCarriers()
89+
{
90+
foreach ($this->carrierNames as $prefix => $info) {
91+
if (empty(Configuration::get($this->dpdPrefix . strtolower($prefix)))) {
92+
$carrier = new Carrier();
93+
94+
$carrier->url ='//tracking.dpd.de/parcelstatus?query=@';
95+
$carrier->name = $info['name'];
96+
$carrier->delay[Configuration::get('PS_LANG_DEFAULT')] = (string)$info['description'];
97+
$carrier->active = 0;
98+
$carrier->deleted = 1;
99+
$carrier->shipping_handling = 1;
100+
$carrier->range_behavior = 0;
101+
$carrier->shipping_external = 0;
102+
$carrier->add();
103+
$carrier->id_reference = $carrier->id;
104+
$carrier->update();
105+
Configuration::updateValue($this->dpdPrefix . strtolower($prefix), $carrier->id);
106+
107+
// copy(dirname(__DIR__) . '/../logo.png', _PS_SHIP_IMG_DIR_ . '/' . (int)$carrier->id . '.jpg'); //assign carrier logo
108+
}
109+
}
110+
$this->setCarrierForAccountType();
111+
return true;
112+
}
113+
114+
public function setCarrierForAccountType()
115+
{
116+
$accountType = Configuration::get($this->dpdPrefix . 'account_type');
117+
118+
foreach ($this->carrierNames as $prefix => $info) {
119+
$configCarrierId = Configuration::get($this->dpdPrefix . $prefix);
120+
121+
$carrierId = $this->getLatestCarrierByReferenceId($configCarrierId, false);
122+
if ($info['type'] == $accountType) {
123+
$this->unDeleteCarrier($carrierId);
124+
} else {
125+
$this->softDeleteCarriers($carrierId);
126+
}
127+
}
128+
}
129+
130+
131+
public function deleteCarriers()
132+
{
133+
foreach ($this->carrierNames as $prefix => $info) {
134+
$carrier_id = $this->getLatestCarrierByReferenceId(Configuration::get($this->dpdPrefix . strtolower($prefix)));
135+
if ($this->softDeleteCarriers($carrier_id)) {
136+
$output = true;
137+
} else {
138+
$output = false;
139+
}
140+
}
141+
142+
return $output;
143+
}
144+
public function getLatestCarrierByReferenceId($id_carrier, $except_deleted = true)
145+
{
146+
if ($id_carrier === false) {
147+
return;
148+
}
149+
$sql = new DbQuery();
150+
$sql->from('carrier');
151+
$sql->select('id_carrier');
152+
$sql->where('id_reference = ' . pSQL($id_carrier));
153+
if ($except_deleted) {
154+
$sql->where('deleted != 1');
155+
}
156+
$sql->orderBy('id_carrier DESC');
157+
$sql->limit(1);
158+
159+
$result = Db::getInstance()->ExecuteS($sql);
160+
if (count($result) == 0) {
161+
return $id_carrier;
162+
} else {
163+
return current($result)['id_carrier'];
164+
}
165+
}
166+
167+
public function ifHasSameReferenceId($carrierId, $referenceId)
168+
{
169+
$tempCarrier = new Carrier($carrierId);
170+
return $tempCarrier->id_reference == $referenceId;
171+
}
172+
173+
public function softDeleteCarriers($carrier_id)
174+
{
175+
Db::getInstance()->update('carrier', ['deleted' => 1], 'id_carrier = '. pSQL($carrier_id));
176+
return true;
177+
}
178+
179+
public function unDeleteCarrier($carrier_id)
180+
{
181+
Db::getInstance()->update('carrier', ['deleted' => 0], 'id_carrier = '. pSQL($carrier_id));
182+
return true;
183+
}
184+
185+
public function checkIfSaturdayAllowed()
186+
{
187+
$showfromday = Configuration::get('dpdconnect_saturday_showfromday');
188+
$showfromtime = Configuration::get('dpdconnect_saturday_showfromtime');
189+
$showtilltime = Configuration::get('dpdconnect_saturday_showtilltime');
190+
$showtillday = Configuration::get('dpdconnect_saturday_showtillday');
191+
if (empty($showfromday) || empty($showfromtime) || empty($showtillday) || empty($showtilltime)) {
192+
return false;
193+
}
194+
$showfromtime = explode(':', $showfromtime);
195+
$firstDate = new \DateTime($showfromday . ' this week ' . $showfromtime[0] . ' hours ' . $showfromtime[1] . ' minutes 00 seconds');
196+
$showtilltime = explode(':', $showtilltime);
197+
$lastDate = new \DateTime($showtillday . ' this week ' . $showtilltime[0] . ' hours ' . $showtilltime[1] . ' minutes 59 seconds');
198+
199+
$today = new \DateTime();
200+
201+
return $today >= $firstDate && $today <= $lastDate;
202+
}
203+
204+
205+
206+
public function getOrderShippingCost($params, $shipping_cost)
207+
{
208+
}
209+
210+
public function getOrderShippingCostExternal($params)
211+
{
212+
}
213+
214+
public function getShortNameShipping($carrierId)
215+
{
216+
$tempCarrier = new Carrier($carrierId);
217+
$tempCarrierReferenceId = $tempCarrier->id_reference;
218+
219+
foreach ($this->carrierNames as $prefix => $info) {
220+
if (Configuration::get($this->dpdPrefix . $prefix) == $tempCarrierReferenceId) {
221+
if ($prefix == 'guarantee18') {
222+
return 'DPD 18';
223+
} elseif ($prefix == 'classic_saturday') {
224+
return 'DPD B2B Sat';
225+
} elseif ($prefix == 'saturday') {
226+
return 'DPD B2C Sat';
227+
} elseif ($prefix == 'express12') {
228+
return 'DPD 12';
229+
} elseif ($prefix == 'express10') {
230+
return 'DPD 10';
231+
} else {
232+
return $tempCarrier->name;
233+
}
234+
}
235+
}
236+
}
237+
238+
239+
public function checkIfCarrierIsDpd($carrierId)
240+
{
241+
$dpdCarrierIds = [];
242+
foreach ($this->carrierNames as $prefix => $info) {
243+
$dpdCarrierIds[] = Configuration::get($this->dpdPrefix . strtolower($prefix));
244+
}
245+
return in_array($carrierId, $dpdCarrierIds);
246+
}
247+
}

classes/DpdEncryptionManager.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace DpdConnect\classes;
4+
5+
/**
6+
* This file is part of the Prestashop Shipping module of DPD Nederland B.V.
7+
*
8+
* Copyright (C) 2017 DPD Nederland B.V.
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
24+
class DpdEncryptionManager
25+
{
26+
protected static $cipher = 'AES-128-CBC';
27+
protected static $key = _COOKIE_KEY_;
28+
29+
public static function decrypt($encoded)
30+
{
31+
$decoded = base64_decode($encoded);
32+
33+
list($iv, $encryption) = explode('::', $decoded, 2);
34+
35+
$decryption = openssl_decrypt($encryption, self::$cipher, self::$key, OPENSSL_RAW_DATA, $iv);
36+
37+
return $decryption;
38+
}
39+
40+
public static function encrypt($decryption)
41+
{
42+
$ivlen = openssl_cipher_iv_length(self::$cipher);
43+
$iv = openssl_random_pseudo_bytes($ivlen);
44+
45+
$encryption = openssl_encrypt($decryption, self::$cipher, self::$key, OPENSSL_RAW_DATA, $iv);
46+
47+
return base64_encode($iv . '::' . $encryption);
48+
}
49+
}

classes/DpdError.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace DpdConnect\classes;
4+
5+
/**
6+
* This file is part of the Prestashop Shipping module of DPD Nederland B.V.
7+
*
8+
* Copyright (C) 2017 DPD Nederland B.V.
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
24+
use dpdconnect;
25+
26+
class DpdError
27+
{
28+
public $errors;
29+
private static $module = null;
30+
31+
public function __construct()
32+
{
33+
self::getModule();
34+
$this->setErrorMessage();
35+
}
36+
37+
private static function getModule()
38+
{
39+
if (is_null(self::$module)) {
40+
self::$module = new dpdconnect();
41+
}
42+
return self::$module;
43+
}
44+
45+
public function setErrorMessage()
46+
{
47+
$this->errors['TOO_MANY_PARCELS'] = self::$module->l('Not allowed to have more than 50 parcel\'s', 'dpderror');
48+
$this->errors['ID_IS_NOT_SET'] = self::$module->l('The ID %s is not set', 'dpderror');
49+
$this->errors['ORDER_ID_DOES_NOT_EXIST'] = self::$module->l('The ID %s doesn\'t exist', 'dpderror');
50+
$this->errors['NOT_SHIPPED_BY_DPD'] = self::$module->l('The order %s is not shipped by DPD', 'dpderror');
51+
$this->errors['WEIGHT_TO_HEAVY'] = self::$module->l('The weight of one parcel can\'t be higher then 31.5. Try to ship it in more parcel\'s', 'dpderror');
52+
$this->errors['CANCELED'] = self::$module->l('The order %s has been canceled', 'dpderror');
53+
$this->errors['LOGIN_8'] = self::$module->l('The DelisId or DelisPassword is wrong', 'dpderror');
54+
$this->errors['PRINT_LABEL'] = self::$module->l('Something went wrong while printing the label', 'dpderror');
55+
$this->errors['DPD_CONNECT_ERROR'] = self::$module->l('Something went wrong while printing the label', 'dpderror');
56+
$this->errors['DPD_CONNECT_EXCEPTION'] = self::$module->l('Something went wrong while printing the label', 'dpderror');
57+
}
58+
59+
public function get()
60+
{
61+
$args = func_get_args();
62+
$args[0] = self::$module->l($this->errors[$args[0]]);
63+
return call_user_func_array('sprintf', $args);
64+
}
65+
}

0 commit comments

Comments
 (0)