const script = document.createElement('script'); script.src = "https://apps.bazaarvoice.com/deployments/primary-kids/main_site/production/en_US/bv.js"; script.async = true; document.body.appendChild(script); (async () => { if(!window.location.search.includes('?bvproxy')) window.location = '/'; let endCursor = new URLSearchParams(window.location.search).get('endCursor'); let hasNextPage = true; const productIds = []; const query = ` { products(first: 100${endCursor ? `, after: "${endCursor}"` : ''}) { edges { node { id handle } } pageInfo { hasNextPage endCursor } } }`; const response = await fetch('/api/2024-10/graphql.json', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Shopify-Storefront-Access-Token': '4318637bb7f4e675da0b10508a062503' }, body: JSON.stringify({ query }) }); const result = await response.json(); console.log({result}) const edges = result.data.products.edges; edges.forEach(edge => productIds.push(edge.node)); hasNextPage = result.data.products.pageInfo.hasNextPage; endCursor = result.data.products.pageInfo.endCursor; const container = document.createElement('div'); productIds.forEach(({id,handle}) => { const div = document.createElement('div'); div.setAttribute('data-bv-show', 'inline_rating'); div.setAttribute('data-bv-product-id', id.split('/').slice(-1)[0]); div.setAttribute('alt',handle) container.appendChild(div); }); const endCursorDiv = document.createElement('div'); endCursorDiv.setAttribute('id','pagination'); endCursorDiv.setAttribute('data-end-cursor',endCursor); endCursorDiv.setAttribute('data-has-next-page',hasNextPage); document.body.appendChild(endCursorDiv); document.body.appendChild(container); console.log(productIds); })();