Pic2shop barcode scanner sample bug

I’ve found a bit of a bug in the example barcode scanner that uses pic2shop.

The first scan is fine using…

  location="pic2shop://scan?callback=" + location.href

…but subsequent calls to pic2shop then use the ‘new’ location.href that already has a returned ean number in it, so the return parameters on subsequent restarts include the barcode ‘ean’ from the original call, presumably in addition to the 2nd barcode, I didn’t check that.

The work around for me was to save the location.href in localstorage on first startup and keep calling pic2shop with that value and not the current location.href.

location="pic2shop://scan?callback=" & localStorage.OriginalLocationhref

Just posted here to help anyone else who may be interested in this example.

Good improvement! If you send me the updated sample, I’ll replace the one we distribute, giving you credit.

Don’t worry about the name but here is the code…

Sub Main()
  'If we are returning from Pic2Scan, ean will be set.
  If localStorage.Original_Location_href = undefined Then localStorage.Original_Location_href = location.href
  If Len(ean)>1 Then
Textarea1.value="EAN scanned is " & ean
  End If
End Sub

Function Button1_onclick()  'Scan
  location="pic2shop://scan?callback=" & localStorage.Original_Location_href
End Function

Function Button2_onclick() 'Scan and Google
End Function

Function Button3_onclick() 'Get Pic2Shop
  location = "https://itunes.apple.com/ca/app/pic2shop-barcode-scanner-qr/id308740640?mt=8"
End Function

'Here's the code for Pic2Shop Pro.
'Be sure to put the full path in Pic2Shop Pro's config:
'http://<your server name>/<path>/BarCode/index.html

Function insertCodeFormat(code,Format)
  Print "you scanned: " & code & " with symbology: " & Format
End Function

Function Button4_onclick()
End Function

Thank you!