enrich example

        foreach ($slots as $slotId => $slot) {
            $resolver = $this->resolvers[$slot->getType()] ?? null;
            if (!$resolver) {
                continue;
            }

            $result = new ElementDataCollection();

            $this->mapSearchResults($result$slot$slotCriteriaList$searchResults);
            $this->mapEntities($result$slot$slotCriteriaList$entities);

            $resolver->enrich($slot$resolverContext$result);

            // replace with return value from enrich(), because it's allowed to change the entity type             $slots->set($slotId$slot);
        }

        return $slots;
    }

    /** * @param string[][] $directReads * * @throws InconsistentCriteriaIdsException * * @return array<string, EntitySearchResult<EntityCollection>> */


    public function testEnrichWithoutContext(): void
    {
        $resolverContext = new ResolverContext($this->createMock(SalesChannelContext::class)new Request());
        $result = new ElementDataCollection();

        $slot = new CmsSlotEntity();
        $slot->setUniqueIdentifier('id');
        $slot->setType('manufacturer-logo');

        $this->manufacturerLogoCmsElementResolver->enrich($slot$resolverContext$result);

        /** @var ManufacturerLogoStruct|null $manufacturerLogoStruct */
        $manufacturerLogoStruct = $slot->getData();
        static::assertInstanceOf(ManufacturerLogoStruct::class$manufacturerLogoStruct);
        static::assertNull($manufacturerLogoStruct->getManufacturer());
    }

    public function testEnrichEntityResolverContext(): void
    {
        $manufacturer = new ProductManufacturerEntity();
        $manufacturer->setId('manufacturer_01');
        
$resolverContext->getSalesChannelContext()->getContext()
        ));

        $fieldConfig = new FieldConfigCollection();
        $fieldConfig->add(new FieldConfig('products', FieldConfig::SOURCE_STATIC, 'product'));

        $slot = new CmsSlotEntity();
        $slot->setUniqueIdentifier('product_id');
        $slot->setType('');
        $slot->setFieldConfig($fieldConfig);

        $productSliderResolver->enrich($slot$resolverContext$result);

        /** @var ProductSliderStruct|null $productSliderStruct */
        $productSliderStruct = $slot->getData();

        static::assertInstanceOf(ProductSliderStruct::class$productSliderStruct);

        $products = $productSliderStruct->getProducts();
        static::assertNotNull($products);

        /* * conditional assertions depending on if an product should be returned or not */
if (!$response instanceof StoreApiResponse) {
            return;
        }

        if (!$event->getRequest()->headers->has(PlatformRequest::HEADER_INCLUDE_SEO_URLS)) {
            return;
        }

        $dataBag = new SeoResolverData();

        $this->find($dataBag$response->getObject());
        $this->enrich($dataBag$event->getRequest()->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_CONTEXT_OBJECT));
    }

    private function find(SeoResolverData $data, Struct $struct): void
    {
        if ($struct instanceof AggregationResultCollection) {
            foreach ($struct as $item) {
                $this->findStruct($data$item);
            }
        }

        if ($struct instanceof EntitySearchResult) {
            


    public function testEnrichWithoutContext(): void
    {
        $resolverContext = new ResolverContext($this->createMock(SalesChannelContext::class)new Request());
        $result = new ElementDataCollection();

        $slot = new CmsSlotEntity();
        $slot->setUniqueIdentifier('id');
        $slot->setType('product-name');

        $this->productNameCmsElementResolver->enrich($slot$resolverContext$result);

        /** @var TextStruct|null $textStruct */
        $textStruct = $slot->getData();
        static::assertInstanceOf(TextStruct::class$textStruct);
        static::assertNull($textStruct->getContent());
    }

    public function testEnrichEntityResolverContext(): void
    {
        $product = new SalesChannelProductEntity();
        $product->setId('product_01');
        
public function testEnrichWithEmptyConfig(): void
    {
        $resolverContext = new ResolverContext($this->createMock(SalesChannelContext::class)new Request());
        $result = new ElementDataCollection();

        $slot = new CmsSlotEntity();
        $slot->setUniqueIdentifier('id');
        $slot->setType('text');
        $slot->setConfig([]);
        $slot->setFieldConfig(new FieldConfigCollection());

        $this->textResolver->enrich($slot$resolverContext$result);

        /** @var TextStruct|null $textStruct */
        $textStruct = $slot->getData();
        static::assertInstanceOf(TextStruct::class$textStruct);
        static::assertNull($textStruct->getContent());
    }

    public function testWithStaticContent(): void
    {
        $resolverContext = new ResolverContext($this->createMock(SalesChannelContext::class)new Request());
        $result = new ElementDataCollection();

        
/** * @param array<string, EntityDefinition>|array<string, EntityDefinition&SalesChannelDefinitionInterface> $definitions * * @return OpenApiSpec */
    public function generate(array $definitions, string $api, string $apiType = DefinitionService::TYPE_JSON_API, ?string $bundleName = null): array
    {
        $forSalesChannel = $this->containsSalesChannelDefinition($definitions);

        $openApi = new OpenApi([]);
        $this->openApiBuilder->enrich($openApi$api);

        ksort($definitions);

        foreach ($definitions as $definition) {
            if (!$this->shouldDefinitionBeIncluded($definition)) {
                continue;
            }

            $onlyFlat = match ($apiType) {
                DefinitionService::TYPE_JSON => true,
                default => $this->shouldIncludeReferenceOnly($definition$forSalesChannel),
            };
public function testEnrichWithEmptyConfig(): void
    {
        $resolverContext = new ResolverContext($this->createMock(SalesChannelContext::class)new Request());
        $result = new ElementDataCollection();

        $slot = new CmsSlotEntity();
        $slot->setUniqueIdentifier('id');
        $slot->setType('image');
        $slot->setConfig([]);
        $slot->setFieldConfig(new FieldConfigCollection());

        $this->imageResolver->enrich($slot$resolverContext$result);

        /** @var ImageStruct|null $imageStruct */
        $imageStruct = $slot->getData();
        static::assertInstanceOf(ImageStruct::class$imageStruct);
        static::assertEmpty($imageStruct->getUrl());
        static::assertEmpty($imageStruct->getMedia());
        static::assertEmpty($imageStruct->getMediaId());
    }

    public function testEnrichWithUrlOnly(): void
    {
        
public function testEnrichCmsAwareAffectedEntities(): void
    {
        static::markTestSkipped('cms-aware will be re-implemented via NEXT-22697');
        static::assertCount(4, $this->customEntities);

        foreach ($this->customEntities as $entity) {
            static::assertCount(4, $entity->getFields());
            static::assertCount(0, $entity->getFlags());
        }

        $enrichedEntities = $this->customEntityEnrichmentService->enrich(
            $this->entitySchema,
            null
        );
        static::assertInstanceOf(CustomEntityXmlSchema::class$enrichedEntities);

        /** @var Entities $outerEnrichedCustomEntities */
        $outerEnrichedCustomEntities = $enrichedEntities->getEntities();
        $enrichedCustomEntities = $outerEnrichedCustomEntities->getEntities();

        foreach ($enrichedCustomEntities as $enrichedCustomEntity) {
            if (!\in_array($enrichedCustomEntity->getName(), self::EXPECTED_CMS_AWARE_ENTITY_NAMES, true)) {
                
$lineItem->setDataTimestamp(null);

                        continue;
                    }
                    $lineItem->setDataTimestamp(new \DateTimeImmutable());
                    $lineItem->setDataContextHash($hash);
                }
            }

            foreach ($lineItems as $match) {
                // enrich all products in original cart                 $this->enrich($context$match['item']$data$behavior);

                // remove "parent" products which should never be displayed in storefront                 $this->validateParents($match['item']$data$match['scope']);

                // validate data timestamps that inactive products (or not assigned to sales channel) are removed                 $this->validateTimestamp($match['item']$original$data$behavior$match['scope']);

                // validate availability of the product stock                 $this->validateStock($match['item']$original$match['scope']$behavior);
            }

            
$this->schemaPath = $bundles['Framework']['path'] . '/Api/ApiDefinition/Generator/Schema/StoreApi';
    }

    public function supports(string $format, string $api): bool
    {
        return $format === self::FORMAT && $api === DefinitionService::STORE_API;
    }

    public function generate(array $definitions, string $api, string $apiType, ?string $bundleName): array
    {
        $openApi = new OpenApi([]);
        $this->openApiBuilder->enrich($openApi$api);

        $forSalesChannel = $api === DefinitionService::STORE_API;

        ksort($definitions);

        foreach ($definitions as $definition) {
            if (!$definition instanceof EntityDefinition) {
                continue;
            }

            if (!$this->shouldDefinitionBeIncluded($definition)) {
                
public function testEnrichWithEmptyConfig(): void
    {
        $resolverContext = new ResolverContext($this->createMock(SalesChannelContext::class)new Request());
        $result = new ElementDataCollection();

        $slot = new CmsSlotEntity();
        $slot->setUniqueIdentifier('id');
        $slot->setType('buy-box');
        $slot->setFieldConfig(new FieldConfigCollection());

        $this->buyBoxResolver->enrich($slot$resolverContext$result);

        /** @var BuyBoxStruct|null $buyBoxStruct */
        $buyBoxStruct = $slot->getData();
        static::assertInstanceOf(BuyBoxStruct::class$buyBoxStruct);
        static::assertNull($buyBoxStruct->getProductId());
        static::assertNull($buyBoxStruct->getProduct());
    }

    public function testEnrichWithStaticConfig(): void
    {
        $product = new SalesChannelProductEntity();
        
static::assertEquals('form', $formCmsElementResolver->getType());
    }

    public function testResolverUsesAbstractSalutationsRouteToEnrichSlot(): void
    {
        $salutationCollection = $this->getSalutationCollection();
        $formCmsElementResolver = new FormCmsElementResolver($this->getSalutationRoute($salutationCollection));

        $formElement = $this->getCmsFormElement();

        $formCmsElementResolver->enrich(
            $formElement,
            new ResolverContext($this->createMock(SalesChannelContext::class)new Request()),
            new ElementDataCollection()
        );

        static::assertSame($formElement->getData()$salutationCollection);
    }

    public function testResolverSortsSalutationsBySalutationKeyDesc(): void
    {
        $salutationCollection = $this->getSalutationCollection();
        


    public function testEnrichWithoutContext(): void
    {
        $resolverContext = new ResolverContext($this->createMock(SalesChannelContext::class)new Request());
        $result = new ElementDataCollection();

        $slot = new CmsSlotEntity();
        $slot->setUniqueIdentifier('id');
        $slot->setType('product-description-reviews');

        $this->productDescriptionReviewResolver->enrich($slot$resolverContext$result);

        /** @var ProductDescriptionReviewsStruct|null $productDescriptionReviewStruct */
        $productDescriptionReviewStruct = $slot->getData();
        static::assertInstanceOf(ProductDescriptionReviewsStruct::class$productDescriptionReviewStruct);
        static::assertNull($productDescriptionReviewStruct->getProduct());
    }
}
$appId
        );
    }

    private function update(string $pathToCustomEntityFile, string $extensionEntityType, string $extensionId): ?CustomEntityXmlSchema
    {
        $customEntityXmlSchema = $this->getXmlSchema($pathToCustomEntityFile);
        if ($customEntityXmlSchema === null) {
            return null;
        }

        $customEntityXmlSchema = $this->customEntityEnrichmentService->enrich(
            $customEntityXmlSchema,
            $this->getAdminUiXmlSchema($pathToCustomEntityFile),
        );

        $this->customEntityPersister->update($customEntityXmlSchema->toStorage()$extensionEntityType$extensionId);
        $this->customEntitySchemaUpdater->update();

        return $customEntityXmlSchema;
    }

    private function getXmlSchema(string $pathToCustomEntityFile): ?CustomEntityXmlSchema
    {
Home | Imprint | This part of the site doesn't use cookies.