-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproductdiscount.php
107 lines (86 loc) · 3.31 KB
/
productdiscount.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/**
* Class for receiving all products to which discounts apply
* Author: Dokukin Vyacheslav Olegovich <[email protected]>
* Date: 23.11.2023
*/
class ProductDiscount
{
private static $result;
private static function CondIBName(array $data)
{
$str = match ($data['logic']) {
'Contain' => "`NAME` like upper('%" . $data['value'] . "%')",
'Equal' => "`NAME`=upper('%" . $data['value'] . "%')",
};
return $str;
}
private static function CondIBElement(array $data)
{
$str = match ($data['logic']) {
'Contain' => "`ID` IN (" . explode(',', $data['value']) . ")",
'Equal' => "`ID` IN (" . implode(',', $data['value']) . ")",
};
return $str;
}
private static function CondBsktFldProduct(array $data)
{
$str = "`ID` IN (" . explode(',', $data['value']) . ")";
return $str;
}
public static function getDiscounProducts()
{
global $DB;
$arOr = array();
$date = date($DB->DateFormatToPHP('Y-m-d'), mktime(0, 0, 0, date("n"), date("d"), date("Y")));
$results = $DB->Query("SELECT `ID`, `CONDITIONS`, `ACTIONS` FROM `b_sale_discount` WHERE `ACTIVE_TO` >= '" . $date . "' AND `ACTIVE` ='Y'");
while($row = $results->Fetch())
{
$return_value = array();
$ACTIONS = unserialize($row['ACTIONS']);
foreach($ACTIONS['CHILDREN'] as $children)
{
foreach($children['CHILDREN'] as $child)
{
if(isset($child['CHILDREN']))
{
foreach($child['CHILDREN'] as $cond)
{
if(!$cond['DATA'])
continue;
$return_value[] = match ($cond['CLASS_ID']) {
'CondIBName' => self::CondIBName($cond['DATA']),
'CondIBElement' => self::CondIBElement($cond['DATA']),
'CondBsktFldProduct' => self::CondBsktFldProduct($cond['DATA']),
default => null
};
}
}else{
if(!$child['DATA'])
continue;
$return_value[] = match ($child['CLASS_ID']) {
'CondIBName' => self::CondIBName($child['DATA']),
'CondIBElement' => self::CondIBElement($child['DATA']),
'CondBsktFldProduct' => self::CondBsktFldProduct($child['DATA']),
default => null
};
}
}
}
if($return_value)
$arOr[] = implode(' OR ', $return_value);
}
if(count($arOr))
{
$res = $DB->Query("SELECT `ID` FROM `b_iblock_element` WHERE " . implode(' OR ', $arOr) . " AND `ACTIVE` = 'Y';");
while($el = $res->Fetch())
{
self::$result[] = $el['ID'];
}
self::$result = array_unique(self::$result);
return self::$result;
}
return array();
}
}
?>