Skip to content

Instantly share code, notes, and snippets.

@savchukoleksii
Last active May 21, 2021 14:08
Show Gist options
  • Save savchukoleksii/664d1194bc663fbf9ff31d42df79ed11 to your computer and use it in GitHub Desktop.
Save savchukoleksii/664d1194bc663fbf9ff31d42df79ed11 to your computer and use it in GitHub Desktop.
if(window.location.pathname.includes("/collections")) {
(async () => {
const meta = await fetch("https://www.kasper.com/collections/clothing?view=meta").then(response => response.text()).then(response => JSON.parse(response));
const products = (await Promise.all(Array.from(new Array(meta.pages).keys()).map(page => page + 1).map((page) => {
return fetch(`https://www.kasper.com/collections/clothing/products.json?page=${page}`).then(response => response.json());
}))).map(products => products.products).reduce((result, products) => {
return [
...result,
...products,
];
}, []);
console.log(products);
})();
}
{%- layout none -%}
{%- assign products_count = collection.products_count -%}
{%- assign pages = products_count | divided_by: 30 -%}
{%- assign products_count_modulo = products_count | modulo: 30 -%}
{%- if products_count_modulo > 0 -%}
{%- assign pages = pages | plus: 1 -%}
{%- endif -%}
{%- capture meta_json -%}
{
"total": {{- products_count | json -}},
"pages": {{- pages -}}
}
{%- endcapture -%}
{{- meta_json -}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment