Skip to content

Instantly share code, notes, and snippets.

View darryn's full-sized avatar

Darryn Soper darryn

View GitHub Profile
@darryn
darryn / line-item-script.rb
Created January 30, 2024 07:35
Shopify Script to discount items in cart based on customer tag, absence of discount code, and excluded products
products_to_exclude = [444750805, 444750821] #product ids to exclude
trigger_customer_tag = 'member-50' #customer tags to trigger script discount
if Input.cart&.customer&.tags.include?(trigger_customer_tag) && Input.cart&.discount_code == nil #does the customer have the right tag, and are there no discounts applied?
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
next if product.gift_card? # don't discount gift cards
next if products_to_exclude.include?(product.id) # don't discount excluded products
line_item.change_line_price(line_item.line_price * 0.50, message: "Pro Deal - 50% Discount") #discount everything else by X%
@darryn
darryn / index.js
Created September 7, 2023 04:51
B2B Fulfillment Constraints
// @ts-check
// Use JSDoc annotations for type safety.
/**
* @typedef {import("../generated/api").InputQuery} InputQuery
* @typedef {import("../generated/api").FunctionResult} FunctionResult
*/
/**
* @type {FunctionResult}
*/
const NO_CHANGES = {
@darryn
darryn / 1. priceListCreate
Last active February 26, 2024 01:41
B2B APIs
mutation priceListCreate($input: PriceListCreateInput!) {
priceListCreate(input: $input) {
priceList {
id
}
userErrors {
field
message
}
}
@darryn
darryn / gift_card_google_script.js
Last active July 12, 2022 11:13
Shopify Gift Card Importer Google App Script
const sheet = SpreadsheetApp.getActive().getSheetByName("[sheet_name]");
const data = sheet.getDataRange().getValues();
function postData(giftData) {
let options = {
'method' : 'post',
'contentType': 'application/json',
'payload' : JSON.stringify(giftData),
'headers': {
@darryn
darryn / blog-loop
Created June 1, 2015 14:39
Output blog articles
<ul>
{% for article in blogs.news.articles %}
<li>
<h4>{{ article.title }}</h4>
{{ article.content }}
</li>
{% endfor %}
</ul>
{% for refund in refunds %}
{% for item in refund.refund_line_items %}
{% for line in line_items %}
{% if item.line_item_id == line.id %}
title: {{ line.title }}
price: {{ line.price | money }}
{% endif %}
{% endfor %}
quantity: {{ item.quantity }}
{% endfor %}
@darryn
darryn / 0_reuse_code.js
Last active August 29, 2015 14:14
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
@darryn
darryn / typeahead with price
Created December 1, 2014 20:25
Shopify - Typeahead with price
<input id="search-input" name="q" type="text" class="search-query" placeholder="{{ 'general.search.search_button' | t }}" data-provide="typeahead" data-source="[{% for product in collections[settings.typeahead_collection].products %}&quot;{{ product.title }} - {{ product.price | money | strip_html }}&quot;{% unless forloop.last %},{% endunless %}{% endfor %}]" autocomplete="off">
@darryn
darryn / custom line item metafields
Created December 1, 2014 03:11
Shopify - custom line items with metafields
{% if product.metafields.properties.size > 0 %}
<div class="col-xs-12 col-lg-6">
{% for l_item in product.metafields.properties %}
{% assign key = l_item.first | split: ':' %}
{% assign key_type = key.last %}
{% assign key_title = key.first %}
{% assign value = l_item.last %}
<div class="form-group">
<label>{{ key_title }}</label>
{% if key_type == 'select' %}
@darryn
darryn / settings.html
Created November 16, 2014 20:20
Lucid One - Responsive Checkout Settings HTML
<fieldset data-overrides-fieldset="checkout">
<legend>Checkout</legend>
<table>
<tbody>
<tr>
<td colspan="2">
<h3>Banner</h3>
</td>
</tr>
<tr class="horizontal">