Skip to content

PayPal_Braintree breaks Sales Order Grid filtering with Purchase Date (created_at rewritten incorrectly → causes duplicated "main_table" prefix) #40351

@oxochenxa

Description

@oxochenxa

Preconditions and environment

Magento Version: Magento Open Source 2.4.8-p3
PHP Version: PHP 8.4.15

Steps to reproduce

  1. In Magento Admin, go to Sales → Orders
  2. Select the 'Purchase Date' filter, and apply the filter.
Image

Expected result

Display orders by purchase date after filter.

Actual result

An error message is displayed, indicating that the filter is invalid or not supported.

Additional information

The PayPal_Braintree module introduces a plugin on
vendor/paypal/module-braintree-core/Plugin/SalesOrderGridPlugin.php
which rewrites SQL WHERE conditions incorrectly.

When the order grid is filtered by Created At, the plugin attempts to rewrite:

`created_at`
→
`main_table`.`created_at`

However, if the condition already contains a table alias, the plugin rewrites it again, causing the final SQL to become:

(((`main_table`.`main_table`.`created_at` >= '2025-11-30 12:00:00')))

This produces invalid SQL and breaks the order grid.
Affected File: vendor/paypal/module-braintree-core/Plugin/SalesOrderGridPlugin.php
Problematic Code
$wherePart[$key] = str_replace("`created_at`", "`main_table`.`created_at`", $condition);
This code runs even when the condition already contains

`main_table`.`created_at`

leading to:

`main_table`.`main_table`.`created_at`

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Type

No type

Projects

Status

Ready for Confirmation

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions