Class: Workarea::Admin::PricingSkuViewModel
- Inherits:
-
ApplicationViewModel
- Object
- ApplicationViewModel
- Workarea::Admin::PricingSkuViewModel
- Defined in:
- app/view_models/workarea/admin/pricing_sku_view_model.rb
Instance Method Summary collapse
- #inventory ⇒ Object
-
#max_price ⇒ Money
The highest regular price set on this SKU.
-
#min_price ⇒ Money
The lowest price that this SKU can be purchased for.
-
#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.
- #product ⇒ Object
-
#sell_price ⇒ String
The price of this SKU as rendered on the index page.
-
#sell_prices ⇒ Array<Workarea::Pricing::Price>
All prices that this SKU will be sold at.
-
#show_range? ⇒ Boolean
Show a price range if the ‘min_price` and `max_price` are not the same value.
- #timeline ⇒ Object
Instance Method Details
#inventory ⇒ Object
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_price ⇒ Money
The highest regular price set on this SKU.
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_price ⇒ Money
The lowest price that this SKU can be purchased for. Dependent on the current sale state of the SKU.
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.
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 |
#product ⇒ Object
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, ) if product.present? end end |
#sell_price ⇒ String
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.
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_prices ⇒ Array<Workarea::Pricing::Price>
All prices that this SKU will be sold at. Makes a determination based on whether the price is on sale.
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.
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 |
#timeline ⇒ Object
4 5 6 |
# File 'app/view_models/workarea/admin/pricing_sku_view_model.rb', line 4 def timeline @timeline ||= TimelineViewModel.new(model) end |