Skip to content

Instantly share code, notes, and snippets.

View peterberwind's full-sized avatar

Peterberwind peterberwind

View GitHub Profile
test 1234
123
123
123
@peterberwind
peterberwind / Prismic.Factory.js
Created November 20, 2016 01:47
Xipsy Prismic.Factory.js
'use strict'
angular.module('$XipsyPrismic', [])
// Everything Prismic Related
.factory('$XipsyPrismicFactory', function($window, $q){
// Initial Prismic Setup
var Prismic = $window.Prismic
var config = {}
config.url = 'https://xipsy.prismic.io/api'
// Maybe we need that stuff later (?)
config.accessToken = 'MC5XQ1MtSkNZQUFDWUFMdFV3.77-9AO-_ve-_ve-_ve-_vWLvv71077-9GO-_vXLvv70977-977-9aSnvv73vv73vv70NU--_vV91ee-_vRs-77-9'
@peterberwind
peterberwind / Checkout.js
Last active November 25, 2016 00:23
Checkout Customization
<script type="text/javascript">
function replaceText(selector, text, newText, flags) {
var matcher = new RegExp(text, flags);
$(selector).each(function () {
var $this = $(this);
if (!$this.children().length)
$this.text($this.text().replace(matcher, newText));
});
}
function replaceAllText() {
@peterberwind
peterberwind / gist:8daabe4aa130969fbb5320184b0ec67a
Created May 3, 2017 20:39
Shopify Script: Buy 2 Get 1 Free
PAID_ITEM_COUNT = 2
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
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
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
@peterberwind
peterberwind / gist:f7404e07292cd5787b6e29f0c9998046
Created May 3, 2017 20:40
Buy X quantity of a product, Get $Y off
DISCOUNTS_BY_QUANTITY = {
10_000 => 20,
1_000 => 15,
100 => 10,
10 => 5,
}
Input.cart.line_items.each do |line_item|
next if line_item.variant.product.gift_card?
@peterberwind
peterberwind / gist:383a5049a69d8f34756204ea745f689c
Created May 3, 2017 20:40
Buy X quantity of a product, Get Y% off
DISCOUNTS_BY_QUANTITY = {
10_000 => 20,
1_000 => 15,
100 => 10,
10 => 5,
}
Input.cart.line_items.each do |line_item|
next if line_item.variant.product.gift_card?
@peterberwind
peterberwind / gist:ea041e4176c1dadc3d1e519114cd1983
Created May 3, 2017 20:41
X% off all products with Y tag
@percent = Decimal.new(25) / 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?('myTag')
line_discount = line_item.line_price * @percent
line_item.change_line_price(line_item.line_price - line_discount, message: "25% Off")
end
Output.cart = Input.cart