Skip to content

Instantly share code, notes, and snippets.

View notkurt's full-sized avatar

Kurtis Tozer notkurt

View GitHub Profile
@notkurt
notkurt / login-shim.js
Last active October 17, 2024 03:25
New Customer Accounts Login Shim
/*
Allows you to hijack the new Customer Accounts login flow and redirect to a custom page after login.
10SQ - 2024
10sq.dev
*/
const SHOP_ID = "<YOUR-SHOP-ID>";
const CLIENT_ID = "<YOUR-CLIENT-ID>"; // Install https://apps.shopify.com/headless
Query
==============================================================
query MultiRecommend {
productRecommendations1: productRecommendations(
productId: "gid://shopify/Product/8197009965299"
) {
id
handle
featuredImage {
{%- comment -%}
----------------------------------------------------------------------------------------------------------------------
SPECULATION RULES SCRIPT COMPONENT
----------------------------------------------------------------------------------------------------------------------
This snippet dynamically generates speculation rules scripts for Shopify themes, aiming to enhance loading performance by pre-rendering pages based on the type of page being viewed. It supports three primary contexts: 'page', 'product', and 'collection'.
********************************************
Section Settings
********************************************
class ForYouModule {
constructor() {
this.state = JSON.parse(
document.querySelector('[data-for-you-initial-state]').textContent
)
this.hasChanges = false
this.parseUrlParams() // Call this method to initialize the state from URL parameters
this.init()
}
<script type="application/json" data-for-you-initial-state>
{ "collections": "{{ cart.attributes['_VIEWED_COLLECTIONS'] }}", "athletes": "{{ cart.attributes['_ATHLETES'] }}", "products": "{{ cart.attributes['_VIEWED_PRODUCTS'] }}", "topics": "{{ cart.attributes['_TOPICS'] }}", "toAdd": { "topic": "{{ page_title | handleize | upcase }}" {% if page.metafields.custom.linked_athlete != blank %}, "athlete": "{{ page.metafields.custom.linked_athlete.value.system.handle }}" {% endif %} {% if product %}, "product": "{{ product.handle }}" {% if collection %},{% endif %} {% endif %} {% if collection %} "collection": "{{ collection.handle }}" {% endif %} } }
</script>
{% liquid
assign target_handle = block.settings.default_athlete
assign default_object = shop.metaobjects.tier_1_athletes[target_handle]
if cart.attributes._ATHLETES != blank
assign athlete_handles = cart.attributes._ATHLETES | split: ','
for athlete_handle in athlete_handles
assign athlete_object = shop.metaobjects.tier_1_athletes[athlete_handle]
if athlete_object != blank