Skip to content

Instantly share code, notes, and snippets.

@hatertron3000
hatertron3000 / app.js
Created October 5, 2019 22:50
customClasses object from app.js that maps custom template files to the appropriate JavaScript module
const customClasses = {
'pages\\custom\\category\\react-demo': () => import('./theme/custom/react-demo'), // Windows
'pages/custom/category/react-demo': () => import('./theme/custom/react-demo'), // Mac/Linux
};
@hatertron3000
hatertron3000 / react-demo.js
Created October 5, 2019 22:42
A JavaScript module that extends the PageClasses module from Cornerstone, and uses it to render a React component with context from the page.
import React from 'react'
import ReactDOM from 'react-dom'
import PageManager from '../page-manager'
const HelloWorld = (props) => (
<div>
<p>Hello World from React!</p>
<p>Here are my props:</p>
<pre>{JSON.stringify(props, null, 2)}</pre>
</div>
@hatertron3000
hatertron3000 / .stencil
Created October 5, 2019 22:35
Example .stencil file that maps a custom category template called react-demo.html to the page url /shop-all/
{
"normalStoreUrl": "https://<store-domain>",
"accessToken": "<api-token>",
"port": 3000,
"customLayouts": {
"brand": {},
"category": {
"react-demo.html": "/shop-all/"
},
"page": {},
@hatertron3000
hatertron3000 / react-demo.html
Created October 5, 2019 22:29
The custom category template that a JS custom pageClass module can use to retrieve the category page context and mount a frontend app.
---
category:
shop_by_price: true
products:
limit: {{theme_settings.categorypage_products_per_page}}
---
{{inject "categoryProductsPerPage" theme_settings.categorypage_products_per_page}}
{{#partial "head"}}
{{#if pagination.category.previous}}
<link rel="prev" href="{{pagination.category.previous}}">
@hatertron3000
hatertron3000 / bcApiClient-cloudformation-template.json
Created September 21, 2019 17:52
Addition to the Resources.LambdaFunction.Environment.Variables object in the BC API Client CloudFormation template
"CLIENT_ID": {
"Ref": "BCCLIENTID"
}
@hatertron3000
hatertron3000 / bcApiClient-cloudformation-template.json
Created September 21, 2019 17:50
Additions to the Parameters object in the BC API Client CloudFormation template
"BCCLIENTID": {
"Type": "String",
"Default": ""
}
@hatertron3000
hatertron3000 / bcApiClient_parameters.json
Created September 21, 2019 17:48
parameters.json for the CloudFormation template for the BC API Client Lambda
{
"BCCLIENTID": "<YOUR BIGCOMMERCE CLIENT ID>"
}
@hatertron3000
hatertron3000 / CognitoStoresDefineAuthChallenge.js
Created September 21, 2019 17:02
Example Define Auth Challenge Lambda implementing that designates the first and only auth challenge as a CUSTOM_CHALLENGE
exports.handler = (event, context, callback) => {
if (event.request.session.length == 0) {
event.response.issueTokens = false
event.response.failAuthentication = false
event.response.challengeName = 'CUSTOM_CHALLENGE'
} else if (event.request.session.length == 1 && event.request.session[0].challengeName == 'CUSTOM_CHALLENGE' && event.request.session[0].challengeResult == true) {
event.response.issueTokens = true
event.response.failAuthentication = false
} else {
event.response.issueTokens = false
@hatertron3000
hatertron3000 / .env
Created September 21, 2019 16:41
Require HTTPS for all routes in the React app
HTTPS=true
@hatertron3000
hatertron3000 / CognitoStoresPreSignup-cloudformation-template.json
Created September 20, 2019 21:50
Environment Variables addition in the CloudFormation template for PresSignup Lambda
"CLIENT_ID": {
"Ref": "BCCLIENTID"
},
"REDIRECT_URL": {
"Ref": "REDIRECTURL"
}