workarea-shipping_message 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) 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/.github/workflows/ci.yml +54 -0
  7. data/.gitignore +13 -0
  8. data/.rubocop.yml +3 -0
  9. data/CHANGELOG.md +42 -0
  10. data/CODE_OF_CONDUCT.md +3 -0
  11. data/CONTRIBUTING.md +3 -0
  12. data/Gemfile +9 -0
  13. data/LICENSE.md +3 -0
  14. data/README.md +40 -0
  15. data/Rakefile +42 -0
  16. data/app/controllers/workarea/admin/pricing_discounts_controller.decorator +8 -0
  17. data/app/models/workarea/pricing/discount/message.rb +15 -0
  18. data/app/models/workarea/pricing/discount/shipping.decorator +11 -0
  19. data/app/seeds/workarea/free_shipping_promo_seeds.rb +24 -0
  20. data/app/view_models/workarea/storefront/cart_view_model.decorator +49 -0
  21. data/app/views/workarea/admin/pricing_discounts/_message_card.haml +22 -0
  22. data/app/views/workarea/admin/pricing_discounts/message.haml +49 -0
  23. data/app/views/workarea/storefront/carts/_shipping_message.html.haml +2 -0
  24. data/bin/rails +18 -0
  25. data/config/initializers/appends.rb +11 -0
  26. data/config/initializers/seeds.rb +3 -0
  27. data/config/locales/en.yml +23 -0
  28. data/config/routes.rb +11 -0
  29. data/lib/workarea/shipping_message.rb +12 -0
  30. data/lib/workarea/shipping_message/engine.rb +8 -0
  31. data/lib/workarea/shipping_message/version.rb +5 -0
  32. data/test/dummy/Rakefile +6 -0
  33. data/test/dummy/app/assets/config/manifest.js +4 -0
  34. data/test/dummy/app/assets/images/.keep +0 -0
  35. data/test/dummy/app/assets/javascripts/application.js +13 -0
  36. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  37. data/test/dummy/app/controllers/application_controller.rb +3 -0
  38. data/test/dummy/app/controllers/concerns/.keep +0 -0
  39. data/test/dummy/app/helpers/application_helper.rb +2 -0
  40. data/test/dummy/app/jobs/application_job.rb +2 -0
  41. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  42. data/test/dummy/app/models/concerns/.keep +0 -0
  43. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  44. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  45. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  46. data/test/dummy/bin/bundle +3 -0
  47. data/test/dummy/bin/rails +4 -0
  48. data/test/dummy/bin/rake +4 -0
  49. data/test/dummy/bin/setup +34 -0
  50. data/test/dummy/bin/update +29 -0
  51. data/test/dummy/config.ru +5 -0
  52. data/test/dummy/config/application.rb +26 -0
  53. data/test/dummy/config/boot.rb +5 -0
  54. data/test/dummy/config/cable.yml +9 -0
  55. data/test/dummy/config/environment.rb +5 -0
  56. data/test/dummy/config/environments/development.rb +54 -0
  57. data/test/dummy/config/environments/production.rb +86 -0
  58. data/test/dummy/config/environments/test.rb +43 -0
  59. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  60. data/test/dummy/config/initializers/assets.rb +11 -0
  61. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  62. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  63. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  64. data/test/dummy/config/initializers/inflections.rb +16 -0
  65. data/test/dummy/config/initializers/mime_types.rb +4 -0
  66. data/test/dummy/config/initializers/new_framework_defaults.rb +17 -0
  67. data/test/dummy/config/initializers/workarea.rb +5 -0
  68. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  69. data/test/dummy/config/locales/en.yml +23 -0
  70. data/test/dummy/config/puma.rb +47 -0
  71. data/test/dummy/config/routes.rb +5 -0
  72. data/test/dummy/config/secrets.yml +22 -0
  73. data/test/dummy/config/spring.rb +6 -0
  74. data/test/dummy/lib/assets/.keep +0 -0
  75. data/test/dummy/log/.keep +0 -0
  76. data/test/dummy/public/404.html +67 -0
  77. data/test/dummy/public/422.html +67 -0
  78. data/test/dummy/public/500.html +66 -0
  79. data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
  80. data/test/dummy/public/apple-touch-icon.png +0 -0
  81. data/test/dummy/public/favicon.ico +0 -0
  82. data/test/system/workarea/admin/free_shipping_message_system_test.rb +49 -0
  83. data/test/system/workarea/storefront/free_shipping_message_on_cart_system_test.rb +60 -0
  84. data/test/test_helper.rb +14 -0
  85. data/test/view_models/workarea/storefront/cart_view_model_test.rb +56 -0
  86. data/workarea-shipping_message.gemspec +17 -0
  87. metadata +142 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e5e1225408130adc4eb18bf709026998b277db84b1a745e18e2429257bab1938
4
+ data.tar.gz: 82b4faf8d0ec2c646a9abfc8a3019bb37b71f1a251c22db8588ffc664c3996ba
5
+ SHA512:
6
+ metadata.gz: ed38dadb210e1bbd5ce3599cc1c67eff9eceef12098f642399a684dfc4ec1d62436845661c470f9b24d4a1f6fcca0d07d2eb3716138a4c6b81d215e43c2ca072
7
+ data.tar.gz: 3d07b7a90cf5d48abf186f987bc0fce5590ecf4c7a61dec0da66bc7fc8bbf3d9ca5f0506af788dacb75cc76d7c30a9dc1d5bc7bd599809d8fd26627ab2d1c8dd
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.
@@ -0,0 +1,54 @@
1
+ name: CI
2
+ on: [push]
3
+
4
+ jobs:
5
+ static_analysis:
6
+ runs-on: ubuntu-latest
7
+ steps:
8
+ - uses: actions/checkout@v1
9
+ - uses: workarea-commerce/ci/bundler-audit@v1
10
+ - uses: workarea-commerce/ci/rubocop@v1
11
+
12
+ admin_tests:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v1
16
+ - uses: actions/setup-ruby@v1
17
+ with:
18
+ ruby-version: 2.6.x
19
+ - uses: workarea-commerce/ci/test@v1
20
+ with:
21
+ command: bin/rails app:workarea:test:admin
22
+
23
+ core_tests:
24
+ runs-on: ubuntu-latest
25
+ steps:
26
+ - uses: actions/checkout@v1
27
+ - uses: actions/setup-ruby@v1
28
+ with:
29
+ ruby-version: 2.6.x
30
+ - uses: workarea-commerce/ci/test@v1
31
+ with:
32
+ command: bin/rails app:workarea:test:core
33
+
34
+ storefront_tests:
35
+ runs-on: ubuntu-latest
36
+ steps:
37
+ - uses: actions/checkout@v1
38
+ - uses: actions/setup-ruby@v1
39
+ with:
40
+ ruby-version: 2.6.x
41
+ - uses: workarea-commerce/ci/test@v1
42
+ with:
43
+ command: bin/rails app:workarea:test:storefront
44
+
45
+ plugins_tests:
46
+ runs-on: ubuntu-latest
47
+ steps:
48
+ - uses: actions/checkout@v1
49
+ - uses: actions/setup-ruby@v1
50
+ with:
51
+ ruby-version: 2.6.x
52
+ - uses: workarea-commerce/ci/test@v1
53
+ with:
54
+ command: bin/rails app:workarea:test:plugins
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ .bundle/
2
+ Gemfile.lock
3
+ .sass-cache/
4
+ log/*.log
5
+ pkg/
6
+ coverage/
7
+ test/dummy/db/*.sqlite3
8
+ test/dummy/db/*.sqlite3-journal
9
+ test/dummy/log/*.log
10
+ test/dummy/tmp/
11
+ test/dummy/.sass-cache
12
+ test/dummy/public/system
13
+ .DS_Store
data/.rubocop.yml ADDED
@@ -0,0 +1,3 @@
1
+ inherit_from:
2
+ - https://raw.githubusercontent.com/workarea-commerce/workarea/master/.rubocop.yml
3
+
data/CHANGELOG.md ADDED
@@ -0,0 +1,42 @@
1
+ Workarea Shipping Message 1.2.0 (2019-11-26)
2
+ --------------------------------------------------------------------------------
3
+
4
+ * Upgrade for v3.5 compatibility
5
+
6
+ Ben Crouse
7
+
8
+
9
+
10
+ Workarea Shipping Message 1.1.0 (2019-04-16)
11
+ --------------------------------------------------------------------------------
12
+
13
+ * Update for v3.4 compatibility
14
+
15
+ * Update admin pricing_discounts/cards to include metrics card
16
+ * Add minimum version requirement
17
+
18
+ SHIPPNGMSG-6
19
+ Jake Beresford
20
+
21
+
22
+
23
+ Workarea Shipping Message 1.0.0 (2018-03-21)
24
+ --------------------------------------------------------------------------------
25
+
26
+ * Upgrade for v3 compatibility
27
+
28
+ In addition to standard upgrade tasks this plugin was significantly refactored to be more conventional. The implementation was updated with a Discount::Message concern which is extended in Pricing::Discount::Shipping removing the need for a custom settings object and unconventional configuration on the host app. This change should also make it more intuitive to add discount messages to other discount types if necessary. Additional logic would need to be defined to achieve this.
29
+
30
+ * Discount::Message uses {amount} keyword that is gsubbed for the amount delta in the view_model
31
+ * Rename everything, update decorators, change before_filter to before_action
32
+ * Add dotfiles and bamboo dependencies
33
+ * Update cart view model decorator so it works
34
+ * Add translations
35
+ * Move admin UI into discounts UI
36
+ * Convert tests to minitest
37
+
38
+ SHIPPNGMSG-5
39
+ Jake Beresford
40
+
41
+
42
+
@@ -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,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'workarea', git: 'https://github.com/workarea-commerce/workarea.git'
6
+
7
+ group :test do
8
+ gem "simplecov", require: false
9
+ end
data/LICENSE.md ADDED
@@ -0,0 +1,3 @@
1
+ View this plugin's license here:
2
+
3
+ <https://github.com/workarea-commerce/workarea/blob/master/LICENSE.md>
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ Workarea Shipping Message
2
+ ================================================================================
3
+
4
+ Discount messaging plugin for the Workarea platform.
5
+
6
+ Out of the box this plugin adds messaging to the cart to let a customer know how
7
+ close they are to receiving a free shipping discount.
8
+
9
+ The plugin includes seed data that sets up a free shipping discount with message.
10
+
11
+ Configuration
12
+ --------------------------------------------------------------------------------
13
+
14
+ No additional configuration is necessary to use this plugin with free shipping messaging.
15
+
16
+ Other discount types can be configured to allow messaging.
17
+ To configure another discount type for messaging you will need to
18
+
19
+ 1. Decorate the discount type and include Pricing::Discount::Message
20
+ 2. Add a method called discount_message_valid? to the decorated discount type.
21
+ See workarea-shipping-message/app/models/workarea/pricing/discount/shipping.decorator
22
+ for an example.
23
+ 3. Create a new discount that meets the criteria of your discount_message_valid?
24
+ method
25
+ 4. Add a method to render your discount message along with any necessary logic to
26
+ the relevant view_model for where your message will be displayed.
27
+ 5. Call the discount render method in the view where your message will be displayed
28
+
29
+ If you think your new discount message might be a useful addition to this plugin
30
+ please include a member of the plugin team on your pull request or open a PR against
31
+ this plugin.
32
+
33
+ Workarea Platform Documentation
34
+ --------------------------------------------------------------------------------
35
+
36
+ See [https://developer.workarea.com](https://developer.workarea.com) for Workarea platform documentation.
37
+
38
+ Copyright & Licensing
39
+ --------------------------------------------------------------------------------
40
+ Workarea Commerce Platform is released under the [Business Software License](https://github.com/workarea-commerce/workarea/blob/master/LICENSE)
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require "bundler/setup"
4
+ rescue LoadError
5
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
6
+ end
7
+
8
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
9
+ load "rails/tasks/engine.rake"
10
+ load "rails/tasks/statistics.rake"
11
+ load "workarea/changelog.rake"
12
+
13
+ require "rake/testtask"
14
+
15
+ Rake::TestTask.new(:test) do |t|
16
+ t.libs << "lib"
17
+ t.libs << "test"
18
+ t.pattern = "test/**/*_test.rb"
19
+ t.verbose = false
20
+ end
21
+
22
+ task default: :test
23
+
24
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
25
+ require "workarea/shipping_message/version"
26
+
27
+ desc "Release version #{Workarea::ShippingMessage::VERSION} of the gem"
28
+ task :release do
29
+ host = "https://#{ENV['BUNDLE_GEMS__WEBLINC__COM']}@gems.weblinc.com"
30
+
31
+ Rake::Task['workarea:changelog'].execute
32
+ system 'git add CHANGELOG.md'
33
+ system 'git commit -m "Update CHANGELOG"'
34
+ system 'git push origin HEAD'
35
+
36
+ system "git tag -a v#{Workarea::ShippingMessage::VERSION} -m 'Tagging #{Workarea::ShippingMessage::VERSION}'"
37
+ system "git push --tags"
38
+
39
+ system "gem build workarea-shipping_message.gemspec"
40
+ system "gem push workarea-shipping_message-#{Workarea::ShippingMessage::VERSION}.gem --host #{host}"
41
+ system "rm workarea-shipping_message-#{Workarea::ShippingMessage::VERSION}.gem"
42
+ end
@@ -0,0 +1,8 @@
1
+ module Workarea
2
+ decorate Admin::PricingDiscountsController, with: :shipping_message do
3
+ def message
4
+ discount = Pricing::Discount.find(params[:id])
5
+ @discount = Admin::DiscountViewModel.wrap(discount, view_model_options)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,15 @@
1
+ module Workarea
2
+ module Pricing
3
+ class Discount
4
+ module Message
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ field :message, type: String, localize: true
9
+ field :message_active, type: Boolean, default: false
10
+ field :message_applied, type: String, localize: true
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Workarea
2
+ decorate Pricing::Discount::Shipping, with: :discount_message do
3
+ decorated do
4
+ include Pricing::Discount::Message
5
+ end
6
+
7
+ def discount_message_valid?
8
+ order_total? && order_total_operator == :greater_than
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ module Workarea
2
+ class FreeShippingPromoSeeds
3
+ def perform
4
+ puts "Adding free shipping discount with message..."
5
+
6
+ create_shipping_message_discount
7
+ end
8
+
9
+ def create_shipping_message_discount
10
+ shipping_service = Shipping::Service.where(name: "Ground").first || Shipping::Service.all.first
11
+
12
+ discount = Pricing::Discount::Shipping.create!(
13
+ name: "Free Shipping Over $50",
14
+ shipping_service: shipping_service,
15
+ amount: 0.to_m,
16
+ order_total_operator: :greater_than,
17
+ order_total: 50.to_m,
18
+ message_active: true,
19
+ message_applied: "You got FREE SHIPPING!",
20
+ message: "You're only {amount} away from FREE SHIPPING!"
21
+ )
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,49 @@
1
+ module Workarea
2
+ decorate Storefront::CartViewModel, with: 'ShippingMessage' do
3
+ decorated do
4
+ include ActionView::Helpers::NumberHelper
5
+ end
6
+
7
+ def free_shipping_discount
8
+ discount ||= Workarea::Pricing::Discount.where(
9
+ order_total_operator: :greater_than,
10
+ amount: 0.to_m,
11
+ message_active: true
12
+ ).first
13
+
14
+ return nil unless discount.present? && discount.active? && discount.discount_message_valid?
15
+
16
+ discount ||= if shipping.present? && shipping.shipping_service.present?
17
+ shipping.price_adjustments.detect do |discount|
18
+ discount.shipping_service.id == shipping_service.id
19
+ end
20
+ else
21
+ discount
22
+ end
23
+ end
24
+
25
+ def amount_away_from_free_shipping
26
+ discount ||= free_shipping_discount
27
+
28
+ return nil unless discount.present?
29
+
30
+ discount.order_total - subtotal_price
31
+ end
32
+
33
+ def free_shipping_message
34
+ amount_delta ||= amount_away_from_free_shipping
35
+ return nil unless amount_delta.present?
36
+
37
+ if amount_delta > 0
38
+ free_shipping_discount.message.gsub(/{amount}/, number_to_currency(amount_delta))
39
+ else
40
+ free_shipping_discount.message_applied
41
+ end
42
+ end
43
+
44
+ private
45
+ def shipping
46
+ Workarea::Shipping.find_by_order(model.id)
47
+ end
48
+ end
49
+ end