/**
  * {@inheritDoc}
  */
 public function getDownloads()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getDownloads', array());
     return parent::getDownloads();
 }
示例#2
0
 /**
  * @param array $data
  * @param \Shopware\Models\Article\Article $article
  * @throws \Shopware\Components\Api\Exception\CustomValidationException
  * @return array
  */
 private function prepareDownloadsAssociatedData($data, ArticleModel $article)
 {
     if (!isset($data['downloads'])) {
         return $data;
     }
     $downloads = $this->checkDataReplacement($article->getDownloads(), $data, 'downloads', true);
     foreach ($data['downloads'] as &$downloadData) {
         $download = $this->getOneToManySubElement($downloads, $downloadData, '\\Shopware\\Models\\Article\\Download');
         if (isset($downloadData['link'])) {
             $media = $this->getMediaResource()->internalCreateMediaByFileLink($downloadData['link'], -6);
             if (isset($downloadData['name']) && !empty($downloadData['name'])) {
                 $media->setDescription($downloadData['name']);
             }
             try {
                 //persist the model into the model manager
                 $this->getManager()->persist($media);
             } catch (\Doctrine\ORM\ORMException $e) {
                 throw new ApiException\CustomValidationException(sprintf("Some error occured while loading your image"));
             }
             $download->setFile($media->getPath());
             $download->setName($media->getName());
             $download->setSize($media->getFileSize());
         }
         $download->fromArray($downloadData);
         $download->setArticle($article);
     }
     $data['downloads'] = $downloads;
     return $data;
 }