Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
basketreservationservice.php
1
<?php
2
3
namespace
Bitrix\Sale\Reservation
;
4
5
use
Bitrix\Main\DI\ServiceLocator
;
6
use
Bitrix\Main\Result
;
7
use
Bitrix\Sale\Reservation\Internals\BasketReservationTable
;
8
12
class
BasketReservationService
13
{
17
protected
$historyService
;
18
22
public
function
__construct
(
23
BasketReservationHistoryService
$historyService
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
}
Bitrix\Main\DI\ServiceLocator
Definition
servicelocator.php:12
Bitrix\Main\ORM\Data\DataManager\delete
static delete($primary)
Definition
datamanager.php:1632
Bitrix\Main\ORM\Data\DataManager\add
static add(array $data)
Definition
datamanager.php:874
Bitrix\Main\ORM\Data\DataManager\getRowById
static getRowById($id)
Definition
datamanager.php:392
Bitrix\Main\ORM\Data\DataManager\update
static update($primary, array $data)
Definition
datamanager.php:1246
Bitrix\Main\ORM\Data\Result
Definition
result.php:16
Bitrix\Main\Result
Definition
result.php:14
Bitrix\Sale\Reservation\BasketReservationHistoryService
Definition
basketreservationhistoryservice.php:21
Bitrix\Sale\Reservation\BasketReservationService
Definition
basketreservationservice.php:13
Bitrix\Sale\Reservation\BasketReservationService\getAvailableCountForBasketItem
getAvailableCountForBasketItem(int $basketId, int $storeId)
Definition
basketreservationservice.php:152
Bitrix\Sale\Reservation\BasketReservationService\$historyService
$historyService
Definition
basketreservationservice.php:17
Bitrix\Sale\Reservation\BasketReservationService\__construct
__construct(BasketReservationHistoryService $historyService)
Definition
basketreservationservice.php:22
Bitrix\Sale\Reservation\BasketReservationService\getAvailableCountForOrder
getAvailableCountForOrder(int $orderId)
Definition
basketreservationservice.php:138
Bitrix\Sale\Reservation\BasketReservationService\add
add(array $fields)
Definition
basketreservationservice.php:45
Bitrix\Sale\Reservation\BasketReservationService\update
update(int $id, array $fields)
Definition
basketreservationservice.php:92
Bitrix\Sale\Reservation\BasketReservationService\getInstance
static getInstance()
Definition
basketreservationservice.php:34
Bitrix\Sale\Reservation\BasketReservationService\getAvailableCountForBasketItems
getAvailableCountForBasketItems(array $basketItemFilter)
Definition
basketreservationservice.php:166
Bitrix\Sale\Reservation\Internals\BasketReservationTable
Definition
basketreservationtable.php:27
Bitrix\Sale\Reservation
Definition
availablequantitycalculator.php:3
modules
sale
lib
reservation
basketreservationservice.php
Создано системой
1.10.0