// PROMOBILE_STOCK_INDEXNOW_V1: observe successful changes; never write stock or prices. if (!class_exists('PromobileStockIndexNow', false)) { class PromobileStockIndexNow { private static $before = array(); public static function beforeUpdate($event) { $id = (int)$event->getParameter('id'); unset(self::$before[$id]); $fields = $event->getParameter('fields'); if ($id <= 0 || !is_array($fields) || (!array_key_exists('QUANTITY', $fields) && !array_key_exists('AVAILABLE', $fields))) return; try { $row = \Bitrix\Catalog\ProductTable::getList(array( 'select' => array('ID', 'QUANTITY', 'AVAILABLE'), 'filter' => array('=ID' => $id), 'limit' => 1, ))->fetch(); if ($row) self::$before[$id] = $row; } catch (\Throwable $error) { // Observability must not change the outcome of the stock transaction. error_log('[PROMOBILE_STOCK_INDEXNOW] before_read_failed'); } } public static function afterUpdate($event) { $id = (int)$event->getParameter('id'); if ($id <= 0 || !isset(self::$before[$id])) return; $before = self::$before[$id]; unset(self::$before[$id]); if ($event->getParameter('success') !== true) return; try { $after = \Bitrix\Catalog\ProductTable::getList(array( 'select' => array('ID', 'QUANTITY', 'AVAILABLE'), 'filter' => array('=ID' => $id), 'limit' => 1, ))->fetch(); if (!$after || ((float)$before['QUANTITY'] === (float)$after['QUANTITY'] && (string)$before['AVAILABLE'] === (string)$after['AVAILABLE'])) return; if (!\Bitrix\Main\Loader::includeModule('iblock') || !\Bitrix\Main\Loader::includeModule('vayti.reindex')) return; if (\Bitrix\Main\Config\Option::get('vayti.reindex', 'is_yandex_active') !== 'Y') return; $item = \CIBlockElement::GetList(array(), array('ID' => $id, 'ACTIVE' => 'Y'), false, false, array('ID', 'IBLOCK_ID', 'DETAIL_PAGE_URL', 'ACTIVE'))->GetNext(); if (!$item) return; if ((int)$item['IBLOCK_ID'] !== 26) { $parent = \CCatalogSku::GetProductInfo($id, (int)$item['IBLOCK_ID']); if (!$parent || (int)$parent['IBLOCK_ID'] !== 26) return; $item = \CIBlockElement::GetList(array(), array('ID' => (int)$parent['ID'], 'IBLOCK_ID' => 26, 'ACTIVE' => 'Y'), false, false, array('ID', 'IBLOCK_ID', 'DETAIL_PAGE_URL', 'ACTIVE'))->GetNext(); } if (!$item || (int)$item['IBLOCK_ID'] !== 26 || $item['ACTIVE'] !== 'Y') return; $path = html_entity_decode((string)$item['DETAIL_PAGE_URL'], ENT_QUOTES, 'UTF-8'); if (strpos($path, '/catalog/') !== 0 || substr($path, -1) !== '/' || strpbrk($path, '?#') !== false) return; \Vayti\Indexing\Indexnow::addLinksToQueue(array('https://promobile.pro'.$path), 'PROMOBILE_StockChanged'); } catch (\Throwable $error) { error_log('[PROMOBILE_STOCK_INDEXNOW] queue_failed'); } } } \Bitrix\Main\EventManager::getInstance()->addEventHandler('catalog', 'Bitrix\\Catalog\\Model\\Product::OnBeforeUpdate', array('PromobileStockIndexNow', 'beforeUpdate')); \Bitrix\Main\EventManager::getInstance()->addEventHandler('catalog', 'Bitrix\\Catalog\\Model\\Product::OnAfterUpdate', array('PromobileStockIndexNow', 'afterUpdate')); }
[RuntimeException] 
Could not start session because headers have already been sent. "/home/users/j/j2738487/domains/promobile.pro/local/php_interface/init.php":1458. (0)
/home/users/j/j2738487/domains/promobile.pro/bitrix/modules/main/lib/Session/Session.php:143
#0: Bitrix\Main\Session\Session->start
	/home/users/j/j2738487/domains/promobile.pro/bitrix/modules/main/lib/Session/KernelSessionProxy.php:47
#1: Bitrix\Main\Session\KernelSessionProxy->start
	/home/users/j/j2738487/domains/promobile.pro/bitrix/modules/main/include.php:151
#2: require_once(string)
	/home/users/j/j2738487/domains/promobile.pro/bitrix/modules/main/include/prolog_before.php:19
#3: require_once(string)
	/home/users/j/j2738487/domains/promobile.pro/bitrix/modules/main/include/prolog.php:10
#4: require_once(string)
	/home/users/j/j2738487/domains/promobile.pro/bitrix/header.php:2
#5: require(string)
	/home/users/j/j2738487/domains/promobile.pro/catalog/index.php:2
#6: include_once(string)
	/home/users/j/j2738487/domains/promobile.pro/bitrix/modules/main/include/urlrewrite.php:128
#7: include_once(string)
	/home/users/j/j2738487/domains/promobile.pro/bitrix/urlrewrite.php:2
----------