Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix admin order sorting functionality #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ulrich-berkmueller
Copy link

Due to a missing query API privided by OXID, SQL strings need to be manipulated directly in admin list controllers.
However, this is very error prone if multiple modules do this. For example one could replace "from oxorder" with "FROM OXORDER" or "from oxorder" (using MySQL identifier quoting (backticks)). All this results in valid SQL and should be considered to make the extension of the sql string more robust.

For example, the oxid paypal module replaces the unqoted from oxorder with a quoted table name:
https://github.com/OXID-eSales/paypal/blob/eb1392f37f34fec5a477d7319cad12aba35722fe/Controller/Admin/OrderList.php#L72

Currently, clicking the admin orders' "sort by payment column" link crashes when the SQL FROM clause is not exactly of the form from oxorder.
Because in that case, the joins are not applied and the order by statement extensions in _prepareOrderByQuery() use columns that can not be found.

The provided solution makes the extension more robust against different valid sql strings so that clicking the sorting link does not crash.

It works with variants like

  • from oxorder
  • FROM OXORDER
  • FROM oxorder
  • FROM oxorder
  • ...

Further it uses str_ireplace as case-insensitive replacement method to be more robust against valid variations.

Due to a missing query API privided by OXID, SQL strings need to be manipulated directly in admin list controllers.
However, this is very error prone if multiple modules do this. For example one could replace `from oxorder`  with `FROM OXORDER` or `from `oxorder``` (using MySQL identifier quoting. All this results in valid SQL and should be considered to make the extension of the sql string more robust.

For example, the oxid paypal module replaces the unqoted `from oxorder` with a quoted table name:
https://github.com/OXID-eSales/paypal/blob/eb1392f37f34fec5a477d7319cad12aba35722fe/Controller/Admin/OrderList.php#L72

Currently, clicking the admin orders' "sort by payment column" link crashes when the SQL FROM clause is not exactly of the form `from oxorder`.
Because in that case, the joins are not applied and the order by statement extensions in `_prepareOrderByQuery()` use columns that can not be found.

The provided solution makes the extension more robust against different valid sql strings so that clicking the sorting link does not crash.

It works with variants like
* `from oxorder`
* `FROM OXORDER`
* `FROM   oxorder`
* ``FROM `oxorder```
* ...

Further it uses `str_ireplace` as case-insensitive replacement method to be more robust against valid variations.
@ulrich-berkmueller
Copy link
Author

ulrich-berkmueller commented Aug 23, 2021

Btw.: In the meantime the oe paypal module has been fixed. (https://github.com/OXID-eSales/paypal/pull/54/files)
So it is up to you if you like to make your module more robust or close this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant