21 $currentUserId =
false;
24 $currentUserId = (int)
$USER->GetID();
25 if ($currentUserId <= 0)
27 $currentUserId =
false;
36 'LOCATION_ID' =>
false,
37 'ISSUING_CENTER' =>
'N',
38 'SHIPPING_CENTER' =>
'N',
48 'DESCRIPTION' =>
true,
52 'LOCATION_ID' =>
true,
54 'MODIFIED_BY' =>
true,
60 'ISSUING_CENTER' =>
true,
61 'SHIPPING_CENTER' =>
true,
73 'DESCRIPTION' =>
true,
77 'LOCATION_ID' =>
true,
78 'MODIFIED_BY' =>
true,
84 'ISSUING_CENTER' =>
true,
85 'SHIPPING_CENTER' =>
true,
107 if (array_key_exists(
'IMAGE_ID',
$arFields))
109 self::prepareImage(
$arFields,
'IMAGE_ID');
140 private static function prepareImage(
array &
$fields, $fieldName): void
144 ||
$fields[$fieldName] ===
'null'
146 ||
$fields[$fieldName] ===
false
164 self::prepareImageArray(
$fields, $fieldName);
172 private static function prepareImageArray(
array &
$fields, $fieldName): void
174 if (empty(
$fields[$fieldName]))
181 if (!isset(
$fields[$fieldName][
'name']) && !isset(
$fields[$fieldName][
'del']))
188 $fields[$fieldName][
'MODULE_ID'] =
'catalog';
198 $store = Catalog\StoreTable::getRow([
213 if ($store[
'IMAGE_ID'] !==
null)
215 $store[
'IMAGE_ID'] = (int)$store[
'IMAGE_ID'];
216 if ($store[
'IMAGE_ID'] <= 0)
218 $store[
'IMAGE_ID'] =
null;
222 foreach (
GetModuleEvents(
"catalog",
"OnBeforeCatalogStoreUpdate",
true) as $arEvent)
228 if (!self::CheckFields(
'UPDATE',
$arFields))
235 $arFields[
'IMAGE_ID'][
'old_file'] = $store[
'IMAGE_ID'];
236 CFile::SaveForDB(
$arFields,
'IMAGE_ID',
'catalog');
238 elseif ($store[
'IMAGE_ID'] !==
null)
240 CFile::Delete($store[
'IMAGE_ID']);
243 $strUpdate =
$DB->PrepareUpdate(
"b_catalog_store",
$arFields);
245 $bNeedConversion =
false;
246 if (!empty($strUpdate))
250 $bNeedConversion = ($store[
'ACTIVE'] !==
$arFields[
'ACTIVE']);
253 $strSql =
"update b_catalog_store set ".$strUpdate.
" where ID = ".$id;
254 if(!
$DB->Query($strSql))
258 Catalog\StoreTable::cleanCache();
266 foreach(
GetModuleEvents(
"catalog",
"OnCatalogStoreUpdate",
true) as $arEvent)
278 $store = Catalog\StoreTable::getRow([
292 if ($store[
'IMAGE_ID'] !==
null)
294 $store[
'IMAGE_ID'] = (int)$store[
'IMAGE_ID'];
295 if ($store[
'IMAGE_ID'] <= 0)
297 $store[
'IMAGE_ID'] =
null;
301 foreach (
GetModuleEvents(
"catalog",
"OnBeforeCatalogStoreDelete",
true) as $arEvent)
307 $dbDocs =
$DB->Query(
"select ID from b_catalog_docs_element where STORE_FROM = ".$id.
" or STORE_TO = ".$id,
true);
308 if($bStoreHaveDocs = $dbDocs->Fetch())
314 $DB->Query(
"delete from b_catalog_store_product where STORE_ID = ".$id,
true);
315 $DB->Query(
"delete from b_catalog_store where ID = ".$id,
true);
316 if ($store[
'IMAGE_ID'] !==
null)
318 CFile::Delete($store[
'IMAGE_ID']);
323 Catalog\StoreTable::cleanCache();
325 foreach(
GetModuleEvents(
"catalog",
"OnCatalogStoreDelete",
true) as $arEvent)
350 $store = Catalog\StoreTable::getList([
352 'filter' => [
'=ID' => $storeId],
370 'select' => [
'ID',
'PRODUCT_ID'],
373 '=STORE_ID' => $storeId,
376 'order' => [
'ID' =>
'ASC'],
379 while ($row = $storeProductList->fetch())
382 $startId = (int)$row[
'ID'];
383 $productIds[] = (int)$row[
'PRODUCT_ID'];
386 if (!empty($productIds))
391 self::recalculateProductsBalancesInternal($productIds, $iblockIds);
398 if (!empty($iblockIds))
400 foreach ($iblockIds as
$iblock)
423 self::recalculateProductsBalancesInternal($productIds, $iblockIds);
429 if (!empty($iblockIds))
431 foreach ($iblockIds as
$iblock)
440 private static function recalculateProductsBalancesInternal(
array $productIds,
array &$iblockIds): void
442 if (empty($productIds))
448 $foundedProductIds = [];
450 $productsList = Catalog\Model\Product::getList([
454 'IBLOCK_ID' =>
'IBLOCK_ELEMENT.IBLOCK_ID',
456 'filter' => [
'@ID' => $productIds],
457 'order' => [
'ID' =>
'ASC'],
459 while ($row = $productsList->fetch())
461 if ($row[
'IBLOCK_ID'] ===
null)
466 $id = (int)$row[
'ID'];
471 'QUANTITY_RESERVED' => (float)$row[
'QUANTITY_RESERVED'],
474 $foundedProductIds[] = $id;
476 unset($row, $productsList);
478 if (empty($products))
483 $storeProductQuantityList = Main\Application::getConnection()->query(
"
485 SUM(CSP.AMOUNT) AS PRODUCT_QUANTITY,
487 FROM b_catalog_store_product CSP
488 INNER JOIN b_catalog_store CS ON CS.ID = CSP.STORE_ID
490 CSP.PRODUCT_ID IN (" . implode(
',', $foundedProductIds) .
")
492 GROUP BY CSP.PRODUCT_ID
494 while ($row = $storeProductQuantityList->fetch())
498 Catalog\Model\Product::update(
502 'QUANTITY' => (
float)$row[
'PRODUCT_QUANTITY'] - $products[$productId][
'QUANTITY_RESERVED'],
504 'external_fields' => [
505 'IBLOCK_ID' => $products[$productId][
'IBLOCK_ID'],
510 unset($products[$productId]);
512 unset($row, $storeProductQuantityList);
513 unset($foundedProductIds);
515 if (!empty($products))
517 foreach ($products as $rowId => $rowData)
519 Catalog\Model\Product::update(
523 'QUANTITY' => ($rowData[
'QUANTITY_RESERVED'] != 0 ? -$rowData[
'QUANTITY_RESERVED'] : 0),
525 'external_fields' => [
526 'IBLOCK_ID' => $rowData[
'IBLOCK_ID'],
533 Catalog\Model\Product::clearCache();
static enableDeferredCalculation()
static disableDeferredCalculation()
static disableDeferredIndexing()
static runDeferredIndexing($iblockId)
static enableDeferredIndexing()
static getList(array $parameters=array())
static normalizeArrayValuesByInt(&$map, $sorted=true)
static recalculateProductsBalances(array $productIds)
static recalculateStoreBalances(int $storeId)
static CheckFields($action, &$arFields)
static Update($id, $arFields)
static clearStoreName($storeId)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
global $USER_FIELD_MANAGER
if(! $catalogEdit->isSuccess()) $iblock
ExecuteModuleEventEx($arEvent, $arParams=[])
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
GetMessage($name, $aReplace=null)
$GLOBALS['____1690880296']
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)