Skip to content

[BUG] Query to retrieve order state crash #145

Closed
@kpitn

Description

@kpitn

Description

I can't run entity scheduler, when using order state.

Query executed is :

SELECT main_table.entity_id FROM sales_order AS main_table
LEFT JOIN opengento_gdpr_erase_entity AS ogee ON main_table.entity_id=ogee.entity_id AND ogee.entity_type="order" WHERE (main_table.customer_id IS NULL) AND (customer_is_guest = 1) AND (state IN('')) AND (updated_at <= '2014-08-23 07:30:14') AND (ogee.erase_id IS NULL)

Result in error : Integrity constraint violation: 1052 Column 'state' in where clause is ambiguous

I quickly made a patch for that :

--- Model/Customer/CustomerChecker.php
+++ Model/Customer/CustomerChecker.php
@@ -40,8 +40,8 @@
     public function canErase(int $customerId): bool
     {
         if (!isset($this->cache[$customerId])) {
-            $this->criteriaBuilder->addFilter(OrderInterface::STATE, $this->config->getAllowedStatesToErase(), 'nin');
-            $this->criteriaBuilder->addFilter(OrderInterface::CUSTOMER_ID, $customerId);
+            $this->criteriaBuilder->addFilter('main_table.' . OrderInterface::STATE, $this->config->getAllowedStatesToErase(), 'nin');
+            $this->criteriaBuilder->addFilter('main_table.' . OrderInterface::CUSTOMER_ID, $customerId);
             $orderList = $this->orderRepository->getList($this->criteriaBuilder->create());

             $this->cache[$customerId] = !$orderList->getTotalCount();
--- Model/Order/SourceProvider/GuestFilterModifier.php
+++ Model/Order/SourceProvider/GuestFilterModifier.php
@@ -29,8 +29,8 @@
      */
     public function apply(Collection $collection, Filter $filter): void
     {
-        $collection->addFieldToFilter(OrderInterface::CUSTOMER_ID, ['null' => true]);
-        $collection->addFieldToFilter(OrderInterface::CUSTOMER_IS_GUEST, ['eq' => 1]);
-        $collection->addFieldToFilter(OrderInterface::STATE, ['in' => $this->config->getAllowedStatesToErase()]);
+        $collection->addFieldToFilter('main_table.'.OrderInterface::CUSTOMER_ID, ['null' => true]);
+        $collection->addFieldToFilter('main_table.'.OrderInterface::CUSTOMER_IS_GUEST, ['eq' => 1]);
+        $collection->addFieldToFilter('main_table.'.OrderInterface::STATE, ['in' => $this->config->getAllowedStatesToErase()]);
     }
 }

I don't know how you want to resolv this.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfixedIssue has been fixed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions