0

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.

DJX
3293 silver badges11 bronze badges
asked Jan 4, 2021 at 14:00

1 Answer 1

0

Try like this:

$connection = $resourceConnection->getConnectionByName('newConnection');

Hope this will solve your problem.

answered Jan 7, 2021 at 8:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.