1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
step_operations.php
См. документацию.
1<?
6
7if (!Loader::includeModule('catalog'))
8 return;
9
10Loc::loadMessages(__FILE__);
11
13{
14 const SESSION_PREFIX = 'BDC';
15
16 protected $filter = array();
17 protected $orderViewUrl = '';
18
20 {
21 $sessID = (string)$sessID;
22 if ($sessID == '')
23 $sessID = self::SESSION_PREFIX.time();
24
25 if (Main\Config\Option::get('main', '~sale_converted_15', 'N') == 'Y')
26 $this->orderViewUrl = '/bitrix/admin/sale_order_view.php?ID=#ID#&lang='.LANGUAGE_ID;
27 else
28 $this->orderViewUrl = '/bitrix/admin/sale_order_detail.php?ID=#ID#&lang='.LANGUAGE_ID;
29
30 parent::__construct($sessID, $maxExecutionTime, $maxOperationCounter);
31 }
32
33 public function setFilter($filter)
34 {
35 if (empty($filter) || !is_array($filter))
36 return;
37 $this->filter = $filter;
38 }
39
40 public function runOperation()
41 {
42 $found = false;
43 $filter = array('>ID' => $this->lastID, 'ORDER_DISCOUNT_DATA.ID' => null);
44 if (!empty($this->filter))
45 {
46 foreach ($this->filter as $filterKey => $filterValue)
47 $filter[$filterKey] = $filterValue;
48 unset($filterKey, $filterValue);
49 }
50 $ordersIterator = Sale\Internals\OrderTable::getList(array(
51 'select' => array('ID', 'CURRENCY', 'LID'),
52 'filter' => $filter,
53 'order' => array('ID' => 'ASC'),
54 'limit' => $this->maxOperationCounter
55 ));
56 while ($order = $ordersIterator->fetch())
57 {
58 $found = true;
59
61 $this->lastID = $order['ID'];
62 $this->allOperationCounter++;
63 if (!$migrateResult->isSuccess())
64 {
65 $this->errorCounter++;
66 $this->stepErrors[] = Loc::getMessage(
67 'SALE_BASKET_DISCOUNT_ORDER_ERROR_REPORT',
68 array(
69 '#URL#' => str_replace('#ID#', $order['ID'], $this->orderViewUrl),
70 '#TITLE#' => $order['ID'],
71 '#ERRORS#' => implode('; ', $migrateResult->getErrorMessages())
72 )
73 );
74 }
75 unset($migrateResult);
76
77 if ($this->maxExecutionTime > 0 && (time() - $this->startOperationTime > $this->maxExecutionTime))
78 break;
79 }
80 unset($order, $ordersIterator);
81 if (!$found)
82 $this->finishOperation = true;
83 }
84
85 public static function getAllCounter()
86 {
87 $countQuery = new Main\Entity\Query(Sale\Internals\OrderTable::getEntity());
88 $countQuery->addSelect(new Main\Entity\ExpressionField('CNT', 'COUNT(1)'));
89 $countQuery->setFilter(array('ORDER_DISCOUNT_DATA.ID' => null));
90 $totalCount = $countQuery->setLimit(null)->setOffset(null)->exec()->fetch();
91 return (int)$totalCount['CNT'];
92 }
93
94 public static function getFilterCounter($filter)
95 {
96 if (!is_array($filter))
97 $filter = array();
98 if (empty($filter))
99 return self::getAllCounter();
100 $filter['ORDER_DISCOUNT_DATA.ID'] = null;
101 $countQuery = new Main\Entity\Query(Sale\Internals\OrderTable::getEntity());
102 $countQuery->addSelect(new Main\Entity\ExpressionField('CNT', 'COUNT(1)'));
103 $countQuery->setFilter($filter);
104 $totalCount = $countQuery->setLimit(null)->setOffset(null)->exec()->fetch();
105 return (int)$totalCount['CNT'];
106 }
107
108 public static function checkFilter(Main\HttpRequest $request)
109 {
110 $filter = array();
111
112 if (!empty($request['filter']['filter_type']))
113 {
114 switch ($request['filter']['filter_type'])
115 {
116 case 'id':
117 if (isset($request['filter']['order_id_from']) && (int)$request['filter']['order_id_from'] > 0)
118 $filter['>=ID'] = (int)$request['filter']['order_id_from'];
119 if (isset($request['filter']['order_id_to']) && (int)$request['filter']['order_id_to'] > 0)
120 $filter['<=ID'] = (int)$request['filter']['order_id_to'];
121 break;
122 case 'date':
123 CTimeZone::Disable();
124 if (isset($request['filter']['order_date_from']) && is_string($request['filter']['order_date_from']))
125 {
126 $date = trim($request['filter']['order_date_from']);
127 if ($date != '')
128 {
129 try
130 {
131 $filter['>=DATE_INSERT'] = Main\Type\DateTime::createFromUserTime($date);
132 }
133 catch (Main\ObjectException $e)
134 {
135
136 }
137 }
138 unset($date);
139 }
140 if (isset($request['filter']['order_date_to']) && is_string($request['filter']['order_date_to']))
141 {
142 $date = trim($request['filter']['order_date_to']);
143 if ($date != '')
144 {
145 try
146 {
147 $filter['<=DATE_INSERT'] = Main\Type\DateTime::createFromUserTime($date);
148 }
149 catch (Main\ObjectException $e)
150 {
151
152 }
153 }
154 unset($date);
155 }
156 CTimeZone::Enable();
157 break;
158 }
159 }
160
161 return $filter;
162 }
163}
164
166{
167 const SESSION_PREFIX = 'SDR';
168
169 protected $discountEditUrl = '';
170
172 {
173 $sessID = (string)$sessID;
174 if ($sessID == '')
175 $sessID = self::SESSION_PREFIX.time();
176 $this->discountEditUrl = '/bitrix/admin/sale_discount_edit.php?ID=#ID#&lang='.LANGUAGE_ID;
177 parent::__construct($sessID, $maxExecutionTime, $maxOperationCounter);
178 }
179
180 public function runOperation()
181 {
182 global $APPLICATION;
183
184 $found = false;
185 $filter = array('>ID' => $this->lastID, '=VERSION' => Sale\Internals\DiscountTable::VERSION_15);
186
187 $discountsIterator = Sale\Internals\DiscountTable::getList(array(
188 'select' => array(
189 'ID', 'MODIFIED_BY', 'TIMESTAMP_X', 'CONDITIONS_LIST', 'ACTIONS_LIST', 'NAME'
190 ),
191 'filter' => $filter,
192 'order' => array('ID' => 'ASC'),
193 'limit' => $this->maxOperationCounter
194 ));
195 while ($discount = $discountsIterator->fetch())
196 {
197 $found = true;
198 $error = array();
199 $rawFields = array(
200 'ID' => $discount['ID'],
201 'CONDITIONS' => $discount['CONDITIONS_LIST'],
202 'ACTIONS' => $discount['ACTIONS_LIST']
203 );
204 if (\CSaleDiscount::checkFields('UPDATE', $rawFields))
205 {
206 $fields = array(
207 'MODIFIED_BY' => $discount['MODIFIED_BY'],
208 'TIMESTAMP_X' => $discount['TIMESTAMP_X'],
209 'UNPACK' => $rawFields['UNPACK'],
210 'APPLICATION' => $rawFields['APPLICATION']
211 );
212 if (isset($rawFields['EXECUTE_MODULE']))
213 $fields['EXECUTE_MODULE'] = $rawFields['EXECUTE_MODULE'];
214 $useCoupons = 'N';
215 $coupon = Sale\Internals\DiscountCouponTable::getList(array(
216 'select' => array('ID', 'DISCOUNT_ID'),
217 'filter' => array('=DISCOUNT_ID' => $discount['ID']),
218 'limit' => 1
219 ))->fetch();
220 if (!empty($coupon))
221 $useCoupons = 'Y';
222 $fields['USE_COUPONS'] = $useCoupons;
223 unset($coupon, $useCoupons);
224 $updateResult = Sale\Internals\DiscountTable::update($discount['ID'], $fields);
225 if ($updateResult->isSuccess())
226 {
227 if (isset($rawFields['ENTITIES']))
228 Sale\Internals\DiscountEntitiesTable::updateByDiscount($discount['ID'], $rawFields['ENTITIES'], true);
229 if (isset($rawFields['HANDLERS']['MODULES']))
230 Sale\Internals\DiscountModuleTable::updateByDiscount($discount['ID'], $rawFields['HANDLERS']['MODULES'], true);
231 }
232 else
233 {
234 $error = $updateResult->getErrorMessages();
235 }
236 }
237 else
238 {
239 if ($ex = $APPLICATION->GetException())
240 $error[] = $ex->GetString();
241 else
242 $error[] = Loc::getMessage('SALE_DISCOUNT_REINDEX_UPDATE_UNKNOWN_ERROR');
243 }
244 $this->lastID = $discount['ID'];
245 $this->allOperationCounter++;
246 if (!empty($error))
247 {
248 $this->errorCounter++;
249 $this->stepErrors[] = Loc::getMessage(
250 'SALE_DISCOUNT_REINDEX_ORDER_ERROR_REPORT',
251 array(
252 '#URL#' => str_replace('#ID#', $discount['ID'], $this->discountEditUrl),
253 '#TITLE#' => (trim((string)$discount['NAME']) != '' ? $discount['NAME'] : $discount['ID']),
254 '#ERRORS#' => implode('; ', $error)
255 )
256 );
257 }
258
259 if ($this->maxExecutionTime > 0 && (time() - $this->startOperationTime > $this->maxExecutionTime))
260 break;
261 }
262 unset($discount, $discountsIterator);
263
264 if (!$found)
265 $this->finishOperation = true;
266 }
267
268 public static function getAllCounter()
269 {
270 $countQuery = new Main\Entity\Query(Sale\Internals\DiscountTable::getEntity());
271 $countQuery->addSelect(new Main\Entity\ExpressionField('CNT', 'COUNT(1)'));
272 $countQuery->setFilter(array('=VERSION' => Sale\Internals\DiscountTable::VERSION_15));
273 $totalCount = $countQuery->setLimit(null)->setOffset(null)->exec()->fetch();
274 return (int)$totalCount['CNT'];
275 }
276}
277
279{
280 const SESSION_PREFIX = 'SDC15';
281
282 protected $discountEditUrl = '';
283 protected $deliveryCodes = array();
284 protected $deliveryRuleId = 'CondSaleDelivery';
285
287 {
288 $sessID = (string)$sessID;
289 if ($sessID == '')
290 $sessID = self::SESSION_PREFIX.time();
291 $this->discountEditUrl = '/bitrix/admin/sale_discount_edit.php?ID=#ID#&lang='.LANGUAGE_ID;
292 parent::__construct($sessID, $maxExecutionTime, $maxOperationCounter);
293 }
294
295 public function runOperation()
296 {
297 global $APPLICATION;
298
299 $this->getDeliveryCodes();
300
301 $found = false;
302 $filter = array('>ID' => $this->lastID, '=VERSION' => Sale\Internals\DiscountTable::VERSION_NEW);
303
304 $discountsIterator = Sale\Internals\DiscountTable::getList(array(
305 'select' => array(
306 'ID', 'MODIFIED_BY', 'TIMESTAMP_X', 'CONDITIONS_LIST', 'ACTIONS_LIST', 'NAME'
307 ),
308 'filter' => $filter,
309 'order' => array('ID' => 'ASC'),
310 'limit' => $this->maxOperationCounter
311 ));
312 while ($discount = $discountsIterator->fetch())
313 {
314 $found = true;
315 $error = array();
316 $this->convertDelivery($discount['CONDITIONS_LIST']);
317 $rawFields = array(
318 'ID' => $discount['ID'],
319 'CONDITIONS' => $discount['CONDITIONS_LIST'],
320 'ACTIONS' => $discount['ACTIONS_LIST']
321 );
322 if (\CSaleDiscount::checkFields('UPDATE', $rawFields))
323 {
324 $fields = array(
325 'MODIFIED_BY' => $discount['MODIFIED_BY'],
326 'TIMESTAMP_X' => $discount['TIMESTAMP_X'],
327 'UNPACK' => $rawFields['UNPACK'],
328 'CONDITIONS_LIST' => $discount['CONDITIONS_LIST'],
330 );
331 if (isset($rawFields['EXECUTE_MODULE']))
332 $fields['EXECUTE_MODULE'] = $rawFields['EXECUTE_MODULE'];
333 $updateResult = Sale\Internals\DiscountTable::update($discount['ID'], $fields);
334 if ($updateResult->isSuccess())
335 {
336 if (isset($rawFields['ENTITIES']))
337 Sale\Internals\DiscountEntitiesTable::updateByDiscount($discount['ID'], $rawFields['ENTITIES'], true);
338 if (isset($rawFields['HANDLERS']['MODULES']))
339 Sale\Internals\DiscountModuleTable::updateByDiscount($discount['ID'], $rawFields['HANDLERS']['MODULES'], true);
340 }
341 else
342 {
343 $error = $updateResult->getErrorMessages();
344 }
345 }
346 else
347 {
348 if ($ex = $APPLICATION->GetException())
349 $error[] = $ex->GetString();
350 else
351 $error[] = Loc::getMessage('SALE_DISCOUNT_REINDEX_UPDATE_UNKNOWN_ERROR');
352 }
353 $this->lastID = $discount['ID'];
354 $this->allOperationCounter++;
355 if (!empty($error))
356 {
357 $this->errorCounter++;
358 $this->stepErrors[] = Loc::getMessage(
359 'SALE_DISCOUNT_REINDEX_ORDER_ERROR_REPORT',
360 array(
361 '#URL#' => str_replace('#ID#', $discount['ID'], $this->discountEditUrl),
362 '#TITLE#' => (trim((string)$discount['NAME']) != '' ? $discount['NAME'] : $discount['ID']),
363 '#ERRORS#' => implode('; ', $error)
364 )
365 );
366 }
367
368 if ($this->maxExecutionTime > 0 && (time() - $this->startOperationTime > $this->maxExecutionTime))
369 break;
370 }
371 unset($discount, $discountsIterator);
372
373 if (!$found)
374 $this->finishOperation = true;
375 }
376
377 public static function getAllCounter()
378 {
379 $countQuery = new Main\Entity\Query(Sale\Internals\DiscountTable::getEntity());
380 $countQuery->addSelect(new Main\Entity\ExpressionField('CNT', 'COUNT(1)'));
381 $countQuery->setFilter(array(
383 '=DISCOUNT_ENTITY.ENTITY' => 'ORDER',
384 '=DISCOUNT_ENTITY.FIELD_ENTITY' => 'PAY_SYSTEM_ID'
385 ));
386 $totalCount = $countQuery->setLimit(null)->setOffset(null)->exec()->fetch();
387 return (int)$totalCount['CNT'];
388 }
389
390 protected function getDeliveryCodes()
391 {
392 $this->deliveryCodes = array();
393 $deliveryIterator = Sale\Delivery\Services\Table::getList(array(
394 'select' => array('ID', 'CODE'),
395 ));
396 while ($delivery = $deliveryIterator->fetch())
397 {
398 $delivery['CODE'] = (string)$delivery['CODE'];
399 if ($delivery['CODE'] == '')
400 continue;
401 $this->deliveryCodes[$delivery['CODE']] = $delivery['ID'];
402 }
403 unset($delivery, $deliveryIterator);
404 }
405
406 protected function convertDelivery(&$condition)
407 {
408 if (empty($condition) || !is_array($condition))
409 return;
410 if (!isset($condition['CLASS_ID']))
411 return;
412 if ($condition['CLASS_ID'] == $this->deliveryRuleId)
413 {
414 if (empty($condition['DATA']) || !is_array($condition['DATA']))
415 return;
416 if (empty($condition['DATA']['value']))
417 return;
418 $value = $condition['DATA']['value'];
419 if (!is_array($value))
420 $value = array($value);
421 $newValue = array();
422 foreach ($value as &$item)
423 {
424 if (isset($this->deliveryCodes[$item]))
425 $newValue[] = $this->deliveryCodes[$item];
426 }
427 unset($item);
428 $condition['DATA']['value'] = $newValue;
429 unset($newValue, $value);
430 }
431 elseif (!empty($condition['CHILDREN']) && is_array($condition['CHILDREN']))
432 {
433 foreach ($condition['CHILDREN'] as &$subCondition)
434 $this->convertDelivery($subCondition);
435 unset($subCondition);
436 }
437 }
438}
global $APPLICATION
Определения include.php:80
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
static get($moduleId, $name, $default="", $siteId=false)
Определения option.php:30
Определения loader.php:13
static getMessage($code, $replace=null, $language=null)
Определения loc.php:30
static createFromUserTime($timeString)
Определения datetime.php:180
static updateByDiscount($discount, $entityList, $clear)
Определения discountentities.php:166
static updateByDiscount($discount, $moduleList, $clear)
Определения discountmodule.php:110
const SESSION_PREFIX
Определения step_operations.php:14
setFilter($filter)
Определения step_operations.php:33
static getAllCounter()
Определения step_operations.php:85
static getFilterCounter($filter)
Определения step_operations.php:94
__construct($sessID, $maxExecutionTime, $maxOperationCounter)
Определения step_operations.php:19
static checkFilter(Main\HttpRequest $request)
Определения step_operations.php:108
const SESSION_PREFIX
Определения step_operations.php:280
static getAllCounter()
Определения step_operations.php:377
convertDelivery(&$condition)
Определения step_operations.php:406
__construct($sessID, $maxExecutionTime, $maxOperationCounter)
Определения step_operations.php:286
const SESSION_PREFIX
Определения step_operations.php:167
static getAllCounter()
Определения step_operations.php:268
__construct($sessID, $maxExecutionTime, $maxOperationCounter)
Определения step_operations.php:171
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$filter
Определения iblock_catalog_list.php:54
Определения ufield.php:9
$order
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$discount
Определения waybill.php:788
$error
Определения subscription_card_product.php:20
$totalCount
Определения subscription_card_product.php:51
$fields
Определения yandex_run.php:501