Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
triggercampaign.php
1<?
2
4
8
9Loc::loadMessages(__FILE__);
10
17{
18 protected static function getMailTemplate(array $params = null)
19 {
20 if(!isset($params['TITLE']))
21 {
22 $params['TITLE'] = '%TITLE%';
23 }
24
25 if(!isset($params['TEXT']))
26 {
27 $params['TEXT'] = '%TEXT%';
28 }
29
30 $content = Templates\Mail::getTemplateHtml();
31 $content = Templates\Mail::replaceTemplateHtml(
32 $content,
33 [
34 'TEXT' => "<br><h2>{$params['TITLE']}</h2><br>{$params['TEXT']}<br><br>"
35 ]
36 );
37
38 return $content;
39 }
40
41 protected static function getCoupon($perc = 5)
42 {
43 if(!is_numeric($perc))
44 $perc = 5;
45
46 return '<?EventMessageThemeCompiler::includeComponent(
47 "bitrix:sale.discount.coupon.mail",
48 "",
49 Array(
50 "COMPONENT_TEMPLATE" => ".default",
51 "DISCOUNT_XML_ID" => "{#SENDER_CHAIN_CODE#}",
52 "DISCOUNT_VALUE" => "' . $perc . '",
53 "DISCOUNT_UNIT" => "Perc",
54 "COUPON_TYPE" => "Order",
55 "COUPON_DESCRIPTION" => "{#EMAIL_TO#}"
56 )
57 );?>';
58 }
59
60 protected static function getBasketCart()
61 {
62 return '<?EventMessageThemeCompiler::includeComponent(
63 "bitrix:sale.basket.basket.small.mail",
64 "",
65 Array(
66 "USER_ID" => "{#USER_ID#}",
67 "PATH_TO_BASKET" => "/",
68 "PATH_TO_ORDER" => "/",
69 )
70 );?>';
71 }
72
73 protected static function getMessagePlaceHolders()
74 {
75 return array(
76 '%BASKET_CART%' => self::getBasketCart(),
77 '%COUPON%' => self::getCoupon(5),
78 '%COUPON_3%' => self::getCoupon(3),
79 '%COUPON_5%' => self::getCoupon(5),
80 '%COUPON_7%' => self::getCoupon(7),
81 '%COUPON_10%' => self::getCoupon(10),
82 '%COUPON_11%' => self::getCoupon(11),
83 '%COUPON_15%' => self::getCoupon(15),
84 '%COUPON_20%' => self::getCoupon(20),
85 );
86 }
87
93 public static function getTemplateCategories()
94 {
95 $list = [];
96
97 $id = 1000;
98 $all = self::getAll();
99 foreach ($all as $item)
100 {
101 $list[] = [
102 'id' => $id++,
103 'code' => mb_strtoupper($item['CODE']),
104 'name' => $item['TYPE'] . '. ' . $item['NAME'],
105 ];
106 }
107
108 return $list;
109 }
110
116 public static function getAll()
117 {
118 $list = [];
119
120 $list[] = self::getForgottenCart(1);
121 $list[] = self::getCanceledOrder();
122 $list[] = self::getPaidOrder();
123 $list[] = self::getDontBuy(90);
124 $list[] = self::getDontAuth(111);
125 $list[] = self::getDontBuy(180);
126 $list[] = self::getDontBuy(360);
127
128 return $list;
129 }
130
137 public static function getForgottenCart($days)
138 {
139 $list = array(
140 'TYPE' => Loc::getMessage('PRESET_TYPE_BASKET'),
141 'CODE' => 'sale_basket',
142 'NAME' => Loc::getMessage('PRESET_FORGOTTEN_BASKET_NAME'),
143 'DESC_USER' => Loc::getMessage('PRESET_FORGOTTEN_BASKET_DESC_USER'),
144 'DESC' => Loc::getMessage('PRESET_FORGOTTEN_BASKET_DESC'),
145 'TRIGGER' => array(
146 'START' => array(
147 'ENDPOINT' => array(
148 'MODULE_ID' => 'sale',
149 'CODE' => 'basket_forgotten',
150 'FIELDS' => array('DAYS_BASKET_FORGOTTEN' => $days)
151 )
152 ),
153 'END' => array(
154 'ENDPOINT' => array(
155 'MODULE_ID' => 'sale',
156 'CODE' => 'order_paid',
157 'FIELDS' => array()
158 )
159 ),
160 ),
161 'CHAIN' => array(
162 array(
163 'TIME_SHIFT' => 0,
164 'SUBJECT' => Loc::getMessage('PRESET_FORGOTTEN_BASKET_LETTER_1_SUBJECT'),
165 'MESSAGE' => self::getMailTemplate(array(
166 'TITLE' => Loc::getMessage('PRESET_FORGOTTEN_BASKET_LETTER_1_SUBJECT'),
167 'TEXT' => Loc::getMessage('PRESET_FORGOTTEN_BASKET_LETTER_1_MESSAGE', static::getMessagePlaceHolders()),
168 )),
169 ),
170 array(
171 'TIME_SHIFT' => 1440,
172 'SUBJECT' => Loc::getMessage('PRESET_FORGOTTEN_BASKET_LETTER_2_SUBJECT'),
173 'MESSAGE' => self::getMailTemplate(array(
174 'TITLE' => Loc::getMessage('PRESET_FORGOTTEN_BASKET_LETTER_2_SUBJECT'),
175 'TEXT' => Loc::getMessage('PRESET_FORGOTTEN_BASKET_LETTER_2_MESSAGE', static::getMessagePlaceHolders()),
176 )),
177 ),
178 array(
179 'TIME_SHIFT' => 1440,
180 'SUBJECT' => Loc::getMessage('PRESET_FORGOTTEN_BASKET_LETTER_3_SUBJECT'),
181 'MESSAGE' => self::getMailTemplate(array(
182 'TITLE' => Loc::getMessage('PRESET_FORGOTTEN_BASKET_LETTER_3_SUBJECT'),
183 'TEXT' => Loc::getMessage('PRESET_FORGOTTEN_BASKET_LETTER_3_MESSAGE', static::getMessagePlaceHolders()),
184 )),
185 ),
186 )
187 );
188
189 foreach ($list['CHAIN'] as $index => $letter)
190 {
191 $letter['TEMPLATE_TYPE'] = Sender\Templates\Type::getCode(Sender\Templates\Type::BASE);
192 $letter['TEMPLATE_ID'] = mb_strtoupper($list['CODE']).'_' . $index;
193 $list['CHAIN'][$index] = $letter;
194 }
195
196 return $list;
197 }
198
204 public static function getCanceledOrder()
205 {
206 $list = array(
207 'TYPE' => Loc::getMessage('PRESET_TYPE_ORDER'),
208 'CODE' => 'sale_order_cancel',
209 'NAME' => Loc::getMessage('PRESET_CANCELED_ORDER_NAME'),
210 'DESC_USER' => Loc::getMessage('PRESET_CANCELED_ORDER_DESC_USER'),
211 'DESC' => Loc::getMessage('PRESET_CANCELED_ORDER_DESC'),
212 'TRIGGER' => array(
213 'START' => array(
214 'ENDPOINT' => array(
215 'MODULE_ID' => 'sale',
216 'CODE' => 'order_cancel',
217 'FIELDS' => array()
218 )
219 ),
220 'END' => array(
221 'ENDPOINT' => array(
222 'MODULE_ID' => 'sale',
223 'CODE' => 'order_paid',
224 'FIELDS' => array()
225 )
226 ),
227 ),
228 'CHAIN' => array(
229 array(
230 'TIME_SHIFT' => 0,
231 'SUBJECT' => Loc::getMessage('PRESET_CANCELED_ORDER_LETTER_1_SUBJECT'),
232 'MESSAGE' => self::getMailTemplate(array(
233 'TITLE' => Loc::getMessage('PRESET_CANCELED_ORDER_LETTER_1_SUBJECT'),
234 'TEXT' => Loc::getMessage('PRESET_CANCELED_ORDER_LETTER_1_MESSAGE', static::getMessagePlaceHolders()),
235 )),
236 ),
237 array(
238 'TIME_SHIFT' => 1440,
239 'SUBJECT' => Loc::getMessage('PRESET_CANCELED_ORDER_LETTER_2_SUBJECT'),
240 'MESSAGE' => self::getMailTemplate(array(
241 'TITLE' => Loc::getMessage('PRESET_CANCELED_ORDER_LETTER_2_SUBJECT'),
242 'TEXT' => Loc::getMessage('PRESET_CANCELED_ORDER_LETTER_2_MESSAGE', static::getMessagePlaceHolders()),
243 )),
244 ),
245 array(
246 'TIME_SHIFT' => 1440,
247 'SUBJECT' => Loc::getMessage('PRESET_CANCELED_ORDER_LETTER_3_SUBJECT'),
248 'MESSAGE' => self::getMailTemplate(array(
249 'TITLE' => Loc::getMessage('PRESET_CANCELED_ORDER_LETTER_3_SUBJECT'),
250 'TEXT' => Loc::getMessage('PRESET_CANCELED_ORDER_LETTER_3_MESSAGE', static::getMessagePlaceHolders()),
251 )),
252 ),
253 )
254 );
255
256 foreach ($list['CHAIN'] as $index => $letter)
257 {
258 $letter['TEMPLATE_TYPE'] = Sender\Templates\Type::getCode(Sender\Templates\Type::BASE);
259 $letter['TEMPLATE_ID'] = mb_strtoupper($list['CODE']).'_' . $index;
260 $list['CHAIN'][$index] = $letter;
261 }
262
263 return $list;
264 }
265
271 public static function getPaidOrder()
272 {
273 $list = array(
274 'TYPE' => Loc::getMessage('PRESET_TYPE_ORDER'),
275 'CODE' => 'sale_order_pay',
276 'NAME' => Loc::getMessage('PRESET_PAID_ORDER_NAME'),
277 'DESC_USER' => Loc::getMessage('PRESET_PAID_ORDER_DESC_USER'),
278 'DESC' => Loc::getMessage('PRESET_PAID_ORDER_DESC'),
279 'TRIGGER' => array(
280 'START' => array(
281 'ENDPOINT' => array(
282 'MODULE_ID' => 'sale',
283 'CODE' => 'order_paid',
284 'FIELDS' => array()
285 )
286 ),
287 'END' => array(
288 'ENDPOINT' => array(
289 'MODULE_ID' => 'sale',
290 'CODE' => 'order_paid',
291 'FIELDS' => array()
292 )
293 ),
294 ),
295 'CHAIN' => array(
296 array(
297 'TIME_SHIFT' => 1440,
298 'SUBJECT' => Loc::getMessage('PRESET_PAID_ORDER_LETTER_1_SUBJECT'),
299 'MESSAGE' => self::getMailTemplate(array(
300 'TITLE' => Loc::getMessage('PRESET_PAID_ORDER_LETTER_1_SUBJECT'),
301 'TEXT' => Loc::getMessage('PRESET_PAID_ORDER_LETTER_1_MESSAGE', static::getMessagePlaceHolders()),
302 )),
303 ),
304 array(
305 'TIME_SHIFT' => 1440,
306 'SUBJECT' => Loc::getMessage('PRESET_PAID_ORDER_LETTER_2_SUBJECT'),
307 'MESSAGE' => self::getMailTemplate(array(
308 'TITLE' => Loc::getMessage('PRESET_PAID_ORDER_LETTER_2_SUBJECT'),
309 'TEXT' => Loc::getMessage('PRESET_PAID_ORDER_LETTER_2_MESSAGE', static::getMessagePlaceHolders()),
310 )),
311 ),
312 array(
313 'TIME_SHIFT' => 1440,
314 'SUBJECT' => Loc::getMessage('PRESET_PAID_ORDER_LETTER_3_SUBJECT'),
315 'MESSAGE' => self::getMailTemplate(array(
316 'TITLE' => Loc::getMessage('PRESET_PAID_ORDER_LETTER_3_SUBJECT'),
317 'TEXT' => Loc::getMessage('PRESET_PAID_ORDER_LETTER_3_MESSAGE', static::getMessagePlaceHolders()),
318 )),
319 ),
320 array(
321 'TIME_SHIFT' => 1440,
322 'SUBJECT' => Loc::getMessage('PRESET_PAID_ORDER_LETTER_4_SUBJECT'),
323 'MESSAGE' => self::getMailTemplate(array(
324 'TITLE' => Loc::getMessage('PRESET_PAID_ORDER_LETTER_4_SUBJECT'),
325 'TEXT' => Loc::getMessage('PRESET_PAID_ORDER_LETTER_4_MESSAGE', static::getMessagePlaceHolders()),
326 )),
327 ),
328 array(
329 'TIME_SHIFT' => 1440,
330 'SUBJECT' => Loc::getMessage('PRESET_PAID_ORDER_LETTER_5_SUBJECT'),
331 'MESSAGE' => self::getMailTemplate(array(
332 'TITLE' => Loc::getMessage('PRESET_PAID_ORDER_LETTER_5_SUBJECT'),
333 'TEXT' => Loc::getMessage('PRESET_PAID_ORDER_LETTER_5_MESSAGE', static::getMessagePlaceHolders()),
334 )),
335 ),
336 )
337 );
338
339 foreach ($list['CHAIN'] as $index => $letter)
340 {
341 $letter['TEMPLATE_TYPE'] = Sender\Templates\Type::getCode(Sender\Templates\Type::BASE);
342 $letter['TEMPLATE_ID'] = mb_strtoupper($list['CODE']).'_' . $index;
343 $list['CHAIN'][$index] = $letter;
344 }
345
346 return $list;
347 }
348
355 public static function getDontBuy($days)
356 {
357 $list = array(
358 'TYPE' => Loc::getMessage('PRESET_TYPE_ORDER'),
359 'CODE' => 'sale_order_not_create'.$days,
360 'NAME' => Loc::getMessage('PRESET_DONT_BUY_NAME', array('%DAYS%' => $days)),
361 'DESC_USER' => Loc::getMessage('PRESET_DONT_BUY_DESC_USER', array('%DAYS%' => $days)),
362 'DESC' => Loc::getMessage('PRESET_DONT_BUY_DESC_' . $days),
363 'TRIGGER' => array(
364 'START' => array(
365 'ENDPOINT' => array(
366 'MODULE_ID' => 'sale',
367 'CODE' => 'dont_buy',
368 'FIELDS' => array('DAYS_DONT_BUY' => $days),
369 'RUN_FOR_OLD_DATA' => ($days > 300 ? 'Y' : 'N')
370 )
371 ),
372 'END' => array(
373 'ENDPOINT' => array(
374 'MODULE_ID' => 'sale',
375 'CODE' => 'order_paid',
376 'FIELDS' => array()
377 )
378 ),
379 ),
380 'CHAIN' => array(
381 array(
382 'TIME_SHIFT' => 0,
383 'SUBJECT' => Loc::getMessage('PRESET_DONT_BUY_LETTER_1_SUBJECT_' . $days),
384 'MESSAGE' => self::getMailTemplate(array(
385 'TITLE' => Loc::getMessage('PRESET_DONT_BUY_LETTER_1_SUBJECT_' . $days),
386 'TEXT' => Loc::getMessage('PRESET_DONT_BUY_LETTER_1_MESSAGE_' . $days, static::getMessagePlaceHolders()),
387 )),
388 ),
389 array(
390 'TIME_SHIFT' => 1440,
391 'SUBJECT' => Loc::getMessage('PRESET_DONT_BUY_LETTER_2_SUBJECT_' . $days),
392 'MESSAGE' => self::getMailTemplate(array(
393 'TITLE' => Loc::getMessage('PRESET_DONT_BUY_LETTER_2_SUBJECT_' . $days),
394 'TEXT' => Loc::getMessage('PRESET_DONT_BUY_LETTER_2_MESSAGE_' . $days, static::getMessagePlaceHolders()),
395 )),
396 ),
397 array(
398 'TIME_SHIFT' => 1440,
399 'SUBJECT' => Loc::getMessage('PRESET_DONT_BUY_LETTER_3_SUBJECT_' . $days),
400 'MESSAGE' => self::getMailTemplate(array(
401 'TITLE' => Loc::getMessage('PRESET_DONT_BUY_LETTER_3_SUBJECT_' . $days),
402 'TEXT' => Loc::getMessage('PRESET_DONT_BUY_LETTER_3_MESSAGE_' . $days, static::getMessagePlaceHolders()),
403 )),
404 ),
405 )
406 );
407
408 foreach ($list['CHAIN'] as $index => $letter)
409 {
410 $letter['TEMPLATE_TYPE'] = Sender\Templates\Type::getCode(Sender\Templates\Type::BASE);
411 $letter['TEMPLATE_ID'] = mb_strtoupper($list['CODE']).'_' . $index;
412 $list['CHAIN'][$index] = $letter;
413 }
414
415 return $list;
416 }
417
424 public static function getDontAuth($days)
425 {
426 $list = array(
427 'TYPE' => Loc::getMessage('PRESET_TYPE_ORDER'),
428 'CODE' => 'sale_user_dontauth',
429 'NAME' => Loc::getMessage('PRESET_DONT_AUTH_NAME'),
430 'DESC_USER' => Loc::getMessage('PRESET_DONT_AUTH_DESC_USER'),
431 'DESC' => Loc::getMessage('PRESET_DONT_AUTH_DESC', array('%DAYS%' => $days)),
432 'TRIGGER' => array(
433 'START' => array(
434 'ENDPOINT' => array(
435 'MODULE_ID' => 'sender',
436 'CODE' => 'user_dontauth',
437 'FIELDS' => array('DAYS_DONT_AUTH' => $days)
438 )
439 ),
440 'END' => array(
441 'ENDPOINT' => array(
442 'MODULE_ID' => 'sender',
443 'CODE' => 'user_auth',
444 'FIELDS' => array()
445 )
446 ),
447 ),
448 'CHAIN' => array(
449 array(
450 'TIME_SHIFT' => 0,
451 'SUBJECT' => Loc::getMessage('PRESET_DONT_AUTH_LETTER_1_SUBJECT'),
452 'MESSAGE' => self::getMailTemplate(array(
453 'TITLE' => Loc::getMessage('PRESET_DONT_AUTH_LETTER_1_SUBJECT'),
454 'TEXT' => Loc::getMessage('PRESET_DONT_AUTH_LETTER_1_MESSAGE', static::getMessagePlaceHolders()),
455 )),
456 ),
457 array(
458 'TIME_SHIFT' => 1440,
459 'SUBJECT' => Loc::getMessage('PRESET_DONT_AUTH_LETTER_2_SUBJECT'),
460 'MESSAGE' => self::getMailTemplate(array(
461 'TITLE' => Loc::getMessage('PRESET_DONT_AUTH_LETTER_2_SUBJECT'),
462 'TEXT' => Loc::getMessage('PRESET_DONT_AUTH_LETTER_2_MESSAGE', static::getMessagePlaceHolders()),
463 )),
464 ),
465 array(
466 'TIME_SHIFT' => 1440,
467 'SUBJECT' => Loc::getMessage('PRESET_DONT_AUTH_LETTER_3_SUBJECT'),
468 'MESSAGE' => self::getMailTemplate(array(
469 'TITLE' => Loc::getMessage('PRESET_DONT_AUTH_LETTER_3_SUBJECT'),
470 'TEXT' => Loc::getMessage('PRESET_DONT_AUTH_LETTER_3_MESSAGE', static::getMessagePlaceHolders()),
471 )),
472 ),
473 array(
474 'TIME_SHIFT' => 1440,
475 'SUBJECT' => Loc::getMessage('PRESET_DONT_AUTH_LETTER_4_SUBJECT'),
476 'MESSAGE' => self::getMailTemplate(array(
477 'TITLE' => Loc::getMessage('PRESET_DONT_AUTH_LETTER_4_SUBJECT'),
478 'TEXT' => Loc::getMessage('PRESET_DONT_AUTH_LETTER_4_MESSAGE', static::getMessagePlaceHolders()),
479 )),
480 ),
481 )
482 );
483
484 foreach ($list['CHAIN'] as $index => $letter)
485 {
486 $letter['TEMPLATE_TYPE'] = Sender\Templates\Type::getCode(Sender\Templates\Type::BASE);
487 $letter['TEMPLATE_ID'] = mb_strtoupper($list['CODE']).'_' . $index;
488 $list['CHAIN'][$index] = $letter;
489 }
490
491 return $list;
492 }
493}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29