Last active
May 8, 2019 19:31
-
-
Save iloveitaly/3187793 to your computer and use it in GitHub Desktop.
Snippets for Spree Commerce Development
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
# with my git configuration the spree repo was giving me issues with line endings | |
# this fixed the issue for me: marking a file as binary causes git to ignore it completely | |
core/vendor/assets/javascripts/jquery.alerts/jquery.alerts.css.erb binary | |
core/vendor/assets/javascripts/jquery.alerts/jquery.alerts.js binary | |
core/vendor/assets/javascripts/jquery.jstree/themes/apple/style.css binary | |
sample/db/sample/spree/line_items.yml binary | |
sample/db/sample/spree/products.yml binary |
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
# `gem install sequel` or add sequel to Gemfile | |
# this will copy over your dev DB to a sqlite test db | |
# assumes your dev DB is a mysql DB and cwd is the project dir | |
rm $PWD/db/test.sqlite3; sequel mysql2://root:root@localhost/spree -C sqlite://$PWD/db/test.sqlite3 |
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
# create global zone containing everything but USA | |
global_zone = Spree::Zone.find_or_initialize_by_name 'Global Zone' do |z| | |
excluded_countries = ['US'] | |
member_list = Spree::Country.find(:all, :conditions => ['iso not in (?)', excluded_countries.map { |c| "'#{c}'" }.join(',')]) | |
puts "Creating Global Zone With Members: #{member_list.map(&:iso)}" | |
member_list.each do |member| | |
z.zone_members.build :zoneable_type => 'Spree::Country', :zoneable_id => member.id | |
end | |
z.description = "Global Zone (excluding US)" | |
z.save! | |
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
Spree::Payment.class_eval do | |
def gateway_error(error) | |
if error.is_a? ActiveMerchant::Billing::Response | |
text = error.params['message'] || error.params['response_reason_text'] || error.message | |
elsif error.is_a? ActiveMerchant::ConnectionError | |
text = I18n.t(:unable_to_connect_to_gateway) | |
else | |
text = error.to_s | |
end | |
logger.error(I18n.t(:gateway_error)) | |
logger.error(" #{error.to_yaml}") | |
exc = Spree::Core::GatewayError.new(text) | |
Airbrake.notify exc, :parameters => (error.is_a? ActiveMerchant::Billing::Response)? error.params : {} | |
raise exc | |
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
# log active merchant errors; working off of 1.1.3 source code | |
Spree::Payment.class_eval do | |
def gateway_error(error) | |
if error.is_a? ActiveMerchant::Billing::Response | |
text = error.params['message'] || error.params['response_reason_text'] || error.message | |
elsif error.is_a? ActiveMerchant::ConnectionError | |
text = I18n.t(:unable_to_connect_to_gateway) | |
else | |
text = error.to_s | |
end | |
logger.error(I18n.t(:gateway_error)) | |
logger.error(" #{error.to_yaml}") | |
exc = Spree::Core::GatewayError.new(text) | |
Airbrake.notify exc, :parameters => (error.is_a? ActiveMerchant::Billing::Response)? error.params : {} | |
raise exc | |
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
# for the whenever gem; fixes the rake execution issues | |
# be sure to create the /var/log/cron.log and `chown spree:spree` | |
# server is configured with spree deployment service | |
env :PATH, ENV['PATH'] | |
set :output, "/var/log/cron.log" |
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
# updates shipments with approximate shipped date | |
# manual DB migration for: https://github.com/spree/spree/commit/cc10ec3aa390b8581cddc343ae4409e89996e783 | |
Spree::Shipment.where("state = 'shipped' and shipped_at IS NULL").select { |s| s.order.state == 'complete' }.each { |s| s.update_column(:shipped_at, s.order.completed_at) } |
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
# when we are testing, we want to see the errors... | |
if Rails.env.test? or Rails.env.development? | |
Spree::OrdersController.class_eval do | |
private | |
def handle_shipping_error(e) | |
raise e | |
end | |
end | |
Spree::CheckoutController.class_eval do | |
private | |
def handle_shipping_error(e) | |
raise e | |
end | |
end | |
else | |
# in production, push all errors to airbrake | |
Spree::OrdersController.class_eval do | |
private | |
def handle_shipping_error(e) | |
Airbrake.notify e | |
flash[:error] = e.message | |
redirect_to checkout_state_path(:address) | |
end | |
end | |
Spree::CheckoutController.class_eval do | |
private | |
def handle_shipping_error(e) | |
Airbrake.notify e | |
flash[:error] = e.message | |
redirect_to checkout_state_path(:address) | |
end | |
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
Spree::Digital.class_eval do | |
has_attached_file :attachment, :path => '/data/spree/shared/uploaded-files/digitals/:id/:basename.:extension' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In second gist (for spree_digital override)
Spree::Config.get(:site_url)
should be replaced (since Spree 2.3) withcurrent_store.url
.Source: https://spreecommerce.com/blog/spree-2-3-released