Skip to content

Instantly share code, notes, and snippets.

View obrien-k's full-sized avatar
🦊

Kyle OBrien obrien-k

🦊
View GitHub Profile
const getWishlists = new Promise(async function(resolve, reject) {
await bigCommerce.get('/wishlists').then(data => {
Arr = data.data;
let wArr = [];
for (let [key, value] of Object.entries(Arr)) {
if (value.id) {
wArr.push(value.id);
}
}
e();
import PageManager from "./page-manager";
const fetch = require('node-fetch');
export default class Custom extends PageManager {
constructor(context) {
super(context);
this.url = window.location.href;
}
onReady(){
const token = jsContext.token;
---
product:
videos:
limit: {{theme_settings.productpage_videos_count}}
reviews:
limit: {{theme_settings.productpage_reviews_count}}
related_products:
limit: {{theme_settings.productpage_related_products_count}}
similar_by_views:
limit: {{theme_settings.productpage_similar_by_views_count}}
{{~inject 'template' template}}
{{inject 'token' settings.storefront_api.token}}
<!-- Declare an empty Array as arr
Then iterate over the custom fields for the intended name ('foo' here)
Inject into the current context -->
<script>
let jsContext = JSON.parse({{jsContext}});
let arr = [];
{{#forEach product.custom_fields}}
{{#if name '===' 'foo'}}
<!-- This will cause the button to only appear for each is_bundle field -->
{{#if product.custom_fields}}
{{#each product.custom_fields}}
{{#if this.name "is_bundle"}}
<div>
<input id="multiButton" data-wait-message="{{lang 'products.adding_to_cart'}}" class="button button--primary" type="submit"
value="Combo to Cart">
</div>
{{else}}
{{/if}}
function addMultiToCart(productIds, cartId){
/* Sets the URL to an existing cart id + /items, if not use the cart endpoint to create a new cart */
let url = cartId ?
`/api/storefront/carts/${cartId}/items`:
`/api/storefront/cart`
/* Set a data variable to our lineItems object with the product ids mapped with a quantity of 1 */
let data = {
lineItems: productIds.map(id => ({
quantity: 1,
productId: id
{{~inject 'template' template}}
{{inject 'token' settings.storefront_api.token}}
<!-- Declare an empty Array as arr
Then iterate over the custom fields for the intended name ('foo' here)
Inject into the current context -->
<script>
let jsContext = JSON.parse({{jsContext}});
let arr = [];
{{#forEach product.custom_fields}}
{{#if name '===' 'foo'}}
/*
Utility functions for rendering
*/
// Based on the browser locale, provide a localized price
function formatLocalizedPrice (price) {
return new Intl.NumberFormat(navigator.language, {style: 'currency', currency: price.currencyCode}).format(price.value);
}
// Create a srcset string for responsive images
@obrien-k
obrien-k / iterm2.md
Last active May 26, 2020 01:02 — forked from squarism/iterm2.md
iterm2 cheatsheet

Tabs and Windows

Function Shortcut
New Tab + T
Close Tab or Window + W (same as many mac apps)
Go to Tab + Number Key (ie: ⌘2 is 2nd tab)
Go to Split Pane by Direction + Option + Arrow Key
Cycle iTerm Windows + backtick (true of all mac apps and works with desktops/mission control)
@obrien-k
obrien-k / server.js
Created October 5, 2020 01:09 — forked from zprima/server.js
medium_p1_c4
// Routes
app.get("/api/login", (req, res) => {
// generate a constant token, no need to be fancy here
const token = jwt.sign({ "username": "Mike" }, jwtSecret, { expiresIn: 60 }) // 1 min token
// return it back
res.json({ "token": token })
});
app.get("/api/token/ping", (req, res) => {
// Middleware will already catch if token is invalid