Class: Workarea::Pricing::Sku
- Inherits:
-
Object
- Object
- Workarea::Pricing::Sku
- Includes:
- ApplicationDocument, UnsupportedSegmentation, Releasable
- Defined in:
- app/models/workarea/pricing/sku.rb
Defined Under Namespace
Classes: MissingPrices
Class Method Summary collapse
Instance Method Summary collapse
-
#active_prices ⇒ Array<Workarea::Pricing::Price>
All active prices (with i18n fallbacks included) for the given SKU.
-
#find_price(options = {}) ⇒ Pricing::Price
Find the price to sell at for a specific options.
-
#name ⇒ String
This is for compatibility with the admin, all models must implement this.
-
#sale_price ⇒ Money
Default sale price, when one unit is placed into the cart of an anonymous user.
-
#sell_price ⇒ Money
(also: #regular_price)
Default selling price, when one unit is placed into the cart of an anonymous user.
Methods included from Releasable
#changesets_with_children, #destroy, #in_release, #release_changes, #release_originals, #save_changeset, #skip_changeset, #without_release
Methods included from Segmentable
#active?, #active_segment_ids_with_children, #segmented?, #segments
Methods included from Release::Activation
#activate_with?, #create_activation_changeset, #save_activate_with, #was_active?
Methods included from ApplicationDocument
Methods included from Sidekiq::Callbacks
add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list
Methods included from Mongoid::Document
Class Method Details
Instance Method Details
#active_prices ⇒ Array<Workarea::Pricing::Price>
All active prices (with i18n fallbacks included) for the given SKU.
73 74 75 |
# File 'app/models/workarea/pricing/sku.rb', line 73 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.
40 41 42 43 44 45 46 47 48 |
# File 'app/models/workarea/pricing/sku.rb', line 40 def find_price( = {}) quantity = [:quantity] || 1 match = active_prices.detect do |price| quantity >= price.min_quantity end match || Price.new end |
#name ⇒ String
This is for compatibility with the admin, all models must implement this
28 29 30 |
# File 'app/models/workarea/pricing/sku.rb', line 28 def name I18n.t('workarea.pricing_sku.name', id: id) end |
#sale_price ⇒ Money
Default sale price, when one unit is placed into the cart of an anonymous user.
65 66 67 |
# File 'app/models/workarea/pricing/sku.rb', line 65 def sale_price find_price(quantity: 1).sale end |
#sell_price ⇒ Money Also known as: regular_price
Default selling price, when one unit is placed into the cart of an anonymous user.
55 56 57 |
# File 'app/models/workarea/pricing/sku.rb', line 55 def sell_price find_price(quantity: 1).sell end |