carono /
php-commerceml
| 1 | <?php |
||
| 2 | |||
| 3 | |||
| 4 | namespace Zenwalker\CommerceML\Model; |
||
| 5 | |||
| 6 | /** |
||
| 7 | * import.xml -> Каталог |
||
| 8 | * |
||
| 9 | * Class Catalog |
||
| 10 | * |
||
| 11 | * @package Zenwalker\CommerceML\Model |
||
| 12 | * @property Product[] $products |
||
| 13 | */ |
||
| 14 | class Catalog extends Simple |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var Product[] |
||
| 18 | */ |
||
| 19 | protected $products = []; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @param string $id |
||
| 23 | * @return null|Product |
||
| 24 | */ |
||
| 25 | 3 | public function getById($id) |
|
| 26 | { |
||
| 27 | 3 | foreach ($this->getProducts() as $product) { |
|
| 28 | 3 | if ($product->id === $id) { |
|
| 29 | 3 | return $product; |
|
| 30 | } |
||
| 31 | } |
||
| 32 | 1 | return null; |
|
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @return Product[] |
||
| 37 | */ |
||
| 38 | 12 | public function getProducts() |
|
| 39 | { |
||
| 40 | 12 | if (empty($this->products) && $this->xml && $this->xml->Товары) { |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 41 | 12 | foreach ($this->xml->Товары->Товар as $product) { |
|
| 42 | 12 | $this->products[] = new Product($this->owner, $product); |
|
| 43 | } |
||
| 44 | } |
||
| 45 | 12 | return $this->products; |
|
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @return \SimpleXMLElement |
||
| 50 | */ |
||
| 51 | 31 | public function loadXml() |
|
| 52 | { |
||
| 53 | 31 | if ($this->owner->importXml) { |
|
| 54 | 31 | return $this->owner->importXml->Каталог; |
|
| 55 | } |
||
| 56 | |||
| 57 | return null; |
||
| 58 | } |
||
| 59 | } |