Skip to content

Sort the wishlist by when products were added, as the page says it does - #541

Draft
boo-code wants to merge 1 commit into
PrestaShop:devfrom
boo-code:fix/wishlist-default-sort-last-added-36496
Draft

Sort the wishlist by when products were added, as the page says it does#541
boo-code wants to merge 1 commit into
PrestaShop:devfrom
boo-code:fix/wishlist-default-sort-last-added-36496

Conversation

@boo-code

@boo-code boo-code commented Sep 5, 2026

Copy link
Copy Markdown
Questions Answers
Description? The wishlist page advertises "Last added" as its sort - products-list.tpl renders data-default-sort="{l s='Last added'}" and WishListProductSearchProvider offers that as the only sort order - but WishlistViewController::getProductSearchQuery() built the query with the catalogue ordering instead, Tools::getProductsOrder('by'/'way'), which is PS_PRODUCTS_ORDER_BY and resolves to cp.position ascending on a stock install. The list therefore came back ordered by where each product sits in its default category, which is unrelated to when it was added, so adding a product could place it anywhere in the list.
Type? bug fix
BC breaks? no
Deprecations? no
Fixed ticket? Fixes PrestaShop/PrestaShop#36496
How to test? Add three products to a wishlist in a known order and open the wishlist. They appear newest first, and a newly added product appears at the top. Before this change the order followed each product's position in its default category, so the newest product could appear anywhere.
Sponsor company

Verified rather than assumed

The replacement is the same SortOrder the provider already exposes, and its emitted clause was checked against core:

SortOrder('wishlist_product', 'id_wishlist_product', 'DESC')
  toLegacyOrderBy(true) = "id_wishlist_product"      Validate::isOrderBy  = true
  toLegacyOrderWay()    = "desc"                     Validate::isOrderWay = true

current default -> "cp.position asc"

The column is unambiguous because the provider inner joins wishlist_product as wp, and cp is only there because the provider left joins category_product for the category filter - so the old clause was valid SQL, just answering the wrong question.

Ordering by a column outside the GROUP BY is fine here: PrestaShop clears the session sql_mode on connect (SET SESSION sql_mode = '' in both DbPDO and DbMySQLi), so ONLY_FULL_GROUP_BY is not in force, and the existing "Last added" option already relies on this.

Why the report was hard to reproduce

The outcome depended entirely on the catalogue positions of the products chosen for the test, which is why @Progi1984 saw it and @florine2623 did not. public/ assets are untouched: this is a PHP controller change with no front-end build involved.

The wishlist page advertises "Last added" as its sort and offers no other
one, but the query was built with the catalogue ordering - PS_PRODUCTS_ORDER_BY,
which is position ascending on a stock install. So the list came back ordered
by where each product sits in its default category, which has nothing to do
with when it was added, and adding a product could place it anywhere.

That also explains why the report could not be reproduced by everyone: the
outcome depends on the chosen products' catalogue positions.

Verified the emitted clause: SortOrder('wishlist_product',
'id_wishlist_product', 'DESC') yields "id_wishlist_product desc", which both
Validate::isOrderBy() and Validate::isOrderWay() accept, and the column is
unambiguous because the provider inner joins wishlist_product as wp. It is
also the exact order the provider already offers as the only sort option.

Reported as PrestaShop/PrestaShop#36496.
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.

Page "My wishlists" - Sort "Last added" doesn't work

1 participant