Ejemplo n.º 1
0
 /**
  * Add products to category.
  * 
  * @param Collection $products
  * @return void
  */
 public function attachProducts($products)
 {
     $this->products = array();
     foreach ($products->fetch() as $product) {
         if (array_key_exists($this->id, $product->categories)) {
             $this->products[$product->id] = $product;
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * @param Model $object
  * @param Collection $collection
  * @param string $path
  * @param \SimpleXMLElement $xml
  * @throws NoObjectException
  */
 protected function addChild($object, $collection, $path, $xml)
 {
     if (!empty(self::$objects[$path]['child']) && method_exists($object, 'addChild')) {
         foreach ($xml->xpath(self::$objects[$path]['child']) as $childxml) {
             $child = new self::$objects[$path]['model']($childxml);
             $object->addChild($child);
             $collection->add($child);
             $this->addChild($child, $collection, $path, $childxml);
         }
     }
 }
Ejemplo n.º 3
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));
         }
     }
 }