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