carono /
php-commerceml
| 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 | protected $stockrooms = []; |
||
| 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 | 27 | public function loadXml() |
|
| 34 | { |
||
| 35 | 27 | if ($this->owner->offersXml) { |
|
| 36 | 27 | return $this->owner->offersXml->ПакетПредложений; |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 37 | } |
||
| 38 | |||
| 39 | return null; |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @return Offer[] |
||
| 44 | */ |
||
| 45 | 6 | public function getOffers() |
|
| 46 | { |
||
| 47 | 6 | if (empty($this->offers) && $this->xml && $this->xml->Предложения) { |
|
| 48 | 6 | foreach ($this->xml->Предложения->Предложение as $offer) { |
|
| 49 | 6 | $this->offers[] = new Offer($this->owner, $offer); |
|
| 50 | } |
||
| 51 | } |
||
| 52 | 6 | 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 | 6 | public function getOffersById($id) |
|
| 88 | { |
||
| 89 | 6 | $result = []; |
|
| 90 | 6 | foreach ($this->getOffers() as $offer) { |
|
| 91 | 6 | if ($offer->getClearId() === $id) { |
|
| 92 | 6 | $result[] = $offer; |
|
| 93 | } |
||
| 94 | } |
||
| 95 | 6 | return $result; |
|
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @return Stockroom[] |
||
| 100 | */ |
||
| 101 | 1 | public function getStockrooms() |
|
| 102 | { |
||
| 103 | 1 | if (empty($this->stockrooms) && isset($this->xml->Склады)) { |
|
| 104 | 1 | foreach ($this->xml->Склады->Склад as $stockroom) { |
|
| 105 | 1 | $this->stockrooms[] = new Stockroom($this->owner, $stockroom); |
|
| 106 | } |
||
| 107 | } |
||
| 108 | 1 | return $this->stockrooms; |
|
| 109 | } |
||
| 110 | } |