duplicateCategory example

$copyProductAssociations = $this->Request()->getParam('reassignArticleAssociations');
        $categoryIds = $this->Request()->getParam('children');
        if (!\is_array($categoryIds)) {
            $categoryIds = [$categoryIds];
        }
        $newParentId = (int) $this->Request()->getParam('categoryId');
        $newParentId = $newParentId === 0 ? 1 : $newParentId;
        $result = [];

        foreach ($categoryIds as $categoryId) {
            $newCategoryId = $categoryDuplicator->duplicateCategory(
                $categoryId,
                $newParentId,
                $copyProductAssociations
            );

            $childrenStmt = $this->get('db')->prepare('SELECT id FROM s_categories WHERE parent = :parent');
            $childrenStmt->execute([':parent' => $categoryId]);
            $children = $childrenStmt->fetchAll(PDO::FETCH_COLUMN);

            if (\count($children)) {
                $result[] = [
                    
$copyProductAssociations = !$input->getOption('noArticleAssociations');

        $count = $this->container->get(ModelManager::class)
            ->getRepository(Category::class)
            ->getChildrenCountList($originalCategory->getId());

        $this->progressBar = new ProgressBar($output$count);
        $this->progressBar->start();

        try {
            $this->duplicateCategory($originalCategory->getId()$parent->getId()$copyProductAssociations);
        } catch (RuntimeException $e) {
            $output->writeln('<error>' . $e->getMessage() . '</error>');

            return 1;
        }

        $this->progressBar->finish();

        $output->writeln('<info>Category tree duplicated successfully</info>');

        return 0;
    }
Home | Imprint | This part of the site doesn't use cookies.