Class: Workarea::Pricing::Discount::Product
- Inherits:
-
Workarea::Pricing::Discount
- Object
- Workarea::Pricing::Discount
- Workarea::Pricing::Discount::Product
- Includes:
- Conditions::ItemQuantity, Conditions::OrderTotal, Conditions::PromoCodes, Conditions::UserTags, FlatOrPercentOff
- Defined in:
- app/models/workarea/pricing/discount/product.rb
Constant Summary
Constants included from Conditions::OrderTotal
Conditions::OrderTotal::OPERATORS
Constants included from FlatOrPercentOff
FlatOrPercentOff::AMOUNT_TYPES
Instance Attribute Summary collapse
-
#product_ids ⇒ Array
Discount applies to these Catalog::Product ids.
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) ⇒ Workarea::Order
Creates the price adjustments for the discount on the matching items.
-
#item_qualifies?(item) ⇒ Boolean
Qualifier method to check whether any items in this order qualify for this discount.
Methods included from Conditions::UserTags
#user_tag?, #user_tags_qualify?
Methods included from Conditions::ItemQuantity
#item_quantity?, #items_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 included from FlatOrPercentOff
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, #qualifies?, #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
#product_ids ⇒ Array
Returns discount applies to these Catalog::Product ids.
16 |
# File 'app/models/workarea/pricing/discount/product.rb', line 16 field :product_ids, type: Array, default: [] |
Class Method Details
.model_name ⇒ Object
21 22 23 |
# File 'app/models/workarea/pricing/discount/product.rb', line 21 def self.model_name Discount.model_name end |
Instance Method Details
#apply(order) ⇒ Workarea::Order
Creates the price adjustments for the discount on the matching items.
47 48 49 50 51 52 53 54 55 56 |
# File 'app/models/workarea/pricing/discount/product.rb', line 47 def apply(order) order.items.each do |item| next unless item_qualifies?(item) value = amount_calculator.calculate(item.current_unit_price, item.quantity) item.adjust_pricing(adjustment_data(value, item.quantity)) end order end |
#item_qualifies?(item) ⇒ Boolean
Qualifier method to check whether any items in this order qualify for this discount.
37 38 39 |
# File 'app/models/workarea/pricing/discount/product.rb', line 37 def item_qualifies?(item) super && item.product_id.in?(product_ids) end |