Skip to content

Instantly share code, notes, and snippets.

@yandexmarketforbitrix
Created September 30, 2022 06:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yandexmarketforbitrix/4cefb9495bd27c03a122fd1aa42c0668 to your computer and use it in GitHub Desktop.
Save yandexmarketforbitrix/4cefb9495bd27c03a122fd1aa42c0668 to your computer and use it in GitHub Desktop.
Обновление прайс-листа на cron
  • Разместите скрипт в директории bitrix/php_interface/include;
  • Добавьте cron-задание с периодичностью (например, 1 раз в час) в качестве аргумента укажите ид прайс-листа.

Пример задания: 0 * * * * /usr/bin/php -f /home/bitrix/www/bitrix/php_interface/include/market_export.php 9

<?php
define('BX_CRONTAB', true);
define('NO_AGENT_CHECK', true);
define('NO_AGENT_STATISTIC', true);
define('NOT_CHECK_PERMISSIONS', true);
define('DisableEventsCheck', true);
$_SERVER['DOCUMENT_ROOT'] = realpath(__DIR__ . '/../../../');
require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php';
use Bitrix\Main;
use Yandex\Market;
set_time_limit(600);
Main\Loader::includeModule('yandex.market');
$setupId = (int)$_SERVER['argv'][1];
$setup = Market\Export\Setup\Model::loadById($setupId);
$processor = new Market\Export\Run\Processor($setup, [
'timeLimit' => 600,
'initTime' => new Main\Type\DateTime(),
'usePublic' => $setup->isAutoUpdate(),
]);
$processResult = $processor->run($setup->isAutoUpdate() ? 'refresh' : 'full');
if (!$processResult->isFinished())
{
if ($processResult->isSuccess())
{
throw new Main\SystemException('resources expired');
}
else
{
$message = implode(PHP_EOL, $processResult->getErrorMessages());
throw new Main\SystemException($message);
}
}
require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/epilog_after.php';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment