16 private static $instance;
24 if (!isset(self::$instance))
26 self::$instance =
new self;
29 return self::$instance;
32 private function __construct()
37 private function __clone()
49 if(isset($discount[
'ACTIONS']) && is_string($discount[
'ACTIONS']))
51 return mb_strpos($discount[
'ACTIONS'], \CSaleActionGiftCtrlGroup::getControlID()) !==
false;
53 elseif(isset($discount[
'ACTIONS_LIST'][
'CHILDREN']) && is_array($discount[
'ACTIONS_LIST'][
'CHILDREN']))
55 foreach($discount[
'ACTIONS_LIST'][
'CHILDREN'] as $child)
58 isset($child[
'CLASS_ID']) && isset($child[
'DATA']) &&
59 $child[
'CLASS_ID'] === \CSaleActionGiftCtrlGroup::getControlID()
80 !isset($discount[
'LAST_DISCOUNT']) ||
81 !isset($discount[
'LAST_LEVEL_DISCOUNT']) ||
82 !isset($discount[
'EXECUTE_MODULE'])
88 if ($discount[
'EXECUTE_MODULE'] !==
'all' && $discount[
'EXECUTE_MODULE'] !==
'catalog')
93 if ($discount[
'LAST_DISCOUNT'] ===
'Y' || $discount[
'LAST_LEVEL_DISCOUNT'] ===
'Y')
98 $tryToFindAppliedCondition = $this->tryToFindAppliedCondition($discount);
99 if ($tryToFindAppliedCondition ===
true || $tryToFindAppliedCondition ===
null)
104 if (!$this->emptyConditionsList($discount))
109 if (!$this->isExistOnlySaleDiscountAction($discount))
124 $query = DiscountTable::query();
125 $query->setSelect(array(
'ID'));
126 $query->setFilter(array(
132 return !(bool)$query->exec()->fetch() && !$this->isThereCustomDiscountModules();
135 private function isThereCustomDiscountModules()
137 $query = DiscountModuleTable::query();
138 $query->setSelect(array(
'ID'));
139 $query->setFilter(array(
140 '!@MODULE_ID' => $this->internalModules,
144 return (
bool)$query->exec()->fetch();
147 private function isExistOnlySaleDiscountAction(array $discount)
149 $actionStructure = $discount[
'ACTIONS_LIST'];
150 if (!$actionStructure || !is_array($actionStructure))
155 if ($actionStructure[
'CLASS_ID'] !=
'CondGroup')
160 if (count($actionStructure[
'CHILDREN']) > 1)
165 $action = reset($actionStructure[
'CHILDREN']);
166 if ($action[
'CLASS_ID'] !=
'ActSaleBsktGrp')
174 private function emptyConditionsList(array $discount)
176 if (empty($discount[
'CONDITIONS_LIST']) || !is_array($discount[
'CONDITIONS_LIST']))
181 if (empty($discount[
'CONDITIONS_LIST'][
'CHILDREN']))
189 private function tryToFindAppliedCondition(array $discount)
191 if (isset($discount[
'ACTIONS']) && is_string($discount[
'ACTIONS']))
193 return mb_strpos($discount[
'ACTIONS'], \CSaleActionCondCtrlBasketFields::CONTROL_ID_APPLIED_DISCOUNT) !==
false;
196 if (isset($discount[
'ACTIONS_LIST']))
198 $asString = serialize($discount[
'ACTIONS_LIST']);
201 return mb_strpos($asString, \CSaleActionCondCtrlBasketFields::CONTROL_ID_APPLIED_DISCOUNT) !==
false;