addState example

new SalesChannelContextServiceParameters(
                $context->getSalesChannel()->getId(),
                $newToken,
                $context->getLanguageId(),
                $context->getCurrencyId(),
                $context->getDomainId(),
                $context->getContext(),
                $customer->getId()
            )
        );

        $new->addState(...$context->getStates());

        if ($customer->getGuest()) {
            $this->eventDispatcher->dispatch(new GuestCustomerRegisterEvent($new$customer));
        } else {
            $this->eventDispatcher->dispatch(new CustomerRegisterEvent($new$customer));
        }

        $criteria = new Criteria([$customer->getId()]);
        $criteria->addAssociation('addresses');
        $criteria->addAssociation('salutation');
        $criteria->setLimit(1);

        
$result = $this->client->search([
                'index' => $this->helper->getIndexName($definition$this->helper->enabledMultilingualIndex() ? null : $context->getLanguageId()),
                'body' => $searchArray,
            ]);
        } catch (\Throwable $e) {
            $this->helper->logAndThrowException($e);

            return $this->decorated->aggregate($definition$criteria$context);
        }

        $result = $this->hydrator->hydrate($definition$criteria$context$result);
        $result->addState(self::RESULT_STATE);

        return $result;
    }

    private function createSearch(EntityDefinition $definition, Criteria $criteria, Context $context): Search
    {
        $search = new Search();
        $this->helper->addFilters($definition$criteria$search$context);
        $this->helper->addQueries($definition$criteria$search$context);
        $this->helper->addAggregations($definition$criteria$search$context);
        $this->helper->addTerm($criteria$search$context$definition);
        
private readonly Connection $connection,
        private readonly EventDispatcherInterface $eventDispatcher,
        private readonly AbstractProductCloseoutFilterFactory $productCloseoutFilterFactory
    ) {
    }

    /** * @return EntitySearchResult<ProductCollection> */
    public function load(Criteria $origin, SalesChannelContext $context): EntitySearchResult
    {
        $origin->addState(Criteria::STATE_ELASTICSEARCH_AWARE);
        $criteria = clone $origin;

        $this->addGrouping($criteria);
        $this->handleAvailableStock($criteria$context);

        $ids = $this->productRepository->searchIds($criteria$context);
        /** @var list<string> $keys */
        $keys = $ids->getIds();
        $aggregations = $this->productRepository->aggregate($criteria$context);

        // no products found, no need to continue
NodeType::create([
      'type' => 'example_c',
    ])->save();

    $this->createEditorialWorkflow();

    $new_workflow = Workflow::create([
      'type' => 'content_moderation',
      'id' => 'new_workflow',
      'label' => 'New workflow',
    ]);
    $new_workflow->getTypePlugin()->addState('bar', 'Bar');
    $new_workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'example_c');
    $new_workflow->save();

    $this->drupalLogin($this->drupalCreateUser([
      'administer workflows',
      'administer views',
    ]));

    $this->container->get('module_installer')->install(['content_moderation_test_views']);

    $new_workflow->getTypePlugin()->removeEntityTypeAndBundle('node', 'example_c');
    


        $options = array_merge($options$overrideOptions);

        $salesChannelContext = $this->factory->create(
            Uuid::randomHex(),
            $order->getSalesChannelId(),
            $options
        );

        $salesChannelContext->getContext()->addExtensions($context->getExtensions());
        $salesChannelContext->addState(...$context->getStates());

        if ($context->hasState(Context::SKIP_TRIGGER_FLOW)) {
            $salesChannelContext->getContext()->addState(Context::SKIP_TRIGGER_FLOW);
        }

        if ($order->getItemRounding() !== null) {
            $salesChannelContext->setItemRounding($order->getItemRounding());
        }

        if ($order->getTotalRounding() !== null) {
            $salesChannelContext->setTotalRounding($order->getTotalRounding());
        }
    $this->installConfig('content_moderation_test_views');

    ConfigurableLanguage::createFromLangcode('fr')->save();
  }

  /** * Tests the content moderation state filter. */
  public function testStateFilterViewsRelationship() {
    $workflow = Workflow::load('editorial');
    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'example');
    $workflow->getTypePlugin()->addState('translated_draft', 'Bar');
    $configuration = $workflow->getTypePlugin()->getConfiguration();
    $configuration['states']['translated_draft'] += [
      'published' => FALSE,
      'default_revision' => FALSE,
    ];
    $workflow->getTypePlugin()->setConfiguration($configuration);
    $workflow->save();

    // Create a published default revision and one forward draft revision.     $node = Node::create([
      'type' => 'example',
      

  public function testCheckAccess($user$operation$result$states_to_create = []) {
    $workflow = Workflow::create([
      'type' => 'workflow_type_test',
      'id' => 'test_workflow',
    ]);
    $workflow->save();
    $workflow_type = $workflow->getTypePlugin();
    foreach ($states_to_create as $state_id => $is_required) {
      $workflow_type->addState($state_id$this->randomString());
    }
    \Drupal::state()->set('workflow_type_test.required_states', array_filter($states_to_create));
    $this->assertEquals($result$this->accessControlHandler->access($workflow$operation$this->{$user}, TRUE));
  }

  /** * Data provider for ::testCheckAccess. * * @return array */
  public function checkAccessProvider() {
    
$this->container->get('cache.messenger.restart_workers_signal'),
            Kernel::SHOPWARE_FALLBACK_VERSION,
            $this->systemConfigService,
            $this->container->get(CustomEntityPersister::class),
            $this->container->get(CustomEntitySchemaUpdater::class),
            $this->container->get(CustomEntityLifecycleService::class),
            $this->container->get(PluginService::class),
            $this->container->get(VersionSanitizer::class),
        );

        $context = Context::createDefaultContext();
        $context->addState(PluginLifecycleService::STATE_SKIP_ASSET_BUILDING);

        $this->createPlugin($this->pluginRepo, $context, SwagTest::PLUGIN_OLD_VERSION);

        $plugin = $this->getPlugin($context);
        $service->installPlugin($plugin$context);
        $service->activatePlugin($plugin$context);
        $service->uninstallPlugin($plugin$context);

        $context->removeState(PluginLifecycleService::STATE_SKIP_ASSET_BUILDING);

        $service->installPlugin($plugin$context);
        
$context = $this->context;

            $this->productRepository->upsert([
                (new ProductBuilder($this->ids, 'u7', 300))
                    ->price(100)
                    ->build(),
            ]$context);

            $this->refreshIndex();

            $criteria = new Criteria();
            $criteria->addState(Criteria::STATE_ELASTICSEARCH_AWARE);
            $criteria->addFilter(new EqualsFilter('productNumber', 'u7'));

            // products should be updated immediately             $searcher = $this->createEntitySearcher();
            $result = $searcher->search($this->productDefinition, $criteria$context);
            static::assertCount(1, $result->getIds());

            $this->productRepository->delete([['id' => $ids->get('u7')]]$context);

            $this->refreshIndex();
            $result = $searcher->search($this->productDefinition, $criteria$context);
            
static::assertInstanceOf(ProductEntity::class$v1);
        static::assertTrue($v1->hasExtension('customEntityBlogInheritedLinkProduct'));
        static::assertInstanceOf(ArrayEntity::class$v1->getExtension('customEntityBlogInheritedLinkProduct'));
        static::assertEquals($blog1['id']$v1->getExtension('customEntityBlogInheritedLinkProduct')->getId());

        $v2 = $products->get($ids->get('one-to-one-2'));
        static::assertInstanceOf(ProductEntity::class$v2);
        static::assertTrue($v2->hasExtension('customEntityBlogInheritedLinkProduct'));
        static::assertInstanceOf(ArrayEntity::class$v2->getExtension('customEntityBlogInheritedLinkProduct'));
        static::assertEquals($blog2['id']$v2->getExtension('customEntityBlogInheritedLinkProduct')->getId());

        $context->addState('debug');
        /** @var EntityRepository $blogRepository */
        $blogRepository = $container->get('custom_entity_blog.repository');
        $blogRepository->delete([['id' => $ids->get('inh.one-to-one.2')]]$context);

        $criteria = new Criteria($ids->getList(['one-to-one-2']));
        $criteria->addAssociation('customEntityBlogInheritedLinkProduct');
        $products = $container->get('product.repository')->search($criteria$context);

        $v2 = $products->get($ids->get('one-to-one-2'));
        static::assertInstanceOf(ProductEntity::class$v2);
        static::assertTrue($v1->hasExtension('customEntityBlogInheritedLinkProduct'));
        
$pluginConfigurationFactory,
            $handler,
            $this->createMock(ThemeLifecycleService::class)
        );

        $subscriber->pluginPostActivate($event);
    }

    public function testThemeLifecycleIsNotCalledWhenDeactivatedUsingContextOnActivate(): void
    {
        $context = Context::createDefaultContext();
        $context->addState(PluginLifecycleService::STATE_SKIP_ASSET_BUILDING);
        $event = new PluginPostActivateEvent(
            $this->getPlugin(),
            new ActivateContext(
                $this->createMock(Plugin::class),
                $context,
                '6.1.0',
                '1.0.0',
                $this->createMock(MigrationCollection::class)
            )
        );

        
true,
            'prefix',
            true,
            $this->createMock(Client::class),
            $registry,
            $this->createMock(CriteriaParser::class),
            $this->createMock(LoggerInterface::class),
            $this->createMock(AbstractKeyValueStorage::class)
        );

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

        static::assertTrue(
            $helper->allowSearch(new ProductDefinition(), Context::createDefaultContext()$criteria)
        );

        static::assertFalse(
            $helper->allowSearch(new CategoryDefinition(), Context::createDefaultContext()$criteria)
        );

        $helper->setEnabled(false);

        
$this->write($payload$context);
        }

        $this->io->progressFinish();
    }

    /** * @param list<array<string, mixed>> $payload */
    private function write(array $payload, Context $context): void
    {
        $context->addState(EntityIndexerRegistry::DISABLE_INDEXING);

        $this->registry->getRepository('promotion')->create($payload$context);

        $context->removeState(EntityIndexerRegistry::DISABLE_INDEXING);
    }

    /** * @param list<array<string, string|int>> $salesChannels * * @return array<string, mixed> */
    


    private function addSorting(PopularitySorting $sorting, QueryBuilder $query): void
    {
        if (!$query->hasState(SalesConditionHandler::STATE_INCLUDES_TOPSELLER_TABLE)) {
            $query->leftJoin(
                'product',
                's_articles_top_seller_ro',
                'topSeller',
                'topSeller.article_id = product.id'
            );
            $query->addState(SalesConditionHandler::STATE_INCLUDES_TOPSELLER_TABLE);
        }

        $query->addOrderBy('topSeller.sales', $sorting->getDirection());
    }
}


    /** * @depends testIndexing */
    public function testAndSearch(IdsCollection $ids): void
    {
        $this->setSearchConfiguration(true, ['name']);
        $this->setSearchScores([]);

        $criteria = new Criteria();
        $criteria->addState(Criteria::STATE_ELASTICSEARCH_AWARE);
        $criteria->setTerm('Aerodynamic Leather');
        $criteria->addSorting(new FieldSorting('name', FieldSorting::ASCENDING));

        $result = $this->productRepository->searchIds($criteria, Context::createDefaultContext());

        /** @var string[] $resultIds */
        $resultIds = $result->getIds();

        static::assertCount(3, $resultIds, 'But got ' . $ids->getKeys($resultIds));

        static::assertSame(
            [
Home | Imprint | This part of the site doesn't use cookies.