Skip to content

Instantly share code, notes, and snippets.

@seedcms
seedcms / wholesale_example_1
Created February 4, 2017 05:22
Wholesale Example 1
{% for tag in customer.tags %}
{% if customer.tags contains 'Wholesale' %}
<div class="cart-item__original-price"><del>{{ item.original_line_price | money }}</del></div>
{% endif %}
{% endfor %}
<div>
{{ item.line_price | money }}
</div>
@seedcms
seedcms / wholesale customer
Created February 4, 2017 05:21
Wholesale Customer Script
Input.cart.line_items.each do |line_item|
customer = Input.cart.customer
product = line_item.variant.product
if customer.tags.include?("Wholesale")
line_item.change_line_price(line_item.line_price * 0.90, message: "Wholesale Customer")
end
end
Output.cart = Input.cart
@seedcms
seedcms / bogo
Created February 1, 2017 07:22
BOGO w/ Coupons
PAID_ITEM_COUNT = 1
DISCOUNTED_ITEM_COUNT = 1
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
def partition(cart, line_items)
sorted_items = line_items.sort_by{|line_item| line_item.variant.price}.reverse
@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?
@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 / 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 / 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 / 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 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 / % 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