1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* INJI |
4
|
|
|
* |
5
|
|
|
* @author Alexey Krupskiy <[email protected]> |
6
|
|
|
* @link http://inji.ru/ |
7
|
|
|
* @copyright 2017 Alexey Krupskiy |
8
|
|
|
* @license https://github.com/injitools/Inji/blob/master/LICENSE |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Ecommerce\DeliveryProvider; |
12
|
|
|
|
13
|
|
|
use Ecommerce\Delivery\Provider\ConfigItem; |
14
|
|
|
|
15
|
|
|
class PickPoint extends \Ecommerce\DeliveryProvider { |
16
|
|
|
static $name = 'PickPoint - курьерская служба'; |
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @param \Ecommerce\Cart $cart |
|
|
|
|
20
|
|
|
* @return \Money\Sums |
21
|
|
|
*/ |
22
|
|
|
static function curl_get_file_contents($URL, $data) { |
|
|
|
|
23
|
|
|
//var_dump($URL,$data); |
|
|
|
|
24
|
|
|
$xml = json_encode($data); |
25
|
|
|
$headers = array( |
26
|
|
|
"Content-type: text/json", |
27
|
|
|
"Content-length: " . strlen($xml), |
28
|
|
|
"Connection: close", |
29
|
|
|
); |
30
|
|
|
$c = curl_init(); |
31
|
|
|
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); |
32
|
|
|
curl_setopt($c, CURLOPT_URL, $URL); |
33
|
|
|
curl_setopt($c, CURLOPT_POST, 1); |
34
|
|
|
curl_setopt($c, CURLOPT_POSTFIELDS, $xml); |
35
|
|
|
curl_setopt($c, CURLOPT_HTTPHEADER, $headers); |
36
|
|
|
$contents = curl_exec($c); |
37
|
|
|
curl_close($c); |
38
|
|
|
|
39
|
|
|
if ($contents) return $contents; |
40
|
|
|
else return FALSE; |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
static function calcPrice($cart) { |
|
|
|
|
44
|
|
|
|
45
|
|
|
|
46
|
|
|
$sessionId = \Cache::get('PickPointSession', []); |
47
|
|
|
if (!$sessionId) { |
48
|
|
|
$config = ConfigItem::getList(['where' => ['delivery_provider_id', $cart->delivery->delivery_provider_id], 'key' => 'name']); |
49
|
|
|
$result = self::curl_get_file_contents('https://e-solution.pickpoint.ru/api/login', [ |
50
|
|
|
'Login' => $config['login']->value, |
51
|
|
|
'Password' => $config['pass']->value, |
52
|
|
|
]); |
53
|
|
|
$sessionId = json_decode($result, true)['SessionId']; |
54
|
|
|
\Cache::set('PickPointSession', $sessionId, [], 12 * 60 * 60); |
55
|
|
|
} |
56
|
|
|
$city = ''; |
57
|
|
|
foreach ($cart->delivery->fields as $field) { |
58
|
|
|
if ($field->code === 'index' && !empty($_POST['deliveryFields'][$field->id]) && is_string($_POST['deliveryFields'][$field->id])) { |
59
|
|
|
$result = json_decode(self::curl_get_file_contents('https://e-solution.pickpoint.ru/api/postindexpostamatlist', ['PostIndex' => $_POST['deliveryFields'][$field->id]]), true); |
60
|
|
|
//print_r($result['PostamatList'][0]); |
|
|
|
|
61
|
|
|
if (!empty($result['PostamatList'][0]['CitiName'])) { |
62
|
|
|
$city = $result['PostamatList'][0]['CitiName']; |
63
|
|
|
$toId = $result['PostamatList'][0]['Number']; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
if (!$city) { |
68
|
|
|
return new \Money\Sums([$cart->delivery->currency_id => 0]); |
69
|
|
|
} |
70
|
|
|
if ($city === 'Красноярск') { |
71
|
|
|
$senderCity = 'Красноярск'; |
72
|
|
|
} else { |
73
|
|
|
$senderCity = 'Москва'; |
74
|
|
|
} |
75
|
|
|
$result = json_decode(self::curl_get_file_contents('https://e-solution.pickpoint.ru/api/calctariff', [ |
76
|
|
|
'SessionId' => $sessionId, |
77
|
|
|
'FromCity' => $senderCity, |
78
|
|
|
'IKN' => $config['ikn']->value, |
79
|
|
|
'PTNumber' => $toId, |
80
|
|
|
'Length' => 25, |
81
|
|
|
'Depth' => 25, |
82
|
|
|
'Width' => 25, |
83
|
|
|
]), true); |
84
|
|
|
$summ = 0; |
85
|
|
|
if (!empty($result['Services'][0]['Tariff'])) { |
86
|
|
|
$summ = $result['Services'][0]['Tariff'] + $result['Services'][0]['NDS']; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return new \Money\Sums([$cart->delivery->currency_id => $summ]); |
90
|
|
|
} |
91
|
|
|
} |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.