1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
BarcodeRepository.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Catalog\v2\Barcode;
4
5
use Bitrix\Catalog\v2\BaseEntity;
6
use Bitrix\Catalog\v2\Sku\BaseSku;
7
use Bitrix\Main\Error;
8
use Bitrix\Main\Result;
9
use Bitrix\Catalog;
10
19
20
class
BarcodeRepository
implements
BarcodeRepositoryContract
21
{
23
protected
$factory
;
24
25
public
function
__construct
(
BarcodeFactory
$factory
)
26
{
27
$this->factory =
$factory
;
28
}
29
32
public
function
getEntityById
(
int
$id): ?
BaseEntity
33
{
34
if
($id <= 0)
35
{
36
throw
new \OutOfRangeException($id);
37
}
38
39
$entities = $this->
getEntitiesBy
([
40
'filter'
=> [
41
'=ID'
=> $id,
42
],
43
]);
44
45
return
reset($entities) ?:
null
;
46
}
47
51
public
function
getEntitiesBy
(
$params
):
array
52
{
53
$entities = [];
54
55
foreach
($this->
getList
((
array
)
$params
) as $item)
56
{
57
$entities[] = $this->
createEntity
($item);
58
}
59
60
return
$entities;
61
}
62
63
public
function
getProductId
(
BaseEntity
$entity
): ?int
64
{
65
$id =
null
;
66
67
$parent =
$entity
->getParent();
68
69
if
($parent && !$parent->isNew())
70
{
71
$id = $parent->getId();
72
}
73
74
return
$id;
75
}
76
80
public
function
save
(
BaseEntity
...$entities):
Result
81
{
82
$result
=
new
Result
();
83
85
foreach
($entities as
$entity
)
86
{
87
if
(!
$entity
->getProductId())
88
{
89
$productId = $this->
getProductId
($entity);
90
91
if
($productId)
92
{
93
$entity
->setProductId($productId);
94
}
95
else
96
{
97
$result
->addError(
new
Error
(
'Wrong product id'
));
98
continue
;
99
}
100
}
101
102
if
(
$entityId
=
$entity
->getId())
103
{
104
$res
= $this->
updateInternal
(
$entityId
,
$entity
->getChangedFields());
105
106
if
(!
$res
->isSuccess())
107
{
108
$result
->addErrors(
$res
->getErrors());
109
}
110
}
111
else
112
{
113
$res
= $this->
addInternal
(
$entity
->getFields());
114
115
if
(
$res
->isSuccess())
116
{
117
$entity
->setId(
$res
->getData()[
'ID'
]);
118
}
119
else
120
{
121
$result
->addErrors(
$res
->getErrors());
122
}
123
}
124
}
125
126
return
$result
;
127
}
128
132
public
function
delete
(BaseEntity ...$entities): Result
133
{
134
$result
=
new
Result();
135
137
foreach
($entities as
$entity
)
138
{
139
if
(
$entityId
=
$entity
->getId())
140
{
141
$res
= $this->
deleteInternal
(
$entityId
);
142
143
if
(!
$res
->isSuccess())
144
{
145
$result
->addErrors(
$res
->getErrors());
146
}
147
}
148
}
149
150
return
$result
;
151
}
152
153
public
function
getCollectionByParent
(
BaseSku
$sku):
BarcodeCollection
154
{
155
if
($sku->
isNew
())
156
{
157
return
$this->
createCollection
();
158
}
159
160
$result
= $this->
getByProductId
($sku->
getId
());
161
162
return
$this->
createCollection
(
$result
);
163
}
164
165
protected
function
getByProductId
(
int
$skuId):
array
166
{
167
return
$this->
getList
([
168
'filter'
=> [
169
'=PRODUCT_ID'
=> $skuId,
170
'=ORDER_ID'
=>
null
,
171
],
172
]);
173
}
174
175
protected
function
getList
(
array
$params
):
array
176
{
177
$rows
=
Catalog\StoreBarcodeTable::getList
(
$params
)->fetchAll();
178
179
return
array_column(
$rows
,
null
,
'ID'
);
180
}
181
182
protected
function
createEntity
(
array
$fields
= []):
Barcode
183
{
184
$entity
= $this->factory->createEntity();
185
186
$entity
->initFields(
$fields
);
187
188
return
$entity
;
189
}
190
191
protected
function
createCollection
(
array
$entityFields = []):
BarcodeCollection
192
{
193
$collection = $this->factory->createCollection();
194
195
foreach
($entityFields as
$fields
)
196
{
197
$barcode = $this->
createEntity
($fields);
198
$collection->add($barcode);
199
}
200
201
return
$collection;
202
}
203
204
protected
function
addInternal
(
array
$fields
):
Result
205
{
206
$result
=
new
Result
();
207
208
$res
=
Catalog\StoreBarcodeTable::add
(
$fields
);
209
if
(
$res
->isSuccess())
210
{
211
$result
->setData([
'ID'
=>
$res
->getId()]);
212
}
213
else
214
{
215
$result
->addErrors(
$res
->getErrors());
216
}
217
218
return
$result
;
219
}
220
221
protected
function
updateInternal
(
int
$id,
array
$fields
):
Result
222
{
223
$result
=
new
Result
();
224
225
$res
=
Catalog\StoreBarcodeTable::update
($id,
$fields
);
226
227
if
(!
$res
->isSuccess())
228
{
229
$result
->addErrors(
$res
->getErrors());
230
}
231
232
return
$result
;
233
}
234
235
protected
function
deleteInternal
(
int
$id):
Result
236
{
237
$result
=
new
Result
();
238
239
$res
=
Catalog\StoreBarcodeTable::delete
($id);
240
241
if
(!
$res
->isSuccess())
242
{
243
$result
->addErrors(
$res
->getErrors());
244
}
245
246
return
$result
;
247
}
248
}
Bitrix\Catalog\v2\Barcode\BarcodeCollection
Определения
BarcodeCollection.php:19
Bitrix\Catalog\v2\Barcode\BarcodeFactory
Определения
BarcodeFactory.php:16
Bitrix\Catalog\v2\Barcode\Barcode
Определения
Barcode.php:19
Bitrix\Catalog\v2\Barcode\BarcodeRepository
Определения
BarcodeRepository.php:21
Bitrix\Catalog\v2\Barcode\BarcodeRepository\$factory
$factory
Определения
BarcodeRepository.php:23
Bitrix\Catalog\v2\Barcode\BarcodeRepository\__construct
__construct(BarcodeFactory $factory)
Определения
BarcodeRepository.php:25
Bitrix\Catalog\v2\Barcode\BarcodeRepository\getEntitiesBy
getEntitiesBy($params)
Определения
BarcodeRepository.php:51
Bitrix\Catalog\v2\Barcode\BarcodeRepository\getByProductId
getByProductId(int $skuId)
Определения
BarcodeRepository.php:165
Bitrix\Catalog\v2\Barcode\BarcodeRepository\getProductId
getProductId(BaseEntity $entity)
Определения
BarcodeRepository.php:63
Bitrix\Catalog\v2\Barcode\BarcodeRepository\deleteInternal
deleteInternal(int $id)
Определения
BarcodeRepository.php:235
Bitrix\Catalog\v2\Barcode\BarcodeRepository\getEntityById
getEntityById(int $id)
Определения
BarcodeRepository.php:32
Bitrix\Catalog\v2\Barcode\BarcodeRepository\addInternal
addInternal(array $fields)
Определения
BarcodeRepository.php:204
Bitrix\Catalog\v2\Barcode\BarcodeRepository\createEntity
createEntity(array $fields=[])
Определения
BarcodeRepository.php:182
Bitrix\Catalog\v2\Barcode\BarcodeRepository\getList
getList(array $params)
Определения
BarcodeRepository.php:175
Bitrix\Catalog\v2\Barcode\BarcodeRepository\createCollection
createCollection(array $entityFields=[])
Определения
BarcodeRepository.php:191
Bitrix\Catalog\v2\Barcode\BarcodeRepository\getCollectionByParent
getCollectionByParent(BaseSku $sku)
Определения
BarcodeRepository.php:153
Bitrix\Catalog\v2\Barcode\BarcodeRepository\updateInternal
updateInternal(int $id, array $fields)
Определения
BarcodeRepository.php:221
Bitrix\Catalog\v2\BaseEntity
Определения
BaseEntity.php:22
Bitrix\Catalog\v2\BaseEntity\getId
getId()
Определения
BaseEntity.php:173
Bitrix\Catalog\v2\BaseEntity\isNew
isNew()
Определения
BaseEntity.php:168
Bitrix\Catalog\v2\Sku\BaseSku
Определения
BaseSku.php:34
Bitrix\Main\Error
Определения
error.php:15
Bitrix\Main\ORM\Data\DataManager\getList
static getList(array $parameters=array())
Определения
datamanager.php:431
Bitrix\Main\ORM\Data\DataManager\delete
static delete($primary)
Определения
datamanager.php:1644
Bitrix\Main\ORM\Data\DataManager\add
static add(array $data)
Определения
datamanager.php:877
Bitrix\Main\ORM\Data\DataManager\update
static update($primary, array $data)
Определения
datamanager.php:1256
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$res
$res
Определения
filter_act.php:7
$result
$result
Определения
get_property_values.php:14
$entity
$entity
Определения
group_bizproc_workflow_delete.php:17
Bitrix\Catalog\v2\Barcode\BarcodeRepositoryContract
Определения
BarcodeRepositoryContract.php:18
Bitrix\Catalog\v2\RepositoryContract\save
save(BaseEntity ... $entities)
Bitrix\Sale\Discount\Result
Определения
compatibleformat.php:2
$entityId
$entityId
Определения
payment.php:4
$params
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения
template.php:799
$rows
$rows
Определения
options.php:264
$fields
$fields
Определения
yandex_run.php:501
bitrix
modules
catalog
lib
v2
Barcode
BarcodeRepository.php
Создано системой
1.14.0