getUniqueIdentifier example


        $product = $this->productRepository->search(new Criteria([$productId])$context)->get($productId);

        if (!$product) {
            throw new ProductNotFoundException($productId);
        }
    }

    private function checkVersion(Entity $entity): void
    {
        if ($entity->getVersionId() === Defaults::LIVE_VERSION) {
            throw OrderException::canNotRecalculateLiveVersion($entity->getUniqueIdentifier());
        }
    }

    /** * @throws AddressNotFoundException * @throws OrderException * @throws InconsistentCriteriaIdsException */
    private function validateOrderAddress(string $orderAddressId, Context $context): void
    {
        $address = $this->orderAddressRepository->search(new Criteria([$orderAddressId])$context)->get($orderAddressId);
        
$result->setMetaData($metaData);

        $fields = new ResponseFields($criteria->getIncludes());

        $this->encodeData($fields$definition$data$result);

        return $this->formatToJson($result);
    }

    protected function serializeEntity(ResponseFields $fields, Entity $entity, EntityDefinition $definition, JsonApiEncodingResult $result, bool $isRelationship = false): void
    {
        if ($result->containsInData($entity->getUniqueIdentifier()$definition->getEntityName())
            || ($isRelationship && $result->containsInIncluded($entity->getUniqueIdentifier()$definition->getEntityName()))
        ) {
            return;
        }

        $self = $result->getBaseUrl() . '/' . $this->camelCaseToSnailCase($definition->getEntityName()) . '/' . $entity->getUniqueIdentifier();

        $serialized = clone $this->createSerializedEntity($fields$definition$result);
        $serialized->addLink('self', $self);
        $serialized->merge($entity);

        

  public function getFieldStorageDefinitions() {
    return $this->state->get('field.storage.deleted', []);
  }

  /** * {@inheritdoc} */
  public function addFieldDefinition(FieldDefinitionInterface $field_definition) {
    $deleted_field_definitions = $this->state->get('field.field.deleted', []);
    $deleted_field_definitions[$field_definition->getUniqueIdentifier()] = $field_definition;
    $this->state->set('field.field.deleted', $deleted_field_definitions);

    return $this;
  }

  /** * {@inheritdoc} */
  public function addFieldStorageDefinition(FieldStorageDefinitionInterface $field_storage_definition) {
    $deleted_storage_definitions = $this->state->get('field.storage.deleted', []);
    $deleted_storage_definitions[$field_storage_definition->getUniqueStorageIdentifier()] = $field_storage_definition;
    
$grouped = [];
        foreach ($data as $entity) {
            $fk = $entity->get($propertyName);

            $grouped[$fk][] = $entity;
        }

        // assign loaded data to root entities         foreach ($collection as $entity) {
            $structData = new $collectionClass();
            if (isset($grouped[$entity->getUniqueIdentifier()])) {
                $structData->fill($grouped[$entity->getUniqueIdentifier()]);
            }

            // assign data of child immediately             if ($association->is(Extension::class)) {
                $entity->addExtension($association->getPropertyName()$structData);
            } else {
                // otherwise the data will be assigned directly as properties                 $entity->assign([$association->getPropertyName() => $structData]);
            }

            
new ProductCollection([$productEntity]),
                    null,
                    new Criteria(),
                    $this->context->getContext()
                )
            );

        $result = $this->route->load('1', new Request()$this->context, new Criteria());

        static::assertInstanceOf(ProductDetailRouteResponse::class$result);
        static::assertEquals('4', $result->getProduct()->getCmsPageId());
        static::assertEquals('mainVariant', $result->getProduct()->getUniqueIdentifier());
    }

    public function testLoadBestVariant(): void
    {
        $productEntity = new SalesChannelProductEntity();
        $productEntity->setCmsPageId('4');
        $productEntity->setId($this->idsCollection->create('product1'));
        $productEntity->setUniqueIdentifier('BestVariant');

        $idsSearchResult = new IdSearchResult(
            1,
            [
return new EntitySearchResult($this->definition->getEntityName()$ids->getTotal()new $collection()$aggregations$criteria$salesChannelContext->getContext());
        }

        $readCriteria = $criteria->cloneForRead($ids->getIds());

        $entities = $this->read($readCriteria$salesChannelContext);

        $search = $ids->getData();

        foreach ($entities as $element) {
            if (!\array_key_exists($element->getUniqueIdentifier()$search)) {
                continue;
            }

            $data = $search[$element->getUniqueIdentifier()];
            unset($data['id']);

            if (empty($data)) {
                continue;
            }

            $element->addExtension('search', new ArrayEntity($data));
        }
public function collect(CmsSlotEntity $slot, ResolverContext $resolverContext): ?CriteriaCollection
    {
        $mediaConfig = $slot->getFieldConfig()->get('media');
        if ($mediaConfig === null || $mediaConfig->isMapped() || $mediaConfig->getValue() === null) {
            return parent::collect($slot$resolverContext);
        }

        $criteria = new Criteria([$mediaConfig->getStringValue()]);

        $criteriaCollection = parent::collect($slot$resolverContext) ?? new CriteriaCollection();
        $criteriaCollection->add('media_' . $slot->getUniqueIdentifier(), MediaDefinition::class$criteria);

        return $criteriaCollection;
    }

    public function enrich(CmsSlotEntity $slot, ResolverContext $resolverContext, ElementDataCollection $result): void
    {
        $config = $slot->getFieldConfig();
        $manufacturerStruct = new ManufacturerLogoStruct();
        $slot->setData($manufacturerStruct);

        $urlConfig = $config->get('url');
        
Criteria $criteria,
        Entity $entity,
        EntityDefinition $definition,
        Request $request,
        Context $context,
        bool $setLocationHeader = false
    ): Response {
        $headers = [];

        $entityBaseUrl = $this->getEntityBaseUrl($request$definition);
        if ($setLocationHeader) {
            $headers['Location'] = $entityBaseUrl . '/' . $entity->getUniqueIdentifier();
        }

        $rootNode = [
            'links' => [
                'self' => $request->getUri(),
            ],
        ];

        $response = $this->serializer->encode(
            $criteria,
            $definition,
            
$partialEvent = $events->first();

        static::assertInstanceOf(PartialEntityLoadedEvent::class$partialEvent);

        $partialCollection = $partialEvent->getEntities();

        static::assertCount(1, $partialCollection);

        $partialEntity = $partialCollection[0];
        static::assertInstanceOf(PartialEntity::class$partialEntity);
        static::assertSame('test', $partialEntity->getUniqueIdentifier());
    }

    public function testGetDefinition(): void
    {
        $definition = new ProductDefinition();

        $repo = new EntityRepository(
            $definition,
            $this->createMock(EntityReaderInterface::class),
            $this->createMock(VersionManager::class),
            $this->createMock(EntitySearcherInterface::class),
            
foreach ($slots as $slot) {
            $resolver = $this->resolvers[$slot->getType()] ?? null;
            if (!$resolver) {
                continue;
            }

            $collection = $resolver->collect($slot$resolverContext);
            if ($collection === null) {
                continue;
            }

            $slotCriteriaList[$slot->getUniqueIdentifier()] = $collection;
        }

        // reduce search requests by combining mergeable criteria objects         [$directReads$searches] = $this->optimizeCriteriaObjects($slotCriteriaList);

        // fetch data from storage         $entities = $this->fetchByIdentifier($directReads$resolverContext->getSalesChannelContext());
        $searchResults = $this->fetchByCriteria($searches$resolverContext->getSalesChannelContext());

        // create result for each slot with the requested data         foreach ($slots as $slotId => $slot) {
            

    /** * @internal */
    public function __construct(
        protected Entity|LineItem $item,
        protected CalculatedPrice $price,
        protected ScriptPriceStubs $priceStubs,
        protected SalesChannelContext $context
    ) {
        if (!$this->price instanceof CalculatedCheapestPrice) {
            throw ProductException::invalidCheapestPriceFacade($this->item->getUniqueIdentifier());
        }
        if (!$this->item instanceof Entity) {
            throw ProductException::invalidCheapestPriceFacade($this->item->getUniqueIdentifier());
        }
    }

    /** * `reset()` allows to reset the cheapest price to the original price of the product. * * @example pricing-cases/product-pricing.twig 64 1 Reset the product price to default */
    
/** * {@inheritdoc} */
  public function getClass() {
    return $this->getBaseFieldDefinition()->getClass();
  }

  /** * {@inheritdoc} */
  public function getUniqueIdentifier() {
    return $this->getBaseFieldDefinition()->getUniqueIdentifier();
  }

  /** * Gets the base field definition. * * @return \Drupal\Core\Field\BaseFieldDefinition */
  protected function getBaseFieldDefinition() {
    if (!isset($this->baseFieldDefinition)) {
      $fields = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions($this->entity_type);
      $this->baseFieldDefinition = $fields[$this->getName()];
    }
public function collect(CmsSlotEntity $slot, ResolverContext $resolverContext): ?CriteriaCollection
    {
        $mediaConfig = $slot->getFieldConfig()->get('previewMedia');
        if ($mediaConfig === null || $mediaConfig->isMapped() || $mediaConfig->getValue() === null) {
            return null;
        }

        $criteria = new Criteria([$mediaConfig->getStringValue()]);

        $criteriaCollection = new CriteriaCollection();
        $criteriaCollection->add('media_' . $slot->getUniqueIdentifier(), MediaDefinition::class$criteria);

        return $criteriaCollection;
    }

    public function enrich(CmsSlotEntity $slot, ResolverContext $resolverContext, ElementDataCollection $result): void
    {
        $config = $slot->getFieldConfig();
        $image = new ImageStruct();
        $slot->setData($image);

        $mediaConfig = $config->get('previewMedia');
        
/** * @var array<string, mixed> */
    private array $entityMap = [];

    public function add(string $entityName, Entity $entity): void
    {
        if (!isset($this->entityMap[$entityName])) {
            $this->entityMap[$entityName] = [];
        }

        $this->entityMap[$entityName][$entity->getUniqueIdentifier()] = $entity;
    }

    /** * @return array<string|int> */
    public function getEntities(): array
    {
        return array_keys($this->entityMap);
    }

    /** * @return array<string|int> */
$slot = new CmsSlotEntity();
        $slot->setUniqueIdentifier('id');
        $slot->setType('image');
        $slot->setFieldConfig($fieldConfig);

        $criteriaCollection = $this->imageResolver->collect($slot$resolverContext);

        static::assertCount(1, $criteriaCollection);

        $expectedCriteria = new Criteria(['media123']);

        $mediaCriteria = $criteriaCollection->all()[MediaDefinition::class]['media_' . $slot->getUniqueIdentifier()];

        static::assertEquals($expectedCriteria$mediaCriteria);
    }

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

        $slot = new CmsSlotEntity();
        $slot->setUniqueIdentifier('id');
        
Home | Imprint | This part of the site doesn't use cookies.