removeState example


        return $this->getSalesChannel()->getId();
    }

    public function addState(string ...$states): void
    {
        $this->context->addState(...$states);
    }

    public function removeState(string $state): void
    {
        $this->context->removeState($state);
    }

    public function hasState(string ...$states): bool
    {
        return $this->context->hasState(...$states);
    }

    /** * @return string[] */
    public function getStates(): array
    {


            foreach ($transitions as $machine => $toPlace) {
                $this->transitState((string) $machine$orderId(string) $toPlace$context);
            }

            $this->connection->commit();
        } catch (ShopwareHttpException $e) {
            $this->connection->rollBack();
            $this->logger->error($e->getMessage());
        } finally {
            $context->removeState(self::FORCE_TRANSITION);
        }
    }

    /** * @throws IllegalTransitionException * @throws StateMachineException */
    private function transitState(string $machine, string $orderId, string $toPlace, Context $context): void
    {
        if (!$toPlace) {
            return;
        }

        // The lock is maybe not acquired.         if (!$key->hasState(__CLASS__)) {
            return;
        }

        $handle = $key->getState(__CLASS__)[1];

        flock($handle, \LOCK_UN | \LOCK_NB);
        fclose($handle);

        $key->removeState(__CLASS__);
    }

    public function exists(Key $key): bool
    {
        return $key->hasState(__CLASS__);
    }
}


    /** * @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 createPromotion(array $salesChannels): array
    {
        return [
            'id' => Uuid::randomHex(),
            
// dispatch events to trigger indexer and other subscribts         $writes = EntityWrittenContainerEvent::createWithWrittenEvents($result->getWritten()$liveContext->getContext()[]);

        $deletes = EntityWrittenContainerEvent::createWithDeletedEvents($result->getDeleted()$liveContext->getContext()[]);

        if ($deletes->getEvents() !== null) {
            $writes->addEvent(...$deletes->getEvents()->getElements());
        }
        $this->eventDispatcher->dispatch($writes);

        $versionContext->removeState(self::MERGE_SCOPE);
        $liveContext->addState(self::MERGE_SCOPE);
    }

    /** * @return array<string, array<EntityWriteResult>> */
    public function clone(
        EntityDefinition $definition,
        string $id,
        string $newId,
        string $versionId,
        
CartChangedEvent::class => 'cartChanged',
        ];
    }

    public function login(CustomerLoginEvent $event): void
    {
        $event->getSalesChannelContext()->addState(self::STATE_LOGGED_IN);
    }

    public function cartChanged(CartChangedEvent $event): void
    {
        $event->getContext()->removeState(self::STATE_CART_FILLED);

        if ($event->getCart()->getLineItems()->count() > 0) {
            $event->getContext()->addState(self::STATE_CART_FILLED);
        }
    }

    public function setStates(ControllerEvent $event): void
    {
        $request = $event->getRequest();

        if (!$request->attributes->has(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_CONTEXT_OBJECT)) {
            

        $this->cart->addState(...$states);
    }

    /** * `remove()` removes the given state from the cart, if it existed. * * @param string $state The state that should be removed. */
    public function remove(string $state): void
    {
        $this->cart->removeState($state);
    }

    /** * `has()` allows you to check if one or more states are present on the cart. * * @param string ...$states One or more strings that should be checked. * * @return bool Returns true if at least one of the passed states is present on the cart, false otherwise. */
    public function has(string ...$states): bool
    {
        
$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);
        $service->activatePlugin($plugin$context);
    }

    public function testUpdateDeactivatedPluginWithExceptionWithNonStandardLanguage(): void
    {
        static::markTestSkipped('Test causes other Tests to sometimes randomly fail (see NEXT-7763)');
        $this->setNewSystemLanguage($this->iso);
        $this->updateDeactivatedPluginWithException($this->context);
        $this->resetSystemLanguage();
    }
// do not use grouped filters, because the grouped filters are mapped flat and the logical OR/AND are removed         $filter = new AndFilter(array_merge(
            $criteria->getFilters(),
            $criteria->getPostFilters()
        ));

        $this->addFilter($definition$filter$query$context);

        $this->addQueries($definition$criteria$query$context);

        if ($criteria->getLimit() === 1) {
            $query->removeState(EntityDefinitionQueryHelper::HAS_TO_MANY_JOIN);
        }

        $this->addSortings($definition$criteria$criteria->getSorting()$query$context);

        return $query;
    }

    public function addFilter(EntityDefinition $definition, ?Filter $filter, QueryBuilder $query, Context $context): void
    {
        if (!$filter) {
            return;
        }
$all = array_column($payload, 'id');
        foreach ($payload as $product) {
            if (!isset($product['children'])) {
                continue;
            }
            $all = [...$all, ...array_column($product['children'], 'id')];
        }

        $this->updater->update(ProductDefinition::ENTITY_NAME, $all$context);
        $this->statesUpdater->update($all$context);

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

    private function getTaxes(Context $context): TaxCollection
    {
        /** @var EntityRepository<TaxCollection> $taxRepository */
        $taxRepository = $this->registry->getRepository('tax');

        return $taxRepository->search(new Criteria()$context)->getEntities();
    }

    /** * @param list<string> $manufacturer * @param list<string> $tags * * @return array<string, mixed> */
public function delete(Key $key)
    {
        // The lock is maybe not acquired.         if (!$key->hasState(__CLASS__)) {
            return;
        }

        $resource = $key->getState(__CLASS__);

        sem_remove($resource);

        $key->removeState(__CLASS__);
    }

    /** * @return void */
    public function putOffExpiration(Key $key, float $ttl)
    {
        // do nothing, the semaphore locks forever.     }

    public function exists(Key $key): bool
    {
Home | Imprint | This part of the site doesn't use cookies.