Class: Workarea::Admin::PricingSkuViewModel

Inherits:
ApplicationViewModel
  • Object
show all
Defined in:
app/view_models/workarea/admin/pricing_sku_view_model.rb

Instance Method Summary collapse

Instance Method Details

#inventoryObject



16
17
18
# File 'app/view_models/workarea/admin/pricing_sku_view_model.rb', line 16

def inventory
  @inventory ||= Inventory::Sku.where(id: model.id).first
end

#max_priceMoney

The highest regular price set on this SKU.

Returns:

  • (Money)


39
40
41
# File 'app/view_models/workarea/admin/pricing_sku_view_model.rb', line 39

def max_price
  sell_prices.last&.sell
end

#min_priceMoney

The lowest price that this SKU can be purchased for. Dependent on the current sale state of the SKU.

Returns:

  • (Money)


32
33
34
# File 'app/view_models/workarea/admin/pricing_sku_view_model.rb', line 32

def min_price
  sell_prices.first&.sell
end

#on_sale?Boolean

This SKU is considered “on sale” if it is marked as such, or if any prices that it contains are marked as such.

Returns:

  • (Boolean)


55
56
57
# File 'app/view_models/workarea/admin/pricing_sku_view_model.rb', line 55

def on_sale?
  model.on_sale? || prices.any?(&:on_sale?)
end

#productObject



8
9
10
11
12
13
14
# File 'app/view_models/workarea/admin/pricing_sku_view_model.rb', line 8

def product
  @product ||=
    begin
      product = Catalog::Product.find_by_sku(model.id)
      ProductViewModel.wrap(product, options) if product.present?
    end
end

#sell_priceString

The price of this SKU as rendered on the index page. Shows a price range when multiple prices are contained within the SKU, otherwise it just shows the only sell price available.

Returns:

  • (String)


64
65
66
67
68
69
# File 'app/view_models/workarea/admin/pricing_sku_view_model.rb', line 64

def sell_price
  return if min_price.blank?
  return min_price.format unless show_range?

  "#{max_price.format}#{min_price.format}"
end

#sell_pricesArray<Workarea::Pricing::Price>

All prices that this SKU will be sold at. Makes a determination based on whether the price is on sale.

Returns:

  • (Array<Workarea::Pricing::Price>)


24
25
26
# File 'app/view_models/workarea/admin/pricing_sku_view_model.rb', line 24

def sell_prices
  prices.sort_by(&:sell)
end

#show_range?Boolean

Show a price range if the ‘min_price` and `max_price` are not the same value.

Returns:

  • (Boolean)


47
48
49
# File 'app/view_models/workarea/admin/pricing_sku_view_model.rb', line 47

def show_range?
  min_price.present? && max_price.present? && min_price != max_price
end

#timelineObject



4
5
6
# File 'app/view_models/workarea/admin/pricing_sku_view_model.rb', line 4

def timeline
  @timeline ||= TimelineViewModel.new(model)
end