Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
orderuserordersnumbergenerator.php
1<?php
3
4use Bitrix\Main\Entity\ExpressionField;
11
17{
18 protected $orderId;
19
20 const TEMPLATE_WORD_USER_ID_ORDERS_COUNT = "USER_ID_ORDERS_COUNT";
21
23 public static function getTemplateWordsForParse()
24 {
25 return [
26 static::getPatternFor(static::TEMPLATE_WORD_USER_ID_ORDERS_COUNT),
27 ];
28 }
29
31 public static function getTemplateWordsSettings()
32 {
33 return [
34 static::getPatternFor(static::TEMPLATE_WORD_USER_ID_ORDERS_COUNT)
35 => Loc::getMessage('BITRIX_SALE_INTEGRATION_NUMERATOR_ORDERUSERORDERSNUMBERGENERATOR_WORD_USER_ID_ORDERS_COUNT'),
36 ];
37 }
38
42 public static function getAvailableForType()
43 {
45 }
46
50 protected function getTableName()
51 {
52 return OrderTable::class;
53 }
54
56 public function parseTemplate($template)
57 {
58 $tableName = $this->getTableName();
60 $userIdOfOrder = $tableName::query()
61 ->addSelect('USER_ID')
62 ->where('ID', $this->orderId)
63 ->exec()
64 ->fetch();
65
66 if ($userIdOfOrder)
67 {
68 $userIdOfOrder = intval($userIdOfOrder['USER_ID']);
69 $countArchiveOrderOfUser = OrderArchiveTable::query()
70 ->addSelect('ORDERS_COUNT')
71 ->registerRuntimeField(
72 new ExpressionField(
73 'ORDERS_COUNT',
74 'COUNT(ID)'
75 )
76 )
77 ->where('USER_ID', $userIdOfOrder)
78 ->addGroup('USER_ID')
79 ->exec()
80 ->fetch();
81 $countArchiveOrderOfUser = (int)$countArchiveOrderOfUser['ORDERS_COUNT'];
82
83 $countOrderOfUser = $tableName::query()
84 ->addSelect('ORDERS_COUNT')
85 ->registerRuntimeField(
86 new ExpressionField(
87 'ORDERS_COUNT',
88 'COUNT(ID)'
89 )
90 )
91 ->where('USER_ID', $userIdOfOrder)
92 ->addGroup('USER_ID')
93 ->exec()
94 ->fetch();
95
96 $countOrderOfUser = (int)$countOrderOfUser['ORDERS_COUNT'] + $countArchiveOrderOfUser;
97 $numID = ($countOrderOfUser > 0) ? $countOrderOfUser : 1;
98 $value = $userIdOfOrder . "_" . $numID;
99 }
100 else
101 {
102 $value = '';
103 }
104
105 return str_replace($this->getWordToReplace(), $value, $template);
106 }
107
111 public function setDynamicConfig($config)
112 {
113 if (is_array($config) && array_key_exists('ORDER_ID', $config))
114 {
115 $this->orderId = $config['ORDER_ID'];
116 }
117 }
118
122 protected function getWordToReplace()
123 {
124 return self::getPatternFor(self::TEMPLATE_WORD_USER_ID_ORDERS_COUNT);
125 }
126}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29