workarea-shipping_estimation 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +20 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  4. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. data/.gitignore +13 -0
  7. data/CHANGELOG.md +58 -0
  8. data/CODE_OF_CONDUCT.md +3 -0
  9. data/CONTRIBUTING.md +3 -0
  10. data/Gemfile +6 -0
  11. data/LICENSE +52 -0
  12. data/README.md +62 -0
  13. data/Rakefile +52 -0
  14. data/app/assets/stylesheets/workarea/storefront/shipping_estimation/components/_shipping_estimation.scss +7 -0
  15. data/app/controllers/workarea/storefront/carts_controller.decorator +17 -0
  16. data/app/controllers/workarea/storefront/shipping_estimations_controller.rb +17 -0
  17. data/app/models/workarea/shipping/address.decorator +30 -0
  18. data/app/services/workarea/set_shipping_estimation_address.rb +48 -0
  19. data/app/views/workarea/storefront/carts/_shipping_estimation_form.html.haml +12 -0
  20. data/bin/rails +19 -0
  21. data/config/initializers/appends.rb +9 -0
  22. data/config/initializers/configuration.rb +8 -0
  23. data/config/locales/en.yml +5 -0
  24. data/config/routes.rb +5 -0
  25. data/lib/tasks/shipping_estimation_tasks.rake +4 -0
  26. data/lib/workarea/shipping_estimation.rb +10 -0
  27. data/lib/workarea/shipping_estimation/engine.rb +8 -0
  28. data/lib/workarea/shipping_estimation/version.rb +5 -0
  29. data/test/dummy/Rakefile +6 -0
  30. data/test/dummy/app/controllers/application_controller.rb +3 -0
  31. data/test/dummy/app/controllers/concerns/.keep +0 -0
  32. data/test/dummy/app/helpers/application_helper.rb +2 -0
  33. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  34. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  35. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  36. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  37. data/test/dummy/bin/bundle +3 -0
  38. data/test/dummy/bin/rails +4 -0
  39. data/test/dummy/bin/rake +4 -0
  40. data/test/dummy/bin/setup +34 -0
  41. data/test/dummy/bin/update +29 -0
  42. data/test/dummy/config.ru +5 -0
  43. data/test/dummy/config/application.rb +30 -0
  44. data/test/dummy/config/boot.rb +5 -0
  45. data/test/dummy/config/cable.yml +9 -0
  46. data/test/dummy/config/environment.rb +5 -0
  47. data/test/dummy/config/environments/development.rb +54 -0
  48. data/test/dummy/config/environments/production.rb +86 -0
  49. data/test/dummy/config/environments/test.rb +43 -0
  50. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  51. data/test/dummy/config/initializers/assets.rb +11 -0
  52. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  53. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  54. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  55. data/test/dummy/config/initializers/inflections.rb +16 -0
  56. data/test/dummy/config/initializers/mime_types.rb +4 -0
  57. data/test/dummy/config/initializers/new_framework_defaults.rb +18 -0
  58. data/test/dummy/config/initializers/session_store.rb +3 -0
  59. data/test/dummy/config/initializers/workarea.rb +5 -0
  60. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  61. data/test/dummy/config/puma.rb +47 -0
  62. data/test/dummy/config/routes.rb +5 -0
  63. data/test/dummy/config/secrets.yml +22 -0
  64. data/test/dummy/config/spring.rb +6 -0
  65. data/test/dummy/lib/assets/.keep +0 -0
  66. data/test/dummy/log/.keep +0 -0
  67. data/test/models/shipping/address_estimation_validation_test.rb +42 -0
  68. data/test/services/workarea/set_shipping_estimation_address_test.rb +114 -0
  69. data/test/system/workarea/storefront/shipping_estimation_system_test.rb +100 -0
  70. data/test/test_helper.rb +10 -0
  71. data/test/vcr_cassettes/geolocation.yml +205 -0
  72. data/test/vcr_cassettes/geolocation_19106.yml +104 -0
  73. data/workarea-shipping_estimation.gemspec +21 -0
  74. metadata +129 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5a56d63bd0fe82a3a189a4fefd5a3af7cb53052c03c9485c2551b291f34efa39
4
+ data.tar.gz: fb2478137bd04d832f63ed2daedffd82074ca6eea0623f5043324956fcb25c8a
5
+ SHA512:
6
+ metadata.gz: 778b498242df337170092623e7af0d2f88dc4d561197f8982cbba263ae1393f928021ecf8292c5ed509d3171d05e4801bdab3056030f55e3445afa2880eb6ff4
7
+ data.tar.gz: 68f36c5b136a4513eef17114379b3806e51d2a431fe6ed8d7da17ebc8b17f1e56e01ad1afcc450631b5b46c8cda36365d3ce1e7b179bee7b9e15ea2e23a468dd
data/.editorconfig ADDED
@@ -0,0 +1,20 @@
1
+ # editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ charset = utf-8
6
+ indent_style = space
7
+ end_of_line = lf
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+
11
+ [{*.rb,*.haml,*.decorator,*.yml,*.yaml,*.jbuilder}]
12
+ indent_size = 2
13
+ indent_style = space
14
+
15
+ [{*.js,*.jst,*.ejs,*.scss}]
16
+ indent_size = 4
17
+
18
+ [*.md]
19
+ indent_size = 4
20
+ trim_trailing_whitespace = false
@@ -0,0 +1,37 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve Workarea
4
+ title: ''
5
+ labels: bug
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ ⚠️**Before you create**⚠️
11
+ Please verify the issue you're experiencing is not part of your Workarea project customizations. The best way to do this is with a [vanilla Workarea installation](https://developer.workarea.com/articles/create-a-new-host-application.html). This will help us spend time on fixes/improvements for the whole community. Thank you!
12
+
13
+ **Describe the bug**
14
+ A clear and concise description of what the bug is.
15
+
16
+ **To Reproduce**
17
+ Steps to reproduce the behavior:
18
+ 1. Go to '...'
19
+ 2. Click on '....'
20
+ 3. Scroll down to '....'
21
+ 4. See error
22
+
23
+ **Expected behavior**
24
+ A clear and concise description of what you expected to happen.
25
+
26
+ **Workarea Setup (please complete the following information):**
27
+ - Workarea Version: [e.g. v3.4.6]
28
+ - Plugins [e.g. workarea-blog, workarea-sitemaps]
29
+
30
+ **Attachments**
31
+ If applicable, add any attachments to help explain your problem, things like:
32
+ - screenshots
33
+ - Gemfile.lock
34
+ - test cases
35
+
36
+ **Additional context**
37
+ Add any other context about the problem here.
@@ -0,0 +1,17 @@
1
+ ---
2
+ name: Documentation request
3
+ about: Suggest documentation
4
+ title: ''
5
+ labels: documentation
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your documentation related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm confused by [...]
12
+
13
+ **Describe the article you'd like**
14
+ A clear and concise description of what would be in the documentation article.
15
+
16
+ **Additional context**
17
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for Workarea
4
+ title: ''
5
+ labels: enhancement
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your feature request related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the feature request here.
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ Gemfile.lock
2
+ .bundle/
3
+ log/*.log
4
+ pkg/
5
+ test/dummy/db/*.sqlite3
6
+ test/dummy/db/*.sqlite3-journal
7
+ test/dummy/tmp/
8
+ test/dummy/public/
9
+ test/dummy/log/*.log
10
+ node_modules
11
+ test/reports
12
+ package.json
13
+ yarn.lock
data/CHANGELOG.md ADDED
@@ -0,0 +1,58 @@
1
+ Workarea Shipping Estimation 1.1.2 (2019-08-21)
2
+ --------------------------------------------------------------------------------
3
+
4
+ * Open Source!
5
+
6
+
7
+
8
+ Workarea Shipping Estimation 1.1.1 (2018-10-30)
9
+ --------------------------------------------------------------------------------
10
+
11
+ * Recalculate Shipping when Cart is Updated
12
+
13
+ Estimating shipping charges in the cart did not previously update when
14
+ the subtotal changed, and causes UX issues because the shipping total in
15
+ the cart's summary could be different from the estimated shipping cost
16
+ given in the dropdown. Workarea Shipping Estimation now calculates the
17
+ shipping total when rendering the cart in order to show the most
18
+ up-to-date shipping cost at all times.
19
+
20
+ SHIPEST-10
21
+ Tom Scott
22
+
23
+ * Leverage Workarea Changelog task
24
+
25
+ ECOMMERCE-5355
26
+ Curt Howard
27
+
28
+
29
+
30
+ Workarea Shipping Estimation 1.1.0 (2018-02-06)
31
+ --------------------------------------------------------------------------------
32
+
33
+ * Remove geocoder dependency from gemspec
34
+
35
+ Workarea already defines a dependency on geocoder. There is no need
36
+ to manage it for this plugin as well.
37
+
38
+ SHIPEST-9
39
+ Matt Duffy
40
+
41
+
42
+ Workarea Shipping Estimation 1.0.0 (2017-10-17)
43
+ --------------------------------------------------------------------------------
44
+
45
+ * Autofill shipping estimation form based on user address or geolocation info
46
+
47
+ SHIPEST-6, SHIPEST-8
48
+ Matt Duffy
49
+
50
+ * Fix mention of weblinc, locale file, add css margin under estimator, loosen postal code field for Canada
51
+
52
+ SHIPEST-5
53
+ Dave Barnow
54
+
55
+ * Update for compatibility with workarea v3
56
+
57
+ SHIPEST-3
58
+ Matt Duffy
@@ -0,0 +1,3 @@
1
+ View this plugin's code of conduct here:
2
+
3
+ <https://github.com/workarea-commerce/workarea/blob/master/CODE_OF_CONDUCT.md>
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,3 @@
1
+ View this plugin's contribution guidelines here:
2
+
3
+ <https://github.com/workarea-commerce/workarea/blob/master/CONTRIBUTING.md>
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+ git_source(:github) { |repo| "git@github.com:#{repo}.git" }
3
+
4
+ gemspec
5
+
6
+ gem 'workarea', github: 'workarea-commerce/workarea'
data/LICENSE ADDED
@@ -0,0 +1,52 @@
1
+ WebLinc
2
+ Business Source License
3
+
4
+ Licensor: WebLinc Corporation, 22 S. 3rd Street, 2nd Floor, Philadelphia PA 19106
5
+
6
+ Licensed Work: Workarea Commerce Platform
7
+ The Licensed Work is (c) 2019 WebLinc Corporation
8
+
9
+ Additional Use Grant:
10
+ You may make production use of the Licensed Work without an additional license agreement with WebLinc so long as you do not use the Licensed Work for a Commerce Service.
11
+
12
+ A "Commerce Service" is a commercial offering that allows third parties (other than your employees and contractors) to access the functionality of the Licensed Work by creating or managing commerce functionality, the products, taxonomy, assets and/or content of which are controlled by such third parties.
13
+
14
+ For information about obtaining an additional license agreement with WebLinc, contact licensing@workarea.com.
15
+
16
+ Change Date: 2019-08-20
17
+
18
+ Change License: Version 2.0 or later of the GNU General Public License as published by the Free Software Foundation
19
+
20
+ Terms
21
+
22
+ The Licensor hereby grants you the right to copy, modify, create derivative works, redistribute, and make non-production use of the Licensed Work. The Licensor may make an Additional Use Grant, above, permitting limited production use.
23
+
24
+ Effective on the Change Date, or the fourth anniversary of the first publicly available distribution of a specific version of the Licensed Work under this License, whichever comes first, the Licensor hereby grants you rights under the terms of the Change License, and the rights granted in the paragraph above terminate.
25
+
26
+ If your use of the Licensed Work does not comply with the requirements currently in effect as described in this License, you must purchase a commercial license from the Licensor, its affiliated entities, or authorized resellers, or you must refrain from using the Licensed Work.
27
+
28
+ All copies of the original and modified Licensed Work, and derivative works of the Licensed Work, are subject to this License. This License applies separately for each version of the Licensed Work and the Change Date may vary for each version of the Licensed Work released by Licensor.
29
+
30
+ You must conspicuously display this License on each original or modified copy of the Licensed Work. If you receive the Licensed Work in original or modified form from a third party, the terms and conditions set forth in this License apply to your use of that work.
31
+
32
+ Any use of the Licensed Work in violation of this License will automatically terminate your rights under this License for the current and all other versions of the Licensed Work.
33
+
34
+ This License does not grant you any right in any trademark or logo of Licensor or its affiliates (provided that you may use a trademark or logo of Licensor as expressly required by this License). TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE. MariaDB hereby grants you permission to use this License’s text to license your works and to refer to it using the trademark "Business Source License" as long as you comply with the Covenants of Licensor below.
35
+
36
+ Covenants of Licensor
37
+ In consideration of the right to use this License’s text and the "Business Source License" name and trademark, Licensor covenants to MariaDB, and to all other recipients of the licensed work to be provided by Licensor:
38
+
39
+ To specify as the Change License the GPL Version 2.0 or any later version, or a license that is compatible with GPL Version 2.0 or a later version, where "compatible" means that software provided under the Change License can be included in a program with software provided under GPL Version 2.0 or a later version. Licensor may specify additional Change Licenses without limitation.
40
+
41
+ To either: (a) specify an additional grant of rights to use that does not impose any additional restriction on the right granted in this License, as the Additional Use Grant; or (b) insert the text "None."
42
+
43
+ To specify a Change Date.
44
+
45
+ Not to modify this License in any other way.
46
+
47
+ Notice
48
+ The Business Source License (this document, or the "License") is not an Open Source license. However, the Licensed Work will eventually be made available under an Open Source License, as stated in this License.
49
+
50
+ For more information on the use of the Business Source License generally, please visit the Adopting and Developing Business Source License FAQ.
51
+
52
+ License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved. "Business Source License" is a trademark of MariaDB Corporation Ab.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ Workarea Shipping Estimation
2
+ ================================================================================
3
+
4
+ A Workarea Commerce plugin that adds shipping estimation functionality to the storefront cart page.
5
+
6
+ Getting Started
7
+ --------------------------------------------------------------------------------
8
+
9
+ Add the gem to your application's Gemfile:
10
+
11
+ ```ruby
12
+ # ...
13
+ gem 'workarea-shipping_estimation'
14
+ # ...
15
+ ```
16
+
17
+ Update your application's bundle.
18
+
19
+ ```bash
20
+ cd path/to/application
21
+ bundle
22
+ ```
23
+
24
+ Configuration
25
+ --------------------------------------------------------------------------------
26
+
27
+ This plugin utilizes the [Geocoder gem](https://github.com/alexreisner/geocoder) for gathering address information required to estimate shipping from a postal code. Depending on the services you decide to use, it may require [configuring Geocoder](https://github.com/alexreisner/geocoder#geocoding-service-lookup-configuration).
28
+
29
+ Workarea recommends using Google for geolocation services. However, Google is not free and requires the use of an [API key](https://developers.google.com/maps/documentation/geocoding/get-api-key).
30
+
31
+ To configure a pay-as-you-go Google API key with Geocoder:
32
+
33
+ ```ruby
34
+ Geocoder.configure(
35
+ lookup: :google,
36
+ api_key: Rails.application.secrets.google_maps_api_key
37
+ )
38
+ ```
39
+
40
+ Testing
41
+ --------------------------------------------------------------------------------
42
+
43
+ When writing tests for/around this gem, make sure to wrap your submissions of the shipping estimate with VCR:
44
+
45
+ ```ruby
46
+ VCR.use_cassette(:geocoding) do
47
+ within '#estimate_shipping_form' do
48
+ select 'Ground - $7.00', from: 'shipping_service'
49
+ click_button 'estimate_shipping'
50
+ end
51
+ end
52
+ ```
53
+
54
+ Workarea Commerce Documentation
55
+ --------------------------------------------------------------------------------
56
+
57
+ See [https://developer.workarea.com](https://developer.workarea.com) for Workarea Commerce documentation.
58
+
59
+ License
60
+ --------------------------------------------------------------------------------
61
+
62
+ Workarea Shipping Estimation is released under the [Business Software License](LICENSE)
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Tasker'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+ load 'rails/tasks/statistics.rake'
20
+ load 'workarea/changelog.rake'
21
+
22
+ require 'rake/testtask'
23
+
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.libs << 'test'
27
+ t.pattern = 'test/**/*_test.rb'
28
+ t.verbose = false
29
+ end
30
+
31
+ task default: :test
32
+
33
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
34
+ require 'workarea/shipping_estimation/version'
35
+
36
+ desc "Release version #{Workarea::ShippingEstimation::VERSION} of the gem"
37
+ task :release do
38
+ host = "https://#{ENV['BUNDLE_GEMS__WEBLINC__COM']}@gems.weblinc.com"
39
+
40
+ #Rake::Task['workarea:changelog'].execute
41
+ #system 'git add CHANGELOG.md'
42
+ #system 'git commit -m "Update CHANGELOG"'
43
+ #system 'git push origin HEAD'
44
+
45
+ system "git tag -a v#{Workarea::ShippingEstimation::VERSION} -m 'Tagging #{Workarea::ShippingEstimation::VERSION}'"
46
+ system 'git push --tags'
47
+
48
+ system 'gem build workarea-shipping_estimation.gemspec'
49
+ system "gem push workarea-shipping_estimation-#{Workarea::ShippingEstimation::VERSION}.gem"
50
+ system "gem push workarea-shipping_estimation-#{Workarea::ShippingEstimation::VERSION}.gem --host #{host}"
51
+ system "rm workarea-shipping_estimation-#{Workarea::ShippingEstimation::VERSION}.gem"
52
+ end
@@ -0,0 +1,7 @@
1
+ /*------------------------------------*\
2
+ #SHIPPING-ESTIMATION
3
+ \*------------------------------------*/
4
+
5
+ .shipping-estimation {
6
+ margin-bottom: $vertical-margin;
7
+ }
@@ -0,0 +1,17 @@
1
+ module Workarea
2
+ decorate Storefront::CartsController, with: :shipping_estimation do
3
+ decorated do
4
+ before_action :set_shipping_estimation_address, only: :show
5
+ end
6
+
7
+ private
8
+
9
+ def set_shipping_estimation_address
10
+ SetShippingEstimationAddress.new(
11
+ current_checkout,
12
+ current_location,
13
+ current_user
14
+ ).perform
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Workarea
2
+ class Storefront::ShippingEstimationsController < Storefront::ApplicationController
3
+ def create
4
+ address = Geocoder.search(params[:postal_code]).first
5
+
6
+ current_shipping.set_address(
7
+ postal_code: address.postal_code,
8
+ region: address.state_code,
9
+ country: address.country_code,
10
+ used_for_shipping_estimation: true
11
+ )
12
+
13
+ Workarea::Checkout::Steps::Shipping.new(current_checkout).update(params)
14
+ redirect_to cart_path
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ module Workarea
2
+ decorate Shipping::Address, with: :shipping_estimation do
3
+ decorated do
4
+ field :used_for_shipping_estimation, type: Boolean, default: false
5
+
6
+ before_validation :set_estimate_data
7
+ after_validation :unset_estimate_data
8
+ end
9
+
10
+ def set_estimate_data
11
+ return unless used_for_shipping_estimation?
12
+
13
+ Workarea.config
14
+ .shipping_estimation_placeholder_address
15
+ .each do |field, value|
16
+ send("#{field}=", value) if send(field).blank?
17
+ end
18
+ end
19
+
20
+ def unset_estimate_data
21
+ return unless used_for_shipping_estimation?
22
+
23
+ Workarea.config
24
+ .shipping_estimation_placeholder_address
25
+ .each do |field, value|
26
+ send("#{field}=", nil) if send(field) == value
27
+ end
28
+ end
29
+ end
30
+ end