• Модуль: seo
  • Путь к файлу: ~/bitrix/modules/seo/lib/analytics/services/accountyandex.php
  • Класс: BitrixSeoAnalyticsServicesAccountYandex
  • Вызов: AccountYandex::getCurrency
protected function getCurrency()
{
	if($this->currency)
	{
		return $this->currency;
	}
	// currency is global for an account, so we get it from the first campaign.
	$cacheString = 'analytics_yandex_currency';
	$cachePath = '/seo/analytics/yandex/';
	$cacheTime = 3600;
	$cache = Cache::createInstance();
	$currency = null;
	if($cache->initCache($cacheTime, $cacheString, $cachePath))
	{
		$currency = $cache->getVars()['currency'];
	}
	if(!$currency)
	{
		$cache->clean($cacheString, $cachePath);
		$cache->startDataCache($cacheTime);

		$response = $this->getClient()->post(
			$this->getYandexServerAdress() . 'campaigns',
			Json::encode([
				'method' => 'get',
				'params' => [
					'SelectionCriteria' => new stdClass(),
					'FieldNames' => ['Currency'],
					'Page' => [
						'Limit' => 1,
					],
				],
			])
		);
		if($response)
		{
			$response = Json::decode($response);
			if(!isset($response['error']) && isset($response['result']) && isset($response['result']['Campaigns']))
			{
				foreach($response['result']['Campaigns'] as $campaign)
				{
					$currency = $campaign['Currency'];
					break;
				}
			}
		}

		if($currency)
		{
			$cache->endDataCache(['currency' => $currency]);
		}
	}

	$this->currency = $currency;

	return $currency;
}