Skip to content

Instantly share code, notes, and snippets.

View dhonig's full-sized avatar

Daniel Honig dhonig

View GitHub Profile
@dhonig
dhonig / BooYah
Created April 2, 2014 09:18
EXAMPLE Filtering within a term query
POST /development_en/product/_search
{
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"match_all": {}
}
context "Searching" do
let!(:taxon) { create(:taxon, name: "shirts") }
let!(:taxon2) { create(:taxon, name: "shoes") }
let!(:a_product) { create(:product, taxons: [taxon], stores: [store],
description: "A product in english", price: 20) }
let!(:another_product) { create(:product, taxons: [taxon, taxon2], stores: [store], price: 80) }
end
@dhonig
dhonig / gist:f2ca099053afe9ca4f31
Created September 10, 2015 16:54
turn off admin alerts
RAILS_ENV=production bundle exec rails runner "Spree::Config.check_for_spree_alerts = false"
def update!(target = nil)
return amount if closed?
if source.present?
amount = source.compute_amount(target || adjustable)
self.update_columns(
amount: amount,
updated_at: Time.now,
)
if promotion?
self.update_column(:eligible, source.promotion.eligible?(adjustable))
def open_adjustments
adjustments = @order.all_adjustments.where(state: 'closed')
adjustments.update_all(state: 'open')
flash[:success] = Spree.t(:all_adjustments_opened)
respond_with(@order) { |format| format.html { redirect_to :back } }
end
describe 'Transfers between shipments' do
let(:user) { stub_model(Spree::User, :email => "spree@example.com") }
#populated with order,email bill_address and ship_address,
let(:order) { FactoryGirl.create(:order_with_line_items) }
let(:a_variant){FactoryGirl.create(:variant)}
it 'should It should transfer items between shipments without adding line items' do
stock_location=order.shipments.first.stock_location
variant=stock_location.stock_items.first.variant
Spree::Shipment.class_eval do
audited associated_with: :order
has_associated_audits
def transfer_to_shipment(variant, quantity, shipment_to_transfer_to)
quantity_already_shipment_to_transfer_to = shipment_to_transfer_to.manifest.find{|mi| mi.line_item.variant == variant}.try(:quantity) || 0
if (quantity <= 0 || self == shipment_to_transfer_to)
Rails.application.routes.draw do
# This line mounts Spree's routes at the root of your application.
# This means, any requests to URLs such as /products, will go to Spree::ProductsController.
# If you would like to change where this engine is mounted, simply change the :at option to something different.
#
# We ask that you don't use the :as option here, as Spree relies on it being the default of "spree"
mount Spree::Core::Engine, :at => '/'
Spree::Core::Engine.add_routes do
namespace :api do
Rails.application.routes.draw do
# This line mounts Spree's routes at the root of your application.
# This means, any requests to URLs such as /products, will go to Spree::ProductsController.
# If you would like to change where this engine is mounted, simply change the :at option to something different.
#
# We ask that you don't use the :as option here, as Spree relies on it being the default of "spree"
mount Spree::Core::Engine, :at => '/'
Spree::Core::Engine.add_routes do
namespace :api do
@dhonig
dhonig / gist:1867270
Created February 20, 2012 02:14
Stacktrace
activesupport (3.1.3) lib/active_support/xml_mini/rexml.rb:36:in `parse'
org/jruby/RubyKernel.java:2078:in `send'
activesupport (3.1.3) lib/active_support/xml_mini.rb:79:in `parse'
activesupport (3.1.3) lib/active_support/core_ext/hash/conversions.rb:90:in `from_xml'
/home/daniel/.rvm/gems/jruby-1.6.6@burrito/bundler/gems/spree_active_shipping-e53dba0632dc/lib/spree/active_shipping/ups_override.rb:266:in `parse_rate_response'
/home/daniel/.rvm/gems/jruby-1.6.6@burrito/bundler/gems/spree_active_shipping-e53dba0632dc/lib/spree/active_shipping/ups_override.rb:198:in `find_rates'
/home/daniel/.rvm/gems/jruby-1.6.6@burrito/bundler/gems/spree_active_shipping-e53dba0632dc/app/models/spree/calculator/active_shipping/base.rb:69:in `retrieve_rates'
/home/daniel/.rvm/gems/jruby-1.6.6@burrito/bundler/gems/spree_active_shipping-e53dba0632dc/app/models/spree/calculator/active_shipping/base.rb:34:in `compute'
activesupport (3.1.3) lib/active_support/cache.rb:297:in `fetch'
activesupport (3.1.3) lib/active_support/cache.rb:5