【问题标题】:How to filtering in Typo3 with categories and subcategories如何在 Typo3 中使用类别和子类别进行过滤
【发布时间】:2021-09-10 08:38:16
【问题描述】:

我在 Typo3 中有几个产品页面,每个页面都可以分配不同的产品组和属性 - 为此我使用 Typo3 类别。有 5 个主要类别,每个类别都有几个子类别:

Series  [id=1]   |  Shape   [id=2] |  Color   [id=3] |  Decor   [id=4] |  Widths  [id=5] 
-----------------|-----------------|-----------------|-----------------|----------------
Series #1 [id=8] | Shape #1 [id=10]| Color #1 [id=15]| Decor #1 [id=18]| Width #1 [id=23] 
Series #2 [id=6] | Shape #2 [id=9] | Color #2 [id=17]| Decor #2 [id=19]| Width #2 [id=22] 
Series #3 [id=27]| Shape #3 [id=11]| Color #3 [id=16]| Decor #3 [id=20]| Width #3 [id=24] 
                 | Shape #4 [id=13]|                 | Decor #4 [id=21]| Width #4 [id=25] 
                 | Shape #5 [id=12]|                 |                 | Width #5 [id=26] 

基于这些类别,产品预告片的输出将被过滤。您应该能够选择一个或多个产品系列,并通过选择其他类别进一步缩小选择范围。

在我看来,子类必须用 OR 链接,而主要类别必须用 AND 链接。

但是我该怎么做呢?

我已经尝试过使用以下排版,不幸的是没有成功:

lib.product-teaser = COA
lib.product-teaser {

    10 = CONTENT
    10 {
        table = pages
        select {
            pidInList.data = register:dTid
            recursive = 5

            selectFields.dataWrap = *, sys_category.uid AS catUid, pages.uid AS pgUid, pages.title AS pgTitle, tt_content.uid AS recUid
            join = sys_category_record_mm ON pages.uid = sys_category_record_mm.uid_foreign JOIN sys_category ON sys_category.uid = sys_category_record_mm.uid_local JOIN tt_content ON pages.uid = tt_content.pid
            groupBy = sys_category_record_mm.uid_foreign

            where {

                cObject = COA
                cObject {

                    10 = TEXT
                    10 {
                        value = tt_content.CType='mask_cnt_tsr_page'
                    }

                    20 = TEXT
                    20 {
                        if.isGreaterThan.data = register:dCid1
                        if.value = 0
                        value.dataWrap = AND sys_category_record_mm.uid_local IN ({register:dCid1})
                        #dCid1 contain a comma-seperated list of IDs of the subcategories from the specific main categorie (id=1), which the user has selected.
                    }

                    30 = TEXT
                    30 {
                        if.isGreaterThan.data = register:dCid2
                        if.value = 0
                        value.dataWrap = AND sys_category_record_mm.uid_local IN ({register:dCid2})
                        # dCid2 contain a comma-seperated list of IDs of the subcategories from the specific main categorie (id=2), which the user has selected.
                    }

                    40 = TEXT
                    40 {
                        if.isGreaterThan.data = register:dCid3
                        if.value = 0
                        value.dataWrap = AND sys_category_record_mm.uid_local IN ({register:dCid3})
                        # dCid3 contain a comma-seperated list of IDs of the subcategories from the specific main categorie (id=3), which the user has selected.
                    }

                    50 = TEXT
                    50 {
                        if.isGreaterThan.data = register:dCid4
                        if.value = 0
                        value.dataWrap = AND sys_category_record_mm.uid_local IN ({register:dCid4})
                        # dCid4 contain a comma-seperated list of IDs of the subcategories from the specific main categorie (id=4), which the user has selected.
                    }

                    60 = TEXT
                    60 {
                        if.isGreaterThan.data = register:dCid5
                        if.value = 0
                        value.dataWrap = AND sys_category_record_mm.uid_local IN ({register:dCid5})
                        # dCid5 contain a comma-seperated list of IDs of the subcategories from the specific main categorie (id=5), which the user has selected.
                    }



                }

            }


        }

        renderObj = COA
        renderObj {
            [...]
            
        }
        
    }
    
}

提前感谢您的帮助!

【问题讨论】:

    标签: mysql typo3 typoscript


    【解决方案1】:

    我不会使用 TypoScript,而是使用 userFunc 并在 PHP 中执行此操作,因为您有更好的控制、可能的调试选项和更少的样板。在普通的 TS 中可能可以做到这一点,但如果你可以用 PHP 做到这一点,那么这样做是没有意义的,因为这样更快更好。

    uidInList.stdWrap.cObject = USER
    uidInList.stdWrap.cObject.userFunc = Vendor\YourSitePackage\Collection.php
    

    文档可以在https://docs.typo3.org/m/typo3/reference-typoscript/master/en-us/ContentObjects/UserAndUserInt/Index.html找到

    【讨论】:

    • 感谢您的回答!但是我不知道我是否可以使用 PHP userFunc 解决问题 - 在我看来,这更有可能是由于 MySQL-WHERE 查询,它(显然)不能那样工作,对吧?您或许知道解决方案?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-10
    • 2018-05-05
    • 2015-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多