Last active
April 9, 2021 03:54
-
-
Save m3l1nd4/c1000bc92f49db9799dd125ab4dd44e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getProductInfoWithYahoo = (barcode) => { | |
try { | |
cordova.plugin.http.get('https://shopping.yahooapis.jp/ShoppingWebService/V3/itemSearch', { | |
appid: yahooApiKey, | |
jan_code: barcode | |
}, {}, function (response) { | |
const data = JSON.parse(response.data); | |
if (data && data.hits && data.hits.length) { | |
document.getElementById("product-name").value = data.hits[0].name; | |
document.getElementById("product-price").value = "¥" + data.hits[0].price; | |
document.getElementById("product-quantity").value = 1; | |
document.getElementById("imageFile").src = data.hits[0].image.medium; | |
} else app.dialog.alert("Please add the details by yourself.", "Product Not Found"); | |
}, function (response) { | |
app.dialog.alert("The Yahoo API Key is not working. Please add the details by yourself.", "Product Not Found"); | |
console.log(response); | |
}); | |
} catch { | |
console.log("The Yahoo API Key is not defined."); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment