alchemy-solidus 2.4.0 → 2.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b6e92c70519b42d1b2ddd77907a413ee2ac8657b8bf180987d28c9beb12b93d9
4
- data.tar.gz: 8dc7e00168b554f7efb2fbe01e884f269a7112d6feeaa7a63aa62c614271cf1d
3
+ metadata.gz: 78297e4bf371b6cfc4d26faa46417dbcbf165650a64d484f60dac52feae1ebde
4
+ data.tar.gz: 9d985945b0d70a693cef42837edf97791ac4c7b3b38b5df5e5e5c79e21382642
5
5
  SHA512:
6
- metadata.gz: 45edca46563a2713b35b39ddd58e743909b0a72219532087264b6d4eb66aebe1199bd466d5d0833b80a04265106ebfcdc866510ecedc25f272f5a54c25701740
7
- data.tar.gz: 78f94fce34c3689cd843da7a451bbe34e83100bd31c1f85b1f3ea0c761dba578b6b292cd340622917a08d39a8c8e74fed755a9a51ce278f7d1976c30a831dc70
6
+ metadata.gz: 0c1f70ee1697b9dc3aa3fdca9ab58e532a5adbf81c0ed5ddc7f3c1e07033c77717b43815920ca47f9d1a0731792fe69e7185402289a9cb5a4aa99bb4a6ae5d53
7
+ data.tar.gz: 7e5923735790b534b8e780f71a51b3cb4e07c34692a7977bf0accf9abb949406eee23cd4166c839b6d40df62c374832367e2dedef16f11ac4163e84041ec6c50
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  [![Build Status](https://travis-ci.org/AlchemyCMS/alchemy-solidus.svg?branch=master)](https://travis-ci.org/AlchemyCMS/alchemy-solidus)
2
+ [![Gem Version](https://badge.fury.io/rb/alchemy-solidus.svg)](https://badge.fury.io/rb/alchemy-solidus)
2
3
 
3
4
  # Alchemy-Solidus
4
5
 
data/Rakefile CHANGED
@@ -26,3 +26,11 @@ task :test_setup do
26
26
  exit($?.exitstatus) unless $?.success?
27
27
  end
28
28
  end
29
+
30
+ require 'github_changelog_generator/task'
31
+ require 'alchemy/solidus/version'
32
+ GitHubChangelogGenerator::RakeTask.new(:changelog) do |config|
33
+ config.user = 'AlchemyCMS'
34
+ config.project = 'alchemy-solidus'
35
+ config.future_release = "v#{Alchemy::Solidus::VERSION}"
36
+ end
@@ -0,0 +1,3 @@
1
+ //= require alchemy/solidus/admin/product_select
2
+ //= require alchemy/solidus/admin/variant_select
3
+ //= require alchemy/solidus/admin/taxon_select
@@ -0,0 +1,32 @@
1
+ //= require alchemy/solidus/admin/select2_config
2
+
3
+ $.fn.alchemyProductSelect = function(options) {
4
+ var config = Alchemy.Solidus.getSelect2Config(options)
5
+
6
+ this.select2($.extend(true, config, {
7
+ ajax: {
8
+ data: function(term, page) {
9
+ return {
10
+ q: $.extend({
11
+ name_cont: term
12
+ }, options.query_params),
13
+ page: page
14
+ }
15
+ },
16
+ results: function(data, page) {
17
+ return {
18
+ results: data.products.map(function(product) {
19
+ return {
20
+ id: product.id,
21
+ text: product.name
22
+ }
23
+ }),
24
+ more: page * data.per_page < data.total_count
25
+ }
26
+ }
27
+ },
28
+ formatSelection: function(product) {
29
+ return product.text || product.name
30
+ }
31
+ }))
32
+ }
@@ -0,0 +1,24 @@
1
+ Alchemy = window.Alchemy || {}
2
+ Alchemy.Solidus = Alchemy.Solidus || {}
3
+
4
+ Alchemy.Solidus.getSelect2Config = function(options) {
5
+ var headers = {
6
+ 'X-Spree-Token': options.apiToken
7
+ }
8
+
9
+ return {
10
+ placeholder: options.placeholder,
11
+ minimumInputLength: 3,
12
+ initSelection: function(_$el, callback) {
13
+ if (options.initialSelection) {
14
+ callback(options.initialSelection)
15
+ }
16
+ },
17
+ ajax: {
18
+ url: options.baseUrl,
19
+ datatype: 'json',
20
+ quietMillis: 300,
21
+ params: { headers: headers }
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,32 @@
1
+ //= require alchemy/solidus/admin/select2_config
2
+
3
+ $.fn.alchemyTaxonSelect = function(options) {
4
+ var config = Alchemy.Solidus.getSelect2Config(options)
5
+
6
+ this.select2($.extend(true, config, {
7
+ ajax: {
8
+ data: function(term, page) {
9
+ return {
10
+ q: $.extend({
11
+ name_cont: term
12
+ }, options.query_params),
13
+ page: page
14
+ }
15
+ },
16
+ results: function(data, page) {
17
+ return {
18
+ results: data.taxons.map(function(taxon) {
19
+ return {
20
+ id: taxon.id,
21
+ text: taxon.name
22
+ }
23
+ }),
24
+ more: page * data.per_page < data.total_count
25
+ }
26
+ }
27
+ },
28
+ formatSelection: function(taxon) {
29
+ return taxon.text || taxon.name
30
+ }
31
+ }))
32
+ }
@@ -0,0 +1,32 @@
1
+ //= require alchemy/solidus/admin/select2_config
2
+
3
+ $.fn.alchemyVariantSelect = function(options) {
4
+ var config = Alchemy.Solidus.getSelect2Config(options)
5
+
6
+ this.select2($.extend(true, config, {
7
+ ajax: {
8
+ data: function(term, page) {
9
+ return {
10
+ q: $.extend({
11
+ product_name_or_sku_cont: term
12
+ }, options.query_params),
13
+ page: page
14
+ }
15
+ },
16
+ results: function(data, page) {
17
+ return {
18
+ results: data.variants.map(function(variant) {
19
+ return {
20
+ id: variant.id,
21
+ text: variant.frontend_display
22
+ }
23
+ }),
24
+ more: page * data.per_page < data.total_count
25
+ }
26
+ }
27
+ },
28
+ formatSelection: function(variant) {
29
+ return variant.text || variant.frontend_display
30
+ }
31
+ }))
32
+ }
@@ -1,14 +1,28 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Alchemy
2
4
  class EssenceSpreeProduct < ActiveRecord::Base
3
- belongs_to :product, class_name: "Spree::Product", foreign_key: 'spree_product_id'
5
+ PRODUCT_ID = /\A\d+\z/
6
+
7
+ belongs_to :product, class_name: 'Spree::Product',
8
+ optional: true, foreign_key: 'spree_product_id'
4
9
 
5
- acts_as_essence(
6
- ingredient_column: 'spree_product_id',
7
- preview_text_method: 'name'
8
- )
10
+ acts_as_essence(ingredient_column: :product)
11
+
12
+ def ingredient=(product_or_id)
13
+ case product_or_id
14
+ when PRODUCT_ID
15
+ self.spree_product_id = product_or_id
16
+ when Spree::Product
17
+ self.product = product_or_id
18
+ else
19
+ super
20
+ end
21
+ end
9
22
 
10
- def ingredient
11
- product
23
+ def preview_text(_maxlength)
24
+ return unless product
25
+ product.name
12
26
  end
13
27
  end
14
28
  end
@@ -1,14 +1,28 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Alchemy
2
4
  class EssenceSpreeTaxon < ActiveRecord::Base
3
- belongs_to :taxon, class_name: "Spree::Taxon", foreign_key: 'taxon_id'
5
+ TAXON_ID = /\A\d+\z/
6
+
7
+ belongs_to :taxon, class_name: 'Spree::Taxon',
8
+ optional: true, foreign_key: 'taxon_id'
4
9
 
5
- acts_as_essence(
6
- ingredient_column: 'taxon_id',
7
- preview_text_method: 'name'
8
- )
10
+ acts_as_essence(ingredient_column: :taxon)
11
+
12
+ def ingredient=(taxon_or_id)
13
+ case taxon_or_id
14
+ when TAXON_ID
15
+ self.taxon_id = taxon_or_id
16
+ when Spree::Taxon
17
+ self.taxon = taxon_or_id
18
+ else
19
+ super
20
+ end
21
+ end
9
22
 
10
- def ingredient
11
- taxon
23
+ def preview_text(_maxlength)
24
+ return unless taxon
25
+ taxon.name
12
26
  end
13
27
  end
14
28
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Alchemy
4
+ class EssenceSpreeVariant < ActiveRecord::Base
5
+ VARIANT_ID = /\A\d+\z/
6
+
7
+ belongs_to :variant, class_name: 'Spree::Variant', optional: true
8
+
9
+ acts_as_essence(ingredient_column: :variant)
10
+
11
+ def ingredient=(variant_or_id)
12
+ case variant_or_id
13
+ when VARIANT_ID
14
+ self.variant_id = variant_or_id
15
+ when Spree::Variant
16
+ self.variant = variant_or_id
17
+ else
18
+ super
19
+ end
20
+ end
21
+
22
+ def preview_text(_maxlength)
23
+ return unless variant
24
+ variant.descriptive_name
25
+ end
26
+ end
27
+ end
@@ -1,9 +1,24 @@
1
- <div class="content_editor essence_spree_product">
2
- <label><%= render_content_name(content) %></label>
3
- <%= select_tag(
1
+ <div class="content_editor essence_spree_product" id="<%= content.dom_id %>" data-content-id="<%= content.id %>">
2
+ <%= content_label(content) %>
3
+ <%= text_field_tag(
4
4
  content.form_field_name,
5
- options_from_collection_for_select(Spree::Product.not_deleted, :id, :name, content.essence.spree_product_id),
6
- class: ['alchemy_selectbox very_long', html_options[:class]].join(' '),
7
- style: html_options[:style]
5
+ content.essence.spree_product_id,
6
+ id: content.form_field_id,
7
+ class: 'alchemy_selectbox full_width'
8
8
  ) %>
9
9
  </div>
10
+
11
+ <script>
12
+ $('#<%= content.form_field_id %>').alchemyProductSelect({
13
+ placeholder: "<%= Alchemy.t(:search_product, scope: 'solidus') %>",
14
+ apiToken: "<%= current_alchemy_user.spree_api_key %>",
15
+ baseUrl: "<%= spree.api_products_path %>",
16
+ query_params: <%== content.settings[:query_params].to_json %>,
17
+ <% if content.essence.product %>
18
+ initialSelection: {
19
+ id: <%= content.essence.spree_product_id %>,
20
+ text: "<%= content.essence.product.name %>"
21
+ }
22
+ <% end %>
23
+ })
24
+ </script>
@@ -1,15 +1,24 @@
1
- <div class="content_editor essence_spree_taxon essence_select">
1
+ <div class="content_editor essence_spree_taxon" id="<%= content.dom_id %>" data-content-id="<%= content.id %>">
2
2
  <%= content_label(content) %>
3
- <%= select_tag(
3
+ <%= text_field_tag(
4
4
  content.form_field_name,
5
- options_from_collection_for_select(
6
- local_assigns.fetch(:options, {})[:taxons] || Spree::Taxon.all,
7
- :id,
8
- :pretty_name,
9
- content.essence.taxon_id
10
- ),
11
- include_blank: t(".none"),
12
- class: ["alchemy_selectbox", "essence_editor_select", html_options[:class]].join(' '),
13
- style: html_options[:style]
5
+ content.essence.taxon_id,
6
+ id: content.form_field_id,
7
+ class: 'alchemy_selectbox full_width'
14
8
  ) %>
15
9
  </div>
10
+
11
+ <script>
12
+ $('#<%= content.form_field_id %>').alchemyTaxonSelect({
13
+ placeholder: "<%= Alchemy.t(:search_taxon, scope: 'solidus') %>",
14
+ apiToken: "<%= current_alchemy_user.spree_api_key %>",
15
+ baseUrl: "<%= spree.api_taxons_path %>",
16
+ query_params: <%== content.settings[:query_params].to_json %>,
17
+ <% if content.essence.taxon %>
18
+ initialSelection: {
19
+ id: <%= content.essence.taxon_id %>,
20
+ text: "<%= content.essence.taxon.name %>"
21
+ }
22
+ <% end %>
23
+ })
24
+ </script>
@@ -0,0 +1,24 @@
1
+ <div class="content_editor essence_spree_variant" id="<%= content.dom_id %>" data-content-id="<%= content.id %>">
2
+ <%= content_label(content) %>
3
+ <%= text_field_tag(
4
+ content.form_field_name,
5
+ content.essence.variant_id,
6
+ id: content.form_field_id,
7
+ class: 'alchemy_selectbox full_width'
8
+ ) %>
9
+ </div>
10
+
11
+ <script>
12
+ $('#<%= content.form_field_id %>').alchemyVariantSelect({
13
+ placeholder: "<%= Alchemy.t(:search_variant, scope: 'solidus') %>",
14
+ apiToken: "<%= current_alchemy_user.spree_api_key %>",
15
+ baseUrl: "<%= spree.api_variants_path %>",
16
+ query_params: <%== content.settings[:query_params].to_json %>,
17
+ <% if content.essence.variant %>
18
+ initialSelection: {
19
+ id: <%= content.essence.variant_id %>,
20
+ text: "<%= content.essence.variant.name %>"
21
+ }
22
+ <% end %>
23
+ })
24
+ </script>
@@ -1,4 +1,9 @@
1
1
  en:
2
+ alchemy:
3
+ solidus:
4
+ search_variant: Search a variant by name or sku
5
+ search_product: Search a product by name
6
+ search_taxon: Search a taxon by name
2
7
  spree:
3
8
  admin:
4
9
  tab:
@@ -0,0 +1,9 @@
1
+ class CreateAlchemyEssenceSpreeVariants < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :alchemy_essence_spree_variants do |t|
4
+ t.references :variant, null: true, foreign_key: { to_table: Spree::Variant.table_name }
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  module Alchemy
2
2
  module Solidus
3
- VERSION = "2.4.0"
3
+ VERSION = "2.5.0"
4
4
  end
5
5
  end
@@ -131,6 +131,11 @@ module Alchemy
131
131
  end
132
132
  end
133
133
  end
134
+
135
+ def append_assets
136
+ append_file "vendor/assets/javascripts/alchemy/admin/all.js",
137
+ "//= require alchemy/solidus/admin.js"
138
+ end
134
139
  end
135
140
  end
136
141
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alchemy-solidus
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas von Deyen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-09 00:00:00.000000000 Z
11
+ date: 2019-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: alchemy_cms
@@ -112,6 +112,20 @@ dependencies:
112
112
  - - "~>"
113
113
  - !ruby/object:Gem::Version
114
114
  version: '3.7'
115
+ - !ruby/object:Gem::Dependency
116
+ name: shoulda-matchers
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: '4.0'
122
+ type: :development
123
+ prerelease: false
124
+ version_requirements: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - "~>"
127
+ - !ruby/object:Gem::Version
128
+ version: '4.0'
115
129
  - !ruby/object:Gem::Dependency
116
130
  name: capybara
117
131
  requirement: !ruby/object:Gem::Requirement
@@ -168,6 +182,20 @@ dependencies:
168
182
  - - "~>"
169
183
  - !ruby/object:Gem::Version
170
184
  version: '2.7'
185
+ - !ruby/object:Gem::Dependency
186
+ name: github_changelog_generator
187
+ requirement: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ type: :development
193
+ prerelease: false
194
+ version_requirements: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
171
199
  description: A AlchemyCMS and Solidus integration
172
200
  email:
173
201
  - thomas@vondeyen.com
@@ -178,12 +206,20 @@ files:
178
206
  - LICENSE
179
207
  - README.md
180
208
  - Rakefile
209
+ - app/assets/javascripts/alchemy/solidus/admin.js
210
+ - app/assets/javascripts/alchemy/solidus/admin/product_select.js
211
+ - app/assets/javascripts/alchemy/solidus/admin/select2_config.js
212
+ - app/assets/javascripts/alchemy/solidus/admin/taxon_select.js
213
+ - app/assets/javascripts/alchemy/solidus/admin/variant_select.js
181
214
  - app/models/alchemy/essence_spree_product.rb
182
215
  - app/models/alchemy/essence_spree_taxon.rb
216
+ - app/models/alchemy/essence_spree_variant.rb
183
217
  - app/views/alchemy/essences/_essence_spree_product_editor.html.erb
184
218
  - app/views/alchemy/essences/_essence_spree_product_view.html.erb
185
219
  - app/views/alchemy/essences/_essence_spree_taxon_editor.html.erb
186
220
  - app/views/alchemy/essences/_essence_spree_taxon_view.html.erb
221
+ - app/views/alchemy/essences/_essence_spree_variant_editor.html.erb
222
+ - app/views/alchemy/essences/_essence_spree_variant_view.html.erb
187
223
  - app/views/spree/admin/shared/_alchemy_sub_menu.html.erb
188
224
  - config/initializers/alchemy.rb
189
225
  - config/initializers/solidus.rb
@@ -192,6 +228,7 @@ files:
192
228
  - config/locales/en.yml
193
229
  - db/migrate/20120229160509_create_alchemy_essence_spree_products.rb
194
230
  - db/migrate/20131030140218_create_alchemy_essence_spree_taxons.rb
231
+ - db/migrate/20191107135822_create_alchemy_essence_spree_variants.rb
195
232
  - lib/alchemy-solidus.rb
196
233
  - lib/alchemy/solidus/alchemy_in_solidus.rb
197
234
  - lib/alchemy/solidus/alchemy_user_extension.rb