Skip to content

Instantly share code, notes, and snippets.

@seedcms
seedcms / cart.liquid
Created January 18, 2017 23:54
Cart table after the updated line items
<tbody class="line-items">
{% for item in cart.items %}
<tr>
<td>{{ item.product.title }}</td>
<td>{{ item.quantity }}</td>
<td>
{{ item.line_price }}
{% if item.total_discount > 0 %}
<s>{{ item.original_line_price }}</s>
( {{ item.message }} )
@seedcms
seedcms / cart.liquid
Created January 18, 2017 23:57
Updated cart summary
<tfoot class="summary">
<tr>
<td colspan="2">Subtotal</td>
<td>{{ cart.original_total_price | money }}</td>
</tr>
<tr>
<td colspan="2">Discount Savings</td>
<td>{{ cart.total_discount | money }}</td>
</tr>
<tr>
@seedcms
seedcms / % off tag
Created January 19, 2017 21:57
Take a percentage off any products with a specific tag.
@percent = Decimal.new(40) / 100.0
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
next if product.gift_card?
next unless product.tags.include?('hugesale')
line_discount = line_item.line_price * @percent
line_item.change_line_price(line_item.line_price - line_discount, message: "HUGESALE! 40% off this item!")
end
Output.cart = Input.cart
@seedcms
seedcms / % off vendor
Created January 19, 2017 22:30
Take a percentage off the product based on vendor
@percent = Decimal.new(20) / 100.0
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
next if product.gift_card?
next unless product.vendor.include?('Nike')
line_discount = line_item.line_price * @percent
line_item.change_line_price(line_item.line_price - line_discount, message: "20% off all Nike products!")
end
Output.cart = Input.cart
@seedcms
seedcms / Free gift form
Created January 22, 2017 00:34
Product Form Free Gift
<button type="submit" name="add" id="AddToCart-{{ section.id }}" {% unless current_variant.available %}disabled="disabled"{% endunless %} class="btn product-form__cart-submit{% if product.options.size == 1 and product.variants[0].title == 'Default Title' %} product-form__cart-submit--small{% endif %} {% if product.handle contains 'free-gift' %}free_item{% endif %}">
@seedcms
seedcms / free-gift-add.js
Created January 22, 2017 00:39
Add to Cart JS
(function(){
$('.add_to_cart').on('click', function(e){
var variantId = VARIANTID GOES HERE;
jQuery.getJSON('/cart.js', function(data){
var items = data.items;
console.log(items);
var currentVarId;
var quantity;
@seedcms
seedcms / Free gift script
Created January 22, 2017 00:51
Free Gift Script
discounted_product = FREE GIFT ID
products_needed = [PRODUCT THAT NEEDS TO BE ADDED FOR FREE GIFT]
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
products_seen << product.id if products_needed.include?(product.id)
end
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
@seedcms
seedcms / fgs
Created January 22, 2017 01:15
Free Gift Script
discounted_product = FREE GIFT PRODUCT.ID
products_needed = [NEEDED PRODUCT.ID]
products_seen = []
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
products_seen << product.id if products_needed.include?(product.id)
end
Input.cart.line_items.each do |line_item|
@seedcms
seedcms / bundle script
Created January 22, 2017 01:57
10% off 3 items / 15% off 7 items via product type
item = 0
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
if product.product_type == "Underwear"
item+=line_item.quantity
elsif product.product_type == "Socks"
item+=line_item.quantity
end
end
@seedcms
seedcms / quantity_breaks.rb
Created January 22, 2017 18:34
Quantity Breaks
DISCOUNTS_BY_QUANTITY = {
100 => 20,
50 => 15,
25 => 10,
10 => 5,
}
Input.cart.line_items.each do |line_item|
next if line_item.variant.product.gift_card?