Magneto 2 is a leading eCommerce platform with lots of advanced features to build a fully functional B2B or B2C web shop. It’s flexibility to implement custom functionalities and scalability makes it the best eCommerce platform in the world. Hire professional magento 2 upgrade service provider to migrate your website to this wonderful eCommerce platform
Sage 200 is an ERP system suitable for small and medium businesses. It helps to manage your stock, accounts etc all at one place
Recently one of our customers wanted to integrate sage 200 ERP with their Magento 2 web store
After discussion with Sage 200 support, we come to know that currently there are no integrations available for synchronization between Magento 2 and Sage 200 software
There is some information provided on website of Sage 200 about the integration but ultimately it leads you to contact their support and at the end it results into the situation where you need to do customization for such integration as there is no channel available which can serve as a bridge between Magento 2 and Sage 200
So our expert magento 2 developers successfully developed a custom solution for the integration that is working really well for our customer
Since there is no pre made solution available for this in the market, this step by step guide will help you to integrate Sage 200 with Magento 2 website without wasting much time
First you need to make sure that your Sage 200 software is setup to work with the eCommerce website for import and export procedures. This includes process of identifying the details of specific procedures and how all the details are going to be mapped with Magento because Sage 200 software has a bit different terminology for processing compared to Magento.
Also, you’ll need to set it up so that it can connect to your Magento store directory with FTP login details and in which directory it should access to fetch the updated file or do the upload.
You can also specify the interval for the import and export procedures to run periodically to process the updates. Make sure that you set this intervals as per the number of procedures and amount of data these procedures process because execution of these updates require Magento’s resources and specifying wrong intervals can easily exhaust resource limit of your Magento 2 instance and depending on the server resource limit it can result in downtime of the store.
Once you are done with this setup you need to check which action Import/Export you need to synchronize with your Magento 2 store and map the fields between Sage 200 and Magento.
Let’s take the Sales Order Import procedure for example which requires the Sales Orders of Magento store to be imported and synced with Sage 200 software for stock management control and internal processing.
The Sales Order Import procedure in Sage 200 Software accepts attributes such as OrderType, CustAccRef, OrderWarehouse, DelPostalName, InvPostalName, PaymentInFull, PaymentRef, PaymentMethod, OrderProcessing, OrderPriority, SettlementDiscountDays, LineType, ProductCode, UnitPrice, CostCentre, Department, ProjectCode, ProspectPostalName, etc.
Let’s go over few of them so we can identify how they are different in terminology compared to Magento ecommerce platform
These were only a few from the Sales Order Import procedure and there are many more but following the above instructions you can now identify them with ease to differentiate and map them with your Magento 2 website
Now that we have some info on the Sales Order Import procedure, we can go ahead and work on Magento for the required setup.
As per the PDF guide Data Exchange for Sage200, it needs to have CSV files created on website server for import into Sage 200 software and it can upload CSV file on server for import in Magento.
For this purpose it is recommended to create new different directories in /var/ directory of your Magento root directory and it should be for each procedure so none of them conflict with each other. For example, we can create /var/salesorderimport/ directory and in that you have only the files exported for Sales Order Import and /var/stockitemexport/ directory and in that have only the files imported for Stock Item Export procedure which exports data of Products from Sage 200 on to website server and Magento can import that data to add new Products or Update existing ones.
Make sure that the directory permissions are setup so that files can be read and written by Sage 200 software by using FTP connection.
There are 29 Import actions and 24 Export actions listed so for the synchronization it’s recommended to go through all of them and only implement which are required because each one needs customization after going through setup of Sage 200 and Magento mapping both
Once you have done setup and mapping of Sage 200 and Magento then next thing is the integration process which serves as a connection bridge to synchronize the data between Sage 200 and Magento store
For this we need to create a custom script and need to set it up from Cron Jobs in the website server to execute the script at regular intervals corresponding with the Import and Export schedule setup in Sage 200 software so it can be synced correspondingly with Magento and vice versa.
Now let’s create the script required for synchronization. We will take Sales Order Import procedure to export Sales Orders from Magento 2 store and import in Sage 200 software:
1. Start with defining the Object and method for procedure script:
1 2 3 4 5 6 7 8 |
class SageSalesOrderImport extends AbstractApp { public function run() { …………………… …………………... } } |
2. Now, we need to get authorization from Magento to execute the custom functionality smoothly and using as much less resources as possible. We can easily achieve this by REST or SOAP API already available in Magento 2. We will take REST for this process so make sure you have the Username and Password with role and permissions to access Sales Order data. Once you have those details then we can get the Access Token from Magento for that user:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$this->_objectManager->get('Magento\Framework\Registry') ->register('isSecureArea', true); $tokenURL='http://www.yourwebsite.com/index.php/rest/V1/integration/admin/token'; $curlConnection = curl_init(); $dataUser = array("username" => "YOUR_USER", "password" => 'PASSWORD'); $userData = json_encode($dataUser); $curlConnection = curl_init($tokenURL); curl_setopt($curlConnection, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curlConnection, CURLOPT_POSTFIELDS, $userData); curl_setopt($curlConnection, CURLOPT_RETURNTRANSFER, true); curl_setopt($curlConnection, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($userData)) ); $userToken = curl_exec($curlConnection); |
3. After that we will fetch all the Sales Orders and Credit Memos from last 15 minutes with the consideration that you have set your Sage 200 to fetch the Sales Orders and Credit Memos every 15 minutes.
1 2 3 |
$allOrders = $this->_objectManager->create('\Magento\Sales\Model\ResourceModel\Order\Collection')->addAttributeToSelect('*')->addFieldToFilter('created_at', array('from' => $fromTime, 'to' => $toTime))->setOrder('entity_id','ASC')->load(); $allCreditMemos = $this->_objectManager->create('\Magento\Sales\Model\ResourceModel\Order\Creditmemo\Collection')->addAttributeToSelect('*')->addFieldToFilter('created_at', array('from' => $fromTime, 'to' => $toTime))->setOrder('entity_id','ASC')->load(); |
4. Next thing is to start creating the export file or check if it’s required to create the file if any new orders are not placed. We will create the file with the required headings in the specific directory and grant it required access.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$orderCount = count($allOrders); $creditMemoCount = count($allCreditMemos); if($orderCount == 0 && $ creditMemoCount == 0) { exit(); // No need for export file as no new Orders or Credit Memos created } // Continue if new Orders or Credit Memos created $salesOrderFile = fopen('/var/salesorderimport/SalesOrders'.date('dmYHi').'.csv', 'w'); fputcsv($salesOrderFile, array('OrderType', 'CustAccRef', 'OrderWarehouse', 'DelPostalName', 'InvPostalName', 'PaymentInFull', 'PaymentRef', 'PaymentMethod', 'OrderProcessing', 'OrderPriority', 'SettlementDiscountDays', 'LineType', 'ProductCode', 'UnitPrice', 'CostCentre', 'Department', 'ProjectCode', 'ProspectPostalName'……) ); |
5. Now we can start fetching the Orders and insert in the export file. For this we will use the REST API with the User Token we obtained.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
foreach($allOrders as $oneOrder) { $orderId = $ oneOrder ->getEntityId(); $orderURL = 'http://www.yourwebsite.com/index.php/rest/V1/orders/' $curlConnection = curl_init($orderURL.$orderId); curl_setopt($curlConnection, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($curlConnection, CURLOPT_RETURNTRANSFER, true); curl_setopt($curlConnection, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($userToken))); $orderDetails = curl_exec($curlConnection); $orderDetails = json_decode($orderDetails, 1); $creditMemoIds = array(); $creditMemos = $oneOrder->getCreditmemosCollection(); foreach ($creditMemos as $creditMemo) { //Go through all the credit memos for the current order. $creditMemoIds[] = $creditMemo->getId(); } // Fetch all the order details and set up the values as per Sage 200 requirement $incrementid = $orderDetails['increment_id']; $orderType = 1; // For Sales Order Order Type is 1 ………………… ………………… // Fetch all the product’s details from order and set up the values foreach($orderDetails['items'] as $orderItem) { $productCode = $orderItem['sku']; $productDescription = $orderItem['name']; $itemQty = $orderItem['qty_ordered']; ………………… ………………… } } |
6. Along with fetching the details, we will keep adding them in the file in new rows for each Sales Order and Credit Memo
1 2 3 4 5 6 7 8 9 10 11 |
$orderSaveDetails = array($orderType, $orderId, $cashAccount, $custAccRef, ….); fputcsv($salesOrderFile, $orderSaveDetails); if(count($creditMemoIds)){ $orderType = 2; // For Credit Memos Order Order Type is 2 $creditMemoDetails = array($ordertype, $orderId, $cashAccount, $custAccRef, ….); } fputcsv($salesOrderFile, $creditMemoDetails); fclose($salesOrderFile); |
By following the above example, you can get all the order details and set them as the Sage 200 requires and create the order export file from Magento 2.
Once you are done with this process and setup this script to execute periodically in the Cron Jobs then you are ready to fetch updated orders from your Magento 2 store into Sage 200 software and have successfully synchronized Sales Order Import procedure
If you are looking to integrate sage 200 with your Magento 2 web store, contact a professional magento 2 development company today.
Please feel free to write in the comments section below if you have any further questions