编程语言
首页 > 编程语言> > php-将Magento类别复制到父母

php-将Magento类别复制到父母

作者:互联网

场景:
一个带有类别产品和客户导入的新空白Magento,其中包含一些需要解决的问题.

类别结构:

Root
 L..Category_parent1 (0 products)
    L..Category_child1 (22)
    L..Category_child2 (34)
 L..Category_parent2 (0)
    L..Category_child1 (22)
    L..Category_child2 (34)
 L..Category_parent3 (0)
    L..Category_child1 (22)
    L..Category_child2 (0)
       L..Category_child2_child1 (22)
       L..Category_child2_child2 (34)
    L..Category_child3 (10)

我想使用SQL查询或php脚本将所有产品从子类别复制到其相对父类别. (我不知道是否可以通过Magento管理员执行此操作).

预期结果:

Root
 L..Category_parent1 (22 + 34 products)
    L..Category_child1 (22)
    L..Category_child2 (34)
 L..Category_parent2 (22 + 34)
    L..Category_child1 (22)
    L..Category_child2 (34)
 L..Category_parent3 (22 + 22 + 34 + 10)
    L..Category_child1 (22)
    L..Category_child2 (22 + 34)
       L..Category_child2_child1 (22)
       L..Category_child2_child2 (34)
    L..Category_child3 (10)

更新!
有办法只在展示产品上这样做吗?
以这种方式查看产品,以它们自己的类别来操纵冲突(只需在列表的视图布局中做到这一点?)?

解决方法:

作为部分解决方案:

insert into catalog_category_product_index (
    select cat.parent_id, prod.product_id, 1 
      from catalog_category_product_index prod, catalog_category_entity cat
      where prod.category_id = cat.entity_id and cat.level >= 1
);

这应该选择所有内容并将其提升一级(直到我们找到根源).单独的查询将有助于位置列(当前已硬编码为1).但是,最大的问题是,您期望的结果实际上使项目的碰撞程度超过了一个级别,而此查询仅执行了一个级别.为了真正正确地概括,可以将此查询放入一些代码中,并从最低深度​​开始重复并向上移动.

希望有帮助!

谢谢,

标签:magento,mysql,php
来源: https://codeday.me/bug/20191209/2096763.html