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
|
|
|
$xml = json_encode($data); |
24
|
|
|
$headers = array( |
25
|
|
|
"Content-type: text/json", |
26
|
|
|
"Content-length: " . strlen($xml), |
27
|
|
|
"Connection: close", |
28
|
|
|
); |
29
|
|
|
$c = curl_init(); |
30
|
|
|
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); |
31
|
|
|
curl_setopt($c, CURLOPT_URL, $URL); |
32
|
|
|
curl_setopt($c, CURLOPT_POST, 1); |
33
|
|
|
curl_setopt($c, CURLOPT_POSTFIELDS, $xml); |
34
|
|
|
curl_setopt($c, CURLOPT_HTTPHEADER, $headers); |
35
|
|
|
$contents = curl_exec($c); |
36
|
|
|
curl_close($c); |
37
|
|
|
|
38
|
|
|
if ($contents) return $contents; |
39
|
|
|
else return FALSE; |
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
static function calcPrice($cart) { |
|
|
|
|
43
|
|
|
|
44
|
|
|
|
45
|
|
|
$sessionId = \Cache::get('PickPointSession'); |
46
|
|
|
if (!$sessionId) { |
47
|
|
|
$config = ConfigItem::getList(['where' => ['delivery_provider_id', $cart->delivery->delivery_provider_id], 'key' => 'name']); |
48
|
|
|
$result = self::curl_get_file_contents('https://e-solution.pickpoint.ru/api/login', [ |
49
|
|
|
'Login' => $config['login']->value, |
50
|
|
|
'Password' => $config['pass']->value, |
51
|
|
|
]); |
52
|
|
|
$sessionId = json_decode($result, true)['SessionId']; |
53
|
|
|
\Cache::set('PickPointSession', $sessionId, [], 12 * 60 * 60); |
54
|
|
|
} |
55
|
|
|
$city = ''; |
56
|
|
|
foreach ($cart->delivery->fields as $field) { |
57
|
|
|
if ($field->code === 'index' && !empty($_POST['deliveryFields'][$field->id]) && is_string($_POST['deliveryFields'][$field->id])) { |
58
|
|
|
$result = json_decode(self::curl_get_file_contents('https://e-solution.pickpoint.ru/api/postindexpostamatlist', ['PostIndex' => $_POST['deliveryFields'][$field->id]]), true); |
59
|
|
|
//print_r($result['PostamatList'][0]); |
|
|
|
|
60
|
|
|
if (!empty($result['PostamatList'][0]['CitiName'])) { |
61
|
|
|
$city = $result['PostamatList'][0]['CitiName']; |
62
|
|
|
$toId = $result['PostamatList'][0]['Id']; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
if (!$city) { |
67
|
|
|
return new \Money\Sums([$cart->delivery->currency_id => 0]); |
68
|
|
|
} |
69
|
|
|
if ($city === 'Красноярск') { |
70
|
|
|
$senderCity = 'Красноярск'; |
71
|
|
|
} else { |
72
|
|
|
$senderCity = 'Москва'; |
73
|
|
|
} |
74
|
|
|
$result = json_decode(self::curl_get_file_contents('https://e-solution.pickpoint.ru/api/calctariff', [ |
|
|
|
|
75
|
|
|
'SessionId'=>$sessionId, |
76
|
|
|
'FromCity'=>$senderCity, |
77
|
|
|
'IKN'=>$config['ikn']->value, |
78
|
|
|
'PTNumber'=>$toId, |
79
|
|
|
'Length'=>25, |
80
|
|
|
'Depth'=>25, |
81
|
|
|
'Width'=>25, |
82
|
|
|
]), true); |
83
|
|
|
//print_r($result); |
84
|
|
|
return new \Money\Sums([$cart->delivery->currency_id => 0]); |
85
|
|
|
} |
86
|
|
|
} |
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.