Class: Spree::Pricing::Context
- Inherits:
-
Object
- Object
- Spree::Pricing::Context
- Defined in:
- lib/spree/core/pricing/context.rb
Instance Attribute Summary collapse
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#market ⇒ Object
readonly
Returns the value of attribute market.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#quantity ⇒ Object
readonly
Returns the value of attribute quantity.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
-
#zone ⇒ Object
readonly
Returns the value of attribute zone.
Class Method Summary collapse
-
.from_currency(variant, currency) ⇒ Spree::Pricing::Context
Returns a new context from a variant and currency.
- .from_order(variant, order, quantity: nil) ⇒ Object
Instance Method Summary collapse
-
#cache_key ⇒ String
Returns the cache key for the context.
-
#initialize(variant: nil, currency:, store: nil, zone: nil, market: nil, user: nil, quantity: nil, date: nil, order: nil) ⇒ Context
constructor
Initializes the context.
Constructor Details
#initialize(variant: nil, currency:, store: nil, zone: nil, market: nil, user: nil, quantity: nil, date: nil, order: nil) ⇒ Context
Initializes the context
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/spree/core/pricing/context.rb', line 16 def initialize(variant: nil, currency:, store: nil, zone: nil, market: nil, user: nil, quantity: nil, date: nil, order: nil) @variant = variant @currency = currency @store = store || Spree::Current.store @zone = zone || Spree::Current.zone @market = market || Spree::Current.market @user = user @quantity = quantity @date = date || Time.current @order = order end |
Instance Attribute Details
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
4 5 6 |
# File 'lib/spree/core/pricing/context.rb', line 4 def currency @currency end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
4 5 6 |
# File 'lib/spree/core/pricing/context.rb', line 4 def date @date end |
#market ⇒ Object (readonly)
Returns the value of attribute market.
4 5 6 |
# File 'lib/spree/core/pricing/context.rb', line 4 def market @market end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
4 5 6 |
# File 'lib/spree/core/pricing/context.rb', line 4 def order @order end |
#quantity ⇒ Object (readonly)
Returns the value of attribute quantity.
4 5 6 |
# File 'lib/spree/core/pricing/context.rb', line 4 def quantity @quantity end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
4 5 6 |
# File 'lib/spree/core/pricing/context.rb', line 4 def store @store end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
4 5 6 |
# File 'lib/spree/core/pricing/context.rb', line 4 def user @user end |
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
4 5 6 |
# File 'lib/spree/core/pricing/context.rb', line 4 def variant @variant end |
#zone ⇒ Object (readonly)
Returns the value of attribute zone.
4 5 6 |
# File 'lib/spree/core/pricing/context.rb', line 4 def zone @zone end |
Class Method Details
.from_currency(variant, currency) ⇒ Spree::Pricing::Context
Returns a new context from a variant and currency
32 33 34 |
# File 'lib/spree/core/pricing/context.rb', line 32 def self.from_currency(variant, currency) new(variant: variant, currency: currency) end |
.from_order(variant, order, quantity: nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/spree/core/pricing/context.rb', line 36 def self.from_order(variant, order, quantity: nil) new( variant: variant, currency: order.currency, store: order.store, zone: order.tax_zone || Spree::Zone.default_tax, user: order.user, quantity: quantity || order.line_items.find_by(variant: variant)&.quantity, order: order ) end |
Instance Method Details
#cache_key ⇒ String
Returns the cache key for the context
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/spree/core/pricing/context.rb', line 50 def cache_key [ 'spree', 'pricing', variant.id, currency, store&.id, zone&.id, market&.id, user&.id, quantity, date&.to_i ].compact.join('/') end |