Magento 2.4.8-p3 Admin Order Grid 'Purchase Date' Filter Bug and Workaround

Magento 2.4.8-p3 Admin Order Grid 'Purchase Date' Filter Bug

A bug has been reported in Magento 2.4.8-p3 that causes an error when filtering the admin order grid by 'Purchase Date'. This issue, initially reported in earlier versions and supposedly fixed, resurfaces in the latest patched version. The error occurs when the created_at field is used for filtering, leading to an exception.

The Problem

The issue arises from an incorrect SQL query generated when filtering by 'Purchase Date'. The query mistakenly appends an extra main_table alias to the created_at field, resulting in a malformed condition like main_table.main_table.created_at. This leads to a database error and prevents users from filtering orders effectively.

Steps to Reproduce

To reproduce the issue, ensure the PayPal_Braintree modules are enabled and attempt to filter the admin order grid by 'Purchase Date'.

The Workaround

A community member, phpDevChandra, provided a workaround in the form of a patch. This patch addresses the incorrect SQL query by modifying the condition used for filtering. The patch file, admin_order_date_filter.patch, can be applied to temporarily resolve the issue.

# admin_order_date_filter.patch
--- a/vendor/magento/module-sales/Ui/Component/Listing/Column/Purchasedat.php
+++ b/vendor/magento/module-sales/Ui/Component/Listing/Column/Purchasedat.php
@@ -64,6 +64,7 @@
         if (isset($condition['from'])) {
             $from = $this->dateTime->formatDate($condition['from'], false);
             $select->where(
+                'main_table.created_at >= ?',
                 'created_at >= ?',
                 $from
             );
@@ -71,6 +72,7 @@
         if (isset($condition['to'])) {
             $to = $this->dateTime->formatDate($condition['to'], false);
             $select->where(
+                'main_table.created_at <= ?',
                 'created_at <= ?',
                 $to
             );

Important Considerations

  • This patch is a temporary workaround. A permanent fix should be implemented at the core level by Magento.
  • The issue has been confirmed to exist in Magento 2.4.8-p3, even with previously released patches applied.
  • The suggested workaround involves modifying core files, so it's crucial to back up your Magento installation before applying the patch.

This community-provided solution offers a practical way to address the 'Purchase Date' filter bug in Magento 2.4.8-p3. While awaiting a formal fix from Magento, this workaround allows users to regain the ability to filter orders by date effectively.

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools