Skip to main content

Poller Integration

Tom Higgs avatar
Written by Tom Higgs
Updated over 2 months ago

The Poller integration is a straightforward way to connect any website that doesn't have a direct API or wants to push orders to the system via the XML or JSON APIs that are available. Additionally, the Poller integration can be used to integrate with Open Cart (Scroll to the bottom to learn more).


Poller Integration Features

  • Order and Stock sync


Setting up the Poller System Account

To set up a Poller Integration, please do the following:

  1. Click Connect then Order Integrations.

  2. Next, click Poller then Create New.

  3. Enter your URL.

    • The base URL of the feed you want to connect to.

  4. Enter your APIKey.

    • The Key used to connect to the feed and stop unauthorized access - it's advisable to use a GUID for the API key.

  5. Continue configuring the connection.

  6. Once ready, click Save.​​​​​​​


Implementing a poller feed

A Poller Feed uses a Rest API that spits out the Order JSON and allows Mintsoft to feedback information such as Tracking Numbers and marking the order as Despatched. The Mintsoft Order Class is the standard format we expect to look for orders in. A list of Mintsoft rrders should then be serialized to JSON. An example PHP of the class can be found below:

Mintsoft Order Class

<?php class MintSoftOrder { // Fields var $OrderNumber; var $Title; var $CompanyName; var $FirstName; var $LastName; var $Address1; var $Address2; var $Address3; var $Town; var $County; var $PostCode; var $Country; var $Email; var $Phone; var $CourierService; var $DeliveryDate; var $Comments; var $OrderValue; var $OrderItems = array(); public function AddOrderItem($Item) { if($Item) { $this->OrderItems[] = $Item; } } } class MintSoftOrderItem{ var $SKU; var $Name; var $Quantity; } ?>

The general idea is to pull orders from the underlying database so they can be imported and then perform basic database updates when orders have been dispatched etc.

Example Poller Feed

<?php define("AREA",'MintSoftAPI'); include("../config.local.php"); include("MintSoft.php"); // API Key $key = 'e3d1ffce-e8e9-4fc7-9cc9-0d4970b6dc8a'; // Config $InitialOrderStatusId = 'P'; $ConfirmedStatusId = 'Z'; $PickingStatusId = 'Y'; // Get Basic from the request $RequestKey = $_REQUEST['APIKEY']; $action = null; if(isset($_REQUEST['action'])) { $action = $_REQUEST['action']; } // Standard CS-Cart Init $host = $config['db_host']; $usr = $config['db_user']; $db = $config['db_name']; $pwd = $config['db_password']; // Check Key is Valid if($key != $RequestKey) { $Error = 'API KEY INVALID'; echo json_encode($Error); exit(); } // More Init $connection = mysql_connect($host,$usr,$pwd); setlocale(LC_CTYPE, 'en_GB'); // Get Latest Orders still in $InitialOrderStatusId if(!$action) { $Orders = array(); $query = mysql_db_query($db, "SELECT * from cscart_orders where status='$InitialOrderStatusId'", $connection); while ($row = mysql_fetch_array($query)) { $OrderId = $row["order_id"]; // Construct MintSoftOrder $Order = new MintSoftOrder(); $Order->OrderNumber = $row["order_id"]; $Order->Title = iconv('ISO-8859-1','UTF-8//TRANSLIT',$row["s_title"]); $Order->FirstName = iconv('ISO-8859-1','UTF-8//TRANSLIT',$row["s_firstname"]); $Order->LastName = iconv('ISO-8859-1','UTF-8//TRANSLIT',$row["s_lastname"]); $Order->Address1 = iconv('ISO-8859-1','UTF-8//TRANSLIT',$row["s_address"]); $Order->Address2 = iconv('ISO-8859-1','UTF-8//TRANSLIT',$row["s_address_2"]); // Funny Address lines if($Order->Address1 == $Order->Address2) { $Order->Address2 = ''; } $Order->Town = iconv('ISO-8859-1','UTF-8//TRANSLIT',$row["s_city"]); $Order->PostCode = iconv('ISO-8859-1','UTF-8//TRANSLIT',$row["s_zipcode"]); $Order->County = iconv('ISO-8859-1','UTF-8//TRANSLIT',$row["s_state"]); $Order->Country = iconv('ISO-8859-1','UTF-8//TRANSLIT',$row["s_country"]); $Order->Phone = iconv('ISO-8859-1','UTF-8//TRANSLIT',$row["phone"]); $Order->Email = iconv('ISO-8859-1','UTF-8//TRANSLIT',$row["email"]); $ShippingId = iconv('ISO-8859-1','UTF-8//TRANSLIT',$row["shipping_ids"]); $Order->OrderValue = $row["total"]; $Order->Comments = iconv('ISO-8859-1','UTF-8//TRANSLIT',$row["notes"]); // Get shipping method $CourierServiceQuery = mysql_db_query($db,"SELECT shipping from cscart_shipping_descriptions where shipping_id='$ShippingId'",$connection); $CourierServiceNameRow = mysql_fetch_row($CourierServiceQuery); if($CourierServiceNameRow) { $Order->CourierService = array_shift(array_values($CourierServiceNameRow)); } //Get the Order Items $itemQuery = mysql_db_query($db, "SELECT * from cscart_order_details where order_id='$OrderId' ", $connection); while($itemRow = mysql_fetch_array($itemQuery)) { //Construct OrderItems $OrderItem = new MintSoftOrderItem(); $OrderItem->SKU = $itemRow["product_code"]; // $OrderItem->Name = $itemRow["products_name"]; $OrderItem->Quantity = $itemRow["amount"]; //Add to Order $Order->AddOrderItem($OrderItem); } $Orders[] = $Order; } // Return JSON echo json_encode($Orders); mysql_close($connection); exit(); } // Confirm Order was imported and update to picking status else if($action == 'confirm') { $ordernumber = $_REQUEST['ordernumber']; $message = " -> Successfully imported into the FulfillmentSystem "; $message.= date("Y-m-d G:i:s"); $insert = mysql_db_query($db, "UPDATE cscart_orders SET details=concat(details,'$message') where order_id='$ordernumber'", $connection); $update = mysql_db_query($db, "UPDATE cscart_orders SET status='$PickingStatusId' where order_id='$ordernumber'", $connection); mysql_close($connection); exit(); } // Set the order to completed status else if($action == 'complete') { $ordernumber = $_REQUEST['ordernumber']; $message = " -> Your Order No: $ordernumber has been despatched"; if(isset($_REQUEST['courierservice'])) { $courierService = $_REQUEST['courierservice']; $message .= " via $courierService"; } if(isset($_REQUEST['tracking'])) { $trackingNumber = $_REQUEST['tracking']; $message .= " Tracking Number: $trackingNumber"; } if(isset($_REQUEST['trackinglink'])) { $trackingLink = $_REQUEST['trackinglink']; $message .= " $trackingLink"; } $message = mysql_real_escape_string($message); $message .= date("Y-m-d G:i:s"); $update1 = mysql_db_query($db, "UPDATE cscart_orders SET status='$ConfirmedStatusId', details=concat(details,'$message') where order_id='$ordernumber'", $connection); mysql_close($connection); exit(); } else if($action == 'stocksync') { if(isset($_REQUEST['sku']) && isset($_REQUEST['stocklevel'])) { $now = date("Y-m-d G:i:s"); $SKU = $_REQUEST['sku']; $StockLevel = $_REQUEST['stocklevel']; $UpdateQuery = "UPDATE products set products_quantity='$StockLevel', products_last_modified='$now' where products_model='$SKU'"; $mysqli->query($UpdateQuery); } exit(); } else { $Error = 'Request Action Invalid'; echo json_encode($Error); } mysql_close($connection); exit(); ?>

Open Cart - Via Poller

It's possible to integrate with Open Cart using PHP files and our Poller Interface. Typically, you'll need to place a subfolder within the Open Cart directory e.g. /API (public_html is the root web folder but could be different depending on installation etc).

There will be two files:

  • Index.php - Contains Logic to pull info from OpenCart DB

  • Mintsoft.php - Contains Definition of what an order should look like.

Did this answer your question?