1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
handler.php
См. документацию.
1<?php
2
3namespace Sale\Handlers\Delivery;
4
5use Bitrix\Currency\CurrencyManager;
6use Bitrix\Main\Loader;
7use \Bitrix\Main\Localization\Loc;
8use \Bitrix\Sale\Delivery\CalculationResult;
9use \Bitrix\Sale\Location\GroupTable;
10
11Loc::loadMessages(__FILE__);
12
13/*
14 * @package Bitrix\Sale\Delivery\Services
15 */
16class SimpleHandler extends \Bitrix\Sale\Delivery\Services\Base
17{
19 protected $handlerCode = 'BITRIX_SIMPLE';
20
21 protected static $isCalculatePriceImmediately = true;
22 protected static $whetherAdminExtraServicesShow = true;
23
28 public function __construct(array $initParams)
29 {
30 parent::__construct($initParams);
31
32 //Default value
33 if(!isset($this->config["MAIN"]["0"]))
34 $this->config["MAIN"]["0"] = "0";
35 }
36
40 public static function getClassTitle()
41 {
42 return Loc::getMessage("SALE_DLVR_HANDL_SMPL_TITLE2");
43 }
44
48 public static function getClassDescription()
49 {
50 return Loc::getMessage("SALE_DLVR_HANDL_SMPL_DESCRIPTION");
51 }
52
57 protected function getLocationGroups()
58 {
59 $result = array();
60 $res = GroupTable::getList(array(
61 'select' => array('ID', 'CODE', 'LNAME' => 'NAME.NAME'),
62 'filter' => array('NAME.LANGUAGE_ID' => LANGUAGE_ID)
63 ));
64
65 while($group = $res->fetch())
66 $result[$group['ID']] = $group['LNAME'];
67
68 return $result;
69 }
70
76 protected function calculateConcrete(\Bitrix\Sale\Shipment $shipment = null)
77 {
78 $result = new CalculationResult;
79 $result->setDeliveryPrice(
80 roundEx(
81 $this->config["MAIN"]["0"],
83 )
84 );
85
86 $order = $shipment->getCollection()->getOrder();
87
88 if(!$props = $order->getPropertyCollection())
89 return $result;
90
91 if(!$locationProp = $props->getDeliveryLocation())
92 return $result;
93
94 if(!$locationCode = $locationProp->getValue())
95 return $result;
96
97 $res = \Bitrix\Sale\Location\LocationTable::getList(array(
98 'runtime' => array(
99 new \Bitrix\Main\Entity\ReferenceField(
100 'PARENT_GROUP',
101 '\Bitrix\Sale\Location\GroupLocationTable',
102 array(
103 '=this.PARENTS.ID' => 'ref.LOCATION_ID',
104 ),
105 array(
106 "join_type" => 'inner'
107 )
108 )
109 ),
110 'filter' => array('=CODE' => $locationCode),
111 'select' => array('CLOSEST_GROUP_ID' => 'PARENT_GROUP.LOCATION_GROUP_ID'),
112 'order' => array('PARENTS.DEPTH_LEVEL' => 'desc'),
113 'limit' => 1
114 ));
115
116 if($group = $res->fetch())
117 {
118 if(isset($this->config["MAIN"][$group['CLOSEST_GROUP_ID']]))
119 {
120 $result->setDeliveryPrice(
121 roundEx(
122 floatval(
123 $this->config["MAIN"][$group['CLOSEST_GROUP_ID']]
124 ),
126 )
127 );
128 }
129 }
130
131 return $result;
132 }
133
138 protected function getConfigStructure()
139 {
141
142 if(Loader::includeModule('currency'))
143 {
144 $currencyList = CurrencyManager::getCurrencyList();
145 if (isset($currencyList[$this->currency]))
146 $currency = $currencyList[$this->currency];
147 unset($currencyList);
148 }
149
150 $result = array(
151 "MAIN" => array(
152 "TITLE" => Loc::getMessage("SALE_DLVR_HANDL_SMPL_TAB_MAIN"),
153 "DESCRIPTION" => Loc::getMessage("SALE_DLVR_HANDL_SMPL_TAB_MAIN_DESCR"),
154 "ITEMS" => array(
155
156 "CURRENCY" => array(
157 "TYPE" => "DELIVERY_READ_ONLY",
158 "NAME" => Loc::getMessage("SALE_DLVR_HANDL_SMPL_CURRENCY"),
159 "VALUE" => $this->currency,
160 "VALUE_VIEW" => $currency
161 ),
162
163 0 => array(
164 "TYPE" => "NUMBER",
165 "MIN" => 0,
166 "NAME" => Loc::getMessage("SALE_DLVR_HANDL_SMPL_DEFAULT")
167 )
168 )
169 )
170 );
171
172 foreach(self::getLocationGroups() as $groupId => $groupName)
173 {
174 $result["MAIN"]["ITEMS"][$groupId] = array(
175 "TYPE" => "NUMBER",
176 "MIN" => 0,
177 "NAME" => $groupName
178 );
179 }
180
181 return $result;
182 }
183
184 public function isCalculatePriceImmediately()
185 {
186 return self::$isCalculatePriceImmediately;
187 }
188
189 public static function whetherAdminExtraServicesShow()
190 {
191 return self::$whetherAdminExtraServicesShow;
192 }
193}
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
roundEx($value, $prec=0)
Определения tools.php:4635
$order
Определения payment.php:8
$currency
Определения template.php:266
$props
Определения template.php:269
const SALE_VALUE_PRECISION
Определения include.php:46