Class: Workarea::Pricing::Discount::Shipping

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

Overview

This discount allows setting a fixed price for specific shipping services.

For example:

* Free ground shipping on orders over $100
* $5 shipping with this promo code

Constant Summary

Constants included from Conditions::OrderTotal

Conditions::OrderTotal::OPERATORS

Instance Attribute Summary collapse

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 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

Instance Attribute Details

#amountObject



23
# File 'app/models/workarea/pricing/discount/shipping.rb', line 23

field :amount, type: Money

#shipping_serviceString

Returns the Shipping::Service name to apply.

Returns:



19
# File 'app/models/workarea/pricing/discount/shipping.rb', line 19

field :shipping_service, type: String

Class Method Details

.model_nameObject



29
30
31
# File 'app/models/workarea/pricing/discount/shipping.rb', line 29

def self.model_name
  Discount.model_name
end

Instance Method Details

#apply(order) ⇒ Object

Add the discount price adjustments to the qualifying shipping.

Parameters:



55
56
57
58
59
60
# File 'app/models/workarea/pricing/discount/shipping.rb', line 55

def apply(order)
  order.shippings.each do |shipping|
    next unless shipping_matches_shipping_service?(shipping)
    apply_to_shipping(shipping)
  end
end

#matching_shipping_service?(order) ⇒ Boolean

Qualifier method for whether the order has a matching shipping address.

Parameters:

Returns:

  • (Boolean)


45
46
47
48
49
# File 'app/models/workarea/pricing/discount/shipping.rb', line 45

def matching_shipping_service?(order)
  order.shippings.any? do |shipping|
    shipping_matches_shipping_service?(shipping)
  end
end