solidus_tec_estimator 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +53 -0
  3. data/.gem_release.yml +5 -0
  4. data/.github/stale.yml +1 -0
  5. data/.github_changelog_generator +2 -0
  6. data/.gitignore +21 -0
  7. data/.rubocop.yml +5 -0
  8. data/CHANGELOG.md +3 -0
  9. data/Gemfile +48 -0
  10. data/LICENSE +26 -0
  11. data/README.md +73 -0
  12. data/Rakefile +7 -0
  13. data/app/controllers/spree/admin/solidus_tec_estimator/providers_controller.rb +57 -0
  14. data/app/models/solidus_tec_estimator/estimator.rb +73 -0
  15. data/app/models/solidus_tec_estimator/provider.rb +5 -0
  16. data/app/models/solidus_tec_estimator/providers/local_delivery.rb +66 -0
  17. data/app/models/solidus_tec_estimator/providers/planilha.rb +0 -0
  18. data/app/views/spree/admin/solidus_tec_estimator/providers/_form.html.erb +41 -0
  19. data/app/views/spree/admin/solidus_tec_estimator/providers/edit.html.erb +6 -0
  20. data/app/views/spree/admin/solidus_tec_estimator/providers/index.html.erb +45 -0
  21. data/app/views/spree/admin/solidus_tec_estimator/providers/new.html.erb +6 -0
  22. data/bin/console +17 -0
  23. data/bin/rails +7 -0
  24. data/bin/rails-engine +13 -0
  25. data/bin/rails-sandbox +16 -0
  26. data/bin/rake +7 -0
  27. data/bin/sandbox +76 -0
  28. data/bin/setup +8 -0
  29. data/config/routes.rb +9 -0
  30. data/db/migrate/20240806142636_create_solidus_tec_estimator_providers.rb +11 -0
  31. data/db/migrate/20240806165855_add_provider_id_to_shipping_method.rb +6 -0
  32. data/db/migrate/20240806202950_recreate_min_and_max_delivery_time.rb +9 -0
  33. data/lib/generators/solidus_tec_estimator/install/install_generator.rb +29 -0
  34. data/lib/generators/solidus_tec_estimator/install/templates/initializer.rb +5 -0
  35. data/lib/solidus_tec_estimator/configuration.rb +17 -0
  36. data/lib/solidus_tec_estimator/engine.rb +13 -0
  37. data/lib/solidus_tec_estimator/version.rb +3 -0
  38. data/lib/solidus_tec_estimator.rb +5 -0
  39. data/solidus_tec_estimator.gemspec +36 -0
  40. data/test/fixtures/solidus_tec_estimator/providers.yml +11 -0
  41. data/test/models/solidus_tec_estimator/provider_test.rb +9 -0
  42. metadata +138 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8075ac792c8dac51fa3711d40d07c0fc2fb0e3b5ff02897175cfe9cc73e6f5f9
4
+ data.tar.gz: a226fea6c4785db4fb17d4fd37e77e1fa3e47e3fc516ed2f7b7481c4253cb5c4
5
+ SHA512:
6
+ metadata.gz: 8c41adbb7bbf0f8df9ecca9eafe8b7160543445c47f6f0fadb359f55fd08239b7b8fbcc49e9e4f042ddbd161c212063e1e474e383a728ce4b138c2f8b92d010c
7
+ data.tar.gz: 68ac4b5ac09c7b77b989736d45e32732d229e366d7f04016d4f1aa23b18e61b4a04371058134a83aae75455cf82edfa34cc53c761a37cd3dbe72f69b64e01526
@@ -0,0 +1,53 @@
1
+ version: 2.1
2
+
3
+ orbs:
4
+ # Required for feature specs.
5
+ browser-tools: circleci/browser-tools@1.1
6
+
7
+ # Always take the latest version of the orb, this allows us to
8
+ # run specs against Solidus supported versions only without the need
9
+ # to change this configuration every time a Solidus version is released
10
+ # or goes EOL.
11
+ solidusio_extensions: solidusio/extensions@volatile
12
+
13
+ jobs:
14
+ run-specs-with-sqlite:
15
+ executor: solidusio_extensions/sqlite
16
+ steps:
17
+ - browser-tools/install-chrome
18
+ - solidusio_extensions/run-tests
19
+ run-specs-with-postgres:
20
+ executor: solidusio_extensions/postgres
21
+ steps:
22
+ - browser-tools/install-chrome
23
+ - solidusio_extensions/run-tests
24
+ run-specs-with-mysql:
25
+ executor: solidusio_extensions/mysql
26
+ steps:
27
+ - browser-tools/install-chrome
28
+ - solidusio_extensions/run-tests
29
+ lint-code:
30
+ executor: solidusio_extensions/sqlite-memory
31
+ steps:
32
+ - solidusio_extensions/lint-code
33
+
34
+ workflows:
35
+ "Run specs on supported Solidus versions":
36
+ jobs:
37
+ - run-specs-with-sqlite
38
+ - run-specs-with-postgres
39
+ - run-specs-with-mysql
40
+ - lint-code
41
+
42
+ "Weekly run specs against main":
43
+ triggers:
44
+ - schedule:
45
+ cron: "0 0 * * 4" # every Thursday
46
+ filters:
47
+ branches:
48
+ only:
49
+ - main
50
+ jobs:
51
+ - run-specs-with-sqlite
52
+ - run-specs-with-postgres
53
+ - run-specs-with-mysql
data/.gem_release.yml ADDED
@@ -0,0 +1,5 @@
1
+ bump:
2
+ recurse: false
3
+ file: 'lib/solidus_tec_estimator/version.rb'
4
+ message: Bump SolidusTecEstimator to %{version}
5
+ tag: true
data/.github/stale.yml ADDED
@@ -0,0 +1 @@
1
+ _extends: .github
@@ -0,0 +1,2 @@
1
+ issues=false
2
+ exclude-labels=infrastructure
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ \#*
3
+ *~
4
+ .#*
5
+ .DS_Store
6
+ .idea
7
+ .project
8
+ .sass-cache
9
+ coverage
10
+ Gemfile.lock
11
+ Gemfile-local
12
+ tmp
13
+ nbproject
14
+ pkg
15
+ *.swp
16
+ spec/dummy
17
+ spec/examples.txt
18
+ /sandbox
19
+ .rvmrc
20
+ .ruby-version
21
+ .ruby-gemset
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ require:
2
+ - solidus_dev_support/rubocop
3
+
4
+ AllCops:
5
+ NewCops: disable
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # Changelog
2
+
3
+ See https://github.com/solidusio-contrib/solidus_tec_estimator/releases or OLD_CHANGELOG.md for older versions.
data/Gemfile ADDED
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5
+
6
+ branch = ENV.fetch('SOLIDUS_BRANCH', 'main')
7
+ gem 'solidus', github: 'solidusio/solidus', branch: branch
8
+
9
+ # The solidus_frontend gem has been pulled out since v3.2
10
+ if branch >= 'v3.2'
11
+ gem 'solidus_frontend'
12
+ elsif branch == 'main'
13
+ gem 'solidus_frontend', github: 'solidusio/solidus_frontend'
14
+ else
15
+ gem 'solidus_frontend', github: 'solidusio/solidus', branch: branch
16
+ end
17
+
18
+ # Needed to help Bundler figure out how to resolve dependencies,
19
+ # otherwise it takes forever to resolve them.
20
+ # See https://github.com/bundler/bundler/issues/6677
21
+ gem 'rails', '>0.a'
22
+
23
+
24
+ # Provides basic authentication functionality for testing parts of your engine
25
+ gem 'solidus_auth_devise'
26
+
27
+ case ENV.fetch('DB', nil)
28
+ when 'mysql'
29
+ gem 'mysql2'
30
+ when 'postgresql'
31
+ gem 'pg'
32
+ else
33
+ gem 'sqlite3'
34
+ end
35
+
36
+ # While we still support Ruby < 3 we need to workaround a limitation in
37
+ # the 'async' gem that relies on the latest ruby, since RubyGems doesn't
38
+ # resolve gems based on the required ruby version.
39
+ gem 'async', '< 3' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3')
40
+
41
+ gemspec
42
+
43
+ # Use a local Gemfile to include development dependencies that might not be
44
+ # relevant for the project or for other contributors, e.g. pry-byebug.
45
+ #
46
+ # We use `send` instead of calling `eval_gemfile` to work around an issue with
47
+ # how Dependabot parses projects: https://github.com/dependabot/dependabot-core/issues/1658.
48
+ send(:eval_gemfile, 'Gemfile-local') if File.exist? 'Gemfile-local'
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2024 ulysses
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Solidus nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # Solidus Tec Estimator
2
+
3
+ [![CircleCI](https://circleci.com/gh/solidusio-contrib/solidus_tec_estimator.svg?style=shield)](https://circleci.com/gh/solidusio-contrib/solidus_tec_estimator)
4
+ [![codecov](https://codecov.io/gh/solidusio-contrib/solidus_tec_estimator/branch/main/graph/badge.svg)](https://codecov.io/gh/solidusio-contrib/solidus_tec_estimator)
5
+
6
+ <!-- Explain what your extension does. -->
7
+
8
+ ## Installation
9
+
10
+ Add solidus_tec_estimator to your Gemfile:
11
+
12
+ ```ruby
13
+ gem 'solidus_tec_estimator'
14
+ ```
15
+
16
+ Bundle your dependencies and run the installation generator:
17
+
18
+ ```shell
19
+ bin/rails generate solidus_tec_estimator:install
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ <!-- Explain how to use your extension once it's been installed. -->
25
+
26
+ ## Development
27
+
28
+ ### Testing the extension
29
+
30
+ First bundle your dependencies, then run `bin/rake`. `bin/rake` will default to building the dummy
31
+ app if it does not exist, then it will run specs. The dummy app can be regenerated by using
32
+ `bin/rake extension:test_app`.
33
+
34
+ ```shell
35
+ bin/rake
36
+ ```
37
+
38
+ To run [Rubocop](https://github.com/bbatsov/rubocop) static code analysis run
39
+
40
+ ```shell
41
+ bundle exec rubocop
42
+ ```
43
+
44
+ When testing your application's integration with this extension you may use its factories.
45
+ You can load Solidus core factories along with this extension's factories using this statement:
46
+
47
+ ```ruby
48
+ SolidusDevSupport::TestingSupport::Factories.load_for(SolidusTecEstimator::Engine)
49
+ ```
50
+
51
+ ### Running the sandbox
52
+
53
+ To run this extension in a sandboxed Solidus application, you can run `bin/sandbox`. The path for
54
+ the sandbox app is `./sandbox` and `bin/rails` will forward any Rails commands to
55
+ `sandbox/bin/rails`.
56
+
57
+ Here's an example:
58
+
59
+ ```
60
+ $ bin/rails server
61
+ => Booting Puma
62
+ => Rails 6.0.2.1 application starting in development
63
+ * Listening on tcp://127.0.0.1:3000
64
+ Use Ctrl-C to stop
65
+ ```
66
+
67
+ ### Releasing new versions
68
+
69
+ Please refer to the [dedicated page](https://github.com/solidusio/solidus/wiki/How-to-release-extensions) in the Solidus wiki.
70
+
71
+ ## License
72
+
73
+ Copyright (c) 2024 ulysses, released under the New BSD License.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require 'solidus_dev_support/rake_tasks'
5
+ SolidusDevSupport::RakeTasks.install
6
+
7
+ task default: 'extension:specs'
@@ -0,0 +1,57 @@
1
+ module Spree
2
+ module Admin
3
+ module SolidusTecEstimator
4
+ class ProvidersController < BaseController
5
+ before_action :set_provider, only: [:edit, :update, :destroy]
6
+ before_action :set_providers_classes, only: [:new, :edit]
7
+
8
+ def index
9
+ @providers = ::SolidusTecEstimator::Provider.all
10
+ end
11
+
12
+ def new
13
+ @provider = ::SolidusTecEstimator::Provider.new
14
+ end
15
+
16
+ def edit
17
+ end
18
+
19
+ def create
20
+ provider = ::SolidusTecEstimator::Provider.new provider_params
21
+ if provider.save
22
+ flash[:success] = "Provider criado com sucesso"
23
+ redirect_to admin_solidus_tec_estimator_providers_path
24
+ else
25
+ flash[:error] = provider.errors.full_messages.join("\n")
26
+ redirect_to new_admin_solidus_tec_estimator_provider_path
27
+ end
28
+ end
29
+
30
+ def update
31
+ @provider.update provider_params
32
+ redirect_to admin_solidus_tec_estimator_providers_path
33
+ end
34
+
35
+ def destroy
36
+ @provider.delete
37
+ flash[:success] = "Provider excluído"
38
+ redirect_to admin_solidus_tec_estimator_providers_path
39
+ end
40
+
41
+ private
42
+
43
+ def set_provider
44
+ @provider = ::SolidusTecEstimator::Provider.find_by(id: params[:id])
45
+ end
46
+
47
+ def set_providers_classes
48
+ @providers_classes = ::SolidusTecEstimator.config.providers_classes || []
49
+ end
50
+
51
+ def provider_params
52
+ params.required(:provider).permit(:name, :class_name, :active)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,73 @@
1
+ module SolidusTecEstimator
2
+ class Estimator
3
+
4
+ def shipping_rates(package, _frontend_only = true)
5
+
6
+ rates = shipping_methods(package).map do |shipping_method|
7
+ cost = shipping_method.calculator.compute(package)
8
+ if cost
9
+ rate = shipping_method.shipping_rates.new(
10
+ cost: cost,
11
+ shipment: package.shipment,
12
+ min_delivery_time: DateTime.now + (SolidusTecEstimator.config.min_delivery_time || 8),
13
+ max_delivery_time: DateTime.now + (SolidusTecEstimator.config.max_delivery_time || 10)
14
+ )
15
+ rate
16
+ end
17
+ end.compact
18
+ rates += providers(package).map do |provider|
19
+ provider_shipping_methods = provider.spree_shipping_methods.available_in_stock_location(package.stock_location)
20
+ provider.class_name.constantize.new(package, provider_shipping_methods).shipping_rates
21
+ end.flatten.compact
22
+
23
+ choose_default_shipping_rate(rates)
24
+ Spree::Config.shipping_rate_sorter_class.new(rates).sort
25
+ end
26
+
27
+ private
28
+
29
+ def choose_default_shipping_rate(shipping_rates)
30
+ unless shipping_rates.empty?
31
+ default_shipping_rate = Spree::Config.shipping_rate_selector_class.new(shipping_rates).find_default
32
+ default_shipping_rate.selected = true
33
+ end
34
+ end
35
+
36
+ def shipping_methods(package)
37
+ package.shipping_methods
38
+ .available_to_store(package.shipment.order.store)
39
+ .available_for_address(package.shipment.order.ship_address)
40
+ .where(available_to_users: true)
41
+ .includes(:calculator)
42
+ .to_a.select do |ship_method|
43
+ calculator = ship_method.calculator
44
+ calculator.available?(package) && (calculator.preferences[:currency].blank? || calculator.preferences[:currency] == package.shipment.order.currency)
45
+ end
46
+ end
47
+
48
+ def providers(package)
49
+ SolidusTecEstimator::Provider.where(active: true)
50
+ end
51
+
52
+ def build_default_shipping_rate package
53
+ shipping_method = Spree::ShippingMethod.find_or_create_by(
54
+ carrier: "Frete Padrão",
55
+ service_level: ""
56
+ ) do |shipping_method|
57
+ shipping_method.name = "Frete Padrão"
58
+ shipping_method.calculator = Spree::Calculator::Shipping::FlatRate.create
59
+ shipping_method.shipping_categories = Spree::ShippingCategory.all
60
+ shipping_method.available_to_users = true
61
+ end
62
+
63
+ Spree::ShippingRate.new(
64
+ shipment: package.shipment,
65
+ shipping_method: shipping_method,
66
+ cost: 15.00,
67
+ min_delivery_time: 8,
68
+ max_delivery_time: 10
69
+ )
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,5 @@
1
+ module SolidusTecEstimator
2
+ class Provider < ApplicationRecord
3
+ has_many :spree_shipping_methods, class_name: "Spree::ShippingMethod"
4
+ end
5
+ end
@@ -0,0 +1,66 @@
1
+ module SolidusTecEstimator
2
+ module Providers
3
+ class LocalDelivery
4
+
5
+ attr_accessor :package, :shipping_methods
6
+ def initialize package, shipping_methods
7
+ @package = package
8
+ @shipping_methods = shipping_methods
9
+ end
10
+
11
+ def shipping_rates
12
+ shipping_rates = []
13
+ if ship_address_city == "São João da Boa Vista" && tem_estoque_na_f1? && package.weight <= 10000
14
+ shipping_rates << build_shipping_rate(package)
15
+ end
16
+ shipping_rates.select { |rate| shipping_methods.include?(rate.shipping_method) }
17
+ end
18
+
19
+ def tem_estoque_na_f1?
20
+ package_quantity = package.contents.map {|c| c.inventory_unit.variant_id }.tally
21
+ variants = package.contents.map(&:variant)
22
+ variants.all? do |variant|
23
+ product_stock = ProductStock.find_by(sku: variant.sku.strip)
24
+ stock_available = product_stock&.quantity || 0
25
+ stock_available >= package_quantity[variant.id]
26
+ end
27
+ end
28
+
29
+ def build_shipping_rate(package)
30
+ shipping_method = Spree::ShippingMethod.find_or_create_by(
31
+ carrier: "Entrega local",
32
+ service_level: ""
33
+ ) do |shipping_method|
34
+ shipping_method.name = "Entrega de moto"
35
+ shipping_method.calculator = Spree::Calculator::Shipping::FlatRate.create
36
+ shipping_method.shipping_categories = Spree::ShippingCategory.all
37
+ shipping_method.available_to_users = true
38
+ shipping_method.provider_id = SolidusTecEstimator::Provider.find_by(class_name: self.class.to_s).id
39
+ end
40
+
41
+ if Time.now < Time.now.change({hour: 16}) && Time.now.on_weekday?
42
+ min_delivery_time = (Time.now + 30.minutes)
43
+ max_delivery_time = (Time.now + 2.hours)
44
+ elsif Time.now > Time.now.change({hour: 16}) && Time.now.next_day.on_weekday?
45
+ min_delivery_time = Time.now.next_day.change({hour: 8})
46
+ max_delivery_time = Time.now.next_day.change({hour: 10})
47
+ else
48
+ min_delivery_time = Time.now.next_weekday.change({hour: 8})
49
+ max_delivery_time = Time.now.next_weekday.change({hour: 10})
50
+ end
51
+
52
+ Spree::ShippingRate.new(
53
+ shipment: package.shipment,
54
+ shipping_method: shipping_method,
55
+ cost: 0,
56
+ min_delivery_time: min_delivery_time,
57
+ max_delivery_time: max_delivery_time
58
+ )
59
+ end
60
+
61
+ def ship_address_city
62
+ Cep.find_by(codigo_postal: package.order.last_zipcode).try(:localidade) || package.order.ship_address.city
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,41 @@
1
+ <%= form_with model: provider, url: form_url do |form| %>
2
+ <fieldset class="no-border-top">
3
+ <legend>
4
+ Dados da Provider
5
+ </legend>
6
+ <div class="row">
7
+ <div class="col-12 col-md-6">
8
+
9
+ <%= form.field_container :name do %>
10
+ <%= form.label :name, "Nome", class: 'required' %>
11
+ <%= form.text_field :name, required: true, class: 'fullwidth' %>
12
+ <%= form.error_message_on :name %>
13
+ <% end %>
14
+
15
+ <%= form.field_container :active do %>
16
+ <label>
17
+ <%= form.check_box :active, { checked: provider.active.nil? ? true : provider.active } %>
18
+ <%= "Ativo" %>
19
+ </label>
20
+ <% end %>
21
+
22
+ </div>
23
+ <div class="col-12 col-md-6">
24
+
25
+ <%= form.field_container :name do %>
26
+ <%= form.label :class_name, "Classe", class: 'required' %>
27
+ <%= form.select :class_name, @providers_classes, {selected: provider.class_name, include_blank: true }, { class: "custom-select fullwidth", required: true } %>
28
+ <%= form.error_message_on :class_name %>
29
+ <% end %>
30
+
31
+ </div>
32
+ </div>
33
+ </fieldset>
34
+
35
+ <div class="form-buttons filter-actions actions" data-hook="buttons">
36
+ <%= form.submit "Salvar", class: 'btn btn-primary' %>
37
+ <% if params["action"] == 'edit' %>
38
+ <%= link_to "Excluir", admin_solidus_tec_estimator_provider_path(provider.id), method: :delete, data: { confirm: "Tem certeza que deseja excluir o provider?"}, class: 'button' %>
39
+ <% end %>
40
+ </div>
41
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <%= render partial: 'spree/admin/shared/shipping_tabs', locals: { current: 'Providers' } %>
2
+
3
+ <% admin_breadcrumb("Provider") %>
4
+
5
+ <%= render "form", provider: @provider, form_url:
6
+ admin_solidus_tec_estimator_provider_path(@provider.id) %>
@@ -0,0 +1,45 @@
1
+ <%= render partial: 'spree/admin/shared/shipping_tabs', locals: { current: 'Providers' } %>
2
+
3
+ <% admin_breadcrumb("Provider") %>
4
+
5
+ <% content_for :page_actions do %>
6
+ <li>
7
+ <%= link_to "Novo Provider", new_admin_solidus_tec_estimator_provider_path, class: 'btn btn-primary' %>
8
+ </li>
9
+ <% end %>
10
+
11
+ <% if @providers.any? %>
12
+ <table class="index">
13
+ <colgroup>
14
+ <col style="width: 85%">
15
+ <col style="width: 15%">
16
+ </colgroup>
17
+ <thead>
18
+ <tr data-hook="categories_header">
19
+ <th><%= "Providers" %></th>
20
+ <th class="actions"></th>
21
+ </tr>
22
+ </thead>
23
+ <tbody>
24
+ <% @providers.each do |provider| %>
25
+ <tr id="<%= spree_dom_id provider %>" data-hook="category_row">
26
+ <td><%= provider.name %></td>
27
+ <td class="actions">
28
+ <% if can?(:update, provider) %>
29
+
30
+ <%= link_to "", edit_admin_solidus_tec_estimator_provider_path(provider.id), class: "icon_link with-tip fa fa-edit no-text"%>
31
+
32
+ <%= link_to "", admin_solidus_tec_estimator_provider_path(provider.id), method: :delete, data: { confirm: "Tem certeza que deseja excluir a provider?"}, class: 'delete-resource icon_link with-tip fa fa-trash no-text' %>
33
+
34
+ <% end %>
35
+
36
+ </td>
37
+ </tr>
38
+ <% end %>
39
+ </tbody>
40
+ </table>
41
+ <% else %>
42
+ <div class="no-objects-found">
43
+ Não tem Provider cadastrado
44
+ </div>
45
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <%= render partial: 'spree/admin/shared/shipping_tabs', locals: { current: 'Providers' } %>
2
+
3
+ <% admin_breadcrumb("Provider") %>
4
+
5
+ <%= render "form", provider: @provider, form_url:
6
+ admin_solidus_tec_estimator_providers_path %>
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_tec_estimator"
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 ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
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_tec_estimator/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,76 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+ test -z "${DEBUG+empty_string}" || set -x
5
+
6
+ test "$DB" = "sqlite" && export DB="sqlite3"
7
+
8
+ if [ -z "$PAYMENT_METHOD" ]
9
+ then
10
+ PAYMENT_METHOD="none"
11
+ fi
12
+
13
+ if [ -z "$SOLIDUS_BRANCH" ]
14
+ then
15
+ echo "~~> Use 'export SOLIDUS_BRANCH=[main|v4.0|...]' to control the Solidus branch"
16
+ SOLIDUS_BRANCH="main"
17
+ fi
18
+ echo "~~> Using branch $SOLIDUS_BRANCH of solidus"
19
+
20
+ extension_name="solidus_tec_estimator"
21
+
22
+ # Stay away from the bundler env of the containing extension.
23
+ function unbundled {
24
+ ruby -rbundler -e'
25
+ Bundler.with_unbundled_env {system *ARGV}' -- \
26
+ env BUNDLE_SUPPRESS_INSTALL_USING_MESSAGES=true $@
27
+ }
28
+
29
+ echo "~~~> Removing the old sandbox"
30
+ rm -rf ./sandbox
31
+
32
+ echo "~~~> Creating a pristine Rails app"
33
+ rails new sandbox \
34
+ --database="${DB:-sqlite3}" \
35
+ --skip-git \
36
+ --skip-keeps \
37
+ --skip-rc \
38
+ --skip-bootsnap \
39
+ --skip-test
40
+
41
+ if [ ! -d "sandbox" ]; then
42
+ echo 'sandbox rails application failed'
43
+ exit 1
44
+ fi
45
+
46
+ echo "~~~> Adding solidus (with i18n) to the Gemfile"
47
+ cd ./sandbox
48
+ cat <<RUBY >> Gemfile
49
+ gem 'solidus', github: 'solidusio/solidus', branch: '$SOLIDUS_BRANCH'
50
+ gem 'rails-i18n'
51
+ gem 'solidus_i18n'
52
+ gem 'solidus_auth_devise'
53
+
54
+ gem '$extension_name', path: '..'
55
+
56
+ group :test, :development do
57
+ platforms :mri do
58
+ gem 'pry-byebug'
59
+ end
60
+ end
61
+ RUBY
62
+
63
+ unbundled bundle install --gemfile Gemfile
64
+
65
+ unbundled bundle exec rake db:drop db:create
66
+
67
+ unbundled bundle exec rails generate solidus:install \
68
+ --auto-accept \
69
+ $@
70
+
71
+ unbundled bundle exec rails generate solidus:auth:install --auto-run-migrations
72
+ unbundled bundle exec rails generate ${extension_name}:install --auto-run-migrations
73
+
74
+ echo
75
+ echo "🚀 Sandbox app successfully created for $extension_name!"
76
+ 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 ADDED
@@ -0,0 +1,9 @@
1
+ Spree::Core::Engine.routes.draw do
2
+
3
+ namespace :admin do
4
+ namespace :solidus_tec_estimator do
5
+ resources :providers
6
+ end
7
+ end
8
+
9
+ end
@@ -0,0 +1,11 @@
1
+ class CreateSolidusTecEstimatorProviders < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :solidus_tec_estimator_providers do |t|
4
+ t.string :name
5
+ t.string :class_name
6
+ t.boolean :active
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ class AddProviderIdToShippingMethod < ActiveRecord::Migration[7.1]
2
+ def change
3
+ add_column :spree_shipping_methods, :provider_id, :bigint, null: true
4
+ add_index :spree_shipping_methods, :provider_id
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ class RecreateMinAndMaxDeliveryTime < ActiveRecord::Migration[7.1]
2
+ def change
3
+ remove_column :spree_shipping_rates, :min_delivery_time, if_exists: true
4
+ remove_column :spree_shipping_rates, :max_delivery_time, if_exists: true
5
+
6
+ add_column :spree_shipping_rates, :min_delivery_time, :datetime
7
+ add_column :spree_shipping_rates, :max_delivery_time, :datetime
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+ module SolidusTecEstimator
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ class_option :auto_run_migrations, type: :boolean, default: false
5
+ source_root File.expand_path('templates', __dir__)
6
+
7
+ def self.exit_on_failure?
8
+ true
9
+ end
10
+
11
+ def copy_initializer
12
+ template 'initializer.rb', 'config/initializers/solidus_tec_estimator.rb'
13
+ end
14
+
15
+ def add_migrations
16
+ run 'bin/rails railties:install:migrations FROM=solidus_tec_estimator'
17
+ end
18
+
19
+ def run_migrations
20
+ run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Layout/LineLength
21
+ if run_migrations
22
+ run 'bin/rails db:migrate'
23
+ else
24
+ puts 'Skipping bin/rails db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ SolidusTecEstimator.configure do |config|
2
+ config.min_delivery_time = 8
3
+ config.max_delivery_time = 10
4
+ config.providers_classes = ["SolidusTecEstimator::Providers::LocalDelivery"]
5
+ end
@@ -0,0 +1,17 @@
1
+ module SolidusTecEstimator
2
+ class Configuration
3
+ attr_accessor :min_delivery_time, :max_delivery_time, :providers_classes
4
+ end
5
+
6
+ class << self
7
+ def configuration
8
+ @configuration ||= Configuration.new
9
+ end
10
+
11
+ alias config configuration
12
+
13
+ def configure
14
+ yield configuration
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ require 'solidus_core'
2
+ require 'solidus_support'
3
+
4
+ module SolidusTecEstimator
5
+ class Engine < Rails::Engine
6
+ include SolidusSupport::EngineExtensions
7
+
8
+ isolate_namespace ::SolidusTecEstimator
9
+
10
+ engine_name 'solidus_tec_estimator'
11
+
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module SolidusTecEstimator
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'solidus_tec_estimator/configuration'
4
+ require 'solidus_tec_estimator/version'
5
+ require 'solidus_tec_estimator/engine'
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/solidus_tec_estimator/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'solidus_tec_estimator'
7
+ spec.version = SolidusTecEstimator::VERSION
8
+ spec.authors = ['ulysses']
9
+ spec.email = 'ulyssesh.20@gmail.com'
10
+
11
+ spec.summary = ''
12
+ spec.description = ''
13
+ spec.homepage = 'https://github.com/ulysses-bull/solidus_tec_estimator#readme'
14
+ spec.license = 'BSD-3-Clause'
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = 'https://github.com/ulysses-bull/solidus_tec_estimator'
18
+ spec.metadata['changelog_uri'] = 'https://github.com/ulysses-bull/solidus_tec_estimator'
19
+
20
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5', '< 4')
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }
25
+
26
+ spec.files = files.grep_v(%r{^(test|spec|features)/})
27
+ spec.test_files = files.grep(%r{^(test|spec|features)/})
28
+ spec.bindir = "exe"
29
+ spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 5']
33
+ spec.add_dependency 'solidus_support', '~> 0.5'
34
+
35
+ spec.add_development_dependency 'solidus_dev_support', '~> 2.9'
36
+ end
@@ -0,0 +1,11 @@
1
+ # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ one:
4
+ name: MyString
5
+ type:
6
+ active: false
7
+
8
+ two:
9
+ name: MyString
10
+ type:
11
+ active: false
@@ -0,0 +1,9 @@
1
+ require "test_helper"
2
+
3
+ module SolidusTecEstimator
4
+ class ProviderTest < ActiveSupport::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: solidus_tec_estimator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - ulysses
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-08-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: solidus_core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5'
33
+ - !ruby/object:Gem::Dependency
34
+ name: solidus_support
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.5'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.5'
47
+ - !ruby/object:Gem::Dependency
48
+ name: solidus_dev_support
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.9'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '2.9'
61
+ description: ''
62
+ email: ulyssesh.20@gmail.com
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - ".circleci/config.yml"
68
+ - ".gem_release.yml"
69
+ - ".github/stale.yml"
70
+ - ".github_changelog_generator"
71
+ - ".gitignore"
72
+ - ".rubocop.yml"
73
+ - CHANGELOG.md
74
+ - Gemfile
75
+ - LICENSE
76
+ - README.md
77
+ - Rakefile
78
+ - app/controllers/spree/admin/solidus_tec_estimator/providers_controller.rb
79
+ - app/models/solidus_tec_estimator/estimator.rb
80
+ - app/models/solidus_tec_estimator/provider.rb
81
+ - app/models/solidus_tec_estimator/providers/local_delivery.rb
82
+ - app/models/solidus_tec_estimator/providers/planilha.rb
83
+ - app/views/spree/admin/solidus_tec_estimator/providers/_form.html.erb
84
+ - app/views/spree/admin/solidus_tec_estimator/providers/edit.html.erb
85
+ - app/views/spree/admin/solidus_tec_estimator/providers/index.html.erb
86
+ - app/views/spree/admin/solidus_tec_estimator/providers/new.html.erb
87
+ - bin/console
88
+ - bin/rails
89
+ - bin/rails-engine
90
+ - bin/rails-sandbox
91
+ - bin/rake
92
+ - bin/sandbox
93
+ - bin/setup
94
+ - config/routes.rb
95
+ - db/migrate/20240806142636_create_solidus_tec_estimator_providers.rb
96
+ - db/migrate/20240806165855_add_provider_id_to_shipping_method.rb
97
+ - db/migrate/20240806202950_recreate_min_and_max_delivery_time.rb
98
+ - lib/generators/solidus_tec_estimator/install/install_generator.rb
99
+ - lib/generators/solidus_tec_estimator/install/templates/initializer.rb
100
+ - lib/solidus_tec_estimator.rb
101
+ - lib/solidus_tec_estimator/configuration.rb
102
+ - lib/solidus_tec_estimator/engine.rb
103
+ - lib/solidus_tec_estimator/version.rb
104
+ - solidus_tec_estimator.gemspec
105
+ - test/fixtures/solidus_tec_estimator/providers.yml
106
+ - test/models/solidus_tec_estimator/provider_test.rb
107
+ homepage: https://github.com/ulysses-bull/solidus_tec_estimator#readme
108
+ licenses:
109
+ - BSD-3-Clause
110
+ metadata:
111
+ homepage_uri: https://github.com/ulysses-bull/solidus_tec_estimator#readme
112
+ source_code_uri: https://github.com/ulysses-bull/solidus_tec_estimator
113
+ changelog_uri: https://github.com/ulysses-bull/solidus_tec_estimator
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '2.5'
123
+ - - "<"
124
+ - !ruby/object:Gem::Version
125
+ version: '4'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubygems_version: 3.5.11
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: ''
136
+ test_files:
137
+ - test/fixtures/solidus_tec_estimator/providers.yml
138
+ - test/models/solidus_tec_estimator/provider_test.rb