Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Wasabules/ed1629ed6862ee4a8cd85fd7574b7c49 to your computer and use it in GitHub Desktop.
Save Wasabules/ed1629ed6862ee4a8cd85fd7574b7c49 to your computer and use it in GitHub Desktop.
Tampermonkey script to export your Aliexpress orders by product line to csv. Removed AUD tax and shipping calculations. Added Euro calc. and item properties.

Export AliExpress orders to csv

This is a Tampermonkey script to export your AliExpress orders by product line to csv It's a fork of a script by wlei6277 (which in itself is a fork from naixx - see below), adapted to Euro-centric orders.

I removed the Australian-specific flat calculations for tax and shipping, changed the Forex currency to Euro and added the option to pull the item properties from the order (e.g. size, color, etc.).

All in all it creates a cleaner version of the csv, allowing for order grouping in Excel or Google Sheets.

Prerequisites

The Tampermonkey extension.

and - of course - the Google Chrome browser.

Installing

If you don't have it already, install the Tampermonkey add-in to your chrome browser. Then add this gist as a new script inside Tampermonkey.

Running the script

  • Activate the Tampermonkey extension

  • Activate this script inside Tampermonkey

  • Log in to AliExpress and go to the "Your Orders" page

  • For a more convenient experience set the number of orders shown to the maximum (30) at the bottom of the page.

  • Press the "LOAD" button at the top of the order page

  • The button changes to "Loaded to clipboard"

  • Paste the clipboard into a text editor

  • load the next order page from Aliexpress

  • Rinse, repeat, ...

  • voilá

Analyzing the order data

  • If you are like me, you want to process the orders with a spreadsheet. Excel's csv import works pretty good. For a simple overview on the orders, the "group" feature is your friend.

CSV Export Format

  • These are the fields in the csv:
  1. Type - currently only "product" is supported
  2. Order number
  3. Order date - ISO format YYYY-MM-DD
  4. Order status
  5. Order currency - The currency billed by Aliexpress, e.g. USD, AUD or EUR
  6. Order amount - The original order amount billed by AliExpress. Includes all items and shipping
  7. "EUR"
  8. Order amount in EUR - calculated with the foreign exchange factor of that day
  9. Item description
  10. Item property
  11. Item currency - Same as Order currency
  12. Item amount - The original item price billed by Aliexpress. Includes shipping
  13. "EUR"
  14. Item amount in EUR - calculated with the foreign exchange factor of that day
  15. Shop Name
  16. Forex value - Exchange value between USD and EUR (EUR = Forex * USD)
  17. Order date & time - the original AliExpress format, if you want to play around with it
  18. Order URL

Authors

This gist is forked from:

  • Billy Leitch - order line iteration - wlei6277

  • naixx - Initial work - naixx

License

The original gists had no license attached, so there you go...

Acknowledgments

  • Not to AliExpress: If you'd offer a decent order export, we wouldn't have to fuck around with this shit!
// ==UserScript==
// @name Aliexpress_orders_ohuf
// @namespace http://tampermonkey.net/
// @version 2
// @description extract Aliexpress orders in a sensible way
// @author ohuf
// @match https://trade.aliexpress.com/orderList.htm*
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// @grant GM_setClipboard
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// ==/UserScript==
// Declare an array called data to hold each row of data to store to the clipboard
var data = [];
// Loop through each of the order div wrappers
$(".order-item-wraper").each(async (ind, el)=>{
// Declaring a variable to hold the GST rate of 10% set on all Aliexpress invoices
let GSTrate = 0.1;
// Store information about the order in a orderInfo object
let orderInfo = {
id: $(el).find(".order-info .first-row .info-body ").text().trim(),
status: $(el).find(".order-status .f-left").text().trim(),
orderCurPrice: $(el).find(".amount-num").text().replace(',', '.').trim(),
orderDate: $(el).find(".order-info .second-row .info-body").text().trim(),
sellerName: $(el).find(".store-info .first-row .info-body").text().trim(),
};
let currency = orderInfo.orderCurPrice.slice(0,1);
switch(currency){
case "€":
currency = "EUR";
break;
case "$":
currency = "USD";
break;
default:
currency = currency; // yes, I know....
}
let order_Amount = orderInfo.orderCurPrice.slice(2,orderInfo.orderCurPrice.length);
let orderEURAmount = parseFloat(order_Amount); //.text().replace(',', '.')
//console.log("PRE " + orderInfo.id + " -> orderEURAmount= " + orderEURAmount);
let order_date = new Date(orderInfo.orderDate);
let order_ISODate = order_date.toISOString();
let USDtoEUR = 1;
let start_date = new Date(orderInfo.orderDate);
// now we step back through dates, until we can get a valid forex rate. Maximum 10 days to avoid bank holidys, exchange closings, etc...
if(currency != "EUR"){
let i=0;
do{
// Convert the date to iso format
let isoDate2 = start_date.toISOString().slice(0,10);
// Set the previous date for the forex api request (because worst case, there's no forex value for 'today')
let prev = new Date(isoDate2);
prev.setDate(prev.getDate()-1);
let isoDate1 = prev.toISOString().slice(0,10);
// Setup the parameters and end point for the api request
let params = {
date1: "start_at="+isoDate1,
date2: "end_at="+isoDate1,
base: "base=USD",
currency: "symbols=EUR"
}
// Make the API request
let endPoint = "https://api.exchangeratesapi.io/history?"+params.date1+"&"+params.date2+"&"+params.base+"&"+params.currency;
let response = await fetch(endPoint);
let json = await response.json();
//Debug:
//console.log("DEBUG order: " + orderInfo.id + " APIdate=" + isoDate1 + "("+ start_date.getDay() +")" + " orderDate=" + orderInfo.orderDate);
//console.log("i=" + i);
//console.log(endPoint);
//console.log(json);
// Pluck the EUR exchange rate off of the json response
try {
USDtoEUR = json.rates[isoDate1].EUR;
i = 10;
}
catch(err) {
console.log("Exception!");
i++;
}
// --- End of API request ---
start_date.setDate(start_date.getDate()-1);
} while(i < 10);
}else{
//console.log("price is already in target currency: no API call necessary.");
}
orderInfo["USDtoEURForex"] = USDtoEUR;
orderEURAmount = (order_Amount * USDtoEUR).toFixed(2);
//console.log(USDtoEUR);
//console.log("POST orderEURAmount= " + orderEURAmount);
// Loop through the order body div wrapper
$(el).find(".order-body").each((i,e)=>{
// Loop through each of the products in the order
$(e).find(".product-sets").each((i,e)=>{
// Clone the orderInfo object into an object called row
let row = JSON.parse(JSON.stringify(orderInfo));
// Add in the product title, price and quantity ordered to the row
row["rowType"] = "product";
row["productTitle"] = $(e).find(".product-title").text().trim();
row["productPrice"] = parseFloat($(e).find(".product-amount span:first()").text().replace(',', '.').trim().slice(1).trim());
if(currency == "USD"){
row["productEURAmount"] = (row.productPrice * USDtoEUR).toFixed(2);
} else {
row["productEURAmount"] = row.productPrice.toFixed(2);
}
row["productQuantity"] = $(e).find(".product-amount span:eq(1)").text().trim().slice(1);
row["productProperty"] = $(e).find(".product-property span:eq(1)").text().trim().slice(1).trim();
row["orderStatus"] = orderInfo.status;
row["orderDate"] = orderInfo.orderDate;
row["ISODate"] = start_date.toISOString().slice(0,10);;
row["orderCurPrice"] = orderInfo.orderCurPrice;
row["orderCurrency"] = currency;
row["orderAmount"] = order_Amount;
row["orderEURAmount"] = orderEURAmount;
// Push row in the dataTable
data.push(row);
});
});
});
// Create a button to click at the top of the order list page which will load the product details to the clip board
$('#mybutton').one('click', function(){
var r=$('<input/>').attr({
type: "button",
id: "field",
value: 'LOAD CSV'
});
$("body").append(r);
});
$('<button/>', {
text: "LOAD", //set text 1 to 10
id: 'csvBtn',
click: function () {
$("#csvBtn").text("Loading...");
var s = "";// "rowType\t id\t ISODate\t orderStatus\t orderCurrency\t orderAmount\t "EUR"\t orderEURAmount\t productTitle\t productProperty\t productQuantity\t orderCurrency\t productPrice\t "EUR"\t productEURAmount\t sellerName\t USDtoEURForex\t orderDate\t orderURL"
Promise.all(data).then(() => {
data.forEach(e=> {
if (e.rowType === "product") {
s += e.rowType + "\t";
s += e.id + "\t";
s += e.ISODate + "\t";
s += e.orderStatus + "\t";
s += e.orderCurrency + "\t";
s += e.orderAmount + "\t";
s += "EUR" + "\t";
s += e.orderEURAmount + "\t";
s += e.productTitle + "\t";
s += e.productProperty + "\t";
s += e.productQuantity + "\t";
s += e.orderCurrency + "\t";
s += e.productPrice + "\t";
s += "EUR" + "\t";
s += e.productEURAmount + "\t";
s += e.sellerName + "\t";
s += e.USDtoEURForex + "\t";
s += e.orderDate + "\t";
s += "https://trade.aliexpress.com/order_detail.htm?orderId=" + e.id + "\t";
s += "\n";
}
});
GM_setClipboard (s);
$("#csvBtn").text("Loaded to clipboard");
});
}
}).appendTo("#appeal-alert");
function test(data){ return data;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment