Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
MeasureRatioCollection.php
1<?php
2
4
6
16{
18 protected $factory;
19
21 {
22 $this->factory = $factory;
23 }
24
25 public function findDefault(): ?BaseMeasureRatio
26 {
28 foreach ($this->getIterator() as $measureRatio)
29 {
30 if ($measureRatio->isDefault())
31 {
32 return $measureRatio;
33 }
34 }
35
36 return null;
37 }
38
39 // ToDo set product id by default? in prices too?
40 public function create(): BaseMeasureRatio
41 {
42 $measureRatio = $this->factory->createEntity();
43
44 $this->add($measureRatio);
45
46 return $measureRatio;
47 }
48
49 public function setDefault(float $ratio): BaseMeasureRatio
50 {
51 $measureRatio = $this->findDefault();
52
53 if (!$measureRatio)
54 {
55 $measureRatio = $this->create()->setDefault();
56 }
57
58 return $measureRatio->setRatio($ratio);
59 }
60}