This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ShopifyAPI | |
module OrderDecorator | |
included do | |
before_update :remove_source_name | |
end | |
private | |
def remove_source_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($, undef){ | |
$.parseQuery = function(str){ | |
var obj = {}; | |
var soRegex = new RegExp(/\[(\S*)\]$/); // Test against sub objects / arrays | |
$.each(str.replace(/^\?/, "").split("&"), function(i, param){ | |
param = param.split("="); | |
var k = decodeURIComponent(param[0]), | |
v = decodeURIComponent(param[1]); | |
var m = k.match(soRegex); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def encrypt_token | |
aes = OpenSSL::Cipher.new('AES-256-CBC') | |
aes.encrypt | |
aes.key = Rails.application.config.shopify.secret | |
aes.iv = iv = aes.random_iv | |
encrypted = aes.update(self[:token]) | |
encrypted << aes.final | |
encoded = Base64.strict_encode64(iv + encrypted) | |
self.send(:token=, encoded) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Event Handler | |
var trackEventAndContinue; | |
(function($, undef){ | |
trackEventAndContinue = function(e){ | |
e.preventDefault(); | |
if((this.disabled !== undef && this.disabled) || $(this).hasClass('disabled')) return false; | |
$(this).unbind(e); | |
var opts = { | |
'hitType': 'event', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Weekdays | |
module NumericExtensions | |
def weekdays | |
Weekday.new(self) | |
end | |
alias :weekday :weekdays | |
end | |
module TimeExtensions | |
def weekday? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def halfdays | |
ActiveSupport::Duration.new(self*12.hours, [[:halfdays, self]]) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FooJob = Struct.new(:shop_id) do | |
def perform | |
## code ## | |
end | |
include ShopifyJobHooks | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FooJob = ShopifyJob.new(:shop_id) do | |
def perform | |
## code I want wrapped in superclass' session call ## | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Order < ActiveRecord::Base | |
def self.fulfillable_for(product_id) | |
select("orders.*, COUNT(up.product_id) AS unfulfillable"). | |
joins(:order_items). | |
joins("LEFT JOIN order_items oi ON oi.order_id = order_items.order_id AND oi.product_id != order_items.product_id"). | |
joins("LEFT JOIN products up ON up.product_id = oi.product_id AND up.available_at > #{ActiveRecord::Base.sanitize(Date.today)}"). | |
where(order_items: { product_id: product_id} ). | |
group("order_items.order_id"). | |
having("unfulfillable <= 0") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ProductDecorator | |
extend ActiveSupport::Concern | |
def fulfillable_product | |
FulfillableProduct.find_or_initialize_by(product_id: id) | |
end | |
def available_at | |
fulfillable_product.available_at | |
end |