Class: Workarea::Pricing::Sku

Inherits:
Object
  • Object
show all
Includes:
ApplicationDocument, Releasable
Defined in:
app/models/workarea/pricing/sku.rb

Defined Under Namespace

Classes: MissingPrices

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Releasable

#activates_with_current_release?, #releasable?, #release_changes, #save_changeset, #skip_changeset

Methods included from ApplicationDocument

#releasable?

Methods included from Sidekiq::Callbacks

assert_valid_config!, async, disable, enable, inline, #run_callbacks

Class Method Details

.sortsObject



19
20
21
# File 'app/models/workarea/pricing/sku.rb', line 19

def self.sorts
  [Sort.modified, Sort.sku, Sort.newest]
end

Instance Method Details

#active_pricesArray<Workarea::Pricing::Price>

All active prices (with i18n fallbacks included) for the given SKU.

Returns:



72
73
74
# File 'app/models/workarea/pricing/sku.rb', line 72

def active_prices
  prices.select(&:active).sort_by(&:min_quantity).reverse
end

#find_price(options = {}) ⇒ Pricing::Price

Find the price to sell at for a specific options.

The only supported option is :quantity, but this takes an options hash as an extension point to plugins and implementations.

Parameters:

  • (Hash)

Returns:



39
40
41
42
43
44
45
46
47
# File 'app/models/workarea/pricing/sku.rb', line 39

def find_price(options = {})
  quantity = options[:quantity] || 1

  match = active_prices.detect do |price|
    quantity >= price.min_quantity
  end

  match || Price.new
end

#nameString

This is for compatibility with the admin, all models must implement this

Returns:



27
28
29
# File 'app/models/workarea/pricing/sku.rb', line 27

def name
  I18n.t('workarea.pricing_sku.name', id: id)
end

#sale_priceMoney

Default sale price, when one unit is placed into the cart of an anonymous user.

Returns:



64
65
66
# File 'app/models/workarea/pricing/sku.rb', line 64

def sale_price
  find_price(quantity: 1).sale
end

#sell_priceMoney Also known as: regular_price

Default selling price, when one unit is placed into the cart of an anonymous user.

Returns:



54
55
56
# File 'app/models/workarea/pricing/sku.rb', line 54

def sell_price
  find_price(quantity: 1).sell
end