1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
delivery.php
См. документацию.
1<?php
2
3namespace Sale\Handlers\DiscountPreset;
4
5use Bitrix\Main;
6use Bitrix\Main\Error;
7use Bitrix\Main\Localization\Loc;
8use Bitrix\Sale\Discount\Preset\ArrayHelper;
9use Bitrix\Sale\Discount\Preset\HtmlHelper;
10use Bitrix\Sale\Discount\Preset\Manager;
11use Bitrix\Sale\Discount\Preset\SelectProductPreset;
12use Bitrix\Sale\Discount\Preset\State;
13
14class Delivery extends SelectProductPreset
15{
16 public function getTitle()
17 {
18 return Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_DELIVERY_NAME');
19 }
20
21 public function getDescription()
22 {
23 return '';
24 }
25
29 public function getCategory()
30 {
31 return Manager::CATEGORY_DELIVERY;
32 }
33
34 public function getFirstStepName()
35 {
36 return 'InputName';
37 }
38
39 public function processShowInputName(State $state)
40 {
41 return $this->processShowInputNameInternal($state);
42 }
43
44 public function processSaveInputName(State $state)
45 {
46 return $this->processSaveInputNameInternal($state, 'InputAmount');
47 }
48
54 protected function getDeliverySystems($siteId)
55 {
56 $parameters = array(
57 'select' => array(
58 '*',
59 'SITES' => 'RESTRICTION_BY_SITE.PARAMS',
60 ),
61 'filter' => array(
62 '=ACTIVE' => 'Y',
63 '!=CLASS_NAME' => array(
64 '\Bitrix\Sale\Delivery\Services\Group',
65 '\Bitrix\Sale\Delivery\Services\EmptyDeliveryService',
66 ),
67 ),
68 'runtime' => array(
69 'RESTRICTION_BY_SITE' => array(
70 'data_type' => 'Bitrix\Sale\Internals\ServiceRestrictionTable',
71 'reference' => array(
72 'ref.SERVICE_ID' => 'this.ID',
73 'ref.SERVICE_TYPE' => array(
74 '?',
75 \Bitrix\Sale\Delivery\Restrictions\Manager::SERVICE_TYPE_SHIPMENT,
76 ),
77 'ref.CLASS_NAME' => array('?', '\Bitrix\Sale\Delivery\Restrictions\BySite'),
78 ),
79 'join_type' => 'left',
80 ),
81 ),
82 );
83
84 $result = array();
85 $dbResultList = \Bitrix\Sale\Delivery\Services\Table::getList($parameters);
86 while($service = $dbResultList->fetch())
87 {
88 if(!empty($service['SITES']) && is_array($service['SITES']['SITE_ID']))
89 {
90 if(!in_array($siteId, $service['SITES']['SITE_ID']))
91 {
92 continue;
93 }
94 }
95 unset($service['SITES']);
96
97 $deliveryService = \Bitrix\Sale\Delivery\Services\Manager::createObject($service);
98 if (!$deliveryService || $deliveryService->canHasProfiles() || $deliveryService->canHasChildren())
99 {
100 continue;
101 }
102
103 $result[$service['ID']] = $deliveryService;
104 }
105
106 return $result;
107 }
108
109 protected function getLabelDiscountValue()
110 {
111 return Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_DELIVERY_DELIVERY_DISCOUNT_VALUE');
112 }
113
114 public function processShowInputAmount(State $state)
115 {
116 $lid = $state->get('discount_lid');
117 $currency = \Bitrix\Sale\Internals\SiteCurrencyTable::getSiteCurrency($lid);
118 $deliverySystems = $this->getDeliverySystems($lid);
119
120 $forSelectData = array();
121 foreach($deliverySystems as $id => $deliverySystem)
122 {
123 $forSelectData[$id] = $deliverySystem->getNameWithParent();
124 }
125 Main\Type\Collection::sortByColumn($forSelectData, 'NAME', '', null, true);
126
127 return '
128 <table width="100%" border="0" cellspacing="7" cellpadding="0">
129 <tbody>
130 <tr>
131 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_SHIPMENT_DELIVERY_ORDER_AMOUNT') . ':</strong></td>
132 <td class="adm-detail-content-cell-r" style="width:60%;">
133 <input type="text" name="discount_order_amount" value="' . htmlspecialcharsbx($state->get('discount_order_amount')) . '" size="39" maxlength="100" style="width: 100px;"> <span>' . $currency . '</span>
134 </td>
135 </tr>' . $this->renderDiscountValue($state, $currency) . '
136 <tr>
137 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_SHIPMENT_DELIVERY_LABEL') . ':</strong></td>
138 <td class="adm-detail-content-cell-r">
139 ' . HtmlHelper::generateSelect('discount_delivery', $forSelectData, $state->get('discount_delivery')) . '
140 </td>
141 </tr>
142 </tbody>
143 </table>
144 ';
145 }
146
147 protected function renderDiscountValue(State $state, $currency)
148 {
149 return '
150 <tr>
151 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . $this->getLabelDiscountValue() . ':</strong></td>
152 <td class="adm-detail-content-cell-r" style="width:60%;">
153 <input type="text" name="discount_value" value="' . htmlspecialcharsbx($state->get('discount_value')) . '" maxlength="100" style="width: 100px;"> '
154 . HtmlHelper::generateSelect('discount_type', array(
155 'Perc' => Loc::getMessage('SHD_BT_SALE_ACT_GROUP_BASKET_SELECT_PERCENT'),
156 'Cur' => $currency,
157 ), $state->get('discount_type')) . '
158 </td>
159 </tr>
160 ';
161 }
162
163 public function processSaveInputAmount(State $state)
164 {
165 if(!trim($state->get('discount_value')))
166 {
167 $this->errorCollection[] = new Error(Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_ERROR_EMPTY_VALUE'));
168 }
169
170 if(!trim($state->get('discount_order_amount')))
171 {
172 $this->errorCollection[] = new Error(Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_ERROR_EMPTY_ORDER_AMOUNT'));
173 }
174
175 if((int)$state->get('discount_delivery') < 0)
176 {
177 $this->errorCollection[] = new Error(Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_ERROR_EMPTY_DELIVERY'));
178 }
179
180 if(!$this->errorCollection->isEmpty())
181 {
182 return array($state, 'InputAmount');
183 }
184
185 return array($state, 'CommonSettings');
186 }
187
188 public function processShowCommonSettings(State $state)
189 {
190 return $this->processShowCommonSettingsInternal($state);
191 }
192
193 public function processSaveCommonSettings(State $state)
194 {
195 return $this->processSaveCommonSettingsInternal($state);
196 }
197
198 public function generateState(array $discountFields)
199 {
200 $discountFields = $this->normalizeDiscountFields($discountFields);
201
202 $stateFields = [
203 'discount_lid' => $discountFields['LID'],
204 'discount_name' => $discountFields['NAME'],
205 'discount_groups' => $this->getUserGroupsByDiscount($discountFields['ID']),
206 'discount_value' => ArrayHelper::getByPath($discountFields, 'ACTIONS.CHILDREN.0.DATA.Value'),
207 'discount_type' => ArrayHelper::getByPath($discountFields, 'ACTIONS.CHILDREN.0.DATA.Unit'),
208 'discount_order_amount' => ArrayHelper::getByPath($discountFields, 'CONDITIONS.CHILDREN.0.DATA.Value'),
209 'discount_delivery' => ArrayHelper::getByPath($discountFields, 'CONDITIONS.CHILDREN.1.DATA.value.0'),
210 ];
211
212 return parent::generateState($discountFields)->append($stateFields);
213 }
214
215 public function generateDiscount(State $state)
216 {
217 return array_merge(parent::generateDiscount($state), array(
218 'CONDITIONS' => array(
219 'CLASS_ID' => 'CondGroup',
220 'DATA' => array(
221 'All' => 'AND',
222 'True' => 'True',
223 ),
224 'CHILDREN' => array(
225 array(
226 'CLASS_ID' => 'CondBsktAmtGroup',
227 'DATA' => array(
228 'logic' => 'EqGr',
229 'Value' => $state->get('discount_order_amount'),
230 'All' => 'AND',
231 ),
232 'CHILDREN' => array(),
233 ),
234 array(
235 'CLASS_ID' => 'CondSaleDelivery',
236 'DATA' => array(
237 'logic' => 'Equal',
238 'value' => array((int)$state->get('discount_delivery')),
239 ),
240 ),
241 ),
242 ),
243 'ACTIONS' => array(
244 'CLASS_ID' => 'CondGroup',
245 'DATA' => array(
246 'All' => 'AND',
247 ),
248 'CHILDREN' => array(
249 array(
250 'CLASS_ID' => 'ActSaleDelivery',
251 'DATA' => array(
252 'Type' => $this->getTypeOfDiscount(),
253 'Value' => $state->get('discount_value'),
254 'Unit' => $state->get('discount_type', 'Cur'),
255 ),
256 ),
257 ),
258 ),
259 ));
260 }
261}
normalizeDiscountFields(array $discountFields)
Определения basepreset.php:608
processSaveCommonSettingsInternal(State $state, $nextStep=self::FINAL_STEP)
Определения basepreset.php:923
processSaveInputNameInternal(State $state, $nextStep)
Определения basepreset.php:811
processShowInputNameInternal(State $state)
Определения basepreset.php:789
processShowCommonSettingsInternal(State $state)
Определения basepreset.php:836
getUserGroupsByDiscount($discountId)
Определения basepreset.php:703
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$siteId
Определения ajax.php:8
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
trait Error
Определения error.php:11
$service
Определения payment.php:18
$currency
Определения template.php:266