• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/lib/component/base.php
  • Класс: BitrixIblockComponentBase
  • Вызов: Base::getMostViewedRecommendation
protected function getMostViewedRecommendation($ids)
{
	$mostViewed = array();
	$recommendationId = 'mostviewed';

	$result = CatalogCatalogViewedProductTable::getList(array(
		'select' => array(
			'ELEMENT_ID',
			new MainEntityExpressionField('SUM_HITS', 'SUM(%s)', 'VIEW_COUNT')
		),
		'filter' => array(
			'=SITE_ID' => $this->getSiteId(),
			'>ELEMENT_ID' => 0,
			'>DATE_VISIT' => new MainTypeDateTime(date('Y-m-d H:i:s', strtotime('-30 days')), 'Y-m-d H:i:s')
		),
		'order' => array('SUM_HITS' => 'DESC'),
		'limit' => $this->arParams['PAGE_ELEMENT_COUNT'] * 10
	));
	while ($row = $result->fetch())
	{
		$mostViewed[] = $row['ELEMENT_ID'];
	}
	unset($row, $result);

	$mostViewed = $this->filterByParams($mostViewed, $this->arParams['FILTER_IDS']);

	foreach ($mostViewed as $id)
	{
		if (!isset($this->recommendationIdToProduct[$id]))
		{
			$this->recommendationIdToProduct[$id] = $recommendationId;
		}
	}

	return array_unique(array_merge($ids, $mostViewed));
}