postnl / postnl-magento2

This is the official Magento 2 extension for the logistics company PostNL. Add shipping options and parcelshops to your checkout. Create labels with track and trace functionality from the backend.
58 stars 61 forks source link

[BUG] Prefix sales_order_grid table #352

Closed BenGoos closed 1 year ago

BenGoos commented 1 year ago

We receive the following error when the database tables have a prefix:

Next Zend_Db_Statement_Exception: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sales_order_grid' doesn't exist, query was: UPDATE sales_order_grid SET tig_postnl_ship_at = ?, tig_postnl_product_code = ?, tig_postnl_confirmed = ? WHERE (entity_id='294026') in /vendor/magento/framework/DB/Statement/Pdo/Mysql.php:109

tig-jeffreybranderhorst commented 1 year ago

Hi @BenGoos ,

Thank you for submitting this, I will place this on our backlog, so we can fix this issue. Looks like this happens when you use prefix together with Async.

Thank again for submitting this issue.

Have a great day, Jeffrey

tig-vincentthart commented 1 year ago

Hi @BenGoos,

We have a fix for this and will include it into the next release. If you already want to fix this you can create patches based on the diff:

diff --git a/Plugin/Order/AsyncPlugin.php b/Plugin/Order/AsyncPlugin.php
index 9bd329bf..aa1a2fa7 100644
--- a/Plugin/Order/AsyncPlugin.php
+++ b/Plugin/Order/AsyncPlugin.php
@@ -123,7 +123,8 @@ public function afterRefreshBySchedule()
             ];

             $where = [$connection->quoteIdentifier('entity_id') . '=?' => $orderId];
-            $connection->update('sales_order_grid', $binds, $where);
+            $tableName = $connection->getTableName('sales_order_grid');
+            $connection->update($tableName, $binds, $where);
         }
     }
 }
diff --git a/Plugin/Shipment/AsyncPlugin.php b/Plugin/Shipment/AsyncPlugin.php
index 4cb2df17..7b429aaf 100644
--- a/Plugin/Shipment/AsyncPlugin.php
+++ b/Plugin/Shipment/AsyncPlugin.php
@@ -123,7 +123,8 @@ public function afterRefreshBySchedule()
             ];

             $where = [$connection->quoteIdentifier('entity_id') . '=?' => $shipmentId];
-            $connection->update('sales_shipment_grid', $binds, $where);
+            $tableName = $connection->getTableName('sales_shipment_grid');
+            $connection->update($tableName, $binds, $where);
         }
     }
 }
BenGoos commented 1 year ago

Hi @tig-vincentthart,

Thank you for the quick solution. I'll add a patch to our application and update when the release is published.

Kind regards, Ben Goossens

tig-vincentthart commented 1 year ago

Hi @BenGoos,

We have added the above solution into the latest release, v1.12.7.

Thanks for bringing this issue to our attention.

Greetings,

Vincent