Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
analyzer.php
1<?php
2
4
8
9final class Analyzer
10{
12 protected $internalModules = array('sale', 'catalog', 'main');
16 private static $instance;
17
22 public static function getInstance()
23 {
24 if (!isset(self::$instance))
25 {
26 self::$instance = new self;
27 }
28
29 return self::$instance;
30 }
31
32 private function __construct()
33 {
34 $this->errorCollection = new ErrorCollection();
35 }
36
37 private function __clone()
38 {
39 }
40
47 public function isContainGiftAction(array $discount)
48 {
49 if(isset($discount['ACTIONS']) && is_string($discount['ACTIONS']))
50 {
51 return mb_strpos($discount['ACTIONS'], \CSaleActionGiftCtrlGroup::getControlID()) !== false;
52 }
53 elseif(isset($discount['ACTIONS_LIST']['CHILDREN']) && is_array($discount['ACTIONS_LIST']['CHILDREN']))
54 {
55 foreach($discount['ACTIONS_LIST']['CHILDREN'] as $child)
56 {
57 if(
58 isset($child['CLASS_ID']) && isset($child['DATA']) &&
59 $child['CLASS_ID'] === \CSaleActionGiftCtrlGroup::getControlID()
60 )
61 {
62 return true;
63 }
64 }
65 unset($child);
66 }
67
68 return false;
69 }
70
77 public function canCalculateSeparately(array $discount)
78 {
79 if(
80 !isset($discount['LAST_DISCOUNT']) ||
81 !isset($discount['LAST_LEVEL_DISCOUNT']) ||
82 !isset($discount['EXECUTE_MODULE'])
83 )
84 {
85 return false;
86 }
87
88 if ($discount['EXECUTE_MODULE'] !== 'all' && $discount['EXECUTE_MODULE'] !== 'catalog')
89 {
90 return false;
91 }
92
93 if ($discount['LAST_DISCOUNT'] === 'Y' || $discount['LAST_LEVEL_DISCOUNT'] === 'Y')
94 {
95 return false;
96 }
97
98 $tryToFindAppliedCondition = $this->tryToFindAppliedCondition($discount);
99 if ($tryToFindAppliedCondition === true || $tryToFindAppliedCondition === null)
100 {
101 return false;
102 }
103
104 if (!$this->emptyConditionsList($discount))
105 {
106 return false;
107 }
108
109 if (!$this->isExistOnlySaleDiscountAction($discount))
110 {
111 return false;
112 }
113
114 return true;
115 }
116
123 {
124 $query = DiscountTable::query();
125 $query->setSelect(array('ID'));
126 $query->setFilter(array(
127 '=ACTIVE' => 'Y',
129 ));
130 $query->setLimit(1);
131
132 return !(bool)$query->exec()->fetch() && !$this->isThereCustomDiscountModules();
133 }
134
135 private function isThereCustomDiscountModules()
136 {
137 $query = DiscountModuleTable::query();
138 $query->setSelect(array('ID'));
139 $query->setFilter(array(
140 '!@MODULE_ID' => $this->internalModules,
141 ));
142 $query->setLimit(1);
143
144 return (bool)$query->exec()->fetch();
145 }
146
147 private function isExistOnlySaleDiscountAction(array $discount)
148 {
149 $actionStructure = $discount['ACTIONS_LIST'];
150 if (!$actionStructure || !is_array($actionStructure))
151 {
152 return null;
153 }
154
155 if ($actionStructure['CLASS_ID'] != 'CondGroup')
156 {
157 return false;
158 }
159
160 if (count($actionStructure['CHILDREN']) > 1)
161 {
162 return false;
163 }
164
165 $action = reset($actionStructure['CHILDREN']);
166 if ($action['CLASS_ID'] != 'ActSaleBsktGrp')
167 {
168 return false;
169 }
170
171 return true;
172 }
173
174 private function emptyConditionsList(array $discount)
175 {
176 if (empty($discount['CONDITIONS_LIST']) || !is_array($discount['CONDITIONS_LIST']))
177 {
178 return null;
179 }
180
181 if (empty($discount['CONDITIONS_LIST']['CHILDREN']))
182 {
183 return true;
184 }
185
186 return false;
187 }
188
189 private function tryToFindAppliedCondition(array $discount)
190 {
191 if (isset($discount['ACTIONS']) && is_string($discount['ACTIONS']))
192 {
193 return mb_strpos($discount['ACTIONS'], \CSaleActionCondCtrlBasketFields::CONTROL_ID_APPLIED_DISCOUNT) !== false;
194 }
195
196 if (isset($discount['ACTIONS_LIST']))
197 {
198 $asString = serialize($discount['ACTIONS_LIST']);
199 if ($asString)
200 {
201 return mb_strpos($asString, \CSaleActionCondCtrlBasketFields::CONTROL_ID_APPLIED_DISCOUNT) !== false;
202 }
203 }
204
205 //it means that there are not ACTIONS or ACTIONS_LIST. So, we can't solve this and decide, that we found condition.
206 //after that this discount will be marked as EXECUTE_MODE=GENERAL
207 return null;
208 }
209}
canCalculateSeparately(array $discount)
Definition analyzer.php:77
isContainGiftAction(array $discount)
Definition analyzer.php:47