setChildren example

$children->add($category);
        }

        $children->sortByPosition();

        $items = new CategoryCollection();
        foreach ($children as $child) {
            if (!$child->getActive() || !$child->getVisible()) {
                continue;
            }

            $child->setChildren($this->buildTree($child->getId()$categories));

            $items->add($child);
        }

        return $items;
    }

    private function resolveAliasId(string $id, SalesChannelEntity $salesChannelEntity): string
    {
        $name = $salesChannelEntity->getTranslation('name') ?? '';
        \assert(\is_string($name));

        
$ids = array_unique(array_filter($ids));
        $parentPages = $this->shopPageChildrenGateway->getList($ids$context);

        foreach ($parentPages as $page) {
            $parentId = $page->getParentId();

            if (!$parentId) {
                continue;
            }

            if (\array_key_exists($parentId$shopPages)) {
                $shopPages[$parentId]->setChildren(array_merge($shopPages[$parentId]->getChildren()[$page]));
            }
        }
    }

    /** * @param array<int, ShopPage> $shopPages */
    private function resolveParents(array $shopPages, ShopContextInterface $context): void
    {
        $parentIds = array_map(function D$page) {
            return $page->getParentId();
        },

        $lineItem = new LineItem('A', 'test');

        $product = new LineItem('B', 'product-1');
        $product->setPriceDefinition(new QuantityPriceDefinition(100, new TaxRuleCollection()));

        $discount = new LineItem('C', 'discount-1');
        $discount->setPriceDefinition(new PercentagePriceDefinition(-10));

        $children = new LineItemCollection([$product$discount]);

        $lineItem->setChildren($children);

        $cart = new Cart('test');
        $cart->add($lineItem);

        $calculated = $this->calculator->calculate($cart->getLineItems()$this->context, new CartBehavior());

        static::assertCount(1, $calculated);
        static::assertInstanceOf(LineItem::class$calculated->get('A'));
        static::assertInstanceOf(CalculatedPrice::class$calculated->get('A')->getPrice());
        static::assertSame(90.0, $calculated->get('A')->getPrice()->getTotalPrice());
        static::assertInstanceOf(LineItem::class$calculated->get('A')->getChildren()->get('B'));
        
$lineItem2 = $this->createLineItem();
        }

        $lineItemCollection = new LineItemCollection([
            $lineItem1,
            $lineItem2,
        ]);
        $containerLineItem = $this->createLineItem();
        if ($containerLineItemPrice !== null && $containerLineItemListPrice !== null) {
            $containerLineItem = $this->createLineItemWithListPrice($containerLineItemPrice$containerLineItemListPrice);
        }
        $containerLineItem->setChildren($lineItemCollection);
        $cart = $this->createCart(new LineItemCollection([$containerLineItem]));

        $match = $this->rule->match(new CartRuleScope(
            $cart,
            $this->createMock(SalesChannelContext::class)
        ));

        static::assertSame($expected$match);
    }

    /** * @return \Traversable<string, array<string|int|bool|null>> */


        $lineItemCollection = new LineItemCollection([
            $lineItem1,
            $lineItem2,
        ]);

        $containerLineItem = $this->createLineItem();
        if ($containerLineItemAmount !== null) {
            $containerLineItem = $this->createLineItemWithLength($containerLineItemAmount);
        }
        $containerLineItem->setChildren($lineItemCollection);
        $cart = $this->createCart(new LineItemCollection([$containerLineItem]));

        $match = $this->rule->match(new CartRuleScope(
            $cart,
            $this->createMock(SalesChannelContext::class)
        ));

        static::assertSame($expected$match);
    }

    /** * @return \Traversable<string, array<string|int|bool|null>> */
private function buildTree($level$categories)
    {
        foreach ($level as &$category) {
            $id = $category->getId();

            if (isset($categories[$id])) {
                $categories[$id] = $this->buildTree(
                    $categories[$id],
                    $categories
                );

                $category->setChildren($categories[$id]);
            }
        }

        return $level;
    }

    /** * Returns all categories, grouped by the parent id * * @param string $locale * @param string $fallbackLocale * * @return array */
public function testChangeQuantityOfParentLineItem(): void
    {
        $lineItem = (new LineItem('A', 'type'))->setStackable(true);

        $child1 = (new LineItem('A.1', 'child', null, 3))->setStackable(true);
        $child2 = (new LineItem('A.2', 'child', null, 2))->setStackable(true);
        $child3 = (new LineItem('A.3', 'child'))->setStackable(true);

        $child4 = (new LineItem('A.3.1', 'child', null, 5))->setStackable(true);
        $child5 = (new LineItem('A.3.2', 'child', null, 10))->setStackable(true);

        $child3->setChildren(new LineItemCollection([$child4$child5]));

        $lineItem->setChildren(new LineItemCollection([$child1$child2$child3]));

        $lineItem->setQuantity(2);

        static::assertSame(2, $lineItem->getQuantity());
        static::assertSame(6, $child1->getQuantity());
        static::assertSame(4, $child2->getQuantity());
        static::assertSame(2, $child3->getQuantity());
        static::assertSame(10, $child4->getQuantity());
        static::assertSame(20, $child5->getQuantity());

        
$lineItem2 = $this->createLineItem();
        }

        $lineItemCollection = new LineItemCollection([
            $lineItem1,
            $lineItem2,
        ]);
        $containerLineItem = $this->createLineItem();
        if ($containerLineItemVolume !== null) {
            $containerLineItem = $this->createLineItemWithVolume($containerLineItemVolume);
        }
        $containerLineItem->setChildren($lineItemCollection);
        $cart = $this->createCart(new LineItemCollection([$containerLineItem]));

        $match = $this->rule->match(new CartRuleScope(
            $cart,
            $this->createMock(SalesChannelContext::class)
        ));

        static::assertSame($expected$match);
    }

    /** * @return \Traversable<string, array<string|int|bool|null>> */

        $shop = DetachedShop::createFromShop($shop);

        $main = $shop->getMain();
        if ($main !== null) {
            $main = DetachedShop::createFromShop($main);
            $shop->setHost($main->getHost());
            $shop->setSecure($main->getSecure());
            $shop->setBasePath($shop->getBasePath() ?: $main->getBasePath());
            $shop->setTemplate($main->getTemplate());
            $shop->setCurrencies($main->getCurrencies());
            $shop->setChildren($main->getChildren());
            $shop->setCustomerScope($main->getCustomerScope());
        }

        $shop->setBaseUrl($shop->getBaseUrl() ?: $shop->getBasePath());

        return DetachedShop::createFromShop($shop);
    }

    /** * returns the right shop depending on the request object * * @param array[] $shops * @param string $requestPath * * @return array|null */
$cart->add((new LineItem('B', 'test'))->setGood(false));

        static::assertCount(0, $cart->getLineItems()->filterGoods());
    }

    public function testCartWithNestedLineItemHasChildren(): void
    {
        $cart = new Cart('test');

        $cart->add(
            (new LineItem('nested', 'nested'))
                ->setChildren(
                    new LineItemCollection([
                        (new LineItem('A', 'test'))->setGood(true),
                        (new LineItem('B', 'test'))->setGood(true),
                    ])
                )
        );

        $cart->add(
            (new LineItem('flat', 'flat'))->setGood(true)
        );

        
$lineItem2 = $this->createLineItem();
        }

        $lineItemCollection = new LineItemCollection([
            $lineItem1,
            $lineItem2,
        ]);
        $containerLineItem = $this->createLineItem();
        if ($containerLineItemPrice !== null) {
            $containerLineItem = $this->createLineItemWithPrice(LineItem::CONTAINER_LINE_ITEM, $containerLineItemPrice);
        }
        $containerLineItem->setChildren($lineItemCollection);
        $cart = $this->createCart(new LineItemCollection([$containerLineItem]));

        $match = $this->rule->match(new CartRuleScope(
            $cart,
            $this->createMock(SalesChannelContext::class)
        ));

        static::assertSame($expected$match);
    }

    /** * @return \Traversable<string, array<string|int|bool|null>> */
$lineItem2 = $this->createLineItem();
        }

        $lineItemCollection = new LineItemCollection([
            $lineItem1,
            $lineItem2,
        ]);
        $containerLineItem = $this->createLineItem();
        if ($containerLineItemWeight !== null) {
            $containerLineItem = $this->createLineItemWithWeight($containerLineItemWeight);
        }
        $containerLineItem->setChildren($lineItemCollection);
        $cart = $this->createCart(new LineItemCollection([$containerLineItem]));

        $match = $this->rule->match(new CartRuleScope(
            $cart,
            $this->createMock(SalesChannelContext::class)
        ));

        static::assertSame($expected$match);
    }

    /** * @return \Traversable<string, array<string|int|bool|null>> */
        $closingNode = $this->createJSXNode(
            "JSXClosingFragment",
            $startClosingToken
        );
        $this->completeNode($closingNode);
        
        //Fragment         $node = $this->createJSXNode("JSXFragment", $startOpeningToken);
        $node->setOpeningFragment($openingNode);
        $node->setClosingFragment($closingNode);
        if ($children) {
            $node->setChildren($children);
        }
        return $this->completeNode($node);
    }
    
    /** * Parses a group of jsx children * * @return \Peast\Syntax\Node\Node[]|null */
    protected function parseJSXChildren()
    {
        
$lineItemC->setId(Uuid::randomHex());
        $lineItemC->setGood(true);

        $lineItemD = new OrderLineItemEntity();
        $lineItemD->setId(Uuid::randomHex());
        $lineItemD->setGood(false);

        $lineItemE = new OrderLineItemEntity();
        $lineItemE->setId(Uuid::randomHex());
        $lineItemE->setGood(true);

        $lineItemC->setChildren(new OrderLineItemCollection([$lineItemE$lineItemD]));

        $collection = new OrderLineItemCollection([$lineItemA$lineItemB$lineItemC]);

        $filtered = $collection->filterGoodsFlat();

        static::assertEquals([$lineItemA$lineItemC$lineItemE]$filtered);
    }

    public function testGetPayloadsProperty(): void
    {
        $lineItemA = new OrderLineItemEntity();
        
$lineItemCollection = new LineItemCollection([
            $lineItem1,
            $lineItem2,
        ]);

        $containerLineItem = $this->createLineItem();
        if ($containerLineItemPrice !== null) {
            $containerLineItem = $this->createLineItemWithPurchasePrice($containerLineItemPrice);
        }
        $containerLineItem->setType(LineItem::CONTAINER_LINE_ITEM);
        $containerLineItem->setChildren($lineItemCollection);
        $cart = $this->createCart(new LineItemCollection([$containerLineItem]));

        $match = $this->rule->match(new CartRuleScope(
            $cart,
            $this->createMock(SalesChannelContext::class)
        ));

        static::assertSame($expected$match);
    }

    /** * @return \Traversable<string, array<string|int|bool|null>> */
Home | Imprint | This part of the site doesn't use cookies.