Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
triggerdontbuy.php
1
<?
2
3
namespace
Bitrix\Sale\Sender
;
4
5
use
Bitrix\Main\Localization\Loc
;
6
use
Bitrix\Main\Loader
;
7
8
if
(!Loader::includeModule(
'sender'
))
9
{
10
return
;
11
}
12
13
Loc::loadMessages
(__FILE__);
14
15
class
TriggerDontBuy
extends
\Bitrix\Sender\TriggerConnectorClosed
16
{
17
18
public
function
getName
()
19
{
20
return
Loc::getMessage
(
'sender_trigger_dont_buy_name'
);
21
}
22
23
public
function
getCode
()
24
{
25
return
"dont_buy"
;
26
}
27
29
public
static
function
canBeTarget
()
30
{
31
return
false
;
32
}
33
35
public
static
function
canRunForOldData
()
36
{
37
return
true
;
38
}
39
40
public
function
filter
()
41
{
42
\Bitrix\Main\Loader::includeModule(
'sale'
);
43
44
$daysDontBuy = $this->
getFieldValue
(
'DAYS_DONT_BUY'
);
45
if
(!is_numeric($daysDontBuy))
46
$daysDontBuy = 90;
47
48
$dateFrom = new \Bitrix\Main\Type\DateTime;
49
$dateTo = new \Bitrix\Main\Type\DateTime;
50
51
$dateFrom->setTime(0, 0, 0)->add(
'-'
. $daysDontBuy .
' days'
);
52
$dateTo->setTime(0, 0, 0)->add(
'1 days'
)->add(
'-'
. $daysDontBuy .
' days'
);
53
54
if
($this->isRunForOldData())
55
{
56
$filter = array(
57
'<MAX_DATE_INSERT'
=> $dateTo->format(\
Bitrix
\Main\
UserFieldTable::MULTIPLE_DATETIME_FORMAT
),
58
);
59
}
60
else
61
{
62
$filter = array(
63
'>MAX_DATE_INSERT'
=> $dateFrom->format(\
Bitrix
\Main\
UserFieldTable::MULTIPLE_DATETIME_FORMAT
),
64
'<MAX_DATE_INSERT'
=> $dateTo->format(\
Bitrix
\Main\
UserFieldTable::MULTIPLE_DATETIME_FORMAT
),
65
);
66
}
67
$filter = $filter + array(
68
'=LID'
=> $this->getSiteId()
69
);
70
71
$userListDb = \Bitrix\Sale\Internals\OrderTable::getList(array(
72
'select'
=> array(
'BUYER_USER_ID'
=>
'USER.ID'
,
'EMAIL'
=>
'USER.EMAIL'
,
'BUYER_USER_NAME'
=>
'USER.NAME'
),
73
'filter'
=> $filter,
74
'runtime'
=> array(
75
new
\
Bitrix
\Main\
Entity
\
ExpressionField
(
'MAX_DATE_INSERT'
,
'MAX(%s)'
,
'DATE_INSERT'
),
76
),
77
'order'
=> array(
'USER_ID'
=>
'ASC'
)
78
));
79
80
if
($userListDb->getSelectedRowsCount() > 0)
81
{
82
$userListDb->addFetchDataModifier(array($this,
'getFetchDataModifier'
));
83
$this->recipient = $userListDb;
84
return
true
;
85
}
86
else
87
return
false
;
88
}
89
90
public
function
getForm
()
91
{
92
$daysDontBuyInput =
' <input size=3 type="text" name="'
.$this->getFieldName(
'DAYS_DONT_BUY'
).
'" value="'
.htmlspecialcharsbx($this->
getFieldValue
(
'DAYS_DONT_BUY'
, 90)).
'"> '
;
93
94
return
'
95
<table>
96
<tr>
97
<td>'
.Loc::getMessage(
'sender_trigger_dont_buy_days'
).
'</td>
98
<td>'
.$daysDontBuyInput.
'</td>
99
</tr>
100
</table>
101
'
;
102
}
103
104
public
function
getRecipient
()
105
{
106
return
$this->recipient;
107
}
108
109
public
function
getFetchDataModifier
($fields)
110
{
111
if
(isset($fields[
'BUYER_USER_NAME'
]))
112
{
113
$fields[
'NAME'
] = $fields[
'BUYER_USER_NAME'
];
114
unset($fields[
'BUYER_USER_NAME'
]);
115
}
116
if
(isset($fields[
'BUYER_USER_ID'
]))
117
{
118
$fields[
'USER_ID'
] = $fields[
'BUYER_USER_ID'
];
119
unset($fields[
'BUYER_USER_ID'
]);
120
}
121
122
return
$fields;
123
}
124
}
Bitrix\Catalog\Model\Entity
Definition
entity.php:12
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\ORM\Fields\ExpressionField
Definition
expressionfield.php:25
Bitrix\Main\UserFieldTable\MULTIPLE_DATETIME_FORMAT
const MULTIPLE_DATETIME_FORMAT
Definition
userfield.php:38
Bitrix\Sale\Sender\TriggerDontBuy
Definition
triggerdontbuy.php:16
Bitrix\Sale\Sender\TriggerDontBuy\getRecipient
getRecipient()
Definition
triggerdontbuy.php:104
Bitrix\Sale\Sender\TriggerDontBuy\getName
getName()
Definition
triggerdontbuy.php:18
Bitrix\Sale\Sender\TriggerDontBuy\canRunForOldData
static canRunForOldData()
Definition
triggerdontbuy.php:35
Bitrix\Sale\Sender\TriggerDontBuy\getForm
getForm()
Definition
triggerdontbuy.php:90
Bitrix\Sale\Sender\TriggerDontBuy\getFetchDataModifier
getFetchDataModifier($fields)
Definition
triggerdontbuy.php:109
Bitrix\Sale\Sender\TriggerDontBuy\filter
filter()
Definition
triggerdontbuy.php:40
Bitrix\Sale\Sender\TriggerDontBuy\getCode
getCode()
Definition
triggerdontbuy.php:23
Bitrix\Sale\Sender\TriggerDontBuy\canBeTarget
static canBeTarget()
Definition
triggerdontbuy.php:29
Bitrix\Sender\Connector\Base\getFieldValue
getFieldValue($name, $defaultValue=null)
Definition
base.php:195
Bitrix\Sender\Trigger\TriggerConnectorClosed
Definition
triggerconnectorclosed.php:12
Bitrix\Sale\Sender
Definition
connectororder.php:3
Bitrix
modules
sale
lib
sender
triggerdontbuy.php
Создано системой
1.10.0