Skip to content

Instantly share code, notes, and snippets.

@agmcleod
Created February 17, 2012 04:14
Show Gist options
  • Save agmcleod/1850574 to your computer and use it in GitHub Desktop.
Save agmcleod/1850574 to your computer and use it in GitHub Desktop.
class CharityProductDeleteJob < Struct.new(:charity_id, :shop_id)
def perform
charity = Charity.find(charity_id)
shop = Shop.find(shop_id)
ShopifyAPI::Base.site = shop.api_url
products = ShopifyAPI::Product.find(:all, params: { handle: "#{charity.handle}-charity" })
unless products.blank?
Rails.logger.debug "Destroy product"
products.each { |p| p.destroy }
end
charity.update_attribute(:enabled, false)
scripts = ShopifyAPI::ScriptTag.find(:all, params: { src: "http://#{DomainConfiguration.domain}/charities/#{charity.id}.js" })
unless scripts.blank?
puts "Destroy script tags"
Rails.logger.debug "Destroy script tags"
scripts.each { |s| s.destroy }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment