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

Update to the latest dev-support template and allow usage of Solidus 3.0 #46

Merged
merged 4 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ jobs:
executor: solidusio_extensions/mysql
steps:
- solidusio_extensions/run-tests
lint-code:
executor: solidusio_extensions/sqlite-memory
steps:
- solidusio_extensions/lint-code

workflows:
"Run specs on supported Solidus versions":
jobs:
- run-specs-with-postgres
- run-specs-with-mysql
- lint-code

"Weekly run specs against master":
triggers:
- schedule:
Expand Down
2 changes: 2 additions & 0 deletions .github_changelog_generator
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
issues=false
exclude-labels=infrastructure
15 changes: 15 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
require:
- solidus_dev_support/rubocop

AllCops:
NewCops: disable

Rails/SkipsModelValidations:
Enabled: false

RSpec/MultipleExpectations:
Enabled: false

RSpec/MultipleMemoizedHelpers:
Enabled: false

RSpec/NestedGroups:
Max: 4
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ gem 'solidus_importer'
Bundle your dependencies and run the installation generator:

```shell
bundle
bundle exec rails g solidus_importer:install
bin/rails generate solidus_importer:install
```

## Usage
Expand Down Expand Up @@ -165,14 +164,21 @@ $ bin/rails server
Use Ctrl-C to stop
```

### Releasing new versions
### Updating the changelog

Your new extension version can be released using `gem-release` like this:
Before and after releases the changelog should be updated to reflect the up-to-date status of
the project:

```shell
bundle exec gem bump -v VERSION --tag --push --remote upstream && gem release
bin/rake changelog
git add CHANGELOG.md
git commit -m "Update the changelog"
```

### Releasing new versions

Please refer to the dedicated [page](https://github.com/solidusio/solidus/wiki/How-to-release-extensions) on Solidus wiki.

## License

Copyright (c) 2020 Nebulab SRLs, released under the New BSD License
2 changes: 1 addition & 1 deletion app/jobs/solidus_importer/import_job.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module SolidusImporter
class ImportJob < ActiveJob::Base
class ImportJob < ApplicationJob
queue_as :default

retry_on ActiveRecord::Deadlocked
Expand Down
2 changes: 2 additions & 0 deletions app/models/solidus_importer/order_updater.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SolidusImporter
class OrderUpdater < Spree::OrderUpdater
# Override this method to avoid tax calculation
Expand Down
4 changes: 3 additions & 1 deletion app/models/solidus_importer/spree_core_importer_order.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SolidusImporter
class SpreeCoreImporterOrder < Spree::Core::Importer::Order
def self.import(user, params)
Expand Down Expand Up @@ -27,7 +29,7 @@ def self.import(user, params)

order.update!(params)

order.create_proposed_shipments unless shipments_attrs.present?
order.create_proposed_shipments if shipments_attrs.blank?

if completed_at
order.completed_at = completed_at
Expand Down
2 changes: 1 addition & 1 deletion bin/sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ unbundled bundle exec rails generate spree:install \
--user_class=Spree::User \
--enforce_available_locales=true \
--with-authentication=false \
--payment-method=none
--payment-method=none \
$@

unbundled bundle exec rails generate solidus:auth:install
Expand Down
17 changes: 16 additions & 1 deletion lib/generators/solidus_importer/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,28 @@ module SolidusImporter
module Generators
class InstallGenerator < Rails::Generators::Base
class_option :auto_run_migrations, type: :boolean, default: false
source_root File.expand_path('templates', __dir__)

def copy_initializer
template 'initializer.rb', 'config/initializers/solidus_importer.rb'
end

def add_javascripts
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_importer\n"
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_importer\n"
end

def add_stylesheets
inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_importer\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_importer\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
end

def add_migrations
run 'bin/rails railties:install:migrations FROM=solidus_importer'
end

def run_migrations
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Metrics/LineLength
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Layout/LineLength
if run_migrations
run 'bin/rails db:migrate'
else
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

SolidusImporter.configure do |config|
# TODO: Remember to change this with the actual preferences you have implemented!
# config.sample_preference = 'sample_value'
end
7 changes: 6 additions & 1 deletion lib/solidus_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

require 'solidus_importer/processors/base'
processors = File.join(__dir__, 'solidus_importer/processors/*.rb')
Dir[processors].each { |file| require file }
Dir[processors].sort.each { |file| require file }

require 'solidus_importer/configuration'
require 'solidus_importer/engine'
Expand All @@ -22,5 +22,10 @@ class << self
def import!(import_path, type:)
ProcessImport.import_from_file(import_path, type.to_sym)
end

def combined_first_and_last_name_in_address?
SolidusSupport.combined_first_and_last_name_in_address? &&
Spree::Address.column_names.include?('name')
end
end
end
3 changes: 1 addition & 2 deletions lib/solidus_importer/base_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def after_import(context)

##
# Defines a method called after the import of each row
def handle_row_import(_ending_row_context)
end
def handle_row_import(_ending_row_context); end
end
end
12 changes: 12 additions & 0 deletions lib/solidus_importer/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,16 @@ def available_types
solidus_importer.keys
end
end

class << self
def configuration
@configuration ||= Configuration.new
end

alias config configuration

def configure
yield configuration
end
end
end
12 changes: 5 additions & 7 deletions lib/solidus_importer/process_row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ def initialize(importer, row)
def process(initial_context)
context = initial_context.dup.merge!(row_id: @row.id, importer: @importer, data: @row.data)
@importer.processors.each do |processor|
begin
processor.call(context)
rescue StandardError => e
context.merge!(success: false, messages: e.message) # rubocop:disable Performance/RedundantMerge
break
end
processor.call(context)
rescue StandardError => e
context.merge!(success: false, messages: e.message) # rubocop:disable Performance/RedundantMerge
break
end

@importer.handle_row_import(context)
Expand All @@ -34,7 +32,7 @@ def process(initial_context)

private

def check_import_finished(context)
def check_import_finished(_context)
return unless @row.import.finished?

@row.import.update!(state: (@row.import.rows.failed.any? ? :failed : :completed))
Expand Down
21 changes: 18 additions & 3 deletions lib/solidus_importer/processors/bill_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,25 @@ def province_code
@data['Billing Province Code']
end

def firstname
@data['Billing First Name']
end

def lastname
@data['Billing Last Name']
end

def name
"#{firstname} #{lastname}".strip
end

def bill_address_attributes
name_attrs = if SolidusImporter.combined_first_and_last_name_in_address?
{ name: name }
else
{ firstname: firstname, lastname: lastname }
end
{
firstname: @data['Billing First Name'],
lastname: @data['Billing Last Name'],
address1: @data['Billing Address1'],
address2: @data['Billing Address2'],
city: @data['Billing City'],
Expand All @@ -37,7 +52,7 @@ def bill_address_attributes
phone: @data['Billing Phone'],
country: country,
state: state
}
}.merge(name_attrs)
end

def country
Expand Down
24 changes: 20 additions & 4 deletions lib/solidus_importer/processors/customer_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,34 @@ def state
@state ||= country&.states&.find_by(abbr: @data['Province Code']) if @data['Province Code']
end

def firstname
@data['First Name']
end

def lastname
@data['Last Name']
end

def name
"#{firstname} #{lastname}".strip
end

def address_attributes
@address_attributes ||= {
firstname: @data['First Name'],
lastname: @data['Last Name'],
name_attrs = if SolidusImporter.combined_first_and_last_name_in_address?
{ name: name }
else

{ firstname: firstname, lastname: lastname }
end
{
address1: @data['Address1'],
address2: @data['Address2'],
city: @data['City'],
zipcode: @data['Zip'],
phone: @data['Phone'],
country: country,
state: state,
}
}.merge(name_attrs)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/solidus_importer/processors/product_images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def call(context)
private

def prepare_image
attachment = URI.open(@data['Image Src'])
attachment = URI.parse(@data['Image Src']).open
Spree::Image.new(attachment: attachment, alt: @data['Alt Text'])
end

Expand Down
23 changes: 20 additions & 3 deletions lib/solidus_importer/processors/ship_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,27 @@ def province_code
@data['Shipping Province Code']
end

def firstname
@data['Shipping First Name']
end

def lastname
@data['Shipping Last Name']
end

def name
"#{firstname} #{lastname}".strip
end

def ship_address_attributes
name_attrs = if SolidusImporter.combined_first_and_last_name_in_address?
{ name: name }
else

{ firstname: firstname, lastname: lastname }
end

{
firstname: @data['Shipping First Name'],
lastname: @data['Shipping Last Name'],
address1: @data['Shipping Address1'],
address2: @data['Shipping Address2'],
city: @data['Shipping City'],
Expand All @@ -37,7 +54,7 @@ def ship_address_attributes
phone: @data['Shipping Phone'],
country: country,
state: state,
}
}.merge(name_attrs)
end

def country
Expand Down
2 changes: 1 addition & 1 deletion lib/solidus_importer/processors/variant_images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def call(context)
private

def prepare_image
attachment = URI.open(@data['Variant Image'])
attachment = URI.parse(@data['Variant Image']).open
Spree::Image.new(attachment: attachment)
end

Expand Down
2 changes: 1 addition & 1 deletion solidus_importer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ Gem::Specification.new do |spec|
spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 3']
spec.add_dependency 'solidus_support', '~> 0.5'

spec.add_development_dependency 'solidus_dev_support'
spec.add_development_dependency 'solidus_dev_support', '~> 2.3'
end
3 changes: 2 additions & 1 deletion spec/features/admin/solidus_importer/imports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
describe 'Import create' do
subject(:described_path) { spree.new_admin_solidus_importer_import_path }

let!(:shipping_method) { create :shipping_method }
let(:shipping_method) { create :shipping_method }

let(:import_file) { page.find 'input[name="solidus_importer_import[file]"]' }
let(:import_button) { page.find '[type="submit"]' }
let(:products_csv_file) { solidus_importer_fixture_path('products.csv') }
let(:import_type) { "products" }

before do
shipping_method
allow(::SolidusImporter::ImportJob).to receive(:perform_later)

visit described_path
Expand Down
Loading