workarea-inventory_notifications 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +15 -0
  3. data/.eslintrc +24 -0
  4. data/.gitignore +12 -0
  5. data/.jshintrc +31 -0
  6. data/.rubocop.yml +2 -0
  7. data/CHANGELOG.md +99 -0
  8. data/Gemfile +17 -0
  9. data/README.md +65 -0
  10. data/Rakefile +43 -0
  11. data/app/assets/stylesheets/workarea/storefront/inventory_notifications/components/_inventory_notifications.scss +14 -0
  12. data/app/controllers/workarea/storefront/inventory_notifications_controller.rb +30 -0
  13. data/app/mailers/workarea/storefront/inventory_update_mailer.rb +17 -0
  14. data/app/models/workarea/inventory/policies/allow_notify.rb +11 -0
  15. data/app/models/workarea/inventory_notification.rb +23 -0
  16. data/app/view_models/product_view_model.decorator +45 -0
  17. data/app/views/workarea/storefront/inventory_notifications/new.html.haml +19 -0
  18. data/app/views/workarea/storefront/inventory_update_mailer/notify.html.haml +32 -0
  19. data/app/views/workarea/storefront/inventory_update_mailer/notify.text.haml +14 -0
  20. data/app/views/workarea/storefront/products/_inventory_notifications.html.haml +8 -0
  21. data/app/workers/workarea/restock_notifier.rb +27 -0
  22. data/bin/rails +18 -0
  23. data/config/initializers/appends.rb +11 -0
  24. data/config/initializers/inventory_policies.rb +3 -0
  25. data/config/locales/en.yml +22 -0
  26. data/config/routes.rb +10 -0
  27. data/lib/workarea/inventory_notifications/engine.rb +8 -0
  28. data/lib/workarea/inventory_notifications/version.rb +5 -0
  29. data/lib/workarea/inventory_notifications.rb +11 -0
  30. data/lib/workarea/mailer_previews/inventory_update_mailer_preview.rb +12 -0
  31. data/script/admin_ci +9 -0
  32. data/script/ci +11 -0
  33. data/script/core_ci +9 -0
  34. data/script/plugins_ci +9 -0
  35. data/script/storefront_ci +9 -0
  36. data/test/dummy/Rakefile +6 -0
  37. data/test/dummy/app/assets/config/manifest.js +4 -0
  38. data/test/dummy/app/assets/images/.keep +0 -0
  39. data/test/dummy/app/assets/javascripts/application.js +13 -0
  40. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  41. data/test/dummy/app/controllers/application_controller.rb +3 -0
  42. data/test/dummy/app/controllers/concerns/.keep +0 -0
  43. data/test/dummy/app/helpers/application_helper.rb +2 -0
  44. data/test/dummy/app/jobs/application_job.rb +2 -0
  45. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  46. data/test/dummy/app/models/concerns/.keep +0 -0
  47. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  48. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  49. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  50. data/test/dummy/bin/bundle +3 -0
  51. data/test/dummy/bin/rails +4 -0
  52. data/test/dummy/bin/rake +4 -0
  53. data/test/dummy/bin/setup +34 -0
  54. data/test/dummy/bin/update +29 -0
  55. data/test/dummy/config/application.rb +24 -0
  56. data/test/dummy/config/boot.rb +5 -0
  57. data/test/dummy/config/cable.yml +9 -0
  58. data/test/dummy/config/environment.rb +5 -0
  59. data/test/dummy/config/environments/development.rb +54 -0
  60. data/test/dummy/config/environments/production.rb +83 -0
  61. data/test/dummy/config/environments/test.rb +43 -0
  62. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  63. data/test/dummy/config/initializers/assets.rb +11 -0
  64. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  65. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  66. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  67. data/test/dummy/config/initializers/inflections.rb +16 -0
  68. data/test/dummy/config/initializers/mime_types.rb +4 -0
  69. data/test/dummy/config/initializers/session_store.rb +3 -0
  70. data/test/dummy/config/initializers/workarea.rb +5 -0
  71. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  72. data/test/dummy/config/locales/en.yml +23 -0
  73. data/test/dummy/config/puma.rb +47 -0
  74. data/test/dummy/config/routes.rb +5 -0
  75. data/test/dummy/config/secrets.yml +22 -0
  76. data/test/dummy/config.ru +5 -0
  77. data/test/dummy/lib/assets/.keep +0 -0
  78. data/test/dummy/log/.keep +0 -0
  79. data/test/dummy/public/404.html +67 -0
  80. data/test/dummy/public/422.html +67 -0
  81. data/test/dummy/public/500.html +66 -0
  82. data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
  83. data/test/dummy/public/apple-touch-icon.png +0 -0
  84. data/test/dummy/public/favicon.ico +1 -0
  85. data/test/mailers/workarea/storefront/inventory_update_mailer_test.rb +55 -0
  86. data/test/models/workarea/inventory_notification_test.rb +16 -0
  87. data/test/system/workarea/storefront/inventory_notifications_system_test.rb +89 -0
  88. data/test/test_helper.rb +10 -0
  89. data/test/view_models/workarea/storefront/product_view_model_test.decorator +28 -0
  90. data/test/workers/workarea/restock_notifier_test.rb +32 -0
  91. data/workarea-inventory_notifications.gemspec +18 -0
  92. metadata +153 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6ba4d6ca31b9f2266d0c3c0631bd42f697a3fb42985178f069a0384b2c0f4a02
4
+ data.tar.gz: e836462072d65e2343d22b34b44dfefe4a9b57f83a16521e311d3a092221166a
5
+ SHA512:
6
+ metadata.gz: ea57e300a4e529f958e7105826555e5055a4debd215cfb45935299c52184206bb7279c709fec1e0a006ed305479128a5e01e4baefa808333780f767c4ac7c038
7
+ data.tar.gz: a0d89f8e017a97f9ad5d91a24c39ebe7a77ea574a0f0fd5595cc674eab08a2663b0c8ce94637dc09c954af776803a559ccbfdd44b506c5085bb570e74928aa46
data/.editorconfig ADDED
@@ -0,0 +1,15 @@
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,*.scss}]
12
+ indent_size = 2
13
+
14
+ [{*.js,*.jst,*.ejs}]
15
+ indent_size = 4
data/.eslintrc ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "extends": "eslint:recommended",
3
+ "rules": {
4
+ "semi": [1, "always"]
5
+ },
6
+ "globals": {
7
+ "window": true,
8
+ "document": true,
9
+ "WORKAREA": true,
10
+ "$": true,
11
+ "jQuery": true,
12
+ "_": true,
13
+ "feature": true,
14
+ "JST": true,
15
+ "Turbolinks": true,
16
+ "I18n": true,
17
+ "Chart": true,
18
+ "Dropzone": true,
19
+ "strftime": true,
20
+ "Waypoint": true,
21
+ "wysihtml": true,
22
+ "LocalTime": true,
23
+ }
24
+ }
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ .DS_Store
2
+ .bundle/
3
+ Gemfile.lock
4
+ .sass-cache/
5
+ log/*.log
6
+ pkg/
7
+ coverage/
8
+ test/dummy/public/system/*
9
+ test/dummy/db/*.sqlite3
10
+ test/dummy/log/*.log
11
+ test/dummy/tmp/
12
+ test/dummy/.sass-cache
data/.jshintrc ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "bitwise": true,
3
+ "camelcase": false,
4
+ "curly": true,
5
+ "eqeqeq": true,
6
+ "forin": true,
7
+ "immed": true,
8
+ "indent": 4,
9
+ "latedef": true,
10
+ "newcap": true,
11
+ "noarg": true,
12
+ "noempty": true,
13
+ "nonew": true,
14
+ "plusplus": true,
15
+ "quotmark": true,
16
+ "undef": true,
17
+ "unused": true,
18
+ "strict": true,
19
+ "trailing": true,
20
+ "browser": true,
21
+ "jquery": true,
22
+ "onevar": true,
23
+ "white": true,
24
+ "globals": {
25
+ "_": false,
26
+ "_gaq": false,
27
+ "JST": false,
28
+ "Modernizr": false,
29
+ "WEBLINC": false
30
+ }
31
+ }
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ inherit_gem:
2
+ workarea-ci: rubocop.yml
data/CHANGELOG.md ADDED
@@ -0,0 +1,99 @@
1
+ Workarea Inventory Notifications 2.1.2 (2019-08-21)
2
+ --------------------------------------------------------------------------------
3
+
4
+ * Open Source!
5
+
6
+
7
+
8
+ Workarea Inventory Notifications 2.1.1 (2019-03-05)
9
+ --------------------------------------------------------------------------------
10
+
11
+ * INVENNOTIF-19: Remove unused view
12
+
13
+ Andy Sides
14
+
15
+
16
+
17
+ Workarea Inventory Notifications 2.1.0 (2019-02-05)
18
+ --------------------------------------------------------------------------------
19
+
20
+ * Update test to be decorated
21
+
22
+ Update Storefront::ProductViewModelTest and require Workarea >= 3.3.0
23
+
24
+ INVENNOTIF-18
25
+ Andy Sides
26
+
27
+
28
+
29
+ Workarea Inventory Notifications 2.0.2 (2019-02-05)
30
+ --------------------------------------------------------------------------------
31
+
32
+ * INVENNOTIF-17: Fix system test file name and location
33
+
34
+ Andy Sides
35
+
36
+
37
+
38
+ Workarea Inventory Notifications 2.0.1 (2019-01-08)
39
+ --------------------------------------------------------------------------------
40
+
41
+ * Fix displaying notification on option set product templates
42
+
43
+ Fixes a bug around the notification link on the option selects or option
44
+ thumbnails product templates
45
+
46
+ INVENNOTIF-15
47
+ Andy Sides
48
+
49
+ * Fix failing tests
50
+
51
+ Update tests to use correct syntax for specifying inventory
52
+ policy and to temporarily adjust Workarea.config.send_email
53
+ when testing email sends.
54
+
55
+ INVENNOTIF-14
56
+ gharnly
57
+
58
+
59
+
60
+ Workarea Inventory Notifications 2.0.0 (2017-05-26)
61
+ --------------------------------------------------------------------------------
62
+
63
+ * Fix bug where inventory notification is displayed before sku is selected
64
+
65
+ Have to use sku from options, rather than current_sku to determine
66
+ whether the current_sku_available? This is because current_sku will
67
+ default to the first sku if no sku is selected.
68
+
69
+ INVENNOTIF-10
70
+ Beresford, Jake
71
+
72
+ * Upgrade for v3
73
+
74
+ * Added new inventory policy AllowNotify for notifications
75
+ * Change logic for unavailable skus in the view model to be specific to current_sku
76
+ * Update UI to show inventory notification link if sku is unavailable
77
+ * rename everything
78
+ * Update decorators to .decorator files
79
+ * Update dependencies
80
+ * Remove JS module that was specific to clothing template
81
+ * Remove add_form controller action, this is now redundant as JS module for clothing was removed
82
+ * storefront translations
83
+ * Update appends and move to initializer
84
+ * Combine listener and worker
85
+ * use ApplicationDocument in model and add index to sku
86
+ * remove unused view models
87
+ * Convert mailer templates to haml and add translations
88
+ * Convert Rspec to minitest
89
+ * Update .gitignore for minitest
90
+ * Install rubocop and clean up code styles
91
+
92
+ INVENNOTIF-9
93
+ Beresford, Jake
94
+
95
+ * INVENNOTIF-7: Add product image to inventory mailer view
96
+ Beresford, Jake
97
+
98
+
99
+
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+ source 'https://gems.weblinc.com'
3
+
4
+ # Declare your gem's dependencies in api.gemspec.
5
+ # Bundler will treat runtime dependencies like base dependencies, and
6
+ # development dependencies will be added by default to the :development group.
7
+ gemspec
8
+
9
+ # Declare any dependencies that are still in development here instead of in
10
+ # your gemspec. These might include edge Rails or gems from your path or
11
+ # Git. Remember to move these dependencies to your gemspec before releasing
12
+ # your gem to rubygems.org.
13
+
14
+ # To use debugger
15
+ # gem 'debugger'
16
+
17
+ gem "workarea", source: 'https://gems.weblinc.com'
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ Workarea Inventory Notifications
2
+ ================================================================================
3
+
4
+ Plugin to add back in stock notifications to the storefront.
5
+
6
+ If a product is out of stock, and has the 'allow notify' inventory policy, consumers will see a link
7
+ to request a back in stock notification.
8
+
9
+ When the Inventory::Sku save method is called the restock_notifier checks if the sku is
10
+ now purchasable, checks for unsent inventory notifications on that sku, and sends the mailer.
11
+
12
+ The notify inventory policy behaves the same ways as Inventory::Policy::Standard except
13
+ it will always display a product, even when it is out of stock.
14
+
15
+
16
+ Compatibility with workarea-clothing
17
+ --------------------------------------------------------------------------------
18
+
19
+ Due to changes in how Clothing works, as of workarea v3, the inventory notifications gem
20
+ is only compatible with Clothing >= v2.1.0.
21
+
22
+
23
+ Getting Started
24
+ --------------------------------------------------------------------------------
25
+
26
+ This gem contains a rails engine that must be mounted onto a host Rails application.
27
+
28
+ You must have access to a WebLinc gems server to use this gem. Add your gems server credentials to Bundler:
29
+
30
+ bundle config gems.weblinc.com my_username:my_password
31
+
32
+ Or set the appropriate environment variable in a shell startup file:
33
+
34
+ export BUNDLE_GEMS__WEBLINC__COM='my_username:my_password'
35
+
36
+ Then add the gem to your application's Gemfile specifying the source:
37
+
38
+ # ...
39
+ gem 'workarea-inventory_notifications', source: 'https://gems.weblinc.com'
40
+ # ...
41
+
42
+ Or use a source block:
43
+
44
+ # ...
45
+ source 'https://gems.weblinc.com' do
46
+ gem 'workarea-inventory_notifications'
47
+ end
48
+ # ...
49
+
50
+ Update your application's bundle.
51
+
52
+ cd path/to/application
53
+ bundle
54
+
55
+ Workarea Platform Documentation
56
+ --------------------------------------------------------------------------------
57
+
58
+ See [http://developer.weblinc.com](http://developer.weblinc.com) for Workarea platform documentation.
59
+
60
+ Copyright & Licensing
61
+ --------------------------------------------------------------------------------
62
+
63
+ Copyright WebLinc 2017. All rights reserved.
64
+
65
+ For licensing, contact sales@workarea.com.
data/Rakefile ADDED
@@ -0,0 +1,43 @@
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/inventory_notifications/version'
26
+
27
+ desc "Release version #{Workarea::InventoryNotifications::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::InventoryNotifications::VERSION} -m 'Tagging #{Workarea::InventoryNotifications::VERSION}'"
37
+ system 'git push --tags'
38
+
39
+ system 'gem build workarea-inventory_notifications.gemspec'
40
+ system "gem push workarea-inventory_notifications-#{Workarea::InventoryNotifications::VERSION}.gem"
41
+ system "gem push workarea-inventory_notifications-#{Workarea::InventoryNotifications::VERSION}.gem --host #{host}"
42
+ system "rm workarea-inventory_notifications-#{Workarea::InventoryNotifications::VERSION}.gem"
43
+ end
@@ -0,0 +1,14 @@
1
+ /*------------------------------------*\
2
+ #INVENTORY-NOTIFICATIONS
3
+ \*------------------------------------*/
4
+
5
+
6
+ .inventory-notifications {}
7
+
8
+ .inventory-notifications__signup {
9
+ display: none;
10
+
11
+ .js & {
12
+ display: block;
13
+ }
14
+ }
@@ -0,0 +1,30 @@
1
+ module Workarea
2
+ class Storefront::InventoryNotificationsController < Storefront::ApplicationController
3
+ before_action :set_product
4
+
5
+ def new; end
6
+
7
+ def create
8
+ @notification = InventoryNotification.new(notification_params)
9
+
10
+ if @notification.save
11
+ flash[:success] = t('workarea.storefront.inventory_notifications.flash_messages.saved')
12
+ redirect_to storefront.product_path(@product)
13
+ else
14
+ flash[:error] = t('workarea.storefront.inventory_notifications.flash_messages.error')
15
+ render :new
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def set_product
22
+ model = Catalog::Product.find_by(slug: params[:product_id])
23
+ @product = Storefront::ProductViewModel.wrap(model, view_model_options)
24
+ end
25
+
26
+ def notification_params
27
+ params[:notification].permit(:product_id, :sku, :email)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,17 @@
1
+ module Workarea
2
+ class Storefront::InventoryUpdateMailer < Storefront::ApplicationMailer
3
+ def notify(product_id, sku, email)
4
+ product = Catalog::Product.find(product_id)
5
+ @product = Storefront::ProductViewModel.wrap(product, sku: sku)
6
+ @variant = product.variants.where(sku: sku).first
7
+
8
+ mail(to: email, from: Workarea.config.email_from, subject: subject)
9
+ end
10
+
11
+ private
12
+
13
+ def subject
14
+ I18n.t('workarea.storefront.restock_mailer.subject')
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ module Workarea
2
+ module Inventory
3
+ module Policies
4
+ class AllowNotify < Standard
5
+ def displayable?
6
+ true
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ module Workarea
2
+ class InventoryNotification
3
+ include ApplicationDocument
4
+
5
+ field :product_id, type: String
6
+ field :sku, type: String
7
+ field :email, type: String
8
+ field :sent_at, type: DateTime
9
+
10
+ validates :product_id, presence: true
11
+ validates :sku, presence: true
12
+ validates :email, presence: true,
13
+ email: true
14
+
15
+ index(sku: 1)
16
+
17
+ scope :unsent, -> { where(sent_at: nil) }
18
+
19
+ def mark_as_sent!
20
+ update_attributes(sent_at: Time.now)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,45 @@
1
+ module Workarea
2
+ decorate(Storefront::ProductViewModel, with: :inventory_notifications) do
3
+
4
+ def unavailable_sku_options
5
+ @unavailable_sku_options ||= format_variant_options(unavailable_skus)
6
+ end
7
+
8
+ def unavailable_skus
9
+ @unavailable_skus ||= variants.select do |variant|
10
+ !inventory.for_sku(variant.sku).purchasable?
11
+ end
12
+ end
13
+
14
+ def current_sku_unavailable?
15
+ unavailable_skus.any? { |sku| sku.sku == current_sku }
16
+ end
17
+
18
+ def purchasable?
19
+ super && !current_sku_unavailable?
20
+ end
21
+
22
+ private
23
+
24
+ def format_variant_options variants
25
+ variant_options = variants.map do |variant|
26
+ text = if variant.details.blank?
27
+ variant.sku
28
+ else
29
+ sku = variant.sku
30
+ details = variant.details.map do |k, v|
31
+ "#{k.titleize}: #{[v].flatten.join(', ')}"
32
+ end.join(", ")
33
+ "#{sku} - #{details}"
34
+ end
35
+ [ text, variant.sku ]
36
+ end
37
+
38
+ if variant_options.one?
39
+ variant_options
40
+ else
41
+ [['Please select options', nil ]] + variant_options
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,19 @@
1
+ - @title = t('workarea.storefront.inventory_notifications.new.title', product: @product.browser_title)
2
+
3
+ .signup-notification.view
4
+
5
+ %h1= t('workarea.storefront.inventory_notifications.new.title', product: @product.browser_title)
6
+
7
+ = form_tag create_product_inventory_notification_path(@product), method: 'post', id: 'inventory_notification_form' do
8
+
9
+ %p= t('workarea.storefront.inventory_notifications.new.instruction')
10
+
11
+ = hidden_field_tag "notification[product_id]", @product.id
12
+ .property
13
+ = label_tag "notification_sku", t('workarea.storefront.inventory_notifications.new.select_options'), class: 'property__name'
14
+ .value= select_tag "notification[sku]", options_for_select(@product.unavailable_sku_options, params.fetch(:notification, {})[:sku]), required: true
15
+ .property
16
+ = label_tag "notification_email", t('workarea.admin.fields.email'), class: 'property__name'
17
+ .value= email_field_tag "notification[email]", current_user.try(:email), class: 'text-box', required: true, placeholder: t('workarea.storefront.forms.email_placeholder')
18
+
19
+ %p.add-to-notify-action= button_tag t('workarea.storefront.inventory_notifications.notify_me'), value: 'add_notification', class: 'button button--large'
@@ -0,0 +1,32 @@
1
+ %tr
2
+ %td{ :colspan => "3", :valign => "top" }
3
+ %table{ :border => "0", :cellpadding => "10", :cellspacing => "0", :width => "100%" }
4
+ %tr
5
+ %td{ :valign => "top" }
6
+ %h1{ :style => "margin: 0 0 6px; font: bold 20px arial; color: #{@config.heading_color};" }
7
+ = t('workarea.storefront.restock_mailer.heading', product_name: @product.name)
8
+ %p{ :style => "margin: 0 0 6px; font: 13px/1.5 arial; color: #{@config.text_color};" }
9
+ = t('workarea.storefront.restock_mailer.message')
10
+ %tr
11
+ %td{ :colspan => "3" }
12
+ %table{ :border => "0", :cellpadding => "10", :cellspacing => "0", :style => "color: #{@config.text_color}; font: 13px/1.5 arial; text-align: left; border-collapse: collapse;", :width => "600" }
13
+ %tbody
14
+ %tr
15
+ %td{ :style => "border: 1px solid #{@config.table_border_color};", :width => "150" }
16
+ %table{ :border => "0", :cellpadding => "10", :cellspacing => "0", :style => "color: #{@config.text_color}; font: 13px/1.5 arial; text-align: left; border-collapse: collapse;", :width => "200" }
17
+ %tr
18
+ %td
19
+ = link_to product_url(@product) do
20
+ = image_tag(product_image_url(@product.primary_image, :medium_thumb), alt: @product.name)
21
+ %td{ :style => "border: 1px solid #{@config.table_border_color};", :width => "450" }
22
+ %p{ :style => "margin: 0 0 6px; font: 13px/1.5 arial; color: #{@config.text_color};" }
23
+ %a{ :href => "#{storefront.product_url(@product, sku: @variant.sku)}", :style => "color: #{@link_color};", :target => "_blank" }
24
+ = @product.name
25
+ %p{ :style => "margin: 0 0 6px; font: 13px/1.5 arial; color: #{@config.text_color};" }
26
+ = @variant.name
27
+ - @variant.details.each do |name, value|
28
+ %p{ :style => "margin: 0 0 6px; font: 13px/1.5 arial; color: #{@config.text_color};" }
29
+ %strong
30
+ = name.titleize
31
+ \:
32
+ = value.first
@@ -0,0 +1,14 @@
1
+ = t('workarea.storefront.restock_mailer.heading', product_name: @product.name)
2
+ \===========================================
3
+
4
+ = "\r\n"
5
+
6
+ = t('workarea.storefront.restock_mailer.message')
7
+ = product_url(@product)
8
+
9
+ = "\r\n"
10
+
11
+ = t('workarea.storefront.restock_mailer.product')
12
+ \=======
13
+ = @product.name
14
+ \- #{@variant.sku}
@@ -0,0 +1,8 @@
1
+ - if product.current_sku_unavailable?
2
+ #inventory_notifications.inventory-notifications
3
+ .inventory-notifications__signup
4
+ %p
5
+ %strong= t('workarea.storefront.products.this_item_is_out_of_stock')
6
+ %p
7
+ = t('workarea.storefront.products.inventory_notification_prompt')
8
+ = link_to t('workarea.storefront.products.sign_up_for_email_notification'), storefront.new_product_inventory_notification_path(product), data: { dialog_button: '' }
@@ -0,0 +1,27 @@
1
+ module Workarea
2
+ class RestockNotifier
3
+ include Sidekiq::Worker
4
+ include Sidekiq::CallbacksWorker
5
+
6
+ sidekiq_options(
7
+ enqueue_on: { Inventory::Sku => :save },
8
+ queue: 'low',
9
+ retry: false
10
+ )
11
+
12
+ def perform(id)
13
+ sku = Inventory::Sku.find(id)
14
+
15
+ return unless sku.purchasable?
16
+
17
+ InventoryNotification.unsent.where(sku: sku.id).each do |notification|
18
+ send_notification(notification);
19
+ end
20
+ end
21
+
22
+ def send_notification(notification)
23
+ attrs = notification.attributes.values_at('product_id', 'sku', 'email')
24
+ notification.mark_as_sent! if Storefront::InventoryUpdateMailer.notify(*attrs).deliver
25
+ end
26
+ end
27
+ end
data/bin/rails ADDED
@@ -0,0 +1,18 @@
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('../..', __FILE__)
6
+ ENGINE_PATH = File.expand_path('../../lib/inventory_notifications/engine', __FILE__)
7
+
8
+ # Set up gems listed in the Gemfile.
9
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
10
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
11
+
12
+ require 'action_controller/railtie'
13
+ require 'action_view/railtie'
14
+ require 'action_mailer/railtie'
15
+ require 'rails/test_unit/railtie'
16
+ require 'sprockets/railtie'
17
+
18
+ require 'rails/engine/commands'
@@ -0,0 +1,11 @@
1
+ module Workarea
2
+ Plugin.append_partials(
3
+ 'storefront.product_details',
4
+ 'workarea/storefront/products/inventory_notifications'
5
+ )
6
+
7
+ Plugin.append_stylesheets(
8
+ 'storefront.components',
9
+ 'workarea/storefront/inventory_notifications/components/inventory_notifications'
10
+ )
11
+ end
@@ -0,0 +1,3 @@
1
+ Workarea.configure do |config|
2
+ config.inventory_policies.insert(-1, 'Workarea::Inventory::Policies::AllowNotify')
3
+ end
@@ -0,0 +1,22 @@
1
+ en:
2
+ workarea:
3
+ storefront:
4
+ inventory_notifications:
5
+ flash_messages:
6
+ saved: You will be notified when this item becomes available.
7
+ error: Notification sign up failed. Please try again.
8
+ new:
9
+ instruction: To receive a notification of when the item comes back in stock, select an option and enter your email address below
10
+ select_options: Select options
11
+ title: "Sign up to be notified when %{product} comes back in stock"
12
+ notify_me: Notify Me
13
+ products:
14
+ this_item_is_out_of_stock: This item is out of stock.
15
+ inventory_notification_prompt: To receive a notification of when the item comes back in stock
16
+ enter_email_address_below: enter your email address below.
17
+ sign_up_for_email_notification: sign up for an email notification
18
+ restock_mailer:
19
+ heading: "%{product_name} is back in stock."
20
+ message: Get yours today!
21
+ product: Product
22
+ subject: Product back in stock
data/config/routes.rb ADDED
@@ -0,0 +1,10 @@
1
+ # Add routes for your plugin, like so:
2
+ #
3
+ # Workarea::Admin::Engine.routes.draw do
4
+ # resources :inventory_notifications
5
+ # end
6
+ #
7
+ Workarea::Storefront::Engine.routes.draw do
8
+ get 'inventory_notifications/:product_id/new' => 'inventory_notifications#new', as: :new_product_inventory_notification
9
+ post 'inventory_notifications/:product_id' => 'inventory_notifications#create', as: :create_product_inventory_notification
10
+ end
@@ -0,0 +1,8 @@
1
+ module Workarea
2
+ module InventoryNotifications
3
+ class Engine < ::Rails::Engine
4
+ include Workarea::Plugin
5
+ isolate_namespace Workarea::InventoryNotifications
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Workarea
2
+ module InventoryNotifications
3
+ VERSION = '2.1.2'
4
+ end
5
+ end