Last active
May 21, 2021 14:08
-
-
Save savchukoleksii/664d1194bc663fbf9ff31d42df79ed11 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
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); | |
})(); | |
} |
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
{%- 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