Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spree-2-2-stable updates #101

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
263525a
change dependency to allow Spree 2.1
charredUtensil Oct 15, 2013
db4287f
initial 2.0 changes, at least get the app to start
charredUtensil Oct 15, 2013
88691e1
get product customizations working on spree 2.1 / rails 4
charredUtensil Oct 19, 2013
5aad882
get ad hoc options working on spree 2.0 / rails 4
charredUtensil Oct 21, 2013
257dce3
vix ad hoc options
charredUtensil Oct 22, 2013
0148b00
use correct function to draw routes
charredUtensil Nov 1, 2013
7053116
use actual correct method this time
charredUtensil Nov 1, 2013
d979cc8
fix layout of products page
charredUtensil Nov 4, 2013
5f3a2a8
fix columns correctly
charredUtensil Nov 4, 2013
14e311e
fix styling on product cart form
charredUtensil Nov 4, 2013
64b9ed0
fix crash on engraving calculator cost = 0, use descriptions for cust…
charredUtensil Nov 7, 2013
aa00ceb
accidentally committed two files
charredUtensil Nov 7, 2013
13ba838
protect against nil cost_price
jsqu99 Nov 11, 2013
057c2f4
Update merge! method within order_decorator to match the syntax of me…
jfields Nov 14, 2013
1b68779
undoes the undoing of option.presentation for option.description
jsqu99 Nov 14, 2013
64175fa
Merge pull request #87 from jfields/spree-2-1-wip
jsqu99 Nov 15, 2013
3b18014
beta work on using the 'new' order populator
jsqu99 Nov 16, 2013
baa18d1
Merge branch 'master' of github.com:jsqu99/spree_flexi_variants into …
jsqu99 Nov 16, 2013
5124eb8
fixes merge conflict
jsqu99 Nov 16, 2013
89c1a94
more versioning to get right w/ spree 2.1. Also, added a no_charge c…
jsqu99 Nov 17, 2013
af917e0
adds missing files
jsqu99 Nov 17, 2013
221e3fd
adds testing improvements
jsqu99 Nov 20, 2013
b4d1f18
made some possibly-unecessary changes to the way the calculators are …
jsqu99 Nov 21, 2013
2de9573
fix Javascript error on engraving calculator
charredUtensil Jan 6, 2014
023a361
Updates to support Spree 2.2
chunkerchunker Feb 25, 2014
ba49995
Allow host app to predefine product_customization calculators.
chunkerchunker Feb 25, 2014
b802514
Typo in amount_times_constant calculator client js.
chunkerchunker Feb 25, 2014
4d61cbb
Minor styling cleanup.
chunkerchunker Feb 25, 2014
1dcdd86
typo in order_decorator
chunkerchunker Mar 1, 2014
cd0f2a1
Allow product customization pricing based on associated line_item con…
chunkerchunker Mar 5, 2014
be9ff6b
typo in order_contents_decorator
chunkerchunker Mar 6, 2014
fb9404b
minor style cleanup
chunkerchunker Mar 6, 2014
e95a76a
line_item validations could lead to unsaved product_customizations
ssendev Apr 7, 2014
92c4b73
Merge remote-tracking branch 'ssendev/spree_flexi_variants/patch-1' i…
chunkerchunker Jun 19, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
source 'http://rubygems.org'

gem 'spree', '~> 1.3.2'

if RUBY_VERSION < "1.9"
gem "ruby-debug"
else
gem "ruby-debug19"
group :development, :test do
gem 'spree', github: 'spree/spree', branch: '2-1-stable'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-1-stable'
end

=begin
group :test do
gem 'rspec-rails', '2.12.0'
gem 'sqlite3'
Expand All @@ -17,8 +15,9 @@ group :test do
gem 'launchy'
gem 'pry'
end

group :assets do
gem 'coffee-rails'
end
=end

gemspec
47 changes: 8 additions & 39 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,46 +1,15 @@
require 'rake'
require 'rake/testtask'
require 'rake/packagetask'
require 'rubygems/package_task'
require 'rspec/core/rake_task'
require 'spree/core/testing_support/common_rake'

gemfile = File.expand_path('../spec/test_app/Gemfile', __FILE__)
if File.exists?(gemfile) && (%w(spec cucumber).include?(ARGV.first.to_s) || ARGV.size == 0)
require 'bundler'
ENV['BUNDLE_GEMFILE'] = gemfile
Bundler.setup

require 'rspec'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new
end

desc "Default Task"
task :default => [:spec ]
require 'bundler'
Bundler::GemHelper.install_tasks

spec = eval(File.read('spree_flexi_variants.gemspec'))
require 'rspec/core/rake_task'
require 'spree/testing_support/common_rake'

Gem::PackageTask.new(spec) do |p|
p.gem_spec = spec
end
RSpec::Core::RakeTask.new

desc "Release to gemcutter"
task :release => :package do
require 'rake/gemcutter'
Rake::Gemcutter::Tasks.new(spec).define
Rake::Task['gem:push'].invoke
end
task :default => [:spec]

desc "Generates a dummy app for testing"
desc 'Generates a dummy app for testing'
task :test_app do
ENV['LIB_NAME'] = 'spree_flexi_variants'
Rake::Task['common:test_app'].invoke
end

namespace :test_app do
desc 'Rebuild test database'
task :rebuild_dbs do
system("cd spec/test_app && bundle exec rake db:drop db:migrate RAILS_ENV=test")
end
Rake::Task['common:test_app'].invoke 'Spree::User'
end
2 changes: 1 addition & 1 deletion app/assets/javascripts/admin/spree_flexi_variants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//= require admin/spree_core
//= require spree/backend
//= require jquery.formatCurrency-1.4.0.min
//= require i18n/jquery.formatCurrency.all
//= require_tree
2 changes: 1 addition & 1 deletion app/assets/javascripts/store/spree_flexi_variants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//= require store/spree_core
//= require spree/frontend
//= require jquery.formatCurrency-1.4.0.min
//= require i18n/jquery.formatCurrency.all
//= require_self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def update_positions
def destroy
ad_hoc_option_value = AdHocOptionValue.find(params[:id])
ad_hoc_option_value.destroy
render :text => nil
redirect_to edit_admin_product_ad_hoc_option_type_path(
ad_hoc_option_value.ad_hoc_option_type.product_id,
ad_hoc_option_value.ad_hoc_option_type_id)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ def create

ave.product=@product
ave.save
redirect_to admin_product_ad_hoc_variant_exclusions_url(@product)
redirect_to admin_product_ad_hoc_variant_exclusions_path(@product)
end

# TODO how is this different than the default 'destroy'. maybe I don't need this method
def remove
@product=@ad_hoc_variant_exclusion.product
@ad_hoc_variant_exclusion.destroy
flash.notice = I18n.t("notice_messages.ad_hoc_variant_exclusion_removed")
redirect_to admin_product_ad_hoc_variant_exclusions_url(@product)
redirect_to admin_product_ad_hoc_variant_exclusions_path(@product)
end

protected
Expand Down
27 changes: 11 additions & 16 deletions app/controllers/spree/orders_controller_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,20 @@ module Spree
# Currently, we are assuming the inbound ad_hoc_option_values and customizations apply to the entire inbound product/variant 'group', as more surgery
# needs to occur in the cart partial for this to be done 'right'
#
# Adds a new item to the order (creating a new order if none already exists)
def populate
@order = current_order(true)
populator = Spree::OrderPopulator.new(current_order(create_order_if_necessary: true), current_currency)

params[:products].each do |product_id,variant_id|
quantity = params[:quantity].to_i if !params[:quantity].is_a?(Hash)
quantity = params[:quantity][variant_id].to_i if params[:quantity].is_a?(Hash)
@order.add_variant(Variant.find(variant_id), quantity, ad_hoc_option_value_ids, product_customizations) if quantity > 0
end if params[:products]
if populator.populate(params[:variant_id], params[:quantity], ad_hoc_option_value_ids, product_customizations)
current_order.ensure_updated_shipments

params[:variants].each do |variant_id, quantity|
quantity = quantity.to_i
@order.add_variant(Variant.find(variant_id), quantity, ad_hoc_option_value_ids, product_customizations) if quantity > 0
end if params[:variants]

fire_event('spree.cart.add')
fire_event('spree.order.contents_changed')

redirect_to cart_path if request.format.html?
respond_with(@order) do |format|
format.html { redirect_to cart_path }
end
else
flash[:error] = populator.errors.full_messages.join(" ")
redirect_to :back
end
end

end
end
15 changes: 0 additions & 15 deletions app/helpers/spree/admin/base_helper_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,15 +0,0 @@
module Spree
module Admin
BaseHelper.module_eval do
#renders hidden field and link to remove record using nested_attributes
def link_to_remove_nested_fields(name, f, options = {})
name = '' if options[:no_text]
options[:class] = '' unless options[:class]
options[:class] += 'no-text with-tip' if options[:no_text]
options[:nest] = '' unless options[:nest]
url = f.object.persisted? ? [:admin, options[:nest], f.object] : '#'
link_to_with_icon('icon-trash', name, url, :class => "remove_fields #{options[:class]}", :data => {:action => 'remove'}, :title => t(:remove)) + f.hidden_field(:_destroy)
end
end
end
end
2 changes: 1 addition & 1 deletion app/models/spree/ad_hoc_option_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AdHocOptionType < ActiveRecord::Base
accepts_nested_attributes_for :ad_hoc_option_values, :allow_destroy => true

# currently no controller for normal users present
attr_accessible :is_required, :ad_hoc_option_values_attributes, :product_id, :option_type_id, :position
#attr_accessible :is_required, :ad_hoc_option_values_attributes, :product_id, :option_type_id, :position

default_scope order(:position)

Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/ad_hoc_option_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class AdHocOptionValue < ActiveRecord::Base
has_many :excluded_ad_hoc_option_values, :dependent => :destroy

# currently no controller for normal users present
attr_accessible :price_modifier, :ad_hoc_option_type_id, :option_value_id, :selected, :cost_price_modifier
#attr_accessible :price_modifier, :ad_hoc_option_type_id, :option_value_id, :selected, :cost_price_modifier

# this opens up a can of worms..deleting option values and having historical data still intact...ugh...what to do?...add 'deleted_at' somewhere along the chain?
# has_many :ad_hoc_option_values_line_items, :dependent => :destroy
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/calculator/amount_times_constant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Calculator::AmountTimesConstant < Calculator
preference :min_amount, :integer, :default=>0
preference :max_amount, :integer, :default=>100

attr_accessible :preferred_multiplier, :preferred_min_amount, :preferred_max_amount
#attr_accessible :preferred_multiplier, :preferred_min_amount, :preferred_max_amount

def self.description
"Amount Times Constant Calculator"
Expand Down
4 changes: 3 additions & 1 deletion app/models/spree/calculator/customization_image.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require_dependency 'spree/calculator'

module Spree
class Calculator::CustomizationImage < Calculator
preference :price, :decimal
attr_accessible :preferred_price, :decimal
#attr_accessible :preferred_price, :decimal

def self.description
"Product Customization Image Calculator"
Expand Down
6 changes: 4 additions & 2 deletions app/models/spree/calculator/engraving.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require_dependency 'spree/calculator'

module Spree
class Calculator::Engraving < Calculator
preference :price_per_letter, :decimal
attr_accessible :preferred_price_per_letter
#attr_accessible :preferred_price_per_letter

def self.description
"Engraving Calculator"
Expand All @@ -24,7 +26,7 @@ def compute(product_customization, variant=nil)

# expecting only one CustomizedProductOption
opt = product_customization.customized_product_options.detect {|cpo| cpo.customizable_product_option.name == "inscription" } rescue ''
opt.value.length * preferred_price_per_letter
opt.value.length * (preferred_price_per_letter || 0)
end

def valid_configuration?(product_customization)
Expand Down
28 changes: 28 additions & 0 deletions app/models/spree/calculator/no_charge.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require_dependency 'spree/calculator'

module Spree
class Calculator::NoCharge < Calculator
def self.description
"This customization has no charge"
end

def self.register
super
ProductCustomizationType.register_calculator(self)
end

def create_options
# This calculator knows that it needs one CustomizableOption named amount
[
]
end

def compute(product_customization, variant=nil)
return 0
end

def valid_configuration?(product_customization)
true
end
end
end
2 changes: 1 addition & 1 deletion app/models/spree/calculator/product_area.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Calculator::ProductArea < Calculator
preference :min_height, :integer, :default => 0
preference :max_height, :integer, :default => 100

attr_accessible :preferred_multiplier, :preferred_min_pricing_area, :preferred_min_width, :preferred_max_width,:preferred_min_height, :preferred_max_height
#attr_accessible :preferred_multiplier, :preferred_min_pricing_area, :preferred_min_width, :preferred_max_width,:preferred_min_height, :preferred_max_height

# preference :min_area, :integer # the minimum sized frame we'll sell

Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/customizable_product_option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ module Spree
class CustomizableProductOption < ActiveRecord::Base
belongs_to :product_customization_type
delegate :calculator, :to => :product_customization_type
attr_accessible :name, :presentation, :description, :product_customization_type_id
#attr_accessible :name, :presentation, :description, :product_customization_type_id
end
end
2 changes: 1 addition & 1 deletion app/models/spree/excluded_ad_hoc_option_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ class ExcludedAdHocOptionValue < ActiveRecord::Base
belongs_to :ad_hoc_variant_exclusion
belongs_to :ad_hoc_option_value

attr_accessible :ad_hoc_variant_exclusion, :ad_hoc_option_value_id
#attr_accessible :ad_hoc_variant_exclusion, :ad_hoc_option_value_id
end
end
2 changes: 1 addition & 1 deletion app/models/spree/line_item_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def options_text
end

def cost_price
variant.cost_price + ad_hoc_option_values.map(&:cost_price).inject(0, :+)
(variant.cost_price || 0) + ad_hoc_option_values.map(&:cost_price).inject(0, :+)
end

def cost_money
Expand Down
63 changes: 63 additions & 0 deletions app/models/spree/order_contents_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
module Spree
OrderContents.class_eval do
# Get current line item for variant if exists
# Add variant qty to line_item
def add(variant, quantity = 1, currency = nil, shipment = nil, ad_hoc_option_value_ids = [], product_customizations = [])
line_item = add_to_line_item(variant, quantity, currency, shipment, ad_hoc_option_value_ids, product_customizations)
reload_totals
PromotionHandler::Cart.new(order, line_item).activate
ItemAdjustments.new(line_item).update
reload_totals
line_item
end

private
def add_to_line_item(variant, quantity, currency=nil, shipment=nil, ad_hoc_option_value_ids = [], product_customizations = [])
line_item = grab_line_item_by_variant(variant, false, ad_hoc_option_value_ids, product_customizations)

if line_item
line_item.target_shipment = shipment
line_item.quantity += quantity.to_i
line_item.currency = currency unless currency.nil?
else
line_item = order.line_items.new(quantity: quantity, variant: variant)
line_item.target_shipment = shipment

line_item.product_customizations = product_customizations
product_customizations.each {|pc| pc.line_item = line_item}

product_customizations.map(&:save) # it is now safe to save the customizations we built

# find, and add the configurations, if any. these have not been fetched from the db yet. line_items.first.variant_id
# we postponed it (performance reasons) until we actaully knew we needed them
povs=[]
ad_hoc_option_value_ids.each do |cid|
povs << AdHocOptionValue.find(cid)
end
line_item.ad_hoc_option_values = povs

offset_price = povs.map(&:price_modifier).compact.sum + product_customizations.map {|pc| pc.price(variant)}.sum

if currency
line_item.currency = currency unless currency.nil?
line_item.price = variant.price_in(currency).amount + offset_price
else
line_item.price = variant.price + offset_price
end
end

line_item.save
line_item
end

def grab_line_item_by_variant(variant, raise_error = false, ad_hoc_option_value_ids = [], product_customizations = [])
line_item = order.find_line_item_by_variant(variant, ad_hoc_option_value_ids, product_customizations)

if !line_item.present? && raise_error
raise ActiveRecord::RecordNotFound, "Line item not found for variant #{variant.sku}"
end

line_item
end
end
end
Loading