TransWikia.com

Sync Magento 2 Customer & Orders data to external mysql database

Magento Asked by Faizan Anwar on December 7, 2021

I want to take data from Magento 2 DB to another custom MySQL database. What are the possible solutions?

Should I use Magento provided APIs? The issue I see in this approach is when and at what time should I call the API to sync data? If I call it constantly it will put the load on my Magento DB and server.

If I use the API to take data first time then how will I know that there is some update in already synced data? How would I do that then?

One Answer

There are multiple possible ways for you to achieve the sync process.

Process 1

  • Call the Magento API's from your external application to collect one time data with pagination, in-order to handle gateway timeout.
  • Write Event observer in Magento to listen any changes for this data and push it to your external application by calling API's of your application.

Process 2

  • Create a custom table in Magento using new custom module. This table will work as a queue to be pushed in your external application.
  • Write an event observer for customer & orders to listen for any changes and in observer add the record id in the newly created queue table.
  • Write a cronjob that will get triggered every 30min(or any), it will collect record id's from this queue table, get the record data using model and push it to your external application. Once pushed it will clear the entries from the queue table.
  • You can restrict max 20-30(or any) records per sync to avoid any load/timeout issue.

Hope it was helpfull. Thanks

Answered by Abdul Pathan on December 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP