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

added default parameter #97

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c912895
added default parameter
coorasse Mar 26, 2014
0909722
confirm email i18n
coorasse Mar 27, 2014
43a50a7
get the tests running.
ideadapt Apr 3, 2014
39788bb
ignore coverage output
ideadapt Apr 3, 2014
2ea6d7f
fix tests
ideadapt Apr 3, 2014
3c1c1bb
clean up obsolete stuff we dont need.
ideadapt Apr 3, 2014
492c13a
add rails 4 compatible rails executable
ideadapt Apr 3, 2014
ce29d8b
cleanup gemspec
ideadapt Apr 3, 2014
0340a98
add total_price to option_value
ideadapt Apr 3, 2014
ad6953e
init price_modifier with option_value.total_price. we have to save it…
ideadapt Apr 3, 2014
141999e
update js to match latest spree version. js price update in frontend …
ideadapt Apr 3, 2014
a5ecf01
version bump
ideadapt Apr 3, 2014
78e7cd1
ignore locally build gems
ideadapt Apr 3, 2014
ef363e1
use more smart default value hook. also better for tests where models…
ideadapt Apr 3, 2014
58ddb0d
add attachment field to option_value
ideadapt Apr 4, 2014
3d6f581
solve rails deprecation warnings
ideadapt Apr 4, 2014
765c956
extend readme for gem developers
ideadapt Apr 4, 2014
cbf679f
add attachment field to option_value
ideadapt Apr 4, 2014
8fa2011
use update_attribute method to set default values in callback
ideadapt Apr 4, 2014
75827e1
fix delete ad hoc option type
ideadapt Apr 4, 2014
b635f01
add description text field to option_value
ideadapt Apr 7, 2014
6696663
test works now
ideadapt Apr 7, 2014
a703587
add accordion element and update deface overrides to latest bootstrap ;)
ideadapt Apr 7, 2014
3642dcf
typo :)
ideadapt Apr 8, 2014
451da75
started with server side model validation
ideadapt Apr 8, 2014
6505fba
refs 1570, for the admin order details view, we do not require any co…
ideadapt Apr 9, 2014
aa6b868
comment not required (and not yet working) line item option values va…
ideadapt Apr 9, 2014
af8a633
refs 1566 add new currency config to javascript. use 'de' as region, …
ideadapt Apr 9, 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ nbproject
doc/notes.txt
Gemfile.lock
spec/dummy
coverage
/*.gem
15 changes: 0 additions & 15 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,4 @@ group :development, :test do
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'
gem 'factory_girl_rails', '~> 1.7.0'
gem 'ffaker'
gem 'capybara', '2.0.2'
gem 'launchy'
gem 'pry'
end
group :assets do
gem 'coffee-rails'
end
=end

gemspec
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,31 @@ Installation
gem 'spree_flexi_variants', :git=>'git@github.com:jsqu99/spree_flexi_variants.git'

bundle install

bundle exec rails g spree_flexi_variants:install

Developer Setup
---------------

While developing this extension you can use bundlers support for local git repos (http://bundler.io/v1.5/git.html):

bundle config local.spree_flexi_variants ~/repos/spree_flexi_variants

and do not forget to change Gemfile.lock before deployment:

bundle config --delete local.spree_flexi_variants

When you create new migrations, you can import them to the project using this gem by:

bundle exec rake railties:install:migrations FROM=spree_flexi_variants



Run Test
--------

rake test_app
bundle exec rspec

## Examples


Expand All @@ -55,3 +77,10 @@ See the [wiki](https://github.com/jsqu99/spree_flexi_variants/wiki) for more det
Many, many thanks to [Brian Quinn](https://github.com/BDQ) for selflessly volunteering his time to mentor me throughout the development process.

Copyright (c) 2011 Jeff Squires, released under the New BSD License


TODO
----

- AdHocVariantExclusionsController remove / delete doesnt work
- AdHocOptionTypesController remove / delete doesnt work
1 change: 1 addition & 0 deletions Versionfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#
#
#
"2.1.x" => { :branch => "2-1-stable" }
"1.2.x" => { :branch => "spree-1-2-stable" }
"1.1.x" => { :branch => "spree-1-1-stable" }
"1.0.x" => { :branch => "spree-1-0-stable" }
Expand Down
19 changes: 0 additions & 19 deletions app/assets/javascripts/admin/orders/edit.js

This file was deleted.

44 changes: 0 additions & 44 deletions app/assets/javascripts/admin/orders/flexi_configuration.js

This file was deleted.

2 changes: 1 addition & 1 deletion app/assets/stylesheets/admin/spree_flexi_variants.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
*= require admin/spree_core
*= require admin/spree_backend
*/
69 changes: 0 additions & 69 deletions app/assets/stylesheets/store/spree-flexi-variants.css

This file was deleted.

12 changes: 11 additions & 1 deletion app/assets/stylesheets/store/spree_flexi_variants.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
/*
*= require store/spree_core
*= require_self
*= require self
*/



#ad_hoc_options {
margin-top: 20px;
overflow: auto;
}
table#cart-detail dl {margin-left: 10px;}
table#cart-detail dt {font-weight: normal;}
table#cart-detail dl p {margin:0;}
12 changes: 7 additions & 5 deletions app/controllers/spree/admin/ad_hoc_option_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ def add_option_value
redirect_to edit_admin_product_ad_hoc_option_type_url(@ad_hoc_option_type.product, @ad_hoc_option_type)
end

def remove
def before_destroy
# TODO: when removing an option type, we need to check if removing the option type from an
# associated exclusion causes the exclusion to only have one member. If so, we'll need to
# remove the entire exclusion
@product=@ad_hoc_option_type.product
@ad_hoc_option_type.destroy
flash.notice = I18n.t("notice_messages.option_type_removed")
redirect_to selected_admin_product_ad_hoc_option_types_url(@product)
# so: implement own destroy action, without using before/after callbacks
# flash.notice = I18n.t('notice_messages.option_type_removed')
end

protected
def location_after_destroy
selected_admin_product_ad_hoc_option_types_url(@object.product)
end

def location_after_save
selected_admin_product_ad_hoc_option_types_url(@ad_hoc_option_type.product)
end
Expand Down
Empty file.
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 @@ -10,7 +10,7 @@ class AdHocOptionType < ActiveRecord::Base
# currently no controller for normal users present
#attr_accessible :is_required, :ad_hoc_option_values_attributes, :product_id, :option_type_id, :position

default_scope order(:position)
default_scope { order(:position) }

# price_modifier_type
# is_required
Expand Down
20 changes: 17 additions & 3 deletions app/models/spree/ad_hoc_option_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,36 @@ class AdHocOptionValue < ActiveRecord::Base
belongs_to :option_value
has_many :excluded_ad_hoc_option_values, :dependent => :destroy

validates :price_modifier, presence: true

# currently no controller for normal users present
#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

# price_modifier
alias :option_type :ad_hoc_option_type
acts_as_list :scope => :ad_hoc_option_type
default_scope order("position asc")
default_scope { order('position asc') }

delegate :name, :to => :option_value
delegate :presentation, :to => :option_value

before_validation :default_values

def default_values
# set and save without validation
update_attribute :price_modifier, option_value.total_price
end

def cost_price
cost_price_modifier || price_modifier || 0
cost_price_modifier || price_presence(:price_modifier) || 0
end

private
def price_presence(price_field)
val = send(price_field)
val == 0.0 || !val ? nil : val
end
end
end
11 changes: 11 additions & 0 deletions app/models/spree/line_item_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ module Spree
has_many :ad_hoc_option_values, :through => :ad_hoc_option_values_line_items
has_many :product_customizations, :dependent => :destroy

#validate :ad_hoc_option_values_required

# def ad_hoc_option_values_required
# required_type_ids = product.ad_hoc_option_types.select{|t| t.is_required }.map &:id
# selected_type_ids = ad_hoc_option_values.select{|v| v.ad_hoc_option_type.is_required }.map &:id
# valid = required_type_ids.uniq.sort == selected_type_ids.uniq.sort
# unless valid
# errors.add(:ad_hoc_option_values, I18n.t('.required'))
# end
# end

def options_text
str = Array.new
unless self.ad_hoc_option_values.empty?
Expand Down
10 changes: 10 additions & 0 deletions app/models/spree/option_value_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
module Spree
OptionValue.class_eval do
has_many :ad_hoc_option_values, :dependent => :destroy

has_attached_file :attachment,
styles: { mini: '48x48>', small: '100x100>', product: '240x240>' },
default_style: :product,
url: '/spree/options/:id/:style/:basename.:extension',
path: ':rails_root/public/spree/options/:id/:style/:basename.:extension',
default_url: '/assets/default_options.png'

include Spree::Core::S3Support
supports_s3 :attachment
end
end
16 changes: 9 additions & 7 deletions app/models/spree/order_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def contains?(variant, ad_hoc_option_value_ids, product_customizations)
find_line_item_by_variant(variant, ad_hoc_option_value_ids, product_customizations).present?
end

def find_line_item_by_variant(variant, ad_hoc_option_value_ids, product_customizations)
def find_line_item_by_variant(variant, ad_hoc_option_value_ids = [], product_customizations = [])
line_items.detect do |li|
li.variant_id == variant.id &&
matching_configurations(li.ad_hoc_option_values,ad_hoc_option_value_ids) &&
matching_customizations(li.product_customizations,product_customizations)
matching_configurations(li.ad_hoc_option_values, ad_hoc_option_value_ids) &&
matching_customizations(li.product_customizations, product_customizations)
end
end

Expand All @@ -64,17 +64,19 @@ def customization_pairs(product_customizations)
Set.new pairs
end

def matching_configurations(existing_povs,new_povs)
def matching_configurations(existing_povs, new_povs)
# if there aren't any povs, there's a 'match'
return true if existing_povs.empty? && new_povs.empty?
# if no new povs given, we dont need to compare anything
return true if (existing_povs.empty? && new_povs.empty?) || (new_povs.empty?)

existing_povs.map(&:id).sort == new_povs.map(&:to_i).sort
end

def matching_customizations(existing_customizations,new_customizations)
def matching_customizations(existing_customizations, new_customizations)

# if there aren't any customizations, there's a 'match'
return true if existing_customizations.empty? && new_customizations.empty?
# # if no new customizations given, we dont need to compare anything
return true if (existing_customizations.empty? && new_customizations.empty?) || (new_customizations.empty?)

# exact match of all customization types?
return false unless existing_customizations.map(&:product_customization_type_id).sort == new_customizations.map(&:product_customization_type_id).sort
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/order_populator_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def attempt_cart_add(variant_id, quantity, ad_hoc_option_value_ids, product_cust
if quantity > 0
line_item = @order.contents.add(variant, quantity, currency, nil, ad_hoc_option_value_ids, product_customizations)
unless line_item.valid?
errors.add(:base, line_item.errors.messages.values.join(" "))
errors.add(:base, line_item.errors.messages.values.join(' '))
return false
end
end
Expand Down
Loading