1 | <?php |
||
2 | |||
3 | |||
4 | namespace Zenwalker\CommerceML\Model; |
||
5 | |||
6 | |||
7 | /** |
||
8 | * Class Price |
||
9 | * |
||
10 | * @package Zenwalker\CommerceML\Model |
||
11 | * @property string performance |
||
12 | * @property string cost |
||
13 | * @property string currency |
||
14 | * @property string unit |
||
15 | * @property string rate |
||
16 | * @property Simple type |
||
17 | */ |
||
18 | class Price extends Simple |
||
19 | { |
||
20 | protected $type; |
||
21 | |||
22 | 1 | public function __get($name) |
|
23 | { |
||
24 | 1 | if ($result = parent::__get($name)) { |
|
25 | 1 | if ($this->type && ($value = $this->type->{$name})) { |
|
26 | return $value; |
||
27 | } |
||
28 | } |
||
29 | 1 | return $result; |
|
30 | } |
||
31 | |||
32 | 1 | public function propertyAliases() |
|
33 | { |
||
34 | return [ |
||
35 | 1 | 'Представление' => 'performance', |
|
36 | 'ИдТипаЦены' => 'id', |
||
37 | 'ЦенаЗаЕдиницу' => 'cost', |
||
38 | 'Валюта' => 'currency', |
||
39 | 'Единица' => 'unit', |
||
40 | 'Коэффициент' => 'rate', |
||
41 | ]; |
||
42 | } |
||
43 | |||
44 | 1 | public function getType() |
|
45 | { |
||
46 | 1 | if (!$this->type && ($id = $this->id)) { |
|
47 | 1 | if ($type = $this->owner->offerPackage->xpath('//c:ТипЦены[c:Ид = :id]', ['id' => $id])) { |
|
48 | 1 | $this->type = new Simple($this->owner, $type[0]); |
|
49 | } |
||
50 | } |
||
51 | 1 | return $this->type; |
|
52 | } |
||
53 | |||
54 | 1 | public function init() |
|
55 | { |
||
56 | 1 | if ($this->xml && $this->xml->Цена) { |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
57 | 1 | foreach ($this->xml->Цена as $price) { |
|
58 | 1 | $this->append(new self($this->owner, $price)); |
|
59 | } |
||
60 | 1 | $this->getType(); |
|
61 | } |
||
62 | 1 | parent::init(); |
|
63 | } |
||
64 | } |