Class: Coupon::Tier2ProgramPricing

Inherits:
Coupon
  • Object
show all
Defined in:
app/services/coupon/tier2_program_pricing.rb

Overview

Service object: tier2 program pricing.

Constant Summary collapse

MSRP_ID =

Msrp id.

577
TRADE_ID =

Trade id.

584

Instance Attribute Summary collapse

Has many collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#auto_applyObject (readonly)



11
# File 'app/services/coupon/tier2_program_pricing.rb', line 11

validates :auto_apply, inclusion: { in: [false], message: "can only be false for this type of coupon" }

Class Method Details

.customer_defaultObject



21
22
23
# File 'app/services/coupon/tier2_program_pricing.rb', line 21

def self.customer_default
  Coupon.find_by(code: 'PP-LEVEL-ZERO')
end

.customer_default_tradeObject



25
26
27
# File 'app/services/coupon/tier2_program_pricing.rb', line 25

def self.customer_default_trade
  Coupon.find_by(code: 'PP-SILVER-LEVEL')
end

.friendly_type_nameObject



81
82
83
# File 'app/services/coupon/tier2_program_pricing.rb', line 81

def self.friendly_type_name
  "Customer Pricing Program"
end

.get_customer_pricing(customer) ⇒ Object



70
71
72
73
74
75
# File 'app/services/coupon/tier2_program_pricing.rb', line 70

def self.get_customer_pricing(customer)
  return customer_default unless customer.catalog.is_main_catalog? # custom catalog always MSRP
  return customer_default if customer.profile.e_commerce_misc? # etailer always MSRP

  get_pricing(customer.profile, customer.buying_group)
end

.get_pricing(profile, _buying_group = nil) ⇒ Object



62
63
64
65
66
67
68
# File 'app/services/coupon/tier2_program_pricing.rb', line 62

def self.get_pricing(profile, _buying_group = nil)
  if profile.try(:organization?)
    customer_default_trade
  else
    customer_default # msrp
  end
end

.model_nameObject



17
18
19
# File 'app/services/coupon/tier2_program_pricing.rb', line 17

def self.model_name
  Coupon.model_name
end

.msrp_tier2_pricing_couponObject



13
14
15
# File 'app/services/coupon/tier2_program_pricing.rb', line 13

def self.msrp_tier2_pricing_coupon
  Coupon.find_by(code: 'PP-LEVEL-ZERO')
end

.select_optionsObject



41
42
43
# File 'app/services/coupon/tier2_program_pricing.rb', line 41

def self.select_options
  all.order(:title).pluck(:title, :id)
end

.select_options_for_customer(customer, role_ids = []) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/services/coupon/tier2_program_pricing.rb', line 45

def self.select_options_for_customer(customer, role_ids = [])
  qb = Coupon::QueryBuilder.new
  qb = qb.for_customer(customer)
  qb = qb.with_role_ids(role_ids) if role_ids.present?
  programs = all.active.merge(qb.query)
  results = programs.order(:title).map { |cp| [cp.title, cp.id] }
  results << [customer.tier2_program_pricing.title, customer.tier2_program_pricing.id] if customer.tier2_program_pricing
  # Add default for profile and buying group too
  if (tpp = customer.buying_group.try(:tier2_program_pricing))
    results << [tpp.title, tpp.id]
  end
  if (tpp = customer.profile.try(:tier2_program_pricing))
    results << [tpp.title, tpp.id]
  end
  results.uniq.sort
end

Instance Method Details

#blacklistable?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'app/services/coupon/tier2_program_pricing.rb', line 77

def blacklistable?
  true
end

#custom?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'app/services/coupon/tier2_program_pricing.rb', line 33

def custom?
  code.starts_with?('CUSTOM')
end

#customersActiveRecord::Relation<Customer>

Returns:

See Also:



9
# File 'app/services/coupon/tier2_program_pricing.rb', line 9

has_many :customers

#discount_percentageObject



85
86
87
# File 'app/services/coupon/tier2_program_pricing.rb', line 85

def discount_percentage
  amount_goods.to_i
end

#msrp?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/services/coupon/tier2_program_pricing.rb', line 29

def msrp?
  %w[PPMSRP PP-LEVEL-ZERO].include?(code)
end

#override?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'app/services/coupon/tier2_program_pricing.rb', line 37

def override?
  code.ends_with?('OVERRIDE')
end