map example

/** @var FkField[] $fields */
        $fields = $definition->getFields()->filterInstance(FkField::class)->filter(fn (FkField $fk): bool => $fk->getReferenceDefinition()->getEntityName() === $this->definition->getEntityName())->getElements();

        return $fields;
    }

    /** * @return string[] */
    private function getAssociationEntities(): array
    {
        return $this->getAssociationFields()->filter(fn (AssociationField $associationField): bool => $associationField instanceof OneToManyAssociationField)->map(fn (AssociationField $field): string => $field->getReferenceDefinition()->getEntityName());
    }

    private function getAssociationDefinitionByEntity(CompiledFieldCollection $collection, string $entityName): ?EntityDefinition
    {
        /** @var AssociationField|null $field */
        $field = $collection->filter(function DAssociationField $associationField) use ($entityName): bool {
            if (!$associationField instanceof OneToManyAssociationField) {
                return false;
            }

            return $associationField->getReferenceDefinition()->getEntityName() === $entityName;
        })

        return 'cart_price_collection';
    }

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

    private function getUnitPriceAmount(): float
    {
        $prices = $this->map(fn (CalculatedPrice $price) => $price->getUnitPrice());

        return array_sum($prices);
    }

    private function getAmount(): float
    {
        $prices = $this->map(fn (CalculatedPrice $price) => $price->getTotalPrice());

        return array_sum($prices);
    }
}

    public function reduce(\Closure $closure$initial = null)
    {
        return array_reduce($this->elements, $closure$initial);
    }

    /** * @return array<array-key, mixed> */
    public function fmap(\Closure $closure): array
    {
        return array_filter($this->map($closure));
    }

    public function sort(\Closure $closure): void
    {
        uasort($this->elements, $closure);
    }

    /** * @param class-string $class * * tag v6.6.0 Return type will be natively typed to `static` * * @return static */

        return new LineItemCollection(
            array_map(
                fn (DeliveryPosition $position) => $position->getLineItem(),
                $this->elements
            )
        );
    }

    public function getWeight(): float
    {
        $weights = $this->getLineItems()->map(function DLineItem $deliverable) {
            if ($deliverable->getDeliveryInformation()) {
                return $deliverable->getDeliveryInformation()->getWeight() * $deliverable->getQuantity();
            }

            return 0;
        });

        return array_sum($weights);
    }

    public function getQuantity(): float
    {
$criteria->addAssociation('searchKeywords');

        /** @var ProductEntity|null $product */
        $product = $this->repository
            ->search($criteria$this->context)
            ->get($id);

        static::assertInstanceOf(ProductEntity::class$product);

        static::assertInstanceOf(ProductSearchKeywordCollection::class$product->getSearchKeywords());

        $keywords = $product->getSearchKeywords()->map(static fn (ProductSearchKeywordEntity $entity) => $entity->getKeyword());

        static::assertContains('default', $keywords);
        static::assertContains('name', $keywords);

        $update = [
            'id' => $id,
            'name' => 'updated',
        ];

        $this->repository->update([$update]$this->context);

        

        }

        return false;
    }

    /** * @return array<array<string, mixed>> */
    public function getPayload(): array
    {
        return $this->map(fn (LineItem $lineItem) => $lineItem->getPayload());
    }

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

    /** * @return LineItem[] */
foreach ($parts as $part) {
                if (!$part->check($node$parent)) {
                    return false;
                }
            }
            return true;
        };
        switch ($this->operator) {
            case " ":
            case ">":
                $children = $this->operator === ">";
                $matches->map(function D$curNode) use ($filter$children) {
                    $ret = array();
                    $curNode->traverse(
                        function D$node$parent) use ($filter$children, &$ret) {
                            if ($filter($node$parent)) {
                                $ret[] = array($node$parent);
                            }
                            if ($children) {
                                return Traverser::DONT_TRAVERSE_CHILD_NODES;
                            }
                        },
                        array(
                            
$productCrossSellingDefinition = $this->getContainer()->get(ProductCrossSellingDefinition::class);

        $serializer = new ProductCrossSellingSerializer($assignedProductsRepository);
        $serializer->setRegistry($this->getContainer()->get(SerializerRegistry::class));

        $serialized = iterator_to_array($serializer->serialize(new Config([][][])$productCrossSellingDefinition$crossSelling));

        static::assertNotEmpty($serialized);

        $assignedProducts = $crossSelling->getAssignedProducts();
        $assignedProducts->sort(fn (ProductCrossSellingAssignedProductsEntity $a, ProductCrossSellingAssignedProductsEntity $b) => $a->getPosition() <=> $b->getPosition());
        $productsIds = $assignedProducts->map(fn (ProductCrossSellingAssignedProductsEntity $assignedProductsEntity) => $assignedProductsEntity->getProductId());

        static::assertSame($crossSelling->getId()$serialized['id']);
        static::assertSame($crossSelling->getProductId()$serialized['productId']);
        static::assertSame(implode('|', $productsIds)$serialized['assignedProducts']);

        $deserialized = $serializer->deserialize(new Config([][][])$productCrossSellingDefinition$serialized);

        static::assertSame($crossSelling->getId()$deserialized['id']);
        static::assertSame($crossSelling->getProductId()$deserialized['productId']);
        static::assertSame(array_values($productsIds)array_column($deserialized['assignedProducts'], 'productId'));
    }

    
'nestedField' => [
                'value' => 'nested',
                'second' => 'ignored',
            ],
            'ignored' => 'ignored',
        ]);

        $analyzer = $this->getContainer()->get(ProductSearchKeywordAnalyzer::class);

        $result = $analyzer->analyze($product, Context::createDefaultContext()$config);

        $words = $result->map(fn (AnalyzedKeyword $keyword) => $keyword->getKeyword());

        static::assertEquals(
            ['searchable', 'match', 'array', '10000000', '10.99999', 'nested'],
            array_values($words)
        );
    }

    /** * @dataProvider casesSearchBaseOnConfigField */
    public function testInsertIntoSearchKeywordForEn(bool $searchable, bool $tokenize, int $ranking): void
    {
foreach ($events as $event) {
            $config = json_decode((string) $event['config'], true, 512, \JSON_THROW_ON_ERROR);
            if (!isset($config['mail_template_type_id'])) {
                continue;
            }

            $mapping[] = ['event_name' => $event['event_name'], 'typeId' => $config['mail_template_type_id']];
        }

        $mails = $this->fetchMails($connectionarray_column($mapping, 'typeId'));

        $mails = $this->map($mapping$mails);

        $this->insertMails($connection$mails);

        // generate entries for order state mails         $ids = $this->getTypeIds($connection[
            'order_delivery.state.cancelled',
            'order_delivery.state.returned',
            'order_delivery.state.returned_partially',
            'order_delivery.state.shipped',
            'order_delivery.state.shipped_partially',
            'order_transaction.state.cancelled',
            
$old = $entities->get($recordA);
        /** @var CustomerEntity $new */
        $new = $entities->get($newId);
        static::assertInstanceOf(CustomerEntity::class$old);
        static::assertInstanceOf(CustomerEntity::class$new);

        static::assertNotNull($oldAddresses = $old->getAddresses());
        static::assertNotNull($newAddresses = $new->getAddresses());
        static::assertCount(2, $oldAddresses);
        static::assertCount(2, $newAddresses);

        $oldAddressIds = $oldAddresses->map(static fn (CustomerAddressEntity $address) => $address->getId());
        $newAddressIds = $newAddresses->map(static fn (CustomerAddressEntity $address) => $address->getId());

        foreach ($oldAddressIds as $id) {
            static::assertNotContains($id$newAddressIds);
        }
    }

    public function testCloneWithManyToMany(): void
    {
        static::markTestSkipped('ManyToMany are currently intendedly not cloned - to be discussed');
        $recordA = Uuid::randomHex();
        
$context = $this->createMock(SalesChannelContext::class);

        $discount = new DiscountLineItem('test', new QuantityPriceDefinition(10, new TaxRuleCollection([]), 1)[
            'discountScope' => 'scope',
            'discountType' => 'type',
            'filter' => [],
        ], null);

        $packages = $packager->getMatchingItems($discount$cart$context);

        $ids = $packages->first()?->getMetaData()->map(fn (LineItemQuantity $item) => $item->getLineItemId());

        static::assertEquals($expected$ids);
    }

    public static function buildPackagesProvider(): \Generator
    {
        $stackable = new LineItem('stackable', LineItem::PRODUCT_LINE_ITEM_TYPE, null, 1);
        $stackable->setPrice(new CalculatedPrice(100, 100, new CalculatedTaxCollection()new TaxRuleCollection()));
        $stackable->setStackable(true);

        $other = new LineItem('other', LineItem::PRODUCT_LINE_ITEM_TYPE, null, 2);
        

    protected function prepareCategoryAssociatedData($data, ProductModel $article)
    {
        if (!isset($data['categories'])) {
            return $data;
        }

        $this->resetProductCategoryAssignment($data$article);

        $categories = $article->getCategories();

        $categoryIds = $categories->map(function DCategory $category) {
            return $category->getId();
        });

        $categoryIds = array_flip($categoryIds->toArray());

        foreach ($data['categories'] as $categoryData) {
            $category = $this->getManyToManySubElement(
                $categories,
                $categoryData,
                Category::class
            D;

            
if ($delivery->getPositions()->has($item->getId())) {
                return true;
            }
        }

        return false;
    }

    public function getShippingCosts(): PriceCollection
    {
        return new PriceCollection(
            $this->map(fn (Delivery $delivery) => $delivery->getShippingCosts())
        );
    }

    public function getAddresses(): CustomerAddressCollection
    {
        $addresses = new CustomerAddressCollection();
        foreach ($this->getIterator() as $delivery) {
            $address = $delivery->getLocation()->getAddress();
            if ($address !== null) {
                $addresses->add($address);
            }
        }
 $context);

        $criteria = new Criteria([$id]);
        $criteria->getAssociation('addresses')->setLimit(3);
        $criteria->getAssociation('addresses')->addSorting(new FieldSorting('street'));

        /** @var CustomerEntity $customer */
        $customer = $repository->search($criteria$context)->get($id);
        static::assertNotNull($customer->getAddresses());
        static::assertCount(3, $customer->getAddresses());

        $streets = $customer->getAddresses()->map(fn (CustomerAddressEntity $e) => $e->getStreet());
        static::assertEquals(['A', 'B', 'D']array_values($streets));

        $criteria = new Criteria([$id]);
        $criteria->getAssociation('addresses')->setLimit(3);
        $criteria->getAssociation('addresses')->addSorting(new FieldSorting('street', FieldSorting::DESCENDING));

        /** @var CustomerEntity $customer */
        $customer = $repository->search($criteria$context)->get($id);
        static::assertNotNull($customer->getAddresses());
        static::assertCount(3, $customer->getAddresses());

        
Home | Imprint | This part of the site doesn't use cookies.