1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
store_utility.php
См. документацию.
1<?php
2IncludeModuleLangFile(__DIR__.'\\store_docs.php');
3
5{
6 protected static $storeNames = array();
7
12 public static function getStoreName($storeId): string
13 {
14 $storeId = (int)$storeId;
15 if ($storeId <= 0)
16 return '';
17
18 if (!isset(self::$storeNames[$storeId]))
19 {
20 $storeIterator = CCatalogStore::GetList(
21 array(),
22 array('ID' => $storeId),
23 false,
24 false,
25 array('ID', 'ADDRESS', 'TITLE')
26 );
27 $storeName = '';
28 if ($store = $storeIterator->Fetch())
29 {
30 $store['ID'] = (int)$store['ID'];
31 $store['ADDRESS'] = (string)$store['ADDRESS'];
32 $store['TITLE'] = (string)$store['TITLE'];
33 $storeName = ($store['TITLE'] !== '' ? $store['TITLE'].' ('.$store['ADDRESS'].')' : $store['ADDRESS']);
34 }
35 unset($store, $storeIterator);
36 self::$storeNames[$storeId] = $storeName;
37 }
38 else
39 {
40 $storeName = self::$storeNames[$storeId];
41 }
42
43 return $storeName;
44 }
45
50 public static function getProductInfo($elementId)
51 {
52 $elementId = (int)$elementId;
53 if($elementId <= 0)
54 return '';
55
56 $dbProduct = CIBlockElement::GetList(
57 array(),
58 array("ID" => $elementId),
59 false,
60 false,
61 array('ID', 'IBLOCK_ID', 'IBLOCK_SECTION_ID', 'DETAIL_PICTURE', 'PREVIEW_PICTURE', 'NAME', 'XML_ID')
62 );
63 $arProduct = $dbProduct->GetNext();
64 unset($dbProduct);
65 if (empty($arProduct))
66 {
67 return '';
68 }
69
70 if($arProduct["IBLOCK_ID"] > 0)
71 {
72 $arProduct["EDIT_PAGE_URL"] = CIBlock::GetAdminElementEditLink(
73 $arProduct["IBLOCK_ID"],
74 $elementId,
75 ["find_section_section" => $arProduct["IBLOCK_SECTION_ID"]]
76 );
77 }
78
79 $imgCode = "";
80 if($arProduct["DETAIL_PICTURE"] > 0)
81 {
82 $imgCode = $arProduct["DETAIL_PICTURE"];
83 }
84 elseif($arProduct["PREVIEW_PICTURE"] > 0)
85 {
86 $imgCode = $arProduct["PREVIEW_PICTURE"];
87 }
88
89 if ($imgCode > 0)
90 {
91 $arFile = CFile::GetFileArray($imgCode);
92 $arImgProduct = CFile::ResizeImageGet($arFile, array('width' => 80, 'height' => 80), BX_RESIZE_IMAGE_PROPORTIONAL, false, false);
93 $arProduct["IMG_URL"] = $arImgProduct['src'];
94 }
95
96 return $arProduct;
97 }
98
103 public static function getFields(string $docType): ?array
104 {
105 if($docType !== '' && isset(CCatalogDocs::$types[$docType]))
106 {
108 $documentClass = CCatalogDocs::$types[$docType];
109 return $documentClass::getFields();
110 }
111 return null;
112 }
113
114 public static function getTypeFields(string $docType): ?array
115 {
116 if ($docType !== '' && isset(CCatalogDocs::$types[$docType]))
117 {
119 $documentClass = CCatalogDocs::$types[$docType];
120
121 return [
122 'DOCUMENT' => $documentClass::getDocumentFields(),
123 'ELEMENT' => $documentClass::getElementFields(),
124 ];
125 }
126
127 return null;
128 }
129
135 public static function showErrorProduct($arProduct, $numberDisplayedElements = 10): string
136 {
137 $strError = '';
138 $numberDisplayedElements = intval($numberDisplayedElements);
139 if($numberDisplayedElements < 1)
140 $numberDisplayedElements = 1;
141 if(is_array($arProduct))
142 {
143 foreach($arProduct as $key => $product)
144 {
145 $strError .= "\n- ".$product;
146 if($key >= ($numberDisplayedElements - 1))
147 {
148 $strError .= "\n...".GetMessage("CAT_DOC_AND_MORE", array("#COUNT#" => (count($arProduct) - $numberDisplayedElements)));
149 break;
150 }
151 }
152 }
153 return $strError;
154 }
155
156 public static function getQuantityInformation($productId)
157 {
158 global $DB;
159
160 return $DB->Query("SELECT SUM(SP.AMOUNT) as SUM, CP.QUANTITY_RESERVED as RESERVED FROM b_catalog_store_product SP INNER JOIN b_catalog_product CP ON SP.PRODUCT_ID = CP.ID INNER JOIN b_catalog_store CS ON SP.STORE_ID = CS.ID WHERE SP.PRODUCT_ID = ".$productId." AND CS.ACTIVE = 'Y' GROUP BY QUANTITY_RESERVED ", true);
161 }
162
163 public static function clearStoreName($storeId)
164 {
165 $storeId = (int)$storeId;
166 if ($storeId > 0)
167 {
168 if (isset(self::$storeNames[$storeId]))
169 unset(self::$storeNames[$storeId]);
170 }
171 }
172
173 public static function clearAllStoreNames()
174 {
175 self::$storeNames = array();
176 }
177
178 public static function loadAllStoreNames($active = true)
179 {
180 $active = ($active === true);
181 self::$storeNames = array();
182 $filter = ($active ? array('ACTIVE' => 'Y') : array());
183 $storeIterator = CCatalogStore::GetList(
184 array(),
185 $filter,
186 false,
187 false,
188 array('ID', 'ADDRESS', 'TITLE')
189 );
190 while ($store = $storeIterator->Fetch())
191 {
192 $store['ID'] = (int)$store['ID'];
193 $store['ADDRESS'] = (string)$store['ADDRESS'];
194 $store['TITLE'] = (string)$store['TITLE'];
195 self::$storeNames[$store['ID']] = ($store['TITLE'] !== '' ? $store['TITLE'].' ('.$store['ADDRESS'].')' : $store['ADDRESS']);
196 }
197 unset($store, $storeIterator, $filter);
198 }
199
207 public static function getMultipleFilesFromPost(\Bitrix\Main\HttpRequest $request, array $fieldList): ?array
208 {
209 if (empty($fieldList))
210 {
211 return null;
212 }
213
214 $result = [];
215 $requestFields = $request->getPostList();
216 foreach ($fieldList as $fieldId)
217 {
218 if (!is_string($fieldId) || $fieldId === '')
219 {
220 continue;
221 }
222 if (isset($requestFields[$fieldId]) && is_array($requestFields[$fieldId]))
223 {
224 foreach ($requestFields[$fieldId] as $rowId => $value)
225 {
226 $fileRow = [];
227 $parsed = [];
228 if (preg_match('/^[0-9]+$/', $rowId, $parsed))
229 {
230 $fileRow = [
231 'ID' => (int)$rowId,
232 ];
233 }
234 elseif (preg_match('/^n[0-9]+$/', $rowId, $parsed))
235 {
236 $fileRow = [
237 'ID' => null,
238 ];
239 }
240
241 if (empty($fileRow))
242 {
243 continue;
244 }
245
246 if (is_array($value))
247 {
248 $fileRow['FILE_UPLOAD'] = \CIBlock::makeFileArray(
249 $value
250 );
251 }
252 elseif (is_string($value))
253 {
254 if (preg_match('/^[0-9]+$/', $value, $parsed))
255 {
256 $fileRow['FILE_ID'] = (int)$value;
257 }
258 else
259 {
260 continue;
261 }
262 }
263 else
264 {
265 continue;
266 }
267
268 if (!isset($result[$fieldId]))
269 {
270 $result[$fieldId] = [];
271 }
272 $result[$fieldId][$rowId] = $fileRow;
273 }
274 }
275
276 $deleteFieldId = $fieldId . '_del';
277 if (isset($requestFields[$deleteFieldId]) && is_array($requestFields[$deleteFieldId]))
278 {
279 foreach ($requestFields[$deleteFieldId] as $rowId => $value)
280 {
281 if ($value !== 'Y')
282 {
283 continue;
284 }
285 $parsed = [];
286 if (!preg_match('/^[0-9]+$/', $rowId, $parsed))
287 {
288 continue;
289 }
290 $rowId = (int)$rowId;
291 if (!isset($result[$fieldId]))
292 {
293 $result[$fieldId] = [];
294 }
295 if (
296 isset($result[$fieldId][$rowId])
297 && isset($result[$fieldId][$rowId]['FILE_ID'])
298 )
299 {
300 $result[$fieldId][$rowId]['DEL'] = $value;
301 }
302 else
303 {
304 $result[$fieldId][$rowId] = [
305 'DEL' => $value,
306 ];
307 }
308 }
309 }
310 }
311
312 return (!empty($result) ? $result : null);
313 }
314
322 public static function getFilesFromPost(\Bitrix\Main\HttpRequest $request, array $fieldList): ?array
323 {
324 if (empty($fieldList))
325 {
326 return null;
327 }
328
329 $result = [];
330 $requestFields = $request->getPostList();
331 foreach ($fieldList as $fieldId)
332 {
333 if (!is_string($fieldId) || $fieldId === '')
334 {
335 continue;
336 }
337 if (isset($requestFields[$fieldId]))
338 {
339 $value = $requestFields[$fieldId];
340
341 $fileRow = [];
342 if (is_array($value))
343 {
344 $fileRow['FILE_UPLOAD'] = \CIBlock::makeFileArray(
345 $value
346 );
347 }
348 elseif (is_string($value))
349 {
350 $parsed = [];
351 if (preg_match('/^[0-9]+$/', $value, $parsed))
352 {
353 $fileRow['FILE_ID'] = (int)$value;
354 }
355 }
356
357 if (!empty($fileRow))
358 {
359 $result[$fieldId] = $fileRow;
360 }
361 }
362
363 $deleteFieldId = $fieldId . '_del';
364 if (isset($requestFields[$deleteFieldId]) && $requestFields[$deleteFieldId] === 'Y')
365 {
366 if (isset($result[$fieldId]) && isset($result[$fieldId]['FILE_ID']))
367 {
368 $result[$fieldId]['DEL'] = 'Y';
369 }
370 else
371 {
372 $result[$fieldId] = [
373 'DEL' => 'Y',
374 ];
375 }
376 }
377 }
378
379 return (!empty($result) ? $result : null);
380 }
381
382 public static function isAllowShowShippingCenter(): bool
383 {
384 if (\Bitrix\Main\ModuleManager::isModuleInstalled('crm'))
385 {
386 return false;
387 }
388
389 return \Bitrix\Main\Config\Option::get('catalog', 'show_store_shipping_center') === 'Y';
390 }
391}
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
static $types
Определения store_docs.php:15
static getProductInfo($elementId)
Определения store_utility.php:50
static getStoreName($storeId)
Определения store_utility.php:12
static getFilesFromPost(\Bitrix\Main\HttpRequest $request, array $fieldList)
Определения store_utility.php:322
static getMultipleFilesFromPost(\Bitrix\Main\HttpRequest $request, array $fieldList)
Определения store_utility.php:207
static clearAllStoreNames()
Определения store_utility.php:173
static showErrorProduct($arProduct, $numberDisplayedElements=10)
Определения store_utility.php:135
static loadAllStoreNames($active=true)
Определения store_utility.php:178
static isAllowShowShippingCenter()
Определения store_utility.php:382
static $storeNames
Определения store_utility.php:6
static getQuantityInformation($productId)
Определения store_utility.php:156
static clearStoreName($storeId)
Определения store_utility.php:163
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$filter
Определения iblock_catalog_list.php:54
$strError
Определения options_user_settings.php:4
global $DB
Определения cron_frame.php:29
const BX_RESIZE_IMAGE_PROPORTIONAL
Определения constants.php:11
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936