Skip to content

Instantly share code, notes, and snippets.

@jmwind
Last active September 23, 2020 15:05
Show Gist options
  • Save jmwind/e34f2ee5e7c39b9ef7e9e9c65e43f241 to your computer and use it in GitHub Desktop.
Save jmwind/e34f2ee5e7c39b9ef7e9e9c65e43f241 to your computer and use it in GitHub Desktop.
const jsonQ = require('jsonq');
const fetch = require('node-fetch');
const open = require('open');
const shop_url = 'https://sc-bushfire-appeal.com';
const generosity_level = 5;
function extractAllVariants(data) {
const json = jsonQ(data);
const products = json.find('products');
const variants = products.find('variants').find('id');
let variant_url = "";
variants.value().forEach(id => {
variant_url += `${id}:${generosity_level},`
});
const cart = `${shop_url}/cart/${variant_url}`;
open(cart);
}
fetch(`${shop_url}/products.json`)
.then(response => response.json())
.then(data => extractAllVariants(data))
@jmwind
Copy link
Author

jmwind commented Jan 11, 2020

package.json

{
"name": "addall",
"version": "1.0.0",
"description": "Add all to a Shopify cart",
"main": "addall.js",
"scripts": {
"test": "test"
},
"author": "jmwind",
"license": "MIT",
"dependencies": {
"jsonq": "^1.2.0",
"node-fetch": "^2.6.0",
"open": "^7.0.0"
}
}

@alii
Copy link

alii commented Jan 23, 2020

thx 4 shopify bot xoxo

@cool
Copy link

cool commented Sep 22, 2020

thank you for the free shopify bot!

@washedgram
Copy link

will people think im funny if i reply to jmwind github post too

@mckay
Copy link

mckay commented Sep 22, 2020

thanks jm, very cool!

bruh

@xssc
Copy link

xssc commented Sep 22, 2020

Nice touch on switching to template strings!

@cool
Copy link

cool commented Sep 22, 2020

will people think im funny if i reply to jmwind github post too

nah

@alii
Copy link

alii commented Sep 22, 2020

will people think im funny if i reply to jmwind github post too

nah

ego

@g-delmo
Copy link

g-delmo commented Sep 22, 2020

Interesting use of snake case

@slagathor2094
Copy link

y'all code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment