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\Delivery\Provider\ConfigItem; |
15
|
|
|
use Ecommerce\UserAdds\Field; |
16
|
|
|
|
17
|
|
|
class CDEK extends \Ecommerce\DeliveryProvider { |
18
|
|
|
static $name = 'СДЭК - курьерская служба'; |
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param \Ecommerce\Cart $cart |
22
|
|
|
* @return \Money\Sums |
23
|
|
|
*/ |
24
|
|
|
static function calcPrice($cart) { |
|
|
|
|
25
|
|
|
$calc = new \Ecommerce\Vendor\CalculatePriceDeliveryCdek(); |
26
|
|
|
$fields = []; |
|
|
|
|
27
|
|
|
$cityId = 0; |
28
|
|
|
$senderCity = 44; |
29
|
|
|
$tariff = 136; |
30
|
|
|
$fieldInfo = Field::get('deliveryfield_city', 'code'); |
31
|
|
|
$field = \Ecommerce\Delivery\Field::get('city', 'code'); |
32
|
|
|
if (isset($cart->infos[$fieldInfo->id])) { |
33
|
|
|
$item = Item::get([['id', $cart->infos[$fieldInfo->id]->value], ['delivery_field_id', $field->id]]); |
34
|
|
|
if ($item) { |
35
|
|
|
$cityId = json_decode($item->data, true)['ID']; |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
foreach ($cart->delivery->fields as $field) { |
39
|
|
|
if ($field->code === 'cdektype' && !empty($_POST['deliveryFields'][$field->id]) && is_numeric($_POST['deliveryFields'][$field->id])) { |
40
|
|
|
$item = Item::get([['id', $_POST['deliveryFields'][$field->id]], ['delivery_field_id', $field->id]]); |
41
|
|
|
if ($item) { |
42
|
|
|
$tariff = $item->data; |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
if ($cityId) { |
47
|
|
|
$config = ConfigItem::getList(['where' => ['delivery_provider_id', $cart->delivery->delivery_provider_id], 'key' => 'name']); |
48
|
|
|
$calc->setAuth($config['authLogin']->value, $config['authPassword']->value); |
49
|
|
|
$calc->setDateExecute(date('Y-m-d H:i:s')); |
50
|
|
|
$calc->setSenderCityId($senderCity); |
51
|
|
|
//устанавливаем город-получатель |
52
|
|
|
$calc->setReceiverCityId($cityId); |
53
|
|
|
$calc->setTariffId($tariff); |
54
|
|
|
$calc->addGoodsItemBySize(3, 25, 25, 24); |
55
|
|
|
if ($calc->calculate()) { |
56
|
|
|
return new \Money\Sums([$cart->delivery->currency_id => $calc->getResult()['result']['price']]); |
57
|
|
|
} else { |
|
|
|
|
58
|
|
|
//var_dump($tariff,$calc->getError()); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
} |
62
|
|
|
return new \Money\Sums([$cart->delivery->currency_id => 0]); |
63
|
|
|
} |
64
|
|
|
} |
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.