It is working, what if products are more than 99
I made an experiment and it worked but I do not know how to write proper code for it.
I added products?page=2 at the end so it brought search results for older products, however, it stopped fetching for newer products then. Please see here:
let products = await fetch(
"https://api.reflowhq.com/v1/stores/1736447397/products?page=2"
).then((r) => r.json());
If we can make a combination of URLS for fetch to take data from page=1 and page=2 and so on, we can then use that combined data to searchâŚ
Then put perpage=999999999999
:")
Yep it should be perpage
, all lowercase. We fixed it in the documentation. Nice detective work
100 is the max the API returns right now. When the official search component arrives this shouldnât be a problem any more.
EDIT: This might not work until you have 100+ productsâŚ
Try replacing the begining of the script to this:
async function search(ss) {
let resultcount = 0;
let searchstring = ss;
let products = await fetch(
"https://api.reflowhq.com/v1/stores/1736447397/products/?perpage=100"
).then((r) => r.json());
let products2 = await fetch(
"https://api.reflowhq.com/v1/stores/1736447397/products/?page=2&perpage=100"
).then((r) => r.json());
productsmerged = products.data.concat(products2.data);
productsmerged.forEach(function (product) {
const cts = JSON.stringify(product).toLowerCase();
; //cts convert to string
It works in theory, looks like you have 40 products at the moment, we will see when youâve added another 60
Hi Richards,
When I use the attached code, I get the following error
This is the code segment the error refers to:
if (searchphrase.length < 2) {
document
.getElementById(âsearchResultsâ)
.append(âPlease enter a longer search phraseâ);
} else {
search(searchphrase);
}
Iâve tried messing around with ID, and the like but canât get the search to work. Any idea whatâs wrong?
This is now out of date, as the official reflow search has been released.
just add the product search from the component/studio tab
but from what i see there is no way to add a link to go directly to that product so your code is better!
EDIT - found a way thanks
All the instructions are here: