Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
basketreservationservice.php
1<?php
2
4
8
13{
17 protected $historyService;
18
22 public function __construct(
24 )
25 {
26 $this->historyService = $historyService;
27 }
28
34 public static function getInstance(): self
35 {
36 return ServiceLocator::getInstance()->get('sale.basketReservation');
37 }
38
45 public function add(array $fields): Result
46 {
47 $result = BasketReservationTable::add($fields);
48
49 if ($result->isSuccess())
50 {
51 // Debug start
52 $reservation = BasketReservationTable::getRowById($result->getId());
53 if (!$reservation)
54 {
55 $logFields = [
56 'STORE_ID' => $fields['STORE_ID'] ?? 0,
57 'BASKET_ID' => $fields['BASKET_ID'] ?? 0,
58 'DATE_RESERVE' => is_object($fields['DATE_RESERVE']) ? $fields['DATE_RESERVE']->toString() : $fields['DATE_RESERVE'],
59 'DATE_RESERVE_END' => is_object($fields['DATE_RESERVE_END']) ? $fields['DATE_RESERVE_END']->toString() : $fields['DATE_RESERVE_END'],
60 'QUANTITY' => $fields['QUANTITY'] ?? 0,
61 ];
62
63 $description = 'ID='.$result->getId().'; json='.\Bitrix\Main\Web\Json::encode($logFields);
64
65 \CEventLog::Add(array(
66 "SEVERITY" => \CEventLog::SEVERITY_DEBUG,
67 "AUDIT_TYPE_ID" => "SALE_RESERVATION_DEBUG",
68 "MODULE_ID" => "sale",
69 "ITEM_ID" => "",
70 "DESCRIPTION" => $description
71 ));
72 }
73 // Debug end
74
75 $historyResult = $this->historyService->addByReservation($result->getId());
76 foreach ($historyResult->getErrors() as $err)
77 {
78 $result->addError($err);
79 }
80 }
81
82 return $result;
83 }
84
92 public function update(int $id, array $fields): Result
93 {
94 $result = BasketReservationTable::update($id, $fields);
95
96 if ($result->isSuccess())
97 {
98 $historyResult = $this->historyService->updateByReservation($id);
99 foreach ($historyResult->getErrors() as $err)
100 {
101 $result->addError($err);
102 }
103 }
104
105 return $result;
106 }
107
114 public function delete(int $id): Result
115 {
116 $result = BasketReservationTable::delete($id);
117
118 if ($result->isSuccess())
119 {
120 $historyResult = $this->historyService->deleteByReservation($id);
121 foreach ($historyResult->getErrors() as $err)
122 {
123 $result->addError($err);
124 }
125 }
126
127 return $result;
128 }
129
138 public function getAvailableCountForOrder(int $orderId): array
139 {
140 return $this->historyService->getAvailableCountForOrder($orderId);
141 }
142
152 public function getAvailableCountForBasketItem(int $basketId, int $storeId): float
153 {
154 return $this->historyService->getAvailableCountForBasketItem($basketId, $storeId);
155 }
156
166 public function getAvailableCountForBasketItems(array $basketItemFilter): array
167 {
168 return $this->historyService->getAvailableCountForBasketItems($basketItemFilter);
169 }
170}
static update($primary, array $data)
__construct(BasketReservationHistoryService $historyService)