Class: Workarea::Pricing::Discount::OrderTotal

Inherits:
Workarea::Pricing::Discount show all
Includes:
Conditions::OrderTotal, Conditions::PromoCodes, Conditions::UserTags, FlatOrPercentOff
Defined in:
app/models/workarea/pricing/discount/order_total.rb

Overview

This discount allows for basic percent of flat amount off an order total.

Constant Summary

Constants included from Conditions::OrderTotal

Conditions::OrderTotal::OPERATORS

Constants included from FlatOrPercentOff

FlatOrPercentOff::AMOUNT_TYPES

Instance Attribute Summary

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

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 included from FlatOrPercentOff

#amount_calculator

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

included

Methods included from ApplicationDocument

#releasable?

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

#embedded_children

Class Method Details

.model_nameObject



14
15
16
# File 'app/models/workarea/pricing/discount/order_total.rb', line 14

def self.model_name
  Discount.model_name
end

Instance Method Details

#apply(order) ⇒ Object

Create the price adjustments for amount off the order total. Distributes the discount amount across all items.

Parameters:



40
41
42
43
44
45
46
47
48
# File 'app/models/workarea/pricing/discount/order_total.rb', line 40

def apply(order)
  total_amount = amount_calculator.calculate(order.subtotal_price)
  distribution = PriceDistributor.for_items(total_amount, order.items)

  order.items.each do |item|
    item_total = distribution[item.id]
    item.adjust_pricing(adjustment_data(item_total, item.quantity))
  end
end

#has_items?(order) ⇒ Boolean

Qualifier method to ensure that the order has some quantity.

Parameters:

Returns:

  • (Boolean)


31
32
33
# File 'app/models/workarea/pricing/discount/order_total.rb', line 31

def has_items?(order)
  order.quantity > 0
end