Skip to content

Instantly share code, notes, and snippets.

View traels's full-sized avatar

Simon Traels Ravn traels

View GitHub Profile
class UsernameBadgeComponent < ActionView::Component::Base
include ActionView::Component::Live::Subscriber
listen_to :user
def initialize(user:)
@user = user
end
def name
class User < ApplicationRecord
include ActionView::Component::Live::Broadcaster
end
<div data-controller="live" data-live-component="UsernameBadgeComponent" data-live-id="<%= id %>">
<span class="badge badge-primary"><%= name %></span>
</div>
Spree::OrderUpdater.class_eval do
def recalculate_adjustments
# if order does not have adjustment of type "buyersgroup discount" then
# create that adjustment on the order
adjustments.includes(:source).each { |adjustment| adjustment.update! order }
end
end
Spree::Gateway::AuthorizeNet.class_eval do
def capture money, code, gateway_opts
provider.capture money, code, gateway_opts
end
end
[GEM_ROOT]/gems/activesupport-4.0.2/lib/active_support/core_ext/kernel/reporting.rb:82:in `capture`
[GEM_ROOT]/bundler/gems/spree-2d8bc75d8955/core/app/models/spree/payment/processing.rb:47:in `block in capture!`
[GEM_ROOT]/bundler/gems/spree-2d8bc75d8955/core/app/models/spree/payment/processing.rb:179:in `protect_from_connection_error`
[GEM_ROOT]/bundler/gems/spree-2d8bc75d8955/core/app/models/spree/payment/processing.rb:38:in `capture!`
[GEM_ROOT]/bundler/gems/spree-2d8bc75d8955/backend/app/controllers/spree/admin/payments_controller.rb:57:in `fire`
[GEM_ROOT]/gems/actionpack-4.0.2/lib/action_controller/metal/implicit_render.rb:4:in `send_action`
[GEM_ROOT]/gems/actionpack-4.0.2/lib/abstract_controller/base.rb:189:in `process_action`
[GEM_ROOT]/gems/actionpack-4.0.2/lib/action_controller/metal/rendering.rb:10:in `process_action`
[GEM_ROOT]/gems/actionpack-4.0.2/lib/abstract_controller/callbacks.rb:18:in `block in process_action`
[GEM_ROOT]/gems/activesupport-4.0.2/lib/active_support/callbacks.rb:493:in `_ru
@traels
traels / gist:5803959
Last active December 18, 2015 15:19
Prevent checkout without shipping method
Spree::Order.state_machine.before_transition :to => :payment, :do => :valid_shipping?
Spree::Order.class_eval do
def valid_shipping?
self.shipment.shipping_rates.count > 0
end
end
@traels
traels / taxons.rb
Last active December 18, 2015 10:29
namespace :import do
task :stuff => :environment do
require 'nokogiri'
taxonomy = Spree::Taxonomy.create!(:name => "Categories")
xref = Hash.new
category_xref = Nokogiri::HTML(open('public/u6Dn_vm_category_xref.xml'))
category_xref.encoding = 'utf-8'
category_xref.xpath('//database/table_data/row').each do |node|
xref[node.at('field[@name="category_child_id"]').text.to_i] = node.at('field[@name="category_parent_id"]').text.to_i