Search code examples
shopwareshopware6

Copy Category Tree without Product Associations


Based on this post,

Fixing Sort Order when Cloning Category Trees

we implemented a plugin that clones category trees.

But using this method, product associations are being cloned as well. Products with categories from the original tree will also have the same categories from the new tree.

Is there a way to prevent this?


Solution

  • You can add the association to the overwrites of the CloneBehavior which should prevent cloning the corresponding assignments of the original.

    $cloneBehavior = new CloneBehavior([
        'parentId' => $newParentId,
        'afterCategoryId' => $previousId,
        'products' => null,
    ], false);