Class: Workarea::Pricing::Discount::QuantityFixedPrice
- Inherits:
-
Workarea::Pricing::Discount
- Object
- Workarea::Pricing::Discount
- Workarea::Pricing::Discount::QuantityFixedPrice
- Defined in:
- app/models/workarea/pricing/discount/quantity_fixed_price.rb
Overview
This discount allows a quantity of products or products from a certain category to be fixed at a price.
For example:
* 2 Shirts for $29
* This product is 3 for $15
Defined Under Namespace
Classes: ApplicationCalculator, ItemShares
Constant Summary
Constants included from Conditions::OrderTotal
Conditions::OrderTotal::OPERATORS
Instance Attribute Summary collapse
-
#category_ids ⇒ Array
Ids to eligible Catalog::Categorys.
-
#max_applications ⇒ Integer
The maximum number of times this can be applied.
-
#price ⇒ Money
The fixed price for the quantity.
-
#product_ids ⇒ Array
Ids to eligible Catalog::Products.
-
#quantity ⇒ Integer
The quantity that receives the fixed price.
Attributes inherited from Workarea::Pricing::Discount
#allow_sale_items, #auto_deactivated, #auto_deactivated_at, #compatible_discount_ids, #excluded_category_ids, #excluded_product_ids, #name, #price_level, #redemptions, #single_use
Class Method Summary collapse
Instance Method Summary collapse
-
#apply(order) ⇒ Object
Create the discount price adjustments on matching items.
-
#qualifies?(order) ⇒ Boolean
These discounts apply if any item matches the catalog requirements.
Methods included from Conditions::UserTags
#user_tag?, #user_tags_qualify?
Methods included from Conditions::PromoCodes
#generated_codes, #promo_code?, #promo_codes_qualify?, #valid?
Methods included from Conditions::OrderTotal
#order_total?, #order_total_qualifies?
Methods inherited from Workarea::Pricing::Discount
#<=>, add_qualifier, auto_deactivate, #auto_deactivate!, #auto_deactivated?, #auto_deactivates_at, #can_be_used_by?, #compatible_discounts, #compatible_with?, #excludes_category_id?, #excludes_product_id?, #has_been_redeemed?, #last_redemption, #log_redemption, qualifier_methods, #remove_from
Methods included from Commentable
#add_subscription, #remove_subscription
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 Mongoid::Document::Taggable
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
Instance Attribute Details
#category_ids ⇒ Array
Returns ids to eligible Catalog::Categorys.
35 |
# File 'app/models/workarea/pricing/discount/quantity_fixed_price.rb', line 35 field :category_ids, type: Array, default: [] |
#max_applications ⇒ Integer
Returns the maximum number of times this can be applied.
24 |
# File 'app/models/workarea/pricing/discount/quantity_fixed_price.rb', line 24 field :max_applications, type: Integer |
#price ⇒ Money
Returns the fixed price for the quantity.
41 |
# File 'app/models/workarea/pricing/discount/quantity_fixed_price.rb', line 41 field :price, type: Money |
#product_ids ⇒ Array
Returns ids to eligible Catalog::Products.
29 |
# File 'app/models/workarea/pricing/discount/quantity_fixed_price.rb', line 29 field :product_ids, type: Array, default: [] |
#quantity ⇒ Integer
Returns the quantity that receives the fixed price.
19 |
# File 'app/models/workarea/pricing/discount/quantity_fixed_price.rb', line 19 field :quantity, type: Integer |
Class Method Details
.model_name ⇒ Object
48 49 50 |
# File 'app/models/workarea/pricing/discount/quantity_fixed_price.rb', line 48 def self.model_name Discount.model_name end |
Instance Method Details
#apply(order) ⇒ Object
Create the discount price adjustments on matching items. Redemption can be across items. For example:
-
discount is quantity 2
-
item of quantity 1 in category
-
different item of quantity 1 in same category
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/models/workarea/pricing/discount/quantity_fixed_price.rb', line 76 def apply(order) applications_calculator = ApplicationCalculator.new(self, order.items) item_shares = ItemShares.new( self, order, applications_calculator.applications ) item_shares.each do |id, value| item = order.items.detect { |i| i.id == id } item.adjust_pricing(adjustment_data(value, item.quantity)) end end |
#qualifies?(order) ⇒ Boolean
These discounts apply if any item matches the catalog requirements.
64 65 66 |
# File 'app/models/workarea/pricing/discount/quantity_fixed_price.rb', line 64 def qualifies?(order) super && order.items.any? { |i| item_qualifies?(i) } end |