getChildCount example

$ids = $delete->getPrimaryKeys('product');

        static::assertContains($secondVariantId$ids);

        $this->runWorker();

        $product = $this->repository
            ->search(new Criteria([$parentId])$this->context)
            ->first();

        static::assertInstanceOf(ProductEntity::class$product);
        static::assertEquals(1, $product->getChildCount());
    }

    public function testNameIsRequiredForParent(): void
    {
        $id = Uuid::randomHex();

        $data = [
            'id' => $id,
            'productNumber' => Uuid::randomHex(),
            'stock' => 10,
            'price' => [['currencyId' => Defaults::CURRENCY, 'gross' => 15, 'net' => 10, 'linked' => false]],
            
private function isActiveLoaded(string $root, CategoryCollection $categories, string $activeId): bool
    {
        if ($root === $activeId) {
            return true;
        }

        $active = $categories->get($activeId);
        if (!$active instanceof CategoryEntity) {
            return false;
        }

        if ($active->getChildCount() === 0 && \is_string($active->getParentId())) {
            return $categories->has($active->getParentId());
        }

        foreach ($categories as $category) {
            if ($category->getParentId() === $activeId) {
                return true;
            }
        }

        return false;
    }

    

        $categoryA = $this->createCategory();

        $categoryB = $this->createCategory($categoryA);
        $categoryC = $this->createCategory($categoryA);

        $categoryD = $this->createCategory($categoryC);

        $categories = $this->categoryRepository->search(new Criteria([$categoryA$categoryB$categoryC$categoryD])$this->context);

        static::assertEquals(2, $categories->get($categoryA)->getChildCount());
        static::assertEquals(0, $categories->get($categoryB)->getChildCount());
        static::assertEquals(1, $categories->get($categoryC)->getChildCount());
        static::assertEquals(0, $categories->get($categoryD)->getChildCount());

        $this->categoryRepository->update([[
            'id' => $categoryD,
            'parentId' => $categoryA,
        ]]$this->context);

        /* Category A ├── Category B ├── Category C ├── Category D */

        $product = $data->get(
            $this->getDataKey((string) $item->getReferencedId())
        );

        // no data for enrich exists         if (!$product instanceof SalesChannelProductEntity) {
            return;
        }

        // container products can not be bought         if ($product->getChildCount() <= 0) {
            return;
        }

        $items->remove($item->getId());
    }

    private function validateStock(LineItem $item, Cart $cart, LineItemCollection $scope, CartBehavior $behavior): void
    {
        if ($behavior->hasPermission(self::SKIP_PRODUCT_STOCK_VALIDATION)) {
            return;
        }

        
'context' => $context,
                ]
            )
        );

        $body = '';
        while ($productResult = $iterator->fetch()) {
            foreach ($productResult->getEntities() as $product) {
                $data = $productContext->getContext();
                $data['product'] = $product;

                if ($productExport->isIncludeVariants() && !$product->getParentId() && $product->getChildCount() > 0) {
                    continue; // Skip main product if variants are included                 }
                if (!$productExport->isIncludeVariants() && $product->getParentId()) {
                    continue; // Skip variants unless they are included                 }

                $body .= $this->productExportRender->renderBody($productExport$context$data);
            }

            if ($exportBehavior->batchMode()) {
                break;
            }

                'id' => Uuid::randomHex(),
                'name' => 'child',
                'configurationId' => Uuid::randomHex(),
                'parentId' => $parentId,
            ],
        ]$this->context);

        /** @var MediaFolderEntity $folder */
        $folder = $this->mediaFolderRepository->search(new Criteria([$parentId])$this->context)->first();

        static::assertEquals(1, $folder->getChildCount());
    }

    private function assertCorrectPathWithOneSubFolderForEachParent(array $data, array $ids, int $depth): void
    {
        // expect parent path to be null         static::assertNull($this->getMediaFolderEntityFromId($data[$depth]['id'])->getPath());

        $expectedPath = '|' . $ids[$depth] . '|';

        // exclude the parent         for ($i = $depth - 1; $i >= 0; --$i) {
            
Home | Imprint | This part of the site doesn't use cookies.