Битрикс — просмотренные товары на API

Как самому вывести просмотренные товары на Битриксе для пользователя.

< ?
$arViewed = [];
$basketUserId = (int) CSaleBasket::GetBasketUserID(false);
if ($basketUserId > 0) {
$viewedIterator = \Bitrix\Catalog\CatalogViewedProductTable::getList([
'select' => ['PRODUCT_ID', 'ELEMENT_ID'],
'filter' => ['=FUSER_ID' => $basketUserId, '=SITE_ID' => SITE_ID],
'order' => ['DATE_VISIT' => 'DESC'],
'limit' => 4
]);
while ($arFields = $viewedIterator->fetch()) {
$arViewed[] = $arFields['ELEMENT_ID'];
}
}
$cnt = count($arViewed);

if (CModule::IncludeModule("iblock")):
$arItems = [];
$res = CIBlockElement::GetList (
Array("ID" => "ASC"),
Array("ID" => $arViewed, "ACTIVE" => "Y"),
false,
false,
Array('ID', 'NAME', 'DETAIL_PAGE_URL', 'PREVIEW_PICTURE', 'CATALOG_PRICE_1')
);
while ($arItem = $res->GetNext()) {
$arItem['PICTURE_SRC'] = CFile::GetPath($arItem['PREVIEW_PICTURE']);
$arItems[] = $arItem;
}
endif;
?>

<?if ($cnt > 0) {?>
<h4><?$APPLICATION->IncludeFile(SITE_TEMPLATE_PATH."/inc/viewed_title.php", [], ["MODE"=>"html"]);?></h4>
<?if ($cnt >= 4) {?>
<div class="all-link-wrap">
<a class="all-link" href="/viewed/">Посмотреть все товары</a>
</div>
<?}?>

<?foreach ($arItems as $key => $item) {?>
<div class="flex mt-2">
<div class="sidebar__latest-view_image">
<?if ($item['PICTURE_SRC']) {?>
<a href="<?=$item['DETAIL_PAGE_URL']?>">
<img src="<?=$item['PICTURE_SRC']?>" alt="<?=$item['NAME']?>" />
</a>
<?}?>
</div>
<div class="sidebar__latest-view_info">
<a href="<?=$item['DETAIL_PAGE_URL']?>" class="product-title"><?=$item['NAME']?></a>
<?if ($item['CATALOG_PRICE_1'] > 0) {?>
<p class="sidebar__latest-view_price">
<?=number_format($item['CATALOG_PRICE_1'], 0, '', ' ')?>
<span>
<svg width="14" height="14" viewBox="0 0 14 14" xmlns="http://www.w3.org/2000/svg" fill="#FF4631">
<path d="M0.954531 11.7725H3.18184V13.6819C3.18184 13.7748 3.21156 13.8508 3.27137 13.9103C3.331 13.9701 3.40724 14 3.50011 14H5.16054C5.24671 14 5.32128 13.9701 5.38426 13.9103C5.44725 13.8508 5.47864 13.7747 5.47864 13.6819V11.7725H10.4999C10.5926 11.7725 10.6689 11.743 10.7287 11.6832C10.7885 11.6234 10.8182 11.5473 10.8182 11.4544V10.1816C10.8182 10.0893 10.7885 10.0127 10.7287 9.95322C10.669 9.89339 10.5926 9.86348 10.4999 9.86348H5.47848V8.69013H8.85916C10.1848 8.69013 11.2668 8.28618 12.1056 7.47713C12.9441 6.66893 13.3635 5.62492 13.3635 4.34507C13.3635 3.06606 12.9441 2.02203 12.1056 1.213C11.267 0.404774 10.1848 0 8.85916 0H3.49995C3.40705 0 3.33097 0.0298867 3.2712 0.0893581C3.21156 0.149159 3.18168 0.225728 3.18168 0.318105V6.57252H0.954531C0.86166 6.57252 0.785557 6.60394 0.725784 6.6669C0.666175 6.72988 0.636261 6.80445 0.636261 6.89059V8.37197C0.636261 8.46487 0.665983 8.54097 0.725784 8.60075C0.785585 8.66058 0.861495 8.69011 0.954531 8.69011H3.18184V9.86345H0.954531C0.86166 9.86345 0.785557 9.89337 0.725784 9.9532C0.666175 10.0126 0.636261 10.0891 0.636261 10.1816V11.4544C0.636261 11.5473 0.665983 11.6234 0.725784 11.6831C0.785557 11.743 0.861632 11.7725 0.954531 11.7725ZM5.47848 2.11811H8.6603C9.36287 2.11811 9.92953 2.32353 10.3605 2.73451C10.7913 3.14551 11.0068 3.68262 11.0068 4.34523C11.0068 5.00817 10.7913 5.54545 10.3605 5.95596C9.92953 6.36729 9.36284 6.57271 8.6603 6.57271H5.47848V2.11811Z"></path>
</svg>
</span>
</p>
<?}?>
</div>
</div>
<?}?>
<?}?>

автор: Dmitriy

web developer

Добавить комментарий

Ваш адрес email не будет опубликован.

#SaveUkraine