aimeos / aimeos-typo3

TYPO3 e-commerce extension for ultra fast online shops, scalable marketplaces, complex B2B applications and #gigacommerce
https://aimeos.org/TYPO3
GNU General Public License v3.0
274 stars 738 forks source link

Adding decorator with new key in Plugin Typoscript configuration appends the item to the list instead of respecting the array key #216

Closed yodaXX closed 4 months ago

yodaXX commented 4 months ago

Tested with Version 23.10.6.

For example the following list of decorators is defined in the base Typoscript configuration.

client.html.catalog.lists.decorators.local { 10 = AssignCategories 15 = AutoSort }

If we add a new decorator with a previously undefined key for a specific plugin through plugin configuration. The key is ignored and the decorator is appended at the end of the list.

client.html.catalog.lists.decorators.local.0 = Test

AssignCategories, AutoSort, Test

The issue is only present for undefined keys. If the key exists in the base setup, the decorator gets replaced. Redefining the whole list would fix the issue too guess.

aimeos commented 4 months ago

Seems like a problem when merging the TypoScript. Do you have a fix?

yodaXX commented 4 months ago

The wrong order of decorators is based on this line https://github.com/aimeos/aimeos-typo3/blob/7985555ea2e8543b80def302e80b9ec20a15b167/Classes/Base/Config.php#L53

For simplicity I suggest to just call ksort on the array before the decorators are added to the client. Made a pull request to ai-client-html

aimeos commented 4 months ago

Using ksort() whenever a list is used is only a workaround and needs to be applied nearly everywhere, so this is not a good option. Why don't you specify the full list instead in TS if you need a specific order, i.e.:

client.html.catalog.lists.decorators.local {
  0 = Test
  10 = AssignCategories
  15 = AutoSort
}
yodaXX commented 4 months ago

Its only a suggestion, because it was counterintitive to me being able to overwrite a key, defining a new decorator in the list, but for the later the new list of keys might not represent the actual order decorators are called. Your proposed solution would work ofcourse, was just looking for a convenient way to deal with it, without redefining the whole list.

aimeos commented 4 months ago

Like said, your suggestion has some consequences and isn't a good solution in the end. Also, the behavior of the array_replace_recursive() function isn't incorrect because it adds non-existing entries to the array but PHP arrays are ordered lists where the order is independent of the key. For now, specifying the complete list in the correct order is the best option.