The poller is a simple way to connect any website that doesn't have a direct API or want to push orders to the system via the XML or JSON API's that are available.
Implementing a poller feed
It's a simple Rest API that spits out JSON of orders and provides some simple method to allow the warehouse order management system to feedback information such as tracking numbers as mark orders as despatched when they leave the warehouse
The MintSoftOrder Class is the standard format we expect to look for orders in. A list of MintSoftOrders should then be serialized to json.
PHP Example of the class Below
<?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; } ?>
Example poller feed below written in PHP but it would be easy to construct this in a range of other languages - we have .net examples so please ask!
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.
<?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(); ?>
Setting up the Poller System Account
Navigate to Connect -> Overview -> Poller then click "Create New"
Option | Details | Example |
---|---|---|
URL | The base URL of the feed you want to connect up to | https://mintsoft.co.uk/api/ |
APIKEY | The Key used to connect to the feed and stop unauthorized access - it's advisable to use a GUID for the API key | 376e2fd4-af85-41ac-bc33-5fc999de63b8 |
Comments
0 comments
Article is closed for comments.