Skip to content

Instantly share code, notes, and snippets.

View benjaminsehl's full-sized avatar

Benjamin Sehl benjaminsehl

View GitHub Profile
@benjaminsehl
benjaminsehl / original-orders.js
Last active June 11, 2022 04:05
Current Order Cube
const shopifyStores = [
{name: 'Canada Web', tablePrefix: 'ca_ecomm'},
{name: 'Canada Retail', tablePrefix: 'ca_retail'},
{name: 'Intl. Web', tablePrefix: 'us_ecomm'},
{name: 'Intl. Retail', tablePrefix: 'us_retail'}
];
let KotnEmailsArray = [
"kotn",
"ordinarysupply",
@benjaminsehl
benjaminsehl / cloudSettings
Last active August 28, 2020 21:31
VS Code Settings
{"lastUpload":"2020-08-28T21:31:48.308Z","extensionVersion":"v3.4.3"}
@benjaminsehl
benjaminsehl / adopt.js
Last active March 20, 2020 22:53
An ES6 function for fixing Orphans
export function adopt(str) {
return str.replace(/\s([^\s<]+)\s*$/g, '\u00A0$1');
}
@benjaminsehl
benjaminsehl / handleize.js
Created April 22, 2020 21:00
Turn a string into a slug
export function handleize (str) {
return str
.toLowerCase()
.replace(/[^\w\u00C0-\u024f]+/g, '-')
.replace(/^-+|-+$/g, '')
}
@benjaminsehl
benjaminsehl / scripts
Last active August 6, 2020 17:11
Zsh alias to print the scripts from a package.json file
alias scripts="pcregrep -M '(?<=scripts\":\s)(.|\n)*?(?=\n\s*},)' package.json"
@benjaminsehl
benjaminsehl / formatters.js
Last active January 30, 2024 16:13
Typography Formatting Function
const formatters = [
{ pattern: /'/g, replacement: '’' }, // Replace straight quotes with smart quotes
{ pattern: /\s([^\s<]+)\s*$/g, replacement: '\u00A0$1' }, // Add non breaking spaces before the last word
]
const formatted = (a) =>
formatters.reduce(
(a, f) => a?.toString().replace(f.pattern, f.replacement),
a,
)
@benjaminsehl
benjaminsehl / shop-pay-unsub-check.sql
Last active February 9, 2021 23:51
Checking for Unsubs via Shop Pay
-- A SQL query to find customers that may have unintentionally unsubscribed from their e-mail.
-- This is related to a Shop Pay bug where if customers come from a Headless shop, they're unsubscribed.
SELECT T1.metadata__email "Email", C.accepts_marketing "Subscribed", C.accepts_marketing_updated_at "Unsubscribe Date", T2.created_at "Transaction Date", O.created_at "Order Date"
FROM ca_ecomm.transactions__receipt__charges__data T1
LEFT JOIN ca_ecomm.transactions T2
ON
T1.metadata__order_transaction_id::VARCHAR = T2.id::VARCHAR
LEFT JOIN ca_ecomm.customers C
@benjaminsehl
benjaminsehl / headless-theme-redirect.liquid
Last active November 11, 2024 20:47
Shopify Headless Theme.liquid Redirect — UPDATE: replace with this theme: https://github.com/benjaminsehl/shopify-headless-theme
{% comment %}
UPDATE: Now you can use this theme to more easily manage your redirects:
https://github.com/benjaminsehl/shopify-headless-theme
{% endcomment %}
{% assign new_website = 'https://headless-website.com/' %}
<!doctype html>
<html>
@benjaminsehl
benjaminsehl / admin-redirect-snippet.tsx
Last active June 8, 2023 16:52
Hydrogen Admin Redirects
import {useUrl, useShopQuery} from '@shopify/hydrogen';
export default function AdminRedirect({response}} {
const url = useUrl();
if (response && response.writeHead) {
response.doNotStream();
}
const {data} = useShopQuery({
@benjaminsehl
benjaminsehl / discount-link.tsx
Last active October 20, 2022 19:25
A rough implementation of discount links in Hydrogen