forked from moonshine/spree-dropdown-variants-by-option
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dropdown_variants_by_option_extension.rb
41 lines (29 loc) · 1.65 KB
/
dropdown_variants_by_option_extension.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Uncomment this if you reference any of your controllers in activate
# require_dependency 'application'
class DropdownVariantsByOptionExtension < Spree::Extension
version "1.0"
description "Display variants as dropdowns on product add to form"
url "http://yourwebsite.com/dropdown_variants_by_option"
# Please use dropdown_variants_by_option/config/routes.rb instead for extension routes.
# def self.require_gems(config)
# config.gem "gemname-goes-here", :version => '1.2.3'
# end
def activate
# Override spree admin products controller to allow option types ordering
Admin::ProductsController.send(:include, Spree::DropdownVariantsByOption::Admin::ProductsController)
# Order product option_types association by position
Product.send(:include, Spree::DropdownVariantsByOption::Product)
# Add helper to construct options for variant dropdown
ProductsHelper.send(:include, Spree::DropdownVariantsByOption::ProductsHelper)
# Add method to find a variant by it's option values
Variant.send(:include, Spree::DropdownVariantsByOption::Variant)
# Add action to refresh image via ajax on change of option value
ProductsController.send(:include, Spree::DropdownVariantsByOption::ProductsController)
# Add method to add a variant to the cart using the selected option values
OrdersController.send(:include, Spree::DropdownVariantsByOption::OrdersController)
# Add method to validate variant being added to cart
Order.send(:include, Spree::DropdownVariantsByOption::Order)
# Add methods to retrieve primary/non-primary
OptionType.send(:include, Spree::DropdownVariantsByOption::OptionType)
end
end