Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Repository.php
1<?php
2
4
7
16final class Repository
17{
19 private static $instance;
20
21 public const DEFAULT_GET_LIST_LIMIT = 10;
22
26 public static function getInstance(): Repository
27 {
28 if (is_null(static::$instance))
29 {
30 static::$instance = new static();
31 }
32
33 return static::$instance;
34 }
35
40 public function getList(array $options = []): array
41 {
42 $result = [];
43
44 if (!Loader::includeModule('sale'))
45 {
46 return $result;
47 }
48
49 $limit = $options['limit'] ?? self::DEFAULT_GET_LIST_LIMIT;
50
51 $viewedProductsList = Catalog\CatalogViewedProductTable::getList(
52 [
53 'filter' => [
54 '=FUSER_ID' => (int)\CSaleBasket::GetBasketUserID(
55 !Catalog\Product\Basket::isNotCrawler()
56 ),
57 '=SITE_ID' => SITE_ID,
58 ],
59 'select' => [
60 'ELEMENT_ID',
61 'PRODUCT_ID',
62 ],
63 'order' => [
64 'DATE_VISIT' => 'DESC',
65 ],
66 'limit' => $limit,
67 ]
68 );
69
70 while ($viewedProduct = $viewedProductsList->fetch())
71 {
72 $sku =
73 Catalog\v2\IoC\ServiceContainer::getRepositoryFacade()
74 ->loadVariation((int)$viewedProduct['PRODUCT_ID'])
75 ;
76
77 if (!$sku)
78 {
79 continue;
80 }
81
82 $result[] = $sku;
83 }
84
85 return $result;
86 }
87}