cart icon indicating copy to clipboard operation
cart copied to clipboard

RouteEnhancer does not work for path_segment but uid and sku?

Open j4k3 opened this issue 4 years ago • 2 comments

Bug Report

Current Behavior I've written a routeEnhancer configuration for a tx_cart installation, but I can't get it to work properly. The urls are generated correcly but upon opening the links, I get redirected to the 404 error page. No error is logged. However, if I switch to either uid or sku for routeFieldName, everything works perfectly. I've now made a copy of the sku sow and set it as path_segment, making sure variable type as well as data are the same for sku and path_segment, but the error persists. I can use sku for route generation, but as soon as I switch over to path_segment, the links no longer work.

I've never experienced anything like this with RouteEnhancers, has anyone else? Can anybody tell me whats going on here?

Heres the snippet of my SiteConfiguration.php

  -
    type: Extbase
    extension: Cartproducts
    plugin: Products
    routes:
      -
        routePath: '/artikel-{product_slug}'
        _controller: 'Product::show'
        _arguments:
          product_slug: product
    defaultController: 'Product::list'
    aspects:
      product_slug:
        type: PersistedAliasMapper
        tableName: tx_cartproducts_domain_model_product_product
        routeFieldName: path_segment

Expected behavior/output Work.

Environment

  • TYPO3 version(s): 9.5.24
  • cart version: 2.1.0
  • Is your TYPO3 installation set up with Composer (Composer Mode): no

j4k3 avatar Feb 19 '21 19:02 j4k3

Can you edit your Configuration so it is readable?

Our configuration looks like this:

routeEnhancers:
    CartProducts:
        type: Extbase
        extension: CartProducts
        plugin: Products
        routes:
        - { routePath: '/{product_title}', _controller: 'Product::show', _arguments: {'product_title': 'product'} }
        defaultController: 'Product::show'
        aspects:
            product_title:
                type: PersistedAliasMapper
                tableName: 'tx_cartproducts_domain_model_product_product'
                routeFieldName: 'path_segment'

extcode avatar Feb 19 '21 19:02 extcode

Hi,

I had the same problem. The cause is the TCA setting 'eval' => 'uniqueInSite' for the field "path_segment". Change it like so in the TCA overrides:

// /Configuration/TCA/Overrides/tx_cartproducts_domain_model_product_product.php
$GLOBALS['TCA']['tx_cartproducts_domain_model_product_product']['columns']['path_segment']['config']['eval'] = 'unique';

This is the standard setting in EXT:news, so I think it's a good idea to change it @extcode? Btw, in EXT:news you can change the setting in the extension settings in backend.

If you still encounter problems for example when linking to a dedicated detail page, try this:

<f:link.action action="show" controller="Product" extensionName="CartProducts" pluginName="Products" arguments="{product : product}" pageUid="{detailPid}">
        {product.title}
    </f:link.action>

... where {detailPid} is the id of the detail page. controller, extenionName and pluginName are actually not needed, but it might help to exclude errors under certain circumstances.

h-e-l-l-o-w-o-r-l-d avatar Mar 10 '23 13:03 h-e-l-l-o-w-o-r-l-d