Beispiel #1
0
 /**
  * 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));
         }
     }
 }
Beispiel #2
0
 /**
  * @param string $line
  */
 public function addLine($line)
 {
     if (!$this->acceptsLines()) {
         throw new \LogicException('You cannot add lines to a block which cannot accept them');
     }
     $this->strings->add($line);
 }