Custom Order Processing Script Documentation
This document provides an overview and documentation for an order processing script that automates various tasks related to order data manipulation. The script is designed to be run periodically to process orders, update shipping costs, VAT rates, and generate CSV files for further processing. The files ae then uploaded to the clients dropbox for processing. Below, you'll find details on how the script works, its main functions, and the dependencies it relies on.
1.Clone the repository and install the dependencies
2.Run the script
The custom order processing script is written in JavaScript and serves the purpose of processing order data obtained from Linworks. It performs the following key tasks:
- Retrieving order data from Linnworks.
- Updating shipping costs for orders based on various conditions provided by the client.
- Updating location references for orders based on specific criteria.
- Updating VAT (Value Added Tax) rates for items in orders.
- Converting currency for order prices to GBP (British Pound).
- Generating two CSV files for further use: one for normal orders and another for orders with location references.
The script consists of several functions and steps. Here's an overview of the key functions and what they do:
This function retrieves order data from Linnworks using an endpoint, /Dashboards/ExecuteCustomScriptQuery, that allows you to send a custom SQL query. It performs data filtering and processing to obtain the required order information.
To Understand the SQL script youll have to go through the Linnworks API Documentation and Database Structure
This function updates shipping costs for items in orders based on various conditions, such as currency and postage cost.
This function updates location references for orders based on specific criteria, including source, sub-source, and email addresses.
This function generates a CSV file for normal orders (without location references) after processing.
This function generates a CSV file for orders with location references after processing.
This function updates VAT rates for items in orders by reading data from the vat.csv file.
The main function orchestrates the entire order processing workflow. It performs the following steps:
- Retrieves order data from the SQL database.
- Filters out already processed orders.
- Updates VAT rates.
- Updates shipping costs.
- Updates location references.
- Converts currency.
- Generates CSV files.
- Uploads generated files to Dropbox and an SFTP server.
- Logs processing information.
The script uses the node-cron library to run periodically. It schedules the main() function to run at specified intervals (e.g., every 30 minutes).
This custom order processing script is designed to automate various tasks related to order data manipulation, shipping cost updates, VAT rate updates, and more.