Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
basketitemrepository.php
1<?php
2
4
6
13{
15 private static $instance;
16
20 private function __construct()
21 {}
22
26 public static function getInstance(): BasketItemRepository
27 {
28 if (is_null(static::$instance))
29 {
30 static::$instance = new BasketItemRepository();
31 }
32
33 return static::$instance;
34 }
35
40 public function getById(int $id): ?Sale\BasketItem
41 {
43 $basketClass = Sale\Registry::getInstance(Sale\Registry::REGISTRY_TYPE_ORDER)->getBasketClassName();
44
45 $basketRow = $basketClass::getList([
46 'select' => ['ID', 'ORDER_ID'],
47 'filter' => [
48 '=ID' => $id
49 ]
50 ])->fetch();
51 if (!$basketRow)
52 {
53 return null;
54 }
55
56 return static::getInstance()->getByRow($basketRow);
57 }
58
63 public function getByIds(array $ids): array
64 {
65 $result = [];
66
68 $basketClass = Sale\Registry::getInstance(Sale\Registry::REGISTRY_TYPE_ORDER)->getBasketClassName();
69
70 $basketList = $basketClass::getList([
71 'select' => ['ID', 'ORDER_ID'],
72 'filter' => [
73 '=ID' => $ids
74 ]
75 ]);
76
77 while ($basketRow = $basketList->fetch())
78 {
79 $basket = static::getInstance()->getByRow($basketRow);
80 if (is_null($basket))
81 {
82 continue;
83 }
84
85 $result[] = $basket;
86 }
87
88 return $result;
89 }
90
95 private function getByRow(array $basketRow): ?Sale\BasketItem
96 {
97 $orderClassName = Sale\Registry::getInstance(Sale\Registry::REGISTRY_TYPE_ORDER)->getOrderClassName();
98
100 $order = $orderClassName::load($basketRow['ORDER_ID']);
101 if ($order === null)
102 {
103 return null;
104 }
105
106 $basket = $order->getBasket();
107
109 foreach ($basket as $basketItem)
110 {
111 if ($basketItem->getId() !== (int)$basketRow['ID'])
112 {
113 continue;
114 }
115
116 return $basketItem;
117 }
118
119 return null;
120 }
121}
fetch(Main\Text\Converter $converter=null)
Definition entity.php:112