solidus_product_assembly 1.0.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +47 -0
  3. data/.gem_release.yml +5 -0
  4. data/.github/dependabot.yml +7 -0
  5. data/.github/stale.yml +17 -0
  6. data/.github_changelog_generator +2 -0
  7. data/.gitignore +18 -2
  8. data/.rspec +1 -2
  9. data/.rubocop.yml +7 -0
  10. data/.rubocop_todo.yml +316 -0
  11. data/CHANGELOG.md +116 -0
  12. data/Gemfile +36 -9
  13. data/LICENSE +26 -0
  14. data/README.md +75 -50
  15. data/Rakefile +4 -19
  16. data/app/controllers/spree/admin/parts_controller.rb +13 -11
  17. data/app/decorators/helpers/solidus_product_assembly/spree/admin/orders_helper_decorator.rb +19 -0
  18. data/app/decorators/models/solidus_product_assembly/spree/inventory_unit_decorator.rb +19 -0
  19. data/app/decorators/models/solidus_product_assembly/spree/line_item_decorator.rb +52 -0
  20. data/app/decorators/models/solidus_product_assembly/spree/product_decorator.rb +83 -0
  21. data/app/decorators/models/solidus_product_assembly/spree/return_item_decorator.rb +15 -0
  22. data/app/decorators/models/solidus_product_assembly/spree/shipment_decorator.rb +55 -0
  23. data/app/decorators/models/solidus_product_assembly/spree/stock/availability_validator_decorator.rb +37 -0
  24. data/app/decorators/models/solidus_product_assembly/spree/stock/differentiator_decorator.rb +17 -0
  25. data/app/decorators/models/solidus_product_assembly/spree/stock/inventory_unit_builder_decorator.rb +39 -0
  26. data/app/decorators/models/solidus_product_assembly/spree/stock/inventory_units_finalizer_decorator.rb +33 -0
  27. data/app/decorators/models/solidus_product_assembly/spree/stock/inventory_validator_decorator.rb +22 -0
  28. data/app/decorators/models/solidus_product_assembly/spree/variant_decorator.rb +26 -0
  29. data/app/models/spree/assemblies_part.rb +6 -4
  30. data/app/models/spree/calculator/returns/assemblies_default_refund_amount.rb +17 -0
  31. data/app/models/spree/order_inventory_assembly.rb +11 -2
  32. data/app/overrides/add_admin_product_form_fields.rb +7 -5
  33. data/app/overrides/add_admin_tabs.rb +7 -5
  34. data/app/overrides/add_line_item_description.rb +7 -5
  35. data/app/overrides/spree/admin/orders/_carton_manifest/_assembly_parts_price.html.erb.deface +9 -0
  36. data/app/overrides/spree/admin/orders/_carton_manifest/_assembly_parts_total_price.html.erb.deface +9 -0
  37. data/app/overrides/spree/admin/orders/_shipment/stock_contents.html.erb.deface +7 -1
  38. data/app/overrides/spree/products/show/add_links_to_parts.html.erb.deface +2 -2
  39. data/app/views/spree/admin/orders/_assemblies.html.erb +8 -17
  40. data/app/views/spree/admin/orders/_stock_contents.html.erb +2 -62
  41. data/app/views/spree/admin/orders/_stock_contents_2_3.html.erb +69 -0
  42. data/app/views/spree/admin/orders/_stock_contents_2_4.html.erb +70 -0
  43. data/app/views/spree/admin/orders/_stock_item.html.erb +13 -10
  44. data/app/views/spree/admin/parts/_parts_table.html.erb +17 -11
  45. data/app/views/spree/admin/parts/available.html.erb +10 -8
  46. data/app/views/spree/admin/parts/available.js.erb +9 -7
  47. data/app/views/spree/admin/parts/index.html.erb +1 -1
  48. data/app/views/spree/admin/products/_product_assembly_fields.html.erb +2 -2
  49. data/app/views/spree/admin/shared/_product_assembly_product_tabs.html.erb +1 -1
  50. data/app/views/spree/api/line_items/show.v1.rabl +27 -0
  51. data/app/views/spree/checkout/_line_item_manifest.html.erb +3 -1
  52. data/bin/console +17 -0
  53. data/bin/rails +5 -5
  54. data/bin/rails-engine +13 -0
  55. data/bin/rails-sandbox +16 -0
  56. data/bin/rake +7 -0
  57. data/bin/sandbox +86 -0
  58. data/bin/setup +8 -0
  59. data/config/routes.rb +2 -2
  60. data/db/migrate/20091028152124_add_many_to_many_relation_to_products.rb +7 -5
  61. data/db/migrate/20091029165620_add_parts_fields_to_products.rb +18 -16
  62. data/db/migrate/20120316141830_namespace_product_assembly_for_spree_one.rb +3 -1
  63. data/db/migrate/20140620223938_add_id_to_spree_assemblies_parts.rb +4 -2
  64. data/lib/generators/solidus_product_assembly/install/install_generator.rb +22 -9
  65. data/lib/generators/solidus_product_assembly/install/templates/initializer.rb +6 -0
  66. data/lib/solidus_product_assembly/configuration.rb +21 -0
  67. data/lib/solidus_product_assembly/engine.rb +12 -8
  68. data/lib/solidus_product_assembly/testing_support/factories.rb +4 -0
  69. data/lib/solidus_product_assembly/version.rb +3 -1
  70. data/lib/solidus_product_assembly.rb +7 -1
  71. data/lib/tasks/spree2_upgrade.rake +12 -12
  72. data/solidus_product_assembly.gemspec +35 -29
  73. data/spec/features/admin/orders_spec.rb +114 -16
  74. data/spec/features/admin/parts_spec.rb +5 -3
  75. data/spec/features/admin/return_items_spec.rb +151 -0
  76. data/spec/features/checkout_spec.rb +103 -21
  77. data/spec/models/spree/assemblies_part_spec.rb +3 -1
  78. data/spec/models/spree/inventory_unit_spec.rb +15 -6
  79. data/spec/models/spree/line_item_spec.rb +6 -4
  80. data/spec/models/spree/order_contents_spec.rb +6 -5
  81. data/spec/models/spree/order_inventory_assembly_spec.rb +8 -6
  82. data/spec/models/spree/order_inventory_spec.rb +7 -3
  83. data/spec/models/spree/product_spec.rb +33 -14
  84. data/spec/models/spree/shipment_spec.rb +20 -13
  85. data/spec/models/spree/stock/availability_validator_spec.rb +22 -33
  86. data/spec/models/spree/stock/coordinator_spec.rb +11 -3
  87. data/spec/models/spree/stock/inventory_unit_builder_spec.rb +5 -7
  88. data/spec/models/spree/variant_spec.rb +3 -1
  89. data/spec/spec_helper.rb +21 -45
  90. data/spec/support/shared_contexts/order_with_bundle.rb +2 -0
  91. metadata +80 -80
  92. data/.travis.yml +0 -21
  93. data/LICENSE.md +0 -13
  94. data/app/controllers/spree/checkout_controller_decorator.rb +0 -9
  95. data/app/helpers/spree/admin/orders_helper_decorator.rb +0 -9
  96. data/app/models/spree/inventory_unit_decorator.rb +0 -13
  97. data/app/models/spree/line_item_decorator.rb +0 -44
  98. data/app/models/spree/product_decorator.rb +0 -56
  99. data/app/models/spree/shipment_decorator.rb +0 -50
  100. data/app/models/spree/stock/availability_validator.rb +0 -28
  101. data/app/models/spree/stock/inventory_unit_builder_decorator.rb +0 -30
  102. data/app/models/spree/stock/inventory_validator_decorator.rb +0 -12
  103. data/app/models/spree/variant_decorator.rb +0 -13
@@ -1,12 +1,12 @@
1
1
  <div class="left six columns alpha">
2
2
  <div class="field">
3
- <%= f.label :can_be_part, Spree.t(:can_be_part)%>
3
+ <%= f.label :can_be_part, t('spree.can_be_part')%>
4
4
  <%= f.check_box(:can_be_part) %>
5
5
  </div>
6
6
  </div>
7
7
  <div class="right six columns omega">
8
8
  <div class="field">
9
- <%= f.label :individual_sale, Spree.t(:individual_sale)%>
9
+ <%= f.label :individual_sale, t('spree.individual_sale')%>
10
10
  <%= f.check_box(:individual_sale) %>
11
11
  </div>
12
12
  </div>
@@ -1,3 +1,3 @@
1
1
  <li<%= ' class="active"' if current == "Parts" %>>
2
- <%= link_to_with_icon 'sitemap', Spree.t(:parts), admin_product_parts_url(@product) %>
2
+ <%= link_to_with_icon 'sitemap', t('spree.parts'), admin_product_parts_url(@product) %>
3
3
  </li>
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ object @line_item
4
+ cache [I18n.locale, root_object]
5
+ attributes *line_item_attributes
6
+ node(:single_display_amount) { |li| li.single_display_amount.to_s }
7
+ node(:display_amount) { |li| li.display_amount.to_s }
8
+ node(:total, &:total)
9
+ glue variant: :parts do
10
+ glue :product do
11
+ child parts: :parts do
12
+ extends "spree/api/variants/small"
13
+ attributes :product_id
14
+
15
+ child(images: :images) { extends "spree/api/images/show" }
16
+ end
17
+ end
18
+ end
19
+ child :variant do
20
+ extends "spree/api/variants/small"
21
+ attributes :product_id
22
+ child(images: :images) { extends "spree/api/images/show" }
23
+ end
24
+
25
+ child adjustments: :adjustments do
26
+ extends "spree/api/adjustments/show"
27
+ end
@@ -1,6 +1,8 @@
1
1
  <% ship_form.object.line_item_manifest.each do |item| %>
2
2
  <tr class="stock-item">
3
- <td class="item-image"><%= mini_image(item.variant) %></td>
3
+ <td class="item-image"><%= render 'spree/shared/image',
4
+ image: (item.variant.gallery.images.first || item.variant.product.gallery.images.first),
5
+ size: :mini %></td>
4
6
  <td class="item-name">
5
7
  <%= item.variant.name %>
6
8
  <%= render 'spree/orders/cart_description', variant: item.variant, line_item: item.line_item %>
data/bin/console ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require "bundler/setup"
6
+ require "solidus_product_assembly"
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+ $LOAD_PATH.unshift(*Dir["#{__dir__}/../app/*"])
11
+
12
+ # (If you use this, don't forget to add pry to your Gemfile!)
13
+ # require "pry"
14
+ # Pry.start
15
+
16
+ require "irb"
17
+ IRB.start(__FILE__)
data/bin/rails CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- ENGINE_ROOT = File.expand_path('../..', __FILE__)
4
- ENGINE_PATH = File.expand_path('../../lib/solidus_product_assembly/engine', __FILE__)
5
-
6
- require 'rails/all'
7
- require 'rails/engine/commands'
3
+ if %w[g generate].include? ARGV.first
4
+ exec "#{__dir__}/rails-engine", *ARGV
5
+ else
6
+ exec "#{__dir__}/rails-sandbox", *ARGV
7
+ end
data/bin/rails-engine ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path('..', __dir__)
6
+ ENGINE_PATH = File.expand_path('../lib/solidus_product_assembly/engine', __dir__)
7
+
8
+ # Set up gems listed in the Gemfile.
9
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
10
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
11
+
12
+ require 'rails/all'
13
+ require 'rails/engine/commands'
data/bin/rails-sandbox ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ app_root = 'sandbox'
4
+
5
+ unless File.exist? "#{app_root}/bin/rails"
6
+ warn 'Creating the sandbox app...'
7
+ Dir.chdir "#{__dir__}/.." do
8
+ system "#{__dir__}/sandbox" or begin
9
+ warn 'Automatic creation of the sandbox app failed'
10
+ exit 1
11
+ end
12
+ end
13
+ end
14
+
15
+ Dir.chdir app_root
16
+ exec 'bin/rails', *ARGV
data/bin/rake ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "rubygems"
5
+ require "bundler/setup"
6
+
7
+ load Gem.bin_path("rake", "rake")
data/bin/sandbox ADDED
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ case "$DB" in
6
+ postgres|postgresql)
7
+ RAILSDB="postgresql"
8
+ ;;
9
+ mysql)
10
+ RAILSDB="mysql"
11
+ ;;
12
+ sqlite|'')
13
+ RAILSDB="sqlite3"
14
+ ;;
15
+ *)
16
+ echo "Invalid DB specified: $DB"
17
+ exit 1
18
+ ;;
19
+ esac
20
+
21
+ if [ ! -z $SOLIDUS_BRANCH ]
22
+ then
23
+ BRANCH=$SOLIDUS_BRANCH
24
+ else
25
+ BRANCH="master"
26
+ fi
27
+
28
+ extension_name="solidus_product_assembly"
29
+
30
+ # Stay away from the bundler env of the containing extension.
31
+ function unbundled {
32
+ ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- $@
33
+ }
34
+
35
+ rm -rf ./sandbox
36
+ unbundled bundle exec rails new sandbox --database="$RAILSDB" \
37
+ --skip-bundle \
38
+ --skip-git \
39
+ --skip-keeps \
40
+ --skip-rc \
41
+ --skip-spring \
42
+ --skip-test \
43
+ --skip-javascript
44
+
45
+ if [ ! -d "sandbox" ]; then
46
+ echo 'sandbox rails application failed'
47
+ exit 1
48
+ fi
49
+
50
+ cd ./sandbox
51
+ cat <<RUBY >> Gemfile
52
+ gem 'solidus', github: 'solidusio/solidus', branch: '$BRANCH'
53
+ gem 'solidus_auth_devise', '>= 2.1.0'
54
+ gem 'rails-i18n'
55
+ gem 'solidus_i18n'
56
+
57
+ gem '$extension_name', path: '..'
58
+
59
+ group :test, :development do
60
+ platforms :mri do
61
+ gem 'pry-byebug'
62
+ end
63
+ end
64
+ RUBY
65
+
66
+ unbundled bundle install --gemfile Gemfile
67
+
68
+ unbundled bundle exec rake db:drop db:create
69
+
70
+ unbundled bundle exec rails generate solidus:install \
71
+ --auto-accept \
72
+ --user_class=Spree::User \
73
+ --enforce_available_locales=true \
74
+ --with-authentication=false \
75
+ --payment-method=none \
76
+ $@
77
+
78
+ unbundled bundle exec rails generate solidus:auth:install
79
+ unbundled bundle exec rails generate ${extension_name}:install
80
+
81
+ echo
82
+ echo "🚀 Sandbox app successfully created for $extension_name!"
83
+ echo "🚀 Using $RAILSDB and Solidus $BRANCH"
84
+ echo "🚀 Use 'export DB=[postgres|mysql|sqlite]' to control the DB adapter"
85
+ echo "🚀 Use 'export SOLIDUS_BRANCH=<BRANCH-NAME>' to control the Solidus version"
86
+ echo "🚀 This app is intended for test purposes."
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ gem install bundler --conservative
7
+ bundle update
8
+ bin/rake clobber
data/config/routes.rb CHANGED
@@ -1,5 +1,6 @@
1
- Spree::Core::Engine.add_routes do
1
+ # frozen_string_literal: true
2
2
 
3
+ Spree::Core::Engine.routes.draw do
3
4
  namespace :admin do
4
5
  resources :products do
5
6
  resources :parts do
@@ -15,5 +16,4 @@ Spree::Core::Engine.add_routes do
15
16
  end
16
17
  end
17
18
  end
18
-
19
19
  end
@@ -1,9 +1,11 @@
1
- class AddManyToManyRelationToProducts < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class AddManyToManyRelationToProducts < SolidusSupport::Migration[4.2]
2
4
  def self.up
3
- create_table :assemblies_parts, :id => false do |t|
4
- t.integer "assembly_id", :null => false
5
- t.integer "part_id", :null => false
6
- t.integer "count", :null => false, :default => 1
5
+ create_table :assemblies_parts, id: false do |t|
6
+ t.integer "assembly_id", null: false
7
+ t.integer "part_id", null: false
8
+ t.integer "count", null: false, default: 1
7
9
  end
8
10
  end
9
11
 
@@ -1,24 +1,26 @@
1
- class AddPartsFieldsToProducts < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class AddPartsFieldsToProducts < SolidusSupport::Migration[4.2]
2
4
  def self.up
3
- table = if table_exists?(:products)
4
- 'products'
5
- elsif table_exists?(:spree_products)
6
- 'spree_products'
7
- end
8
-
5
+ table = if data_source_exists?(:products)
6
+ 'products'
7
+ elsif data_source_exists?(:spree_products)
8
+ 'spree_products'
9
+ end
10
+
9
11
  change_table(table) do |t|
10
- t.column :can_be_part, :boolean, :default => false, :null => false
11
- t.column :individual_sale, :boolean, :default => true, :null => false
12
- end
12
+ t.column :can_be_part, :boolean, default: false, null: false
13
+ t.column :individual_sale, :boolean, default: true, null: false
14
+ end
13
15
  end
14
16
 
15
17
  def self.down
16
- table = if table_exists?(:products)
17
- 'products'
18
- elsif table_exists?(:spree_products)
19
- 'spree_products'
20
- end
21
-
18
+ table = if data_source_exists?(:products)
19
+ 'products'
20
+ elsif data_source_exists?(:spree_products)
21
+ 'spree_products'
22
+ end
23
+
22
24
  change_table(table) do |t|
23
25
  t.remove :can_be_part
24
26
  t.remove :individual_sale
@@ -1,4 +1,6 @@
1
- class NamespaceProductAssemblyForSpreeOne < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class NamespaceProductAssemblyForSpreeOne < SolidusSupport::Migration[4.2]
2
4
  def up
3
5
  rename_table :assemblies_parts, :spree_assemblies_parts
4
6
  end
@@ -1,9 +1,11 @@
1
- class AddIdToSpreeAssembliesParts < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class AddIdToSpreeAssembliesParts < SolidusSupport::Migration[4.2]
2
4
  def up
3
5
  add_column :spree_assemblies_parts, :id, :primary_key
4
6
  end
5
7
 
6
8
  def down
7
- add_column :spree_assemblies_parts, :id
9
+ remove_column :spree_assemblies_parts, :id
8
10
  end
9
11
  end
@@ -1,23 +1,36 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SolidusProductAssembly
2
4
  module Generators
3
5
  class InstallGenerator < Rails::Generators::Base
4
- class_option :auto_run_migrations, :type => :boolean, :default => false
6
+ class_option :auto_run_migrations, type: :boolean, default: false
7
+ source_root File.expand_path('templates', __dir__)
5
8
 
6
- def add_migrations
7
- run 'rake railties:install:migrations FROM=solidus_product_assembly'
9
+ def copy_initializer
10
+ template 'initializer.rb', 'config/initializers/solidus_product_assembly.rb'
8
11
  end
9
12
 
10
13
  def add_javascripts
11
- append_file "vendor/assets/javascripts/spree/backend/all.js", "//= require spree/backend/solidus_product_assembly\n"
14
+ append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_product_assembly\n"
15
+ append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_product_assembly\n"
16
+ end
17
+
18
+ def add_stylesheets
19
+ inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_product_assembly\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
20
+ inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_product_assembly\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
21
+ end
22
+
23
+ def add_migrations
24
+ run 'bin/rails railties:install:migrations FROM=solidus_product_assembly'
12
25
  end
13
26
 
14
27
  def run_migrations
15
- run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask 'Would you like to run the migrations now? [Y/n]')
28
+ run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Layout/LineLength
16
29
  if run_migrations
17
- run 'rake db:migrate'
18
- else
19
- puts "Skiping rake db:migrate, don't forget to run it!"
20
- end
30
+ run 'bin/rails db:migrate'
31
+ else
32
+ puts 'Skipping bin/rails db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
33
+ end
21
34
  end
22
35
  end
23
36
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ SolidusProductAssembly.configure do |config|
4
+ # TODO: Remember to change this with the actual preferences you have implemented!
5
+ # config.sample_preference = 'sample_value'
6
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusProductAssembly
4
+ class Configuration
5
+ # Define here the settings for this extension, e.g.:
6
+ #
7
+ # attr_accessor :my_setting
8
+ end
9
+
10
+ class << self
11
+ def configuration
12
+ @configuration ||= Configuration.new
13
+ end
14
+
15
+ alias config configuration
16
+
17
+ def configure
18
+ yield configuration
19
+ end
20
+ end
21
+ end
@@ -1,15 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'solidus_core'
4
+ require 'solidus_support'
5
+
1
6
  module SolidusProductAssembly
2
7
  class Engine < Rails::Engine
3
- engine_name 'solidus_product_assembly'
8
+ include SolidusSupport::EngineExtensions
4
9
 
5
- config.autoload_paths += %W(#{config.root}/lib)
10
+ isolate_namespace ::Spree
6
11
 
7
- def self.activate
8
- Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator.rb")) do |c|
9
- Rails.configuration.cache_classes ? require(c) : load(c)
10
- end
11
- end
12
+ engine_name 'solidus_product_assembly'
12
13
 
13
- config.to_prepare &method(:activate).to_proc
14
+ # use rspec for tests
15
+ config.generators do |g|
16
+ g.test_framework :rspec
17
+ end
14
18
  end
15
19
  end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SolidusProductAssembly
2
- VERSION = '1.0.0'
4
+ VERSION = '1.2.0'
3
5
  end
@@ -1,3 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'solidus_core'
2
- require 'solidus_product_assembly/engine'
4
+ require 'solidus_support'
5
+ require 'deface'
6
+
3
7
  require 'solidus_product_assembly/version'
8
+ require 'solidus_product_assembly/engine'
9
+ require 'solidus_product_assembly/configuration'
@@ -1,27 +1,27 @@
1
+ # frozen_string_literal: true
2
+
1
3
  namespace :solidus_product_assembly do
2
4
  desc 'Link legacy inventory units to an order line item'
3
- task :upgrade => :environment do
5
+ task upgrade: :environment do
4
6
  shipments = Spree::Shipment.includes(:inventory_units).where("spree_inventory_units.line_item_id IS NULL")
5
7
 
6
8
  shipments.each do |shipment|
7
9
  shipment.inventory_units.includes(:variant).group_by(&:variant).each do |variant, units|
8
-
9
10
  line_item = shipment.order.line_items.detect { |line_item| line_item.variant_id == variant.id }
10
11
 
11
- unless line_item
12
+ next if line_item
12
13
 
13
- begin
14
- master = shipment.order.products.detect { |p| variant.assemblies.include? p }.master
15
- supposed_line_item = shipment.order.line_items.detect { |line_item| line_item.variant_id == master.id }
14
+ begin
15
+ master = shipment.order.products.detect { |p| variant.assemblies.include? p }.master
16
+ supposed_line_item = shipment.order.line_items.detect { |line_item| line_item.variant_id == master.id }
16
17
 
17
- if supposed_line_item
18
- Spree::InventoryUnit.where(id: units.map(&:id)).update_all "line_item_id = #{supposed_line_item.id}"
19
- else
20
- puts "Couldn't find a matching line item for #{variant.name}"
21
- end
22
- rescue
18
+ if supposed_line_item
19
+ Spree::InventoryUnit.where(id: units.map(&:id)).update_all "line_item_id = #{supposed_line_item.id}"
20
+ else
23
21
  puts "Couldn't find a matching line item for #{variant.name}"
24
22
  end
23
+ rescue StandardError
24
+ puts "Couldn't find a matching line item for #{variant.name}"
25
25
  end
26
26
  end
27
27
  end
@@ -1,35 +1,41 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('../lib/', __FILE__)
4
- $:.unshift lib unless $:.include?(lib)
5
-
6
- require 'solidus_product_assembly/version'
3
+ require_relative 'lib/solidus_product_assembly/version'
7
4
 
8
5
  Gem::Specification.new do |s|
9
6
  s.platform = Gem::Platform::RUBY
10
- s.name = 'solidus_product_assembly'
11
- s.version = SolidusProductAssembly::VERSION
12
- s.summary = 'Adds oportunity to make bundle of products to your Spree store'
7
+ s.name = 'solidus_product_assembly'
8
+ s.version = SolidusProductAssembly::VERSION
9
+ s.authors = ['Roman Smirnov']
10
+ s.email = 'roman@railsdog.com'
11
+
12
+ s.summary = 'Adds opportunity to make bundle of products to your Spree store'
13
13
  s.description = s.summary
14
- s.required_ruby_version = '>= 1.9.3'
15
-
16
- s.author = 'Roman Smirnov'
17
- s.email = 'roman@railsdog.com'
18
- s.homepage = 'https://solidus.io'
19
-
20
- s.files = `git ls-files`.split("\n")
21
- s.test_files = `git ls-files -- spec/*`.split("\n")
22
- s.require_path = 'lib'
23
- s.requirements << 'none'
24
-
25
- s.add_runtime_dependency 'solidus_backend', [">= 1.0", "< 3"]
26
-
27
- s.add_development_dependency 'rspec-rails', '~> 3.4'
28
- s.add_development_dependency 'sqlite3'
29
- s.add_development_dependency 'ffaker'
30
- s.add_development_dependency 'factory_girl', '~> 4.4'
31
- s.add_development_dependency 'capybara', '~> 2.7'
32
- s.add_development_dependency 'poltergeist', '~> 1.9'
33
- s.add_development_dependency 'database_cleaner', '~> 1.3'
34
- s.add_development_dependency 'simplecov'
14
+ s.homepage = 'https://solidus.io'
15
+ s.license = 'BSD-3-Clause'
16
+
17
+ s.metadata['homepage_uri'] = s.homepage
18
+ s.metadata['source_code_uri'] = 'https://github.com/solidusio-contrib/solidus_product_assembly'
19
+ s.metadata['changelog_uri'] = 'https://github.com/SuperGoodSoft/solidus_product_assembly/blob/master/CHANGELOG.md'
20
+
21
+ s.required_ruby_version = '>= 2.4'
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }
26
+
27
+ s.files = files.grep_v(%r{^(test|spec|features)/})
28
+ s.test_files = files.grep(%r{^(test|spec|features)/})
29
+ s.bindir = "exe"
30
+ s.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ s.require_paths = ["lib"]
32
+
33
+ s.add_dependency 'solidus_core', ['>= 2.0.0', '< 4']
34
+ s.add_dependency 'solidus_support', '~> 0.8'
35
+ s.add_dependency 'deface'
36
+
37
+ s.add_development_dependency 'solidus_dev_support', '~> 2.5'
38
+ s.add_development_dependency 'github_changelog_generator'
39
+ s.add_development_dependency 'selenium-webdriver'
40
+ s.add_development_dependency 'webdrivers'
35
41
  end