英文:
Copy Category Tree without Product Associations
问题
根据这篇帖子,https://stackoverflow.com/questions/74183504/fixing-sort-order-when-cloning-category-trees,我们实现了一个克隆类别树的插件。但是使用这种方法,产品关联也被克隆了。原始树中带有类别的产品将在新树中具有相同的类别。有没有办法阻止这种情况发生?
英文:
Based on this post,
https://stackoverflow.com/questions/74183504/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?
答案1
得分: 1
您可以将关联添加到CloneBehavior
的重写中,这将阻止克隆原始分配的相应内容。
$cloneBehavior = new CloneBehavior([
'parentId' => $newParentId,
'afterCategoryId' => $previousId,
'products' => null,
], false);
英文:
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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论