加入收藏 | 设为首页 | 会员中心 | 我要投稿 拼字网 - 核心网 (https://www.hexinwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

php-将Magento类别复制到父母

发布时间:2021-01-25 06:43:10 所属栏目:MySql教程 来源:网络整理
导读:场景: 一个带有类别产品和客户导入的新空白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_child

场景:
一个带有类别产品和客户导入的新空白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).但是,最大的问题是,您期望的结果实际上使项目的碰撞程度超过了一个级别,而此查询仅执行了一个级别.为了真正正确地概括,可以将此查询放入一些代码中,并从最低深度??开始重复并向上移动.

希望有帮助!

谢谢,

(编辑:拼字网 - 核心网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!