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

upgrade from 0.5.0 to 3.1.0 #1

Merged
merged 4 commits into from
May 20, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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 @@ -8,3 +8,5 @@ test/dummy_hooks/after_migrate.rb
test/dummy
capybara-*.html
.rvmrc
spec/dummy
.byebug_history
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# encoding: UTF-8
require 'bundler'
require 'rubygems'
require 'spree/testing_support/common_rake'
begin
require 'bundler/setup'
rescue LoadError
Expand All @@ -23,4 +25,10 @@ Cucumber::Rake::Task.new do |t|
t.cucumber_opts = %w{--format pretty}
end

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

task :default => [ :test, :cucumber ]
1 change: 0 additions & 1 deletion app/assets/javascripts/spree_variant_options.js

This file was deleted.

24 changes: 0 additions & 24 deletions app/assets/javascripts/store/product_variant_options.js

This file was deleted.

235 changes: 0 additions & 235 deletions app/assets/javascripts/store/variant_options.js

This file was deleted.

3 changes: 0 additions & 3 deletions app/assets/stylesheets/spree_variant_options.css

This file was deleted.

18 changes: 0 additions & 18 deletions app/controllers/spree/admin/option_values_controller.rb

This file was deleted.

4 changes: 2 additions & 2 deletions app/models/spree/app_configuration/variant_configuration.rb
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
21 changes: 7 additions & 14 deletions app/models/spree/option_value_decorator.rb
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
34 changes: 13 additions & 21 deletions app/models/spree/product_decorator.rb
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

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is required


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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ankit1910 - Why we have eager loaded option_values in grouped_option_values?

Copy link

@nishant-cyro nishant-cyro May 20, 2016

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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
Loading