I have an external magneto 2 database in which old sales orders exist and I want to show that orders in custom grid like sales order grid.
I followed the https://github.com/joshspivey/magento2-sales-grid link and create custom grid for sales order but order is showing current m2 system but I want to show external's database orders in this grid.
I'm able to create multiple connection by adding following code in env.php
'db' =>
array (
'table_prefix' => '',
'connection' =>
array (
'default' =>
array (
'host' => 'localhost',
'dbname' => 'magento',
'username' => 'your_username',
'password' => 'your_password',
'model' => 'mysql4',
'engine' => 'innodb',
'initStatements' => 'SET NAMES utf8;',
'active' => '1',
),
'newConnection' =>
array (
'host' => 'localhost',
'dbname' => 'magento_new',
'username' => 'your_username2',
'password' => 'your_password2',
'model' => 'mysql4',
'engine' => 'innodb',
'initStatements' => 'SET NAMES utf8;',
'active' => '1',
)
),
),
and for the resource
'resource' => array (
'default_setup' => array (
'connection' => 'default',
),
'newConnection' => array(
'connection' => 'newConnection'
)
),
reference - https://blog.imranshakil.com/custom-database-connection-on-magento-2/
I have change $this->resource->getConnection('sales'); to $this->resource->getConnection('newConnection'); in sales module but it is still showing in magento's core module but still showing the current system orders. I got stuck. Please help.
Any help would be appreciated.
1 Answer 1
Try like this:
$connection = $resourceConnection->getConnectionByName('newConnection');
Hope this will solve your problem.