Skip to content

Instantly share code, notes, and snippets.

View lsorese's full-sized avatar
🧻
The Tower

Logan Sorese lsorese

🧻
The Tower
View GitHub Profile
@lsorese
lsorese / gtm_pixel.js
Created August 19, 2024 16:14
ST Existing GTM Pixel
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer', 'GTM-NDRSNM');
const script = document.createElement('script');
script.src = 'https://www.googletagmanager.com/gtag/js?id=AW-963004865';
script.async = true;
document.head.appendChild(script);
@lsorese
lsorese / graphql
Last active August 6, 2024 21:54
The 2024-01 Shopify API update introduced the separation of orders and transactions, with transactions now retrieved through a separate query. The refunds is a vestiage of an old system and may be removed in the future. You can query this using graphql which will provide then all in one call.
{
shop {
name
orders(first: 10) {
nodes {
id
... OTHER FIELDS ...
transactions(first: 10) {
amountSet {
shopMoney {
<script>
// NEW GWP DATA
// https://cdn.shopify.com/s/files/1/0367/5301/products/underwater-camera-check_360x.jpg
{% comment %}
{% assign gwpNew1Product = all_products['sunnylife-luxe-beach-umbrella-more-colors'] %}
{% assign gwpNew2Product = all_products['sunnylife-luxe-beach-umbrella-more-colors'] %}
{% assign gwpNew1Variant = 39835307409507 %}
{% assign gwpNew2Variant = 39835307442275 %}
const updateAltImage = ({
variantId,
productImageUrls,
productImageAlts,
images,
}) => {
let image = {};
const imageRegex = {
activeVariantB: new RegExp(`${variantId}(_([0-9]*_)*)b`),
otherVariantB: new RegExp('[0-9]{1,6}(_([0-9]*_)*)b'),
async function getInventoryLevelsForProduct(productId) {
if (window.queryapi == false) return;
if (inventoryCache) {
applyInventoryLevels(inventoryCache);
return;
}
const query = `
{
product(id: "gid://shopify/Product/${productId}") {
import shipper from 'shopify-shipping-calculator';
import queryCartProductData from '@/scripts/storefront/queries/queryCartProductData';
import storefront from '@/scripts/storefront/storefront';
// Snippets
import '@/scripts/snippets/cart-rewards';
import '@/scripts/snippets/cart-free-gift';
/* eslint no-underscore-dangle: 0 */
class CustomCart extends HTMLElement {
/** @jsx h */
/* global globalSwatches */
import { h } from 'preact'
import { useProduct } from './product-context'
const queryableArray = (array) => {
return array.reduce((acc, current) => {
const key = current.swatchID
delete current.swatchID
acc[key] = current
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
@lsorese
lsorese / yotpo-reviews.js
Last active June 6, 2023 16:07
Yotpo Reviews for 0.5.0
import { h } from 'preact';
import { useEffect } from 'preact/hooks';
const Reviews = ({ id }) => {
useEffect(() => {
if (window.yotpoWidgetsContainer?.initWidgets) {
window.yotpoWidgetsContainer.initWidgets();
}
}, [id]);