Module: SpreeCmCommissioner::TaxonDecorator

Defined in:
app/models/spree_cm_commissioner/taxon_decorator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object

rubocop:disable Metrics/MethodLength



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
42
43
44
45
46
47
48
49
50
51
# File 'app/models/spree_cm_commissioner/taxon_decorator.rb', line 4

def self.prepended(base)
  base.include SpreeCmCommissioner::TaxonKind
  base.include SpreeCmCommissioner::Transit::TaxonBitwise

  base.preference :background_color, :string
  base.preference :foreground_color, :string

  base.has_many :taxon_vendors, class_name: 'SpreeCmCommissioner::TaxonVendor'
  base.has_many :vendors, through: :taxon_vendors

  base.has_many :guest_card_classes, class_name: 'SpreeCmCommissioner::GuestCardClass'
  base.has_many :homepage_section_relatables,
                class_name: 'SpreeCmCommissioner::HomepageSectionRelatable',
                dependent: :destroy, as: :relatable

  base.has_many :user_events, class_name: 'SpreeCmCommissioner::UserEvent'
  base.has_many :users, through: :user_events, class_name: Spree.user_class.to_s
  base.has_many :products, through: :classifications, class_name: 'Spree::Product'
  base.has_many :guests, foreign_key: :event_id, class_name: 'SpreeCmCommissioner::Guest', dependent: :nullify
  base.has_many :check_ins, as: :checkinable, class_name: 'SpreeCmCommissioner::CheckIn', dependent: :nullify
  base.has_many :customer_taxons, class_name: 'SpreeCmCommissioner::CustomerTaxon'

  base.has_one :category_icon, as: :viewable, dependent: :destroy, class_name: 'SpreeCmCommissioner::TaxonCategoryIcon'

  base.has_one :web_banner, as: :viewable, dependent: :destroy, class_name: 'SpreeCmCommissioner::TaxonWebBanner'
  base.has_one :app_banner, as: :viewable, dependent: :destroy, class_name: 'SpreeCmCommissioner::TaxonAppBanner'
  base.has_one :home_banner, as: :viewable, dependent: :destroy, class_name: 'SpreeCmCommissioner::TaxonHomeBanner'

  # Update children association to work with nested set (lft, rgt)
  base.has_many :children, -> { order(:lft) }, class_name: 'Spree::Taxon', foreign_key: :parent_id, dependent: :destroy
  base.has_many :children_classifications, through: :children, source: :classifications, class_name: 'Spree::Classification'

  base.has_many :notification_taxons, class_name: 'SpreeCmCommissioner::NotificationTaxon'
  base.has_many :customer_notifications, through: :notification_taxons, class_name: 'SpreeCmCommissioner::CustomerNotification'

  base.has_many :visible_classifications, -> { where(visible: true).order(:position) }, class_name: 'Spree::Classification'
  base.has_many :visible_products, through: :visible_classifications, class_name: 'Spree::Product', source: :product

  base.belongs_to :vendor, class_name: 'Spree::Vendor'

  base.validates_associated :category_icon
  base.before_save :set_kind
  base.before_save :set_slug

  base.whitelisted_ransackable_attributes |= %w[kind]

  base.enum purchasable_on: { both: 0, web: 1, app: 2 }
end

Instance Method Details

#background_colorObject

rubocop:enable Metrics/MethodLength



54
55
56
# File 'app/models/spree_cm_commissioner/taxon_decorator.rb', line 54

def background_color
  preferred_background_color
end

#event_slugObject



70
71
72
# File 'app/models/spree_cm_commissioner/taxon_decorator.rb', line 70

def event_slug
  slug.sub(/^events-/, '')
end

#event_urlObject



81
82
83
# File 'app/models/spree_cm_commissioner/taxon_decorator.rb', line 81

def event_url
  "https://#{Spree::Store.default.url}/t/#{permalink}"
end

#foreground_colorObject



58
59
60
# File 'app/models/spree_cm_commissioner/taxon_decorator.rb', line 58

def foreground_color
  preferred_foreground_color
end

#products_option_type_namesObject



74
75
76
77
78
79
# File 'app/models/spree_cm_commissioner/taxon_decorator.rb', line 74

def products_option_type_names
  Spree::OptionType.joins(products: :taxons)
                   .where(spree_taxons: { id: child_ids })
                   .pluck('spree_option_types.name')
                   .uniq
end

#set_kindObject



62
63
64
# File 'app/models/spree_cm_commissioner/taxon_decorator.rb', line 62

def set_kind
  self.kind = taxonomy.kind
end

#set_slugObject



66
67
68
# File 'app/models/spree_cm_commissioner/taxon_decorator.rb', line 66

def set_slug
  self.slug = permalink&.parameterize
end