复制类别树,不包括产品关联。

huangapple go评论58阅读模式
英文:

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);

huangapple
  • 本文由 发表于 2023年3月9日 22:46:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/75686174.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定