Class: Workarea::Pricing::Discount::ProductAttribute
- Inherits:
-
Workarea::Pricing::Discount
- Object
- Workarea::Pricing::Discount
- Workarea::Pricing::Discount::ProductAttribute
- Includes:
- Conditions::ItemQuantity, Conditions::OrderTotal, Conditions::PromoCodes, Conditions::UserTags, FlatOrPercentOff
- Defined in:
- app/models/workarea/pricing/discount/product_attribute.rb
Overview
This discount allows discounting items based on whether any of the the Catalog::Product or Catalog::Variant details match.
Defined Under Namespace
Classes: ItemQualifier
Constant Summary
Constants included from Conditions::OrderTotal
Conditions::OrderTotal::OPERATORS
Constants included from FlatOrPercentOff
FlatOrPercentOff::AMOUNT_TYPES
Instance Attribute Summary collapse
-
#attribute_name ⇒ Array
The details name to match.
-
#attribute_value ⇒ Array
The details value to match.
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 items that match the attribute requirements.
-
#item_qualifies?(item) ⇒ Boolean
Qualifier method for whether any items in the order match the attribute qualification.
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
assert_valid_config!, async, disable, enable, inline, #run_callbacks
Methods included from Mongoid::Document
Instance Attribute Details
#attribute_name ⇒ Array
Returns the details name to match.
18 |
# File 'app/models/workarea/pricing/discount/product_attribute.rb', line 18 field :attribute_name, type: String |
#attribute_value ⇒ Array
Returns the details value to match.
23 |
# File 'app/models/workarea/pricing/discount/product_attribute.rb', line 23 field :attribute_value, type: String |
Class Method Details
.model_name ⇒ Object
29 30 31 |
# File 'app/models/workarea/pricing/discount/product_attribute.rb', line 29 def self.model_name Discount.model_name end |
Instance Method Details
#apply(order) ⇒ Object
Create the discount price adjustments on items that match the attribute requirements.
54 55 56 57 58 59 60 61 |
# File 'app/models/workarea/pricing/discount/product_attribute.rb', line 54 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 end |
#item_qualifies?(item) ⇒ Boolean
Qualifier method for whether any items in the order match the attribute qualification.
45 46 47 |
# File 'app/models/workarea/pricing/discount/product_attribute.rb', line 45 def item_qualifies?(item) super && ItemQualifier.new(self, item).qualifies? end |