Module: SolidusTaxCloud::Spree::LineItemDecorator

Defined in:
app/decorators/models/solidus_tax_cloud/spree/line_item_decorator.rb

Instance Method Summary collapse

Instance Method Details

#price_with_discountsObject



36
37
38
# File 'app/decorators/models/solidus_tax_cloud/spree/line_item_decorator.rb', line 36

def price_with_discounts
  round_to_two_places(total_excluding_vat / quantity)
end

#round_to_two_places(amount) ⇒ Object



40
41
42
# File 'app/decorators/models/solidus_tax_cloud/spree/line_item_decorator.rb', line 40

def round_to_two_places(amount)
  BigDecimal(amount.to_s).round(2, BigDecimal::ROUND_HALF_UP)
end

#tax_cloud_cache_keyObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/decorators/models/solidus_tax_cloud/spree/line_item_decorator.rb', line 6

def tax_cloud_cache_key
  if ActiveRecord::Base.try(:cache_versioning)
    cache_key
  else
    key = "Spree::LineItem #{id}: #{quantity}x<#{variant.cache_key}>@#{total_excluding_vat}#{currency}"

    if order.ship_address
      key += "shipped_to<#{order.ship_address.try(:cache_key)}>"
    elsif order.billing_address
      key += "billed_to<#{order.bill_address.try(:cache_key)}>"
    end

    key
  end
end

#tax_cloud_cache_versionObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/decorators/models/solidus_tax_cloud/spree/line_item_decorator.rb', line 22

def tax_cloud_cache_version
  if ActiveRecord::Base.try(:cache_versioning)
    key = "Spree::LineItem #{id}: #{quantity}x<#{variant.cache_version}>@#{total_excluding_vat}#{currency}"

    if order.ship_address
      key += "shipped_to<#{order.ship_address.try(:cache_version)}>"
    elsif order.billing_address
      key += "billed_to<#{order.bill_address.try(:cache_version)}>"
    end

    key
  end
end