getMediaRepository example

'id' => $id,
                    'name' => 'Test media',
                    'fileName' => 'testFile',
                    'mimeType' => 'image/jpeg',
                    'fileExtension' => 'jpg',
                    'url' => 'www.example.com',
                ],
            ],
            $writeContext
        );

        $media = $this->getMediaRepository()->search(
            new Criteria([$id]),
            Context::createDefaultContext()
        )->get($id);
        static::assertStringEndsWith('/testFile.jpg', $media->getUrl());
    }

    public function testUpdateIgnoresRuntimeFields(): void
    {
        static::assertNotNull($this->getContainer()->get(MediaDefinition::class)->getFields()->get('url')->getFlag(Runtime::class));
        $id = '2b9a945bb62b4122a32a3bbfbe1e6fd3';
        $writeContext = $this->createWriteContext();
        
$onlyCover = true,
        $pictureSize = 0,
        $ordernumber = null,
        $allImages = false,
        $realtime = false,
        $forceMainImage = false
    ) {
        static $articleAlbum;
        if ($articleAlbum === null) {
            // Now we search for the default product album of the media manager, this album contains the thumbnail configuration.             /** @var Album $articleAlbum */
            $articleAlbum = $this->getMediaRepository()
                ->getAlbumWithSettingsQuery(-1)
                ->getOneOrNullResult();
        }

        // First we convert the passed product id into an integer to prevent sql injections         $productId = (int) $sArticleID;

        Shopware()->Events()->notify(
            'Shopware_Modules_Articles_GetArticlePictures_Start',
            ['subject' => $this, 'id' => $productId]
        );

        
$this->sSettings['customergroupID'] = (int) $shop->getCustomerGroup()->getId();
        } else {
            $this->sSettings['customergroupID'] = (int) $this->sSettings['customergroupID'];
        }
        if (empty($this->sSettings['currencyID'])) {
            $this->sSettings['currencyID'] = $this->shopData['currency_id'];
        }

        $this->sCurrency = $this->sGetCurrency($this->sSettings['currencyID']);
        $this->sCustomergroup = $this->sGetCustomergroup($this->sSettings['customergroupID']);

        $this->articleMediaAlbum = $this->getMediaRepository()
            ->getAlbumWithSettingsQuery(-1)
            ->getOneOrNullResult(AbstractQuery::HYDRATE_OBJECT);

        if ($this->sCurrency === false) {
            throw new RuntimeException('Currency could not be fetched correctly.');
        }
        $currency = Shopware()->Models()->getRepository(Currency::class)->find($this->sCurrency['id']);
        $shop->setCurrency($currency);
        Shopware()->Container()->get(ShopRegistrationServiceInterface::class)->registerShop($shop);

        if ($this->sCustomergroup !== false) {
            
Home | Imprint | This part of the site doesn't use cookies.