alchemy-solidus 7.5.1 → 7.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -26
  3. data/app/components/alchemy/admin/link_dialog/product_tab.rb +2 -1
  4. data/app/components/alchemy/admin/product_select.rb +14 -4
  5. data/app/components/alchemy/admin/taxon_select.rb +46 -0
  6. data/app/components/alchemy/admin/variant_select.rb +48 -0
  7. data/app/javascript/alchemy_solidus/components/ajax_config.js +10 -0
  8. data/app/javascript/alchemy_solidus/components/product_select.js +56 -27
  9. data/app/javascript/alchemy_solidus/components/taxon_select.js +48 -0
  10. data/app/javascript/alchemy_solidus/components/variant_select.js +79 -0
  11. data/app/javascript/alchemy_solidus.js +2 -0
  12. data/app/jobs/alchemy/solidus/base_job.rb +7 -0
  13. data/app/jobs/alchemy/solidus/invalidate_elements_cache_job.rb +39 -0
  14. data/app/patches/controllers/alchemy/solidus/alchemy_base_controller_patch.rb +22 -0
  15. data/app/patches/controllers/alchemy/solidus/application_controller_patch.rb +19 -0
  16. data/app/patches/controllers/alchemy/solidus/spree_user_confirmations_controller_patch.rb +15 -0
  17. data/app/patches/controllers/alchemy/solidus/spree_user_passwords_controller_patch.rb +15 -0
  18. data/app/patches/controllers/alchemy/solidus/spree_user_registrations_controller_patch.rb +15 -0
  19. data/app/patches/controllers/alchemy/solidus/spree_user_sessions_controller_patch.rb +15 -0
  20. data/app/patches/helpers/alchemy/solidus/alchemy_base_helper_patch.rb +19 -0
  21. data/{lib/alchemy/solidus/alchemy_user_extension.rb → app/patches/models/alchemy/solidus/alchemy_user_patch.rb} +7 -3
  22. data/app/{decorators/models/alchemy/solidus/spree_product_decorator.rb → patches/models/alchemy/solidus/spree_product_patch.rb} +9 -2
  23. data/app/patches/models/alchemy/solidus/spree_taxon_patch.rb +23 -0
  24. data/app/patches/models/alchemy/solidus/spree_user_patch.rb +27 -0
  25. data/app/patches/models/alchemy/solidus/spree_variant_patch.rb +23 -0
  26. data/app/views/alchemy/ingredients/_spree_product_editor.html.erb +10 -21
  27. data/app/views/alchemy/ingredients/_spree_taxon_editor.html.erb +10 -21
  28. data/app/views/alchemy/ingredients/_spree_variant_editor.html.erb +10 -22
  29. data/config/initializers/alchemy.rb +20 -20
  30. data/config/initializers/spree.rb +7 -7
  31. data/lib/alchemy/solidus/engine.rb +17 -16
  32. data/lib/alchemy/solidus/version.rb +1 -1
  33. data/lib/generators/alchemy/solidus/install/install_generator.rb +32 -32
  34. data/lib/patches/backend/controllers/alchemy/solidus/spree_admin_base_controller_patch.rb +25 -0
  35. data/lib/patches/frontend/controllers/alchemy/solidus/spree_store_controller_patch.rb +17 -0
  36. metadata +26 -22
  37. data/app/decorators/models/alchemy/solidus/spree_taxon_decorator.rb +0 -14
  38. data/app/decorators/models/alchemy/solidus/spree_variant_decorator.rb +0 -14
  39. data/app/javascript/alchemy_solidus/product_select.js +0 -37
  40. data/app/javascript/alchemy_solidus/select2_config.js +0 -24
  41. data/app/javascript/alchemy_solidus/taxon_select.js +0 -37
  42. data/app/javascript/alchemy_solidus/variant_select.js +0 -55
  43. data/app/models/alchemy/solidus/touch_alchemy_ingredients.rb +0 -20
  44. data/db/migrate/20120229160509_create_alchemy_essence_spree_products.rb +0 -8
  45. data/db/migrate/20131030140218_create_alchemy_essence_spree_taxons.rb +0 -10
  46. data/db/migrate/20191107135822_create_alchemy_essence_spree_variants.rb +0 -9
  47. data/lib/alchemy/solidus/alchemy_in_solidus.rb +0 -17
  48. data/lib/alchemy/solidus/current_user_helpers.rb +0 -9
  49. data/lib/alchemy/solidus/spree_admin_unauthorized_redirect.rb +0 -9
  50. data/lib/alchemy/solidus/spree_user_extension.rb +0 -21
  51. data/lib/alchemy/solidus/use_solidus_layout.rb +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 286c4a4ae1a6aba7c83ecc17b9f51e06b2e4b3cf7504382970edaed1c4de9ef1
4
- data.tar.gz: fd623314a68027a9a1cd6bcd49067e0891a6342364f140668217f2c3fa339d7c
3
+ metadata.gz: 143befa0b406d415141a772a96b1b8203914f8826ba3bfeab814753525ce9808
4
+ data.tar.gz: ebd5ffbb9ecc0049e43b15e7a685eb7fe0fb729f54702ced9448827811ef02c5
5
5
  SHA512:
6
- metadata.gz: 541d7bda1ff72e631923ab176dcd868c3f5bb16716a6e0eb0592a0749a9fef22f08f043c2b8393e9ce0a6e82ac2fcf919fb9fc5de621ddc452146e22d8045060
7
- data.tar.gz: 3d260407d78557bda063934ac4105ff8f7357a40f0a9b25313608a8a5f256cc7eb2a739eb3775ec924cbd0c3dc9e7765da950936e2fba57ccda68fc7af1272d4
6
+ metadata.gz: e2d5614f2d2279cdd6905bfeef1e396d6d9b4e4913aeb843527f1e0c678dcfde1094e5a9dae7ea7c80d96883999bae0a12e83dcbf85b84d52a36b667d3e179da
7
+ data.tar.gz: 23cab9eee9c6ceb74acf1510edf65386ab57c931c3d0cb226b02c6b37a9bd41c9e104525a75da01431b380d7e7a2290dca1a9b4b7cdce45ab662325814ebb8a9
data/README.md CHANGED
@@ -194,32 +194,6 @@ $ bundle exec rake alchemy:install
194
194
 
195
195
  and follow the on screen instructions.
196
196
 
197
- ### Render Alchemy Content in Solidus Layout
198
-
199
- ~~If you plan to render the Alchemy site in the Solidus layout add the following
200
- to your initializer:~~
201
-
202
- ```ruby
203
- # config/initializers/alchemy.rb
204
- require 'alchemy/solidus/use_solidus_layout'
205
- ```
206
-
207
- **NOTE:** Since v2.5.2 this is done automatically for you. If you upgraded from an older version you can safely remove this from your initializers.
208
-
209
- ### Render Alchemy Content in Solidus views
210
-
211
- ~~If you plan to render Alchemy content in your Solidus views (ie. a global header
212
- or footer section), you need to include the Alchemy view helpers and language
213
- store in your Solidus controllers with the following addition to your
214
- initializer:~~
215
-
216
- ```ruby
217
- # config/initializers/alchemy.rb
218
- require 'alchemy/solidus/alchemy_in_solidus'
219
- ```
220
-
221
- **NOTE:** Since v2.5.2 this is done automatically for you. If you upgraded from an older version you can safely remove this from your initializers.
222
-
223
197
  ### Routing
224
198
 
225
199
  For routing you have a few options.
@@ -47,7 +47,8 @@ module Alchemy
47
47
  select = render self.class.product_select_class.new(
48
48
  current_alchemy_user.spree_api_key,
49
49
  product: product,
50
- url: spree.api_products_path
50
+ url: spree.api_products_path,
51
+ value_attribute: :slug
51
52
  ).with_content(input)
52
53
  content_tag("div", label + select, class: "input select")
53
54
  end
@@ -1,15 +1,19 @@
1
1
  module Alchemy
2
2
  module Admin
3
3
  class ProductSelect < ViewComponent::Base
4
+ VALUE_ATTRIBUTES = %i[id slug].freeze
5
+
4
6
  delegate :spree, to: :helpers
5
7
 
6
- attr_reader :api_key, :product, :url, :query_params
8
+ attr_reader :api_key, :product, :url, :query_params, :placeholder
7
9
 
8
- def initialize(api_key, product: nil, url: nil, query_params: nil)
10
+ def initialize(api_key, product: nil, url: nil, query_params: nil, placeholder: nil, value_attribute: nil)
9
11
  @api_key = api_key
10
12
  @product = product
11
13
  @url = url
12
14
  @query_params = query_params
15
+ @placeholder = placeholder
16
+ @value_attribute = value_attribute
13
17
  end
14
18
 
15
19
  def call
@@ -18,9 +22,15 @@ module Alchemy
18
22
 
19
23
  private
20
24
 
25
+ def value_attribute
26
+ @value_attribute.in?(VALUE_ATTRIBUTES) ? @value_attribute : :id
27
+ end
28
+
21
29
  def attributes
22
30
  attrs = {
31
+ placeholder: placeholder || Alchemy.t(:search_product, scope: "solidus"),
23
32
  url: url || spree.api_products_path,
33
+ "value-attribute": value_attribute,
24
34
  "api-key": api_key
25
35
  }
26
36
 
@@ -35,8 +45,8 @@ module Alchemy
35
45
 
36
46
  def serialized_selection
37
47
  {
38
- name: product.name,
39
- slug: product.slug
48
+ id: product.send(value_attribute),
49
+ name: product.name
40
50
  }.to_json
41
51
  end
42
52
  end
@@ -0,0 +1,46 @@
1
+ module Alchemy
2
+ module Admin
3
+ class TaxonSelect < ViewComponent::Base
4
+ delegate :spree, to: :helpers
5
+
6
+ attr_reader :api_key, :taxon, :url, :query_params, :placeholder
7
+
8
+ def initialize(api_key, taxon: nil, url: nil, query_params: nil, placeholder: nil)
9
+ @api_key = api_key
10
+ @taxon = taxon
11
+ @url = url
12
+ @query_params = query_params
13
+ @placeholder = placeholder
14
+ end
15
+
16
+ def call
17
+ content_tag("alchemy-taxon-select", content, attributes)
18
+ end
19
+
20
+ private
21
+
22
+ def attributes
23
+ attrs = {
24
+ url: url || spree.api_taxons_path,
25
+ placeholder: placeholder || Alchemy.t(:search_taxon, scope: :solidus),
26
+ "api-key": api_key
27
+ }
28
+
29
+ attrs[:"query-params"] = query_params.to_json if query_params
30
+
31
+ if taxon
32
+ attrs[:selection] = serialized_selection
33
+ end
34
+
35
+ attrs
36
+ end
37
+
38
+ def serialized_selection
39
+ {
40
+ id: taxon.id,
41
+ text: taxon.pretty_name
42
+ }.to_json
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,48 @@
1
+ module Alchemy
2
+ module Admin
3
+ class VariantSelect < ViewComponent::Base
4
+ delegate :spree, to: :helpers
5
+
6
+ attr_reader :api_key, :variant, :url, :query_params, :placeholder
7
+
8
+ def initialize(api_key, variant: nil, url: nil, query_params: nil, placeholder: nil)
9
+ @api_key = api_key
10
+ @variant = variant
11
+ @url = url
12
+ @query_params = query_params
13
+ @placeholder = placeholder
14
+ end
15
+
16
+ def call
17
+ content_tag("alchemy-variant-select", content, attributes)
18
+ end
19
+
20
+ private
21
+
22
+ def attributes
23
+ attrs = {
24
+ url: url || spree.api_variants_path,
25
+ placeholder: placeholder || Alchemy.t(:search_variant, scope: :solidus),
26
+ "api-key": api_key
27
+ }
28
+
29
+ attrs[:"query-params"] = query_params.to_json if query_params
30
+
31
+ if variant
32
+ attrs[:selection] = serialized_selection
33
+ end
34
+
35
+ attrs
36
+ end
37
+
38
+ def serialized_selection
39
+ {
40
+ id: variant.id,
41
+ name: variant.name,
42
+ sku: variant.sku,
43
+ options_text: variant.options_text
44
+ }.to_json
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,10 @@
1
+ export default function ajaxConfig(ajaxConfig, apiKey) {
2
+ return {
3
+ ...ajaxConfig,
4
+ params: {
5
+ headers: {
6
+ Authorization: `Bearer ${apiKey}`,
7
+ },
8
+ },
9
+ }
10
+ }
@@ -1,42 +1,71 @@
1
- import "alchemy_solidus/product_select"
2
-
3
- export default class ProductSelect extends HTMLElement {
4
- connectedCallback() {
5
- const input = this.querySelector("#product_link")
6
- input.classList.add("alchemy_selectbox")
7
-
8
- $(input).alchemyProductSelect({
9
- baseUrl: this.url,
10
- apiToken: this.apiToken,
11
- initSelection: this._initSelection.bind(this),
12
- formatResultObject: this._formatResult.bind(this),
13
- })
14
- }
1
+ import { RemoteSelect } from "alchemy_admin/components/remote_select"
2
+ import ajaxConfig from "alchemy_solidus/components/ajax_config"
15
3
 
16
- get url() {
17
- return this.getAttribute("url")
4
+ export default class ProductSelect extends RemoteSelect {
5
+ get ajaxConfig() {
6
+ return ajaxConfig(super.ajaxConfig, this.apiKey)
18
7
  }
19
8
 
20
- get apiToken() {
9
+ get apiKey() {
21
10
  return this.getAttribute("api-key")
22
11
  }
23
12
 
24
- _initSelection(_$el, callback) {
25
- const selection = this.getAttribute("selection")
26
- const product = JSON.parse(selection)
27
- callback(this._formatResult(product))
13
+ get valueAttribute() {
14
+ return this.getAttribute("value-attribute") || "id"
28
15
  }
29
16
 
30
- _formatResult(product) {
17
+ /**
18
+ * Parses server response into select2 results object
19
+ * @param {object} response
20
+ * @returns {object}
21
+ * @private
22
+ */
23
+ _parseResponse(response) {
31
24
  return {
32
- id: `${Spree.mountedAt()}products/${product.slug}`,
33
- text: product.name,
25
+ results: response.products.map((product) => {
26
+ return {
27
+ id: this._parsedValue(product),
28
+ name: product.name,
29
+ }
30
+ }),
31
+ more: response.current_page * response.per_page < response.total_count,
34
32
  }
35
33
  }
36
34
 
37
- _searchQuery(value) {
38
- const slug = value.replace(`${Spree.mountedAt()}products/`, "")
39
- return `q[slug_eq]=${slug}`
35
+ /**
36
+ * The value used for the select send to the server
37
+ * after submitting the form this select is placed in.
38
+ *
39
+ * Note: Returning an url if the `value-attribute` is "slug".
40
+ *
41
+ * @param {object} product
42
+ * @returns {string}
43
+ */
44
+ _parsedValue(product) {
45
+ return this.valueAttribute === "slug"
46
+ ? `${Spree.mountedAt()}products/${product.slug}`
47
+ : product.id
48
+ }
49
+
50
+ /**
51
+ * result which is visible if a product was selected
52
+ * @param {object} product
53
+ * @returns {string}
54
+ * @private
55
+ */
56
+ _renderResult(product) {
57
+ return product.name
58
+ }
59
+
60
+ /**
61
+ * html template for each list entry
62
+ * @param {object} product
63
+ * @param {string} term
64
+ * @returns {string}
65
+ * @private
66
+ */
67
+ _renderListEntry(product, term) {
68
+ return this._hightlightTerm(product.name, term)
40
69
  }
41
70
  }
42
71
 
@@ -0,0 +1,48 @@
1
+ import { RemoteSelect } from "alchemy_admin/components/remote_select"
2
+ import ajaxConfig from "alchemy_solidus/components/ajax_config"
3
+
4
+ export default class TaxonSelect extends RemoteSelect {
5
+ get ajaxConfig() {
6
+ return ajaxConfig(super.ajaxConfig, this.apiKey)
7
+ }
8
+
9
+ get apiKey() {
10
+ return this.getAttribute("api-key")
11
+ }
12
+
13
+ /**
14
+ * Parses server response into select2 results object
15
+ * @param {object} response
16
+ * @returns {object}
17
+ * @private
18
+ */
19
+ _parseResponse(response) {
20
+ return {
21
+ results: response.taxons,
22
+ more: response.current_page * response.per_page < response.total_count,
23
+ }
24
+ }
25
+
26
+ /**
27
+ * result which is visible if a taxon was selected
28
+ * @param {object} taxon
29
+ * @returns {string}
30
+ * @private
31
+ */
32
+ _renderResult(taxon) {
33
+ return taxon.text || taxon.pretty_name
34
+ }
35
+
36
+ /**
37
+ * html template for each list entry
38
+ * @param {object} taxon
39
+ * @param {string} term
40
+ * @returns {string}
41
+ * @private
42
+ */
43
+ _renderListEntry(taxon, term) {
44
+ return this._hightlightTerm(taxon.pretty_name, term)
45
+ }
46
+ }
47
+
48
+ customElements.define("alchemy-taxon-select", TaxonSelect)
@@ -0,0 +1,79 @@
1
+ import { RemoteSelect } from "alchemy_admin/components/remote_select"
2
+ import ajaxConfig from "alchemy_solidus/components/ajax_config"
3
+
4
+ export default class VariantSelect extends RemoteSelect {
5
+ get ajaxConfig() {
6
+ return ajaxConfig(super.ajaxConfig, this.apiKey)
7
+ }
8
+
9
+ get apiKey() {
10
+ return this.getAttribute("api-key")
11
+ }
12
+
13
+ /**
14
+ * Search query send to server from select2
15
+ * @param {string} term
16
+ * @param {number} page
17
+ * @returns {object}
18
+ * @private
19
+ */
20
+ _searchQuery(term, page) {
21
+ return {
22
+ q: {
23
+ product_name_or_sku_cont: term,
24
+ ...JSON.parse(this.queryParams),
25
+ },
26
+ page: page,
27
+ }
28
+ }
29
+
30
+ /**
31
+ * Parses server response into select2 results object
32
+ * @param {object} response
33
+ * @returns {object}
34
+ * @private
35
+ */
36
+ _parseResponse(response) {
37
+ return {
38
+ results: response.variants,
39
+ more: response.current_page * response.per_page < response.total_count,
40
+ }
41
+ }
42
+
43
+ /**
44
+ * result which is visible if a variant was selected
45
+ * @param {object} variant
46
+ * @returns {string}
47
+ * @private
48
+ */
49
+ _renderResult(variant) {
50
+ return variant.options_text
51
+ ? `${variant.name} - ${variant.options_text}`
52
+ : variant.name
53
+ }
54
+
55
+ /**
56
+ * html template for each list entry
57
+ * @param {object} variant
58
+ * @param {string} term
59
+ * @returns {string}
60
+ * @private
61
+ */
62
+ _renderListEntry(variant, term) {
63
+ const name = this._hightlightTerm(variant.name, term)
64
+ const sku = this._hightlightTerm(variant.sku, term)
65
+ return `
66
+ <div class="variant-select-result">
67
+ <div>
68
+ <span>${name}</span>
69
+ </div>
70
+ <div>
71
+ <span>${variant.options_text}</span>
72
+ <span>${sku}</span>
73
+ </div>
74
+ </div>
75
+ `
76
+ }
77
+ }
78
+
79
+ customElements.define("alchemy-variant-select", VariantSelect)
@@ -1 +1,3 @@
1
1
  import "alchemy_solidus/components/product_select"
2
+ import "alchemy_solidus/components/taxon_select"
3
+ import "alchemy_solidus/components/variant_select"
@@ -0,0 +1,7 @@
1
+ module Alchemy
2
+ module Solidus
3
+ class BaseJob < ActiveJob::Base
4
+ retry_on ActiveRecord::Deadlocked
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,39 @@
1
+ module Alchemy
2
+ module Solidus
3
+ class InvalidateElementsCacheJob < BaseJob
4
+ queue_as :default
5
+
6
+ def perform(model_name, id)
7
+ now = Time.current
8
+
9
+ element_ids = model(model_name)
10
+ .where(related_object_id: id)
11
+ .joins(:element)
12
+ .pluck("alchemy_elements.id")
13
+ elements = ::Alchemy::Element.where(id: element_ids)
14
+
15
+ all_element_ids = get_all_element_ids(elements, element_ids)
16
+ ::Alchemy::Element.where(id: all_element_ids.uniq).update_all(updated_at: now)
17
+
18
+ page_ids = elements.joins(page_version: :page).pluck("alchemy_pages.id")
19
+ ::Alchemy::Page.where(id: page_ids.uniq).update_all(updated_at: now)
20
+ end
21
+
22
+ private
23
+
24
+ def get_all_element_ids(elements, element_ids)
25
+ parent_element_ids = elements.pluck(:parent_element_id).compact
26
+ parent_elements = ::Alchemy::Element.distinct.where(id: parent_element_ids)
27
+
28
+ if parent_elements.any?
29
+ element_ids += parent_element_ids
30
+ get_all_element_ids(parent_elements, element_ids)
31
+ else
32
+ element_ids
33
+ end
34
+ end
35
+
36
+ def model(model_name) = "Alchemy::Ingredients::#{model_name}".constantize
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Alchemy
4
+ module Solidus
5
+ module AlchemyBaseControllerPatch
6
+ def self.prepended(base)
7
+ base.include Spree::Core::ControllerHelpers::Auth
8
+ base.include Spree::Core::ControllerHelpers::Common
9
+ base.include Spree::Core::ControllerHelpers::Order
10
+ base.include Spree::Core::ControllerHelpers::PaymentParameters
11
+ base.include Spree::Core::ControllerHelpers::Pricing
12
+ base.include Spree::Core::ControllerHelpers::Search
13
+ base.include Spree::Core::ControllerHelpers::Store
14
+ base.include Spree::Core::ControllerHelpers::StrongParameters
15
+ end
16
+
17
+ if defined?(::Alchemy::BaseController)
18
+ ::Alchemy::BaseController.prepend self
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Alchemy
4
+ module Solidus
5
+ module ApplicationControllerPatch
6
+ def spree_current_user
7
+ if Alchemy.user_class_name == "::Alchemy::User"
8
+ current_user
9
+ else
10
+ super
11
+ end
12
+ end
13
+
14
+ if defined?(::ApplicationController)
15
+ ::ApplicationController.prepend self
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Alchemy
4
+ module Solidus
5
+ module SpreeUserConfirmationsControllerPatch
6
+ def self.prepended(base)
7
+ base.include Alchemy::ControllerActions
8
+ end
9
+
10
+ if defined?(::Spree::UserConfirmationsController)
11
+ ::Spree::UserConfirmationsController.prepend self
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Alchemy
4
+ module Solidus
5
+ module SpreeUserPasswordsControllerPatch
6
+ def self.prepended(base)
7
+ base.include Alchemy::ControllerActions
8
+ end
9
+
10
+ if defined?(::Spree::UserPasswordsController)
11
+ ::Spree::UserPasswordsController.prepend self
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Alchemy
4
+ module Solidus
5
+ module SpreeUserRegistrationsControllerPatch
6
+ def self.prepended(base)
7
+ base.include Alchemy::ControllerActions
8
+ end
9
+
10
+ if defined?(::Spree::UserRegistrationsController)
11
+ ::Spree::UserRegistrationsController.prepend self
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Alchemy
4
+ module Solidus
5
+ module SpreeUserSessionsControllerPatch
6
+ def self.prepended(base)
7
+ base.include Alchemy::ControllerActions
8
+ end
9
+
10
+ if defined?(::Spree::UserSessionsController)
11
+ ::Spree::UserSessionsController.prepend self
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Alchemy
4
+ module Solidus
5
+ module AlchemyBaseHelperPatch
6
+ def self.prepended(base)
7
+ base.include Spree::BaseHelper
8
+ base.include Spree::CheckoutHelper
9
+ base.include Spree::ProductsHelper
10
+ base.include Spree::StoreHelper
11
+ base.include Spree::TaxonsHelper
12
+ end
13
+
14
+ if defined?(::Alchemy::BaseHelper)
15
+ ::Alchemy::BaseHelper.prepend self
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,17 +1,21 @@
1
1
  module Alchemy
2
2
  module Solidus
3
- module AlchemyUserExtension
4
- def self.included(klass)
3
+ module AlchemyUserPatch
4
+ def self.prepended(klass)
5
5
  klass.include Spree::UserMethods
6
6
  end
7
7
 
8
8
  def spree_roles
9
9
  if admin?
10
- ::Spree::Role.where(name: 'admin')
10
+ ::Spree::Role.where(name: "admin")
11
11
  else
12
12
  ::Spree::Role.none
13
13
  end
14
14
  end
15
+
16
+ if defined?(::Alchemy::User)
17
+ ::Alchemy::User.prepend self
18
+ end
15
19
  end
16
20
  end
17
21
  end
@@ -2,9 +2,10 @@
2
2
 
3
3
  module Alchemy
4
4
  module Solidus
5
- module SpreeProductDecorator
5
+ module SpreeProductPatch
6
6
  def self.prepended(base)
7
- base.include Alchemy::Solidus::TouchAlchemyIngredients
7
+ # Solidus runs touch callbacks on product after_save
8
+ base.after_touch :touch_alchemy_ingredients
8
9
  base.has_many :alchemy_ingredients, class_name: "Alchemy::Ingredients::SpreeProduct", as: :related_object, dependent: :nullify
9
10
  end
10
11
 
@@ -23,6 +24,12 @@ module Alchemy
23
24
  taxons.each(&:touch)
24
25
  end
25
26
 
27
+ # Touch all elements that have this product assigned to one of its ingredients.
28
+ # This cascades to all parent elements and pages as well.
29
+ def touch_alchemy_ingredients
30
+ InvalidateElementsCacheJob.perform_later("SpreeProduct", id)
31
+ end
32
+
26
33
  ::Spree::Product.prepend self
27
34
  end
28
35
  end