Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
triggerdontbuy.php
1<?
2
3namespace Bitrix\Sale\Sender;
4
7
8if (!Loader::includeModule('sender'))
9{
10 return;
11}
12
13Loc::loadMessages(__FILE__);
14
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}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
getFieldValue($name, $defaultValue=null)
Definition base.php:195