Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
accountnumbercompatibilitymanager.php
1<?php
3
5use Bitrix\Main\Entity\Event;
6use Bitrix\Main\Entity\EventResult;
11
17{
26 public static function onBuildNumeratorTemplateWordsList(\Bitrix\Main\Event $event)
27 {
28 $parameters = [];
29 if ($event->getParameter('numeratorType') === Registry::REGISTRY_TYPE_ORDER)
30 {
31 $event = new \Bitrix\Main\Event('sale', 'OnBuildAccountNumberTemplateList', []);
32 $event->send();
33
34 if ($event->getResults())
35 {
37 foreach ($event->getResults() as $eventResult)
38 {
39 $parameters[] = $eventResult->getParameters();
40 }
41 }
42 return $parameters;
43 }
44 return $parameters;
45 }
46
52 public static function resetAccountNumberType(Event $event)
53 {
54 Option::set("sale", "account_number_template", '');
55 return new EventResult();
56 }
57
66 public static function updateAccountNumberType(Event $event)
67 {
68 $result = new EventResult();
69 $numeratorFields = $event->getParameter("fields");
70 if ($numeratorFields['TYPE'] === Registry::REGISTRY_TYPE_ORDER)
71 {
72 $numberTemplate = isset($numeratorFields['TEMPLATE']) ? $numeratorFields['TEMPLATE'] : '';
73 $settings = Json::decode($numeratorFields['SETTINGS']);
74 if ($numberTemplate)
75 {
76 $type = '';
77 switch ($numberTemplate)
78 {
79 case '{NUMBER}':
80 $settingsSequent = $settings[SequentNumberGenerator::getType()];
81 if (isset($settingsSequent['step']) && ($settingsSequent['step'] == 1)
82 &&
83 key_exists('periodicBy', $settingsSequent) && ($settingsSequent['periodicBy'] == null)
84 )
85 {
86 $type = 'NUMBER';
87 }
88 break;
89 case '{PREFIX}{ORDER_ID}':
90 $type = 'PREFIX';
91 break;
92 case '{RANDOM}':
93 $type = 'RANDOM';
94 break;
95 case '{USER_ID_ORDERS_COUNT}':
96 $type = 'USER';
97 break;
98 case '{DAY}{MONTH}{YEAR} / {NUMBER}':
99 $settingsSequent = $settings[SequentNumberGenerator::getType()];
100 if (isset($settingsSequent['step']) && $settingsSequent['step'] == 1
101 &&
102 key_exists('periodicBy', $settingsSequent) && $settingsSequent['periodicBy'] == SequentNumberGenerator::DAY
103 )
104 {
105 $type = 'DATE';
106 }
107 break;
108 case '{MONTH}{YEAR} / {NUMBER}':
109 $settingsSequent = $settings[SequentNumberGenerator::getType()];
110 if (isset($settingsSequent['step']) && $settingsSequent['step'] == 1
111 &&
112 key_exists('periodicBy', $settingsSequent) && $settingsSequent['periodicBy'] == SequentNumberGenerator::MONTH
113 )
114 {
115 $type = 'DATE';
116 }
117 break;
118 case '{YEAR} / {NUMBER}':
119 $settingsSequent = $settings[SequentNumberGenerator::getType()];
120 if (isset($settingsSequent['step']) && $settingsSequent['step'] == 1
121 &&
122 key_exists('periodicBy', $settingsSequent) && $settingsSequent['periodicBy'] == SequentNumberGenerator::YEAR
123 )
124 {
125 $type = 'DATE';
126 }
127 break;
128 default:
129 if (!$type)
130 {
131 // check if template is a custom type - it should contain only custom word
132 $isStartIsUserDefinedPattern = strncmp($numberTemplate, NumberGenerator::USER_DEFINED_SYMBOL_START, mb_strlen(NumberGenerator::USER_DEFINED_SYMBOL_START)) === 0;
133 $isEndIsUserDefinedPattern = mb_substr($numberTemplate, -mb_strlen(NumberGenerator::USER_DEFINED_SYMBOL_END)) === NumberGenerator::USER_DEFINED_SYMBOL_END;
134 if ($isStartIsUserDefinedPattern && $isEndIsUserDefinedPattern)
135 {
136 $type = mb_substr(mb_substr($numberTemplate, mb_strlen(NumberGenerator::USER_DEFINED_SYMBOL_START)), 0, -mb_strlen(NumberGenerator::USER_DEFINED_SYMBOL_END));
137 }
138 }
139 break;
140 }
141
142 Option::set("sale", "account_number_template", $type);
143 }
144 }
145
146 return $result;
147 }
148}