Skip to content

Instantly share code, notes, and snippets.

View k-montgomery's full-sized avatar

Kyle Montgomery k-montgomery

View GitHub Profile
@k-montgomery
k-montgomery / csc-02-real-time-inventory-sample-v2-normalized.json
Created September 6, 2018 20:19
CSC.02 Real-Time Inventory Service Request-Response JSON v2 Normalized
// REAL-TIME INVENTORY CHECK - V2
// CAN BE USED TO SUPPORT BOPIS AND INVENTORY THRESHOLD USE CASES
// SAMPLE REQUEST WITH VARYING PRODUCTS + LOCATIONS
// THIS VERSION IS NORMALIZED BY LOCATION
{
"quantityLocationQueries": [
{
"locationID": "425",
@k-montgomery
k-montgomery / csc-02-real-time-inventory-sample-v1.json
Last active September 6, 2018 20:13
CSC.02 Real-Time Inventory Service Request-Response JSON v1
// REAL-TIME INVENTORY CHECK
// CAN BE USED TO SUPPORT BOPIS AND INVENTORY THRESHOLD USE CASES
// SAMPLE REQUEST WITH VARYING PRODUCTS + LOCATIONS
{
"quantityLocationQueries": [
{
"locationID": "425",
"locationType": "store",
@k-montgomery
k-montgomery / simple-minicart.js
Created April 21, 2017 23:40
Simple minicart in SFCC
/**
* Displays the current items in the cart in the minicart panel.
* The minicart only uses session.privacy.cartQty and not render all the contents; those would be loaded on hover
*/
function miniCartSimple() {
// get total qty in basket and cache in session, this is updated on every calculation
if(empty(session.privacy.cartQty)){
var cartModel = app.getModel('Cart').get();
if(cartModel){
session.privacy.cartQty = cartModel.getUnitCount();
@k-montgomery
k-montgomery / GoodController.js
Created March 6, 2017 21:03
Example of a good JS Controller in Salesforce Commerce Cloud, which can be used by Controllers or pipelines
'use strict';
var app = require('storefront_controllers/cartridge/scripts/app');
var guard = require('storefront_controllers/cartridge/scripts/guard.js');
var messageString = require('~/cartridge/scripts/messageString');
function show () {
var msg = messageString.getMessage();
app.getView(msg).render('sometemplate');
@k-montgomery
k-montgomery / BadController.js
Created March 6, 2017 21:02
Example of bad JS Controller in Salesforce Commerce Cloud - cannot be used by pipelines
'use strict';
var app = require('storefront_controllers/cartridge/scripts/app');
var guard = require('storefront_controllers/cartridge/scripts/guard.js');
function show () {
var msg = getMessage();
app.getView(msg).render('sometemplate');
}
@k-montgomery
k-montgomery / ocapi-data-login.ds
Created February 16, 2017 21:08
OCAPI Data API OAuth login
var client = new dw.net.HTTPClient();
var basicAuth = "Basic " + dw.util.StringUtils.encodeBase64(pdict.CurrentHttpParameterMap.clientID + ":" + pdict.CurrentHttpParameterMap.clientPassword);
client.setRequestHeader("Authorization",basicAuth);
client.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
client.setTimeout(2000);
client.open("POST", "https://account.demandware.com/dw/oauth2/access_token");
client.send("grant_type=client_credentials");
@k-montgomery
k-montgomery / isml-in-js-controllers.isml
Created January 13, 2017 17:44
Notes on JS Controllers, ismodule
//instead of `ismodule`s you could do
${pdict.includes.image(pdict.product)}`
//in `image()` you can use `ISML.render()` to render the image
//advantage: clean scopes
@k-montgomery
k-montgomery / 0_reuse_code.js
Created December 16, 2016 21:36
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console