Skip to content
Open
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
5 changes: 5 additions & 0 deletions .gem_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bump:
recurse: false
file: 'lib/solidus_marketplace/version.rb'
message: Bump SolidusMarketplace to %{version}
tag: true
17 changes: 17 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 60
# Number of days of inactivity before a stale issue is closed
daysUntilClose: false
# Issues with these labels will never be considered stale
exemptLabels:
- pinned
- security
# Label to use when marking an issue as stale
staleLabel: stale
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It might be closed if no further activity occurs. Thank you
for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: false
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
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
*.gem
\#*
*~
.#*
.bundle
.DS_Store
.idea
.project
.ruby-gemset
.ruby-version
.sass-cache
coverage
Gemfile.lock
Expand All @@ -15,5 +13,8 @@ nbproject
pkg
*.swp
spec/dummy
spec/vcr_cassettes
spec/examples.txt
/sandbox
.rvmrc
.ruby-version
.ruby-gemset
2 changes: 1 addition & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
--color
-r spec_helper
--require spec_helper
11 changes: 11 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require:
- solidus_dev_support/rubocop

AllCops:
NewCops: disable

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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ else
end

group :development, :test do
gem 'pry-rails'
gem 'byebug'
gem 'pry-rails'
end

gemspec
Expand Down
23 changes: 3 additions & 20 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
# frozen_string_literal: true

require 'bundler'
Bundler::GemHelper.install_tasks
require 'solidus_dev_support/rake_tasks'
SolidusDevSupport::RakeTasks.install

require 'rspec/core/rake_task'
require 'spree/testing_support/extension_rake'

RSpec::Core::RakeTask.new

task :default do
if Dir["spec/dummy"].empty?
Rake::Task[:test_app].invoke
Dir.chdir("../../")
end
Rake::Task[:spec].invoke
end

desc 'Generates a dummy app for testing'
task :test_app do
ENV['LIB_NAME'] = 'solidus_marketplace'
Rake::Task['extension:test_app'].invoke
end
task default: 'extension:specs'
4 changes: 4 additions & 0 deletions app/assets/stylesheets/spree/backend/solidus_marketplace.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
Placeholder manifest file.
the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/backend/all.css'
*/
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Spree
module Admin
class MarketplaceSettingsController < Spree::Admin::BaseController
Expand All @@ -10,6 +12,7 @@ def update

params.each do |name, value|
next unless config.has_preference? name

config[name] = value
end

Expand Down
22 changes: 16 additions & 6 deletions app/controllers/spree/admin/shipments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Spree
module Admin
class ShipmentsController < Spree::Admin::ResourceController
Expand All @@ -13,18 +15,26 @@ def index
created_at_gt = params[:q][:created_at_gt]
created_at_lt = params[:q][:created_at_lt]

if !params[:q][:created_at_gt].blank?
params[:q][:created_at_gt] = Time.zone.parse(params[:q][:created_at_gt]).beginning_of_day rescue ""
if params[:q][:created_at_gt].present?
params[:q][:created_at_gt] = begin
Time.zone.parse(params[:q][:created_at_gt]).beginning_of_day
rescue StandardError
""
end
end

if !params[:q][:created_at_lt].blank?
params[:q][:created_at_lt] = Time.zone.parse(params[:q][:created_at_lt]).end_of_day rescue ""
if params[:q][:created_at_lt].present?
params[:q][:created_at_lt] = begin
Time.zone.parse(params[:q][:created_at_lt]).end_of_day
rescue StandardError
""
end
end

@search = Spree::Shipment.accessible_by(current_ability, :index).ransack(params[:q])
@shipments = @search.result.
page(params[:page]).
per(params[:per_page] || Spree::Config[:orders_per_page])
page(params[:page]).
per(params[:per_page] || Spree::Config[:orders_per_page])

# Restore dates
params[:q][:created_at_gt] = created_at_gt
Expand Down
10 changes: 7 additions & 3 deletions app/controllers/spree/admin/suppliers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
# frozen_string_literal: true

module Spree
module Admin
class SuppliersController < Spree::Admin::ResourceController
# rubocop:disable Rails/LexicallyScopedActionFilter
before_action :set_address, only: [:update]
before_action :build_address, only: [:edit, :new]
# rubocop:enable Rails/LexicallyScopedActionFilter

private

def set_address
@object.address = Spree::Address.immutable_merge(@object.address,
permitted_resource_params.delete(:address_attributes))
permitted_resource_params.delete(:address_attributes))
end

def build_address
@object.address = Spree::Address.build_default unless @object.address.present?
@object.address = Spree::Address.build_default if @object.address.blank?
end

def collection
params[:q] ||= {}
@search = Spree::Supplier.search(params[:q])
@collection = @search.result.includes(:admins).page(params[:page]).
per(Spree::Config[:orders_per_page])
per(Spree::Config[:orders_per_page])
end

def find_resource
Expand Down
16 changes: 9 additions & 7 deletions app/controllers/spree/api/suppliers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# frozen_string_literal: true

module Spree
module Api
class SuppliersController < Spree::Api::BaseController
def index
if params[:ids]
@suppliers = Spree::Supplier.accessible_by(current_ability, :read).
where(id: params[:ids].split(',')).order(:name)
else
@suppliers = Spree::Supplier.accessible_by(current_ability, :read).
order(:name).ransack(params[:q]).result
end
@suppliers = if params[:ids]
Spree::Supplier.accessible_by(current_ability, :read).
where(id: params[:ids].split(',')).order(:name)
else
Spree::Supplier.accessible_by(current_ability, :read).
order(:name).ransack(params[:q]).result
end

@suppliers = paginate(@suppliers)
respond_with(@suppliers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ def self.prepended(base)
base.after_filter :set_supplier, only: [:create]
end

def index
end
def index; end

private

def set_supplier
if try_spree_current_user.supplier? and @attachment
@attachment.supplier = try_spree_current_user.supplier
@attachment.save
end
return unless try_spree_current_user.supplier? && @attachment

@attachment.supplier = try_spree_current_user.supplier
@attachment.save
end

if defined?(Ckeditor::AttachmentFilesController)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ def self.prepended(base)
base.after_filter :set_supplier, only: [:create]
end

def index
end
def index; end

private

def set_supplier
if spree_current_user.supplier? and @picture
@picture.supplier = spree_current_user.supplier
@picture.save
end
return unless spree_current_user.supplier? && @picture

@picture.supplier = spree_current_user.supplier
@picture.save
end

if defined?(Ckeditor::PicturesController)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ module Spree
module Admin
module ProductsControllerDecorator
def self.prepended(base)
base.before_action :get_suppliers, only: [:edit] #, :update]
base.before_action :load_suppliers, only: [:edit] # , :update]
base.before_action :supplier_collection, only: [:index]
base.after_action :update_product_suppliers, only: [:update], unless: -> { params['product']['supplier_ids'].nil? }
base.after_action :update_product_suppliers, only: [:update], unless: -> {
params['product']['supplier_ids'].nil?
}
base.after_action :add_product_to_supplier, only: [:create]
end

Expand All @@ -30,7 +32,7 @@ def update_product_suppliers
@product.remove_suppliers!(current_suppliers)
@product.add_suppliers!(new_suppliers)
elsif same_suppliers?
#noop
# noop
end
end

Expand All @@ -56,30 +58,30 @@ def different_suppliers?

def new_supplier_ids
return [] unless params["product"].present? && params["product"]["supplier_ids"].present?

params["product"]["supplier_ids"].split(",").map(&:to_i)
end

def current_supplier_ids
@product.supplier_ids
end

def get_suppliers
def load_suppliers
@suppliers = ::Spree::Supplier.order(:name)
end

# Scopes the collection to what the user should have access to, based on the user's role
def supplier_collection
return unless try_spree_current_user
return unless try_spree_current_user&.supplier?

if try_spree_current_user.supplier?
@collection = @collection.joins(:suppliers).where('spree_suppliers.id = ?', try_spree_current_user.supplier_id)
end
@collection = @collection.joins(:suppliers).where('spree_suppliers.id = ?',
try_spree_current_user.supplier_id)
end

# Newly added products by a Supplier are associated with it.
def add_product_to_supplier
if try_spree_current_user&.supplier?
@product.add_supplier!(try_spree_current_user.supplier_id)
@product.add_supplier!(try_spree_current_user.supplier_id)
elsif user_admin?
@product.add_suppliers!(new_supplier_ids)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def self.prepended(base)
end

def earnings
@supplier_earnings = get_supplier_earnings
@supplier_earnings = supplier_earnings

respond_to do |format|
format.html
Expand All @@ -27,9 +27,9 @@ def earnings_csv
csv << header1
csv << header2
@supplier_earnings.each do |se|
csv << ["#{se[:name]}",
"#{se[:earnings].to_html}",
"#{se[:paypal_email]}"]
csv << [(se[:name]).to_s,
se[:earnings].to_html.to_s,
(se[:paypal_email]).to_s]
end
end
end
Expand All @@ -46,7 +46,7 @@ def marketplace_reports
[:earnings]
end

def get_supplier_earnings
def supplier_earnings
grouped_supplier_earnings.each do |se|
se[:earnings] = se[:earnings].inject(Spree::Money.new(0)) do |e, c|
c + e
Expand All @@ -62,7 +62,7 @@ def grouped_supplier_earnings

supplier_earnings_map = @orders.map(&:supplier_earnings_map)
grouped_suppliers_map = supplier_earnings_map.flatten.group_by(&:name).values
grouped_earnings = grouped_suppliers_map.map do |gs|
grouped_suppliers_map.map do |gs|
h = {}
h[:name] = nil
h[:paypal_email] = nil
Expand All @@ -74,8 +74,6 @@ def grouped_supplier_earnings
end
h
end

grouped_earnings
end

if defined?(SolidusReports::Engine)
Expand Down
Loading