/** * Class constructor. * @param \SimpleXMLElement $xml */ public function __construct(\SimpleXMLElement $xml) { $this->categories = new Collection(); $this->requisites = new Collection(); $this->properties = new Collection(); $this->characteristics = new Collection(); $this->images = new Collection(); $this->taxRate = new Collection(); $this->id = (string) $xml->Ид; $this->name = (string) $xml->Наименование; $this->description = (string) $xml->Описание; $this->sku = (string) $xml->Артикул; $this->barcode = (string) $xml->ШтрихКод; if ($xml->Группы) { foreach ($xml->Группы->Ид as $categoryId) { $this->categories->add((string) $categoryId); } } if ($xml->ЗначенияРеквизитов) { foreach ($xml->ЗначенияРеквизитов->ЗначениеРеквизита as $value) { $this->requisites->add(new RequisiteValue($value)); } } if ($xml->ЗначенияСвойств) { foreach ($xml->ЗначенияСвойств->ЗначенияСвойства as $prop) { $this->properties->add(new PropertyValue($prop)); } } if ($xml->Картинка) { $dirName = dirname(Parser::getInstance()->getCurrentFile()->getRealPath()); foreach ($xml->Картинка as $image) { if (file_exists($path = realpath($dirName . DIRECTORY_SEPARATOR . (string) $image))) { $this->images->add($path); } } } if ($xml->Изготовитель) { $this->manufacturer = new Partner($xml->Изготовитель); } if ($xml->ХарактеристикиТовара) { foreach ($xml->ХарактеристикиТовара->ХарактеристикаТовара as $value) { $this->characteristics->add(new ProductCharacteristic($value)); } } if ($xml->БазоваяЕдиница) { $this->baseUnit = new BaseUnit($xml->БазоваяЕдиница); } if ($xml->СтавкиНалогов) { foreach ($xml->СтавкиНалогов->СтавкаНалога as $value) { $this->taxRate->add(new TaxRate($value)); } } }
public function testParser() { $this->parser->addListener('ProductEvent', [$this, 'ProductEvent']); $this->parser->addListener('CategoryEvent', [$this, 'CategoryEvent']); $this->parser->addListener('OfferEvent', [$this, 'OfferEvent']); $this->parser->addListener('PropertyEvent', [$this, 'PropertyEvent']); $this->parser->parse(dirname(__FILE__) . '/../../example/import___6b163182-d760-4302-b5fb-4c1d76d8eb85.xml'); $this->parser->parse(dirname(__FILE__) . '/../../example/import___b815e2db-7a65-4265-9241-5f0c4f0565a7.xml'); $this->parser->parse(dirname(__FILE__) . '/../../example/offers___7f304edc-2527-4d3d-b058-6e4ee53de2e0.xml'); $this->parser->parse(dirname(__FILE__) . '/../../example/offers___f0bab95c-14a6-4141-9746-6650b65f1191.xml'); $this->parser->parse(dirname(__FILE__) . '/../../example/prices___d66a6b51-ce9c-4e7a-8c7c-25079721107f.xml'); $this->parser->parse(dirname(__FILE__) . '/../../example/rests___1af6e7b8-a026-4690-9752-1c9d64cb914d.xml'); }