Example #1
0
 /**
  * @param \SimpleXMLElement $it
  * @return Product
  */
 public function decodeProduct(\SimpleXMLElement $it)
 {
     if (!isset($it->uid)) {
         throw new InputException('Missing product attribute "uid"');
     }
     foreach (['created', 'updated', 'deleted'] as $attribute) {
         if (!isset($it[$attribute])) {
             throw new InputException('Missing product attribute "' . $attribute . '"');
         }
     }
     $product = new Product((string) $it->uid);
     $product->setCreated(\DateTime::createFromFormat(self::DATE_FORMAT, (string) $it['created']));
     $product->setUpdated(\DateTime::createFromFormat(self::DATE_FORMAT, (string) $it['updated']));
     $product->setDeleted((string) $it['deleted'] === 'true');
     if (isset($it->description)) {
         $product->setDescription((string) $it->description);
     }
     if (isset($it->fulldescription)) {
         $product->setFullDescription((string) $it->fulldescription);
     }
     if (isset($it->warranty)) {
         $product->setWarranty((int) $it->warranty);
     }
     if (isset($it->url)) {
         $product->setUrl((string) $it->url);
     }
     if (isset($it->vat)) {
         $product->setVatRate((double) $it->vat);
     }
     if (isset($it->brand)) {
         $product->setBrand($this->decodeBrand($it->brand));
     }
     if (isset($it->category)) {
         foreach ($it->category as $category) {
             $product->addCategory($this->decodeCategory($category));
         }
     }
     if (isset($it->video)) {
         foreach ($it->video as $video) {
             $product->addVideo($this->decodeVideo($video));
         }
     }
     if (isset($it->variant)) {
         foreach ($it->variant as $variant) {
             $product->addVariant($this->decodeVariant($variant));
         }
     }
     $product->setChecksum(md5($it->asXML()));
     $this->decodeItem($it, $product);
     return $product;
 }