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\Field\Item; |
14
|
|
|
use Ecommerce\UserAdds\Field; |
15
|
|
|
|
16
|
|
|
class CDEK extends \Ecommerce\DeliveryProvider { |
17
|
|
|
static $name = 'СДЭК - курьерская служба'; |
|
|
|
|
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param \Ecommerce\Cart $cart |
21
|
|
|
*/ |
22
|
|
|
static function request($cart) { |
|
|
|
|
23
|
|
|
$cityId = 0; |
24
|
|
|
$senderCity = 44; |
25
|
|
|
$tariff = 136; |
26
|
|
|
$fieldInfo = Field::get('deliveryfield_city', 'code'); |
27
|
|
|
$field = \Ecommerce\Delivery\Field::get('city', 'code'); |
28
|
|
View Code Duplication |
if (isset($cart->infos[$fieldInfo->id])) { |
|
|
|
|
29
|
|
|
$item = Item::get([['id', $cart->infos[$fieldInfo->id]->value], ['delivery_field_id', $field->id]]); |
30
|
|
|
if ($item) { |
31
|
|
|
$cityId = json_decode($item->data, true)['ID']; |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
$field = \Ecommerce\Delivery\Field::get('cdektype', 'code'); |
35
|
|
View Code Duplication |
if (isset($cart->deliveryInfos[$field->id])) { |
|
|
|
|
36
|
|
|
$item = Item::get([['id', $cart->deliveryInfos[$field->id]->value], ['delivery_field_id', $field->id]]); |
37
|
|
|
if ($item) { |
38
|
|
|
$tariff = $item->data; |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
if ($cityId) { |
42
|
|
|
$config = self::config(); |
43
|
|
|
return \Cache::get('pickPointCalc', [ |
44
|
|
|
'login' => $config['authLogin'], |
45
|
|
|
'pass' => $config['authPassword'], |
46
|
|
|
'senderCity' => $senderCity, |
47
|
|
|
'cityId' => $cityId, |
48
|
|
|
'tariff' => $tariff, |
49
|
|
|
], function ($data) { |
50
|
|
|
$calc = new \Ecommerce\Vendor\CalculatePriceDeliveryCdek(); |
51
|
|
|
$calc->setAuth($data['login'], $data['pass']); |
52
|
|
|
$calc->setDateExecute(date('Y-m-d H:i:s')); |
53
|
|
|
$calc->setSenderCityId($data['senderCity']); |
54
|
|
|
//устанавливаем город-получатель |
55
|
|
|
$calc->setReceiverCityId($data['cityId']); |
56
|
|
|
$calc->setTariffId($data['tariff']); |
57
|
|
|
$calc->addGoodsItemBySize(3, 25, 25, 24); |
58
|
|
|
if ($calc->calculate()) { |
59
|
|
|
return $calc->getResult(); |
60
|
|
|
} else { |
61
|
|
|
//var_dump($tariff,$calc->getError()); |
|
|
|
|
62
|
|
|
return false; |
63
|
|
|
} |
64
|
|
|
}); |
65
|
|
|
} |
66
|
|
|
return false; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
static function calcPrice($cart) { |
|
|
|
|
70
|
|
|
$result = self::request($cart); |
71
|
|
|
if (!empty($result['result']['price'])) { |
72
|
|
|
return new \Money\Sums([$cart->delivery->currency_id => round($result['result']['price'] * 1.1, 2)]); |
73
|
|
|
} |
74
|
|
|
return new \Money\Sums([$cart->delivery->currency_id => 0]); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
static function deliveryTime($cart) { |
|
|
|
|
78
|
|
|
$result = self::request($cart); |
79
|
|
|
if (isset($result['result']['deliveryPeriodMin'])) { |
80
|
|
|
return [ |
81
|
|
|
'min' => $result['result']['deliveryPeriodMin'], |
82
|
|
|
'max' => $result['result']['deliveryPeriodMax'], |
83
|
|
|
]; |
84
|
|
|
} |
85
|
|
|
return [ |
86
|
|
|
'min' => 0, |
87
|
|
|
'max' => 0, |
88
|
|
|
]; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
static function availablePayTypeGroups($cart) { |
|
|
|
|
92
|
|
|
$field = \Ecommerce\Delivery\Field::get('cdektype', 'code'); |
93
|
|
|
if (isset($cart->deliveryInfos[$field->id])) { |
94
|
|
|
$item = Item::get([['id', $cart->deliveryInfos[$field->id]->value], ['delivery_field_id', $field->id]]); |
95
|
|
|
if ($item) { |
96
|
|
|
if ($item->data == 137) { |
97
|
|
|
return ['*']; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
return ['online']; |
102
|
|
|
} |
103
|
|
|
} |
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.