Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
discountexecutionmodeindex.php
1<?
2
3namespace Bitrix\Sale\Update;
4
10
12{
13 const CONTINUE_EXECUTING = true;
14 const STOP_EXECUTING = false;
15
16 const PORTION = 30;
17 const TMP_EXECUTE_MODE = 22;
18
19 protected static $moduleId = 'sale';
20
21 public function execute(array &$result)
22 {
23 $status = $this->loadCurrentStatus();
24 if (empty($status['count']) || $status['count'] < 0)
25 {
27 }
28
29 $newStatus = array(
30 'count' => $status['count'],
31 'steps' => $status['steps'],
32 );
33 $connection = Application::getConnection();
34 $discountRows = DiscountTable::getList(
35 array(
36 'select' => array('*'),
37 'filter' => array(
38 '>ID' => $status['lastId'],
39 'EXECUTE_MODE' => self::TMP_EXECUTE_MODE,
40 ),
41 'order' => array('ID' => 'ASC'),
42 'offset' => 0,
43 'limit' => self::PORTION,
44 )
45 );
46
47 foreach ($discountRows as $discountRow)
48 {
49 $mode = Analyzer::getInstance()->canCalculateSeparately($discountRow) ?
50 DiscountTable::EXECUTE_MODE_SEPARATELY : DiscountTable::EXECUTE_MODE_GENERAL;
51
52 $connection->queryExecute("UPDATE b_sale_discount SET EXECUTE_MODE = {$mode} WHERE ID = {$discountRow['ID']}");
53
54 $newStatus['lastId'] = $discountRow['ID'];
55 $newStatus['steps']++;
56 }
57
58 if (!empty($newStatus['lastId']))
59 {
60 Option::set('sale', 'discountexecutionmodeindex', serialize($newStatus));
61 $result = array(
62 'count' => $newStatus['count'],
63 'steps' => $newStatus['steps'],
64 );
65
67 }
68
69 $canCalculateSeparately = Analyzer::getInstance()->canCalculateSeparatelyAllDiscount();
70 Option::set('sale', 'discount_separately_calculation', $canCalculateSeparately? 'Y' : 'N');
71 Option::delete('sale', array('name' => 'discountexecutionmodeindex'));
72
74 }
75
79 protected function loadCurrentStatus()
80 {
81 $status = Option::get('sale', 'discountexecutionmodeindex', '');
82 $status = ($status !== '' ? @unserialize($status, ['allowed_classes' => false]) : array());
83 $status = (is_array($status) ? $status : array());
84
85 if (empty($status))
86 {
87 $status = array(
88 'lastId' => 0,
89 'steps' => 0,
90 'count' => DiscountTable::getCount(
91 array(
92 'EXECUTE_MODE' => 22,
93 '=ACTIVE' => 'Y',
94 )
95 )
96 );
97 }
98
99 return $status;
100 }
101}
102
103?>
static getConnection($name="")