PHPackages                             0stoya/btfix - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. 0stoya/btfix

ActiveMagento2-module[Database &amp; ORM](/categories/database)

0stoya/btfix
============

Fixes malformed SQL aliases (main\_table.main\_table) caused by Braintree or other extensions in Magento 2 admin order grid.

1.0.0(5mo ago)051MITPHP

Since Nov 29Pushed 5mo agoCompare

[ Source](https://github.com/0stoya/BtFix)[ Packagist](https://packagist.org/packages/0stoya/btfix)[ RSS](/packages/0stoya-btfix/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

FixBraintreeWhereClause
=======================

[](#fixbraintreewhereclause)

A Magento 2 module that fixes malformed SQL aliases generated by certain extensions (commonly **Braintree**) in the **Admin Sales Order Grid**.

Some modules incorrectly construct SQL like:

```
`main_table`.`main_table`.created_at

```

which breaks the grid with errors such as:

```
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'main_table.main_table.created_at'

```

This module cleans the SQL on-the-fly, ensuring your order grid loads correctly.

---

📦 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require 0stoya/btfix
```

Then enable the module:

```
bin/magento setup:upgrade
bin/magento cache:flush
```

That's it — no configuration required.

---

🚀 What This Module Fixes
------------------------

[](#-what-this-module-fixes)

Magento’s `sales_order_grid` uses the alias `main_table`. Some payment/reporting modules incorrectly prepend the alias twice, causing SQL like:

```
main_table.main_table.status

```

This module:

1. Hooks into `Magento\Sales\Model\ResourceModel\Order\Grid\Collection::load()`
2. Inspects the generated SQL (`WHERE` clause)
3. Detects invalid patterns:

    - ``main_table`.`main_table`.field`
    - `main_table.main_table.field`
4. Automatically rewrites them to:

    - ``main_table`.field`
    - `main_table.field`
5. Allows the grid to execute normally.

It is safe, upgrade-proof, and does not override core or vendor files.

---

🛠 Compatibility
---------------

[](#-compatibility)

✔ Magento 2.3.x ✔ Magento 2.4.x ✔ Fully compatible with Magento **2.4.8-p1**✔ Works alongside Braintree, PayPal, Adyen, Klarna, custom modules, etc. ✔ No overrides — safe for upgrades

---

⚙️ Troubleshooting
------------------

[](#️-troubleshooting)

### Still seeing errors?

[](#still-seeing-errors)

Some extensions may inject malformed aliases into other SQL parts such as:

- `ORDER BY`
- `HAVING`

You can extend the cleaning list inside the plugin:

```
$partsToClean = ['where', 'order', 'having'];
```

### Other aliases broken?

[](#other-aliases-broken)

If another module uses a different alias, simply add another replacement rule.

---

📄 License
---------

[](#-license)

MIT License (or choose another if you prefer).

---

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance70

Regular maintenance activity

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

170d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/51473934003a3d2edaf38d33ffea86eb6f68fcac6e8755fe5eb46b74ce02eab8?d=identicon)[Watch3r!](/maintainers/Watch3r!)

---

Top Contributors

[![0stoya](https://avatars.githubusercontent.com/u/224377174?v=4)](https://github.com/0stoya "0stoya (14 commits)")

---

Tags

mage-fixmagentomagento2-extension

### Embed Badge

![Health badge](/badges/0stoya-btfix/health.svg)

```
[![Health](https://phpackages.com/badges/0stoya-btfix/health.svg)](https://phpackages.com/packages/0stoya-btfix)
```

###  Alternatives

[swissup/module-search-mysql-legacy

Legacy mysql search for magento 2.4

10483.0k](/packages/swissup-module-search-mysql-legacy)[comunicart/magento2-reset

Reset database removing categories, products, orders, customers and reviews.

224.4k](/packages/comunicart-magento2-reset)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
