cancel
Showing results for 
Search instead for 
Did you mean: 
facuna
First-timer
Status: New

When searching orders, if the results return one order which is the case 100% of the time as we scan a barcode with the order ID it then shows the results which is only one result. This then requires the user to click on the one result to open the order. Ideally, if there is only one result from the search, it should just go straight to the order/result without having to do the extra click. 

1 Comment
VikingGawd
New Contributor

Sounds like you are printing your own barcodes with the ID number.

The way to do this with a barcode is to create a order barcode.  Same that comes on the packing slip.

Its not documented but the barcode is the order id encoded to hexadecimal with ^#^ in the beginning and ^ at the end. If you scan this while on the orders page (dont need to click search) then it will bring up the order.  Only way I could make it work easily.

so an id of 11234567 in the api would be a value of AB6D07. So the barcode would be ^#^AB6D07^.  

Was looking for years and finally noticed the correlation one day.

PHP:

$orderId = 11234567;
$barcode = '^#^' . strtoupper(dechex($orderId)) . '^';

And reverse barcode to order ID:

$fromBarcode = '^#^AB6D07^';
if (preg_match('/\^#\^[a-fA-F0-9]*\^/', $fromBarcode) === 1) {
$fromOrderId = hexdec(substr($fromBarcode, 3, -1));
}

Javascript:

const orderId = 11234567

const barcode = `^#^${orderId.toString(16).toUpperCase()}^`;
const barcodeLegacy = '^#^' & orderId.toString(16).toUpperCase() & '^';
 
And Reverse
const fromBarcode = '^#^AB6D07^'
let fromOrderId = null
if (/\^#\^[a-fA-F0-9]*\^/.test(fromBarcode)) {
fromOrderId = parseInt(fromBarcode.slice(3,-1), 16)
}