stall 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +60 -23
  3. data/app/assets/javascripts/para/stall.coffee +1 -0
  4. data/app/assets/javascripts/para/stall/inputs/variant-select.coffee +62 -0
  5. data/app/assets/javascripts/para/stall/inputs/variants-matrix.coffee +12 -0
  6. data/app/assets/javascripts/para/stall/inputs/variants-matrix/helpers.coffee +40 -0
  7. data/app/assets/javascripts/para/stall/inputs/variants-matrix/input.coffee +133 -0
  8. data/app/assets/javascripts/para/stall/inputs/variants-matrix/nested-fields.coffee +38 -0
  9. data/app/assets/javascripts/para/stall/inputs/variants-matrix/properties_select.coffee +45 -0
  10. data/app/assets/javascripts/para/stall/inputs/variants-matrix/variant.coffee +59 -0
  11. data/app/assets/javascripts/stall.coffee +1 -0
  12. data/app/assets/javascripts/stall/add-to-cart-form.coffee +53 -28
  13. data/app/assets/javascripts/stall/cart-form.coffee +7 -2
  14. data/app/assets/stylesheets/para/stall.sass +28 -0
  15. data/app/controllers/para/stall/admin/carts_controller.rb +27 -0
  16. data/app/controllers/stall/cart_credits_controller.rb +27 -0
  17. data/app/controllers/stall/carts_controller.rb +1 -1
  18. data/app/controllers/stall/checkout/steps_controller.rb +22 -12
  19. data/app/controllers/stall/checkouts_controller.rb +1 -0
  20. data/app/controllers/stall/line_items_controller.rb +1 -0
  21. data/app/controllers/stall/payments_controller.rb +16 -1
  22. data/app/helpers/stall/credit_notes_helper.rb +25 -0
  23. data/app/helpers/stall/customers_helper.rb +3 -1
  24. data/app/models/billing_address.rb +2 -0
  25. data/app/models/cart_credit_note_adjustment.rb +3 -0
  26. data/app/models/credit_note.rb +3 -0
  27. data/app/models/credit_note_adjustment.rb +3 -0
  28. data/app/models/credit_note_usage.rb +3 -0
  29. data/app/models/product.rb +3 -0
  30. data/app/models/product_category.rb +3 -0
  31. data/app/models/product_detail.rb +3 -0
  32. data/app/models/property.rb +3 -0
  33. data/app/models/property_value.rb +3 -0
  34. data/app/models/shipping_address.rb +2 -0
  35. data/app/models/stall/models/address.rb +2 -2
  36. data/app/models/stall/models/cart.rb +2 -15
  37. data/app/models/stall/models/cart_credit_note_adjustment.rb +11 -0
  38. data/app/models/stall/models/credit_note.rb +50 -0
  39. data/app/models/stall/models/credit_note_adjustment.rb +13 -0
  40. data/app/models/stall/models/credit_note_usage.rb +16 -0
  41. data/app/models/stall/models/customer.rb +20 -8
  42. data/app/models/stall/models/line_item.rb +9 -0
  43. data/app/models/stall/models/product.rb +45 -0
  44. data/app/models/stall/models/product_category.rb +31 -0
  45. data/app/models/stall/models/product_detail.rb +17 -0
  46. data/app/models/stall/models/product_list.rb +9 -45
  47. data/app/models/stall/models/property.rb +20 -0
  48. data/app/models/stall/models/property_value.rb +23 -0
  49. data/app/models/stall/models/variant.rb +34 -0
  50. data/app/models/stall/models/variant_property_value.rb +18 -0
  51. data/app/models/variant.rb +3 -0
  52. data/app/models/variant_property_value.rb +3 -0
  53. data/app/services/stall/cart_credit_note_creation_service.rb +40 -0
  54. data/app/services/stall/cart_payment_validation_service.rb +28 -0
  55. data/app/services/stall/cart_update_service.rb +17 -6
  56. data/app/services/stall/credit_usage_service.rb +102 -0
  57. data/app/services/stall/payment_notification_service.rb +4 -8
  58. data/app/services/stall/product_list_staleness_handling_service.rb +33 -0
  59. data/app/views/admin/addresses/_fields.html.haml +9 -0
  60. data/app/views/admin/carts/_filters.html.haml +17 -0
  61. data/app/views/admin/carts/_form.html.haml +43 -0
  62. data/app/views/admin/carts/_table.html.haml +17 -0
  63. data/app/views/admin/customers/_fields.html.haml +1 -0
  64. data/app/views/admin/line_items/_fields.html.haml +15 -0
  65. data/app/views/admin/products/_table.html.haml +12 -0
  66. data/app/views/admin/properties/_form.html.haml +6 -0
  67. data/app/views/admin/properties/_table.html.haml +8 -0
  68. data/app/views/admin/property_values/_fields.html.haml +1 -0
  69. data/app/views/admin/shipments/_fields.html.haml +7 -0
  70. data/app/views/checkout/steps/_informations.html.haml +3 -1
  71. data/app/views/checkout/steps/_payment.html.haml +2 -0
  72. data/app/views/checkout/steps/_payment_return.html.haml +0 -1
  73. data/app/views/para/admin/resources/_variant_row.html.haml +24 -0
  74. data/app/views/para/stall/inputs/_variant_select.html.haml +14 -0
  75. data/app/views/para/stall/inputs/_variants_matrix.html.haml +41 -0
  76. data/app/views/stall/addresses/_fields.html.haml +6 -12
  77. data/app/views/stall/carts/_cart.html.haml +45 -37
  78. data/app/views/stall/carts/_widget.html.haml +28 -0
  79. data/app/views/stall/carts/show.html.haml +2 -0
  80. data/app/views/stall/checkout/steps/_navigation.html.haml +13 -0
  81. data/app/views/stall/credit_note_adjustments/_form.html.haml +28 -0
  82. data/app/views/stall/line_items/_added.html.haml +2 -2
  83. data/app/views/stall/line_items/_form.html.haml +1 -1
  84. data/app/views/stall/payments/manual_payment_gateway/_form.html.haml +10 -0
  85. data/app/views/stall/shared/mailers/_cart.html.haml +1 -1
  86. data/config/locales/stall.fr.yml +82 -2
  87. data/db/migrate/20161129101956_add_type_to_stall_address_ownerships.rb +52 -0
  88. data/db/migrate/20161202080218_add_reference_to_product_lists.rb +17 -0
  89. data/db/migrate/20170118103916_create_credit_notes.rb +17 -0
  90. data/db/migrate/20170118144047_create_credit_note_adjustments.rb +13 -0
  91. data/db/migrate/20170123123115_create_stall_product_categories.rb +12 -0
  92. data/db/migrate/20170123123326_create_stall_products.rb +17 -0
  93. data/db/migrate/20170123125030_create_stall_variants.rb +13 -0
  94. data/db/migrate/20170123131748_create_stall_product_category_hierarchies.rb +16 -0
  95. data/db/migrate/20170123143704_create_stall_product_details.rb +14 -0
  96. data/db/migrate/20170125152622_convert_all_money_fields_to_decimal_to_use_infinite_precision.rb +27 -0
  97. data/db/migrate/20170131162537_add_data_to_stall_adjustments.rb +5 -0
  98. data/db/migrate/20170202165514_create_stall_properties.rb +9 -0
  99. data/db/migrate/20170202165516_create_stall_property_values.rb +13 -0
  100. data/db/migrate/20170202165518_create_stall_variant_property_values.rb +13 -0
  101. data/lib/generators/stall/install/templates/initializer.rb +21 -0
  102. data/lib/generators/stall/view/view_generator.rb +41 -19
  103. data/lib/para/stall.rb +32 -0
  104. data/lib/para/stall/inputs.rb +13 -0
  105. data/lib/para/stall/inputs/variant_input_helper.rb +34 -0
  106. data/lib/para/stall/inputs/variant_select_input.rb +79 -0
  107. data/lib/para/stall/inputs/variants_matrix_input.rb +72 -0
  108. data/lib/para/stall/routes.rb +11 -0
  109. data/lib/para/stall/variants_property_config.rb +78 -0
  110. data/lib/stall.rb +10 -0
  111. data/lib/stall/addressable.rb +11 -59
  112. data/lib/stall/addresses.rb +1 -0
  113. data/lib/stall/addresses/copier_base.rb +3 -1
  114. data/lib/stall/addresses/copy.rb +10 -0
  115. data/lib/stall/addresses/copy_source_to_target.rb +10 -24
  116. data/lib/stall/addresses/prefill_target_from_source.rb +8 -16
  117. data/lib/stall/adjustable.rb +20 -0
  118. data/lib/stall/archived_paid_cart_helper.rb +36 -0
  119. data/lib/stall/cart_helper.rb +15 -7
  120. data/lib/stall/checkout/informations_checkout_step.rb +47 -50
  121. data/lib/stall/checkout/payment_return_checkout_step.rb +4 -1
  122. data/lib/stall/checkout/step.rb +24 -3
  123. data/lib/stall/checkout/step_form.rb +11 -5
  124. data/lib/stall/checkout/wizard.rb +7 -6
  125. data/lib/stall/config.rb +9 -0
  126. data/lib/stall/default_currency_manager.rb +27 -0
  127. data/lib/stall/engine.rb +14 -3
  128. data/lib/stall/payments.rb +2 -0
  129. data/lib/stall/payments/gateway_request.rb +15 -0
  130. data/lib/stall/payments/gateway_response.rb +33 -0
  131. data/lib/stall/payments/manual_payment_gateway.rb +86 -0
  132. data/lib/stall/priceable.rb +4 -0
  133. data/lib/stall/reference_manager.rb +17 -0
  134. data/lib/stall/routes.rb +1 -0
  135. data/lib/stall/shippable.rb +18 -0
  136. data/lib/stall/total_prices_manager.rb +40 -0
  137. data/lib/stall/version.rb +1 -1
  138. metadata +120 -5
  139. data/app/models/address_ownership.rb +0 -3
  140. data/app/models/stall/models/address_ownership.rb +0 -26
@@ -0,0 +1,52 @@
1
+ # Before this migration, the AddressOwnership class is removed so we declare it
2
+ # here in its minimal version as a temporary fallback allowing us to easily
3
+ # migrate our data to the new address direct-relation model
4
+ #
5
+ class AddressOwnership < ActiveRecord::Base
6
+ self.table_name = 'stall_address_ownerships'
7
+ belongs_to :address
8
+ belongs_to :addressable, polymorphic: true
9
+ end
10
+
11
+ class AddTypeToStallAddressOwnerships < ActiveRecord::Migration
12
+ def up
13
+ change_table :stall_addresses do |t|
14
+ t.string :type
15
+ t.references :addressable, polymorphic: true
16
+ end
17
+
18
+ AddressOwnership.find_each do |ownership|
19
+ address = ownership.address
20
+ address.addressable = ownership.addressable
21
+
22
+ if ownership.shipping
23
+ address.type = 'ShippingAddress'
24
+ address.save!
25
+
26
+ if ownership.billing
27
+ billing_address = BillingAddress.new(addressable: ownership.addressable)
28
+ Stall::Addresses::Copy.new(address, billing_address)
29
+ billing_address.save!
30
+ end
31
+ elsif ownership.billing
32
+ address.type = 'BillingAddress'
33
+ ownership.save!
34
+ else
35
+ ownership.destroy
36
+ end
37
+ end
38
+
39
+ remove_column :stall_address_ownerships, :billing
40
+ remove_column :stall_address_ownerships, :shipping
41
+ end
42
+
43
+ def down
44
+ add_column :stall_address_ownerships, :billing, :boolean
45
+ add_column :stall_address_ownerships, :shipping, :boolean
46
+
47
+ change_table :stall_addresses do |t|
48
+ t.remove :type
49
+ t.remove_references :addressable, polymorphic: true
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,17 @@
1
+ class AddReferenceToProductLists < ActiveRecord::Migration
2
+ def up
3
+ add_column :stall_product_lists, :reference, :string
4
+ add_index :stall_product_lists, :reference, unique: true
5
+
6
+ # Migrate all references stored in the JSON data columns to the new
7
+ # reference column
8
+ Cart.update_all("reference = data->>'reference'")
9
+ # Remove all reference keys in the JSON data columns
10
+ Cart.update_all("data = (data - 'reference')")
11
+ end
12
+
13
+ def down
14
+ remove_index :stall_product_lists, :reference
15
+ remove_column :stall_product_lists, :reference
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ class CreateCreditNotes < ActiveRecord::Migration
2
+ def change
3
+ create_table :stall_credit_notes do |t|
4
+ t.string :reference
5
+ t.references :customer, index: true
6
+ t.string :currency
7
+ t.monetize :eot_amount, null: false, currency: { present: false }
8
+ t.monetize :amount, null: false, currency: { present: false }
9
+ t.decimal :vat_rate, precision: 11, scale: 2
10
+ t.references :source, polymorphic: true, index: true
11
+
12
+ t.timestamps null: false
13
+ end
14
+
15
+ add_foreign_key :stall_credit_notes, :stall_customers, column: :customer_id
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ class CreateCreditNoteAdjustments < ActiveRecord::Migration
2
+ def change
3
+ create_table :stall_credit_note_usages do |t|
4
+ t.references :credit_note, index: true
5
+ t.references :adjustment, index: true
6
+
7
+ t.timestamps null: false
8
+ end
9
+
10
+ add_foreign_key :stall_credit_note_usages, :stall_credit_notes, column: :credit_note_id
11
+ add_foreign_key :stall_credit_note_usages, :stall_adjustments, column: :adjustment_id
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ class CreateStallProductCategories < ActiveRecord::Migration
2
+ def change
3
+ create_table :stall_product_categories do |t|
4
+ t.string :name
5
+ t.text :slug
6
+ t.integer :position, default: 0
7
+ t.integer :parent_id
8
+
9
+ t.timestamps null: false
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ class CreateStallProducts < ActiveRecord::Migration
2
+ def change
3
+ create_table :stall_products do |t|
4
+ t.string :name
5
+ t.attachment :image
6
+ t.text :description
7
+ t.text :slug
8
+ t.integer :position
9
+ t.boolean :visible, default: true
10
+ t.references :product_category, index: true
11
+
12
+ t.timestamps null: false
13
+ end
14
+
15
+ add_foreign_key :stall_products, :stall_product_categories, column: 'product_category_id'
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ class CreateStallVariants < ActiveRecord::Migration
2
+ def change
3
+ create_table :stall_variants do |t|
4
+ t.references :product, index: true
5
+ t.monetize :price
6
+ t.boolean :published, default: true
7
+
8
+ t.timestamps null: false
9
+ end
10
+
11
+ add_foreign_key :stall_variants, :stall_products, column: 'product_id'
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ class CreateStallProductCategoryHierarchies < ActiveRecord::Migration
2
+ def change
3
+ create_table :stall_product_category_hierarchies, id: false do |t|
4
+ t.integer :ancestor_id, null: false
5
+ t.integer :descendant_id, null: false
6
+ t.integer :generations, null: false
7
+ end
8
+
9
+ add_index :stall_product_category_hierarchies, [:ancestor_id, :descendant_id, :generations],
10
+ unique: true,
11
+ name: "stall_product_category_anc_desc_idx"
12
+
13
+ add_index :stall_product_category_hierarchies, [:descendant_id],
14
+ name: "stall_product_category_desc_idx"
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ class CreateStallProductDetails < ActiveRecord::Migration
2
+ def change
3
+ create_table :stall_product_details do |t|
4
+ t.references :product, index: true
5
+ t.string :name
6
+ t.text :content
7
+ t.integer :position, default: 0
8
+
9
+ t.timestamps null: false
10
+ end
11
+
12
+ add_foreign_key :stall_product_details, :stall_products, column: 'product_id'
13
+ end
14
+ end
@@ -0,0 +1,27 @@
1
+ class ConvertAllMoneyFieldsToDecimalToUseInfinitePrecision < ActiveRecord::Migration
2
+ def up
3
+ change_column :stall_adjustments, :price_cents, :decimal, precision: 13, scale: 3
4
+ change_column :stall_adjustments, :eot_price_cents, :decimal, precision: 13, scale: 3
5
+ change_column :stall_credit_notes, :eot_amount_cents, :decimal, precision: 13, scale: 3
6
+ change_column :stall_credit_notes, :amount_cents, :decimal, precision: 13, scale: 3
7
+ change_column :stall_line_items, :unit_eot_price_cents, :decimal, precision: 13, scale: 3
8
+ change_column :stall_line_items, :unit_price_cents, :decimal, precision: 13, scale: 3
9
+ change_column :stall_line_items, :eot_price_cents, :decimal, precision: 13, scale: 3
10
+ change_column :stall_line_items, :price_cents, :decimal, precision: 13, scale: 3
11
+ change_column :stall_shipments, :price_cents, :decimal, precision: 13, scale: 3
12
+ change_column :stall_shipments, :eot_price_cents, :decimal, precision: 13, scale: 3
13
+ end
14
+
15
+ def down
16
+ change_column :stall_adjustments, :price_cents, :integer
17
+ change_column :stall_adjustments, :eot_price_cents, :integer
18
+ change_column :stall_credit_notes, :eot_amount_cents, :integer
19
+ change_column :stall_credit_notes, :amount_cents, :integer
20
+ change_column :stall_line_items, :unit_eot_price_cents, :integer
21
+ change_column :stall_line_items, :unit_price_cents, :integer
22
+ change_column :stall_line_items, :eot_price_cents, :integer
23
+ change_column :stall_line_items, :price_cents, :integer
24
+ change_column :stall_shipments, :price_cents, :integer
25
+ change_column :stall_shipments, :eot_price_cents, :integer
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ class AddDataToStallAdjustments < ActiveRecord::Migration
2
+ def change
3
+ add_column :stall_adjustments, :data, :jsonb
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ class CreateStallProperties < ActiveRecord::Migration
2
+ def change
3
+ create_table :stall_properties do |t|
4
+ t.string :name
5
+
6
+ t.timestamps null: false
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ class CreateStallPropertyValues < ActiveRecord::Migration
2
+ def change
3
+ create_table :stall_property_values do |t|
4
+ t.references :property, index: true
5
+ t.string :value
6
+ t.integer :position, default: 0
7
+
8
+ t.timestamps null: false
9
+ end
10
+
11
+ add_foreign_key :stall_property_values, :stall_properties, column: :property_id
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ class CreateStallVariantPropertyValues < ActiveRecord::Migration
2
+ def change
3
+ create_table :stall_variant_property_values do |t|
4
+ t.references :property_value, index: true
5
+ t.references :variant, index: true
6
+
7
+ t.timestamps null: false
8
+ end
9
+
10
+ add_foreign_key :stall_variant_property_values, :stall_property_values, column: :property_value_id
11
+ add_foreign_key :stall_variant_property_values, :stall_variants, column: :variant_id
12
+ end
13
+ end
@@ -25,6 +25,20 @@ Stall.configure do |config|
25
25
  #
26
26
  # config.sender_email = ENV['STALL_SENDER_EMAIL']
27
27
 
28
+ # Set the customer associated user model used by the shop to bind user
29
+ # accounts to.
30
+ #
31
+ # This model should have an e-mail, password and password_confirmation
32
+ # fields.
33
+ #
34
+ # config.default_user_model_name = 'User'
35
+
36
+ # A method available in all controllers to fetch the current signed in user
37
+ # in your app. It should return a user model if the visitor is signed in, and
38
+ # nil if it's unsigned.
39
+ #
40
+ # config.default_user_helper_method = :current_user
41
+
28
42
  # Global default VAT rate, can be overrided by products
29
43
  #
30
44
  # config.vat_rate = BigDecimal.new('20.0')
@@ -94,6 +108,13 @@ Stall.configure do |config|
94
108
  #
95
109
  # config.default_product_weight = 0
96
110
 
111
+ # When a cart total balance is negative, automatically convert the remaining
112
+ # amount into a credit note for the cart customer
113
+ #
114
+ # Defaults to false, losing the remainder for the customer when paid
115
+ #
116
+ # config.convert_cart_remainder_to_credit_note = false
117
+
97
118
  # Allows configuring which countries are available for free shipping offers
98
119
  #
99
120
  # Accepts an array of country codes or a proc with an Address argument
@@ -1,37 +1,59 @@
1
1
  module Stall
2
2
  class ViewGenerator < ::Rails::Generators::Base
3
- class ViewNotFound < StandardError; end
4
-
5
3
  VIEWS_DIR = File.expand_path('../../../../../app/views', __FILE__)
6
4
  source_root VIEWS_DIR
7
5
 
8
6
  argument :file_paths, type: :array, required: true
9
7
 
10
8
  def copy_view_template
11
- paths = file_paths.map do |file_path|
12
- source_path = source_path_for(file_path)
13
- raise ViewNotFound, "Could not find any stall view for #{ file_path }" unless File.exist?(source_path)
14
- target_path = "app/views/#{ file_path_with_ext_for(file_path) }"
9
+ paths = file_paths.map { |file_path| ViewTemplate.new(file_path) }
15
10
 
16
- [source_path, target_path]
11
+ paths.each do |view_template|
12
+ template(view_template.source_path, view_template.target_path)
17
13
  end
14
+ end
15
+
16
+
17
+ class ViewTemplate
18
+ class ViewNotFound < StandardError; end
18
19
 
19
- paths.each do |source_path, target_path|
20
- template(source_path, target_path)
20
+ attr_reader :file_path
21
+
22
+ def initialize(file_path)
23
+ @file_path = file_path
21
24
  end
22
- end
23
25
 
24
- private
26
+ def source_path
27
+ source_file_for(file_path_with_ext)
28
+ end
25
29
 
26
- def source_path_for(file_path)
27
- File.join(VIEWS_DIR, file_path_with_ext_for(file_path))
28
- end
30
+ def target_path
31
+ "app/views/#{ file_path_with_ext }"
32
+ end
33
+
34
+ private
35
+
36
+ def file_path_with_ext
37
+ return @file_path_with_ext if @file_path_with_ext
38
+ @file_path += '.html.haml' unless file_path.match(/\.html\.haml\z/)
39
+
40
+ if File.exist?(source_file_for(file_path))
41
+ @file_path_with_ext = file_path
42
+ return @file_path_with_ext
43
+ end
44
+
45
+ partial_path = [File.dirname(file_path), File.basename(file_path)].join('/_')
46
+
47
+ if File.exist?(source_file_for(partial_path))
48
+ @file_path_with_ext = partial_path
49
+ return @file_path_with_ext
50
+ end
51
+
52
+ raise ViewNotFound, "No Stall view was found for #{ file_path } !"
53
+ end
29
54
 
30
- def file_path_with_ext_for(file_path)
31
- if file_path.match(/\.html\.haml\z/)
32
- file_path
33
- else
34
- "#{ file_path }.html.haml"
55
+ def source_file_for(path)
56
+ File.join(Stall::ViewGenerator::VIEWS_DIR, path)
35
57
  end
36
58
  end
37
59
  end
@@ -0,0 +1,32 @@
1
+ require 'para'
2
+ require 'stall'
3
+ require 'simple_form'
4
+
5
+ require 'para/stall/inputs'
6
+
7
+ module Para
8
+ module Stall
9
+ extend ActiveSupport::Autoload
10
+
11
+ autoload :Routes
12
+ autoload :VariantsPropertyConfig
13
+
14
+ class << self
15
+ def config(&block)
16
+ if block
17
+ block.call(self)
18
+ else
19
+ self
20
+ end
21
+ end
22
+
23
+ def javascript_includes
24
+ %w(para/stall)
25
+ end
26
+
27
+ def stylesheet_includes
28
+ %w(para/stall)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,13 @@
1
+ module Para
2
+ module Stall
3
+ module Inputs
4
+ extend ActiveSupport::Autoload
5
+
6
+ autoload :VariantInputHelper
7
+ autoload :VariantsMatrixInput
8
+ autoload :VariantSelectInput
9
+ end
10
+ end
11
+ end
12
+
13
+ SimpleForm.custom_inputs_namespaces << 'Para::Stall::Inputs'
@@ -0,0 +1,34 @@
1
+ module Para
2
+ module Stall
3
+ module Inputs
4
+ module VariantInputHelper
5
+ private
6
+
7
+ def resource
8
+ @resource ||= @builder.object
9
+ end
10
+
11
+ def model
12
+ @model ||= resource.class
13
+ end
14
+
15
+ def variant_sort_method(variant)
16
+ properties.map do |property_config|
17
+ if (variant_value = property_config.variant_property_value_for(variant))
18
+ variant_value.property_value.position
19
+ end
20
+ end.join(':')
21
+ end
22
+
23
+ # Raises a comprehensive error for easy wrong form attribute catching
24
+ #
25
+ def ensure_target_relation_present!
26
+ unless model.reflect_on_association(attribute_name)
27
+ raise NoMethodError,
28
+ "Relation ##{ attribute_name } does not exist for model #{ model.name }."
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end