-
Notifications
You must be signed in to change notification settings - Fork 12
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
upgrade from 0.5.0 to 3.1.0 #1
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ test/dummy_hooks/after_migrate.rb | |
test/dummy | ||
capybara-*.html | ||
.rvmrc | ||
spec/dummy | ||
.byebug_history |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module SpreeVariantOptions | ||
class VariantConfiguration < Spree::Preferences::Configuration | ||
preference :allow_select_outofstock, :boolean, :default => false | ||
preference :default_instock, :boolean, :default => false | ||
preference :allow_select_outofstock, :boolean, default: false | ||
preference :default_instock, :boolean, default: false | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,15 @@ | ||
Spree::OptionValue.class_eval do | ||
|
||
attr_accessible :image | ||
|
||
default_scope order("#{quoted_table_name}.position") | ||
|
||
has_attached_file :image, | ||
:styles => { :small => '40x30#', :large => '140x110#' }, | ||
:default_style => :small, | ||
:url => "/spree/option_values/:id/:style/:basename.:extension", | ||
:path => ":rails_root/public/spree/option_values/:id/:style/:basename.:extension" | ||
styles: { small: '40x30#', large: '140x110#' }, | ||
default_style: :small, | ||
url: "/spree/option_values/:id/:style/:basename.:extension", | ||
path: ":rails_root/public/spree/option_values/:id/:style/:basename.:extension" | ||
|
||
include Spree::Core::S3Support | ||
supports_s3 :image | ||
validates_attachment :image, content_type: { content_type: /\Aimage\/.*\Z/ }, | ||
size: { in: 0..1.megabytes } | ||
|
||
def has_image? | ||
image_file_name && !image_file_name.empty? | ||
!!(image_file_name && !image_file_name.empty?) | ||
end | ||
|
||
scope :for_product, lambda { |product| select("DISTINCT #{table_name}.*").where("spree_option_values_variants.variant_id IN (?)", product.variant_ids).joins(:variants) | ||
} | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,23 @@ | ||
Spree::Product.class_eval do | ||
|
||
def option_values | ||
@_option_values ||= Spree::OptionValue.for_product(self).order(:position).sort_by {|ov| ov.option_type.position } | ||
end | ||
has_many :option_values, -> { uniq }, through: :variants | ||
|
||
def grouped_option_values | ||
@_grouped_option_values ||= option_values.group_by(&:option_type) | ||
end | ||
|
||
def variants_for_option_value(value) | ||
@_variant_option_values ||= variants.includes(:option_values).all | ||
@_variant_option_values.select { |i| i.option_value_ids.include?(value.id) } | ||
option_types.includes(:option_values).order(:position) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ankit1910 - Why we have eager loaded option_values in grouped_option_values? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ankit1910 - Please rename this method. |
||
end | ||
|
||
def variant_options_hash | ||
return @_variant_options_hash if @_variant_options_hash | ||
hash = {} | ||
variants.includes(:option_values).each do |variant| | ||
variant.option_values.each do |ov| | ||
otid = ov.option_type_id.to_s | ||
ovid = ov.id.to_s | ||
hash[otid] ||= {} | ||
hash[otid][ovid] ||= {} | ||
hash[otid][ovid][variant.id.to_s] = variant.to_hash | ||
def variants_option_value_details | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ankit1910 - Lets refactor this. |
||
variants.includes(option_values: :option_type).collect do |variant| | ||
details = { | ||
in_stock: variant.can_supply?, | ||
variant_id: variant.id, | ||
variant_price: variant.price_in(Spree::Config[:currency]).money, | ||
option_types: {}, | ||
} | ||
variant.option_values.each do |option_value| | ||
details[:option_types][option_value.option_type.id] = option_value.id | ||
end | ||
details | ||
end | ||
@_variant_options_hash = hash | ||
end | ||
|
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ankit1910 - We don't require to add uniq here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is required