Class: Workarea::Pricing::Discount::Category
- Inherits:
-
Workarea::Pricing::Discount
- Object
- Workarea::Pricing::Discount
- Workarea::Pricing::Discount::Category
- Includes:
- Workarea::Pricing::Discount::Conditions::ItemQuantity, Workarea::Pricing::Discount::Conditions::OrderTotal, Workarea::Pricing::Discount::Conditions::PromoCodes, Workarea::Pricing::Discount::Conditions::UserTags, FlatOrPercentOff
- Defined in:
- app/models/workarea/pricing/discount/category.rb
Overview
This class allows discounts to any products categorized in one or many categories.
Constant Summary
Constants included from Workarea::Pricing::Discount::Conditions::OrderTotal
Workarea::Pricing::Discount::Conditions::OrderTotal::OPERATORS
Constants included from FlatOrPercentOff
FlatOrPercentOff::AMOUNT_TYPES
Instance Attribute Summary collapse
-
#category_ids ⇒ Integer
The ids for the Catalog::Category.
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 item price adjustments for items that qualify match the #category_ids.
-
#item_qualifies?(item) ⇒ Boolean
Whether the order item qualifies based on category and quantity requirements.
Methods included from Workarea::Pricing::Discount::Conditions::UserTags
#user_tag?, #user_tags_qualify?
Methods included from Workarea::Pricing::Discount::Conditions::ItemQuantity
#item_quantity?, #items_qualify?
Methods included from Workarea::Pricing::Discount::Conditions::PromoCodes
#generated_codes, #promo_code?, #promo_codes_qualify?, #valid?
Methods included from Workarea::Pricing::Discount::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
#category_ids ⇒ Integer
Returns the ids for the Catalog::Category.
17 |
# File 'app/models/workarea/pricing/discount/category.rb', line 17 field :category_ids, type: Array, default: [] |
Class Method Details
.model_name ⇒ Object
23 24 25 |
# File 'app/models/workarea/pricing/discount/category.rb', line 23 def self.model_name Discount.model_name end |
Instance Method Details
#apply(order) ⇒ Object
Create the item price adjustments for items that qualify match the #category_ids.
48 49 50 51 52 53 54 55 |
# File 'app/models/workarea/pricing/discount/category.rb', line 48 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
Whether the order item qualifies based on category and quantity requirements
39 40 41 |
# File 'app/models/workarea/pricing/discount/category.rb', line 39 def item_qualifies?(item) super && item.matches_categories?(category_ids) end |