- Модуль: catalog
- Путь к файлу: ~/bitrix/modules/catalog/lib/catalogviewedproduct.php
- Класс: BitrixCatalogCatalogViewedProductTable
- Вызов: CatalogViewedProductTable::truncateUserViewedProducts
static function truncateUserViewedProducts($fuserId, $siteId)
{
$fuserId = (int)$fuserId;
$siteId = (string)$siteId;
if ($fuserId <= 0 || $siteId == '')
return;
$maxCount = (int)MainConfigOption::get('catalog', 'viewed_count');
if ($maxCount <= 0)
return;
$iterator = self::getList(array(
'select' => array('DATE_VISIT', 'FUSER_ID', 'SITE_ID'),
'filter' => array('=FUSER_ID' => $fuserId, '=SITE_ID' => $siteId),
'order' => array('FUSER_ID' => 'ASC', 'SITE_ID' => 'ASC', 'DATE_VISIT' => 'DESC'),
'limit' => 1,
'offset' => $maxCount
));
$row = $iterator->fetch();
unset($iterator);
if (!empty($row) && $row['DATE_VISIT'] instanceof MainTypeDateTime)
{
$connection = Application::getConnection();
$helper = $connection->getSqlHelper();
$query = 'delete from '.$helper->quote(self::getTableName()).
' where '.$helper->quote('FUSER_ID').' = '.$fuserId.
' and '.$helper->quote('SITE_ID').' = ''.$helper->forSql($siteId).'''.
' and '.$helper->quote('DATE_VISIT').' <= '.$helper->convertToDbDateTime($row['DATE_VISIT']);
$connection->query($query);
unset($query, $helper, $connection);
}
unset($row);
}