Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
BarcodeCollection.php
1
<?php
2
3
namespace
Bitrix\Catalog\v2\Barcode
;
4
5
use
Bitrix\Catalog\v2\BaseCollection
;
6
use
Bitrix\Catalog\v2\BaseEntity
;
7
use
Bitrix\Catalog\v2\IoC\ContainerContract
;
8
use
Bitrix\Catalog\v2\IoC\Dependency
;
9
18
class
BarcodeCollection
extends
BaseCollection
19
{
21
protected
$container
;
23
protected
$factory
;
24
25
public
function
__construct
(
ContainerContract
$container
,
BarcodeFactory
$factory
)
26
{
27
$this->container =
$container
;
28
$this->factory =
$factory
;
29
}
30
31
public
function
create
():
Barcode
32
{
33
$barcode = $this->factory->createEntity();
34
$this->
add
($barcode);
35
36
return
$barcode;
37
}
38
39
public
function
getItemByBarcode(
string
$barcode): ?
Barcode
40
{
42
foreach
($this->items as $item)
43
{
44
if
($barcode === $item->getBarcode())
45
{
46
return
$item;
47
}
48
}
49
50
return
null
;
51
}
52
53
public
function
setSimpleBarcodeValue
(
string
$value =
''
): self
54
{
55
$barcodeItem = $this->
getFirst
();
56
if
($value !==
''
)
57
{
58
if
(!$barcodeItem)
59
{
60
$barcodeItem = $this->
create
();
61
$this->
add
($barcodeItem);
62
}
63
64
$barcodeItem->setBarcode($value);
65
66
}
67
elseif ($barcodeItem)
68
{
69
$barcodeItem->remove();
70
}
71
72
return
$this;
73
}
74
}
Bitrix\Catalog\v2\Barcode\BarcodeCollection
Definition
BarcodeCollection.php:19
Bitrix\Catalog\v2\Barcode\BarcodeCollection\$factory
$factory
Definition
BarcodeCollection.php:23
Bitrix\Catalog\v2\Barcode\BarcodeCollection\__construct
__construct(ContainerContract $container, BarcodeFactory $factory)
Definition
BarcodeCollection.php:25
Bitrix\Catalog\v2\Barcode\BarcodeCollection\create
create()
Definition
BarcodeCollection.php:31
Bitrix\Catalog\v2\Barcode\BarcodeCollection\$container
$container
Definition
BarcodeCollection.php:21
Bitrix\Catalog\v2\Barcode\BarcodeCollection\setSimpleBarcodeValue
setSimpleBarcodeValue(string $value='')
Definition
BarcodeCollection.php:53
Bitrix\Catalog\v2\Barcode\BarcodeFactory
Definition
BarcodeFactory.php:16
Bitrix\Catalog\v2\Barcode\Barcode
Definition
Barcode.php:19
Bitrix\Catalog\v2\BaseCollection
Definition
BaseCollection.php:17
Bitrix\Catalog\v2\BaseCollection\add
add(BaseEntity ... $items)
Definition
BaseCollection.php:50
Bitrix\Catalog\v2\BaseCollection\getFirst
getFirst(callable $callback=null)
Definition
BaseCollection.php:171
Bitrix\Catalog\v2\BaseEntity
Definition
BaseEntity.php:22
Bitrix\Catalog\v2\IoC\Dependency
Definition
Dependency.php:40
Bitrix\Catalog\v2\IoC\ContainerContract
Definition
ContainerContract.php:15
Bitrix\Catalog\v2\Barcode
Definition
Barcode.php:3
modules
catalog
lib
v2
Barcode
BarcodeCollection.php
Создано системой
1.10.0