Skip to content

Instantly share code, notes, and snippets.

View dylanjhunt's full-sized avatar

Dylan Hunt dylanjhunt

View GitHub Profile
@dylanjhunt
dylanjhunt / gist:6453373
Last active December 22, 2015 09:39
Shopify
I started at Shopify on Tuesday, September 3rd, 2013.
self.per_page = 15
gem 'stripe'
rails g controller charges
def new
end
def create
# Amount in cents
@amount = 500
customer = Stripe::Customer.create(
:email => params[:stripeEmail],
:source => params[:stripeToken]
bin/rails generate migration NameOfMigration
class NameOfMigration < ActiveRecord::Migration[5.0]
def change
end
end
@dylanjhunt
dylanjhunt / Shopify Script - $5 Discount on Products with a certain tag
Created November 2, 2016 16:58
This will give a $5 discount on any product that has the tag identified in this Gist with MyTag
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
next if product.gift_card?
next unless product.tags.include?('MyTag')
line_item.change_line_price(line_item.line_price - Money.new(cents: 500), message: "$5 Off")
end
Output.cart = Input.cart
@dylanjhunt
dylanjhunt / Shopify Script - Buy 1 Get 1 for X% off
Created November 2, 2016 17:01
This will give a Buy 1 Get 1 discount percentage for the product ID marked on line 63 with the discount outlined on line 30
PAID_ITEM_COUNT = 1
DISCOUNTED_ITEM_COUNT = 1
# Returns the integer amount of items that must be discounted next
# given the amount of items seen
#
def discounted_items_to_find(total_items_seen, discounted_items_seen)
Integer(total_items_seen / (PAID_ITEM_COUNT + DISCOUNTED_ITEM_COUNT) * DISCOUNTED_ITEM_COUNT) - discounted_items_seen
end
{% if cart.item_count == 0 %}
<div class="sixteen columns">
<div class="section clearfix">
<div class="six columns offset-by-five">
<p class="quote">{{ 'cart.general.continue_browsing_html' | t }}</p>
<a href="{% if cart.items.first.product.collections != blank %}{{ cart.items.first.product.collections.last.url }}{% else %}/collections/all{% endif %}" class="action_button continue-button add_to_cart">{{ 'cart.general.continue_shopping_link_html' | t }}</a>
</div>
<br class="clear" />
</div>
</div>