| Total Complexity | 8 |
| Total Lines | 34 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php namespace Zenwalker\CommerceML\Model; |
||
| 11 | class Property extends Simple |
||
| 12 | { |
||
| 13 | public $productId; |
||
| 14 | protected $_value; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @return \SimpleXMLElement[] |
||
| 18 | */ |
||
| 19 | 1 | public function getAvailableValues() |
|
| 20 | { |
||
| 21 | 1 | return $this->owner->classifier->getReferenceBookById($this->id); |
|
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @return Simple|null |
||
| 26 | */ |
||
| 27 | 2 | public function getValueModel() |
|
| 28 | { |
||
| 29 | 2 | if ($this->productId && !$this->_value && ($product = $this->owner->catalog->getById($this->productId))) { |
|
| 30 | 2 | $xpath = "c:ЗначенияСвойств/c:ЗначенияСвойства[c:Ид = '{$this->id}']"; |
|
| 31 | 2 | $valueXml = $product->xpath($xpath)[0]; |
|
| 32 | 2 | $value = $this->_value = (string)$valueXml->Значение; |
|
|
|
|||
| 33 | 2 | if ($property = $this->owner->classifier->getReferenceBookValueById($value)) { |
|
| 34 | 1 | $this->_value = new Simple($this->owner, $property); |
|
| 35 | } else { |
||
| 36 | 1 | $this->_value = new Simple($this->owner, $valueXml); |
|
| 37 | } |
||
| 38 | } |
||
| 39 | 2 | return $this->_value; |
|
| 40 | } |
||
| 41 | |||
| 42 | 2 | public function getValue() |
|
| 43 | { |
||
| 44 | 2 | return $this->getValueModel() ? (string)$this->getValueModel()->value : null; |
|
| 45 | } |
||
| 46 | } |