setMediaId example

if ($mediaConfig && $mediaConfig->getValue()) {
            $this->addMediaEntity($slot$image$result$mediaConfig$resolverContext);
        }
    }

    private function addMediaEntity(CmsSlotEntity $slot, ImageStruct $image, ElementDataCollection $result, FieldConfig $config, ResolverContext $resolverContext): void
    {
        if ($config->isMapped() && $resolverContext instanceof EntityResolverContext) {
            $media = $this->resolveEntityValue($resolverContext->getEntity()$config->getStringValue());

            if ($media instanceof MediaEntity) {
                $image->setMediaId($media->getUniqueIdentifier());
                $image->setMedia($media);
            }
        }

        if ($config->isStatic()) {
            $image->setMediaId($config->getStringValue());

            $searchResult = $result->get('media_' . $slot->getUniqueIdentifier());
            if (!$searchResult) {
                return;
            }

            
$newTabConfig = $config->get('newTab');
        if ($newTabConfig !== null) {
            $manufacturerStruct->setNewTab($newTabConfig->getBoolValue());
        }

        $mediaConfig = $config->get('media');

        if ($mediaConfig !== null) {
            $media = $this->getMedia($slot$result$mediaConfig$resolverContext);
            if ($media !== null) {
                $manufacturerStruct->setMedia($media);
                $manufacturerStruct->setMediaId($media->getId());
            }
        }

        if ($resolverContext instanceof EntityResolverContext && $resolverContext->getDefinition() instanceof SalesChannelProductDefinition) {
            /** @var SalesChannelProductEntity $product */
            $product = $resolverContext->getEntity();
            $manufacturerStruct->setManufacturer($product->getManufacturer());
        }
    }

    private function getConfigUrl(FieldConfig $config, ResolverContext $resolverContext): ?string
    {
protected function getProductMediaCollection(): ProductMediaCollection
    {
        $productMedia = [];
        for ($i = 4; $i >= 0; --$i) {
            $mediaId = 'media' . $i;
            $mediaEntity = new MediaEntity();
            $mediaEntity->setId($mediaId);

            $tempProductMedia = new ProductMediaEntity();
            $tempProductMedia->setId($mediaId);
            $tempProductMedia->setMediaId($mediaId);
            $tempProductMedia->setMedia($mediaEntity);
            $tempProductMedia->setPosition($i);

            $productMedia[] = $tempProductMedia;
        }

        return new ProductMediaCollection($productMedia);
    }

    protected function getResolverContext(ProductMediaCollection $productMediaCollection, ?string $coverId = null): EntityResolverContext
    {
        
$orderLineItem->setId('order-line-item-id');
        $orderLineItem->setQuantity(1);
        $orderLineItem->setType('order-line-item-type');
        $orderLineItem->setLabel('order-line-item-label');
        $orderLineItem->setGood(true);
        $orderLineItem->setRemovable(false);
        $orderLineItem->setStackable(true);

        if ($toManipulate === 'order-add-line-item-download') {
            $orderLineItemDownload = new OrderLineItemDownloadEntity();
            $orderLineItemDownload->setId(Uuid::randomHex());
            $orderLineItemDownload->setMediaId(Uuid::randomHex());

            $orderLineItemDownloadCollection = new OrderLineItemDownloadCollection();
            $orderLineItemDownloadCollection->add($orderLineItemDownload);
            $orderLineItem->setDownloads($orderLineItemDownloadCollection);
        }

        $orderLineItemCollection = new OrderLineItemCollection();
        $orderLineItemCollection->add($orderLineItem);

        // Order delivery position         $orderDeliveryPositionCollection = new OrderDeliveryPositionCollection();
        
$media = $this->mediaResolver->getDefaultCmsMediaEntity($config->getStringValue());

            if ($media) {
                $image->setMedia($media);
            }
        }

        if ($config->isMapped() && $resolverContext instanceof EntityResolverContext) {
            $media = $this->resolveEntityValue($resolverContext->getEntity()$config->getStringValue());

            if ($media instanceof MediaEntity) {
                $image->setMediaId($media->getUniqueIdentifier());
                $image->setMedia($media);
            }
        }

        if ($config->isStatic()) {
            $image->setMediaId($config->getStringValue());

            $searchResult = $result->get('media_' . $slot->getUniqueIdentifier());
            if (!$searchResult) {
                return;
            }

            
static::assertEquals([]$payload);
    }

    public function testLoadDownloadsPayload(): void
    {
        $productId = Uuid::randomHex();
        $mediaId = Uuid::randomHex();
        $productDownload = new ProductDownloadEntity();
        $productDownload->setId(Uuid::randomHex());
        $productDownload->setPosition(0);
        $productDownload->setProductId($productId);
        $productDownload->setMediaId($mediaId);
        $productDownload->setMedia(new MediaEntity());

        $entitySearchResult = $this->createMock(EntitySearchResult::class);
        $entitySearchResult->method('getEntities')->willReturn(new EntityCollection([$productDownload]));
        $this->productDownloadRepository
            ->expects(static::once())
            ->method('search')
            ->willReturn($entitySearchResult);

        $lineItems = [
            [
                
Home | Imprint | This part of the site doesn't use cookies.