Class: BBMB::Model::ProductInfo

Inherits:
Subject
  • Object
show all
Includes:
Util::Numbers
Defined in:
lib/bbmb/model/product.rb,
lib/bbmb/persistence/odba/model/product.rb

Direct Known Subclasses

Product

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::Numbers

append_features

Methods inherited from Subject

multilingual

Constructor Details

#initialize(article_number) ⇒ ProductInfo

Returns a new instance of ProductInfo.



19
20
21
22
# File 'lib/bbmb/model/product.rb', line 19

def initialize(article_number)
  @article_number = article_number
  @backorder = false
end

Instance Attribute Details

#article_numberObject (readonly)

Returns the value of attribute article_number.



12
13
14
# File 'lib/bbmb/model/product.rb', line 12

def article_number
  @article_number
end

#backorderObject (readonly)

Returns the value of attribute backorder.



12
13
14
# File 'lib/bbmb/model/product.rb', line 12

def backorder
  @backorder
end

#backorder_dateObject

Returns the value of attribute backorder_date.



13
14
15
# File 'lib/bbmb/model/product.rb', line 13

def backorder_date
  @backorder_date
end

#commit_dateObject

Returns the value of attribute commit_date.



13
14
15
# File 'lib/bbmb/model/product.rb', line 13

def commit_date
  @commit_date
end

#ean13Object

Returns the value of attribute ean13.



13
14
15
# File 'lib/bbmb/model/product.rb', line 13

def ean13
  @ean13
end

#expiry_dateObject

Returns the value of attribute expiry_date.



13
14
15
# File 'lib/bbmb/model/product.rb', line 13

def expiry_date
  @expiry_date
end

#partner_indexObject

Returns the value of attribute partner_index.



13
14
15
# File 'lib/bbmb/model/product.rb', line 13

def partner_index
  @partner_index
end

#pcodeObject

Returns the value of attribute pcode.



13
14
15
# File 'lib/bbmb/model/product.rb', line 13

def pcode
  @pcode
end

#promotionObject

Returns the value of attribute promotion.



13
14
15
# File 'lib/bbmb/model/product.rb', line 13

def promotion
  @promotion
end

#saleObject

Returns the value of attribute sale.



13
14
15
# File 'lib/bbmb/model/product.rb', line 13

def sale
  @sale
end

#statusObject

Returns the value of attribute status.



13
14
15
# File 'lib/bbmb/model/product.rb', line 13

def status
  @status
end

Instance Method Details

#==(other) ⇒ Object



68
69
70
# File 'lib/bbmb/model/product.rb', line 68

def ==(other)
  other.is_a?(ProductInfo) && @article_number == other.article_number
end

#current_promoObject



23
24
25
# File 'lib/bbmb/model/product.rb', line 23

def current_promo
  [@sale, @promotion].find { |promo| promo }
end

#freebies(level) ⇒ Object



26
27
28
# File 'lib/bbmb/model/product.rb', line 26

def freebies(level)
  (promo = current_promo) && promo.freebies(level)
end

#migrate_to_subjectObject



9
10
11
12
13
14
# File 'lib/bbmb/persistence/odba/model/product.rb', line 9

def migrate_to_subject
  changed = super
  @promotion && @promotion.migrate_to_subject && (changed = true)
  @sale && @sale.migrate_to_subject && (changed = true)
  changed
end

#price(qty = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bbmb/model/product.rb', line 29

def price(qty=nil)
  qty ||= 1
  res = @price
  (1..6).each { |num|
    if(res.nil? || ((tmp = instance_variable_get("@l#{num}_qty")) \
                    && qty >= tmp))
      res = instance_variable_get("@l#{num}_price") || res
    end
  }
  if((pr = current_promo) && (((price = pr.price_qty(qty)) && price > res) \
     || ((price = pr.l1_price) && price > res)))
    res = price
  end
  res
end

#price_baseObject



44
45
46
# File 'lib/bbmb/model/product.rb', line 44

def price_base
  price(1)
end

#price_effective(qty = nil) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/bbmb/model/product.rb', line 47

def price_effective(qty=nil)
  price = price_qty(qty)
  if((promo = current_promo) && (discount = promo.discount(qty)))
    price *= (100.0 - discount) / 100.0
  end
  price || Util::Money.new(0)
end

#price_qty(qty = nil) ⇒ Object



54
55
56
57
# File 'lib/bbmb/model/product.rb', line 54

def price_qty(qty=nil)
  ((promo = current_promo) && promo.price_qty(qty)) \
    || price(qty)
end

#qty_level(level = nil) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/bbmb/model/product.rb', line 58

def qty_level(level=nil)
  if((promo = current_promo) && promo.has_price_qty?)
    promo.qty_level(level)
  else
    instance_variable_get("@l#{level}_qty")
  end
end

#to_infoObject



65
66
67
# File 'lib/bbmb/model/product.rb', line 65

def to_info
self
end