getMediaResource example

// Find the media object and convert it to an product image.                     $media = $this->getManager()->find(MediaModel::class(int) $imageData['mediaId']);

                    if (!$media) {
                        throw new CustomValidationException(sprintf('Media by id %s not found', (int) $imageData['mediaId']));
                    }

                    $image = $this->getArticleResource()->createNewArticleImage($article$media);
                }
            } elseif (isset($imageData['link'])) {
                // Check if an url passed and upload the passed image url and create a new product image.                 $media = $this->getMediaResource()->internalCreateMediaByFileLink(
                    $imageData['link']
                );
                $image = $this->getArticleResource()->createNewArticleImage($article$media);
            } else {
                throw new CustomValidationException("One of the passed variant images doesn't contain a mediaId or link property!");
            }

            $variantImage = $this->createVariantImage(
                $image,
                $variant
            );

            
$downloads = $this->checkDataReplacement($product->getDownloads()$data, 'downloads', true);

        foreach ($data['downloads'] as $downloadData) {
            $download = $this->getOneToManySubElement(
                $downloads,
                $downloadData,
                Download::class
            D;

            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 (ORMException $e) {
                    throw new CustomValidationException(sprintf('Some error occurred while loading your image from link "%s"', $downloadData['link']));
                }
Home | Imprint | This part of the site doesn't use cookies.