Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: CMF Admin Customer List -> File Export doesn't work if customer segment filter applied #544

Open
arrabiata-asanz opened this issue Dec 2, 2024 · 2 comments · May be fixed by #548
Assignees

Comments

@arrabiata-asanz
Copy link

Expected behavior

I can apply the customer segments filter and export the results

Actual behavior

I get an error and can't download the results
Error Log:
request.CRITICAL: Uncaught PHP Exception Doctrine\DBAL\Exception\NonUniqueFieldNameException: "An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in field list is ambiguous" at ExceptionConverter.php line 72 {"exception":"[object] (Doctrine\\DBAL\\Exception\\NonUniqueFieldNameException(code: 1052): An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in field list is ambiguous

Steps to reproduce

  1. Go to https://demo.pimcore.com/admin/
  2. Open the CMF Customer List
  3. Apply the Gender Filter 'male' or any that has at least 1 result
  4. Export the results
@arrabiata-asanz
Copy link
Author

The actual problem is the inner join that applies the segment's filtering because the table object_relations_Customer also has an id column
SELECT id FROM object_Customer INNER JOIN object_relations_Customer fltr_seg_123_0_a_0 ON ....
It should look like this:
SELECT object_Customer.id FROM object_Customer INNER JOIN object_relations_Customer fltr_seg_123_0_a_0 ON ....

The second part is just needed in case you have customized your query with joins for example, if you don't have joins then you don't need this part:

+        $fromTable = $listing->getQueryBuilder()->getQueryPart('from')[0]['table'];
+        $listing->addConditionParam($fromTable . '.' . $idField . ' in ('.implode(', ', $ids).')');

We fixed it this way, but for sure there is cleaner way to fix it.

Subject: [PATCH] fix customers export
---
Index: src/Controller/Admin/CustomersController.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/Controller/Admin/CustomersController.php b/src/Controller/Admin/CustomersController.php
--- a/src/Controller/Admin/CustomersController.php	(revision 95b70584be705f772f94c24eab4719deceadb126)
+++ b/src/Controller/Admin/CustomersController.php	(revision 25e66e45f4b6c4f8c71cb0ca3e762226a335140f)
@@ -164,9 +164,12 @@
         $listing = $this->buildListing($filters);

         $idField = Service::getVersionDependentDatabaseColumnName('id');
+        $fromTable = $listing->getQueryBuilder()->getQueryPart('from')[0]['table'];
         $query = $listing->getQueryBuilder()
+            ->resetQueryPart('from')
+            ->from($fromTable, $fromTable)
             ->resetQueryPart('select')
-            ->select($idField);
+            ->select($fromTable . '.' . $idField);
         $ids = Db::get()->fetchFirstColumn((string)$query);

         $jobId = uniqid();
@@ -218,7 +221,8 @@

         $idField = Service::getVersionDependentDatabaseColumnName('id');
         $listing = $this->buildListing();
-        $listing->addConditionParam($idField . ' in ('.implode(', ', $ids).')');
+        $fromTable = $listing->getQueryBuilder()->getQueryPart('from')[0]['table'];
+        $listing->addConditionParam($fromTable . '.' . $idField . ' in ('.implode(', ', $ids).')');

         $exporter = $this->getExporter($listing, $data['exporter']);
         $exportData = $exporter->getExportData();

@kingjia90 kingjia90 linked a pull request Dec 11, 2024 that will close this issue
@kingjia90 kingjia90 removed a link to a pull request Dec 11, 2024
@kingjia90 kingjia90 linked a pull request Dec 11, 2024 that will close this issue
@kingjia90 kingjia90 linked a pull request Dec 11, 2024 that will close this issue
Copy link

Thanks a lot for reporting the issue. We did not consider the issue as "Pimcore:Priority", "Pimcore:ToDo" or "Pimcore:Backlog", so we're not going to work on that anytime soon. Please create a pull request to fix the issue if this is a bug report. We'll then review it as quickly as possible. If you're interested in contributing a feature, please contact us first here before creating a pull request. We'll then decide whether we'd accept it or not. Thanks for your understanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants