getElements example

public function __construct(private readonly iterable $validators)
    {
    }

    public function validate(Cart $cart, SalesChannelContext $context): array
    {
        $errors = new ErrorCollection();
        foreach ($this->validators as $validator) {
            $validator->validate($cart$errors$context);
        }

        return array_values($errors->getElements());
    }
}
private string $deepLinkCode;

    /** * @var EntityRepository<CustomerCollection> */
    private EntityRepository $customerRepository;

    protected function setUp(): void
    {
        $this->defaultCountryId = $this->getValidCountryId(null);

        $validCountries = $this->getValidCountries()->getElements();
        $this->browser = $this->createCustomSalesChannelBrowser([
            'id' => TestDefaults::SALES_CHANNEL,
            'languages' => [],
            'countryId' => $this->defaultCountryId,
            'countries' => \array_map(static fn (CountryEntity $country) => ['id' => $country->getId()]$validCountries),
        ]);

        $this->assignSalesChannelContext($this->browser);

        $this->contextPersister = $this->getContainer()->get(SalesChannelContextPersister::class);
        $this->orderRepository = $this->getContainer()->get('order.repository');
        
return false;
    }

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

    public function getPrices(): PriceCollection
    {
        return new PriceCollection(
            array_filter(array_map(static fn (OrderLineItemEntity $orderLineItem) => $orderLineItem->getPrice()array_values($this->getElements())))
        );
    }

    protected function getExpectedClass(): string
    {
        return OrderLineItemEntity::class;
    }

    /** * @return OrderLineItemEntity[] */
    
$package2 = new DiscountPackage(new LineItemQuantityCollection(
            [
                new LineItemQuantity('GHJ', 1),
            ]
        ));

        $splitted = (new DiscountPackageCollection([$package1$package2]))->splitPackages();

        static::assertEquals(3, $splitted->count());

        $package1 = $splitted->getElements()[0];
        $package2 = $splitted->getElements()[1];
        $package3 = $splitted->getElements()[2];

        // now test the content of each package. only 1 item has to be in there         static::assertEquals(1, $package1->getMetaData()->count());
        static::assertEquals(1, $package2->getMetaData()->count());
        static::assertEquals(1, $package3->getMetaData()->count());
    }
}
$flowSequenceRepository->delete([
            ['id' => $this->ids->get('flow_sequence_id2')],
            ['id' => $this->ids->get('flow_sequence_id1')],
            ['id' => $this->ids->get('flow_sequence_id')],
        ], Context::createDefaultContext());

        $criteria = new Criteria([$this->ids->get('flow_id')]);
        $criteria->addAssociation('sequences');
        $flow = $this->flowRepository->search($criteria, Context::createDefaultContext())->getEntities()->first();
        static::assertNotNull($flow);

        static::assertSame([]$flow->getSequences()?->getElements());
        static::assertSame(serialize(new Flow($this->ids->get('flow_id')[]))$flow->getPayload());
    }

    public function testPayloadShouldBeCorrectWithoutSequence(): void
    {
        $this->flowRepository->create([[
            'id' => $this->ids->create('flow_id'),
            'name' => 'Create Order',
            'eventName' => CheckoutOrderPlacedEvent::EVENT_NAME,
            'priority' => 1,
            'active' => true,
            


        $this->repository->create($data, Context::createDefaultContext());
        $this->addTaxDataToSalesChannel($this->context, $data[0]['tax']);

        $criteria = (new Criteria())->addFilter(new EqualsFilter('product.parentId', $productId));
        /** @var SalesChannelProductEntity $salesChannelProduct */
        $salesChannelProduct = $this->salesChannelProductRepository->search($criteria$this->context)->first();

        // get ordered PropertyGroupCollection         $groups = $this->loader->load($salesChannelProduct$this->context);
        $propertyGroupNames = array_map(fn (PropertyGroupEntity $propertyGroupEntity) => $propertyGroupEntity->getName()$groups->getElements());

        return array_values($propertyGroupNames);
    }
}

  public function testSchemaData() {
    // Try a simple property.     $meta = \Drupal::service('config.typed')->get('system.site');
    $property = $meta->get('page')->get('front');
    $this->assertInstanceOf(StringInterface::class$property);
    $this->assertEquals('/user/login', $property->getValue(), 'Got the right value for page.front data.');
    $definition = $property->getDataDefinition();
    $this->assertEmpty($definition['translatable'], 'Got the right translatability setting for page.front data.');

    // Check nested array of properties.     $list = $meta->get('page')->getElements();
    $this->assertCount(3, $list, 'Got a list with the right number of properties for site page data');
    $this->assertArrayHasKey('front', $list);
    $this->assertArrayHasKey('403', $list);
    $this->assertArrayHasKey('404', $list);
    $this->assertEquals('/user/login', $list['front']->getValue(), 'Got the right value for page.front data from the list.');

    // And test some TypedConfigInterface methods.     $properties = $list;
    $this->assertCount(3, $properties, 'Got the right number of properties for site page.');
    $this->assertSame($list['front']$properties['front']);
    $values = $meta->get('page')->toArray();
    


        return \json_decode((string) $response->getBody(), true, flags: \JSON_THROW_ON_ERROR)['signature'];
    }

    public function listMyExtensions(ExtensionCollection $extensions, Context $context): ExtensionCollection
    {
        try {
            $payload = ['plugins' => array_map(fn (ExtensionStruct $e) => [
                'name' => $e->getName(),
                'version' => $e->getVersion(),
            ]$extensions->getElements())];

            $response = $this->fetchLicenses($payload$context);
        } catch (ClientException $e) {
            throw new StoreApiException($e);
        }

        $body = \json_decode($response->getBody()->getContents(), true, flags: \JSON_THROW_ON_ERROR);

        $myExtensions = new ExtensionCollection();

        foreach ($body as $item) {
            
'OR',
                    [
                        new EqualsFilter('storefrontSalesChannelId', $salesChannelId),
                        new EqualsFilter('salesChannelDomain.salesChannel.id', $salesChannelId),
                    ]
                )
            );

        /** * @var array<ProductExportEntity> */
        return $this->productExportRepository->search($criteria$salesChannelContext->getContext())->getElements();
    }

    private function shouldBeRun(ProductExportEntity $productExport, \DateTimeImmutable $now): bool
    {
        if ($productExport->getIsRunning()) {
            return false;
        }

        if ($productExport->getGeneratedAt() === null) {
            return true;
        }

        
/** * @internal */
class CollectionTest extends TestCase
{
    public function testConstructor(): void
    {
        $elements = ['a', 'b'];
        $collection = new TestCollection($elements);

        static::assertEquals($elements$collection->getElements());
    }

    public function testConstructorKeepingKeys(): void
    {
        $elements = ['z' => 'a', 'y' => 'b'];
        $collection = new TestCollection($elements);

        static::assertEquals($elements$collection->getElements());
    }

    public function testClear(): void
    {
$context = Context::createDefaultContext();
        $productRepo->create([$p->build()]$context);

        // Old database records don't have a product_media_version_id set         $connection->executeStatement('UPDATE product SET product_media_version_id = NULL WHERE product_media_id IS NULL');

        $criteria = new Criteria([$ids->get('p1')$ids->get('p2')]);
        $criteria->addAssociation('cover');

        /** @var ProductEntity[] $products */
        $products = array_values($productRepo->search($criteria$context)->getElements());

        static::assertCount(2, $products);

        [$product1$product2] = $products;

        static::assertNotNull($product1->getCover());
        static::assertNull($product2->getCover());

        // Enable inheritance
        $context->setConsiderInheritance(true);

        
public function testGetParentWithDot()
    {
        $propertyPath = new PropertyPath('grandpa.parent.child');

        $this->assertEquals(new PropertyPath('grandpa.parent')$propertyPath->getParent());
    }

    public function testGetElementsWithEscapedDot()
    {
        $propertyPath = new PropertyPath('grandpa\.parent.child');

        $this->assertEquals(['grandpa.parent', 'child']$propertyPath->getElements());
    }

    public function testGetElementsWithEscapedArray()
    {
        $propertyPath = new PropertyPath('grandpa\[parent][child]');

        $this->assertEquals(['grandpa[parent]', 'child']$propertyPath->getElements());
    }

    public function testGetElementsWithDoubleEscapedDot()
    {
        
return $providers;
    }

    private function buildTaxes(
        TaxProviderCollection $providers,
        Cart $cart,
        SalesChannelContext $context,
        TaxProviderExceptions $exceptions,
    ): ?TaxProviderResult {
        /** @var TaxProviderEntity $providerEntity */
        foreach ($providers->getElements() as $providerEntity) {
            // app providers             if ($providerEntity->getApp() && $providerEntity->getProcessUrl()) {
                return $this->handleAppRequest($providerEntity->getApp()$providerEntity->getProcessUrl()$cart$context);
            }

            $provider = $this->registry->get($providerEntity->getIdentifier());

            if (!$provider) {
                $exceptions->add(
                    $providerEntity->getIdentifier(),
                    new NotFoundHttpException(\sprintf('No tax provider found for identifier %s', $providerEntity->getIdentifier()))
                );
#[Package('checkout')] class LineItemGroupPriceDescSorter implements LineItemGroupSorterInterface
{
    public function getKey(): string
    {
        return 'PRICE_DESC';
    }

    public function sort(LineItemFlatCollection $items): LineItemFlatCollection
    {
        $sorted = $items->getElements();

        usort($sortedstatic function DLineItem $a, LineItem $b) {
            if ($a->getPrice() === null) {
                return 1;
            }

            if ($b->getPrice() === null) {
                return 0;
            }

            return $b->getPrice()->getUnitPrice() <=> $a->getPrice()->getUnitPrice();
        });
        $this->deleteClones($commits$versionContext$versionId);

        // release lock to ensure no other merge is running         $lock->release();

        // 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(
        
Home | Imprint | This part of the site doesn't use cookies.