The cart submodule introduces a "cart <> 1" filter on the default commerce_orders view for all displays. This causes a fatal error if you add a relationship to entities of the same type to the default display or any subsequently added displays.

Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'cart' in where clause is ambiguous:...

This might arguably be a feature request since vanilla Commerce doesn't have this issue and one can clone the default view or use a new view for one's needs, but the forced filter is at the very least not graceful.

Steps to reproduce:

  • Add an entity reference field of type commerce_order to any commerce_order bundle.
  • Add a commerce_order relationship to the commerce_orders view, based on the value from the entity reference field.
  • Access the view path and notice the fatal error.

Proposed solution:

Remove commerce_cart.views_execution.inc which contains commerce_cart_views_query_alter which only adds this forced filter, and move the filter to the yml definition of the view in the order submodule.

Remaining tasks:

Create an update hook to add the filter to the "commerce_order..default" entity view displays of all bundles.
Update documentation.

Comments

ts.ag created an issue. See original summary.

jsacksick’s picture

The patch is incorrect. It cannot be done this way... Since the commerce_order module doesn't depend on commerce_cart which is the reason why the filter is added like it is today.

tbkot’s picture

Status: Needs work » Needs review
StatusFileSize
new963 bytes

  • jsacksick committed 38f88e9c on 8.x-2.x authored by tBKoT
    Issue #3440271 by ts.ag, tBKoT, jsacksick: Column 'cart' in where clause...

  • jsacksick committed d7bb456c on 3.0.x authored by tBKoT
    Issue #3440271 by ts.ag, tBKoT, jsacksick: Column 'cart' in where clause...
jsacksick’s picture

Status: Needs review » Fixed

Committed, thanks Dmytrii!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.