Skip to content

Product order in category changed after update to Magento 2.2.4 #15627

@dverkade

Description

@dverkade

Preconditions

  1. Magento 2.2.4
  2. PHP 7.1
  3. This issue is introduced by the following PR: Magento 2.2.0 A solution for Product Repeat Issue after filter on category listing page. #11429

Steps to reproduce

  1. Have a category in Magento with several products in it, all have the position in the category set to the value 0
  2. The default sort order should be set to position
  3. In Magento 2.2.3 the newest product in the database (the one with the highest entity_id) was shown first. With Magento 2.2.4 this behaviour changed. The oldest product is shown first, the newest last.

Expected result

  1. Product sort order should be the same between Magento 2.2.3 and Magento 2.2.4. This change is not documented, so can be qualified as a bug, because it was not the intended behaviour.
  2. Newest product should be shown first, oldest last.

Actual result

  1. Product sort order changed. The oldest product is shown first, the newest last.

Cause

In PR #11429 the following code was added:
->addAttributeToSort('entity_id', $this->getCurrentDirection());

The Order by for the SQL query for retrieving the products has changed from:

ORDER BY `cat_index_position` ASC, `cat_index`.`position` ASC, `e`.`entity_id` DESC

To

ORDER BY `cat_index_position` asc, `cat_index`.`position` asc, `e`.`entity_id` asc, `e`.`entity_id` DESC, `cat_index_position` asc, `cat_index`.`position` asc, `e`.`entity_id` asc

So as can be seen a e.entity_id asc is inserted in the order by before the default e.entity_id DESC is in the order by clause changing this behaviour.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Format is validGate 1 Passed. Automatic verification of issue format passed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions