|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Zenwalker\CommerceML\Model; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class OfferPackage |
|
9
|
|
|
* |
|
10
|
|
|
* @package Zenwalker\CommerceML\Model |
|
11
|
|
|
* @property Offer[] offers |
|
12
|
|
|
* @property string containsOnlyChanges |
|
13
|
|
|
*/ |
|
14
|
|
|
class OfferPackage extends Simple |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var Offer[] |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $offers = []; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var Simple[] array |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $priceTypes = []; |
|
25
|
|
|
|
|
26
|
1 |
|
public function propertyAliases() |
|
27
|
|
|
{ |
|
28
|
1 |
|
return array_merge(parent::propertyAliases(), [ |
|
29
|
1 |
|
'СодержитТолькоИзменения' => 'containsOnlyChanges' |
|
30
|
|
|
]); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
14 |
|
public function loadXml() |
|
34
|
|
|
{ |
|
35
|
14 |
|
if ($this->owner->offersXml) { |
|
36
|
14 |
|
return $this->owner->offersXml->ПакетПредложений; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
return null; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @return Offer[] |
|
44
|
|
|
*/ |
|
45
|
4 |
|
public function getOffers() |
|
46
|
|
|
{ |
|
47
|
4 |
|
if (empty($this->offers) && $this->xml && $this->xml->Предложения) { |
|
48
|
4 |
|
foreach ($this->xml->Предложения->Предложение as $offer) { |
|
49
|
4 |
|
$this->offers[] = new Offer($this->owner, $offer); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
4 |
|
return $this->offers; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return Simple[] |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getPriceTypes() |
|
59
|
|
|
{ |
|
60
|
|
|
if (empty($this->priceTypes) && $this->xml) { |
|
61
|
|
|
foreach ($this->xpath('//c:ТипыЦен/c:ТипЦены') as $type) { |
|
62
|
|
|
$this->priceTypes[] = new Simple($this->owner, $type); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
return $this->priceTypes; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param $id |
|
70
|
|
|
* @return null|Offer |
|
71
|
|
|
* @deprecated will removed in 0.3.0 |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getOfferById($id) |
|
74
|
|
|
{ |
|
75
|
|
|
foreach ($this->getOffers() as $offer) { |
|
76
|
|
|
if ($offer->getClearId() === $id) { |
|
77
|
|
|
return $offer; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
return null; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @param $id |
|
85
|
|
|
* @return Offer[] |
|
86
|
|
|
*/ |
|
87
|
4 |
|
public function getOffersById($id) |
|
88
|
|
|
{ |
|
89
|
4 |
|
$result = []; |
|
90
|
4 |
|
foreach ($this->getOffers() as $offer) { |
|
91
|
4 |
|
if ($offer->getClearId() === $id) { |
|
92
|
4 |
|
$result[] = $offer; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
4 |
|
return $result; |
|
96
|
|
|
} |
|
97
|
|
|
} |