hasState example

 {
    }

    public function getDecorated(): AbstractProductSearchRoute
    {
        return $this->decorated;
    }

    #[Route(path: '/store-api/search', name: 'store-api.search', methods: ['POST'], defaults: ['_entity' => 'product'])]     public function load(Request $request, SalesChannelContext $context, Criteria $criteria): ProductSearchRouteResponse
    {
        if ($context->hasState(...$this->states)) {
            return $this->getDecorated()->load($request$context$criteria);
        }

        $key = $this->generateKey($request$context$criteria);

        if ($key === null) {
            return $this->getDecorated()->load($request$context$criteria);
        }

        $value = $this->cache->get($keyfunction DItemInterface $item) use ($request$context$criteria) {
            $response = $this->tracer->trace(self::NAME, fn () => $this->getDecorated()->load($request$context$criteria));

            
', 2)';
    }

    /** * {@inheritdoc} */
    public function joinPrices(
        QueryBuilder $query,
        ShopContextInterface $context
    ) {
        if ($query->hasState(self::STATE_INCLUDES_CHEAPEST_PRICE)) {
            return;
        }

        $this->joinDefaultPrices($query$context);

        $graduation = 'customerPrice.from = 1';
        if ($this->config->get('useLastGraduationForCheapestPrice')) {
            $graduation = "IF(priceGroup.id IS NOT NULL, customerPrice.from = 1, customerPrice.to = 'beliebig')";
        }

        $query->leftJoin(
            
if (!$field instanceof TranslatedField) {
            return $context->getAlias();
        }

        $definition = $context->getDefinition();
        $translationDefinition = $definition->getTranslationDefinition();
        if (!$translationDefinition) {
            throw new \RuntimeException(sprintf('Can not detect translation definition of entity %s', $definition->getEntityName()));
        }

        $alias = $context->getAlias() . '.' . $definition->getEntityName() . '_translation';
        if ($context->getQuery()->hasState($alias)) {
            return $alias;
        }
        $context->getQuery()->addState($alias);

        $variables = [
            '#alias#' => EntityDefinitionQueryHelper::escape($alias),
            '#foreignKey#' => EntityDefinitionQueryHelper::escape($definition->getEntityName() . '_id'),
            '#on#' => EntityDefinitionQueryHelper::escape($context->getAlias()),
        ];

        $rootVersionFieldName = null;
        


    public function getDecorated(): AbstractCategoryRoute
    {
        return $this->decorated;
    }

    #[Route(path: '/store-api/category/{navigationId}', name: 'store-api.category.detail', methods: ['GET', 'POST'])]     public function load(string $navigationId, Request $request, SalesChannelContext $context): CategoryRouteResponse
    {
        return Profiler::trace('category-route', function D) use ($navigationId$request$context) {
            if ($context->hasState(...$this->states)) {
                return $this->getDecorated()->load($navigationId$request$context);
            }

            $key = $this->generateKey($navigationId$request$context);

            if ($key === null) {
                return $this->getDecorated()->load($navigationId$request$context);
            }

            $value = $this->cache->get($keyfunction DItemInterface $item) use ($navigationId$request$context) {
                $name = self::buildName($navigationId);

                
return $sorting instanceof SearchRankingSorting;
    }

    /** * {@inheritdoc} */
    public function generateSorting(
        SortingInterface $sorting,
        QueryBuilder $query,
        ShopContextInterface $context
    ) {
        if (!$query->hasState(SearchTermConditionHandler::STATE_INCLUDES_RANKING)) {
            return;
        }

        $this->addSorting($sorting$query);
    }

    private function addSorting(SearchRankingSorting $sorting, QueryBuilder $query): void
    {
        $query->addOrderBy('searchTable.ranking', $sorting->getDirection());
    }
}
$this->joinListingPrices($query$context$criteria);
        } else {
            $this->joinSalePrices($query$context$criteria);
        }
    }

    /** * {@inheritdoc} */
    public function joinVariants(QueryBuilder $query)
    {
        if ($query->hasState(self::VARIANTS_JOINED)) {
            return;
        }

        $query->innerJoin(
            'product',
            's_articles_details',
            'allVariants',
            'allVariants.articleID = product.id AND allVariants.active = 1'
        );

        $query->addState(self::VARIANTS_JOINED);
    }

    public function supportsSorting(SortingInterface $sorting)
    {
        return $sorting instanceof ManualSorting;
    }

    /** * {@inheritdoc} */
    public function generateSorting(SortingInterface $sorting, QueryBuilder $query, ShopContextInterface $context)
    {
        if (!$query->hasState(CategoryConditionHandler::STATE_NAME)) {
            return;
        }

        $this->addSorting($sorting$query);
    }

    private function addSorting(ManualSorting $sorting, QueryBuilder $query): void
    {
        $query->leftJoin(
            CategoryConditionHandler::STATE_NAME,
            's_categories_manual_sorting',
            


    public function testRestoreByCustomerPassesStates(): void
    {
        $context = Context::createDefaultContext();
        $context->addState('foo');

        $ids = new TestDataCollection();
        $this->createOrder($ids);

        $saleChanelContext = $this->contextRestorer->restoreByCustomer($this->createCustomer()->getId()$context);
        static::assertTrue($saleChanelContext->getContext()->hasState('foo'));
    }

    public function testOrderCriteriaEventIsFired(): void
    {
        $context = Context::createDefaultContext();
        $ids = new TestDataCollection();
        $this->createOrder($ids);

        $this->eventDispatcher->addListener(SalesChannelContextRestorerOrderCriteriaEvent::class$this->callbackFn);
        $this->contextRestorer->restoreByOrder($ids->create('order')$context);

        
$this->states = array_unique($states);
    }

    public function getDecorated(): AbstractProductReviewRoute
    {
        return $this->decorated;
    }

    #[Route(path: '/store-api/product/{productId}/reviews', name: 'store-api.product-review.list', methods: ['POST'], defaults: ['_entity' => 'product_review'])]     public function load(string $productId, Request $request, SalesChannelContext $context, Criteria $criteria): ProductReviewRouteResponse
    {
        if ($context->hasState(...$this->states)) {
            return $this->getDecorated()->load($productId$request$context$criteria);
        }

        $key = $this->generateKey($productId$request$context$criteria);

        $value = $this->cache->get($keyfunction DItemInterface $item) use ($productId$request$context$criteria) {
            $name = self::buildName($productId);
            $response = $this->tracer->trace($namefn () => $this->getDecorated()->load($productId$request$context$criteria));

            $item->tag($this->generateTags($productId$request$response$context$criteria));

            

        if ($criteria->getGroupFields()) {
            foreach ($criteria->getGroupFields() as $grouping) {
                $accessor = $this->queryHelper->getFieldAccessor($grouping->getField()$definition$definition->getEntityName()$context);

                $query->addGroupBy($accessor);
            }

            return;
        }

        if ($query->hasState(EntityDefinitionQueryHelper::HAS_TO_MANY_JOIN)) {
            $query->addGroupBy(
                EntityDefinitionQueryHelper::escape($table) . '.' . EntityDefinitionQueryHelper::escape('id')
            );
        }
    }

    private function sortByIdArray(array $ids, array $data): array
    {
        $sorted = [];

        foreach ($ids as $id) {
            
#[Package('core')] class ManyToManyAssociationFieldResolver extends AbstractFieldResolver
{
    public function join(FieldResolverContext $context): string
    {
        $field = $context->getField();
        if (!$field instanceof ManyToManyAssociationField) {
            throw new \InvalidArgumentException('Expected ' . ManyToManyAssociationField::class);
        }

        $alias = $context->getAlias() . '.' . $field->getPropertyName();
        if ($context->getQuery()->hasState($alias)) {
            return $alias;
        }
        $context->getQuery()->addState($alias);
        $context->getQuery()->addState(EntityDefinitionQueryHelper::HAS_TO_MANY_JOIN);

        $mappingAlias = $alias . '.mapping';

        $source = $this->getMappingSourceColumn($context->getAlias()$field$context->getContext());

        $parameters = [
            '#root#' => EntityDefinitionQueryHelper::escape($context->getAlias()),
            
$this->getSession()->reload();
    $this->assertSession()->elementContains('css', 'tr[data-drupal-selector="edit-states-published"]', 'Delete');
    $this->assertSession()->linkByHrefExists($published_delete_link);
    $this->assertSession()->linkByHrefExists($draft_delete_link);

    // Delete the Draft state.     $this->clickLink('Delete');
    $this->assertSession()->pageTextContains('Are you sure you want to delete Draft from Test?');
    $this->submitForm([], 'Delete');
    $this->assertSession()->pageTextContains('State Draft deleted.');
    $workflow = $workflow_storage->loadUnchanged('test');
    $this->assertFalse($workflow->getTypePlugin()->hasState('draft'), 'Draft state deleted');
    $this->assertTrue($workflow->getTypePlugin()->hasState('published'), 'Workflow still has published state');

    // The last state cannot be deleted so the only delete link on the page will     // be for the workflow.     $this->assertSession()->linkByHrefNotExists($published_delete_link);
    $this->clickLink('Delete');
    $this->assertSession()->pageTextContains('Are you sure you want to delete Test?');
    $this->submitForm([], 'Delete');
    $this->assertSession()->pageTextContains('Workflow Test deleted.');
    $this->assertSession()->pageTextContains('There are no workflows yet.');
    $this->assertNull($workflow_storage->loadUnchanged('test'), 'The test workflow has been deleted');

    
return 'salutation-route';
    }

    public function getDecorated(): AbstractSalutationRoute
    {
        return $this->decorated;
    }

    #[Route(path: '/store-api/salutation', name: 'store-api.salutation', methods: ['GET', 'POST'], defaults: ['_entity' => 'salutation'])]     public function load(Request $request, SalesChannelContext $context, Criteria $criteria): SalutationRouteResponse
    {
        if ($context->hasState(...$this->states)) {
            return $this->getDecorated()->load($request$context$criteria);
        }

        $key = $this->generateKey($request$context$criteria);

        if ($key === null) {
            return $this->getDecorated()->load($request$context$criteria);
        }

        $value = $this->cache->get($keyfunction DItemInterface $item) use ($request$context$criteria) {
            $name = self::buildName();

            
$request = new Request();

            $criteria = new Criteria();
            $criteria->addState(Criteria::STATE_ELASTICSEARCH_AWARE);

            $result = $this->getContainer()->get(ProductListingRoute::class)
                ->load($context->getSalesChannel()->getNavigationCategoryId()$request$context$criteria);

            $listing = $result->getResult();

            // ensure that all data loaded by elastic search             static::assertTrue($listing->hasState(ElasticsearchEntitySearcher::RESULT_STATE));
            static::assertTrue($listing->getAggregations()->hasState(ElasticsearchEntityAggregator::RESULT_STATE));

            static::assertTrue($listing->getTotal() > 0);
            static::assertTrue($listing->getAggregations()->has('shipping-free'));
            static::assertTrue($listing->getAggregations()->has('rating'));
            static::assertTrue($listing->getAggregations()->has('price'));
            static::assertTrue($listing->getAggregations()->has('properties'));
            static::assertTrue($listing->getAggregations()->has('manufacturer'));
        } catch (\Exception $e) {
            static::tearDown();

            


        if ($this->redis instanceof \Predis\ClientInterface) {
            return $this->redis->eval(...array_merge([$script, 1, $resource]$args));
        }

        throw new InvalidArgumentException(sprintf('"%s()" expects being initialized with a Redis, Relay, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, get_debug_type($this->redis)));
    }

    private function getUniqueToken(Key $key): string
    {
        if (!$key->hasState(__CLASS__)) {
            $token = base64_encode(random_bytes(32));
            $key->setState(__CLASS__, $token);
        }

        return $key->getState(__CLASS__);
    }
}
Home | Imprint | This part of the site doesn't use cookies.