getStates example

$this->container->get('session')->get('sUserId')
        );

        // Create a list of ids of occurring countries and states         $countryIds = array_unique(array_filter(array_column($addresses, 'countryId')));
        $stateIds = array_unique(array_filter(array_column($addresses, 'stateId')));

        $countryRepository = $this->container->get(CountryGatewayInterface::class);
        $context = $this->container->get(ContextServiceInterface::class)->getShopContext();

        $countries = $countryRepository->getCountries($countryIds$context);
        $states = $countryRepository->getStates($stateIds$context);

        // Apply translations for countries and states to address array, converting them from structs to arrays in the process         foreach ($addresses as &$address) {
            if (\array_key_exists($address['countryId']$countries)) {
                $address['country'] = json_decode(json_encode($countries[$address['countryId']]), true);
            }
            if (\array_key_exists($address['stateId']$states)) {
                $address['state'] = json_decode(json_encode($states[$address['stateId']]), true);
            }
        }
        unset($address);

        
/** * {@inheritdoc} */
  public function buildRow(EntityInterface $entity) {
    /** @var \Drupal\workflows\WorkflowInterface $entity */
    $row['label'] = $entity->label();

    $row['type']['data'] = [
      '#markup' => $entity->getTypePlugin()->label(),
    ];

    $items = array_map([State::class, 'labelCallback']$entity->getTypePlugin()->getStates());
    $row['states']['data'] = [
      '#theme' => 'item_list',
      '#context' => ['list_style' => 'comma-list'],
      '#items' => $items,
    ];

    return $row + parent::buildRow($entity);
  }

  /** * {@inheritdoc} */

        return (new RuleConfig())
            ->operatorSet(RuleConfig::OPERATOR_SET_STRING)
            ->selectField('productState', [
                State::IS_PHYSICAL,
                State::IS_DOWNLOAD,
            ]);
    }

    private function lineItemMatches(LineItem $lineItem): bool
    {
        return RuleComparison::stringArray($this->productState, array_values($lineItem->getStates())$this->operator);
    }
}
$products = $this->productRepository
            ->search(new Criteria($productIds), Context::createDefaultContext())
            ->getEntities();

        $product1 = $products->get($ids->get('product-1'));
        $product2 = $products->get($ids->get('product-2'));
        $product3 = $products->get($ids->get('product-3'));

        static::assertInstanceOf(ProductEntity::class$product1);
        static::assertInstanceOf(ProductEntity::class$product2);
        static::assertInstanceOf(ProductEntity::class$product3);
        static::assertEquals([State::IS_DOWNLOAD]$product1->getStates());
        static::assertEquals([State::IS_PHYSICAL]$product2->getStates());
        static::assertEquals([State::IS_PHYSICAL]$product3->getStates());
    }

    public function prepareProducts(IdsCollection $ids): void
    {
        $products = [
            (new ProductBuilder($ids, 'product-1'))
                ->price(1.0)
                ->add('downloads', [
                    [
                        
if ($lineItem->getGood()) {
                $filtered[] = $lineItem;
            }
        }

        return $filtered;
    }

    public function hasLineItemWithState(string $state): bool
    {
        foreach ($this->buildFlat($this) as $lineItem) {
            if (\in_array($state$lineItem->getStates(), true)) {
                return true;
            }
        }

        return false;
    }

    public function getApiAlias(): string
    {
        return 'order_line_item_collection';
    }

    
/** @var PartialEntity|null $category */
        $category = $this->categoryRepository->search($categoryCriteria$context->getContext())->first();
        if (!$category) {
            throw ProductException::categoryNotFound($categoryId);
        }

        $this->extendCriteria($context$criteria$category);

        $entities = $this->listingLoader->load($criteria$context);

        $result = ProductListingResult::createFrom($entities);
        $result->addState(...$entities->getStates());

        $result->setStreamId($category->get('productStreamId'));

        return new ProductListingRouteResponse($result);
    }

    private function extendCriteria(SalesChannelContext $salesChannelContext, Criteria $criteria, PartialEntity $category): void
    {
        $hasProductStream = $category->get('productAssignmentType') === CategoryDefinition::PRODUCT_ASSIGNMENT_TYPE_PRODUCT_STREAM
            && $category->get('productStreamId') !== null;

        
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);

        
if ($product->getCover()) {
            $lineItem->setCover($product->getCover()->getMedia());
        }

        $deliveryTime = null;
        if ($product->getDeliveryTime() !== null) {
            $deliveryTime = DeliveryTime::createFromEntity($product->getDeliveryTime());
        }

        $weight = $product->getWeight();

        $lineItem->setStates($product->getStates());

        if ($lineItem->hasState(State::IS_PHYSICAL)) {
            $lineItem->setDeliveryInformation(
                new DeliveryInformation(
                    (int) $product->getAvailableStock(),
                    $weight,
                    $product->getShippingFree() === true,
                    $product->getRestockTime(),
                    $deliveryTime,
                    $product->getHeight(),
                    $product->getWidth(),
                    

        $countries = $this->getCountries([$id]$context);

        return array_shift($countries);
    }

    /** * {@inheritdoc} */
    public function getState($id, ShopContextInterface $context)
    {
        $states = $this->getStates([$id]$context);

        return array_shift($states);
    }

    /** * {@inheritdoc} */
    public function getAreas(array $ids, ShopContextInterface $context)
    {
        if (empty($ids)) {
            return [];
        }
new SalesChannelContextServiceParameters(
                $context->getSalesChannel()->getId(),
                $newToken,
                $context->getLanguageId(),
                $context->getCurrencyId(),
                $context->getDomainId(),
                $context->getContext(),
                $customerEntity->getId()
            )
        );

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

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

        $event = new CustomerLoginEvent($new$customerEntity$newToken);
        $this->eventDispatcher->dispatch($event);

        $response->headers->set(PlatformRequest::HEADER_CONTEXT_TOKEN, $newToken);

        


    protected function assertOrderTransactionState(string $state, string $transactionId): void
    {
        $criteria = new Criteria([$transactionId]);
        $criteria->addAssociation('state');

        /** @var OrderTransactionEntity|null $transaction */
        $transaction = $this->orderTransactionRepository->search($criteria$this->context)->first();
        static::assertNotNull($transaction);

        $states = $this->stateMachineRegistry->getStateMachine(OrderTransactionStates::STATE_MACHINE, $this->context)->getStates();
        static::assertNotNull($states);
        $actualState = $states->get($transaction->getStateId());
        static::assertNotNull($actualState);
        static::assertSame($state$actualState->getTechnicalName());
    }

    protected function assertRefundState(string $state, string $refundId): void
    {
        $criteria = new Criteria([$refundId]);
        $criteria->addAssociation('state');

        
'active' => $country->isActive(),
            'iso3' => $country->getIso3(),
            'display_state_in_registration' => $country->displayStateSelection(),
            'force_state_in_registration' => $country->requiresStateSelection(),
            'areaID' => $country->getAreaId(),
            'allow_shipping' => $country->allowShipping(),
            'states' => [],
            'attributes' => $country->getAttributes(),
        ]);

        if ($country->displayStateSelection()) {
            $data['states'] = $this->convertStateStructList($country->getStates());
            $data['states'] = array_map(function D$state) use ($country) {
                $state['countryID'] = $country->getId();

                return $state;
            }$data['states']);
        }

        if ($country->hasAttribute('core')) {
            $data['attribute'] = $country->getAttribute('core');
        }

        
$request = new Request();
        $context = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();

        /** @var AccountLoginPageLoadedEvent $event */
        $event = null;
        $this->catchEvent(AccountLoginPageLoadedEvent::class$event);

        $page = $this->getPageLoader()->load($request$context);

        static::assertInstanceOf(AccountLoginPage::class$page);
        static::assertSame(StorefrontPageTestConstants::COUNTRY_COUNT, $page->getCountries()->count());
        static::assertInstanceOf(CountryStateCollection::class$page->getCountries()->first()->getStates());
        self::assertPageEvent(AccountLoginPageLoadedEvent::class$event$context$request$page);
    }

    public function testItLoadsWithoutACustomer(): void
    {
        $request = new Request();
        $context = $this->createSalesChannelContextWithNavigation();
        $page = $this->getPageLoader()->load($request$context);

        static::assertSame(StorefrontPageTestConstants::COUNTRY_COUNT, $page->getCountries()->count());
        static::assertInstanceOf(CountryStateCollection::class$page->getCountries()->first()->getStates());
    }
'#title' => $this->t('States'),
      '#empty' => $this->t('There are no states yet.'),
      '#tabledrag' => [
        [
          'action' => 'order',
          'relationship' => 'sibling',
          'group' => 'state-weight',
        ],
      ],
    ];

    $states = $workflow->getTypePlugin()->getStates();

    // Warn the user if there are no states.     if (empty($states)) {
      $this->messenger()->addWarning(
        $this->t(
          'This workflow has no states and will be disabled until there is at least one, <a href=":add-state">add a new state.</a>',
          [':add-state' => $workflow->toUrl('add-state-form')->toString()]
        )
      );
    }

    
'#default_value' => $transition->label(),
      '#required' => TRUE,
    ];

    $form['id'] = [
      '#type' => 'value',
      '#value' => $this->transitionId,
    ];

    // @todo https://www.drupal.org/node/2830584 Add some ajax to ensure that     // only valid transitions are selectable.     $states = array_map([State::class, 'labelCallback']$workflow->getTypePlugin()->getStates());
    $form['from'] = [
      '#type' => 'checkboxes',
      '#title' => $this->t('From'),
      '#required' => TRUE,
      '#default_value' => array_keys($transition->from()),
      '#options' => $states,
    ];
    $form['to'] = [
      '#type' => 'radios',
      '#title' => $this->t('To'),
      '#required' => TRUE,
      
Home | Imprint | This part of the site doesn't use cookies.