Search code examples
typo3typo3-8.xrealurl

Handling of parameters which can be empty with RealURL


I have a generated path with different categories and products made with an own extension. There can be one, two or three categories, plus a product below the second or third category.

Examples of URLs that should work:

/mainCategory/
/mainCategory/secondCategory/
/mainCategory/secondCategory/product-title
/mainCategory/secondCategory/thirdCategory/
/mainCategory/secondCategory/thirdCategory/product-title

The problem now is the not required thirdCategory to show the product.
My configuration:

'fixedPostVars' =>
    [
        'produkt' =>
            [
                0 =>
                     [
                          'GETvar' => 'tx_vendor_plugin[mainCategory]',
                           'lookUpTable' =>
                               [
                                   'table' => 'sys_category',
                                   'id_field' => 'uid',
                                   'alias_field' => 'title',
                                   'languageGetVar' => 'L',
                                   'languageField' => 'sys_language_uid',
                                   'transOrigPointerField' => 'l10n_parent',
                                   'useUniqueCache' => 1,
                                   'useUniqueCache_conf' =>
                                       [
                                           'strtolower' => 1,
                                           'spaceCharacter' => '-',
                                       ],
                                    ],
                            ],
                        1 =>
                            [
                                'GETvar' => 'tx_vendor_plugin[subCategory]',
                                'lookUpTable' =>
                                    [
                                        'table' => 'sys_category',
                                        'id_field' => 'uid',
                                        'alias_field' => 'title',
                                        'languageGetVar' => 'L',
                                        'languageField' => 'sys_language_uid',
                                        'transOrigPointerField' => 'l10n_parent',
                                        'useUniqueCache' => 1,
                                        'useUniqueCache_conf' =>
                                            [
                                                'strtolower' => 1,
                                                'spaceCharacter' => '-',
                                            ],
                                    ],
                            ],
                        2 =>
                            [
                                'GETvar' => 'tx_vendor_plugin[thirdCategory]',
                                'lookUpTable' =>
                                    [
                                        'table' => 'sys_category',
                                        'id_field' => 'uid',
                                        'alias_field' => 'title',
                                        'languageGetVar' => 'L',
                                        'languageField' => 'sys_language_uid',
                                        'transOrigPointerField' => 'l10n_parent',
                                        'useUniqueCache' => 1,
                                        'useUniqueCache_conf' =>
                                            [
                                                'strtolower' => 1,
                                                'spaceCharacter' => '-',
                                            ],
                                    ],
                            ],
                        3 =>
                            [
                                'GETvar' => 'tx_vndor_plugin[product]',
                                'lookUpTable' =>
                                    [
                                        'table' => 'tx_vendor_domain_model_product',
                                        'id_field' => 'uid',
                                        'alias_field' => 'title',
                                        'languageGetVar' => 'L',
                                        'languageField' => 'sys_language_uid',
                                        'transOrigPointerField' => 'l10n_parent',
                                        'useUniqueCache' => 1,
                                        'useUniqueCache_conf' =>
                                            [
                                                'strtolower' => 1,
                                                'spaceCharacter' => '-',
                                            ],
                                    ],
                            ],
                    ],

When I add noMatch => bypass to the thirdCategory, it doesn't show up any third category. Every third category cannot be accessed.

When I use it without noMatch => bypass, there is an empty path parameter in the URL for products without third category: /mainCategory/secondCategory//product-title

Who can help me with that?


Solution

  • This was asked and answered by Dmitry in the TYPO3 Slack a while ago:

    In other words: you can;t have optional parameters in the beginning or middle of the postVar.

    Thus the verdict is that this is impossible with RealURL.

    An example:

    /mainCategory/secondCategory/product-title/
    /mainCategory/secondCategory/thirdCategory/
    

    How should RealURL know what to decode product-title and thirdCategory here? It's ambiguous since it could be a product or a category. That's why RealURL uses empty path segments for anything which can be optional in the beginning/middle.